AppDelegate+Menu.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. @objc public func showMenuIn(viewController: UIViewController) {
  28. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  29. mainMenuViewController.actions = self.initMenu()
  30. let menuPanelController = NCMenuPanelController()
  31. menuPanelController.parentPresenter = viewController
  32. menuPanelController.delegate = mainMenuViewController
  33. menuPanelController.set(contentViewController: mainMenuViewController)
  34. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  35. viewController.present(menuPanelController, animated: true, completion: nil)
  36. }
  37. private func initMenu() -> [NCMenuAction] {
  38. var actions = [NCMenuAction]()
  39. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  40. let directEditingCreators = NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount)
  41. let isEncrypted = CCUtility.isFolderEncrypted(appDelegate.activeMain.serverUrl, e2eEncrypted: false, account: appDelegate.activeAccount)
  42. let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerVersion(account: appDelegate.activeAccount, element: "major")
  43. actions.append(
  44. NCMenuAction(
  45. title: NSLocalizedString("_upload_photos_videos_", comment: ""),
  46. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  47. action: { menuAction in
  48. appDelegate.activeMain.openAssetsPickerController()
  49. }
  50. )
  51. )
  52. actions.append(
  53. NCMenuAction(
  54. title: NSLocalizedString("_upload_file_", comment: ""),
  55. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  56. action: { menuAction in
  57. appDelegate.activeMain.openImportDocumentPicker()
  58. }
  59. )
  60. )
  61. #if HC
  62. actions.append(
  63. NCMenuAction(
  64. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
  65. icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
  66. action: { menuAction in
  67. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl, imagemeterViewerDelegate: NCNetworkingMain.sharedInstance)
  68. }
  69. )
  70. )
  71. #endif
  72. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_text}) && !isEncrypted {
  73. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_text})!
  74. actions.append(
  75. 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
  76. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  77. return
  78. }
  79. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  80. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  81. viewController.editorId = k_editor_text
  82. viewController.creatorId = directEditingCreator.identifier
  83. viewController.typeTemplate = k_template_document
  84. viewController.serverUrl = appDelegate.activeMain.serverUrl
  85. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  86. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  87. })
  88. )
  89. }
  90. #if !targetEnvironment(simulator)
  91. actions.append(
  92. NCMenuAction(
  93. title: NSLocalizedString("_scans_document_", comment: ""),
  94. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  95. action: { menuAction in
  96. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  97. }
  98. )
  99. )
  100. #endif
  101. actions.append(
  102. NCMenuAction(
  103. title: NSLocalizedString("_create_voice_memo_", comment: ""),
  104. icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  105. action: { menuAction in
  106. NCMainCommon.sharedInstance.startAudioRecorder()
  107. }
  108. )
  109. )
  110. actions.append(
  111. NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  112. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brand),
  113. action: { menuAction in
  114. appDelegate.activeMain.createFolder()
  115. }
  116. )
  117. )
  118. if (serverVersionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) && !isEncrypted {
  119. actions.append(
  120. NCMenuAction(
  121. title: NSLocalizedString("_add_folder_info_", comment: ""),
  122. icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  123. action: { menuAction in
  124. self.activeMain.createRichWorkspace()
  125. }
  126. )
  127. )
  128. }
  129. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx}) && !isEncrypted {
  130. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx})!
  131. actions.append(
  132. NCMenuAction(
  133. title: NSLocalizedString("_create_new_document_", comment: ""),
  134. icon: UIImage(named: "create_file_document")!,
  135. action: { menuAction in
  136. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  137. return
  138. }
  139. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  140. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  141. viewController.editorId = k_editor_onlyoffice
  142. viewController.creatorId = directEditingCreator.identifier
  143. viewController.typeTemplate = k_template_document
  144. viewController.serverUrl = appDelegate.activeMain.serverUrl
  145. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  146. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  147. }
  148. )
  149. )
  150. }
  151. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx}) && !isEncrypted {
  152. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx})!
  153. actions.append(
  154. NCMenuAction(
  155. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  156. icon: UIImage(named: "create_file_xls")!,
  157. action: { menuAction in
  158. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  159. return
  160. }
  161. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  162. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  163. viewController.editorId = k_editor_onlyoffice
  164. viewController.creatorId = directEditingCreator.identifier
  165. viewController.typeTemplate = k_template_spreadsheet
  166. viewController.serverUrl = appDelegate.activeMain.serverUrl
  167. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  168. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  169. }
  170. )
  171. )
  172. }
  173. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx}) && !isEncrypted {
  174. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx})!
  175. actions.append(
  176. NCMenuAction(
  177. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  178. icon: UIImage(named: "create_file_ppt")!,
  179. action: { menuAction in
  180. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  181. return
  182. }
  183. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  184. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  185. viewController.editorId = k_editor_onlyoffice
  186. viewController.creatorId = directEditingCreator.identifier
  187. viewController.typeTemplate = k_template_presentation
  188. viewController.serverUrl = appDelegate.activeMain.serverUrl
  189. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  190. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  191. }
  192. )
  193. )
  194. }
  195. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  196. if richdocumentsMimetypes.count > 0 && appDelegate.reachability.isReachable() && !isEncrypted {
  197. actions.append(
  198. NCMenuAction(
  199. title: NSLocalizedString("_create_new_document_", comment: ""),
  200. icon: UIImage(named: "create_file_document")!,
  201. action: { menuAction in
  202. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  203. return
  204. }
  205. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  206. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  207. viewController.editorId = k_editor_collabora
  208. viewController.typeTemplate = k_template_document
  209. viewController.serverUrl = appDelegate.activeMain.serverUrl
  210. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  211. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  212. }
  213. )
  214. )
  215. actions.append(
  216. NCMenuAction(
  217. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  218. icon: UIImage(named: "create_file_xls")!,
  219. action: { menuAction in
  220. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  221. return
  222. }
  223. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  224. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  225. viewController.editorId = k_editor_collabora
  226. viewController.typeTemplate = k_template_spreadsheet
  227. viewController.serverUrl = appDelegate.activeMain.serverUrl
  228. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  229. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  230. }
  231. )
  232. )
  233. actions.append(
  234. NCMenuAction(
  235. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  236. icon: UIImage(named: "create_file_ppt")!,
  237. action: { menuAction in
  238. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  239. return
  240. }
  241. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  242. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  243. viewController.editorId = k_editor_collabora
  244. viewController.typeTemplate = k_template_presentation
  245. viewController.serverUrl = appDelegate.activeMain.serverUrl
  246. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  247. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  248. }
  249. )
  250. )
  251. }
  252. }
  253. return actions
  254. }
  255. }