diff options
author | jan Iversen <jani@apache.org> | 2018-07-14 16:52:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-21 07:49:25 -0700 |
commit | b9b1f03f0d77f1eea86efeed8776a623bd5b30ee (patch) | |
tree | 1804b5204b538d082673ed0223768de2f602bb95 | |
parent | 4b68329c9db7ed13eaed7dd36ce6c82b1d7d11ca (diff) | |
download | subsurface-b9b1f03f0d77f1eea86efeed8776a623bd5b30ee.tar.gz |
core: activate qPrefCloudStorage
remove CloudStorage from SettingsObjectWrapper and reference qPrefCloudStorage
update files using SettingsObjectWrapper/CloudStorage to use qPrefCloudStorage
this activated qPrefCloudStorage and removed the similar class from
SettingsObjectWrapper.
Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r-- | core/cloudstorage.cpp | 9 | ||||
-rw-r--r-- | core/settings/qPref.cpp | 1 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 204 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.h | 61 | ||||
-rw-r--r-- | desktop-widgets/preferences/preferences_network.cpp | 22 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 4 | ||||
-rw-r--r-- | tests/testpreferences.cpp | 82 |
7 files changed, 63 insertions, 320 deletions
diff --git a/core/cloudstorage.cpp b/core/cloudstorage.cpp index 8c4da4791..51bdf5994 100644 --- a/core/cloudstorage.cpp +++ b/core/cloudstorage.cpp @@ -3,7 +3,6 @@ #include "pref.h" #include "qthelper.h" #include "settings/qPref.h" -#include "core/subsurface-qt/SettingsObjectWrapper.h" #include <QApplication> CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : @@ -49,10 +48,10 @@ void CloudStorageAuthenticate::uploadFinished() QString cloudAuthReply(reply->readAll()); qDebug() << "Completed connection with cloud storage backend, response" << cloudAuthReply; - CloudStorageSettings csSettings(parent()); + qPrefCloudStorage csSettings(parent()); if (cloudAuthReply == QLatin1String("[VERIFIED]") || cloudAuthReply == QLatin1String("[OK]")) { - csSettings.setVerificationStatus(qPref::CS_VERIFIED); + csSettings.set_cloud_verification_status(qPref::CS_VERIFIED); /* TODO: Move this to a correct place NotificationWidget *nw = MainWindow::instance()->getNotificationWidget(); if (nw->getNotificationText() == myLastError) @@ -61,7 +60,7 @@ void CloudStorageAuthenticate::uploadFinished() myLastError.clear(); } else if (cloudAuthReply == QLatin1String("[VERIFY]") || cloudAuthReply == QLatin1String("Invalid PIN")) { - csSettings.setVerificationStatus(qPref::CS_NEED_TO_VERIFY); + csSettings.set_cloud_verification_status(qPref::CS_NEED_TO_VERIFY); report_error(qPrintable(tr("Cloud account verification required, enter PIN in preferences"))); } else if (cloudAuthReply == QLatin1String("[PASSWDCHANGED]")) { free((void *)prefs.cloud_storage_password); @@ -70,7 +69,7 @@ void CloudStorageAuthenticate::uploadFinished() emit passwordChangeSuccessful(); return; } else { - csSettings.setVerificationStatus(qPref::CS_INCORRECT_USER_PASSWD); + csSettings.set_cloud_verification_status(qPref::CS_INCORRECT_USER_PASSWD); myLastError = cloudAuthReply; report_error("%s", qPrintable(cloudAuthReply)); } diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index 1605e30df..fb80e9d92 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -15,6 +15,7 @@ static qPref *self = new qPref; void qPref::loadSync(bool doSync) { + qPrefCloudStorage::instance()->loadSync(doSync); qPrefDisplay::instance()->loadSync(doSync); } diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index e2fadd90c..31920fded 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -975,185 +975,6 @@ void ProxySettings::setPass(const QString& value) emit passChanged(value); } -CloudStorageSettings::CloudStorageSettings(QObject *parent) : - QObject(parent) -{ - -} - -bool CloudStorageSettings::gitLocalOnly() const -{ - return prefs.git_local_only; -} - -QString CloudStorageSettings::password() const -{ - return QString(prefs.cloud_storage_password); -} - -QString CloudStorageSettings::newPassword() const -{ - return QString(prefs.cloud_storage_newpassword); -} - -QString CloudStorageSettings::email() const -{ - return QString(prefs.cloud_storage_email); -} - -QString CloudStorageSettings::emailEncoded() const -{ - return QString(prefs.cloud_storage_email_encoded); -} - -bool CloudStorageSettings::savePasswordLocal() const -{ - return prefs.save_password_local; -} - -short CloudStorageSettings::verificationStatus() const -{ - return prefs.cloud_verification_status; -} - -QString CloudStorageSettings::userId() const -{ - return QString(prefs.userid); -} - -QString CloudStorageSettings::baseUrl() const -{ - return QString(prefs.cloud_base_url); -} - -QString CloudStorageSettings::gitUrl() const -{ - return QString(prefs.cloud_git_url); -} - -void CloudStorageSettings::setPassword(const QString& value) -{ - if (value == prefs.cloud_storage_password) - return; - QSettings s; - s.beginGroup(group); - s.setValue("password", value); - free((void *)prefs.cloud_storage_password); - prefs.cloud_storage_password = copy_qstring(value); - emit passwordChanged(value); -} - -void CloudStorageSettings::setNewPassword(const QString& value) -{ - if (value == prefs.cloud_storage_newpassword) - return; - /*TODO: This looks like wrong, but 'new password' is not saved on disk, why it's on prefs? */ - free((void *)prefs.cloud_storage_newpassword); - prefs.cloud_storage_newpassword = copy_qstring(value); - emit newPasswordChanged(value); -} - -void CloudStorageSettings::setEmail(const QString& value) -{ - if (value == prefs.cloud_storage_email) - return; - QSettings s; - s.beginGroup(group); - s.setValue("email", value); - free((void *)prefs.cloud_storage_email); - prefs.cloud_storage_email = copy_qstring(value); - emit emailChanged(value); -} - -void CloudStorageSettings::setUserId(const QString& value) -{ - if (value == prefs.userid) - return; - //WARNING: UserId is stored outside of any group, but it belongs to Cloud Storage. - QSettings s; - s.setValue("subsurface_webservice_uid", value); - free((void *)prefs.userid); - prefs.userid = copy_qstring(value); - emit userIdChanged(value); -} - -void CloudStorageSettings::setEmailEncoded(const QString& value) -{ - if (value == prefs.cloud_storage_email_encoded) - return; - /*TODO: This looks like wrong, but 'email encoded' is not saved on disk, why it's on prefs? */ - free((void *)prefs.cloud_storage_email_encoded); - prefs.cloud_storage_email_encoded = copy_qstring(value); - emit emailEncodedChanged(value); -} - -void CloudStorageSettings::setSavePasswordLocal(bool value) -{ - if (value == prefs.save_password_local) - return; - QSettings s; - s.beginGroup(group); - s.setValue("save_password_local", value); - prefs.save_password_local = value; - emit savePasswordLocalChanged(value); -} - -void CloudStorageSettings::setVerificationStatus(short value) -{ - if (value == prefs.cloud_verification_status) - return; - QSettings s; - s.beginGroup(group); - s.setValue("cloud_verification_status", value); - prefs.cloud_verification_status = value; - emit verificationStatusChanged(value); -} - -void CloudStorageSettings::setSaveUserIdLocal(bool value) -{ - //TODO: this is not saved on disk? - if (value == prefs.save_userid_local) - return; - prefs.save_userid_local = value; - emit saveUserIdLocalChanged(value); -} - -bool CloudStorageSettings::saveUserIdLocal() const -{ - return prefs.save_userid_local; -} - -void CloudStorageSettings::setBaseUrl(const QString& value) -{ - if (value == prefs.cloud_base_url) - return; - - // dont free data segment. - if (prefs.cloud_base_url != default_prefs.cloud_base_url) { - free((void *)prefs.cloud_base_url); - free((void *)prefs.cloud_git_url); - } - QSettings s; - s.beginGroup(group); - s.setValue("cloud_base_url", value); - prefs.cloud_base_url = copy_qstring(value); - prefs.cloud_git_url = copy_qstring(QString(prefs.cloud_base_url) + "/git"); -} - -void CloudStorageSettings::setGitUrl(const QString&) -{ -} - -void CloudStorageSettings::setGitLocalOnly(bool value) -{ - if (value == prefs.git_local_only) - return; - QSettings s; - s.beginGroup("CloudStorage"); - s.setValue("git_local_only", value); - prefs.git_local_only = value; - emit gitLocalOnlyChanged(value); -} DivePlannerSettings::DivePlannerSettings(QObject *parent) : QObject(parent) @@ -2100,7 +1921,7 @@ QObject(parent), facebook(new FacebookSettings(this)), geocoding(new GeocodingPreferences(this)), proxy(new ProxySettings(this)), - cloud_storage(new CloudStorageSettings(this)), + cloud_storage(new qPrefCloudStorage(this)), planner_settings(new DivePlannerSettings(this)), unit_settings(new UnitsSettings(this)), general_settings(new GeneralSettingsObjectWrapper(this)), @@ -2212,28 +2033,7 @@ void SettingsObjectWrapper::load() GET_TXT("proxy_pass", proxy_pass); s.endGroup(); - s.beginGroup("CloudStorage"); - GET_TXT("email", cloud_storage_email); -#ifndef SUBSURFACE_MOBILE - GET_BOOL("save_password_local", save_password_local); -#else - // always save the password in Subsurface-mobile - prefs.save_password_local = true; -#endif - if (prefs.save_password_local) { // GET_TEXT macro is not a single statement - GET_TXT("password", cloud_storage_password); - } - GET_INT("cloud_verification_status", cloud_verification_status); - GET_BOOL("git_local_only", git_local_only); - - // creating the git url here is simply a convenience when C code wants - // to compare against that git URL - it's always derived from the base URL - GET_TXT("cloud_base_url", cloud_base_url); - prefs.cloud_git_url = copy_qstring(QString(prefs.cloud_base_url) + "/git"); - s.endGroup(); - - // Subsurface webservice id is stored outside of the groups - GET_TXT("subsurface_webservice_uid", userid); + qPrefCloudStorage::instance()->load(); // GeoManagement s.beginGroup("geocoding"); diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h index 075227384..fdf0b08f6 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.h +++ b/core/subsurface-qt/SettingsObjectWrapper.h @@ -326,63 +326,6 @@ private: const QString group = QStringLiteral("Network"); }; -class CloudStorageSettings : public QObject { - Q_OBJECT - Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) - Q_PROPERTY(QString newpassword READ newPassword WRITE setNewPassword NOTIFY newPasswordChanged) - Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged) - Q_PROPERTY(QString email_encoded READ emailEncoded WRITE setEmailEncoded NOTIFY emailEncodedChanged) - Q_PROPERTY(QString userid READ userId WRITE setUserId NOTIFY userIdChanged) - Q_PROPERTY(QString base_url READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged) - Q_PROPERTY(QString git_url READ gitUrl WRITE setGitUrl NOTIFY gitUrlChanged) - Q_PROPERTY(bool save_userid_local READ saveUserIdLocal WRITE setSaveUserIdLocal NOTIFY saveUserIdLocalChanged) - Q_PROPERTY(bool git_local_only READ gitLocalOnly WRITE setGitLocalOnly NOTIFY gitLocalOnlyChanged) - Q_PROPERTY(bool save_password_local READ savePasswordLocal WRITE setSavePasswordLocal NOTIFY savePasswordLocalChanged) - Q_PROPERTY(short verification_status READ verificationStatus WRITE setVerificationStatus NOTIFY verificationStatusChanged) -public: - CloudStorageSettings(QObject *parent); - QString password() const; - QString newPassword() const; - QString email() const; - QString emailEncoded() const; - QString userId() const; - QString baseUrl() const; - QString gitUrl() const; - bool savePasswordLocal() const; - short verificationStatus() const; - bool gitLocalOnly() const; - bool saveUserIdLocal() const; - -public slots: - void setPassword(const QString& value); - void setNewPassword(const QString& value); - void setEmail(const QString& value); - void setEmailEncoded(const QString& value); - void setUserId(const QString& value); - void setBaseUrl(const QString& value); - void setGitUrl(const QString& value); - void setSavePasswordLocal(bool value); - void setVerificationStatus(short value); - void setGitLocalOnly(bool value); - void setSaveUserIdLocal(bool value); - -signals: - void passwordChanged(const QString& value); - void newPasswordChanged(const QString& value); - void emailChanged(const QString& value); - void emailEncodedChanged(const QString& value); - void userIdChanged(const QString& value); - void baseUrlChanged(const QString& value); - void gitUrlChanged(const QString& value); - void savePasswordLocalChanged(bool value); - void verificationStatusChanged(short value); - void gitLocalOnlyChanged(bool value); - void saveUserIdLocalChanged(bool value); - -private: - const QString group = QStringLiteral("CloudStorage"); -}; - class DivePlannerSettings : public QObject { Q_OBJECT Q_PROPERTY(bool last_stop READ lastStop WRITE setLastStop NOTIFY lastStopChanged) @@ -666,7 +609,7 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(FacebookSettings* facebook MEMBER facebook CONSTANT) Q_PROPERTY(GeocodingPreferences* geocoding MEMBER geocoding CONSTANT) Q_PROPERTY(ProxySettings* proxy MEMBER proxy CONSTANT) - Q_PROPERTY(CloudStorageSettings* cloud_storage MEMBER cloud_storage CONSTANT) + Q_PROPERTY(qPrefCloudStorage* cloud_storage MEMBER cloud_storage CONSTANT) Q_PROPERTY(DivePlannerSettings* planner MEMBER planner_settings CONSTANT) Q_PROPERTY(UnitsSettings* units MEMBER unit_settings CONSTANT) @@ -686,7 +629,7 @@ public: FacebookSettings *facebook; GeocodingPreferences *geocoding; ProxySettings *proxy; - CloudStorageSettings *cloud_storage; + qPrefCloudStorage *cloud_storage; DivePlannerSettings *planner_settings; UnitsSettings *unit_settings; GeneralSettingsObjectWrapper *general_settings; diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp index 37dbc5721..ba08cea63 100644 --- a/desktop-widgets/preferences/preferences_network.cpp +++ b/desktop-widgets/preferences/preferences_network.cpp @@ -48,8 +48,8 @@ void PreferencesNetwork::syncSettings() auto cloud = SettingsObjectWrapper::instance()->cloud_storage; auto proxy = SettingsObjectWrapper::instance()->proxy; - cloud->setUserId(ui->default_uid->text().toUpper()); - cloud->setSaveUserIdLocal(ui->save_uid_local->checkState()); + cloud->set_userid(ui->default_uid->text().toUpper()); + cloud->set_save_userid_local(ui->save_uid_local->checkState()); proxy->setType(ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt()); proxy->setHost(ui->proxyHost->text()); @@ -82,7 +82,7 @@ void PreferencesNetwork::syncSettings() connect(cloudAuth, &CloudStorageAuthenticate::passwordChangeSuccessful, this, &PreferencesNetwork::passwordUpdateSuccessful); cloudAuth->backend(email, password, "", newpassword); ui->cloud_storage_new_passwd->setText(""); - cloud->setNewPassword(newpassword); + cloud->set_cloud_storage_newpassword(newpassword); } } else if (prefs.cloud_verification_status == qPref::CS_UNKNOWN || prefs.cloud_verification_status == qPref::CS_INCORRECT_USER_PASSWD || @@ -90,14 +90,14 @@ void PreferencesNetwork::syncSettings() password != prefs.cloud_storage_password) { // different credentials - reset verification status - int oldVerificationStatus = cloud->verificationStatus(); - cloud->setVerificationStatus(qPref::CS_UNKNOWN); + int oldVerificationStatus = cloud->cloud_verification_status(); + cloud->set_cloud_verification_status(qPref::CS_UNKNOWN); if (!email.isEmpty() && !password.isEmpty()) { // connect to backend server to check / create credentials QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - cloud->setVerificationStatus(oldVerificationStatus); + cloud->set_cloud_verification_status(oldVerificationStatus); return; } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); @@ -118,11 +118,11 @@ void PreferencesNetwork::syncSettings() cloudAuth->backend(email, password, pin); } } - cloud->setEmail(email); - cloud->setSavePasswordLocal(ui->save_password_local->isChecked()); - cloud->setPassword(password); - cloud->setVerificationStatus(prefs.cloud_verification_status); - cloud->setBaseUrl(prefs.cloud_base_url); + cloud->set_cloud_storage_email(email); + cloud->set_save_password_local(ui->save_password_local->isChecked()); + cloud->set_cloud_storage_password(password); + cloud->set_cloud_verification_status(prefs.cloud_verification_status); + cloud->set_cloud_base_url(prefs.cloud_base_url); } void PreferencesNetwork::updateCloudAuthenticationState() diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 5ed068d2f..d1af7715d 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -2,6 +2,7 @@ #include "desktop-widgets/subsurfacewebservices.h" #include "core/qthelper.h" #include "core/webservice.h" +#include "core/settings/qPref.h" #include "desktop-widgets/mainwindow.h" #include "desktop-widgets/usersurvey.h" #include "core/divelist.h" @@ -9,7 +10,6 @@ #include "desktop-widgets/tab-widgets/maintab.h" #include "core/display.h" #include "core/membuffer.h" -#include "core/subsurface-qt/SettingsObjectWrapper.h" #include <errno.h> #include "core/cloudstorage.h" #include "core/subsurface-string.h" @@ -436,7 +436,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) QSettings s; QString qDialogUid = ui.userID->text().toUpper(); bool qSaveUid = ui.saveUidLocal->checkState(); - SettingsObjectWrapper::instance()->cloud_storage->setSaveUserIdLocal(qSaveUid); + qPrefCloudStorage::instance()->set_save_userid_local(qSaveUid); //WARN: Dirk, this seems to be wrong, I coundn't really understand the code. if (qSaveUid) { diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index d950c49f9..b0f543a45 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -26,51 +26,51 @@ void TestPreferences::testPreferences() auto cloud = pref->cloud_storage; - cloud->setBaseUrl("test_one"); - TEST(cloud->baseUrl(), QStringLiteral("test_one")); - cloud->setBaseUrl("test_two"); - TEST(cloud->baseUrl(), QStringLiteral("test_two")); + cloud->set_cloud_base_url("test_one"); + TEST(cloud->cloud_base_url(), QStringLiteral("test_one")); + cloud->set_cloud_base_url("test_two"); + TEST(cloud->cloud_base_url(), QStringLiteral("test_two")); - cloud->setEmail("tomaz@subsurface.com"); - TEST(cloud->email(), QStringLiteral("tomaz@subsurface.com")); - cloud->setEmail("tomaz@gmail.com"); - TEST(cloud->email(), QStringLiteral("tomaz@gmail.com")); + cloud->set_cloud_storage_email("tomaz@subsurface.com"); + TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@subsurface.com")); + cloud->set_cloud_storage_email("tomaz@gmail.com"); + TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@gmail.com")); - cloud->setGitLocalOnly(true); - TEST(cloud->gitLocalOnly(), true); - cloud->setGitLocalOnly(false); - TEST(cloud->gitLocalOnly(), false); + cloud->set_git_local_only(true); + TEST(cloud->git_local_only(), true); + cloud->set_git_local_only(false); + TEST(cloud->git_local_only(), false); // Why there's new password and password on the prefs? - cloud->setNewPassword("ABCD"); - TEST(cloud->newPassword(), QStringLiteral("ABCD")); - cloud->setNewPassword("ABCDE"); - TEST(cloud->newPassword(), QStringLiteral("ABCDE")); - - cloud->setPassword("ABCDE"); - TEST(cloud->password(), QStringLiteral("ABCDE")); - cloud->setPassword("ABCABC"); - TEST(cloud->password(), QStringLiteral("ABCABC")); - - cloud->setSavePasswordLocal(true); - TEST(cloud->savePasswordLocal(), true); - cloud->setSavePasswordLocal(false); - TEST(cloud->savePasswordLocal(), false); - - cloud->setSaveUserIdLocal(1); - TEST(cloud->saveUserIdLocal(), true); - cloud->setSaveUserIdLocal(0); - TEST(cloud->saveUserIdLocal(), false); - - cloud->setUserId("Tomaz"); - TEST(cloud->userId(), QStringLiteral("Tomaz")); - cloud->setUserId("Zamot"); - TEST(cloud->userId(), QStringLiteral("Zamot")); - - cloud->setVerificationStatus(0); - TEST(cloud->verificationStatus(), (short)0); - cloud->setVerificationStatus(1); - TEST(cloud->verificationStatus(), (short)1); + cloud->set_cloud_storage_newpassword("ABCD"); + TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCD")); + cloud->set_cloud_storage_newpassword("ABCDE"); + TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCDE")); + + cloud->set_cloud_storage_password("ABCDE"); + TEST(cloud->cloud_storage_password(), QStringLiteral("ABCDE")); + cloud->set_cloud_storage_password("ABCABC"); + TEST(cloud->cloud_storage_password(), QStringLiteral("ABCABC")); + + cloud->set_save_password_local(true); + TEST(cloud->save_password_local(), true); + cloud->set_save_password_local(false); + TEST(cloud->save_password_local(), false); + + cloud->set_save_userid_local(1); + TEST(cloud->save_userid_local(), true); + cloud->set_save_userid_local(0); + TEST(cloud->save_userid_local(), false); + + cloud->set_userid("Tomaz"); + TEST(cloud->userid(), QStringLiteral("Tomaz")); + cloud->set_userid("Zamot"); + TEST(cloud->userid(), QStringLiteral("Zamot")); + + cloud->set_cloud_verification_status(0); + TEST(cloud->cloud_verification_status(), (short)0); + cloud->set_cloud_verification_status(1); + TEST(cloud->cloud_verification_status(), (short)1); auto tecDetails = pref->techDetails; tecDetails->setModpO2(0.2); |