aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/cloud/cloudmanager.cpp10
-rw-r--r--backends/cloud/cloudmanager.h99
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp80
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h12
-rw-r--r--backends/cloud/googledrive/googledrivestorage.h10
-rw-r--r--backends/cloud/onedrive/onedrivestorage.h8
-rw-r--r--gui/storagewizarddialog.cpp20
-rw-r--r--gui/storagewizarddialog.h2
-rw-r--r--gui/themes/scummmodern/scummmodern_layout.stx4
-rw-r--r--gui/themes/scummmodern/scummmodern_layout_lowres.stx4
10 files changed, 124 insertions, 125 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index fed35a9f38..adfebdca88 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -195,6 +195,16 @@ void CloudManager::setStorageLastSync(uint32 index, Common::String date) {
save();
}
+void CloudManager::connectStorage(uint32 index, Common::String code) {
+ Storage *storage = nullptr;
+ switch (index) {
+ case kStorageDropboxId: storage = new Dropbox::DropboxStorage(code); break;
+ case kStorageOneDriveId: storage = new OneDrive::OneDriveStorage(code); break;
+ case kStorageGoogleDriveId: storage = new GoogleDrive::GoogleDriveStorage(code); break;
+ }
+ //these would automatically request replaceStorage() when they receive the token
+}
+
void CloudManager::printBool(Storage::BoolResponse response) const {
debug("bool = %s", (response.value ? "true" : "false"));
}
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index fd130c5ee8..9f4882d772 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -97,79 +97,88 @@ public:
Cloud::Storage *getCurrentStorage() const;
/**
- * Return active Storage's index.
- *
- * @return active Storage's index.
- */
+ * Return active Storage's index.
+ *
+ * @return active Storage's index.
+ */
uint32 getStorageIndex() const;
/**
- * Return Storages names as list.
- *
- * @return a list of Storages names.
- */
+ * Return Storages names as list.
+ *
+ * @return a list of Storages names.
+ */
Common::StringArray listStorages() const;
/**
- * Changes the storage to the one with given index.
- *
- * @param new Storage's index.
- */
+ * Changes the storage to the one with given index.
+ *
+ * @param new Storage's index.
+ */
bool switchStorage(uint32 index);
/**
- * Return username used by Storage.
- *
- * @param Storage's index.
- * @returns username or "" if index is invalid (no such Storage).
- */
+ * Return username used by Storage.
+ *
+ * @param Storage's index.
+ * @returns username or "" if index is invalid (no such Storage).
+ */
Common::String getStorageUsername(uint32 index);
/**
- * Return space used by Storage.
- *
- * @param Storage's index.
- * @returns used space in bytes or 0 if index is invalid (no such Storage).
- */
+ * Return space used by Storage.
+ *
+ * @param Storage's index.
+ * @returns used space in bytes or 0 if index is invalid (no such Storage).
+ */
uint64 getStorageUsedSpace(uint32 index);
/**
- * Return Storage's last sync date.
- *
- * @param Storage's index.
- * @returns last sync date or "" if index is invalid (no such Storage).
+ * Return Storage's last sync date.
+ *
+ * @param Storage's index.
+ * @returns last sync date or "" if index is invalid (no such Storage).
It also returns "" if there never was any sync
or if storage is syncing right now.
- */
+ */
Common::String getStorageLastSync(uint32 index);
/**
- * Set Storage's username.
- * Automatically saves changes to the config.
- *
- * @param index Storage's index.
- * @param name username to set
- */
+ * Set Storage's username.
+ * Automatically saves changes to the config.
+ *
+ * @param index Storage's index.
+ * @param name username to set
+ */
void setStorageUsername(uint32 index, Common::String name);
/**
- * Set Storage's used space field.
- * Automatically saves changes to the config.
- *
- * @param index Storage's index.
- * @param used value to set
- */
+ * Set Storage's used space field.
+ * Automatically saves changes to the config.
+ *
+ * @param index Storage's index.
+ * @param used value to set
+ */
void setStorageUsedSpace(uint32 index, uint64 used);
/**
- * Set Storage's last sync date.
- * Automatically saves changes to the config.
- *
- * @param index Storage's index.
- * @param date date to set
- */
+ * Set Storage's last sync date.
+ * Automatically saves changes to the config.
+ *
+ * @param index Storage's index.
+ * @param date date to set
+ */
void setStorageLastSync(uint32 index, Common::String date);
+ /**
+ * Replace Storage which has given index with a
+ * storage created with given code.
+ *
+ * @param index Storage's index
+ * @param code OAuth2 code received from user
+ */
+ void connectStorage(uint32 index, Common::String code);
+
/** Returns ListDirectoryResponse with list of files. */
Networking::Request *listDirectory(Common::String path, Storage::ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index faff10f1d9..180b40c3d5 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -51,41 +51,47 @@ void DropboxStorage::loadKeyAndSecret() {
SECRET[k.size()] = 0;
}
-static void saveAccessTokenCallback(Networking::JsonResponse pair) {
- Common::JSONValue *json = (Common::JSONValue *)pair.value;
- if (json) {
- debug("saveAccessTokenCallback:");
- debug("%s", json->stringify(true).c_str());
+DropboxStorage::DropboxStorage(Common::String accessToken, Common::String userId): _token(accessToken), _uid(userId) {}
+
+DropboxStorage::DropboxStorage(Common::String code) {
+ getAccessToken(code);
+}
+
+DropboxStorage::~DropboxStorage() {}
+
+void DropboxStorage::getAccessToken(Common::String code) {
+ Networking::JsonCallback callback = new Common::Callback<DropboxStorage, Networking::JsonResponse>(this, &DropboxStorage::codeFlowComplete);
+ Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, nullptr, "https://api.dropboxapi.com/1/oauth2/token");
+ request->addPostField("code=" + code);
+ request->addPostField("grant_type=authorization_code");
+ request->addPostField("client_id=" + Common::String(KEY));
+ request->addPostField("client_secret=" + Common::String(SECRET));
+ request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F");
+ addRequest(request);
+}
+void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) {
+ Common::JSONValue *json = (Common::JSONValue *)response.value;
+ if (json) {
Common::JSONObject result = json->asObject();
if (!result.contains("access_token") || !result.contains("uid")) {
warning("Bad response, no token/uid passed");
} else {
- //we suppose that's the first storage
- //TODO: update it to use CloudMan.replaceStorage()
- ConfMan.set("current_storage", "1", "cloud");
- ConfMan.set("storage_Dropbox_type", "Dropbox", "cloud");
- ConfMan.set("storage_Dropbox_access_token", result.getVal("access_token")->asString(), "cloud");
- ConfMan.set("storage_Dropbox_user_id", result.getVal("uid")->asString(), "cloud");
+ _token = result.getVal("access_token")->asString();
+ _uid = result.getVal("user_id")->asString();
ConfMan.removeKey("dropbox_code", "cloud");
+ CloudMan.replaceStorage(this, kStorageDropboxId);
ConfMan.flushToDisk();
- debug("Now please restart ScummVM to apply the changes.");
+ debug("Done! You can use Dropbox now! Look:");
+ CloudMan.testFeature();
}
delete json;
} else {
- debug("saveAccessTokenCallback: got NULL instead of JSON!");
+ debug("DropboxStorage::codeFlowComplete: got NULL instead of JSON!");
}
}
-DropboxStorage::DropboxStorage(Common::String accessToken, Common::String userId): _token(accessToken), _uid(userId) {
- curl_global_init(CURL_GLOBAL_ALL);
-}
-
-DropboxStorage::~DropboxStorage() {
- curl_global_cleanup();
-}
-
void DropboxStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "access_token", _token, "cloud");
ConfMan.set(keyPrefix + "user_id", _uid, "cloud");
@@ -216,37 +222,5 @@ Common::String DropboxStorage::getAuthLink() {
return url;
}
-void DropboxStorage::authThroughConsole() {
- if (!ConfMan.hasKey("DROPBOX_KEY", "cloud") || !ConfMan.hasKey("DROPBOX_SECRET", "cloud")) {
- warning("No Dropbox keys available, cannot do auth");
- return;
- }
-
- loadKeyAndSecret();
-
- if (ConfMan.hasKey("dropbox_code", "cloud")) {
- //phase 2: get access_token using specified code
- getAccessToken(ConfMan.get("dropbox_code", "cloud"));
- return;
- }
-
- debug("Navigate to this URL and press \"Allow\":");
- debug("%s\n", getAuthLink().c_str());
- debug("Then, add dropbox_code key in [cloud] section of configuration file. You should copy the <code> value from URL and put it as value for that key.\n");
- debug("Navigate to this URL to get more information on ScummVM's configuration files:");
- debug("http://wiki.scummvm.org/index.php/User_Manual/Configuring_ScummVM#Using_the_configuration_file_to_configure_ScummVM\n");
-}
-
-void DropboxStorage::getAccessToken(Common::String code) {
- Networking::JsonCallback callback = new Common::GlobalFunctionCallback<Networking::JsonResponse>(saveAccessTokenCallback);
- Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, nullptr, "https://api.dropboxapi.com/1/oauth2/token"); //TODO
- request->addPostField("code=" + code);
- request->addPostField("grant_type=authorization_code");
- request->addPostField("client_id=" + Common::String(KEY));
- request->addPostField("client_secret=" + Common::String(SECRET));
- request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F");
- ConnMan.addRequest(request);
-}
-
} // End of namespace Dropbox
} // End of namespace Cloud
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index 60a8075201..d256e0562b 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -40,7 +40,8 @@ class DropboxStorage: public Cloud::Storage {
/** This private constructor is called from loadFromConfig(). */
DropboxStorage(Common::String token, Common::String uid);
- static void getAccessToken(Common::String code);
+ void getAccessToken(Common::String code);
+ void codeFlowComplete(Networking::JsonResponse response);
/** Constructs StorageInfo based on JSON response from cloud. */
void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json);
@@ -49,7 +50,9 @@ class DropboxStorage: public Cloud::Storage {
void printBool(BoolResponse response);
void printStorageFile(UploadResponse response);
-public:
+public:
+ /** This constructor uses OAuth code flow to get tokens. */
+ DropboxStorage(Common::String code);
virtual ~DropboxStorage();
/**
@@ -107,11 +110,6 @@ public:
* Returns Dropbox auth link.
*/
static Common::String getAuthLink();
-
- /**
- * Show message with Dropbox auth instructions. (Temporary)
- */
- static void authThroughConsole();
};
} // End of namespace Dropbox
diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h
index 489260db09..8093ef1938 100644
--- a/backends/cloud/googledrive/googledrivestorage.h
+++ b/backends/cloud/googledrive/googledrivestorage.h
@@ -40,12 +40,6 @@ class GoogleDriveStorage: public Cloud::Storage {
/** This private constructor is called from loadFromConfig(). */
GoogleDriveStorage(Common::String token, Common::String refreshToken);
- /**
- * This private constructor is called from authThroughConsole() (phase 2).
- * It uses OAuth code flow to get tokens.
- */
- GoogleDriveStorage(Common::String code);
-
void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response);
void codeFlowComplete(BoolResponse response);
@@ -61,7 +55,9 @@ class GoogleDriveStorage: public Cloud::Storage {
void printBool(BoolResponse response);
void printFile(UploadResponse response);
void printInfo(StorageInfoResponse response);
-public:
+public:
+ /** This constructor uses OAuth code flow to get tokens. */
+ GoogleDriveStorage(Common::String code);
virtual ~GoogleDriveStorage();
/**
diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h
index 3932d44aae..061d0fa172 100644
--- a/backends/cloud/onedrive/onedrivestorage.h
+++ b/backends/cloud/onedrive/onedrivestorage.h
@@ -40,12 +40,6 @@ class OneDriveStorage: public Cloud::Storage {
/** This private constructor is called from loadFromConfig(). */
OneDriveStorage(Common::String token, Common::String uid, Common::String refreshToken);
- /**
- * This private constructor is called from authThroughConsole() (phase 2).
- * It uses OAuth code flow to get tokens.
- */
- OneDriveStorage(Common::String code);
-
void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response);
void codeFlowComplete(BoolResponse response);
@@ -60,6 +54,8 @@ class OneDriveStorage: public Cloud::Storage {
void fileInfoCallback(Networking::NetworkReadStreamCallback outerCallback, Networking::JsonResponse response);
public:
+ /** This constructor uses OAuth code flow to get tokens. */
+ OneDriveStorage(Common::String code);
virtual ~OneDriveStorage();
/**
diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp
index 996365da03..d637440fc8 100644
--- a/gui/storagewizarddialog.cpp
+++ b/gui/storagewizarddialog.cpp
@@ -27,11 +27,13 @@
#include "common/translation.h"
#include "backends/cloud/cloudmanager.h"
+#include "widgets/edittext.h"
namespace GUI {
enum {
- kConnectCmd = 'Cnnt'
+ kConnectCmd = 'Cnnt',
+ kCodeBoxCmd = 'CdBx'
};
StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId) {
@@ -42,17 +44,18 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOption
new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.NavigateLine", _s("Navigate to the following URL:"));
- Common::String url = "https://www.scummvm.org/cloud-";
+ Common::String url = "https://www.scummvm.org/c/";
switch (storageId) {
- case Cloud::kStorageDropboxId: url += "dropbox"; break;
- case Cloud::kStorageOneDriveId: url += "onedrive"; break;
- case Cloud::kStorageGoogleDriveId: url += "googledrive"; break;
+ case Cloud::kStorageDropboxId: url += "db"; break;
+ case Cloud::kStorageOneDriveId: url += "od"; break;
+ case Cloud::kStorageGoogleDriveId: url += "gd"; break;
}
new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", url);
- new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Press 'Continue' when you obtain"));
- new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("the code from the storage."));
+ new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it"));
+ new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':"));
+ _codeWidget = new EditTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CodeBox", _s("Code"), 0, kCodeBoxCmd);
// Buttons
new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd);
@@ -61,7 +64,10 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOption
void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
+ case kCodeBoxCmd:
+ break;
case kConnectCmd:
+ CloudMan.connectStorage(_storageId, _codeWidget->getEditString());
setResult(1);
close();
break;
diff --git a/gui/storagewizarddialog.h b/gui/storagewizarddialog.h
index ec5329b8af..00a36172fe 100644
--- a/gui/storagewizarddialog.h
+++ b/gui/storagewizarddialog.h
@@ -29,9 +29,11 @@
namespace GUI {
class CommandSender;
+class EditTextWidget;
class StorageWizardDialog : public Dialog {
uint32 _storageId;
+ EditTextWidget *_codeWidget;
public:
StorageWizardDialog(uint32 storageId);
diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx
index 824c6fa790..cd76856c8b 100644
--- a/gui/themes/scummmodern/scummmodern_layout.stx
+++ b/gui/themes/scummmodern/scummmodern_layout.stx
@@ -607,6 +607,10 @@
<widget name = 'ReturnLine2'
height = 'Globals.Line.Height'
/>
+ <widget name = 'CodeBox'
+ width = '150'
+ height = 'Globals.Line.Height'
+ />
<space size = '6' />
</layout>
</layout>
diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx
index 3d2c3b49a7..dd6700ed2e 100644
--- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx
+++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx
@@ -600,6 +600,10 @@
<widget name = 'ReturnLine2'
height = 'Globals.Line.Height'
/>
+ <widget name = 'CodeBox'
+ width = '150'
+ height = '16'
+ />
<space size = '4' />
</layout>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>