AppDelegate+Menu.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. }
  79. #if !targetEnvironment(simulator)
  80. if #available(iOS 11.0, *) {
  81. actions.append(
  82. NCMenuAction(
  83. title: NSLocalizedString("_scans_document_", comment: ""),
  84. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  85. action: { menuAction in
  86. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  87. }
  88. )
  89. )
  90. }
  91. #endif
  92. actions.append(
  93. NCMenuAction(
  94. title: NSLocalizedString("_create_voice_memo_", comment: ""),
  95. icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  96. action: { menuAction in
  97. NCMainCommon.sharedInstance.startAudioRecorder()
  98. }
  99. )
  100. )
  101. actions.append(
  102. NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  103. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brand),
  104. action: { menuAction in
  105. appDelegate.activeMain.createFolder()
  106. }
  107. )
  108. )
  109. if #available(iOS 11.0, *) {
  110. if let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: appDelegate.activeAccount) {
  111. if (capabilities.versionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) && !isEncrypted {
  112. actions.append(
  113. NCMenuAction(
  114. title: NSLocalizedString("_add_folder_info_", comment: ""),
  115. icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  116. action: { menuAction in
  117. self.activeMain.createRichWorkspace()
  118. }
  119. )
  120. )
  121. }
  122. }
  123. }
  124. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx}) && !isEncrypted {
  125. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx})!
  126. actions.append(
  127. NCMenuAction(
  128. title: NSLocalizedString("_create_new_document_", comment: ""),
  129. icon: UIImage(named: "create_file_document")!,
  130. action: { menuAction in
  131. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  132. return
  133. }
  134. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  135. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  136. viewController.editorId = k_editor_onlyoffice
  137. viewController.creatorId = directEditingCreator.identifier
  138. viewController.typeTemplate = k_template_document
  139. viewController.serverUrl = appDelegate.activeMain.serverUrl
  140. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  141. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  142. }
  143. )
  144. )
  145. }
  146. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx}) && !isEncrypted {
  147. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx})!
  148. actions.append(
  149. NCMenuAction(
  150. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  151. icon: UIImage(named: "create_file_xls")!,
  152. action: { menuAction in
  153. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  154. return
  155. }
  156. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  157. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  158. viewController.editorId = k_editor_onlyoffice
  159. viewController.creatorId = directEditingCreator.identifier
  160. viewController.typeTemplate = k_template_spreadsheet
  161. viewController.serverUrl = appDelegate.activeMain.serverUrl
  162. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  163. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  164. }
  165. )
  166. )
  167. }
  168. if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx}) && !isEncrypted {
  169. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx})!
  170. actions.append(
  171. NCMenuAction(
  172. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  173. icon: UIImage(named: "create_file_ppt")!,
  174. action: { menuAction in
  175. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  176. return
  177. }
  178. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  179. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  180. viewController.editorId = k_editor_onlyoffice
  181. viewController.creatorId = directEditingCreator.identifier
  182. viewController.typeTemplate = k_template_presentation
  183. viewController.serverUrl = appDelegate.activeMain.serverUrl
  184. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  185. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  186. }
  187. )
  188. )
  189. }
  190. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  191. if richdocumentsMimetypes.count > 0 && appDelegate.reachability.isReachable() && !isEncrypted {
  192. actions.append(
  193. NCMenuAction(
  194. title: NSLocalizedString("_create_new_document_", comment: ""),
  195. icon: UIImage(named: "create_file_document")!,
  196. action: { menuAction in
  197. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  198. return
  199. }
  200. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  201. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  202. viewController.editorId = k_editor_collabora
  203. viewController.typeTemplate = k_template_document
  204. viewController.serverUrl = appDelegate.activeMain.serverUrl
  205. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  206. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  207. }
  208. )
  209. )
  210. actions.append(
  211. NCMenuAction(
  212. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  213. icon: UIImage(named: "create_file_xls")!,
  214. action: { menuAction in
  215. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  216. return
  217. }
  218. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  219. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  220. viewController.editorId = k_editor_collabora
  221. viewController.typeTemplate = k_template_spreadsheet
  222. viewController.serverUrl = appDelegate.activeMain.serverUrl
  223. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  224. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  225. }
  226. )
  227. )
  228. actions.append(
  229. NCMenuAction(
  230. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  231. icon: UIImage(named: "create_file_ppt")!,
  232. action: { menuAction in
  233. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  234. return
  235. }
  236. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  237. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  238. viewController.editorId = k_editor_collabora
  239. viewController.typeTemplate = k_template_presentation
  240. viewController.serverUrl = appDelegate.activeMain.serverUrl
  241. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  242. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  243. }
  244. )
  245. )
  246. }
  247. }
  248. return actions
  249. }
  250. @objc public func showMenuIn(viewController: UIViewController) {
  251. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  252. mainMenuViewController.actions = self.initMenu()
  253. let menuPanelController = NCMenuPanelController()
  254. menuPanelController.parentPresenter = viewController
  255. menuPanelController.delegate = mainMenuViewController
  256. menuPanelController.set(contentViewController: mainMenuViewController)
  257. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  258. viewController.present(menuPanelController, animated: true, completion: nil)
  259. }
  260. }