AppDelegate+Menu.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. actions.append(
  43. NCMenuAction(
  44. title: NSLocalizedString("_upload_photos_videos_", comment: ""),
  45. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  46. action: { menuAction in
  47. appDelegate.activeMain.openAssetsPickerController()
  48. }
  49. )
  50. )
  51. actions.append(
  52. NCMenuAction(
  53. title: NSLocalizedString("_upload_file_", comment: ""),
  54. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  55. action: { menuAction in
  56. appDelegate.activeMain.openImportDocumentPicker()
  57. }
  58. )
  59. )
  60. #if HC
  61. actions.append(
  62. NCMenuAction(
  63. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
  64. icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
  65. action: { menuAction in
  66. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl, imagemeterViewerDelegate: NCNetworkingMain.sharedInstance)
  67. }
  68. )
  69. )
  70. #endif
  71. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_text}) && !isEncrypted {
  72. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_text})!
  73. actions.append(
  74. 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
  75. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  76. return
  77. }
  78. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  79. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  80. viewController.editorId = k_editor_text
  81. viewController.creatorId = directEditingCreator.identifier
  82. viewController.typeTemplate = k_template_document
  83. viewController.serverUrl = appDelegate.activeMain.serverUrl
  84. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  85. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  86. })
  87. )
  88. }
  89. #if !targetEnvironment(simulator)
  90. actions.append(
  91. NCMenuAction(
  92. title: NSLocalizedString("_scans_document_", comment: ""),
  93. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  94. action: { menuAction in
  95. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  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 let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: appDelegate.activeAccount) {
  118. if (capabilities.versionMajor >= 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. }
  130. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx}) && !isEncrypted {
  131. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx})!
  132. actions.append(
  133. NCMenuAction(
  134. title: NSLocalizedString("_create_new_document_", comment: ""),
  135. icon: UIImage(named: "create_file_document")!,
  136. action: { menuAction in
  137. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  138. return
  139. }
  140. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  141. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  142. viewController.editorId = k_editor_onlyoffice
  143. viewController.creatorId = directEditingCreator.identifier
  144. viewController.typeTemplate = k_template_document
  145. viewController.serverUrl = appDelegate.activeMain.serverUrl
  146. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  147. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  148. }
  149. )
  150. )
  151. }
  152. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx}) && !isEncrypted {
  153. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx})!
  154. actions.append(
  155. NCMenuAction(
  156. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  157. icon: UIImage(named: "create_file_xls")!,
  158. action: { menuAction in
  159. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  160. return
  161. }
  162. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  163. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  164. viewController.editorId = k_editor_onlyoffice
  165. viewController.creatorId = directEditingCreator.identifier
  166. viewController.typeTemplate = k_template_spreadsheet
  167. viewController.serverUrl = appDelegate.activeMain.serverUrl
  168. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  169. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  170. }
  171. )
  172. )
  173. }
  174. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx}) && !isEncrypted {
  175. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx})!
  176. actions.append(
  177. NCMenuAction(
  178. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  179. icon: UIImage(named: "create_file_ppt")!,
  180. action: { menuAction in
  181. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  182. return
  183. }
  184. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  185. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  186. viewController.editorId = k_editor_onlyoffice
  187. viewController.creatorId = directEditingCreator.identifier
  188. viewController.typeTemplate = k_template_presentation
  189. viewController.serverUrl = appDelegate.activeMain.serverUrl
  190. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  191. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  192. }
  193. )
  194. )
  195. }
  196. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  197. if richdocumentsMimetypes.count > 0 && appDelegate.reachability.isReachable() && !isEncrypted {
  198. actions.append(
  199. NCMenuAction(
  200. title: NSLocalizedString("_create_new_document_", comment: ""),
  201. icon: UIImage(named: "create_file_document")!,
  202. action: { menuAction in
  203. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  204. return
  205. }
  206. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  207. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  208. viewController.editorId = k_editor_collabora
  209. viewController.typeTemplate = k_template_document
  210. viewController.serverUrl = appDelegate.activeMain.serverUrl
  211. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  212. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  213. }
  214. )
  215. )
  216. actions.append(
  217. NCMenuAction(
  218. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  219. icon: UIImage(named: "create_file_xls")!,
  220. action: { menuAction in
  221. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  222. return
  223. }
  224. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  225. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  226. viewController.editorId = k_editor_collabora
  227. viewController.typeTemplate = k_template_spreadsheet
  228. viewController.serverUrl = appDelegate.activeMain.serverUrl
  229. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  230. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  231. }
  232. )
  233. )
  234. actions.append(
  235. NCMenuAction(
  236. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  237. icon: UIImage(named: "create_file_ppt")!,
  238. action: { menuAction in
  239. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  240. return
  241. }
  242. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  243. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  244. viewController.editorId = k_editor_collabora
  245. viewController.typeTemplate = k_template_presentation
  246. viewController.serverUrl = appDelegate.activeMain.serverUrl
  247. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  248. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  249. }
  250. )
  251. )
  252. }
  253. }
  254. return actions
  255. }
  256. }