ScummVM API documentation
cloudmanager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef CLOUD_CLOUDMANAGER_H
23 #define CLOUD_CLOUDMANAGER_H
24 
25 #include "backends/cloud/storage.h"
26 #include "backends/cloud/cloudicon.h"
27 #include "backends/networking/curl/curljsonrequest.h"
28 
29 #include "common/array.h"
30 #include "common/singleton.h"
31 #include "common/str-array.h"
32 #include "common/events.h"
33 
34 namespace GUI {
35 
36 class CommandReceiver;
37 
38 }
39 
40 namespace Cloud {
41 
42 // The actual indexes in CloudManager's array
43 enum StorageID {
44  kStorageNoneId = 0,
45  kStorageDropboxId = 1,
46  kStorageOneDriveId = 2,
47  kStorageGoogleDriveId = 3,
48  kStorageBoxId = 4,
49 
50  kStorageTotal
51 };
52 
53 class CloudManager : public Common::Singleton<CloudManager>, public Common::EventSource {
54  static const char *const kStoragePrefix;
55 
56  struct StorageConfig {
57  Common::String name, username;
58  uint64 usedBytes;
59  Common::String lastSyncDate;
60  };
61 
63  uint _currentStorageIndex;
64  Storage *_activeStorage;
65  Common::Array<Storage *> _storagesToRemove;
66 
67  CloudIcon _icon;
68 
69  void loadStorage();
70 
71  Common::String getStorageConfigName(uint32 index) const;
72 
74  void freeStorages();
75 
77  void passNoStorageConnected(Networking::ErrorCallback errorCallback) const;
78 
89  bool pollEvent(Common::Event &event) override;
90 
91 public:
92  CloudManager();
93  ~CloudManager() override;
94 
100  void init();
101 
105  void save();
106 
114  void replaceStorage(Storage *storage, uint32 index);
115 
117  void removeStorage(Storage *storage);
118 
125  Cloud::Storage *getCurrentStorage() const;
126 
132  uint32 getStorageIndex() const;
133 
139  Common::StringArray listStorages() const;
140 
146  bool switchStorage(uint32 index);
147 
154  Common::String getStorageUsername(uint32 index);
155 
162  uint64 getStorageUsedSpace(uint32 index);
163 
172  Common::String getStorageLastSync(uint32 index);
173 
181  void setStorageUsername(uint32 index, const Common::String &name);
182 
190  void setStorageUsedSpace(uint32 index, uint64 used);
191 
199  void setStorageLastSync(uint32 index, const Common::String &date);
200 
209  void connectStorage(uint32 index, const Common::String &code, Networking::ErrorCallback cb = nullptr);
210 
219  void connectStorage(uint32 index, Networking::JsonResponse codeFlowJson, Networking::ErrorCallback cb = nullptr);
220 
230  bool connectStorage(Networking::JsonResponse codeFlowJson, Networking::ErrorCallback cb = nullptr);
231 
237  void disconnectStorage(uint32 index);
238 
240  Networking::Request *listDirectory(const Common::String &path, Storage::ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
241 
243  Networking::Request *downloadFolder(const Common::String &remotePath, const Common::Path &localPath, Storage::FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
244 
247 
249  Common::String savesDirectoryPath();
250 
252  bool canSyncFilename(const Common::String &filename) const;
253 
255  bool isStorageEnabled() const;
256 
258  void enableStorage();
259 
263  SavesSyncRequest *syncSaves(Cloud::Storage::BoolCallback callback = nullptr, Networking::ErrorCallback errorCallback = nullptr);
264 
266  bool isWorking() const;
267 
269 
271  bool isSyncing() const;
272 
274  double getSyncDownloadingProgress() const;
275 
277  void getSyncDownloadingInfo(Storage::SyncDownloadingInfo &info) const;
278 
280  double getSyncProgress() const;
281 
283  Common::Array<Common::String> getSyncingFiles() const;
284 
286  void cancelSync() const;
287 
289  void showCloudDisabledIcon();
290 
292 
294  bool startDownload(const Common::String &remotePath, const Common::Path &localPath) const;
295 
297  void cancelDownload() const;
298 
300  void setDownloadTarget(GUI::CommandReceiver *target) const;
301 
303  bool isDownloading() const;
304 
306  double getDownloadingProgress() const;
307 
309  uint64 getDownloadBytesNumber() const;
310 
312  uint64 getDownloadTotalBytesNumber() const;
313 
315  uint64 getDownloadSpeed() const;
316 
318  Common::String getDownloadRemoteDirectory() const;
319 
321  Common::Path getDownloadLocalDirectory() const;
322 };
323 
325 #define CloudMan Cloud::CloudManager::instance()
326 
327 } // End of namespace Cloud
328 
329 #endif
Definition: str.h:59
Definition: basestorage.h:28
Definition: cloudmanager.h:53
Definition: storage.h:47
Definition: cloudicon.h:29
Definition: path.h:52
Definition: request.h:47
Definition: system.h:46
Definition: events.h:199
Definition: callback.h:49
Definition: storage.h:189
Definition: object.h:33
Definition: savessyncrequest.h:32
Definition: events.h:259
Definition: singleton.h:42
Definition: request.h:119