mobile-widgets: solve cloudstatus register problem

Use Q_ENUM instad of Q_ENUMS (which is depreciated) since it does the
meta registration for all Qt platforms.

Q_ENUM require the enum to be defined in the class and cannot refer to
a global class, therefore copied enum to class.

This commit is made to get the release to work, with minimal changes,
this class will be moved to qPref and the double definition solved

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-07-05 09:46:07 +02:00 committed by Dirk Hohndel
parent 5fc2e0f80f
commit 19803ab3c3
3 changed files with 39 additions and 31 deletions

View file

@ -269,12 +269,12 @@ void QMLManager::openLocalThenRemote(QString url)
* no cloud repo solves this. * no cloud repo solves this.
*/ */
if (QMLPrefs::instance()->credentialStatus() != CS_NOCLOUD) if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD)
QMLPrefs::instance()->setCredentialStatus(CS_NEED_TO_VERIFY); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NEED_TO_VERIFY);
} else { } else {
// if we can load from the cache, we know that we have a valid cloud account // if we can load from the cache, we know that we have a valid cloud account
if (QMLPrefs::instance()->credentialStatus() == CS_UNKNOWN) if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_UNKNOWN)
QMLPrefs::instance()->setCredentialStatus(CS_VERIFIED); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED);
prefs.unit_system = git_prefs.unit_system; prefs.unit_system = git_prefs.unit_system;
if (git_prefs.unit_system == IMPERIAL) if (git_prefs.unit_system == IMPERIAL)
git_prefs.units = IMPERIAL_units; git_prefs.units = IMPERIAL_units;
@ -292,11 +292,11 @@ void QMLManager::openLocalThenRemote(QString url)
appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr)); appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr));
setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr)); setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr));
} }
if (QMLPrefs::instance()->credentialStatus() == CS_NEED_TO_VERIFY) { if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_NEED_TO_VERIFY) {
appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN")); appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN"));
QMLPrefs::instance()->setShowPin(true); QMLPrefs::instance()->setShowPin(true);
} }
if (QMLPrefs::instance()->oldStatus() == CS_NOCLOUD) { if (QMLPrefs::instance()->oldStatus() == QMLPrefs::CS_NOCLOUD) {
// if we switch to credentials from CS_NOCLOUD, we take things online temporarily // if we switch to credentials from CS_NOCLOUD, we take things online temporarily
prefs.git_local_only = false; prefs.git_local_only = false;
appendTextToLog(QStringLiteral("taking things online to be able to switch to cloud account")); appendTextToLog(QStringLiteral("taking things online to be able to switch to cloud account"));
@ -373,7 +373,7 @@ void QMLManager::finishSetup()
QMLPrefs::instance()->setCloudUserName(prefs.cloud_storage_email); QMLPrefs::instance()->setCloudUserName(prefs.cloud_storage_email);
QMLPrefs::instance()->setCloudPassword(prefs.cloud_storage_password); QMLPrefs::instance()->setCloudPassword(prefs.cloud_storage_password);
setSyncToCloud(!prefs.git_local_only); setSyncToCloud(!prefs.git_local_only);
QMLPrefs::instance()->setCredentialStatus((cloud_status) prefs.cloud_verification_status); QMLPrefs::instance()->setCredentialStatus((QMLPrefs::cloud_status) prefs.cloud_verification_status);
// if the cloud credentials are valid, we should get the GPS Webservice ID as well // if the cloud credentials are valid, we should get the GPS Webservice ID as well
QString url; QString url;
if (!QMLPrefs::instance()->cloudUserName().isEmpty() && if (!QMLPrefs::instance()->cloudUserName().isEmpty() &&
@ -384,8 +384,8 @@ void QMLManager::finishSetup()
alreadySaving = true; alreadySaving = true;
openLocalThenRemote(url); openLocalThenRemote(url);
} else if (!empty_string(existing_filename) && } else if (!empty_string(existing_filename) &&
QMLPrefs::instance()->credentialStatus() != CS_UNKNOWN) { QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_UNKNOWN) {
QMLPrefs::instance()->setCredentialStatus(CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD);
saveCloudCredentials(); saveCloudCredentials();
appendTextToLog(tr("working in no-cloud mode")); appendTextToLog(tr("working in no-cloud mode"));
int error = parse_file(existing_filename); int error = parse_file(existing_filename);
@ -399,7 +399,7 @@ void QMLManager::finishSetup()
appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename));
} }
} else { } else {
QMLPrefs::instance()->setCredentialStatus(CS_UNKNOWN); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_UNKNOWN);
appendTextToLog(tr("no cloud credentials")); appendTextToLog(tr("no cloud credentials"));
setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
} }
@ -437,7 +437,7 @@ void QMLManager::saveCloudCredentials()
bool cloudCredentialsChanged = false; bool cloudCredentialsChanged = false;
// make sure we only have letters, numbers, and +-_. in password and email address // make sure we only have letters, numbers, and +-_. in password and email address
QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$"); QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$");
if (QMLPrefs::instance()->credentialStatus() != CS_NOCLOUD) { if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD) {
// in case of NO_CLOUD, the email address + passwd do not care, so do not check it. // in case of NO_CLOUD, the email address + passwd do not care, so do not check it.
if (QMLPrefs::instance()->cloudPassword().isEmpty() || if (QMLPrefs::instance()->cloudPassword().isEmpty() ||
!regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() || !regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() ||
@ -467,7 +467,7 @@ void QMLManager::saveCloudCredentials()
cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password,
qPrintable(QMLPrefs::instance()->cloudPassword())); qPrintable(QMLPrefs::instance()->cloudPassword()));
if (QMLPrefs::instance()->credentialStatus() != CS_NOCLOUD && if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD &&
!cloudCredentialsChanged) { !cloudCredentialsChanged) {
// just go back to the dive list // just go back to the dive list
QMLPrefs::instance()->setCredentialStatus(QMLPrefs::instance()->oldStatus()); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::instance()->oldStatus());
@ -478,7 +478,7 @@ void QMLManager::saveCloudCredentials()
free((void *)prefs.cloud_storage_password); free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = copy_qstring(QMLPrefs::instance()->cloudPassword()); prefs.cloud_storage_password = copy_qstring(QMLPrefs::instance()->cloudPassword());
} }
if (QMLPrefs::instance()->oldStatus() == CS_NOCLOUD && cloudCredentialsChanged && dive_table.nr) { if (QMLPrefs::instance()->oldStatus() == QMLPrefs::CS_NOCLOUD && cloudCredentialsChanged && dive_table.nr) {
// we came from NOCLOUD and are connecting to a cloud account; // we came from NOCLOUD and are connecting to a cloud account;
// since we already have dives in the table, let's remember that so we can keep them // since we already have dives in the table, let's remember that so we can keep them
noCloudToCloud = true; noCloudToCloud = true;
@ -508,7 +508,7 @@ void QMLManager::saveCloudCredentials()
currentGitLocalOnly = prefs.git_local_only; currentGitLocalOnly = prefs.git_local_only;
prefs.git_local_only = false; prefs.git_local_only = false;
openLocalThenRemote(url); openLocalThenRemote(url);
} else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY && } else if (prefs.cloud_verification_status == QMLPrefs::CS_NEED_TO_VERIFY &&
!QMLPrefs::instance()->cloudPin().isEmpty()) { !QMLPrefs::instance()->cloudPin().isEmpty()) {
// the user entered a PIN? // the user entered a PIN?
tryRetrieveDataFromBackend(); tryRetrieveDataFromBackend();
@ -542,12 +542,12 @@ void QMLManager::tryRetrieveDataFromBackend()
} }
myTimer.stop(); myTimer.stop();
QMLPrefs::instance()->setCloudPin(""); QMLPrefs::instance()->setCloudPin("");
if (prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD) { if (prefs.cloud_verification_status == QMLPrefs::CS_INCORRECT_USER_PASSWD) {
appendTextToLog(QStringLiteral("Incorrect cloud credentials")); appendTextToLog(QStringLiteral("Incorrect cloud credentials"));
setStartPageText(RED_FONT + tr("Incorrect cloud credentials") + END_FONT); setStartPageText(RED_FONT + tr("Incorrect cloud credentials") + END_FONT);
revertToNoCloudIfNeeded(); revertToNoCloudIfNeeded();
return; return;
} else if (prefs.cloud_verification_status != CS_VERIFIED) { } else if (prefs.cloud_verification_status != QMLPrefs::CS_VERIFIED) {
// here we need to enter the PIN // here we need to enter the PIN
appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN")); appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN"));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT); setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT);
@ -578,7 +578,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth)
// OK, credentials have been tried and didn't work, so they are invalid // OK, credentials have been tried and didn't work, so they are invalid
appendTextToLog("Cloud credentials are invalid"); appendTextToLog("Cloud credentials are invalid");
setStartPageText(RED_FONT + tr("Cloud credentials are invalid") + END_FONT); setStartPageText(RED_FONT + tr("Cloud credentials are invalid") + END_FONT);
QMLPrefs::instance()->setCredentialStatus(CS_INCORRECT_USER_PASSWD); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_INCORRECT_USER_PASSWD);
reply->disconnect(); reply->disconnect();
reply->abort(); reply->abort();
reply->deleteLater(); reply->deleteLater();
@ -622,7 +622,7 @@ void QMLManager::retrieveUserid()
revertToNoCloudIfNeeded(); revertToNoCloudIfNeeded();
return; return;
} }
QMLPrefs::instance()->setCredentialStatus(CS_VERIFIED); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED);
QString userid(prefs.userid); QString userid(prefs.userid);
if (userid.isEmpty()) { if (userid.isEmpty()) {
if (empty_string(prefs.cloud_storage_email) || empty_string(prefs.cloud_storage_password)) { if (empty_string(prefs.cloud_storage_email) || empty_string(prefs.cloud_storage_password)) {
@ -641,7 +641,7 @@ void QMLManager::retrieveUserid()
s.setValue("subsurface_webservice_uid", prefs.userid); s.setValue("subsurface_webservice_uid", prefs.userid);
s.sync(); s.sync();
} }
QMLPrefs::instance()->setCredentialStatus(CS_VERIFIED); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED);
setStartPageText(tr("Cloud credentials valid, loading dives...")); setStartPageText(tr("Cloud credentials valid, loading dives..."));
// this only gets called with "alreadySaving" already locked // this only gets called with "alreadySaving" already locked
loadDivesWithValidCredentials(); loadDivesWithValidCredentials();
@ -726,7 +726,7 @@ void QMLManager::revertToNoCloudIfNeeded()
currentGitLocalOnly = false; currentGitLocalOnly = false;
prefs.git_local_only = true; prefs.git_local_only = true;
} }
if (QMLPrefs::instance()->oldStatus() == CS_NOCLOUD) { if (QMLPrefs::instance()->oldStatus() == QMLPrefs::CS_NOCLOUD) {
// we tried to switch to a cloud account and had previously used local data, // we tried to switch to a cloud account and had previously used local data,
// but connecting to the cloud account (and subsequently merging the local // but connecting to the cloud account (and subsequently merging the local
// and cloud data) failed - so let's delete the cloud credentials and go // and cloud data) failed - so let's delete the cloud credentials and go
@ -742,7 +742,7 @@ void QMLManager::revertToNoCloudIfNeeded()
prefs.cloud_storage_password = NULL; prefs.cloud_storage_password = NULL;
QMLPrefs::instance()->setCloudUserName(""); QMLPrefs::instance()->setCloudUserName("");
QMLPrefs::instance()->setCloudPassword(""); QMLPrefs::instance()->setCloudPassword("");
QMLPrefs::instance()->setCredentialStatus(CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD);
set_filename(NOCLOUD_LOCALSTORAGE); set_filename(NOCLOUD_LOCALSTORAGE);
setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT);
} }
@ -1202,7 +1202,7 @@ void QMLManager::openNoCloudRepo()
void QMLManager::saveChangesLocal() void QMLManager::saveChangesLocal()
{ {
if (unsaved_changes()) { if (unsaved_changes()) {
if (QMLPrefs::instance()->credentialStatus() == CS_NOCLOUD) { if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_NOCLOUD) {
if (empty_string(existing_filename)) { if (empty_string(existing_filename)) {
char *filename = NOCLOUD_LOCALSTORAGE; char *filename = NOCLOUD_LOCALSTORAGE;
git_create_local_repo(filename); git_create_local_repo(filename);

View file

@ -11,10 +11,10 @@
QMLPrefs *QMLPrefs::m_instance = NULL; QMLPrefs *QMLPrefs::m_instance = NULL;
QMLPrefs::QMLPrefs() : QMLPrefs::QMLPrefs() :
m_credentialStatus(CS_UNKNOWN), m_credentialStatus(QMLPrefs::CS_UNKNOWN),
m_developer(false), m_developer(false),
m_distanceThreshold(1000), m_distanceThreshold(1000),
m_oldStatus(CS_UNKNOWN), m_oldStatus(QMLPrefs::CS_UNKNOWN),
m_showPin(false), m_showPin(false),
m_timeThreshold(60) m_timeThreshold(60)
{ {
@ -69,16 +69,16 @@ void QMLPrefs::setCloudUserName(const QString &cloudUserName)
emit cloudUserNameChanged(); emit cloudUserNameChanged();
} }
cloud_status QMLPrefs::credentialStatus() const QMLPrefs::cloud_status QMLPrefs::credentialStatus() const
{ {
return m_credentialStatus; return m_credentialStatus;
} }
void QMLPrefs::setCredentialStatus(const cloud_status value) void QMLPrefs::setCredentialStatus(const QMLPrefs::cloud_status value)
{ {
if (m_credentialStatus != value) { if (m_credentialStatus != value) {
setOldStatus(m_credentialStatus); setOldStatus(m_credentialStatus);
if (value == CS_NOCLOUD) { if (value == QMLPrefs::CS_NOCLOUD) {
QMLManager::instance()->appendTextToLog("Switching to no cloud mode"); QMLManager::instance()->appendTextToLog("Switching to no cloud mode");
set_filename(NOCLOUD_LOCALSTORAGE); set_filename(NOCLOUD_LOCALSTORAGE);
clearCredentials(); clearCredentials();
@ -105,12 +105,12 @@ void QMLPrefs::setDistanceThreshold(int distance)
emit distanceThresholdChanged(); emit distanceThresholdChanged();
} }
cloud_status QMLPrefs::oldStatus() const QMLPrefs::cloud_status QMLPrefs::oldStatus() const
{ {
return m_oldStatus; return m_oldStatus;
} }
void QMLPrefs::setOldStatus(const cloud_status value) void QMLPrefs::setOldStatus(const QMLPrefs::cloud_status value)
{ {
if (m_oldStatus != value) { if (m_oldStatus != value) {
m_oldStatus = value; m_oldStatus = value;
@ -177,7 +177,7 @@ void QMLPrefs::cancelCredentialsPinSetup()
*/ */
QSettings s; QSettings s;
setCredentialStatus(CS_UNKNOWN); setCredentialStatus(QMLPrefs::CS_UNKNOWN);
s.beginGroup("CloudStorage"); s.beginGroup("CloudStorage");
s.setValue("email", m_cloudUserName); s.setValue("email", m_cloudUserName);
s.setValue("password", m_cloudPassword); s.setValue("password", m_cloudPassword);

View file

@ -8,7 +8,7 @@
class QMLPrefs : public QObject { class QMLPrefs : public QObject {
Q_OBJECT Q_OBJECT
Q_ENUMS(cloud_status) Q_ENUM(cloud_status)
Q_PROPERTY(QString cloudPassword Q_PROPERTY(QString cloudPassword
MEMBER m_cloudPassword MEMBER m_cloudPassword
WRITE setCloudPassword WRITE setCloudPassword
@ -51,6 +51,14 @@ class QMLPrefs : public QObject {
NOTIFY timeThresholdChanged) NOTIFY timeThresholdChanged)
public: public:
enum cloud_status {
CS_UNKNOWN,
CS_INCORRECT_USER_PASSWD,
CS_NEED_TO_VERIFY,
CS_VERIFIED,
CS_NOCLOUD
};
QMLPrefs(); QMLPrefs();
~QMLPrefs(); ~QMLPrefs();