AppDelegate+Menu.swift 17 KB

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