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/http/httpjsonrequest.h"
28
29#include "common/array.h"
30#include "common/singleton.h"
31#include "common/str-array.h"
32#include "common/events.h"
33
34namespace GUI {
35
36class CommandReceiver;
37
38}
39
40namespace Cloud {
41
42// The actual indexes in CloudManager's array
43enum StorageID {
44 kStorageNoneId = 0,
45 kStorageDropboxId = 1,
46 kStorageOneDriveId = 2,
47 kStorageGoogleDriveId = 3,
48 kStorageBoxId = 4,
49
50 kStorageTotal
51};
52
53class 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
91public:
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
126
132 uint32 getStorageIndex() const;
133
140
146 bool switchStorage(uint32 index);
147
155
162 uint64 getStorageUsedSpace(uint32 index);
163
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
231
237 void disconnectStorage(uint32 index);
238
241
243 Networking::Request *downloadFolder(const Common::String &remotePath, const Common::Path &localPath, Storage::FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
244
247
250
252 bool canSyncFilename(const Common::String &filename) const;
253
255 bool isStorageEnabled() const;
256
259
264
266 bool isWorking() const;
267
269
271 bool isSyncing() const;
272
275
278
280 double getSyncProgress() const;
281
284
286 void cancelSync() const;
287
290
292
294 bool startDownload(const Common::String &remotePath, const Common::Path &localPath) const;
295
297 void cancelDownload() const;
298
301
303 bool isDownloading() const;
304
307
310
313
315 uint64 getDownloadSpeed() const;
316
319
322};
323
325#define CloudMan Cloud::CloudManager::instance()
326
327} // End of namespace Cloud
328
329#endif
Definition: cloudicon.h:29
Definition: cloudmanager.h:53
uint64 getDownloadTotalBytesNumber() const
Common::Path getDownloadLocalDirectory() const
void cancelDownload() const
Common::String getStorageUsername(uint32 index)
bool canSyncFilename(const Common::String &filename) const
void setStorageLastSync(uint32 index, const Common::String &date)
void setDownloadTarget(GUI::CommandReceiver *target) const
bool isWorking() const
bool startDownload(const Common::String &remotePath, const Common::Path &localPath) const
double getSyncDownloadingProgress() const
Common::String savesDirectoryPath()
uint64 getDownloadBytesNumber() const
void connectStorage(uint32 index, Networking::JsonResponse codeFlowJson, Networking::ErrorCallback cb=nullptr)
void getSyncDownloadingInfo(Storage::SyncDownloadingInfo &info) const
bool isDownloading() const
uint64 getStorageUsedSpace(uint32 index)
void cancelSync() const
void setStorageUsername(uint32 index, const Common::String &name)
uint32 getStorageIndex() const
Cloud::Storage * getCurrentStorage() const
Networking::Request * listDirectory(const Common::String &path, Storage::ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive=false)
uint64 getDownloadSpeed() const
void replaceStorage(Storage *storage, uint32 index)
Common::String getStorageLastSync(uint32 index)
Networking::Request * downloadFolder(const Common::String &remotePath, const Common::Path &localPath, Storage::FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive=false)
void disconnectStorage(uint32 index)
bool switchStorage(uint32 index)
double getDownloadingProgress() const
SavesSyncRequest * syncSaves(Cloud::Storage::BoolCallback callback=nullptr, Networking::ErrorCallback errorCallback=nullptr)
bool connectStorage(Networking::JsonResponse codeFlowJson, Networking::ErrorCallback cb=nullptr)
void removeStorage(Storage *storage)
void setStorageUsedSpace(uint32 index, uint64 used)
Common::String getDownloadRemoteDirectory() const
Networking::Request * info(Storage::StorageInfoCallback callback, Networking::ErrorCallback errorCallback)
Common::Array< Common::String > getSyncingFiles() const
bool isStorageEnabled() const
void connectStorage(uint32 index, const Common::String &code, Networking::ErrorCallback cb=nullptr)
void showCloudDisabledIcon()
bool isSyncing() const
double getSyncProgress() const
Common::StringArray listStorages() const
Definition: savessyncrequest.h:32
Definition: storage.h:47
Definition: events.h:278
Definition: path.h:52
Definition: singleton.h:42
Definition: str.h:59
Definition: object.h:33
Definition: request.h:119
Definition: storage.h:189
Definition: events.h:218
Definition: request.h:47