diff options
author | jan Iversen <jani@apache.org> | 2018-06-13 18:06:11 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-06-15 14:12:14 -0700 |
commit | b8eb348f546291c49e2d606649b3c85d23e43782 (patch) | |
tree | 8ca54d1f5aa363496de4b83e1b6200b92304a8a3 /mobile-widgets | |
parent | 62ca5e90e13d65235d3cd53feffd0cb62cfbac43 (diff) | |
download | subsurface-b8eb348f546291c49e2d606649b3c85d23e43782.tar.gz |
mobile: move settings from qmlmanager to qmlprefs
add settings variables/functions to qmlprefs
remove settings variables/functions from qmlmanager
change manager. to prefs. in qml files for setting variables/functions
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qml/CloudCredentials.qml | 12 | ||||
-rw-r--r-- | mobile-widgets/qml/DiveList.qml | 17 | ||||
-rw-r--r-- | mobile-widgets/qml/Settings.qml | 33 | ||||
-rw-r--r-- | mobile-widgets/qml/main.qml | 30 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 233 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 69 | ||||
-rw-r--r-- | mobile-widgets/qmlprefs.cpp | 179 | ||||
-rw-r--r-- | mobile-widgets/qmlprefs.h | 99 |
8 files changed, 389 insertions, 283 deletions
diff --git a/mobile-widgets/qml/CloudCredentials.qml b/mobile-widgets/qml/CloudCredentials.qml index 52a7162ce..b32323d05 100644 --- a/mobile-widgets/qml/CloudCredentials.qml +++ b/mobile-widgets/qml/CloudCredentials.qml @@ -15,9 +15,9 @@ Item { property string password: password.text; function saveCredentials() { - manager.cloudUserName = login.text - manager.cloudPassword = password.text - manager.cloudPin = pin.text + prefs.cloudUserName = login.text + prefs.cloudPassword = password.text + prefs.cloudPin = pin.text manager.saveCloudCredentials() } @@ -60,7 +60,7 @@ Item { Controls.TextField { id: login - text: manager.cloudUserName + text: prefs.cloudUserName visible: !rootItem.showPin Layout.fillWidth: true inputMethodHints: Qt.ImhEmailCharactersOnly | @@ -76,7 +76,7 @@ Item { Controls.TextField { id: password - text: manager.cloudPassword + text: prefs.cloudPassword visible: !rootItem.showPin echoMode: TextInput.PasswordEchoOnEdit inputMethodHints: Qt.ImhSensitiveData | @@ -146,7 +146,7 @@ Item { text: qsTr("No cloud mode") onClicked: { manager.syncToCloud = false - manager.credentialStatus = QMLManager.CS_NOCLOUD + manager.credentialStatus = QMLPrefs.CS_NOCLOUD manager.saveCloudCredentials() manager.openNoCloudRepo() } diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index 31b2204fa..36929951a 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -13,7 +13,7 @@ Kirigami.ScrollablePage { title: qsTr("Dive list") verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff width: subsurfaceTheme.columnWidth - property int credentialStatus: manager.credentialStatus + property int credentialStatus: prefs.credentialStatus property int numDives: diveListView.count property color textColor: subsurfaceTheme.textColor property color secondaryTextColor: subsurfaceTheme.secondaryTextColor @@ -23,14 +23,14 @@ Kirigami.ScrollablePage { supportsRefreshing: true onRefreshingChanged: { if (refreshing) { - if (manager.credentialStatus === QMLManager.CS_VERIFIED) { + if (prefs.credentialStatus === QMLPrefs.CS_VERIFIED) { console.log("User pulled down dive list - syncing with cloud storage") detailsWindow.endEditMode() manager.saveChangesCloud(true) console.log("done syncing, turn off spinner") refreshing = false } else { - console.log("sync with cloud storage requested, but credentialStatus is " + manager.credentialStatus) + console.log("sync with cloud storage requested, but credentialStatus is " + prefs.credentialStatus) console.log("no syncing, turn off spinner") refreshing = false } @@ -339,7 +339,8 @@ Kirigami.ScrollablePage { StartPage { id: startPage anchors.fill: parent - opacity: credentialStatus === QMLManager.CS_NOCLOUD || (credentialStatus === QMLManager.CS_VERIFIED) ? 0 : 1 + opacity: credentialStatus === QMLPrefs.CS_NOCLOUD || + (credentialStatus === QMLPrefs.CS_VERIFIED) ? 0 : 1 visible: opacity > 0 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } function setupActions() { @@ -347,7 +348,8 @@ Kirigami.ScrollablePage { page.actions.main = null page.actions.right = null page.title = qsTr("Cloud credentials") - } else if (manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD) { + } else if (prefs.credentialStatus === QMLPrefs.CS_VERIFIED || + prefs.credentialStatus === QMLPrefs.CS_NOCLOUD) { page.actions.main = page.downloadFromDCAction page.actions.right = page.addDiveAction page.title = qsTr("Dive list") @@ -424,8 +426,9 @@ Kirigami.ScrollablePage { } onBackRequested: { - if (startPage.visible && diveListView.count > 0 && manager.credentialStatus !== QMLManager.CS_INCORRECT_USER_PASSWD) { - manager.credentialStatus = oldStatus + if (startPage.visible && diveListView.count > 0 && + prefs.credentialStatus !== QMLPrefs.CS_INCORRECT_USER_PASSWD) { + prefs.credentialStatus = oldStatus event.accepted = true; } if (!startPage.visible) { diff --git a/mobile-widgets/qml/Settings.qml b/mobile-widgets/qml/Settings.qml index 40ee2ea08..3c567f156 100644 --- a/mobile-widgets/qml/Settings.qml +++ b/mobile-widgets/qml/Settings.qml @@ -42,7 +42,8 @@ Kirigami.ScrollablePage { Layout.preferredHeight: Kirigami.Units.gridUnit * 2 } Controls.Label { - text: manager.credentialStatus === QMLManager.CS_NOCLOUD ? qsTr("Not applicable") : manager.cloudUserName + text: prefs.credentialStatus === QMLPrefs.CS_NOCLOUD ? qsTr("Not applicable") : + prefs.cloudUserName Layout.alignment: Qt.AlignRight Layout.preferredWidth: gridWidth * 0.60 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 @@ -63,7 +64,7 @@ Kirigami.ScrollablePage { Layout.preferredHeight: Kirigami.Units.gridUnit * 2 } Controls.Label { - text: describe[manager.credentialStatus] + text: describe[prefs.credentialStatus] Layout.alignment: Qt.AlignRight Layout.preferredWidth: gridWidth * 0.60 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 @@ -136,8 +137,8 @@ Kirigami.ScrollablePage { enabled: subsurfaceTheme.currentTheme !== "Blue" onClicked: { blueTheme() - manager.theme = subsurfaceTheme.currentTheme - manager.savePreferences() + prefs.theme = subsurfaceTheme.currentTheme + prefs.savePreferences() } } @@ -189,8 +190,8 @@ Kirigami.ScrollablePage { enabled: subsurfaceTheme.currentTheme !== "Pink" onClicked: { pinkTheme() - manager.theme = subsurfaceTheme.currentTheme - manager.savePreferences() + prefs.theme = subsurfaceTheme.currentTheme + prefs.savePreferences() } } @@ -241,8 +242,8 @@ Kirigami.ScrollablePage { enabled: subsurfaceTheme.currentTheme !== "Dark" onClicked: { darkTheme() - manager.theme = subsurfaceTheme.currentTheme - manager.savePreferences() + prefs.theme = subsurfaceTheme.currentTheme + prefs.savePreferences() } } } @@ -275,11 +276,11 @@ Kirigami.ScrollablePage { Controls.TextField { id: distanceThreshold - text: manager.distanceThreshold + text: prefs.distanceThreshold Layout.preferredWidth: gridWidth * 0.25 onEditingFinished: { - manager.distanceThreshold = distanceThreshold.text - manager.savePreferences() + prefs.distanceThreshold = distanceThreshold.text + prefs.savePreferences() } } @@ -291,11 +292,11 @@ Kirigami.ScrollablePage { Controls.TextField { id: timeThreshold - text: manager.timeThreshold + text: prefs.timeThreshold Layout.preferredWidth: gridWidth * 0.25 onEditingFinished: { - manager.timeThreshold = timeThreshold.text - manager.savePreferences() + prefs.timeThreshold = timeThreshold.text + prefs.savePreferences() } } @@ -325,10 +326,10 @@ Kirigami.ScrollablePage { } SsrfSwitch { id: developerButton - checked: manager.developer + checked: prefs.developer Layout.preferredWidth: gridWidth * 0.25 onClicked: { - manager.developer = checked + prefs.developer = checked } } } diff --git a/mobile-widgets/qml/main.qml b/mobile-widgets/qml/main.qml index 28f16a9b8..125d964ec 100644 --- a/mobile-widgets/qml/main.qml +++ b/mobile-widgets/qml/main.qml @@ -20,11 +20,11 @@ Kirigami.ApplicationWindow { maximumHeight: Kirigami.Units.gridUnit * 2 background: Rectangle { color: subsurfaceTheme.primaryColor } } - property alias oldStatus: manager.oldStatus + property alias oldStatus: prefs.oldStatus property alias notificationText: manager.notificationText property alias syncToCloud: manager.syncToCloud property alias locationServiceEnabled: manager.locationServiceEnabled - property alias showPin: manager.showPin + property alias showPin: prefs.showPin onNotificationTextChanged: { if (notificationText != "") { // there's a risk that we have a >5 second gap in update events; @@ -119,12 +119,12 @@ Kirigami.ApplicationWindow { } text: qsTr("Dive list") onTriggered: { - manager.appendTextToLog("requested dive list with credential status " + manager.credentialStatus) - if (manager.credentialStatus == QMLManager.CS_UNKNOWN) { + manager.appendTextToLog("requested dive list with credential status " + prefs.credentialStatus) + if (prefs.credentialStatus == QMLPrefs.CS_UNKNOWN) { // the user has asked to change credentials - if the credentials before that // were valid, go back to dive list - if (oldStatus == QMLManager.CS_VERIFIED) { - manager.credentialStatus = oldStatus + if (oldStatus == QMLPrefs.CS_VERIFIED) { + prefs.credentialStatus = oldStatus } } returnTopPage() @@ -150,7 +150,8 @@ Kirigami.ApplicationWindow { name: ":/icons/ic_add.svg" } text: qsTr("Add dive manually") - enabled: manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD + enabled: prefs.credentialStatus === QMLPrefs.CS_VERIFIED || + prefs.credentialStatus === QMLPrefs.CS_NOCLOUD onTriggered: { globalDrawer.close() returnTopPage() // otherwise odd things happen with the page stack @@ -184,13 +185,14 @@ Kirigami.ApplicationWindow { name: ":/icons/cloud_sync.svg" } text: qsTr("Manual sync with cloud") - enabled: manager.credentialStatus === QMLManager.CS_VERIFIED || manager.credentialStatus === QMLManager.CS_NOCLOUD + enabled: prefs.credentialStatus === QMLPrefs.CS_VERIFIED || + prefs.credentialStatus === QMLPrefs.CS_NOCLOUD onTriggered: { - if (manager.credentialStatus === QMLManager.CS_NOCLOUD) { + if (prefs.credentialStatus === QMLPrefs.CS_NOCLOUD) { returnTopPage() - oldStatus = manager.credentialStatus + oldStatus = prefs.credentialStatus manager.startPageText = "Enter valid cloud storage credentials" - manager.credentialStatus = QMLManager.CS_UNKNOWN + prefs.credentialStatus = QMLPrefs.CS_UNKNOWN globalDrawer.close() } else { globalDrawer.close() @@ -205,7 +207,7 @@ Kirigami.ApplicationWindow { name: syncToCloud ? ":/icons/ic_cloud_off.svg" : ":/icons/ic_cloud_done.svg" } text: syncToCloud ? qsTr("Disable auto cloud sync") : qsTr("Enable auto cloud sync") - enabled: manager.credentialStatus !== QMLManager.CS_NOCLOUD + enabled: prefs.credentialStatus !== QMLPrefs.CS_NOCLOUD onTriggered: { syncToCloud = !syncToCloud if (!syncToCloud) { @@ -307,7 +309,7 @@ if you have network connectivity and want to sync your data to cloud storage."), name: ":/icons/ic_adb.svg" } text: qsTr("Developer") - visible: manager.developer + visible: prefs.developer Kirigami.Action { text: qsTr("App log") onTriggered: { @@ -452,7 +454,7 @@ if you have network connectivity and want to sync your data to cloud storage."), property int columnWidth: Math.round(rootItem.width/(Kirigami.Units.gridUnit*28)) > 0 ? Math.round(rootItem.width / Math.round(rootItem.width/(Kirigami.Units.gridUnit*28))) : rootItem.width Component.onCompleted: { // this needs to pick the theme from persistent preference settings - var theme = manager.theme + var theme = prefs.theme if (theme == "Blue") blueTheme() else if (theme == "Pink") diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 94e15ef66..e441428b9 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "qmlmanager.h" +#include "qmlprefs.h" #include <QUrl> #include <QSettings> #include <QDebug> @@ -22,15 +23,16 @@ #include "qt-models/messagehandlermodel.h" #include "core/divelist.h" #include "core/device.h" -#include "core/pref.h" #include "core/qthelper.h" #include "core/qt-gui.h" #include "core/git-access.h" #include "core/cloudstorage.h" -#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/membuffer.h" #include "qt-models/tankinfomodel.h" #include "core/downloadfromdcthread.h" +#include "core/subsurface-string.h" +#include "core/pref.h" +#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/ssrf.h" @@ -134,7 +136,6 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), deletedTrip(0), m_updateSelectedDive(-1), m_selectedDiveTimestamp(0), - m_credentialStatus(CS_UNKNOWN), alreadySaving(false), m_device_data(new DCDeviceData) { @@ -183,7 +184,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), LOG_STP("qmlmgr bt available"); connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &QMLManager::btHostModeChange); - setShowPin(false); + QMLPrefs::instance()->setShowPin(false); // create location manager service locationProvider = new GpsLocation(&appendTextToLogStandalone, this); progress_callback = &progressCallback; @@ -246,12 +247,12 @@ void QMLManager::openLocalThenRemote(QString url) * no cloud repo solves this. */ - if (m_credentialStatus != CS_NOCLOUD) - setCredentialStatus(CS_NEED_TO_VERIFY); + if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD) + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NEED_TO_VERIFY); } else { // if we can load from the cache, we know that we have a valid cloud account - if (m_credentialStatus == CS_UNKNOWN) - setCredentialStatus(CS_VERIFIED); + if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_UNKNOWN) + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED); prefs.unit_system = git_prefs.unit_system; if (git_prefs.unit_system == IMPERIAL) git_prefs.units = IMPERIAL_units; @@ -269,11 +270,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 (m_credentialStatus == CS_NEED_TO_VERIFY) { + if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_NEED_TO_VERIFY) { appendTextToLog(QStringLiteral("have cloud credentials, but still needs PIN")); - setShowPin(true); + QMLPrefs::instance()->setShowPin(true); } - if (m_oldStatus == CS_NOCLOUD) { + if (QMLPrefs::instance()->oldStatus() == QMLPrefs::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")); @@ -304,42 +305,6 @@ void QMLManager::mergeLocalRepo() process_dives(true, false); } -void QMLManager::clearCredentials() -{ - setCloudUserName(NULL); - setCloudPassword(NULL); - setCloudPin(NULL); -} - -void QMLManager::cancelCredentialsPinSetup() -{ - /* - * The user selected <cancel> on the final stage of the - * cloud account generation (entering the emailed PIN). - * - * Resets the cloud credential status to CS_UNKNOWN, resulting - * in a return to the first crededentials page, with the - * email and passwd still filled in. In case of a cancel - * of registration (from the PIN page), the email address - * was probably misspelled, so the user never received a PIN to - * complete the process. - * - * Notice that this function is also used to switch to a different - * cloud account, so the name is not perfect. - */ - QSettings s; - - setCredentialStatus(CS_UNKNOWN); - s.beginGroup("CloudStorage"); - s.setValue("email", m_cloudUserName); - s.setValue("password", m_cloudPassword); - s.setValue("cloud_verification_status", m_credentialStatus); - s.sync(); - setStartPageText(tr("Starting...")); - - setShowPin(false); -} - void QMLManager::copyAppLogToClipboard() { /* @@ -369,21 +334,22 @@ void QMLManager::copyAppLogToClipboard() void QMLManager::finishSetup() { // Initialize cloud credentials. - setCloudUserName(prefs.cloud_storage_email); - setCloudPassword(prefs.cloud_storage_password); + QMLPrefs::instance()->setCloudUserName(prefs.cloud_storage_email); + QMLPrefs::instance()->setCloudPassword(prefs.cloud_storage_password); setSyncToCloud(!prefs.git_local_only); - setCredentialStatus((cloud_status_qml) prefs.cloud_verification_status); + QMLPrefs::instance()->setCredentialStatus((QMLPrefs::cloud_status_qml) prefs.cloud_verification_status); // if the cloud credentials are valid, we should get the GPS Webservice ID as well QString url; - if (!m_cloudUserName.isEmpty() && - !m_cloudPassword.isEmpty() && + if (!QMLPrefs::instance()->cloudUserName().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, // but we need to make sure we stay the only ones accessing git storage alreadySaving = true; openLocalThenRemote(url); - } else if (!empty_string(existing_filename) && m_credentialStatus != CS_UNKNOWN) { - setCredentialStatus(CS_NOCLOUD); + } else if (!empty_string(existing_filename) && + QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_UNKNOWN) { + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD); saveCloudCredentials(); appendTextToLog(tr("working in no-cloud mode")); int error = parse_file(existing_filename); @@ -397,12 +363,12 @@ void QMLManager::finishSetup() appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); } } else { - setCredentialStatus(CS_UNKNOWN); + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_UNKNOWN); appendTextToLog(tr("no cloud credentials")); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } - setDistanceThreshold(prefs.distance_threshold); - setTimeThreshold(prefs.time_threshold / 60); + QMLPrefs::instance()->setDistanceThreshold(prefs.distance_threshold); + QMLPrefs::instance()->setTimeThreshold(prefs.time_threshold / 60); } QMLManager::~QMLManager() @@ -421,9 +387,9 @@ QMLManager *QMLManager::instance() void QMLManager::savePreferences() { - auto location = SettingsObjectWrapper::instance()->location_settings; - location->setTimeThreshold(m_timeThreshold * 60); - location->setDistanceThreshold(m_distanceThreshold); + auto location = SettingsObjectWrapper::instance()->location_settings; + location->setTimeThreshold(QMLPrefs::instance()->timeThreshold() * 60); + location->setDistanceThreshold(QMLPrefs::instance()->distanceThreshold()); } #define CLOUDURL QString(prefs.cloud_base_url) @@ -435,42 +401,49 @@ 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 (m_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. - if (m_cloudPassword.isEmpty() || !regExp.match(m_cloudPassword).hasMatch() || !regExp.match(m_cloudUserName).hasMatch()) { + if (QMLPrefs::instance()->cloudPassword().isEmpty() || + !regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() || + !regExp.match(QMLPrefs::instance()->cloudUserName()).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(m_cloudUserName).hasMatch()) { + if (!regExp.match(QMLPrefs::instance()->cloudUserName()).hasMatch()) { setStartPageText(RED_FONT + tr("Invalid format for email address") + END_FONT); return; } } s.beginGroup("CloudStorage"); - s.setValue("email", m_cloudUserName); - s.setValue("password", m_cloudPassword); - s.setValue("cloud_verification_status", m_credentialStatus); + s.setValue("email", QMLPrefs::instance()->cloudUserName()); + s.setValue("password", QMLPrefs::instance()->cloudPassword()); + s.setValue("cloud_verification_status", QMLPrefs::instance()->credentialStatus()); s.sync(); - if (!same_string(prefs.cloud_storage_email, qPrintable(m_cloudUserName))) { + if (!same_string(prefs.cloud_storage_email, + qPrintable(QMLPrefs::instance()->cloudUserName()))) { free((void *)prefs.cloud_storage_email); - prefs.cloud_storage_email = copy_qstring(m_cloudUserName); + prefs.cloud_storage_email = copy_qstring(QMLPrefs::instance()->cloudUserName()); cloudCredentialsChanged = true; } - cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(m_cloudPassword)); + cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, + qPrintable(QMLPrefs::instance()->cloudPassword())); - if (m_credentialStatus != CS_NOCLOUD && !cloudCredentialsChanged) { + if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD && + !cloudCredentialsChanged) { // just go back to the dive list - setCredentialStatus(m_oldStatus); + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::instance()->oldStatus()); } - if (!same_string(prefs.cloud_storage_password, qPrintable(m_cloudPassword))) { + if (!same_string(prefs.cloud_storage_password, + qPrintable(QMLPrefs::instance()->cloudPassword()))) { free((void *)prefs.cloud_storage_password); - prefs.cloud_storage_password = copy_qstring(m_cloudPassword); + prefs.cloud_storage_password = copy_qstring(QMLPrefs::instance()->cloudPassword()); } - if (m_cloudUserName.isEmpty() || m_cloudPassword.isEmpty()) { + if (QMLPrefs::instance()->cloudUserName().isEmpty() || + QMLPrefs::instance()->cloudPassword().isEmpty()) { setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); } else if (cloudCredentialsChanged) { // let's make sure there are no unsaved changes @@ -493,7 +466,8 @@ void QMLManager::saveCloudCredentials() currentGitLocalOnly = prefs.git_local_only; prefs.git_local_only = false; openLocalThenRemote(url); - } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY && !m_cloudPin.isEmpty()) { + } else if (prefs.cloud_verification_status == QMLPrefs::CS_NEED_TO_VERIFY && + !QMLPrefs::instance()->cloudPin().isEmpty()) { // the user entered a PIN? tryRetrieveDataFromBackend(); } @@ -508,7 +482,8 @@ void QMLManager::tryRetrieveDataFromBackend() setStartPageText(tr("Testing cloud credentials")); appendTextToLog("Have credentials, let's see if they are valid"); CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this); - csa->backend(prefs.cloud_storage_email, prefs.cloud_storage_password, m_cloudPin); + csa->backend(prefs.cloud_storage_email, prefs.cloud_storage_password, + QMLPrefs::instance()->cloudPin()); // let's wait here for the signal to avoid too many more nested functions QTimer myTimer; myTimer.setSingleShot(true); @@ -524,7 +499,7 @@ void QMLManager::tryRetrieveDataFromBackend() return; } myTimer.stop(); - setCloudPin(""); + QMLPrefs::instance()->setCloudPin(""); if (prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD) { appendTextToLog(QStringLiteral("Incorrect cloud credentials")); setStartPageText(RED_FONT + tr("Incorrect cloud credentials") + END_FONT); @@ -535,11 +510,11 @@ void QMLManager::tryRetrieveDataFromBackend() 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); revertToNoCloudIfNeeded(); - setShowPin(true); + QMLPrefs::instance()->setShowPin(true); return; } - if (m_showPin) - setShowPin(false); + if (QMLPrefs::instance()->showPin()) + QMLPrefs::instance()->setShowPin(false); // now check the redirect URL to make sure everything is set up on the cloud server connect(manager(), &QNetworkAccessManager::authenticationRequired, this, &QMLManager::provideAuth, Qt::UniqueConnection); @@ -561,7 +536,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); - setCredentialStatus(CS_INCORRECT_USER_PASSWD); + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_INCORRECT_USER_PASSWD); reply->disconnect(); reply->abort(); reply->deleteLater(); @@ -605,7 +580,7 @@ void QMLManager::retrieveUserid() revertToNoCloudIfNeeded(); return; } - setCredentialStatus(CS_VERIFIED); + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED); QString userid(prefs.userid); if (userid.isEmpty()) { if (empty_string(prefs.cloud_storage_email) || empty_string(prefs.cloud_storage_password)) { @@ -624,7 +599,7 @@ void QMLManager::retrieveUserid() s.setValue("subsurface_webservice_uid", prefs.userid); s.sync(); } - setCredentialStatus(CS_VERIFIED); + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_VERIFIED); setStartPageText(tr("Cloud credentials valid, loading dives...")); // this only gets called with "alreadySaving" already locked loadDivesWithValidCredentials(); @@ -674,7 +649,7 @@ successful_exit: setLoadFromCloud(true); // if we came from local storage mode, let's merge the local data into the local cache // for the remote data - which then later gets merged with the remote data if necessary - if (m_oldStatus == CS_NOCLOUD) { + if (QMLPrefs::instance()->oldStatus() == QMLPrefs::CS_NOCLOUD) { git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)"))); dive_table.preexisting = dive_table.nr; mergeLocalRepo(); @@ -702,7 +677,7 @@ void QMLManager::revertToNoCloudIfNeeded() currentGitLocalOnly = false; prefs.git_local_only = true; } - if (m_oldStatus == CS_NOCLOUD) { + if (QMLPrefs::instance()->oldStatus() == QMLPrefs::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 @@ -716,9 +691,9 @@ void QMLManager::revertToNoCloudIfNeeded() prefs.cloud_storage_email = NULL; free((void *)prefs.cloud_storage_password); prefs.cloud_storage_password = NULL; - setCloudUserName(""); - setCloudPassword(""); - setCredentialStatus(CS_NOCLOUD); + QMLPrefs::instance()->setCloudUserName(""); + QMLPrefs::instance()->setCloudPassword(""); + QMLPrefs::instance()->setCredentialStatus(QMLPrefs::CS_NOCLOUD); set_filename(NOCLOUD_LOCALSTORAGE); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); } @@ -1183,7 +1158,7 @@ void QMLManager::openNoCloudRepo() void QMLManager::saveChangesLocal() { if (unsaved_changes()) { - if (m_credentialStatus == CS_NOCLOUD) { + if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_NOCLOUD) { if (empty_string(existing_filename)) { char *filename = NOCLOUD_LOCALSTORAGE; git_create_local_repo(filename); @@ -1426,52 +1401,6 @@ void QMLManager::setVerboseEnabled(bool verboseMode) emit verboseEnabledChanged(); } -void QMLManager::setCloudPassword(const QString &cloudPassword) -{ - m_cloudPassword = cloudPassword; - emit cloudPasswordChanged(); -} - -void QMLManager::setCloudPin(const QString &cloudPin) -{ - m_cloudPin = cloudPin; - emit cloudPinChanged(); -} - -void QMLManager::setCloudUserName(const QString &cloudUserName) -{ - m_cloudUserName = cloudUserName.toLower(); - emit cloudUserNameChanged(); -} - -void QMLManager::setDistanceThreshold(int distance) -{ - m_distanceThreshold = distance; - emit distanceThresholdChanged(); -} - -void QMLManager::setTimeThreshold(int time) -{ - m_timeThreshold = time; - locationProvider->setGpsTimeThreshold(m_timeThreshold * 60); - emit timeThresholdChanged(); -} - -void QMLManager::setTheme(QString theme) -{ - QSettings s; - s.beginGroup("Theme"); - s.setValue("currentTheme", theme); - emit themeChanged(); -} - -QString QMLManager::theme() const -{ - QSettings s; - s.beginGroup("Theme"); - return s.value("currentTheme", "Blue").toString(); -} - void QMLManager::syncLoadFromCloud() { QSettings s; @@ -1494,28 +1423,6 @@ void QMLManager::setStartPageText(const QString& text) emit startPageTextChanged(); } -void QMLManager::setCredentialStatus(const cloud_status_qml value) -{ - if (m_credentialStatus != value) { - setOldStatus(m_credentialStatus); - if (value == CS_NOCLOUD) { - appendTextToLog("Switching to no cloud mode"); - set_filename(NOCLOUD_LOCALSTORAGE); - clearCredentials(); - } - m_credentialStatus = value; - emit credentialStatusChanged(); - } -} - -void QMLManager::setOldStatus(const cloud_status_qml value) -{ - if (m_oldStatus != value) { - m_oldStatus = value; - emit oldStatusChanged(); - } -} - QString QMLManager::getNumber(const QString& diveId) { int dive_id = diveId.toInt(); @@ -1647,24 +1554,12 @@ QStringList QMLManager::cylinderInit() const return cylinders; } -void QMLManager::setShowPin(bool enable) -{ - m_showPin = enable; - emit showPinChanged(); -} - void QMLManager::setProgressMessage(QString text) { m_progressMessage = text; emit progressMessageChanged(); } -void QMLManager::setDeveloper(bool value) -{ - m_developer = value; - emit developerChanged(); -} - void QMLManager::setBtEnabled(bool value) { m_btEnabled = value; diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 6de279b4b..abc497e0c 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -21,21 +21,12 @@ class QMLManager : public QObject { Q_OBJECT - Q_ENUMS(cloud_status_qml) - Q_PROPERTY(QString cloudUserName MEMBER m_cloudUserName WRITE setCloudUserName NOTIFY cloudUserNameChanged) - Q_PROPERTY(QString cloudPassword MEMBER m_cloudPassword WRITE setCloudPassword NOTIFY cloudPasswordChanged) - Q_PROPERTY(QString cloudPin MEMBER m_cloudPin WRITE setCloudPin NOTIFY cloudPinChanged) Q_PROPERTY(QString logText READ logText WRITE setLogText NOTIFY logTextChanged) Q_PROPERTY(bool locationServiceEnabled MEMBER m_locationServiceEnabled WRITE setLocationServiceEnabled NOTIFY locationServiceEnabledChanged) Q_PROPERTY(bool locationServiceAvailable MEMBER m_locationServiceAvailable WRITE setLocationServiceAvailable NOTIFY locationServiceAvailableChanged) - Q_PROPERTY(int distanceThreshold MEMBER m_distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged) - Q_PROPERTY(int timeThreshold MEMBER m_timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged) - Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(bool loadFromCloud MEMBER m_loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged) Q_PROPERTY(QString startPageText MEMBER m_startPageText WRITE setStartPageText NOTIFY startPageTextChanged) Q_PROPERTY(bool verboseEnabled MEMBER m_verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged) - Q_PROPERTY(cloud_status_qml credentialStatus MEMBER m_credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged) - Q_PROPERTY(cloud_status_qml oldStatus MEMBER m_oldStatus WRITE setOldStatus NOTIFY oldStatusChanged) Q_PROPERTY(QString notificationText MEMBER m_notificationText WRITE setNotificationText NOTIFY notificationTextChanged) Q_PROPERTY(bool syncToCloud MEMBER m_syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged) @@ -45,9 +36,7 @@ class QMLManager : public QObject { Q_PROPERTY(QStringList divemasterList READ divemasterList NOTIFY divemasterListChanged) Q_PROPERTY(QStringList locationList READ locationList NOTIFY locationListChanged) Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT) - Q_PROPERTY(bool showPin MEMBER m_showPin WRITE setShowPin NOTIFY showPinChanged) Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged) - Q_PROPERTY(bool developer MEMBER m_developer WRITE setDeveloper NOTIFY developerChanged) Q_PROPERTY(bool btEnabled MEMBER m_btEnabled WRITE setBtEnabled NOTIFY btEnabledChanged) Q_PROPERTY(QString DC_vendor READ DC_vendor WRITE DC_setVendor) @@ -106,27 +95,10 @@ public: Q_INVOKABLE int getDetectedVendorIndex(); Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText); public: - enum cloud_status_qml { - CS_UNKNOWN, - CS_INCORRECT_USER_PASSWD, - CS_NEED_TO_VERIFY, - CS_VERIFIED, - CS_NOCLOUD - }; - static QMLManager *instance(); Q_INVOKABLE void registerError(QString error); QString consumeError(); - QString cloudUserName() const; - void setCloudUserName(const QString &cloudUserName); - - QString cloudPassword() const; - void setCloudPassword(const QString &cloudPassword); - - QString cloudPin() const; - void setCloudPin(const QString &cloudPin); - bool locationServiceEnabled() const; void setLocationServiceEnabled(bool locationServiceEnable); @@ -136,15 +108,6 @@ public: bool verboseEnabled() const; void setVerboseEnabled(bool verboseMode); - int distanceThreshold() const; - void setDistanceThreshold(int distance); - - int timeThreshold() const; - void setTimeThreshold(int time); - - QString theme() const; - void setTheme(QString theme); - bool loadFromCloud() const; void setLoadFromCloud(bool done); void syncLoadFromCloud(); @@ -152,12 +115,6 @@ public: QString startPageText() const; void setStartPageText(const QString& text); - cloud_status_qml credentialStatus() const; - void setCredentialStatus(const cloud_status_qml value); - - cloud_status_qml oldStatus() const; - void setOldStatus(const cloud_status_qml value); - QString logText() const; void setLogText(const QString &logText); @@ -176,9 +133,6 @@ public: QString progressMessage() const; void setProgressMessage(QString text); - bool developer() const; - void setDeveloper(bool value); - bool btEnabled() const; void setBtEnabled(bool value); @@ -189,8 +143,6 @@ public: QStringList divemasterList() const; QStringList locationList() const; QStringList cylinderInit() const; - bool showPin() const; - void setShowPin(bool enable); Q_INVOKABLE void setStatusbarColor(QColor color); void btHostModeChange(QBluetoothLocalDevice::HostMode state); @@ -227,8 +179,6 @@ public slots: void populateGpsData(); void cancelDownloadDC(); void clearGpsData(); - void clearCredentials(); - void cancelCredentialsPinSetup(); void copyAppLogToClipboard(); void finishSetup(); void openLocalThenRemote(QString url); @@ -256,9 +206,6 @@ private: SuitCompletionModel suitModel; DiveMasterCompletionModel divemasterModel; LocationInformationModel locationModel; - QString m_cloudUserName; - QString m_cloudPassword; - QString m_cloudPin; QString m_ssrfGpsWebUserid; QString m_startPageText; QString m_logText; @@ -266,8 +213,6 @@ private: bool m_locationServiceEnabled; bool m_locationServiceAvailable; bool m_verboseEnabled; - int m_distanceThreshold; - int m_timeThreshold; GpsLocation *locationProvider; bool m_loadFromCloud; static QMLManager *m_instance; @@ -277,8 +222,6 @@ private: bool m_syncToCloud; int m_updateSelectedDive; int m_selectedDiveTimestamp; - cloud_status_qml m_credentialStatus; - cloud_status_qml m_oldStatus; qreal m_lastDevicePixelRatio; QElapsedTimer timer; bool alreadySaving; @@ -287,10 +230,8 @@ private: bool checkDuration(DiveObjectHelper *myDive, struct dive *d, QString duration); bool checkDepth(DiveObjectHelper *myDive, struct dive *d, QString depth); bool currentGitLocalOnly; - bool m_showPin; Q_INVOKABLE DCDeviceData *m_device_data; QString m_progressMessage; - bool m_developer; bool m_btEnabled; void updateAllGlobalLists(); @@ -301,28 +242,18 @@ private: #endif signals: - void cloudUserNameChanged(); - void cloudPasswordChanged(); - void cloudPinChanged(); void locationServiceEnabledChanged(); void locationServiceAvailableChanged(); void verboseEnabledChanged(); void logTextChanged(); - void timeThresholdChanged(); - void themeChanged(); - void distanceThresholdChanged(); void loadFromCloudChanged(); void startPageTextChanged(); - void credentialStatusChanged(); - void oldStatusChanged(); void notificationTextChanged(); void syncToCloudChanged(); void updateSelectedDiveChanged(); void selectedDiveTimestampChanged(); - void showPinChanged(); void sendScreenChanged(QScreen *screen); void progressMessageChanged(); - void developerChanged(); void btEnabledChanged(); void suitListChanged(); void buddyListChanged(); diff --git a/mobile-widgets/qmlprefs.cpp b/mobile-widgets/qmlprefs.cpp index 49a788708..589234095 100644 --- a/mobile-widgets/qmlprefs.cpp +++ b/mobile-widgets/qmlprefs.cpp @@ -1,11 +1,25 @@ // SPDX-License-Identifier: GPL-2.0 #include "qmlprefs.h" +#include "qmlmanager.h" + +#include "core/membuffer.h" +#include "core/subsurface-qt/SettingsObjectWrapper.h" +#include "core/gpslocation.h" -QMLPrefs *QMLPrefs::m_instance = NULL; +/*** Global and constructors ***/ +QMLPrefs *QMLPrefs::m_instance = NULL; -QMLPrefs::QMLPrefs() +QMLPrefs::QMLPrefs() : + m_credentialStatus(CS_UNKNOWN), + m_developer(false), + m_distanceThreshold(1000), + m_oldStatus(CS_UNKNOWN), + m_showPin(false), + m_timeThreshold(60) { + // This strange construct is needed because QMLEngine calls new and that + // cannot be overwritten if (!m_instance) m_instance = this; } @@ -19,3 +33,164 @@ QMLPrefs *QMLPrefs::instance() { return m_instance; } + + +/*** public functions ***/ +const QString QMLPrefs::cloudPassword() const +{ + return m_cloudPassword; +} + +void QMLPrefs::setCloudPassword(const QString &cloudPassword) +{ + m_cloudPassword = cloudPassword; + emit cloudPasswordChanged(); +} + +const QString QMLPrefs::cloudPin() const +{ + return m_cloudPin; +} + +void QMLPrefs::setCloudPin(const QString &cloudPin) +{ + m_cloudPin = cloudPin; + emit cloudPinChanged(); +} + +const QString QMLPrefs::cloudUserName() const +{ + return m_cloudUserName; +} + +void QMLPrefs::setCloudUserName(const QString &cloudUserName) +{ + m_cloudUserName = cloudUserName.toLower(); + emit cloudUserNameChanged(); +} + +QMLPrefs::cloud_status_qml QMLPrefs::credentialStatus() const +{ + return m_credentialStatus; +} + +void QMLPrefs::setCredentialStatus(const cloud_status_qml value) +{ + if (m_credentialStatus != value) { + setOldStatus(m_credentialStatus); + if (value == CS_NOCLOUD) { + QMLManager::instance()->appendTextToLog("Switching to no cloud mode"); + set_filename(NOCLOUD_LOCALSTORAGE); + clearCredentials(); + } + m_credentialStatus = value; + emit credentialStatusChanged(); + } +} + +void QMLPrefs::setDeveloper(bool value) +{ + m_developer = value; + emit developerChanged(); +} + +int QMLPrefs::distanceThreshold() const +{ + return m_distanceThreshold; +} + +void QMLPrefs::setDistanceThreshold(int distance) +{ + m_distanceThreshold = distance; + emit distanceThresholdChanged(); +} + +QMLPrefs::cloud_status_qml QMLPrefs::oldStatus() const +{ + return m_oldStatus; +} + +void QMLPrefs::setOldStatus(const cloud_status_qml value) +{ + if (m_oldStatus != value) { + m_oldStatus = value; + emit oldStatusChanged(); + } +} + +bool QMLPrefs::showPin() const +{ + return m_showPin; +} + +void QMLPrefs::setShowPin(bool enable) +{ + m_showPin = enable; + emit showPinChanged(); +} + +int QMLPrefs::timeThreshold() const +{ + return m_timeThreshold; +} + +void QMLPrefs::setTimeThreshold(int time) +{ + m_timeThreshold = time; + GpsLocation::instance()->setGpsTimeThreshold(m_timeThreshold * 60); + emit timeThresholdChanged(); +} + +const QString QMLPrefs::theme() const +{ + QSettings s; + s.beginGroup("Theme"); + return s.value("currentTheme", "Blue").toString(); +} + +void QMLPrefs::setTheme(QString theme) +{ + QSettings s; + s.beginGroup("Theme"); + s.setValue("currentTheme", theme); + emit themeChanged(); +} + + + +/*** public slot functions ***/ +void QMLPrefs::cancelCredentialsPinSetup() +{ + /* + * The user selected <cancel> on the final stage of the + * cloud account generation (entering the emailed PIN). + * + * Resets the cloud credential status to CS_UNKNOWN, resulting + * in a return to the first crededentials page, with the + * email and passwd still filled in. In case of a cancel + * of registration (from the PIN page), the email address + * was probably misspelled, so the user never received a PIN to + * complete the process. + * + * Notice that this function is also used to switch to a different + * cloud account, so the name is not perfect. + */ + QSettings s; + + setCredentialStatus(CS_UNKNOWN); + s.beginGroup("CloudStorage"); + s.setValue("email", m_cloudUserName); + s.setValue("password", m_cloudPassword); + s.setValue("cloud_verification_status", m_credentialStatus); + s.sync(); + QMLManager::instance()->setStartPageText(tr("Starting...")); + + setShowPin(false); +} + +void QMLPrefs::clearCredentials() +{ + setCloudUserName(NULL); + setCloudPassword(NULL); + setCloudPin(NULL); +} diff --git a/mobile-widgets/qmlprefs.h b/mobile-widgets/qmlprefs.h index 2755014e8..6acba5438 100644 --- a/mobile-widgets/qmlprefs.h +++ b/mobile-widgets/qmlprefs.h @@ -7,6 +7,47 @@ class QMLPrefs : public QObject { Q_OBJECT + Q_ENUMS(cloud_status_qml) + Q_PROPERTY(QString cloudPassword + MEMBER m_cloudPassword + WRITE setCloudPassword + NOTIFY cloudPasswordChanged) + Q_PROPERTY(QString cloudPin + MEMBER m_cloudPin + WRITE setCloudPin + NOTIFY cloudPinChanged) + Q_PROPERTY(QString cloudUserName + MEMBER m_cloudUserName + WRITE setCloudUserName + NOTIFY cloudUserNameChanged) + Q_PROPERTY(cloud_status_qml credentialStatus + MEMBER m_credentialStatus + WRITE setCredentialStatus + NOTIFY credentialStatusChanged) + Q_PROPERTY(bool developer + MEMBER m_developer + WRITE setDeveloper + NOTIFY developerChanged) + Q_PROPERTY(int distanceThreshold + MEMBER m_distanceThreshold + WRITE setDistanceThreshold + NOTIFY distanceThresholdChanged) + Q_PROPERTY(bool showPin + MEMBER m_showPin + WRITE setShowPin + NOTIFY showPinChanged) + Q_PROPERTY(cloud_status_qml oldStatus + MEMBER m_oldStatus + WRITE setOldStatus + NOTIFY oldStatusChanged) + Q_PROPERTY(QString theme + READ theme + WRITE setTheme + NOTIFY themeChanged) + Q_PROPERTY(int timeThreshold + MEMBER m_timeThreshold + WRITE setTimeThreshold + NOTIFY timeThresholdChanged) public: QMLPrefs(); @@ -14,12 +55,70 @@ 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); + + const QString cloudPin() const; + void setCloudPin(const QString &cloudPin); + + const QString cloudUserName() const; + void setCloudUserName(const QString &cloudUserName); + + cloud_status_qml credentialStatus() const; + void setCredentialStatus(const cloud_status_qml value); + + void setDeveloper(bool value); + + int distanceThreshold() const; + void setDistanceThreshold(int distance); + + cloud_status_qml oldStatus() const; + void setOldStatus(const cloud_status_qml value); + + bool showPin() const; + void setShowPin(bool enable); + + int timeThreshold() const; + void setTimeThreshold(int time); + + const QString theme() const; + void setTheme(QString theme); + public slots: + void cancelCredentialsPinSetup(); + void clearCredentials(); private: + QString m_cloudPassword; + QString m_cloudPin; + QString m_cloudUserName; + cloud_status_qml m_credentialStatus; + bool m_developer; + int m_distanceThreshold; static QMLPrefs *m_instance; + cloud_status_qml m_oldStatus; + bool m_showPin; + int m_timeThreshold; signals: + void cloudPasswordChanged(); + void cloudPinChanged(); + void cloudUserNameChanged(); + void credentialStatusChanged(); + void distanceThresholdChanged(); + void developerChanged(); + void oldStatusChanged(); + void showPinChanged(); + void themeChanged(); + void timeThresholdChanged(); }; #endif |