diff options
author | jan Iversen <jani@apache.org> | 2018-07-12 21:01:31 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-21 07:49:25 -0700 |
commit | 4b68329c9db7ed13eaed7dd36ce6c82b1d7d11ca (patch) | |
tree | d8ef014e67beb0e3204c2c943b69e2324d3cbedd /core/settings/qPrefCloudStorage.cpp | |
parent | f23425c5587327620281519a4e4cf53286e4eac2 (diff) | |
download | subsurface-4b68329c9db7ed13eaed7dd36ce6c82b1d7d11ca.tar.gz |
core: create qPrefCloudStorage from SettingsObjectWrapper
Update set/get functions to follow common name scheme:
- get function have same name as in struct preferences
- set function have set_<name> (from struct preferences>)
- signal function have <name>_changed (from struct preferences>)
one class one .h/.cpp is the C++ idiom. Having load/sync of each
variable in 1 functions (in contrast to the distributed way SettingsObjectWrapper
handles it) secures the same storage name is used. Having the set/get/load/sync
functions grouped together makes it easier to get an overview.
REMARK: this commit only defines the class, it is not active in production
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core/settings/qPrefCloudStorage.cpp')
-rw-r--r-- | core/settings/qPrefCloudStorage.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/core/settings/qPrefCloudStorage.cpp b/core/settings/qPrefCloudStorage.cpp new file mode 100644 index 000000000..68e0bd027 --- /dev/null +++ b/core/settings/qPrefCloudStorage.cpp @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qPref.h" +#include "qPrefPrivate.h" + +static const QString group = QStringLiteral("CloudStorage"); + +qPrefCloudStorage::qPrefCloudStorage(QObject *parent) : QObject(parent) +{ +} +qPrefCloudStorage*qPrefCloudStorage::instance() +{ + static qPrefCloudStorage *self = new qPrefCloudStorage; + return self; +} + +void qPrefCloudStorage::loadSync(bool doSync) +{ + disk_cloud_base_url(doSync); + disk_cloud_git_url(doSync); + disk_cloud_storage_email(doSync); + disk_cloud_storage_email_encoded(doSync); + disk_cloud_storage_password(doSync); + disk_cloud_storage_pin(doSync); + disk_cloud_timeout(doSync); + disk_cloud_verification_status(doSync); + disk_git_local_only(doSync); + disk_save_password_local(doSync); + disk_save_userid_local(doSync); + disk_userid(doSync); +} + +GET_PREFERENCE_TXT(CloudStorage, cloud_base_url); +void qPrefCloudStorage::set_cloud_base_url(const QString& value) +{ + if (value != prefs.cloud_base_url) { + // only free and set if not default + if (prefs.cloud_base_url != default_prefs.cloud_base_url) { + COPY_TXT(cloud_base_url, value); + COPY_TXT(cloud_git_url, QString(prefs.cloud_base_url) + "/git"); + } + + disk_cloud_base_url(true); + emit cloud_base_url_changed(value); + } +} +void qPrefCloudStorage::disk_cloud_base_url(bool doSync) +{ + LOADSYNC_TXT("/cloud_base_url", cloud_base_url); + LOADSYNC_TXT("/cloud_git_url", cloud_git_url); +} + +GET_PREFERENCE_TXT(CloudStorage, cloud_git_url); +void qPrefCloudStorage::set_cloud_git_url(const QString& value) +{ + if (value != prefs.cloud_git_url) { + // only free and set if not default + if (prefs.cloud_git_url != default_prefs.cloud_git_url) { + COPY_TXT(cloud_git_url, value); + } + disk_cloud_git_url(true); + emit cloud_git_url_changed(value); + } +} +DISK_LOADSYNC_TXT(CloudStorage, "/cloud_git_url", cloud_git_url) + +HANDLE_PREFERENCE_TXT(CloudStorage, "/email", cloud_storage_email); + +HANDLE_PREFERENCE_TXT(CloudStorage, "/email_encoded", cloud_storage_email_encoded); + +GET_PREFERENCE_TXT(CloudStorage, cloud_storage_newpassword); +void qPrefCloudStorage::set_cloud_storage_newpassword(const QString& value) +{ + if (value == prefs.cloud_storage_newpassword) + return; + + COPY_TXT(cloud_storage_newpassword, value); + + // NOT saved on disk, because it is only temporary + emit cloud_storage_newpassword_changed(value); +} + +GET_PREFERENCE_TXT(CloudStorage, cloud_storage_password); +void qPrefCloudStorage::set_cloud_storage_password(const QString& value) +{ + if (value != prefs.cloud_storage_password) { + COPY_TXT(cloud_storage_password,value); + disk_cloud_storage_password(true); + emit cloud_storage_password_changed(value); + } +} +void qPrefCloudStorage::disk_cloud_storage_password(bool doSync) +{ + if (!doSync || prefs.save_password_local) + LOADSYNC_TXT("/password", cloud_storage_password); +} + +HANDLE_PREFERENCE_TXT(CloudStorage, "/pin", cloud_storage_pin); + +HANDLE_PREFERENCE_INT(CloudStorage, "/timeout", cloud_timeout); + +HANDLE_PREFERENCE_INT(CloudStorage, "/cloud_verification_status", cloud_verification_status); + +HANDLE_PREFERENCE_BOOL(CloudStorage, "/git_local_only", git_local_only); + +HANDLE_PREFERENCE_BOOL(CloudStorage, "/save_password_local", save_password_local); + +HANDLE_PREFERENCE_BOOL(CloudStorage, "/save_userid_local", save_userid_local); + +GET_PREFERENCE_TXT(CloudStorage, userid); +SET_PREFERENCE_TXT(CloudStorage, userid); +void qPrefCloudStorage::disk_userid(bool doSync) +{ + //WARNING: UserId is stored outside of any group, but it belongs to Cloud Storage. + const QString group = QStringLiteral(""); + LOADSYNC_TXT("subsurface_webservice_uid", userid); +} |