mobile UI/login: replace use of cloudUserName

Replace prefs.cloudUserName with PrefCloudStorage.cloud_storage_email in QML

Replace QMLPrefs.....cloudUserName with PrefCloudStorage::cloud_storage_email in C++

Signed-off-by: Jan Iversen <jani@apache.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
jan Iversen 2019-12-20 16:35:12 +01:00 committed by Dirk Hohndel
parent 4b713ece96
commit ac28896a5d
4 changed files with 12 additions and 17 deletions

View file

@ -58,7 +58,7 @@ Item {
Controls.TextField {
id: login
text: prefs.cloudUserName
text: PrefCloudStorage.cloud_storage_email
visible: !prefs.showPin
Layout.fillWidth: true
inputMethodHints: Qt.ImhEmailCharactersOnly |

View file

@ -50,7 +50,7 @@ Kirigami.ScrollablePage {
"If you do not receive an email from us within 15 minutes, please check " +
"the correct spelling of your email address and your spam box first.<br/><br/>" +
"In case of any problems regarding cloud account setup, please contact us " +
"at our user forum \(https://subsurface-divelog.org/user-forum/\).<br/><br/>").arg(prefs.cloudUserName)
"at our user forum \(https://subsurface-divelog.org/user-forum/\).<br/><br/>").arg(PrefCloudStorage.cloud_storage_email)
wrapMode: Text.WordWrap
}
Item { width: Kirigami.Units.gridUnit; height: 3 * Kirigami.Units.gridUnit}

View file

@ -225,7 +225,7 @@ Kirigami.ApplicationWindow {
visible: text.length > 0
level: 3
color: "white"
text: prefs.cloudUserName
text: PrefCloudStorage.cloud_storage_email
wrapMode: Text.NoWrap
elide: Text.ElideRight
font.weight: Font.Normal

View file

@ -442,13 +442,12 @@ QString QMLManager::getCombinedLogs()
void QMLManager::finishSetup()
{
// Initialize cloud credentials.
QMLPrefs::instance()->setCloudUserName(qPrefCloudStorage::cloud_storage_email());
QMLPrefs::instance()->setCloudPassword(qPrefCloudStorage::cloud_storage_password());
git_local_only = !prefs.cloud_auto_sync;
QMLPrefs::instance()->setCredentialStatus((qPrefCloudStorage::cloud_status) prefs.cloud_verification_status);
// if the cloud credentials are valid, we should get the GPS Webservice ID as well
QString url;
if (!QMLPrefs::instance()->cloudUserName().isEmpty() &&
if (!qPrefCloudStorage::cloud_storage_email().isEmpty() &&
!QMLPrefs::instance()->cloudPassword().isEmpty() &&
getCloudURL(url) == 0) {
// we know that we are the first ones to access git storage, so we don't need to test,
@ -499,7 +498,6 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
bool cloudCredentialsChanged = false;
bool noCloud = QMLPrefs::instance()->credentialStatus() == qPrefCloudStorage::CS_NOCLOUD;
QMLPrefs::instance()->setCloudUserName(newEmail);
QMLPrefs::instance()->setCloudPassword(newPassword);
// make sure we only have letters, numbers, and +-_. in password and email address
@ -508,21 +506,18 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
// in case of NO_CLOUD, the email address + passwd do not care, so do not check it.
if (QMLPrefs::instance()->cloudPassword().isEmpty() ||
!regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() ||
!regExp.match(QMLPrefs::instance()->cloudUserName()).hasMatch()) {
!regExp.match(newEmail).hasMatch()) {
setStartPageText(RED_FONT + tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.") + END_FONT);
return;
}
// use the same simplistic regex as the backend to check email addresses
regExp = QRegularExpression("^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.+_-]+\\.[a-zA-Z0-9]+");
if (!regExp.match(QMLPrefs::instance()->cloudUserName()).hasMatch()) {
if (!regExp.match(newEmail).hasMatch()) {
setStartPageText(RED_FONT + tr("Invalid format for email address") + END_FONT);
return;
}
}
if (!same_string(prefs.cloud_storage_email,
qPrintable(QMLPrefs::instance()->cloudUserName()))) {
free((void *)prefs.cloud_storage_email);
prefs.cloud_storage_email = copy_qstring(QMLPrefs::instance()->cloudUserName());
if (!same_string(prefs.cloud_storage_email, qPrintable(newEmail))) {
cloudCredentialsChanged = true;
}
@ -536,10 +531,10 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
}
if (!noCloud &&
!verifyCredentials(QMLPrefs::instance()->cloudUserName(), QMLPrefs::instance()->cloudPassword(), QMLPrefs::instance()->cloudPin()))
!verifyCredentials(newEmail, QMLPrefs::instance()->cloudPassword(), QMLPrefs::instance()->cloudPin()))
return;
qPrefCloudStorage::set_cloud_storage_email(QMLPrefs::instance()->cloudUserName());
qPrefCloudStorage::set_cloud_storage_email(newEmail);
qPrefCloudStorage::set_cloud_storage_password(QMLPrefs::instance()->cloudPassword());
qPrefCloudStorage::set_cloud_verification_status(QMLPrefs::instance()->credentialStatus());
@ -554,7 +549,7 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
noCloudToCloud = true;
appendTextToLog("transitioning from no-cloud to cloud and have dives");
}
if (QMLPrefs::instance()->cloudUserName().isEmpty() ||
if (qPrefCloudStorage::cloud_storage_email().isEmpty() ||
QMLPrefs::instance()->cloudPassword().isEmpty()) {
setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
} else if (cloudCredentialsChanged) {
@ -832,7 +827,7 @@ void QMLManager::revertToNoCloudIfNeeded()
prefs.cloud_storage_email = NULL;
free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = NULL;
QMLPrefs::instance()->setCloudUserName("");
qPrefCloudStorage::set_cloud_storage_email("");
QMLPrefs::instance()->setCloudPassword("");
QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD);
set_filename(NOCLOUD_LOCALSTORAGE);