aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/dropbox
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-23 12:21:45 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit735db74b900d1e0a0654ca03983cd91cea36f41e (patch)
tree05d851451ca39bf493ebe6d3e452aa4b6acefd85 /backends/cloud/dropbox
parenta439bd4c33e6f8a47a856d7cb4a4db7c540a85ab (diff)
downloadscummvm-rg350-735db74b900d1e0a0654ca03983cd91cea36f41e.tar.gz
scummvm-rg350-735db74b900d1e0a0654ca03983cd91cea36f41e.tar.bz2
scummvm-rg350-735db74b900d1e0a0654ca03983cd91cea36f41e.zip
CLOUD: Add DropboxStorage::listDirectory sketch
It doesn't support any "has_more", doesn't call user's callback and just prints JSON instead of parsing in into an array of files. I believe it would become DropboxListDirectoryRequest in the next commit.
Diffstat (limited to 'backends/cloud/dropbox')
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp34
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h2
2 files changed, 31 insertions, 5 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index 5a881211e3..28d14c6a2e 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -75,11 +75,37 @@ void DropboxStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "user_id", _uid, "cloud");
}
+void printJson(void *ptr) {
+ Common::JSONValue *json = (Common::JSONValue *)ptr;
+ if (json) {
+ debug("%s", json->stringify(true).c_str());
+ } else {
+ warning("null, not json");
+ }
+}
+
+void DropboxStorage::listDirectory(Common::String path, FileArrayCallback outerCallback, bool recursive) {
+ //Common::BaseCallback<> *innerCallback = new Common::CallbackBridge<DropboxStorage, Common::Array<StorageFile> >(this, &DropboxStorage::listDirectoryInnerCallback, outerCallback);
+ Common::BaseCallback<> *innerCallback = new Common::GlobalFunctionCallback(printJson); //okay
+ Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, "https://api.dropboxapi.com/2/files/list_folder");
+ request->addHeader("Authorization: Bearer " + _token);
+ request->addHeader("Content-Type: application/json");
+
+ Common::JSONObject jsonRequestParameters;
+ jsonRequestParameters.setVal("path", new Common::JSONValue(path));
+ jsonRequestParameters.setVal("recursive", new Common::JSONValue(recursive));
+ jsonRequestParameters.setVal("include_media_info", new Common::JSONValue(false));
+ jsonRequestParameters.setVal("include_deleted", new Common::JSONValue(false));
+
+ Common::JSONValue value(jsonRequestParameters);
+ request->addPostField(Common::JSON::stringify(&value));
+
+ ConnMan.addRequest(request);
+}
+
void DropboxStorage::syncSaves(BoolCallback callback) {
- //this is not the real syncSaves() implementation
- info(new Common::Callback<DropboxStorage, StorageInfo>(this, &DropboxStorage::infoMethodCallback));
- //that line meant the following:
- //"please, do the info API request and, when it's finished, call the infoMethodCallback() of me"
+ //this is not the real syncSaves() implementation
+ listDirectory("", 0); //"" is root in Dropbox, not "/"
}
void DropboxStorage::info(StorageInfoCallback outerCallback) {
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index 493fcdd25d..3077b98763 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -62,7 +62,7 @@ public:
/** Public Cloud API comes down there. */
/** Returns Common::Array<StorageFile>. */
- virtual void listDirectory(Common::String path, FileArrayCallback callback) {} //TODO
+ virtual void listDirectory(Common::String path, FileArrayCallback callback, bool recursive = false);
/** Calls the callback when finished. */
virtual void upload(Common::String path, Common::ReadStream* contents, BoolCallback callback) {} //TODO