summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-06-16 10:08:34 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-04 05:32:30 +0800
commit2f951413303e10a80e540cacd0c6c282f8ce82cc (patch)
treed20a09bc203f93b65090727c2e3e68a42e985836
parentd02a03983d91da1d10aac5b0a5d84d15e94e9291 (diff)
downloadsubsurface-2f951413303e10a80e540cacd0c6c282f8ce82cc.tar.gz
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>
-rw-r--r--core/cloudstorage.cpp1
-rw-r--r--core/settings/qPref.cpp13
-rw-r--r--core/settings/qPref.h5
-rw-r--r--desktop-widgets/mainwindow.cpp1
-rw-r--r--desktop-widgets/preferences/preferences_network.cpp2
-rw-r--r--mobile-widgets/qmlmanager.cpp40
-rw-r--r--mobile-widgets/qmlprefs.cpp8
-rw-r--r--mobile-widgets/qmlprefs.h27
8 files changed, 45 insertions, 52 deletions
diff --git a/core/cloudstorage.cpp b/core/cloudstorage.cpp
index 89e4ba553..68b81fbbf 100644
--- a/core/cloudstorage.cpp
+++ b/core/cloudstorage.cpp
@@ -2,6 +2,7 @@
#include "cloudstorage.h"
#include "pref.h"
#include "qthelper.h"
+#include "settings/qPref.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QApplication>
diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp
index b703c1fcb..791ec44b8 100644
--- a/core/settings/qPref.cpp
+++ b/core/settings/qPref.cpp
@@ -2,17 +2,16 @@
#include "qPref_private.h"
#include "qPref.h"
-
-qPref *qPref::m_instance = NULL;
+qPref::qPref(QObject *parent) :
+ QObject(parent)
+{
+}
qPref *qPref::instance()
{
- if (!m_instance)
- m_instance = new qPref;
- return m_instance;
+static qPref *self = new qPref;
+ return self;
}
-
-
void qPref::loadSync(bool doSync)
{
}
diff --git a/core/settings/qPref.h b/core/settings/qPref.h
index 4170e5e64..f312f328a 100644
--- a/core/settings/qPref.h
+++ b/core/settings/qPref.h
@@ -7,10 +7,10 @@
class qPref : public QObject {
Q_OBJECT
+ Q_ENUMS(cloud_status);
public:
- qPref(QObject *parent = NULL) : QObject(parent) {};
- ~qPref() {};
+ qPref(QObject *parent = NULL);
static qPref *instance();
// Load/Sync local settings (disk) and struct preference
@@ -19,7 +19,6 @@ public:
public:
private:
- static qPref *m_instance;
};
#endif
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index a7cf6d82e..9ea1d25c0 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -47,6 +47,7 @@
#include "core/windowtitleupdate.h"
#include "desktop-widgets/locationinformation.h"
#include "preferences/preferencesdialog.h"
+#include "core/settings/qPref.h"
#ifndef NO_USERMANUAL
#include "usermanual.h"
diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp
index 710c96422..193a38c89 100644
--- a/desktop-widgets/preferences/preferences_network.cpp
+++ b/desktop-widgets/preferences/preferences_network.cpp
@@ -2,8 +2,8 @@
#include "preferences_network.h"
#include "ui_preferences_network.h"
#include "subsurfacewebservices.h"
-#include "core/dive.h"
#include "core/cloudstorage.h"
+#include "core/dive.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QNetworkProxy>
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 5269be9fe..137dc55e0 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -269,12 +269,12 @@ void QMLManager::openLocalThenRemote(QString url)
* no cloud repo solves this.
*/
- if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD)
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NEED_TO_VERIFY);
+ if (QMLPrefs::instance()->credentialStatus() != CS_NOCLOUD)
+ QMLPrefs::instance()->setCredentialStatus(CS_NEED_TO_VERIFY);
} else {
// if we can load from the cache, we know that we have a valid cloud account
- if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_UNKNOWN)
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED);
+ if (QMLPrefs::instance()->credentialStatus() == CS_UNKNOWN)
+ QMLPrefs::instance()->setCredentialStatus(CS_VERIFIED);
prefs.unit_system = git_prefs.unit_system;
if (git_prefs.unit_system == IMPERIAL)
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));
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"));
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
prefs.git_local_only = false;
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()->setCloudPassword(prefs.cloud_storage_password);
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
QString url;
if (!QMLPrefs::instance()->cloudUserName().isEmpty() &&
@@ -384,8 +384,8 @@ void QMLManager::finishSetup()
alreadySaving = true;
openLocalThenRemote(url);
} else if (!empty_string(existing_filename) &&
- QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_UNKNOWN) {
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD);
+ QMLPrefs::instance()->credentialStatus() != CS_UNKNOWN) {
+ QMLPrefs::instance()->setCredentialStatus(CS_NOCLOUD);
saveCloudCredentials();
appendTextToLog(tr("working in no-cloud mode"));
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));
}
} else {
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_UNKNOWN);
+ QMLPrefs::instance()->setCredentialStatus(CS_UNKNOWN);
appendTextToLog(tr("no cloud credentials"));
setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
}
@@ -437,7 +437,7 @@ void QMLManager::saveCloudCredentials()
bool cloudCredentialsChanged = false;
// make sure we only have letters, numbers, and +-_. in password and email address
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.
if (QMLPrefs::instance()->cloudPassword().isEmpty() ||
!regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() ||
@@ -467,7 +467,7 @@ void QMLManager::saveCloudCredentials()
cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password,
qPrintable(QMLPrefs::instance()->cloudPassword()));
- if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD &&
+ if (QMLPrefs::instance()->credentialStatus() != CS_NOCLOUD &&
!cloudCredentialsChanged) {
// just go back to the dive list
QMLPrefs::instance()->setCredentialStatus(QMLPrefs::instance()->oldStatus());
@@ -478,7 +478,7 @@ void QMLManager::saveCloudCredentials()
free((void *)prefs.cloud_storage_password);
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;
// since we already have dives in the table, let's remember that so we can keep them
noCloudToCloud = true;
@@ -508,7 +508,7 @@ void QMLManager::saveCloudCredentials()
currentGitLocalOnly = prefs.git_local_only;
prefs.git_local_only = false;
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()) {
// the user entered a PIN?
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
appendTextToLog("Cloud credentials are invalid");
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->abort();
reply->deleteLater();
@@ -622,7 +622,7 @@ void QMLManager::retrieveUserid()
revertToNoCloudIfNeeded();
return;
}
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED);
+ QMLPrefs::instance()->setCredentialStatus(CS_VERIFIED);
QString userid(prefs.userid);
if (userid.isEmpty()) {
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.sync();
}
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED);
+ QMLPrefs::instance()->setCredentialStatus(CS_VERIFIED);
setStartPageText(tr("Cloud credentials valid, loading dives..."));
// this only gets called with "alreadySaving" already locked
loadDivesWithValidCredentials();
@@ -726,7 +726,7 @@ void QMLManager::revertToNoCloudIfNeeded()
currentGitLocalOnly = false;
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,
// but connecting to the cloud account (and subsequently merging the local
// 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;
QMLPrefs::instance()->setCloudUserName("");
QMLPrefs::instance()->setCloudPassword("");
- QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD);
+ QMLPrefs::instance()->setCredentialStatus(CS_NOCLOUD);
set_filename(NOCLOUD_LOCALSTORAGE);
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()
{
if (unsaved_changes()) {
- if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_NOCLOUD) {
+ if (QMLPrefs::instance()->credentialStatus() == CS_NOCLOUD) {
if (empty_string(existing_filename)) {
char *filename = NOCLOUD_LOCALSTORAGE;
git_create_local_repo(filename);
diff --git a/mobile-widgets/qmlprefs.cpp b/mobile-widgets/qmlprefs.cpp
index 589234095..a166fdd5a 100644
--- a/mobile-widgets/qmlprefs.cpp
+++ b/mobile-widgets/qmlprefs.cpp
@@ -69,12 +69,12 @@ void QMLPrefs::setCloudUserName(const QString &cloudUserName)
emit cloudUserNameChanged();
}
-QMLPrefs::cloud_status_qml QMLPrefs::credentialStatus() const
+cloud_status QMLPrefs::credentialStatus() const
{
return m_credentialStatus;
}
-void QMLPrefs::setCredentialStatus(const cloud_status_qml value)
+void QMLPrefs::setCredentialStatus(const cloud_status value)
{
if (m_credentialStatus != value) {
setOldStatus(m_credentialStatus);
@@ -105,12 +105,12 @@ void QMLPrefs::setDistanceThreshold(int distance)
emit distanceThresholdChanged();
}
-QMLPrefs::cloud_status_qml QMLPrefs::oldStatus() const
+cloud_status QMLPrefs::oldStatus() const
{
return m_oldStatus;
}
-void QMLPrefs::setOldStatus(const cloud_status_qml value)
+void QMLPrefs::setOldStatus(const cloud_status value)
{
if (m_oldStatus != value) {
m_oldStatus = value;
diff --git a/mobile-widgets/qmlprefs.h b/mobile-widgets/qmlprefs.h
index 6acba5438..dc8de0686 100644
--- a/mobile-widgets/qmlprefs.h
+++ b/mobile-widgets/qmlprefs.h
@@ -3,11 +3,12 @@
#define QMLPREFS_H
#include <QObject>
+#include "core/settings/qPref.h"
class QMLPrefs : public QObject {
Q_OBJECT
- Q_ENUMS(cloud_status_qml)
+ Q_ENUMS(cloud_status)
Q_PROPERTY(QString cloudPassword
MEMBER m_cloudPassword
WRITE setCloudPassword
@@ -20,7 +21,7 @@ class QMLPrefs : public QObject {
MEMBER m_cloudUserName
WRITE setCloudUserName
NOTIFY cloudUserNameChanged)
- Q_PROPERTY(cloud_status_qml credentialStatus
+ Q_PROPERTY(cloud_status credentialStatus
MEMBER m_credentialStatus
WRITE setCredentialStatus
NOTIFY credentialStatusChanged)
@@ -36,7 +37,7 @@ class QMLPrefs : public QObject {
MEMBER m_showPin
WRITE setShowPin
NOTIFY showPinChanged)
- Q_PROPERTY(cloud_status_qml oldStatus
+ Q_PROPERTY(cloud_status oldStatus
MEMBER m_oldStatus
WRITE setOldStatus
NOTIFY oldStatusChanged)
@@ -55,14 +56,6 @@ public:
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;
void setCloudPassword(const QString &cloudPassword);
@@ -72,16 +65,16 @@ public:
const QString cloudUserName() const;
void setCloudUserName(const QString &cloudUserName);
- cloud_status_qml credentialStatus() const;
- void setCredentialStatus(const cloud_status_qml value);
+ cloud_status credentialStatus() const;
+ void setCredentialStatus(const cloud_status value);
void setDeveloper(bool value);
int distanceThreshold() const;
void setDistanceThreshold(int distance);
- cloud_status_qml oldStatus() const;
- void setOldStatus(const cloud_status_qml value);
+ cloud_status oldStatus() const;
+ void setOldStatus(const cloud_status value);
bool showPin() const;
void setShowPin(bool enable);
@@ -100,11 +93,11 @@ private:
QString m_cloudPassword;
QString m_cloudPin;
QString m_cloudUserName;
- cloud_status_qml m_credentialStatus;
+ cloud_status m_credentialStatus;
bool m_developer;
int m_distanceThreshold;
static QMLPrefs *m_instance;
- cloud_status_qml m_oldStatus;
+ cloud_status m_oldStatus;
bool m_showPin;
int m_timeThreshold;