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