AppDelegate+Menu.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. //
  2. // AppDelegate+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.01.20.
  6. // Copyright © 2020 Philippe Weidmann. All rights reserved.
  7. // Copyright © 2020 Marino Faggiana All rights reserved.
  8. //
  9. // Author Philippe Weidmann <philippe.weidmann@infomaniak.com>
  10. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import FloatingPanel
  26. extension AppDelegate {
  27. private func initMenu() -> [NCMenuAction] {
  28. var actions = [NCMenuAction]()
  29. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  30. let directEditingCreators = NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount)
  31. actions.append(
  32. NCMenuAction(
  33. title: NSLocalizedString("_upload_photos_videos_", comment: ""),
  34. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  35. action: { menuAction in
  36. appDelegate.activeMain.openAssetsPickerController()
  37. }
  38. )
  39. )
  40. actions.append(
  41. NCMenuAction(
  42. title: NSLocalizedString("_upload_file_", comment: ""),
  43. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  44. action: { menuAction in
  45. appDelegate.activeMain.openImportDocumentPicker()
  46. }
  47. )
  48. )
  49. #if HC
  50. actions.append(
  51. NCMenuAction(
  52. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
  53. icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
  54. action: { menuAction in
  55. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl, imagemeterViewerDelegate: NCNetworkingMain.sharedInstance)
  56. }
  57. )
  58. )
  59. #endif
  60. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_text}) {
  61. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_text})!
  62. actions.append(
  63. NCMenuAction(title: NSLocalizedString("_create_nextcloudtext_document_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  64. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  65. return
  66. }
  67. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  68. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  69. viewController.editorId = k_editor_text
  70. viewController.creatorId = directEditingCreator.identifier
  71. viewController.typeTemplate = k_template_document
  72. viewController.serverUrl = appDelegate.activeMain.serverUrl
  73. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  74. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  75. })
  76. )
  77. } else {
  78. actions.append(
  79. NCMenuAction(title: NSLocalizedString("_upload_file_text_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  80. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  81. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  82. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  83. appDelegate.activeMain.present(controller, animated: true, completion: nil)
  84. })
  85. )
  86. }
  87. #if !targetEnvironment(simulator)
  88. if #available(iOS 11.0, *) {
  89. actions.append(
  90. NCMenuAction(
  91. title: NSLocalizedString("_scans_document_", comment: ""),
  92. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  93. action: { menuAction in
  94. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  95. }
  96. )
  97. )
  98. }
  99. #endif
  100. actions.append(
  101. NCMenuAction(
  102. title: NSLocalizedString("_create_voice_memo_", comment: ""),
  103. icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  104. action: { menuAction in
  105. NCMainCommon.sharedInstance.startAudioRecorder()
  106. }
  107. )
  108. )
  109. actions.append(
  110. NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  111. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brand),
  112. action: { menuAction in
  113. appDelegate.activeMain.createFolder()
  114. }
  115. )
  116. )
  117. if #available(iOS 11.0, *) {
  118. if let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: appDelegate.activeAccount) {
  119. if (capabilities.versionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) {
  120. actions.append(
  121. NCMenuAction(
  122. title: NSLocalizedString("_add_folder_info_", comment: ""),
  123. icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  124. action: { menuAction in
  125. self.activeMain.createRichWorkspace()
  126. }
  127. )
  128. )
  129. }
  130. }
  131. }
  132. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx}) {
  133. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx})!
  134. actions.append(
  135. NCMenuAction(
  136. title: NSLocalizedString("_create_new_document_", comment: ""),
  137. icon: UIImage(named: "create_file_document")!,
  138. action: { menuAction in
  139. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  140. return
  141. }
  142. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  143. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  144. viewController.editorId = k_editor_onlyoffice
  145. viewController.creatorId = directEditingCreator.identifier
  146. viewController.typeTemplate = k_template_document
  147. viewController.serverUrl = appDelegate.activeMain.serverUrl
  148. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  149. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  150. }
  151. )
  152. )
  153. }
  154. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx}) {
  155. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx})!
  156. actions.append(
  157. NCMenuAction(
  158. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  159. icon: UIImage(named: "create_file_xls")!,
  160. action: { menuAction in
  161. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  162. return
  163. }
  164. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  165. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  166. viewController.editorId = k_editor_onlyoffice
  167. viewController.creatorId = directEditingCreator.identifier
  168. viewController.typeTemplate = k_template_spreadsheet
  169. viewController.serverUrl = appDelegate.activeMain.serverUrl
  170. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  171. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  172. }
  173. )
  174. )
  175. }
  176. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx}) {
  177. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx})!
  178. actions.append(
  179. NCMenuAction(
  180. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  181. icon: UIImage(named: "create_file_ppt")!,
  182. action: { menuAction in
  183. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  184. return
  185. }
  186. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  187. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  188. viewController.editorId = k_editor_onlyoffice
  189. viewController.creatorId = directEditingCreator.identifier
  190. viewController.typeTemplate = k_template_presentation
  191. viewController.serverUrl = appDelegate.activeMain.serverUrl
  192. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  193. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  194. }
  195. )
  196. )
  197. }
  198. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  199. if richdocumentsMimetypes.count > 0 && appDelegate.reachability.isReachable() {
  200. actions.append(
  201. NCMenuAction(
  202. title: NSLocalizedString("_create_new_document_", comment: ""),
  203. icon: UIImage(named: "create_file_document")!,
  204. action: { menuAction in
  205. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  206. return
  207. }
  208. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  209. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  210. viewController.editorId = k_editor_collabora
  211. viewController.typeTemplate = k_template_document
  212. viewController.serverUrl = appDelegate.activeMain.serverUrl
  213. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  214. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  215. }
  216. )
  217. )
  218. actions.append(
  219. NCMenuAction(
  220. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  221. icon: UIImage(named: "create_file_xls")!,
  222. action: { menuAction in
  223. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  224. return
  225. }
  226. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  227. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  228. viewController.editorId = k_editor_collabora
  229. viewController.typeTemplate = k_template_spreadsheet
  230. viewController.serverUrl = appDelegate.activeMain.serverUrl
  231. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  232. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  233. }
  234. )
  235. )
  236. actions.append(
  237. NCMenuAction(
  238. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  239. icon: UIImage(named: "create_file_ppt")!,
  240. action: { menuAction in
  241. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  242. return
  243. }
  244. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  245. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  246. viewController.editorId = k_editor_collabora
  247. viewController.typeTemplate = k_template_presentation
  248. viewController.serverUrl = appDelegate.activeMain.serverUrl
  249. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  250. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  251. }
  252. )
  253. )
  254. }
  255. }
  256. return actions
  257. }
  258. @objc public func showMenuIn(viewController: UIViewController) {
  259. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  260. mainMenuViewController.actions = self.initMenu()
  261. let menuPanelController = NCMenuPanelController()
  262. menuPanelController.parentPresenter = viewController
  263. menuPanelController.delegate = mainMenuViewController
  264. menuPanelController.set(contentViewController: mainMenuViewController)
  265. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  266. viewController.present(menuPanelController, animated: true, completion: nil)
  267. }
  268. }