AppDelegate+Menu.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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: NCAudioRecorderViewControllerDelegate {
  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.shared.getDirectEditingCreators(account: appDelegate.account)
  42. let isEncrypted = CCUtility.isFolderEncrypted(appDelegate.activeServerUrl, e2eEncrypted: false, account: appDelegate.account, urlBase: appDelegate.urlBase)
  43. let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, appDelegate.activeServerUrl))
  44. let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
  45. actions.append(
  46. NCMenuAction(
  47. title: NSLocalizedString("_upload_photos_videos_", comment: ""), icon: UIImage(named: "file_photo")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  48. NCPhotosPickerViewController.init(viewController: appDelegate.window.rootViewController!, maxSelectedAssets: 0, singleSelectedMode: false)
  49. }
  50. )
  51. )
  52. actions.append(
  53. NCMenuAction(
  54. title: NSLocalizedString("_upload_file_", comment: ""), icon: UIImage(named: "file")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  55. if let tabBarController = self.window.rootViewController as? UITabBarController {
  56. self.documentPickerViewController = NCDocumentPickerViewController.init(tabBarController: tabBarController)
  57. }
  58. }
  59. )
  60. )
  61. #if HC
  62. actions.append(
  63. NCMenuAction(
  64. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""), icon: UIImage(named: "imagemeter")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  65. _ = IMCreate.init(serverUrl: appDelegate.activeServerUrl, imagemeterViewerDelegate: NCNetworkingMain.shared)
  66. }
  67. )
  68. )
  69. #endif
  70. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == NCBrandGlobal.shared.editorText}) && !isEncrypted {
  71. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == NCBrandGlobal.shared.editorText})!
  72. actions.append(
  73. NCMenuAction(title: NSLocalizedString("_create_nextcloudtext_document_", comment: ""), icon: UIImage(named: "file_txt")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  74. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  75. return
  76. }
  77. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  78. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  79. viewController.editorId = NCBrandGlobal.shared.editorText
  80. viewController.creatorId = directEditingCreator.identifier
  81. viewController.typeTemplate = NCBrandGlobal.shared.templateDocument
  82. viewController.serverUrl = appDelegate.activeServerUrl
  83. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  84. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  85. })
  86. )
  87. }
  88. if #available(iOS 13.0, *) {
  89. actions.append(
  90. NCMenuAction(
  91. title: NSLocalizedString("_scans_document_", comment: ""), icon: UIImage(named: "scan")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  92. NCCreateScanDocument.shared.openScannerDocument(viewController: appDelegate.window.rootViewController!)
  93. }
  94. )
  95. )
  96. }
  97. actions.append(
  98. NCMenuAction(
  99. title: NSLocalizedString("_create_voice_memo_", comment: ""), icon: UIImage(named: "microphone")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  100. let fileName = CCUtility.createFileNameDate(NSLocalizedString("_voice_memo_filename_", comment: ""), extension: "m4a")!
  101. let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as! NCAudioRecorderViewController
  102. viewController.delegate = self
  103. viewController.createRecorder(fileName: fileName)
  104. viewController.modalTransitionStyle = .crossDissolve
  105. viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  106. appDelegate.window.rootViewController?.present(viewController, animated: true, completion: nil)
  107. }
  108. )
  109. )
  110. actions.append(
  111. NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  112. icon: UIImage(named: "folder")!.image(color: NCBrandColor.shared.brandElement, size: 50), action: { menuAction in
  113. guard let serverUrl = appDelegate.activeServerUrl else { return }
  114. let alertController = UIAlertController(title: NSLocalizedString("_create_folder_on_", comment: ""), message: nil, preferredStyle: .alert)
  115. alertController.addTextField { (textField) in
  116. textField.autocapitalizationType = UITextAutocapitalizationType.sentences
  117. }
  118. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  119. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  120. if let fileNameFolder = alertController.textFields?.first?.text {
  121. NCNetworking.shared.createFolder(fileName: fileNameFolder, serverUrl: serverUrl, account: appDelegate.account, urlBase: appDelegate.urlBase, overwrite: false) { (errorCode, errorDescription) in
  122. if errorCode != 0 {
  123. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  124. }
  125. }
  126. }
  127. })
  128. alertController.addAction(cancelAction)
  129. alertController.addAction(okAction)
  130. appDelegate.window.rootViewController?.present(alertController, animated: true, completion: nil)
  131. }
  132. )
  133. )
  134. if serverVersionMajor >= NCBrandGlobal.shared.nextcloudVersion18 && directory?.richWorkspace == nil && !isEncrypted && NCCommunication.shared.isNetworkReachable() {
  135. actions.append(
  136. NCMenuAction(
  137. title: NSLocalizedString("_add_folder_info_", comment: ""), icon: UIImage(named: "addFolderInfo")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
  138. let richWorkspaceCommon = NCRichWorkspaceCommon()
  139. if let viewController = self.activeViewController {
  140. if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.account, appDelegate.activeServerUrl, NCBrandGlobal.shared.fileNameRichWorkspace.lowercased())) == nil {
  141. richWorkspaceCommon.createViewerNextcloudText(serverUrl: appDelegate.activeServerUrl, viewController: viewController)
  142. } else {
  143. richWorkspaceCommon.openViewerNextcloudText(serverUrl: appDelegate.activeServerUrl, viewController: viewController)
  144. }
  145. }
  146. }
  147. )
  148. )
  149. }
  150. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == NCBrandGlobal.shared.editorOnlyoffice && $0.identifier == NCBrandGlobal.shared.onlyofficeDocx}) && !isEncrypted {
  151. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == NCBrandGlobal.shared.editorOnlyoffice && $0.identifier == NCBrandGlobal.shared.onlyofficeDocx})!
  152. actions.append(
  153. NCMenuAction(
  154. title: NSLocalizedString("_create_new_document_", comment: ""), icon: UIImage(named: "create_file_document")!, action: { menuAction in
  155. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  156. return
  157. }
  158. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  159. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  160. viewController.editorId = NCBrandGlobal.shared.editorOnlyoffice
  161. viewController.creatorId = directEditingCreator.identifier
  162. viewController.typeTemplate = NCBrandGlobal.shared.templateDocument
  163. viewController.serverUrl = appDelegate.activeServerUrl
  164. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  165. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  166. }
  167. )
  168. )
  169. }
  170. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == NCBrandGlobal.shared.editorOnlyoffice && $0.identifier == NCBrandGlobal.shared.onlyofficeXlsx}) && !isEncrypted {
  171. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == NCBrandGlobal.shared.editorOnlyoffice && $0.identifier == NCBrandGlobal.shared.onlyofficeXlsx})!
  172. actions.append(
  173. NCMenuAction(
  174. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), icon: UIImage(named: "create_file_xls")!, 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 = NCBrandGlobal.shared.editorOnlyoffice
  181. viewController.creatorId = directEditingCreator.identifier
  182. viewController.typeTemplate = NCBrandGlobal.shared.templateSpreadsheet
  183. viewController.serverUrl = appDelegate.activeServerUrl
  184. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  185. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  186. }
  187. )
  188. )
  189. }
  190. if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == NCBrandGlobal.shared.editorOnlyoffice && $0.identifier == NCBrandGlobal.shared.onlyofficePptx}) && !isEncrypted {
  191. let directEditingCreator = directEditingCreators!.first(where: { $0.editor == NCBrandGlobal.shared.editorOnlyoffice && $0.identifier == NCBrandGlobal.shared.onlyofficePptx})!
  192. actions.append(
  193. NCMenuAction(
  194. title: NSLocalizedString("_create_new_presentation_", comment: ""), icon: UIImage(named: "create_file_ppt")!, action: { menuAction in
  195. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  196. return
  197. }
  198. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  199. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  200. viewController.editorId = NCBrandGlobal.shared.editorOnlyoffice
  201. viewController.creatorId = directEditingCreator.identifier
  202. viewController.typeTemplate = NCBrandGlobal.shared.templatePresentation
  203. viewController.serverUrl = appDelegate.activeServerUrl
  204. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  205. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  206. }
  207. )
  208. )
  209. }
  210. if let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
  211. if richdocumentsMimetypes.count > 0 && NCCommunication.shared.isNetworkReachable() && !isEncrypted {
  212. actions.append(
  213. NCMenuAction(
  214. title: NSLocalizedString("_create_new_document_", comment: ""), icon: UIImage(named: "create_file_document")!, 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 = NCBrandGlobal.shared.editorCollabora
  221. viewController.typeTemplate = NCBrandGlobal.shared.templateDocument
  222. viewController.serverUrl = appDelegate.activeServerUrl
  223. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  224. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  225. }
  226. )
  227. )
  228. actions.append(
  229. NCMenuAction(
  230. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), icon: UIImage(named: "create_file_xls")!, action: { menuAction in
  231. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  232. return
  233. }
  234. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  235. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  236. viewController.editorId = NCBrandGlobal.shared.editorCollabora
  237. viewController.typeTemplate = NCBrandGlobal.shared.templateSpreadsheet
  238. viewController.serverUrl = appDelegate.activeServerUrl
  239. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  240. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  241. }
  242. )
  243. )
  244. actions.append(
  245. NCMenuAction(
  246. title: NSLocalizedString("_create_new_presentation_", comment: ""), icon: UIImage(named: "create_file_ppt")!, action: { menuAction in
  247. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  248. return
  249. }
  250. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  251. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  252. viewController.editorId = NCBrandGlobal.shared.editorCollabora
  253. viewController.typeTemplate = NCBrandGlobal.shared.templatePresentation
  254. viewController.serverUrl = appDelegate.activeServerUrl
  255. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  256. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  257. }
  258. )
  259. )
  260. }
  261. }
  262. return actions
  263. }
  264. // MARK: - NCAudioRecorder ViewController Delegate
  265. func didFinishRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
  266. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadVoiceNote", bundle: nil).instantiateInitialViewController() else { return }
  267. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  268. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  269. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadVoiceNote
  270. viewController.setup(serverUrl: appDelegate.activeServerUrl, fileNamePath: NSTemporaryDirectory() + fileName, fileName: fileName)
  271. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  272. }
  273. func didFinishWithoutRecording(_ viewController: NCAudioRecorderViewController, fileName: String) { }
  274. }