marinofaggiana 5 years ago
parent
commit
0017c564d0

+ 15 - 5
iOSClient/CCGlobal.h

@@ -274,13 +274,9 @@
 // Toolbar Detail
 #define k_detail_Toolbar_Height                         49
 
-// Template Rich document
-#define k_richdocument_document                         @"document"
-#define k_richdocument_spreadsheet                      @"spreadsheet"
-#define k_richdocument_presentation                     @"presentation"
 
 // Template Nextcloud Text
-#define k_nextcloudtext_document                        @"textdocument"
+
 
 // Layout
 #define k_layout_list                                   @"typeLayoutList"
@@ -294,6 +290,20 @@
 // Rich Workspace
 #define k_fileNameRichWorkspace                         @"Readme.md"
 
+// Text -  OnlyOffice - Collabora
+#define k_editor_text                                   @"text"
+#define k_editor_onlyoffice                             @"onlyoffice"
+#define k_editor_collabora                              @"collabora"
+
+#define k_onlyoffice_docx                               @"onlyoffice_docx"
+#define k_onlyoffice_xlsx                               @"onlyoffice_xlsx"
+#define k_onlyoffice_pptx                               @"onlyoffice_pptx"
+
+// Template
+#define k_template_document                             @"document"
+#define k_template_spreadsheet                          @"spreadsheet"
+#define k_template_presentation                         @"presentation"
+
 // Nextcloud unsupported
 #define k_nextcloud_unsupported                         13
 

+ 19 - 6
iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift

@@ -28,6 +28,7 @@ import NCCommunication
 
 class NCCreateFormUploadDocuments: XLFormViewController, NCSelectDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
     
+    var typeEditor = ""
     var typeTemplate = ""
     var serverUrl = ""
     var fileNameFolder = ""
@@ -265,9 +266,9 @@ class NCCreateFormUploadDocuments: XLFormViewController, NCSelectDelegate, UICol
             fileName = CCUtility.returnFileNamePath(fromFileName: fileName, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)
         }
             
-        if self.typeTemplate == k_nextcloudtext_document {
+        if self.typeEditor == k_editor_text || self.typeEditor == k_editor_onlyoffice {
                                     
-            NCCommunication.sharedInstance.NCTextCreateFile(urlString: appDelegate.activeUrl, fileNamePath: fileName, editor: "text", templateId: selectTemplate.identifier, account: self.appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
+            NCCommunication.sharedInstance.NCTextCreateFile(urlString: appDelegate.activeUrl, fileNamePath: fileName, editor: typeEditor, templateId: selectTemplate.identifier, account: self.appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
                 
                 if errorCode == 0 && account == self.appDelegate.activeAccount {
                     
@@ -287,7 +288,9 @@ class NCCreateFormUploadDocuments: XLFormViewController, NCSelectDelegate, UICol
                 }
             }
             
-        } else {
+        }
+        
+        if self.typeEditor == k_editor_collabora {
             
             OCNetworking.sharedManager().createNewRichdocuments(withAccount: appDelegate.activeAccount, fileName: fileName, serverUrl: serverUrl, templateID: selectTemplate.identifier, completion: { (account, url, message, errorCode) in
                        
@@ -323,7 +326,7 @@ class NCCreateFormUploadDocuments: XLFormViewController, NCSelectDelegate, UICol
         indicator.color = NCBrandColor.sharedInstance.brand
         indicator.startAnimating()
         
-        if self.typeTemplate == k_nextcloudtext_document {
+        if self.typeEditor == k_editor_text || self.typeEditor == k_editor_onlyoffice {
             
             // default
             fileNameExtension = "md"
@@ -358,7 +361,15 @@ class NCCreateFormUploadDocuments: XLFormViewController, NCSelectDelegate, UICol
                         let temp = NCEditorTemplates()
                         
                         temp.identifier = ""
-                        temp.ext = "md"
+                        if self.typeEditor == k_editor_text {
+                            temp.ext = "md"
+                        } else if self.typeEditor == k_editor_onlyoffice && self.typeTemplate == k_template_document {
+                            temp.ext = "docx"
+                        } else if self.typeEditor == k_editor_onlyoffice && self.typeTemplate == k_template_spreadsheet {
+                            temp.ext = "xlsx"
+                        } else if self.typeEditor == k_editor_onlyoffice && self.typeTemplate == k_template_presentation {
+                            temp.ext = "pptx"
+                        }
                         temp.name = "Empty"
                         temp.preview = ""
                                                                       
@@ -378,7 +389,9 @@ class NCCreateFormUploadDocuments: XLFormViewController, NCSelectDelegate, UICol
                 }
             }
             
-        } else {
+        }
+        
+        if self.typeEditor == k_editor_collabora  {
             
             // default
             

+ 4 - 4
iOSClient/Main/Create cloud/NCCreateMenuAdd.swift

@@ -97,7 +97,7 @@ class NCCreateMenuAdd: NSObject {
                 navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
                 
                 let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                viewController.typeTemplate = k_nextcloudtext_document
+                viewController.typeTemplate = k_template_document
                 viewController.serverUrl = self.appDelegate.activeMain.serverUrl
                 viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
                 
@@ -120,7 +120,7 @@ class NCCreateMenuAdd: NSObject {
                 navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
                 
                 let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                viewController.typeTemplate = k_richdocument_document
+                viewController.typeTemplate = k_template_document
                 viewController.serverUrl = self.appDelegate.activeMain.serverUrl
                 viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
                 
@@ -133,7 +133,7 @@ class NCCreateMenuAdd: NSObject {
                 navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
                 
                 let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                viewController.typeTemplate = k_richdocument_spreadsheet
+                viewController.typeTemplate = k_template_spreadsheet
                 viewController.serverUrl = self.appDelegate.activeMain.serverUrl
                 viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
                 
@@ -146,7 +146,7 @@ class NCCreateMenuAdd: NSObject {
                 navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
                 
                 let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                viewController.typeTemplate = k_richdocument_presentation
+                viewController.typeTemplate = k_template_presentation
                 viewController.serverUrl = self.appDelegate.activeMain.serverUrl
                 viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
                 

+ 98 - 36
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -30,11 +30,7 @@ extension AppDelegate {
     private func initMenu() -> [NCMenuAction] {
         var actions = [NCMenuAction]()
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
-        var isNextcloudTextAvailable = false
-
-        if appDelegate.reachability.isReachable() && NCBrandBeta.shared.directEditing && NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount) != nil {
-            isNextcloudTextAvailable = true
-        }
+        let directEditingCreators = NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount)
 
         actions.append(
             NCMenuAction(
@@ -67,41 +63,35 @@ extension AppDelegate {
                 )
             )
         }
-
-        if isNextcloudTextAvailable {
+        
+        if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(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
+                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.typeTemplate = k_nextcloudtext_document
-                        viewController.serverUrl = appDelegate.activeMain.serverUrl
-                        viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
+                    let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
+                    viewController.typeEditor = k_editor_text
+                    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)
-                    }
-                )
+                    appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                })
             )
         } else {
             actions.append(
-                NCMenuAction(
-                    title: NSLocalizedString("_upload_file_text_", comment: ""),
-                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
-                    action: { menuAction in
-                        let storyboard = UIStoryboard(name: "NCText", bundle: nil)
-                        let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
-                        controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
-                        appDelegate.activeMain.present(controller, animated: true, completion: nil)
-                    }
-                )
+                NCMenuAction(title: NSLocalizedString("_upload_file_text_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                    let storyboard = UIStoryboard(name: "NCText", bundle: nil)
+                    let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
+                    controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
+                    appDelegate.activeMain.present(controller, animated: true, completion: nil)
+                })
             )
         }
-
+        
         #if !targetEnvironment(simulator)
             if #available(iOS 11.0, *) {
                 actions.append(
@@ -148,7 +138,76 @@ extension AppDelegate {
                 )
             }
         }
+        
+        if appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice}) && directEditingCreators!.contains(where: { $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.typeEditor = k_editor_onlyoffice
+                        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 appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice}) && directEditingCreators!.contains(where: { $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.typeEditor = k_editor_onlyoffice
+                        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 appDelegate.reachability.isReachable() && directEditingCreators != nil && directEditingCreators!.contains(where: { $0.editor == k_editor_onlyoffice}) && directEditingCreators!.contains(where: { $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.typeEditor = k_editor_onlyoffice
+                        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.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
             if richdocumentsMimetypes.count > 0 {
                 actions.append(
@@ -162,9 +221,10 @@ extension AppDelegate {
                             navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
 
                             let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                            viewController.typeTemplate = k_richdocument_document
+                            viewController.typeEditor = k_editor_collabora
+                            viewController.typeTemplate = k_template_document
                             viewController.serverUrl = appDelegate.activeMain.serverUrl
-                            viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
+                            viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
 
                             appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
                         }
@@ -182,7 +242,8 @@ extension AppDelegate {
                             navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
 
                             let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                            viewController.typeTemplate = k_richdocument_spreadsheet
+                            viewController.typeEditor = k_editor_collabora
+                            viewController.typeTemplate = k_template_spreadsheet
                             viewController.serverUrl = appDelegate.activeMain.serverUrl
                             viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
 
@@ -202,7 +263,8 @@ extension AppDelegate {
                             navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
 
                             let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
-                            viewController.typeTemplate = k_richdocument_presentation
+                            viewController.typeEditor = k_editor_collabora
+                            viewController.typeTemplate = k_template_presentation
                             viewController.serverUrl = appDelegate.activeMain.serverUrl
                             viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
 

+ 2 - 2
iOSClient/Utility/NCContentPresenter.swift

@@ -54,8 +54,8 @@ class NCContentPresenter: NSObject {
             case Int(CFNetworkErrors.cfurlErrorNotConnectedToInternet.rawValue):
                 let image = CCGraphics.changeThemingColorImage(UIImage(named: "networkInProgress")!, width: 40, height: 40, color: .white)
                 self.noteTop(text:  NSLocalizedString(title, comment: ""), image: image, color: .lightGray, delay: delay, name: "\(errorCode)")
-            case Int(kOCErrorServerUnauthorized), Int(kOCErrorServerForbidden):
-                break
+            //case Int(kOCErrorServerUnauthorized), Int(kOCErrorServerForbidden):
+            //    break
             default:
                 var description = description
                 if description == nil { description = "" }