marinofaggiana 5 年之前
父节点
当前提交
42f4147e25

+ 1 - 1
File Provider Extension/FileProviderExtension.swift

@@ -238,7 +238,7 @@ class FileProviderExtension: NSFileProviderExtension, CCNetworkingDelegate {
             return
         }
         
-        let task = OCNetworking.sharedManager().download(withAccount: providerData.account, fileNameServerUrl: metadata.serverUrl + "/" + metadata.fileName, fileNameLocalPath: url.path, communication: OCNetworking.sharedManager()?.sharedOCCommunicationExtensionDownload(), completion: { (account, lenght, etag, date, message, errorCode) in
+        let task = OCNetworking.sharedManager().download(withAccount: providerData.account, fileNameServerUrl: metadata.serverUrl + "/" + metadata.fileName, fileNameLocalPath: url.path, encode:true, communication: OCNetworking.sharedManager()?.sharedOCCommunicationExtensionDownload(), completion: { (account, lenght, etag, date, message, errorCode) in
             
             if errorCode == 0 && account == self.providerData.account {
                 

+ 1 - 1
iOSClient/Activity/NCActivity.swift

@@ -365,7 +365,7 @@ extension activityTableViewCell: UICollectionViewDelegate {
             
             NCUtility.sharedInstance.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!, bottom: 0)
             
-            let _ = OCNetworking.sharedManager()?.download(withAccount: activityPreview.account, url: url, fileNameLocalPath: fileNameLocalPath, completion: { (account, message, errorCode) in
+            let _ = OCNetworking.sharedManager()?.download(withAccount: activityPreview.account, url: url, fileNameLocalPath: fileNameLocalPath, encode:true, completion: { (account, message, errorCode) in
                 
                 if account == self.appDelegate.activeAccount && errorCode == 0 {
                     

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.h

@@ -379,7 +379,7 @@ typedef enum {
  *
  */
 
-- (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest;
+- (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority encode:(BOOL)encode onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest;
 
 ///-----------------------------------
 /// @name Set Download Task Complete Block

+ 2 - 2
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -467,11 +467,11 @@
 
 
 
-- (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest {
+- (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority encode:(BOOL)encode onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest {
     
     OCWebDAVClient *request = [OCWebDAVClient new];
     request = [self getRequestWithCredentials:request];
-    remotePath = [remotePath encodeString:NSUTF8StringEncoding];
+    if (encode) remotePath = [remotePath encodeString:NSUTF8StringEncoding];
     
     NSURLSessionDownloadTask *downloadTask = [request downloadWithSessionPath:remotePath toPath:localPath defaultPriority:defaultPriority onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
         downloadProgress(progress);

+ 4 - 4
iOSClient/Main/CCDetail.m

@@ -237,7 +237,7 @@
                         
                         self.richDocument = [[NCViewerRichdocument alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
                         [self.view addSubview:self.richDocument];
-                        [self.richDocument viewRichDocumentAt:link detail:self];
+                        [self.richDocument viewRichDocumentAt:link detail:self metadata:self.metadataDetail];
 
                     } else {
                         
@@ -257,7 +257,7 @@
                 
                 self.richDocument = [[NCViewerRichdocument alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
                 [self.view addSubview:self.richDocument];
-                [self.richDocument viewRichDocumentAt:self.metadataDetail.url detail:self];
+                [self.richDocument viewRichDocumentAt:self.metadataDetail.url detail:self metadata:self.metadataDetail];
             }
             
             return;
@@ -982,8 +982,8 @@
     
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
         [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
-    
-    [docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
+    else
+        [docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
 }
 
 - (void)shareButtonPressed:(UIBarButtonItem *)sender

+ 1 - 1
iOSClient/Main/Create cloud/NCCreateFormUploadRichdocuments.swift

@@ -319,7 +319,7 @@ class NCCreateFormUploadRichdocuments: XLFormViewController, NCSelectDelegate, U
         
         let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + template.name + ".png"
 
-        OCNetworking.sharedManager().download(withAccount: appDelegate.activeAccount, url: template.preview, fileNameLocalPath: fileNameLocalPath, completion: { (account, message, errorCode) in
+        OCNetworking.sharedManager().download(withAccount: appDelegate.activeAccount, url: template.preview, fileNameLocalPath: fileNameLocalPath, encode:true, completion: { (account, message, errorCode) in
             
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 self.collectionView.reloadItems(at: [indexPath])

+ 2 - 2
iOSClient/Networking/OCNetworking.h

@@ -42,8 +42,8 @@
 
 #pragma mark ===== Download / Upload =====
 
-- (NSURLSessionTask *)downloadWithAccount:(NSString *)account fileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication completion:(void (^)(NSString *account, int64_t length, NSString *etag, NSDate *date, NSString *message, NSInteger errorCode))completion;
-- (NSURLSessionTask *)downloadWithAccount:(NSString *)account url:(NSString *)url fileNameLocalPath:(NSString *)fileNameLocalPath completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
+- (NSURLSessionTask *)downloadWithAccount:(NSString *)account fileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath encode:(BOOL)encode communication:(OCCommunication *)communication completion:(void (^)(NSString *account, int64_t length, NSString *etag, NSDate *date, NSString *message, NSInteger errorCode))completion;
+- (NSURLSessionTask *)downloadWithAccount:(NSString *)account url:(NSString *)url fileNameLocalPath:(NSString *)fileNameLocalPath encode:(BOOL)encode completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 - (NSURLSessionTask *)uploadWithAccount:(NSString *)account fileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath progress:(void(^)(NSProgress *progress))uploadProgress completion:(void(^)(NSString *account, NSString *fileID, NSString *etag, NSDate *date, NSString *message, NSInteger errorCode))completion;
 
 #pragma mark ===== WebDav =====

+ 4 - 4
iOSClient/Networking/OCNetworking.m

@@ -308,7 +308,7 @@
 #pragma mark ===== download / upload =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (NSURLSessionTask *)downloadWithAccount:(NSString *)account fileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication completion:(void (^)(NSString *account, int64_t length, NSString *etag, NSDate *date, NSString *message, NSInteger errorCode))completion
+- (NSURLSessionTask *)downloadWithAccount:(NSString *)account fileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath encode:(BOOL)encode communication:(OCCommunication *)communication completion:(void (^)(NSString *account, int64_t length, NSString *etag, NSDate *date, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -322,7 +322,7 @@
     [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    NSURLSessionTask *sessionTask = [communication downloadFileSession:fileNameServerUrl toDestiny:fileNameLocalPath defaultPriority:YES onCommunication:communication progress:^(NSProgress *progress) {
+    NSURLSessionTask *sessionTask = [communication downloadFileSession:fileNameServerUrl toDestiny:fileNameLocalPath defaultPriority:YES encode:encode onCommunication:communication progress:^(NSProgress *progress) {
         //float percent = roundf (progress.fractionCompleted * 100);
     } successRequest:^(NSURLResponse *response, NSURL *filePath) {
 
@@ -383,7 +383,7 @@
     return sessionTask;
 }
 
-- (NSURLSessionTask *)downloadWithAccount:(NSString *)account url:(NSString *)url fileNameLocalPath:(NSString *)fileNameLocalPath completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (NSURLSessionTask *)downloadWithAccount:(NSString *)account url:(NSString *)url fileNameLocalPath:(NSString *)fileNameLocalPath encode:(BOOL)encode completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -399,7 +399,7 @@
     [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
     [communication setUserAgent:[CCUtility getUserAgent]];
 
-    NSURLSessionTask *sessionTask = [communication downloadFileSession:url toDestiny:fileNameLocalPath defaultPriority:YES onCommunication:communication progress:^(NSProgress *progress) {
+    NSURLSessionTask *sessionTask = [communication downloadFileSession:url toDestiny:fileNameLocalPath defaultPriority:YES encode:encode onCommunication:communication progress:^(NSProgress *progress) {
         //float percent = roundf (progress.fractionCompleted * 100);
     } successRequest:^(NSURLResponse *response, NSURL *filePath) {
         

+ 33 - 9
iOSClient/Viewer/NCViewerRichdocument.swift

@@ -27,6 +27,8 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var detail: CCDetail!
+    var metadata: tableMetadata!
+    var documentInteractionController: UIDocumentInteractionController!
    
     override init(frame: CGRect, configuration: WKWebViewConfiguration) {
         super.init(frame: frame, configuration: configuration)
@@ -42,9 +44,10 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
         super.init(coder: coder)
     }
     
-    @objc func viewRichDocumentAt(_ link: String, detail: CCDetail) {
+    @objc func viewRichDocumentAt(_ link: String, detail: CCDetail, metadata: tableMetadata) {
         
         self.detail = detail
+        self.metadata = metadata
         
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
@@ -81,7 +84,7 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
         
         if (message.name == "RichDocumentsMobileInterface") {
             
-            if message.body as! String == "close" {
+            if message.body as? String == "close" {
                 
                 removeFromSuperview()
                 
@@ -90,7 +93,7 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
                 self.detail.navigationController?.navigationBar.topItem?.title = ""
             }
             
-            if message.body as! String == "insertGraphic" {
+            if message.body as? String == "insertGraphic" {
                 
                 let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
                 let navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
@@ -108,18 +111,39 @@ class NCViewerRichdocument: WKWebView, WKNavigationDelegate, WKScriptMessageHand
                 self.detail.present(navigationController, animated: true, completion: nil)
             }
             
-            if message.body as! String == "share" {
+            if message.body as? String == "share" {
                 appDelegate.activeMain.openShare(with: self.detail.metadataDetail)
             }
             
-            if message.body as! String == "downloadAs" {
-                
+            if let param = message.body as? Dictionary<AnyHashable,Any> {
+                if param["MessageName"] as? String == "downloadAs" {
+                    if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
+                         if let url = values["URL"] as? String {
+                            guard let filename = values["Type"] as? String else {
+                                return
+                            }
+                            let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + filename + ".pdf"
+                            let account = metadata.account
+                            
+                            _ = OCNetworking.sharedManager()?.download(withAccount: account, url: url, fileNameLocalPath: fileNameLocalPath, encode:false, completion: { (account, message, errorCode) in
+                                if errorCode == 0 && account == self.metadata.account {
+                                    if filename == "print" {
+                                        self.documentInteractionController = UIDocumentInteractionController()
+                                        self.documentInteractionController.url = URL(fileURLWithPath: fileNameLocalPath)
+                                        self.documentInteractionController.presentOptionsMenu(from: self.appDelegate.window.rootViewController!.view.bounds, in: self.appDelegate.window.rootViewController!.view, animated: true)
+                                    }
+                                } else {
+                                    self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                                }
+                            })
+                        }
+                    }
+                }
             }
             
-            if message.body as! String == "documentLoaded" {
-                
+            if message.body as? String == "documentLoaded" {
+                print("documentLoaded")
             }
-            
         }
     }