1 #ifndef SEAFILE_CLIENT_FILE_BROWSER_DATA_MANAGER_H 2 #define SEAFILE_CLIENT_FILE_BROWSER_DATA_MANAGER_H 3 4 #include <QObject> 5 #include <QHash> 6 #include <QScopedPointer> 7 #include <utility> 8 9 #include "api/api-error.h" 10 #include "account.h" 11 #include "seaf-dirent.h" 12 #include "utils/singleton.h" 13 14 15 template<typename Key> class QList; 16 17 class SeafileApiRequest; 18 class GetDirentsRequest; 19 class GetRepoRequest; 20 class CreateSubrepoRequest; 21 class DirentsCache; 22 class FileCache; 23 class FileCache; 24 class FileNetworkTask; 25 class FileUploadTask; 26 class FileDownloadTask; 27 class QueryAsyncOperationProgress; 28 class AsyncCopyAndMoveOneItemRequest; 29 30 /** 31 * DataManager is responsible for getting dirents/files from seahub, as well 32 * as the caching policy. 33 * 34 */ 35 class DataManager : public QObject { 36 SINGLETON_DEFINE(DataManager) 37 Q_OBJECT 38 39 public: 40 DataManager(); 41 ~DataManager(); 42 43 void start(); 44 account()45 const Account& account() const { return account_; } 46 47 bool getDirents(const QString& repo_id, 48 const QString& path, 49 QList<SeafDirent> *dirents, 50 bool *current_readonly); 51 52 void getDirentsFromServer(const QString& repo_id, 53 const QString& path); 54 55 void createDirectory(const QString &repo_id, 56 const QString &path); 57 58 void renameDirent(const QString &repo_id, 59 const QString &path, 60 const QString &new_path, 61 bool is_file); 62 63 void lockFile(const QString &repo_id, 64 const QString &path, 65 bool lock); 66 67 void removeDirent(const QString &repo_id, 68 const QString &path, 69 bool is_file); 70 71 void removeDirents(const QString &repo_id, 72 const QString &parent_path, 73 const QStringList &filenames); 74 75 void shareDirent(const QString &repo_id, 76 const QString &path, 77 bool is_file); 78 79 void copyDirents(const QString &repo_id, 80 const QString &dir_path, 81 const QMap<QString, int> &dict_file_names, 82 const QString &dst_repo_id, 83 const QString &dst_dir_path); 84 85 void moveDirents(const QString &repo_id, 86 const QString &dir_path, 87 const QMap<QString, int> &dict_file_names, 88 const QString &dst_repo_id, 89 const QString &dst_dir_path); 90 91 QString getLocalCachedFile(const QString& repo_id, 92 const QString& path, 93 const QString& file_id); 94 95 FileDownloadTask* createDownloadTask(const QString& repo_id, 96 const QString& path); 97 98 FileDownloadTask* createSaveAsTask(const QString& repo_id, 99 const QString& path, 100 const QString& local_path); 101 102 FileUploadTask* createUploadTask(const QString& repo_id, 103 const QString& parent_dir, 104 const QString& local_path, 105 const QString& name, 106 const bool overwrite); 107 108 FileUploadTask* createUploadMultipleTask(const QString& repo_id, 109 const QString& parent_dir, 110 const QString& local_path, 111 const QStringList& names, 112 const bool overwrite); 113 114 bool isRepoPasswordSet(const QString& repo_id) const; repoPassword(const QString & repo_id)115 QString repoPassword(const QString& repo_id) const { 116 if (!isRepoPasswordSet(repo_id)) 117 return QString(); 118 return passwords_cache_[repo_id].second; 119 } 120 void setRepoPasswordSet(const QString& repo_id, const QString& password); 121 122 QString getRepoCacheFolder(const QString& repo_id) const; 123 124 static QString getLocalCacheFilePath(const QString& repo_id, 125 const QString& path); 126 127 void createSubrepo(const QString &name, const QString& repo_id, const QString &path); 128 129 signals: 130 void aboutToDestroy(); 131 132 void getDirentsSuccess(bool current_readonly, const QList<SeafDirent>& dirents, const QString& repo_id); 133 void getDirentsFailed(const ApiError& error, const QString& repo_id); 134 135 void createDirectorySuccess(const QString& path, const QString& repo_id); 136 void createDirectoryFailed(const ApiError& error); 137 138 void lockFileSuccess(const QString& path, bool lock, const QString& repo_id); 139 void lockFileFailed(const ApiError& error); 140 141 void renameDirentSuccess(const QString& path, const QString& new_name, const QString& repo_id); 142 void renameDirentFailed(const ApiError& error); 143 144 void removeDirentSuccess(const QString& path, const QString& repo_id); 145 void removeDirentFailed(const ApiError& error); 146 147 void removeDirentsSuccess(const QString& parent_path, const QStringList& filenames, const QString& repo_id); 148 void removeDirentsFailed(const ApiError& error); 149 150 void shareDirentSuccess(const QString& link, const QString& repo_id); 151 void shareDirentFailed(const ApiError& error); 152 153 void copyDirentsSuccess(const QString& dst_repo_id); 154 void copyDirentsFailed(const ApiError& error); 155 156 void moveDirentsSuccess(const QString& dst_repo_id); 157 void moveDirentsFailed(const ApiError& error); 158 159 void createSubrepoSuccess(const ServerRepo &repo, const QString& repo_id); 160 void createSubrepoFailed(const ApiError& error); 161 162 private slots: 163 void onGetDirentsSuccess(bool current_readonly, const QList<SeafDirent>& dirents, const QString& repo_id); 164 void onFileUploadFinished(bool success); 165 void onFileDownloadFinished(bool success); 166 167 void onCreateDirectorySuccess(const QString& repo_id); 168 void onLockFileSuccess(const QString& repo_id); 169 void onRenameDirentSuccess(const QString& repo_id); 170 void onRemoveDirentSuccess(const QString& repo_id); 171 void onRemoveDirentsSuccess(const QString& repo_id); 172 void onCopyDirentsSuccess(const QString& dst_repo_id); 173 void onMoveDirentsSuccess(const QString& dst_repo_id); 174 175 void onCreateSubrepoSuccess(const QString& new_repoid); 176 void onCreateSubrepoRefreshSuccess(const ServerRepo& new_repo); 177 178 void onAccountChanged(); 179 180 public slots: 181 // async copy operation 182 void slotAsyncCopyMutipleItemsSuccess(const QString& task_id); 183 void slotAsyncCopyMutipleItemsFailed(const ApiError& error); 184 void asyncCopyOneItemApi(); 185 void slotAsyncCopyOneItemSuccess(const QString& task_id); 186 void slotAsyncCopyOneItemFailed(const ApiError& error); 187 void slotQueryAsyncCopyOperaProgress(); 188 void slotQueryAsyncCopyOperationProgressSuccess(); 189 void slotQueryAsyncCopyOperationProgressFailed(const ApiError& error); 190 191 // async move operations 192 void slotAsyncMoveMutipleItemsSuccess(const QString& task_id); 193 void slotAsyncMoveMutipleItemsFailed(const ApiError& error); 194 void asyncMoveOneItemApi(); 195 void slotAsyncMoveOneItemSuccess(const QString& task_id); 196 void slotAsyncMoveOneItemFailed(const ApiError& error); 197 void slotQueryAsyncMoveOperaProgress(); 198 void slotQueryAsyncMoveOperationProgressSuccess(); 199 void slotQueryAsyncMoveOperationProgressFailed(const ApiError& error); 200 201 private: 202 void removeDirentsCache(const QString& repo_id, 203 const QString& path, 204 bool is_file); 205 void setupTaskCleanup(FileNetworkTask *task); 206 Account account_; 207 208 QScopedPointer<CreateSubrepoRequest, QScopedPointerDeleteLater> create_subrepo_req_; 209 QString create_subrepo_parent_repo_id_; 210 QString create_subrepo_parent_path_; 211 QScopedPointer<GetRepoRequest, QScopedPointerDeleteLater> get_repo_req_; 212 213 QList<SeafileApiRequest*> reqs_; 214 215 FileCache *filecache_; 216 217 DirentsCache *dirents_cache_; 218 QString old_repo_id_; 219 220 // copy and move struct 221 QMap<QString, int> src_dirents_; 222 QString repo_id_; 223 QString dir_path_; 224 QString dst_repo_id_; 225 QString dst_dir_path_; 226 bool is_batch_operation_; 227 QString task_id_; 228 229 static QHash<QString, std::pair<qint64, QString> > passwords_cache_; 230 QTimer* query_async_opera_progress_timer_; 231 QScopedPointer<AsyncCopyAndMoveOneItemRequest, QScopedPointerDeleteLater> async_copy_one_item_req_; 232 bool copy_move_in_progress_; 233 }; 234 235 236 #endif // SEAFILE_CLIENT_FILE_BROWSER_DATA_MANAGER_H 237