diff options
author | jan Iversen <jani@apache.org> | 2018-07-23 17:49:12 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-27 12:36:20 -0700 |
commit | f175890632d5845d57066b0669c347b4c0992ff9 (patch) | |
tree | efe856eb90e077c64f990b5ec5681c95eed7c866 | |
parent | e0f1817fdc3b0024c5e97cfa0db048384aae6d78 (diff) | |
download | subsurface-f175890632d5845d57066b0669c347b4c0992ff9.tar.gz |
core: activate qPrefFacebook
remove Facebook from SettingsObjectWrapper and reference qPrefFacebook
update files using SettingsObjectWrapper/Facebook to use qPrefFacebook
this activated qPrefFacebook and removed the similar class from
SettingsObjectWrapper.
Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 68 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.h | 31 | ||||
-rw-r--r-- | desktop-widgets/plugins/facebook/facebookconnectwidget.cpp | 30 | ||||
-rw-r--r-- | subsurface-helper.cpp | 3 | ||||
-rw-r--r-- | tests/testpreferences.cpp | 32 |
5 files changed, 37 insertions, 127 deletions
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 9e0e8992c..3085216c7 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -662,72 +662,6 @@ void TechnicalDetailsSettings::setShowIcd(bool value) emit showIcdChanged(value); } -FacebookSettings::FacebookSettings(QObject *parent) : - QObject(parent), - group(QStringLiteral("WebApps")), - subgroup(QStringLiteral("Facebook")) -{ -} - -QString FacebookSettings::accessToken() const -{ - return QString(prefs.facebook.access_token); -} - -QString FacebookSettings::userId() const -{ - return QString(prefs.facebook.user_id); -} - -QString FacebookSettings::albumId() const -{ - return QString(prefs.facebook.album_id); -} - -void FacebookSettings::setAccessToken (const QString& value) -{ -#if SAVE_FB_CREDENTIALS - QSettings s; - s.beginGroup(group); - s.beginGroup(subgroup); - s.setValue("ConnectToken", value); -#endif - free((void *)prefs.facebook.access_token); - prefs.facebook.access_token = copy_qstring(value); - emit accessTokenChanged(value); -} - -void FacebookSettings::setUserId(const QString& value) -{ - if (value == prefs.facebook.user_id) - return; -#if SAVE_FB_CREDENTIALS - QSettings s; - s.beginGroup(group); - s.beginGroup(subgroup); - s.setValue("UserId", value); -#endif - free((void *)prefs.facebook.user_id); - prefs.facebook.user_id = copy_qstring(value); - emit userIdChanged(value); -} - -void FacebookSettings::setAlbumId(const QString& value) -{ - if (value == prefs.facebook.album_id) - return; -#if SAVE_FB_CREDENTIALS - QSettings s; - s.beginGroup(group); - s.beginGroup(subgroup); - s.setValue("AlbumId", value); -#endif - free((void *)prefs.facebook.album_id); - prefs.facebook.album_id = copy_qstring(value); - emit albumIdChanged(value); -} - - GeocodingPreferences::GeocodingPreferences(QObject *parent) : QObject(parent) { @@ -1829,7 +1763,7 @@ SettingsObjectWrapper::SettingsObjectWrapper(QObject* parent): QObject(parent), techDetails(new TechnicalDetailsSettings(this)), pp_gas(new PartialPressureGasSettings(this)), - facebook(new FacebookSettings(this)), + facebook(new qPrefFacebook(this)), geocoding(new GeocodingPreferences(this)), proxy(new ProxySettings(this)), cloud_storage(new qPrefCloudStorage(this)), diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h index 9cb707044..cd30cb1ac 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.h +++ b/core/subsurface-qt/SettingsObjectWrapper.h @@ -204,33 +204,6 @@ private: const QString group = QStringLiteral("TecDetails"); }; -/* Control the state of the Facebook preferences */ -class FacebookSettings : public QObject { - Q_OBJECT - Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken NOTIFY accessTokenChanged) - Q_PROPERTY(QString userId READ userId WRITE setUserId NOTIFY userIdChanged) - Q_PROPERTY(QString albumId READ albumId WRITE setAlbumId NOTIFY albumIdChanged) - -public: - FacebookSettings(QObject *parent); - QString accessToken() const; - QString userId() const; - QString albumId() const; - -public slots: - void setAccessToken (const QString& value); - void setUserId(const QString& value); - void setAlbumId(const QString& value); - -signals: - void accessTokenChanged(const QString& value); - void userIdChanged(const QString& value); - void albumIdChanged(const QString& value); -private: - QString group; - QString subgroup; -}; - /* Control the state of the Geocoding preferences */ class GeocodingPreferences : public QObject { Q_OBJECT @@ -573,7 +546,7 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(TechnicalDetailsSettings* techical_details MEMBER techDetails CONSTANT) Q_PROPERTY(PartialPressureGasSettings* pp_gas MEMBER pp_gas CONSTANT) - Q_PROPERTY(FacebookSettings* facebook MEMBER facebook CONSTANT) + Q_PROPERTY(qPrefFacebook* facebook MEMBER facebook CONSTANT) Q_PROPERTY(GeocodingPreferences* geocoding MEMBER geocoding CONSTANT) Q_PROPERTY(ProxySettings* proxy MEMBER proxy CONSTANT) Q_PROPERTY(qPrefCloudStorage* cloud_storage MEMBER cloud_storage CONSTANT) @@ -593,7 +566,7 @@ public: TechnicalDetailsSettings *techDetails; PartialPressureGasSettings *pp_gas; - FacebookSettings *facebook; + qPrefFacebook *facebook; GeocodingPreferences *geocoding; ProxySettings *proxy; qPrefCloudStorage *cloud_storage; diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp index 1600556f0..d76cc88cd 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp @@ -88,18 +88,18 @@ void FacebookManager::tryLogin(const QUrl& loginResponse) int to = result.indexOf("&expires_in"); QString securityToken = result.mid(from, to-from); - auto fb = SettingsObjectWrapper::instance()->facebook; - fb->setAccessToken(securityToken); + auto fb = qPrefFacebook::instance(); + fb->set_access_token(securityToken); qCDebug(lcFacebook) << "Got securityToken" << securityToken; requestUserId(); } void FacebookManager::logout() { - auto fb = SettingsObjectWrapper::instance()->facebook; - fb->setAccessToken(QString()); - fb->setUserId(QString()); - fb->setAlbumId(QString()); + auto fb = qPrefFacebook::instance(); + fb->set_access_token(QString()); + fb->set_user_id(QString()); + fb->set_album_id(QString()); emit justLoggedOut(true); } @@ -116,15 +116,15 @@ void FacebookManager::albumListReceived() QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll()); QJsonArray albumObj = albumsDoc.object().value("data").toArray(); - auto fb = SettingsObjectWrapper::instance()->facebook; + auto fb = qPrefFacebook::instance(); reply->deleteLater(); foreach(const QJsonValue &v, albumObj){ QJsonObject obj = v.toObject(); if (obj.value("name").toString() == fbInfo.albumName) { - fb->setAlbumId(obj.value("id").toString()); + fb->set_album_id(obj.value("id").toString()); qCDebug(lcFacebook) << "Album" << fbInfo.albumName << "already exists, using id" << obj.value("id").toString(); - emit albumIdReceived(fb->albumId()); + emit albumIdReceived(fb->album_id()); return; } } @@ -158,9 +158,9 @@ void FacebookManager::facebookAlbumCreated() if (album.contains("id")) { qCDebug(lcFacebook) << "Album" << fbInfo.albumName << "created successfully with id" << album.value("id").toString(); - auto fb = SettingsObjectWrapper::instance()->facebook; - fb->setAlbumId(album.value("id").toString()); - emit albumIdReceived(fb->albumId()); + auto fb = qPrefFacebook::instance(); + fb->set_album_id(album.value("id").toString()); + emit albumIdReceived(fb->album_id()); return; } else { qCDebug(lcFacebook) << "It was not possible to create the album with name" << fbInfo.albumName; @@ -168,8 +168,8 @@ void FacebookManager::facebookAlbumCreated() // FIXME: we are lacking 'user_photos' facebook permission to create an album, // but we are able to upload the image to Facebook (album will be named 'Subsurface Photos') qCDebug(lcFacebook) << "But we are still able to upload data. Album name will be 'Subsurface Photos'"; - auto fb = SettingsObjectWrapper::instance()->facebook; - emit albumIdReceived(fb->albumId()); + auto fb = qPrefFacebook::instance(); + emit albumIdReceived(fb->album_id()); } } @@ -189,7 +189,7 @@ void FacebookManager::userIdReceived() QJsonObject obj = jsonDoc.object(); if (obj.keys().contains("id")) { qCDebug(lcFacebook) << "User id requested successfully:" << obj.value("id").toString(); - SettingsObjectWrapper::instance()->facebook->setUserId(obj.value("id").toString()); + qPrefFacebook::instance()->set_user_id(obj.value("id").toString()); emit sendMessage(tr("Facebook logged in successfully")); emit justLoggedIn(true); } else { diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index e55425abf..b8ccf5a92 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -165,6 +165,9 @@ void register_qml_types() rc = qmlRegisterType<qPrefDiveComputer>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDiveComputerPrefs"); if (rc < 0) qDebug() << "ERROR: Cannot register DiveComputerPrefs (class qPrefDiveComputer), QML will not work!!"; + rc = qmlRegisterType<qPrefFacebook>("org.subsurfacedivelog.mobile", 1, 0, "SsrfFacebookPrefs"); + if (rc < 0) + qDebug() << "ERROR: Cannot register FacebookPrefs (class qPrefFacebook), QML will not work!!"; #ifndef SUBSURFACE_TEST_DATA #ifdef SUBSURFACE_MOBILE diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index bba580458..2fe863959 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -160,22 +160,22 @@ void TestPreferences::testPreferences() TEST(pp->po2ThresholdMin(), 4.0); TEST(pp->po2ThresholdMax(), 5.0); - auto fb = pref->facebook; - fb->setAccessToken("rand-access-token"); - fb->setUserId("tomaz-user-id"); - fb->setAlbumId("album-id"); - - TEST(fb->accessToken(), QStringLiteral("rand-access-token")); - TEST(fb->userId(), QStringLiteral("tomaz-user-id")); - TEST(fb->albumId(), QStringLiteral("album-id")); - - fb->setAccessToken("rand-access-token-2"); - fb->setUserId("tomaz-user-id-2"); - fb->setAlbumId("album-id-2"); - - TEST(fb->accessToken(), QStringLiteral("rand-access-token-2")); - TEST(fb->userId(), QStringLiteral("tomaz-user-id-2")); - TEST(fb->albumId(), QStringLiteral("album-id-2")); + auto fb = qPrefFacebook::instance(); + fb->set_access_token("rand-access-token"); + fb->set_user_id("tomaz-user-id"); + fb->set_album_id("album-id"); + + TEST(fb->access_token(),QStringLiteral("rand-access-token")); + TEST(fb->user_id(), QStringLiteral("tomaz-user-id")); + TEST(fb->album_id(), QStringLiteral("album-id")); + + fb->set_access_token("rand-access-token-2"); + fb->set_user_id("tomaz-user-id-2"); + fb->set_album_id("album-id-2"); + + TEST(fb->access_token(),QStringLiteral("rand-access-token-2")); + TEST(fb->user_id(), QStringLiteral("tomaz-user-id-2")); + TEST(fb->album_id(), QStringLiteral("album-id-2")); auto geo = pref->geocoding; geo->setFirstTaxonomyCategory(TC_NONE); |