QML UI: Implement saving of cloud password

If the user ticks the 'Save Password' box, then we save the password
for future use.

Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com>
This commit is contained in:
Grace Karanja 2015-07-21 11:57:10 +03:00
parent b28517b9b0
commit ea11eff279
3 changed files with 30 additions and 4 deletions

View file

@ -50,6 +50,7 @@ Item {
}
CheckBox {
checked: manager.saveCloudPassword
id: savePassword
}
@ -63,6 +64,7 @@ Item {
onClicked: {
manager.cloudUserName = login.text
manager.cloudPassword = password.text
manager.saveCloudPassword = savePassword.checked
manager.savePreferences()
stackView.pop()
}

View file

@ -20,6 +20,7 @@ QMLManager::QMLManager()
//Initialize cloud credentials.
setCloudUserName(prefs.cloud_storage_email);
setCloudPassword(prefs.cloud_storage_password);
setSaveCloudPassword(prefs.save_password_local);
}
QMLManager::~QMLManager()
@ -31,15 +32,22 @@ void QMLManager::savePreferences()
QSettings s;
s.beginGroup("CloudStorage");
s.setValue("email", cloudUserName());
s.setValue("password", cloudPassword());
s.setValue("save_password_local", saveCloudPassword());
if (saveCloudPassword())
s.setValue("password", cloudPassword());
s.sync();
if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) {
free(prefs.cloud_storage_email);
prefs.cloud_storage_email = strdup(qPrintable(cloudUserName()));
}
if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) {
free(prefs.cloud_storage_password);
prefs.cloud_storage_password = strdup(qPrintable(cloudPassword()));
if (saveCloudPassword() != prefs.save_password_local) {
prefs.save_password_local = saveCloudPassword();
}
if (saveCloudPassword()) {
if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) {
free(prefs.cloud_storage_password);
prefs.cloud_storage_password = strdup(qPrintable(cloudPassword()));
}
}
}
@ -114,6 +122,16 @@ void QMLManager::saveChanges()
set_filename(fileName.toUtf8().data(), true);
mark_divelist_changed(false);
}
bool QMLManager::saveCloudPassword() const
{
return m_saveCloudPassword;
}
void QMLManager::setSaveCloudPassword(bool saveCloudPassword)
{
m_saveCloudPassword = saveCloudPassword;
}
QString QMLManager::cloudPassword() const
{

View file

@ -9,6 +9,7 @@ class QMLManager : public QObject
Q_OBJECT
Q_PROPERTY(QString cloudUserName READ cloudUserName WRITE setCloudUserName NOTIFY cloudUserNameChanged)
Q_PROPERTY(QString cloudPassword READ cloudPassword WRITE setCloudPassword NOTIFY cloudPasswordChanged)
Q_PROPERTY(bool saveCloudPassword READ saveCloudPassword WRITE setSaveCloudPassword NOTIFY saveCloudPasswordChanged)
public:
QMLManager();
~QMLManager();
@ -19,6 +20,9 @@ public:
QString cloudPassword() const;
void setCloudPassword(const QString &cloudPassword);
bool saveCloudPassword() const;
void setSaveCloudPassword(bool saveCloudPassword);
public slots:
void savePreferences();
void loadDives();
@ -27,10 +31,12 @@ public slots:
private:
QString m_cloudUserName;
QString m_cloudPassword;
bool m_saveCloudPassword;
signals:
void cloudUserNameChanged();
void cloudPasswordChanged();
void saveCloudPasswordChanged();
};
#endif