AppDelegate+Menu.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.activeServerUrl, e2eEncrypted: false, account: appDelegate.account, urlBase: appDelegate.urlBase)
  43. let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, appDelegate.activeServerUrl))
  44. let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
  45. actions.append(
  46. NCMenuAction(
  47. title: NSLocalizedString("_upload_photos_videos_", comment: ""),
  48. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  49. action: { menuAction in
  50. NCPhotosPickerViewController.init(viewController: appDelegate.window.rootViewController!, maxSelectedAssets: 100, singleSelectedMode: false)
  51. }
  52. )
  53. )
  54. actions.append(
  55. NCMenuAction(
  56. title: NSLocalizedString("_upload_file_", comment: ""),
  57. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  58. action: { menuAction in
  59. if let navigationController = (self.window.rootViewController as! UISplitViewController).viewControllers.first as? UINavigationController {
  60. if let tabBarController = navigationController.topViewController as? UITabBarController {
  61. self.documentPickerViewController = NCDocumentPickerViewController.init(tabBarController: tabBarController)
  62. }
  63. }
  64. }
  65. )
  66. )
  67. #if HC
  68. actions.append(
  69. NCMenuAction(
  70. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
  71. icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
  72. action: { menuAction in
  73. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl, imagemeterViewerDelegate: NCNetworkingMain.sharedInstance)
  74. }
  75. )
  76. )
  77. #endif
  78. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_text}) && !isEncrypted {
  79. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_text})!
  80. actions.append(
  81. 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
  82. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  83. return
  84. }
  85. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  86. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  87. viewController.editorId = k_editor_text
  88. viewController.creatorId = directEditingCreator.identifier
  89. viewController.typeTemplate = k_template_document
  90. viewController.serverUrl = appDelegate.activeMain.serverUrl
  91. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  92. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  93. })
  94. )
  95. }
  96. actions.append(
  97. NCMenuAction(
  98. title: NSLocalizedString("_scans_document_", comment: ""),
  99. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  100. action: { menuAction in
  101. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  102. }
  103. )
  104. )
  105. actions.append(
  106. NCMenuAction(
  107. title: NSLocalizedString("_create_voice_memo_", comment: ""),
  108. icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  109. action: { menuAction in
  110. NCMainCommon.shared.startAudioRecorder()
  111. }
  112. )
  113. )
  114. actions.append(
  115. NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  116. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
  117. action: { menuAction in
  118. guard let serverUrl = appDelegate.activeServerUrl else { return }
  119. let alertController = UIAlertController(title: NSLocalizedString("_create_folder_on_", comment: ""), message: nil, preferredStyle: .alert)
  120. alertController.addTextField { (textField) in
  121. //[textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  122. textField.autocapitalizationType = UITextAutocapitalizationType.sentences
  123. }
  124. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  125. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  126. if let fileNameFolder = alertController.textFields?.first?.text {
  127. NCNetworking.shared.createFolder(fileName: fileNameFolder, serverUrl: serverUrl, account: appDelegate.account, urlBase: appDelegate.urlBase, overwrite: false) { (errorCode, errorDescription) in
  128. if errorCode != 0 {
  129. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  130. }
  131. }
  132. }
  133. })
  134. //okAction.enabled = NO;
  135. alertController.addAction(cancelAction)
  136. alertController.addAction(okAction)
  137. appDelegate.window.rootViewController?.present(alertController, animated: true, completion: nil)
  138. }
  139. )
  140. )
  141. if serverVersionMajor >= k_nextcloud_version_18_0 && directory?.richWorkspace == nil && !isEncrypted && NCCommunication.shared.isNetworkReachable() {
  142. actions.append(
  143. NCMenuAction(
  144. title: NSLocalizedString("_add_folder_info_", comment: ""),
  145. icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  146. action: { menuAction in
  147. let richWorkspaceCommon = NCRichWorkspaceCommon()
  148. if let viewController = appDelegate.window.rootViewController {
  149. if NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.account, appDelegate.activeServerUrl, k_fileNameRichWorkspace.lowercased())) == nil {
  150. richWorkspaceCommon.createViewerNextcloudText(serverUrl: appDelegate.activeServerUrl, viewController: viewController)
  151. } else {
  152. richWorkspaceCommon.openViewerNextcloudText(serverUrl: appDelegate.activeServerUrl, viewController: viewController)
  153. }
  154. }
  155. }
  156. )
  157. )
  158. }
  159. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx}) && !isEncrypted {
  160. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx})!
  161. actions.append(
  162. NCMenuAction(
  163. title: NSLocalizedString("_create_new_document_", comment: ""),
  164. icon: UIImage(named: "create_file_document")!,
  165. action: { menuAction in
  166. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  167. return
  168. }
  169. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  170. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  171. viewController.editorId = k_editor_onlyoffice
  172. viewController.creatorId = directEditingCreator.identifier
  173. viewController.typeTemplate = k_template_document
  174. viewController.serverUrl = appDelegate.activeMain.serverUrl
  175. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  176. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  177. }
  178. )
  179. )
  180. }
  181. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx}) && !isEncrypted {
  182. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx})!
  183. actions.append(
  184. NCMenuAction(
  185. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  186. icon: UIImage(named: "create_file_xls")!,
  187. action: { menuAction in
  188. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  189. return
  190. }
  191. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  192. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  193. viewController.editorId = k_editor_onlyoffice
  194. viewController.creatorId = directEditingCreator.identifier
  195. viewController.typeTemplate = k_template_spreadsheet
  196. viewController.serverUrl = appDelegate.activeMain.serverUrl
  197. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  198. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  199. }
  200. )
  201. )
  202. }
  203. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx}) && !isEncrypted {
  204. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx})!
  205. actions.append(
  206. NCMenuAction(
  207. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  208. icon: UIImage(named: "create_file_ppt")!,
  209. action: { menuAction in
  210. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  211. return
  212. }
  213. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  214. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  215. viewController.editorId = k_editor_onlyoffice
  216. viewController.creatorId = directEditingCreator.identifier
  217. viewController.typeTemplate = k_template_presentation
  218. viewController.serverUrl = appDelegate.activeMain.serverUrl
  219. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  220. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  221. }
  222. )
  223. )
  224. }
  225. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
  226. if richdocumentsMimetypes.count > 0 && NCCommunication.shared.isNetworkReachable() && !isEncrypted {
  227. actions.append(
  228. NCMenuAction(
  229. title: NSLocalizedString("_create_new_document_", comment: ""),
  230. icon: UIImage(named: "create_file_document")!,
  231. action: { menuAction in
  232. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  233. return
  234. }
  235. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  236. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  237. viewController.editorId = k_editor_collabora
  238. viewController.typeTemplate = k_template_document
  239. viewController.serverUrl = appDelegate.activeMain.serverUrl
  240. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  241. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  242. }
  243. )
  244. )
  245. actions.append(
  246. NCMenuAction(
  247. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  248. icon: UIImage(named: "create_file_xls")!,
  249. action: { menuAction in
  250. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  251. return
  252. }
  253. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  254. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  255. viewController.editorId = k_editor_collabora
  256. viewController.typeTemplate = k_template_spreadsheet
  257. viewController.serverUrl = appDelegate.activeMain.serverUrl
  258. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  259. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  260. }
  261. )
  262. )
  263. actions.append(
  264. NCMenuAction(
  265. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  266. icon: UIImage(named: "create_file_ppt")!,
  267. action: { menuAction in
  268. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  269. return
  270. }
  271. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  272. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  273. viewController.editorId = k_editor_collabora
  274. viewController.typeTemplate = k_template_presentation
  275. viewController.serverUrl = appDelegate.activeMain.serverUrl
  276. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  277. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  278. }
  279. )
  280. )
  281. }
  282. }
  283. return actions
  284. }
  285. }