core: remove double definition of enum cloud_storage_status

Remove cloud_storage_status from qmlprefs.h.
usage to qPref::

enum cloud_storage_status is not used from C, but only from C++, and
having the same structure defined multiple times is a maintenance
challenge.

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-06-16 10:08:34 +02:00 committed by Dirk Hohndel
parent d02a03983d
commit 2f95141330
8 changed files with 45 additions and 52 deletions

View file

@ -2,6 +2,7 @@
#include "cloudstorage.h" #include "cloudstorage.h"
#include "pref.h" #include "pref.h"
#include "qthelper.h" #include "qthelper.h"
#include "settings/qPref.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QApplication> #include <QApplication>

View file

@ -2,17 +2,16 @@
#include "qPref_private.h" #include "qPref_private.h"
#include "qPref.h" #include "qPref.h"
qPref::qPref(QObject *parent) :
qPref *qPref::m_instance = NULL; QObject(parent)
{
}
qPref *qPref::instance() qPref *qPref::instance()
{ {
if (!m_instance) static qPref *self = new qPref;
m_instance = new qPref; return self;
return m_instance;
} }
void qPref::loadSync(bool doSync) void qPref::loadSync(bool doSync)
{ {
} }

View file

@ -7,10 +7,10 @@
class qPref : public QObject { class qPref : public QObject {
Q_OBJECT Q_OBJECT
Q_ENUMS(cloud_status);
public: public:
qPref(QObject *parent = NULL) : QObject(parent) {}; qPref(QObject *parent = NULL);
~qPref() {};
static qPref *instance(); static qPref *instance();
// Load/Sync local settings (disk) and struct preference // Load/Sync local settings (disk) and struct preference
@ -19,7 +19,6 @@ public:
public: public:
private: private:
static qPref *m_instance;
}; };
#endif #endif

View file

@ -47,6 +47,7 @@
#include "core/windowtitleupdate.h" #include "core/windowtitleupdate.h"
#include "desktop-widgets/locationinformation.h" #include "desktop-widgets/locationinformation.h"
#include "preferences/preferencesdialog.h" #include "preferences/preferencesdialog.h"
#include "core/settings/qPref.h"
#ifndef NO_USERMANUAL #ifndef NO_USERMANUAL
#include "usermanual.h" #include "usermanual.h"

View file

@ -2,8 +2,8 @@
#include "preferences_network.h" #include "preferences_network.h"
#include "ui_preferences_network.h" #include "ui_preferences_network.h"
#include "subsurfacewebservices.h" #include "subsurfacewebservices.h"
#include "core/dive.h"
#include "core/cloudstorage.h" #include "core/cloudstorage.h"
#include "core/dive.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QNetworkProxy> #include <QNetworkProxy>

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() != QMLPrefs::CS_NOCLOUD) if (QMLPrefs::instance()->credentialStatus() != CS_NOCLOUD)
QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NEED_TO_VERIFY); QMLPrefs::instance()->setCredentialStatus(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() == QMLPrefs::CS_UNKNOWN) if (QMLPrefs::instance()->credentialStatus() == CS_UNKNOWN)
QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED); QMLPrefs::instance()->setCredentialStatus(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() == QMLPrefs::CS_NEED_TO_VERIFY) { if (QMLPrefs::instance()->credentialStatus() == 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() == QMLPrefs::CS_NOCLOUD) { if (QMLPrefs::instance()->oldStatus() == 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((QMLPrefs::cloud_status_qml) prefs.cloud_verification_status); QMLPrefs::instance()->setCredentialStatus((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() != QMLPrefs::CS_UNKNOWN) { QMLPrefs::instance()->credentialStatus() != CS_UNKNOWN) {
QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(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(QMLPrefs::CS_UNKNOWN); QMLPrefs::instance()->setCredentialStatus(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() != QMLPrefs::CS_NOCLOUD) { if (QMLPrefs::instance()->credentialStatus() != 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() != QMLPrefs::CS_NOCLOUD && if (QMLPrefs::instance()->credentialStatus() != 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() == QMLPrefs::CS_NOCLOUD && cloudCredentialsChanged && dive_table.nr) { if (QMLPrefs::instance()->oldStatus() == 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 == QMLPrefs::CS_NEED_TO_VERIFY && } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY &&
!QMLPrefs::instance()->cloudPin().isEmpty()) { !QMLPrefs::instance()->cloudPin().isEmpty()) {
// the user entered a PIN? // the user entered a PIN?
tryRetrieveDataFromBackend(); tryRetrieveDataFromBackend();
@ -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(QMLPrefs::CS_INCORRECT_USER_PASSWD); QMLPrefs::instance()->setCredentialStatus(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(QMLPrefs::CS_VERIFIED); QMLPrefs::instance()->setCredentialStatus(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(QMLPrefs::CS_VERIFIED); QMLPrefs::instance()->setCredentialStatus(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() == QMLPrefs::CS_NOCLOUD) { if (QMLPrefs::instance()->oldStatus() == 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(QMLPrefs::CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(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() == QMLPrefs::CS_NOCLOUD) { if (QMLPrefs::instance()->credentialStatus() == 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

@ -69,12 +69,12 @@ void QMLPrefs::setCloudUserName(const QString &cloudUserName)
emit cloudUserNameChanged(); emit cloudUserNameChanged();
} }
QMLPrefs::cloud_status_qml QMLPrefs::credentialStatus() const cloud_status QMLPrefs::credentialStatus() const
{ {
return m_credentialStatus; return m_credentialStatus;
} }
void QMLPrefs::setCredentialStatus(const cloud_status_qml value) void QMLPrefs::setCredentialStatus(const cloud_status value)
{ {
if (m_credentialStatus != value) { if (m_credentialStatus != value) {
setOldStatus(m_credentialStatus); setOldStatus(m_credentialStatus);
@ -105,12 +105,12 @@ void QMLPrefs::setDistanceThreshold(int distance)
emit distanceThresholdChanged(); emit distanceThresholdChanged();
} }
QMLPrefs::cloud_status_qml QMLPrefs::oldStatus() const cloud_status QMLPrefs::oldStatus() const
{ {
return m_oldStatus; return m_oldStatus;
} }
void QMLPrefs::setOldStatus(const cloud_status_qml value) void QMLPrefs::setOldStatus(const cloud_status value)
{ {
if (m_oldStatus != value) { if (m_oldStatus != value) {
m_oldStatus = value; m_oldStatus = value;

View file

@ -3,11 +3,12 @@
#define QMLPREFS_H #define QMLPREFS_H
#include <QObject> #include <QObject>
#include "core/settings/qPref.h"
class QMLPrefs : public QObject { class QMLPrefs : public QObject {
Q_OBJECT Q_OBJECT
Q_ENUMS(cloud_status_qml) Q_ENUMS(cloud_status)
Q_PROPERTY(QString cloudPassword Q_PROPERTY(QString cloudPassword
MEMBER m_cloudPassword MEMBER m_cloudPassword
WRITE setCloudPassword WRITE setCloudPassword
@ -20,7 +21,7 @@ class QMLPrefs : public QObject {
MEMBER m_cloudUserName MEMBER m_cloudUserName
WRITE setCloudUserName WRITE setCloudUserName
NOTIFY cloudUserNameChanged) NOTIFY cloudUserNameChanged)
Q_PROPERTY(cloud_status_qml credentialStatus Q_PROPERTY(cloud_status credentialStatus
MEMBER m_credentialStatus MEMBER m_credentialStatus
WRITE setCredentialStatus WRITE setCredentialStatus
NOTIFY credentialStatusChanged) NOTIFY credentialStatusChanged)
@ -36,7 +37,7 @@ class QMLPrefs : public QObject {
MEMBER m_showPin MEMBER m_showPin
WRITE setShowPin WRITE setShowPin
NOTIFY showPinChanged) NOTIFY showPinChanged)
Q_PROPERTY(cloud_status_qml oldStatus Q_PROPERTY(cloud_status oldStatus
MEMBER m_oldStatus MEMBER m_oldStatus
WRITE setOldStatus WRITE setOldStatus
NOTIFY oldStatusChanged) NOTIFY oldStatusChanged)
@ -55,14 +56,6 @@ public:
static QMLPrefs *instance(); static QMLPrefs *instance();
enum cloud_status_qml {
CS_UNKNOWN,
CS_INCORRECT_USER_PASSWD,
CS_NEED_TO_VERIFY,
CS_VERIFIED,
CS_NOCLOUD
};
const QString cloudPassword() const; const QString cloudPassword() const;
void setCloudPassword(const QString &cloudPassword); void setCloudPassword(const QString &cloudPassword);
@ -72,16 +65,16 @@ public:
const QString cloudUserName() const; const QString cloudUserName() const;
void setCloudUserName(const QString &cloudUserName); void setCloudUserName(const QString &cloudUserName);
cloud_status_qml credentialStatus() const; cloud_status credentialStatus() const;
void setCredentialStatus(const cloud_status_qml value); void setCredentialStatus(const cloud_status value);
void setDeveloper(bool value); void setDeveloper(bool value);
int distanceThreshold() const; int distanceThreshold() const;
void setDistanceThreshold(int distance); void setDistanceThreshold(int distance);
cloud_status_qml oldStatus() const; cloud_status oldStatus() const;
void setOldStatus(const cloud_status_qml value); void setOldStatus(const cloud_status value);
bool showPin() const; bool showPin() const;
void setShowPin(bool enable); void setShowPin(bool enable);
@ -100,11 +93,11 @@ private:
QString m_cloudPassword; QString m_cloudPassword;
QString m_cloudPin; QString m_cloudPin;
QString m_cloudUserName; QString m_cloudUserName;
cloud_status_qml m_credentialStatus; cloud_status m_credentialStatus;
bool m_developer; bool m_developer;
int m_distanceThreshold; int m_distanceThreshold;
static QMLPrefs *m_instance; static QMLPrefs *m_instance;
cloud_status_qml m_oldStatus; cloud_status m_oldStatus;
bool m_showPin; bool m_showPin;
int m_timeThreshold; int m_timeThreshold;