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 /core | |
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>
Diffstat (limited to 'core')
-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 |
4 files changed, 9 insertions, 266 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; |