KMCloudServer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // KMCloudServer.h
  3. // PDF Reader
  4. //
  5. // Created by wanjun on 2020/7/16.
  6. // Copyright © 2020 Kdan Mobile. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <AppKit/AppKit.h>
  10. #import "KMServicesCloudFile.h"
  11. #import "GTLRDrive.h"
  12. #define KMBoxName @"Box"
  13. #define KMDropboxName @"Dropbox"
  14. extern NSString *const KMServerCloudFileManagerDownloadStateChangeNotification;
  15. extern NSString *const KMServerCloudFileManagerDownloadSuccessfulNotification;
  16. extern NSString *const KMServerCloudFileManagerDownloadFailureNotification;
  17. extern NSString *const KMServerCloudFileManagerUploadSuccessfulNotification;
  18. extern NSString *const KMServerCloudFileManagerUploadFailureNotification;
  19. typedef enum {
  20. KMNone = 0,
  21. KMDropbox ,
  22. KMGoogleDrive ,
  23. }KMServerType;
  24. typedef void(^CloudLoginCallBack)(id cloudFile, BOOL finished);
  25. typedef void(^CloudLogoutCallBack)(BOOL finished);
  26. typedef void(^CloudDeleteFileCallBack)(KMServicesCloudFile *cloudFile, BOOL finished);
  27. typedef void(^CreateFolderCallBack)(KMServicesCloudFile *cloudFile, BOOL finished);
  28. typedef void(^GetFileListCallBack)(NSArray<KMServicesCloudFile *> *fileList,KMServerType serviceType,NSError *error);
  29. typedef void(^CurrentProgressCallBack)(KMServicesCloudFile *cloudFile,CGFloat loadProgress);
  30. typedef void(^CompletionCallBack)(KMServicesCloudFile *cloudFile,BOOL finished);
  31. @class KMCloudOperation;
  32. @interface KMCloudServer : NSObject
  33. {
  34. NSMutableArray<KMCloudOperation *> *operationArr;
  35. NSMutableArray<KMServicesCloudFile *> *DropboxLocalFileList;
  36. NSMutableArray<KMServicesCloudFile *> *GoogleDriveLocalFileList;
  37. }
  38. @property (nonatomic, strong) NSMutableArray<KMServicesCloudFile *> *DropboxLocalFileList; //获取当前的文件列表
  39. @property (nonatomic, strong) NSMutableArray<KMServicesCloudFile *> *GoogleDriveLocalFileList; //获取当前的文件列表
  40. @property (nonatomic, strong) NSMutableArray<KMCloudOperation *> *operationArr;
  41. @property (nonatomic, readonly) KMServicesCloudFile *localRootFolder;//获取本读根文件夹
  42. @property (nonatomic, assign) KMServerType serverType;
  43. @property (nonatomic, assign) NSInteger index;
  44. @property (nonatomic, copy) NSString *accountId;
  45. @property (nonatomic, copy) NSString *userEmail;
  46. /**
  47. Retrieve all logged-in cloud services objects
  48. @return Return an array fo KMServerType objects
  49. */
  50. + (NSArray <KMCloudServer *>*)getAllLoginServer;
  51. + (BOOL)networkConnectionStatus;
  52. + (BOOL)isConnectionAvailable;
  53. /**
  54. First run time Settings Server type.
  55. @param type Server type.
  56. */
  57. - (id) initCloudWithServerType:(KMServerType)type;
  58. /** Cloud Whether to login. */
  59. - (BOOL)isSignedIn;
  60. /** Cloud auth/login. */
  61. - (void) authorizedLoginCompletion:(CloudLoginCallBack)completion;
  62. /** Cloud logout. */
  63. - (void) authorizedLogoutCompletion:(CloudLogoutCallBack)completion;
  64. /**
  65. Upload local content to Cloud cloud disk space.
  66. @param cloudPath Cloud cloud disk space.
  67. @param localPath local file path url.
  68. @return upload operation.
  69. */
  70. - (KMCloudOperation *)uploadCloudPath:(KMServicesCloudFile *)cloudPath
  71. localPath:(NSURL *)localPath
  72. currentConvetProgress:(CurrentProgressCallBack)currentProgress
  73. completion:(CompletionCallBack)completion;
  74. /**
  75. Cloud cancel upload operation.
  76. @param operation upload operation
  77. */
  78. - (void) uploadCancel:(KMCloudOperation *)operation;
  79. /**
  80. Download files from Cloud cloud disk to local space.
  81. @param cloudPath Cloud cloud disk space.
  82. @param localPath local space path url.
  83. @return download operation.
  84. */
  85. - (KMCloudOperation *)downloadCloudPath:(KMServicesCloudFile *)cloudPath
  86. localPath:(NSURL *)localPath
  87. currentConvetProgress:(CurrentProgressCallBack)currentProgress
  88. completion:(CompletionCallBack)completion;
  89. /**
  90. Cloud cancel download operation.
  91. @param operation download operation
  92. */
  93. - (void) downloadCancel:(KMCloudOperation *)operation;
  94. /**
  95. Delete Cloud file based on file object.
  96. @param fileData Cloud file metadata
  97. */
  98. -(void) deleteFileWithPath:(KMServicesCloudFile *)fileData
  99. completion:(CloudDeleteFileCallBack)completion;
  100. /**
  101. Create Cloud folder based on file object.
  102. @param fileData Cloud file metadata.
  103. @param folderName Created folder name.
  104. */
  105. -(void) createFolderWithPath:(KMServicesCloudFile * )fileData
  106. folderName:(NSString *)folderName
  107. completion:(CreateFolderCallBack)completion;
  108. /**
  109. Get Cloud file list based on file object.
  110. @param fileData Cloud file metadata. Root folder is 'localRootFolder'
  111. @param responseBlock succeed block
  112. */
  113. - (void)getListWithFilePath:(KMServicesCloudFile *)fileData
  114. setResponseBlock:(GetFileListCallBack)responseBlock;
  115. - (NSArray<KMCloudOperation *> *) operations;
  116. - (KMServicesCloudFile *)cloudFolderCacheForDisPath:(NSString *)path;
  117. - (KMServicesCloudFile *)getUpperPathCloudFolder:(KMServicesCloudFile *)file;
  118. @end
  119. @interface KMCloudServer (Additions)
  120. + (BOOL)networkConnectionStatusOnceAlertWhileNetworkNotReachable;
  121. + (BOOL)networkConnectionStatusForAdjectiveFunctionAlertWhileNetworkNotReachable;
  122. @end