aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2019-07-14 04:42:40 +0700
committerMatan Bareket2019-07-30 14:51:41 -0400
commitddcfcc18b2b4fc17e2217014ad069dc95fbf4fa1 (patch)
tree87a6313ba9dc199d239a9dc8e6ea44669533fb19
parent1bebaf96f7ba1b11417fb16b69b7baebb711ae42 (diff)
downloadscummvm-rg350-ddcfcc18b2b4fc17e2217014ad069dc95fbf4fa1.tar.gz
scummvm-rg350-ddcfcc18b2b4fc17e2217014ad069dc95fbf4fa1.tar.bz2
scummvm-rg350-ddcfcc18b2b4fc17e2217014ad069dc95fbf4fa1.zip
CLOUD: Update DropboxStorage to work via scummvm.org & StorageWizardDialog correspondingly
-rw-r--r--backends/cloud/cloudmanager.cpp8
-rw-r--r--backends/cloud/cloudmanager.h3
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp40
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h4
-rw-r--r--backends/cloud/googledrive/googledrivestorage.cpp6
-rw-r--r--backends/cloud/onedrive/onedrivestorage.cpp6
-rw-r--r--gui/storagewizarddialog.cpp55
7 files changed, 35 insertions, 87 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index 5519e4baab..20c279323c 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -336,14 +336,6 @@ bool CloudManager::isWorking() const {
return false;
}
-bool CloudManager::couldUseLocalServer() {
-#ifdef USE_SDL_NET
- return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT;
-#else
- return false;
-#endif
-}
-
///// SavesSyncRequest-related /////
bool CloudManager::isSyncing() const {
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index f58ea8373a..eb882a63af 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -227,9 +227,6 @@ public:
/** Returns whether there are any requests running. */
bool isWorking() const;
- /** Returns whether LocalWebserver is available to use for auth. */
- static bool couldUseLocalServer();
-
///// SavesSyncRequest-related /////
/** Returns whether there is a SavesSyncRequest running. */
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index b856c6cb2c..bf964ae51b 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -42,29 +42,9 @@
namespace Cloud {
namespace Dropbox {
-#define DROPBOX_OAUTH2_TOKEN "https://api.dropboxapi.com/oauth2/token"
+#define DROPBOX_OAUTH2_TOKEN "https://scummvm.org/admin/cloud/cloud/dropbox/token/"
#define DROPBOX_API_FILES_DOWNLOAD "https://content.dropboxapi.com/2/files/download"
-char *DropboxStorage::KEY = nullptr; //can't use CloudConfig there yet, loading it on instance creation/auth
-char *DropboxStorage::SECRET = nullptr;
-
-void DropboxStorage::loadKeyAndSecret() {
-#ifdef ENABLE_RELEASE
- KEY = RELEASE_DROPBOX_KEY;
- SECRET = RELEASE_DROPBOX_SECRET;
-#else
- Common::String k = ConfMan.get("DROPBOX_KEY", ConfMan.kCloudDomain);
- KEY = new char[k.size() + 1];
- memcpy(KEY, k.c_str(), k.size());
- KEY[k.size()] = 0;
-
- k = ConfMan.get("DROPBOX_SECRET", ConfMan.kCloudDomain);
- SECRET = new char[k.size() + 1];
- memcpy(SECRET, k.c_str(), k.size());
- SECRET[k.size()] = 0;
-#endif
-}
-
DropboxStorage::DropboxStorage(Common::String accessToken, Common::String userId): _token(accessToken), _uid(userId) {}
DropboxStorage::DropboxStorage(Common::String code) {
@@ -74,20 +54,12 @@ DropboxStorage::DropboxStorage(Common::String code) {
DropboxStorage::~DropboxStorage() {}
void DropboxStorage::getAccessToken(Common::String code) {
- if (!KEY || !SECRET)
- loadKeyAndSecret();
Networking::JsonCallback callback = new Common::Callback<DropboxStorage, Networking::JsonResponse>(this, &DropboxStorage::codeFlowComplete);
Networking::ErrorCallback errorCallback = new Common::Callback<DropboxStorage, Networking::ErrorResponse>(this, &DropboxStorage::codeFlowFailed);
- Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, errorCallback, DROPBOX_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));
- if (Cloud::CloudManager::couldUseLocalServer()) {
- request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F");
- } else {
- request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
- }
+
+ Common::String url = Common::String(DROPBOX_OAUTH2_TOKEN) + code;
+ Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, errorCallback, url);
+
addRequest(request);
}
@@ -177,8 +149,6 @@ Networking::Request *DropboxStorage::info(StorageInfoCallback callback, Networki
Common::String DropboxStorage::savesDirectoryPath() { return "/saves/"; }
DropboxStorage *DropboxStorage::loadFromConfig(Common::String keyPrefix) {
- loadKeyAndSecret();
-
if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) {
warning("DropboxStorage: no access_token found");
return nullptr;
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index 44fb8a3475..eec34d8bc5 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -31,10 +31,6 @@ namespace Cloud {
namespace Dropbox {
class DropboxStorage: public Cloud::Storage {
- static char *KEY, *SECRET;
-
- static void loadKeyAndSecret();
-
Common::String _token, _uid;
/** This private constructor is called from loadFromConfig(). */
diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp
index 4a870c01b6..8bd9228714 100644
--- a/backends/cloud/googledrive/googledrivestorage.cpp
+++ b/backends/cloud/googledrive/googledrivestorage.cpp
@@ -105,11 +105,7 @@ void GoogleDriveStorage::getAccessToken(BoolCallback callback, Networking::Error
}
request->addPostField("client_id=" + Common::String(KEY));
request->addPostField("client_secret=" + Common::String(SECRET));
- if (Cloud::CloudManager::couldUseLocalServer()) {
- request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345");
- } else {
- request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
- }
+ request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
addRequest(request);
}
diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp
index 9f7cad2e01..396370e23f 100644
--- a/backends/cloud/onedrive/onedrivestorage.cpp
+++ b/backends/cloud/onedrive/onedrivestorage.cpp
@@ -105,11 +105,7 @@ void OneDriveStorage::getAccessToken(BoolCallback callback, Networking::ErrorCal
}
request->addPostField("client_id=" + Common::String(KEY));
request->addPostField("client_secret=" + Common::String(SECRET));
- if (Cloud::CloudManager::couldUseLocalServer()) {
- request->addPostField("&redirect_uri=http%3A%2F%2Flocalhost%3A12345%2F");
- } else {
- request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
- }
+ request->addPostField("&redirect_uri=https%3A%2F%2Fwww.scummvm.org/c/code");
addRequest(request);
}
diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp
index fe5a1090cd..0a50f8e812 100644
--- a/gui/storagewizarddialog.cpp
+++ b/gui/storagewizarddialog.cpp
@@ -73,12 +73,6 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId):
// Initialy the code is empty, so disable the connect button
_connectWidget->setEnabled(false);
- if (Cloud::CloudManager::couldUseLocalServer()) {
- // hide fields and even the button if local webserver is on
- _returnLine1->setLabel(_("You will be directed to ScummVM's page where"));
- _returnLine2->setLabel(_("you should allow it to access your storage."));
- }
-
_picture = new GraphicsWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.Picture");
#ifndef DISABLE_FANCY_THEMES
if (g_gui.theme()->supportsImages()) {
@@ -130,24 +124,9 @@ void StorageWizardDialog::open() {
return;
}
}
-
-#ifdef USE_SDL_NET
- if (Cloud::CloudManager::couldUseLocalServer()) {
- _stopServerOnClose = !LocalServer.isRunning();
- LocalServer.start(true); // using "minimal mode" (no "/files", "/download", etc available)
- LocalServer.indexPageHandler().setTarget(this);
- }
-#endif
}
void StorageWizardDialog::close() {
-#ifdef USE_SDL_NET
- if (Cloud::CloudManager::couldUseLocalServer()) {
- if (_stopServerOnClose)
- LocalServer.stopOnIdle();
- LocalServer.indexPageHandler().setTarget(nullptr);
- }
-#endif
Dialog::close();
}
@@ -155,6 +134,19 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
switch (cmd) {
case kCodeBoxCmd: {
Common::String code, message;
+
+ if (_storageId == Cloud::kStorageDropboxId) {
+ // new handling
+ code = _codeWidget[0]->getEditString();
+
+ bool ok = (code.size() > 0);
+ message = ""; // (ok ? _("All OK!") : "");
+
+ _connectWidget->setEnabled(ok);
+ _messageWidget->setLabel(message);
+ return;
+ }
+
uint32 correctFields = 0;
for (uint32 i = 0; i < CODE_FIELDS; ++i) {
Common::String subcode = _codeWidget[i]->getEditString();
@@ -236,6 +228,18 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
break;
}
case kConnectCmd: {
+ if (_storageId == Cloud::kStorageDropboxId) {
+ // new handling
+ Common::String code = _codeWidget[0]->getEditString();
+ if (code.size() == 0)
+ return;
+
+ CloudMan.connectStorage(_storageId, code);
+ setResult(1);
+ close();
+ return;
+ }
+
Common::String code;
for (uint32 i = 0; i < CODE_FIELDS; ++i) {
Common::String subcode = _codeWidget[i]->getEditString();
@@ -283,9 +287,9 @@ void StorageWizardDialog::containerWidgetsReflow() {
if (_returnLine1) _returnLine1->setVisible(true);
if (_returnLine2) _returnLine2->setVisible(true);
- bool showFields = (!Cloud::CloudManager::couldUseLocalServer());
+ bool showFields = true; // TODO: remove this const
for (uint32 i = 0; i < CODE_FIELDS; ++i)
- _codeWidget[i]->setVisible(showFields);
+ _codeWidget[i]->setVisible(showFields && (_storageId != Cloud::kStorageDropboxId || i < 1)); // show only one field for Dropbox
_messageWidget->setVisible(showFields);
// left column / first bottom row
@@ -312,7 +316,7 @@ Common::String StorageWizardDialog::getUrl() const {
Common::String url = "https://www.scummvm.org/c/";
switch (_storageId) {
case Cloud::kStorageDropboxId:
- url += "db";
+ url = "https://cloud.scummvm.org/";
break;
case Cloud::kStorageOneDriveId:
url += "od";
@@ -325,9 +329,6 @@ Common::String StorageWizardDialog::getUrl() const {
break;
}
- if (Cloud::CloudManager::couldUseLocalServer())
- url += "s";
-
return url;
}