123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- //
- // AppDelegate+Menu.swift
- // Nextcloud
- //
- // Created by Philippe Weidmann on 24.01.20.
- // Copyright © 2020 Philippe Weidmann. All rights reserved.
- // Copyright © 2020 Marino Faggiana All rights reserved.
- //
- // Author Philippe Weidmann <philippe.weidmann@infomaniak.com>
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import FloatingPanel
- import NCCommunication
- extension AppDelegate {
- @objc public func showMenuIn(viewController: UIViewController) {
- let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
- mainMenuViewController.actions = self.initMenu()
- let menuPanelController = NCMenuPanelController()
- menuPanelController.parentPresenter = viewController
- menuPanelController.delegate = mainMenuViewController
- menuPanelController.set(contentViewController: mainMenuViewController)
- menuPanelController.track(scrollView: mainMenuViewController.tableView)
- viewController.present(menuPanelController, animated: true, completion: nil)
- }
-
- private func initMenu() -> [NCMenuAction] {
- var actions = [NCMenuAction]()
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- let directEditingCreators = NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount)
- let isEncrypted = CCUtility.isFolderEncrypted(appDelegate.activeMain.serverUrl, e2eEncrypted: false, account: appDelegate.activeAccount)
- let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: appDelegate.activeAccount, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
-
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_upload_photos_videos_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- appDelegate.activeMain.openAssetsPickerController()
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_upload_file_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- appDelegate.activeMain.openImportDocumentPicker()
- }
- )
- )
- #if HC
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
- icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
- action: { menuAction in
- _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl, imagemeterViewerDelegate: NCNetworkingMain.sharedInstance)
- }
- )
- )
- #endif
-
- if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_text}) && !isEncrypted {
- let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_text})!
- actions.append(
- 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
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
-
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_text
- viewController.creatorId = directEditingCreator.identifier
- viewController.typeTemplate = k_template_document
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- })
- )
- }
-
- #if !targetEnvironment(simulator)
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_scans_document_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
- }
- )
- )
- #endif
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_voice_memo_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- NCMainCommon.sharedInstance.startAudioRecorder()
- }
- )
- )
- actions.append(
- NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brand),
- action: { menuAction in
- appDelegate.activeMain.createFolder()
- }
- )
- )
- if (serverVersionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) && !isEncrypted && NCCommunication.shared.isNetworkReachable() {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_add_folder_info_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.activeMain.createRichWorkspace()
- }
- )
- )
- }
-
- if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx}) && !isEncrypted {
- let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_docx})!
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_new_document_", comment: ""),
- icon: UIImage(named: "create_file_document")!,
- action: { menuAction in
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_onlyoffice
- viewController.creatorId = directEditingCreator.identifier
- viewController.typeTemplate = k_template_document
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
- }
-
- if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx}) && !isEncrypted {
- let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_xlsx})!
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
- icon: UIImage(named: "create_file_xls")!,
- action: { menuAction in
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_onlyoffice
- viewController.creatorId = directEditingCreator.identifier
- viewController.typeTemplate = k_template_spreadsheet
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
- }
-
- if NCCommunication.shared.isNetworkReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx}) && !isEncrypted {
- let directEditingCreator = directEditingCreators!.first(where: { $0.editor == k_editor_onlyoffice && $0.identifier == k_onlyoffice_pptx})!
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_new_presentation_", comment: ""),
- icon: UIImage(named: "create_file_ppt")!,
- action: { menuAction in
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_onlyoffice
- viewController.creatorId = directEditingCreator.identifier
- viewController.typeTemplate = k_template_presentation
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
- }
-
- if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getCapabilitiesServerArray(account: appDelegate.activeAccount, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
- if richdocumentsMimetypes.count > 0 && NCCommunication.shared.isNetworkReachable() && !isEncrypted {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_new_document_", comment: ""),
- icon: UIImage(named: "create_file_document")!,
- action: { menuAction in
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_collabora
- viewController.typeTemplate = k_template_document
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
- icon: UIImage(named: "create_file_xls")!,
- action: { menuAction in
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_collabora
- viewController.typeTemplate = k_template_spreadsheet
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
-
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_create_new_presentation_", comment: ""),
- icon: UIImage(named: "create_file_ppt")!,
- action: { menuAction in
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
- return
- }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
- viewController.editorId = k_editor_collabora
- viewController.typeTemplate = k_template_presentation
- viewController.serverUrl = appDelegate.activeMain.serverUrl
- viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
- appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
- }
- }
- return actions
- }
- }
|