diff options
author | Tomaz Canabrava <tomaz.canabrava@gmail.com> | 2016-08-26 15:17:49 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-08-27 11:40:45 -0700 |
commit | 12eccda523da4e25a29aaaae441acfc5ad7825d1 (patch) | |
tree | 327a0abdedff513d483b9ceceaa707aad4767631 /desktop-widgets | |
parent | 5651abfd75f3b3bde45841a8ce4650ae64d9390a (diff) | |
download | subsurface-12eccda523da4e25a29aaaae441acfc5ad7825d1.tar.gz |
Settings update: Fix Facebook Widget to use the SettingsObjectWrapper
Fix facebook widget to use the SettingsObjectWrapper instead
of figthing our complementary Settings each call.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/plugins/facebook/facebookconnectwidget.cpp | 79 | ||||
-rw-r--r-- | desktop-widgets/plugins/facebook/facebookconnectwidget.h | 3 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 2 |
3 files changed, 15 insertions, 69 deletions
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp index ba54ae3bf..e0d2aab67 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp @@ -11,7 +11,6 @@ #include <QUrlQuery> #include <QEventLoop> #include <QHttpMultiPart> -#include <QSettings> #include <QFile> #include <QBuffer> #include <QDebug> @@ -24,6 +23,7 @@ #include "core/pref.h" #include "core/helpers.h" +#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "ui_socialnetworksdialog.h" #include "ui_facebookconnectwidget.h" @@ -45,7 +45,6 @@ FacebookManager *FacebookManager::instance() FacebookManager::FacebookManager(QObject *parent) : QObject(parent) { - sync(); } QUrl FacebookManager::connectUrl() { @@ -62,20 +61,6 @@ bool FacebookManager::loggedIn() { return prefs.facebook.access_token != NULL; } -void FacebookManager::sync() -{ -#if SAVE_FB_CREDENTIALS - QSettings s; - s.beginGroup("WebApps"); - s.beginGroup("Facebook"); - - QVariant v; - GET_TXT("ConnectToken", facebook.access_token); - GET_TXT("UserId", facebook.user_id); - GET_TXT("AlbumId", facebook.album_id); -#endif -} - void FacebookManager::tryLogin(const QUrl& loginResponse) { QString result = loginResponse.toString(); @@ -90,38 +75,18 @@ void FacebookManager::tryLogin(const QUrl& loginResponse) int to = result.indexOf("&expires_in"); QString securityToken = result.mid(from, to-from); -#if SAVE_FB_CREDENTIALS - QSettings settings; - settings.beginGroup("WebApps"); - settings.beginGroup("Facebook"); - settings.setValue("ConnectToken", securityToken); - sync(); -#else - prefs.facebook.access_token = copy_string(securityToken.toUtf8().data()); -#endif + auto fb = SettingsObjectWrapper::instance()->facebook; + fb->setAccessToken(securityToken); requestUserId(); - sync(); emit justLoggedIn(true); } void FacebookManager::logout() { -#if SAVE_FB_CREDENTIALS - QSettings settings; - settings.beginGroup("WebApps"); - settings.beginGroup("Facebook"); - settings.remove("ConnectToken"); - settings.remove("UserId"); - settings.remove("AlbumId"); - sync(); -#else - free(prefs.facebook.access_token); - free(prefs.facebook.album_id); - free(prefs.facebook.user_id); - prefs.facebook.access_token = NULL; - prefs.facebook.album_id = NULL; - prefs.facebook.user_id = NULL; -#endif + auto fb = SettingsObjectWrapper::instance()->facebook; + fb->setAccessToken(QString()); + fb->setUserId(QString()); + fb->setAlbumId(QString()); emit justLoggedOut(true); } @@ -135,22 +100,14 @@ void FacebookManager::requestAlbumId() connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); -#if SAVE_FB_CREDENTIALS - QSettings s; - s.beginGroup("WebApps"); - s.beginGroup("Facebook"); -#endif - QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll()); QJsonArray albumObj = albumsDoc.object().value("data").toArray(); + auto fb = SettingsObjectWrapper::instance()->facebook; + foreach(const QJsonValue &v, albumObj){ QJsonObject obj = v.toObject(); if (obj.value("name").toString() == albumName) { -#if SAVE_FB_CREDENTIALS - s.setValue("AlbumId", obj.value("id").toString()); -#else - prefs.facebook.album_id = copy_string(obj.value("id").toString().toUtf8().data()); -#endif + fb->setAlbumId(obj.value("id").toString()); return; } } @@ -169,12 +126,7 @@ void FacebookManager::requestAlbumId() albumsDoc = QJsonDocument::fromJson(reply->readAll()); QJsonObject album = albumsDoc.object(); if (album.contains("id")) { -#if SAVE_FB_CREDENTIALS - s.setValue("AlbumId", album.value("id").toString()); -#else - prefs.facebook.album_id = copy_string(album.value("id").toString().toUtf8().data()); -#endif - sync(); + fb->setAlbumId(album.value("id").toString()); return; } } @@ -192,14 +144,7 @@ void FacebookManager::requestUserId() QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll()); QJsonObject obj = jsonDoc.object(); if (obj.keys().contains("id")){ -#if SAVE_FB_CREDENTIALS - QSettings s; - s.beginGroup("WebApps"); - s.beginGroup("Facebook"); - s.setValue("UserId", obj.value("id").toVariant()); -#else - prefs.facebook.user_id = copy_string(obj.value("id").toString().toUtf8().data()); -#endif + SettingsObjectWrapper::instance()->facebook->setUserId(obj.value("id").toString()); return; } } diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h index 61966f566..e97097806 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.h +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h @@ -15,7 +15,6 @@ public: static FacebookManager *instance(); void requestAlbumId(); void requestUserId(); - void sync(); QUrl connectUrl(); bool loggedIn(); signals: @@ -58,4 +57,4 @@ private: Ui::SocialnetworksDialog *ui; }; -#endif
\ No newline at end of file +#endif diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 74868d2bd..312e82314 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -438,6 +438,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) bool qSaveUid = ui.saveUidLocal->checkState(); SettingsObjectWrapper::instance()->cloud_storage->setSaveUserIdLocal(qSaveUid); + //WARN: Dirk, this seems to be wrong, I coundn't really understand the code. if (qSaveUid) { QString qSettingUid = s.value("subsurface_webservice_uid").toString(); QString qFileUid = QString(prefs.userid); @@ -758,6 +759,7 @@ DivelogsDeWebServices::DivelogsDeWebServices(QWidget *parent, Qt::WindowFlags f) multipart(NULL), uploadMode(false) { + //FIXME: DivelogDE user and pass should be on the prefs struct or something? QSettings s; ui.userID->setText(s.value("divelogde_user").toString()); ui.password->setText(s.value("divelogde_pass").toString()); |