Settings QObjectification: cloud storage preferences

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2016-01-14 13:38:35 -02:00 committed by Dirk Hohndel
parent f5c69e3a56
commit 93762249fa
2 changed files with 184 additions and 3 deletions

View file

@ -641,3 +641,148 @@ void ProxySettings::setPass(const QString& value)
prefs.proxy_pass = copy_string(qPrintable(value));
emit passChanged(value);
}
CloudStorageSettings::CloudStorageSettings(QObject *parent) :
group(QStringLiteral("CloudStorage"))
{
}
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;
}
bool CloudStorageSettings::backgroundSync() const
{
return prefs.cloud_background_sync;
}
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)
{
QSettings s;
s.beginGroup(group);
s.setValue("password", value);
free(prefs.proxy_pass);
prefs.proxy_pass = copy_string(qPrintable(value));
emit passwordChanged(value);
}
void CloudStorageSettings::setNewPassword(const QString& value)
{
/*TODO: This looks like wrong, but 'new password' is not saved on disk, why it's on prefs? */
free(prefs.cloud_storage_newpassword);
prefs.cloud_storage_newpassword = copy_string(qPrintable(value));
emit newPasswordChanged(value);
}
void CloudStorageSettings::setEmail(const QString& value)
{
QSettings s;
s.beginGroup(group);
s.setValue("email", value);
free(prefs.cloud_storage_email);
prefs.cloud_storage_email = copy_string(qPrintable(value));
emit emailChanged(value);
}
void CloudStorageSettings::setUserId(const QString& value)
{
//WARNING: UserId is stored outside of any group, but it belongs to Cloud Storage.
QSettings s;
s.setValue("subsurface_webservice_uid", value);
free(prefs.userid);
prefs.userid = copy_string(qPrintable(value));
emit userIdChanged(value);
}
void CloudStorageSettings::setEmailEncoded(const QString& value)
{
/*TODO: This looks like wrong, but 'email encoded' is not saved on disk, why it's on prefs? */
free(prefs.cloud_storage_email_encoded);
prefs.cloud_storage_email_encoded = copy_string(qPrintable(value));
emit emailEncodedChanged(value);
}
void CloudStorageSettings::setSavePasswordLocal(bool value)
{
QSettings s;
s.beginGroup(group);
s.setValue("save_password_local", value);
free(prefs.save_password_local);
prefs.save_password_local = value;
emit savePasswordLocalChanged(value);
}
void CloudStorageSettings::setVerificationStatus(short value)
{
QSettings s;
s.beginGroup(group);
s.setValue("cloud_verification_status", value);
free(prefs.cloud_verification_status);
prefs.cloud_verification_status = value;
emit verificationStatusChanged(value);
}
void CloudStorageSettings::setBackgroundSync(bool value)
{
QSettings s;
s.beginGroup(group);
s.setValue("cloud_background_sync", value);
free(prefs.cloud_background_sync);
prefs.cloud_background_sync = copy_string(qPrintable(value));
emit backgroundSyncChanged(value);
}
void CloudStorageSettings::setBaseUrl(const QString& value)
{
free(prefs.cloud_base_url);
free(prefs.cloud_git_url);
prefs.cloud_base_url = copy_string(qPrintable(value));
prefs.cloud_git_url = strdup(qPrintable(QString(prefs.cloud_base_url) + "/git"));
}
void CloudStorageSettings::setCloudUrl(const QString& value) /* no-op */
{
Q_UNUSED(value);
}

View file

@ -253,11 +253,50 @@ class CloudStorageSettings : public QObject {
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_password_local READ savePasswordLocal WRITE setSavePasswordLocal NOTIFY savePasswordLocalChanged)
Q_PROPERTY(short verification_status READ verificationStatus WRITE setVerificationStatus NOTIFY verificationStatusChanged)
Q_PROPERTY(bool background_sync READ backgroundSync WRITE setBackgroundSync NOTIFY backgroundSyncChanged)
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 backgroundSync() 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 setCloudUrl(const QString& value);
void setSavePasswordLocal(bool value);
void setVerificationStatus(short value);
void setBackgroundSync(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 backgroundSyncChanged(bool value);
private:
QString group;
};
/* Monster class, should be breaken into a few more understandable classes later, wich will be easy to do:
@ -268,8 +307,6 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(QString divelist_font READ divelistFont WRITE setDivelistFont NOTIFY divelistFontChanged)
Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
Q_PROPERTY(QString default_cylinder READ defaultCylinder WRITE setDefaultCylinder NOTIFY defaultCylinderChanged)
Q_PROPERTY(QString cloud_base_url READ cloudBaseUrl WRITE setCloudBaseURL NOTIFY cloudBaseUrlChanged)
Q_PROPERTY(QString cloud_git_url READ cloudGitUrl WRITE setCloudGitUrl NOTIFY cloudGitUrlChanged)
Q_PROPERTY(QString time_format READ timeFormat WRITE setTimeFormat NOTIFY timeFormatChanged)
Q_PROPERTY(QString date_format READ dateFormat WRITE setDateFormat NOTIFY dateFormatChanged)
Q_PROPERTY(QString date_format_short READ dateFormatShort WRITE setDateFormatShort NOTIFY dateFormatShortChanged)
@ -281,7 +318,6 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(short unit_system READ unitSystem WRITE setUnitSystem NOTIFY uintSystemChanged)
Q_PROPERTY(bool coordinates_traditional READ coordinatesTraditional WRITE setCoordinatesTraditional NOTIFY coordinatesTraditionalChanged)
Q_PROPERTY(short save_userid_local READ saveUserIdLocal WRITE setSaveUserIdLocal NOTIFY saveUserIdLocalChanged)
Q_PROPERTY(QString userid READ userId WRITE setUserId NOTIFY userIdChanged)
Q_PROPERTY(int ascrate75 READ ascrate75 WRITE setAscrate75 NOTIFY ascrate75Changed)
Q_PROPERTY(int ascrate50 READ ascrate50 WRITE setAscrate50 NOTIFY ascrate50Changed)
Q_PROPERTY(int ascratestops READ ascratestops WRITE setAscratestops NOTIFY ascratestopsChanged)