2018-07-12 19:01:31 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-08-14 10:25:15 +00:00
|
|
|
#include "qPrefCloudStorage.h"
|
2018-07-12 19:01:31 +00:00
|
|
|
#include "qPrefPrivate.h"
|
|
|
|
|
|
|
|
static const QString group = QStringLiteral("CloudStorage");
|
|
|
|
|
|
|
|
qPrefCloudStorage::qPrefCloudStorage(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
2018-09-07 00:13:48 +00:00
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
qPrefCloudStorage *qPrefCloudStorage::instance()
|
2018-07-12 19:01:31 +00:00
|
|
|
{
|
|
|
|
static qPrefCloudStorage *self = new qPrefCloudStorage;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qPrefCloudStorage::loadSync(bool doSync)
|
|
|
|
{
|
|
|
|
disk_cloud_base_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);
|
|
|
|
}
|
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPrefCloudStorage::set_cloud_base_url(const QString &value)
|
2018-07-12 19:01:31 +00:00
|
|
|
{
|
2018-07-18 20:52:13 +00:00
|
|
|
QString valueGit = value + "/git";
|
2018-07-12 19:01:31 +00:00
|
|
|
if (value != prefs.cloud_base_url) {
|
|
|
|
// only free and set if not default
|
|
|
|
if (prefs.cloud_base_url != default_prefs.cloud_base_url) {
|
2018-07-18 18:47:59 +00:00
|
|
|
qPrefPrivate::copy_txt(&prefs.cloud_base_url, value);
|
|
|
|
qPrefPrivate::copy_txt(&prefs.cloud_git_url, QString(prefs.cloud_base_url) + "/git");
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
disk_cloud_base_url(true);
|
2018-08-14 08:30:07 +00:00
|
|
|
emit instance()->cloud_base_url_changed(value);
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-26 16:26:17 +00:00
|
|
|
void qPrefCloudStorage::disk_cloud_base_url(bool doSync)
|
2018-07-12 19:01:31 +00:00
|
|
|
{
|
2018-07-26 16:26:17 +00:00
|
|
|
if (doSync) {
|
2018-09-07 16:06:00 +00:00
|
|
|
qPrefPrivate::propSetValue(keyFromGroupAndName(group, "cloud_base_url"), prefs.cloud_base_url, default_prefs.cloud_base_url);
|
2018-07-26 16:26:17 +00:00
|
|
|
} else {
|
2018-09-07 16:06:00 +00:00
|
|
|
prefs.cloud_base_url = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group, "cloud_base_url"), default_prefs.cloud_base_url).toString());
|
2018-07-26 16:26:17 +00:00
|
|
|
qPrefPrivate::copy_txt(&prefs.cloud_git_url, QString(prefs.cloud_base_url) + "/git");
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-25 17:49:48 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_TXT(CloudStorage, "email", cloud_storage_email);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_TXT(CloudStorage, "email_encoded", cloud_storage_email_encoded);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPrefCloudStorage::set_cloud_storage_newpassword(const QString &value)
|
2018-07-12 19:01:31 +00:00
|
|
|
{
|
|
|
|
if (value == prefs.cloud_storage_newpassword)
|
|
|
|
return;
|
|
|
|
|
2018-07-18 18:47:59 +00:00
|
|
|
qPrefPrivate::copy_txt(&prefs.cloud_storage_newpassword, value);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
|
|
|
// NOT saved on disk, because it is only temporary
|
2018-08-14 08:30:07 +00:00
|
|
|
emit instance()->cloud_storage_newpassword_changed(value);
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPrefCloudStorage::set_cloud_storage_password(const QString &value)
|
2018-07-12 19:01:31 +00:00
|
|
|
{
|
|
|
|
if (value != prefs.cloud_storage_password) {
|
2018-07-18 18:47:59 +00:00
|
|
|
qPrefPrivate::copy_txt(&prefs.cloud_storage_password, value);
|
2018-07-12 19:01:31 +00:00
|
|
|
disk_cloud_storage_password(true);
|
2018-08-14 08:30:07 +00:00
|
|
|
emit instance()->cloud_storage_password_changed(value);
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void qPrefCloudStorage::disk_cloud_storage_password(bool doSync)
|
|
|
|
{
|
2018-07-18 20:52:13 +00:00
|
|
|
if (doSync) {
|
2018-07-25 17:49:48 +00:00
|
|
|
if (prefs.save_password_local)
|
2018-09-07 16:06:00 +00:00
|
|
|
qPrefPrivate::propSetValue(keyFromGroupAndName(group, "password"), prefs.cloud_storage_password, default_prefs.cloud_storage_password);
|
2018-07-18 20:52:13 +00:00
|
|
|
} else {
|
2018-09-07 16:06:00 +00:00
|
|
|
prefs.cloud_storage_password = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group, "password"), default_prefs.cloud_storage_password).toString());
|
2018-07-18 20:52:13 +00:00
|
|
|
}
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_TXT(CloudStorage, "pin", cloud_storage_pin);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_INT(CloudStorage, "timeout", cloud_timeout);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_INT(CloudStorage, "cloud_verification_status", cloud_verification_status);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_BOOL(CloudStorage, "git_local_only", git_local_only);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_BOOL(CloudStorage, "save_password_local", save_password_local);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_BOOL(CloudStorage, "save_userid_local", save_userid_local);
|
2018-07-12 19:01:31 +00:00
|
|
|
|
|
|
|
SET_PREFERENCE_TXT(CloudStorage, userid);
|
|
|
|
void qPrefCloudStorage::disk_userid(bool doSync)
|
|
|
|
{
|
2018-07-24 19:33:11 +00:00
|
|
|
if (doSync) {
|
|
|
|
// always save in new position (part of cloud storage group)
|
2018-09-07 16:06:00 +00:00
|
|
|
qPrefPrivate::propSetValue(keyFromGroupAndName(group, "subsurface_webservice_uid"), prefs.userid, default_prefs.userid);
|
2018-07-24 19:33:11 +00:00
|
|
|
} else {
|
|
|
|
//WARNING: UserId was stored outside of any group.
|
|
|
|
// try to read from new location, if it fails read from old location
|
2018-09-07 16:06:00 +00:00
|
|
|
prefs.userid = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group, "subsurface_webservice_uid"), "NoUserIdHere").toString());
|
2018-07-24 19:33:11 +00:00
|
|
|
if (QString(prefs.userid) == "NoUserIdHere") {
|
|
|
|
const QString group = QStringLiteral("");
|
2018-09-07 16:06:00 +00:00
|
|
|
prefs.userid = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group,"subsurface_webservice_uid"), default_prefs.userid).toString());
|
2018-07-24 19:33:11 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-12 19:01:31 +00:00
|
|
|
}
|