AppDelegate+Menu.swift 17 KB

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