AppDelegate+Menu.swift 21 KB

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