summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlprefs.cpp
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-06-13 18:06:11 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-06-15 14:12:14 -0700
commitb8eb348f546291c49e2d606649b3c85d23e43782 (patch)
tree8ca54d1f5aa363496de4b83e1b6200b92304a8a3 /mobile-widgets/qmlprefs.cpp
parent62ca5e90e13d65235d3cd53feffd0cb62cfbac43 (diff)
downloadsubsurface-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/qmlprefs.cpp')
-rw-r--r--mobile-widgets/qmlprefs.cpp179
1 files changed, 177 insertions, 2 deletions
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);
+}