AppDelegate+Menu.swift 21 KB

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