mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									62ca5e90e1
								
							
						
					
					
						commit
						b8eb348f54
					
				
					 8 changed files with 389 additions and 283 deletions
				
			
		|  | @ -15,9 +15,9 @@ Item { | ||||||
| 	property string password: password.text; | 	property string password: password.text; | ||||||
| 
 | 
 | ||||||
| 	function saveCredentials() { | 	function saveCredentials() { | ||||||
| 		manager.cloudUserName = login.text | 		prefs.cloudUserName = login.text | ||||||
| 		manager.cloudPassword = password.text | 		prefs.cloudPassword = password.text | ||||||
| 		manager.cloudPin = pin.text | 		prefs.cloudPin = pin.text | ||||||
| 		manager.saveCloudCredentials() | 		manager.saveCloudCredentials() | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -60,7 +60,7 @@ Item { | ||||||
| 
 | 
 | ||||||
| 		Controls.TextField { | 		Controls.TextField { | ||||||
| 			id: login | 			id: login | ||||||
| 			text: manager.cloudUserName | 			text: prefs.cloudUserName | ||||||
| 			visible: !rootItem.showPin | 			visible: !rootItem.showPin | ||||||
| 			Layout.fillWidth: true | 			Layout.fillWidth: true | ||||||
| 			inputMethodHints: Qt.ImhEmailCharactersOnly | | 			inputMethodHints: Qt.ImhEmailCharactersOnly | | ||||||
|  | @ -76,7 +76,7 @@ Item { | ||||||
| 
 | 
 | ||||||
| 		Controls.TextField { | 		Controls.TextField { | ||||||
| 			id: password | 			id: password | ||||||
| 			text: manager.cloudPassword | 			text: prefs.cloudPassword | ||||||
| 			visible: !rootItem.showPin | 			visible: !rootItem.showPin | ||||||
| 			echoMode: TextInput.PasswordEchoOnEdit | 			echoMode: TextInput.PasswordEchoOnEdit | ||||||
| 			inputMethodHints: Qt.ImhSensitiveData | | 			inputMethodHints: Qt.ImhSensitiveData | | ||||||
|  | @ -146,7 +146,7 @@ Item { | ||||||
| 				text: qsTr("No cloud mode") | 				text: qsTr("No cloud mode") | ||||||
| 				onClicked: { | 				onClicked: { | ||||||
| 					manager.syncToCloud = false | 					manager.syncToCloud = false | ||||||
| 					manager.credentialStatus = QMLManager.CS_NOCLOUD | 					manager.credentialStatus = QMLPrefs.CS_NOCLOUD | ||||||
| 					manager.saveCloudCredentials() | 					manager.saveCloudCredentials() | ||||||
| 					manager.openNoCloudRepo() | 					manager.openNoCloudRepo() | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ Kirigami.ScrollablePage { | ||||||
| 	title: qsTr("Dive list") | 	title: qsTr("Dive list") | ||||||
| 	verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff | 	verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff | ||||||
| 	width: subsurfaceTheme.columnWidth | 	width: subsurfaceTheme.columnWidth | ||||||
| 	property int credentialStatus: manager.credentialStatus | 	property int credentialStatus: prefs.credentialStatus | ||||||
| 	property int numDives: diveListView.count | 	property int numDives: diveListView.count | ||||||
| 	property color textColor: subsurfaceTheme.textColor | 	property color textColor: subsurfaceTheme.textColor | ||||||
| 	property color secondaryTextColor: subsurfaceTheme.secondaryTextColor | 	property color secondaryTextColor: subsurfaceTheme.secondaryTextColor | ||||||
|  | @ -23,14 +23,14 @@ Kirigami.ScrollablePage { | ||||||
| 	supportsRefreshing: true | 	supportsRefreshing: true | ||||||
| 	onRefreshingChanged: { | 	onRefreshingChanged: { | ||||||
| 		if (refreshing) { | 		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") | 				console.log("User pulled down dive list - syncing with cloud storage") | ||||||
| 				detailsWindow.endEditMode() | 				detailsWindow.endEditMode() | ||||||
| 				manager.saveChangesCloud(true) | 				manager.saveChangesCloud(true) | ||||||
| 				console.log("done syncing, turn off spinner") | 				console.log("done syncing, turn off spinner") | ||||||
| 				refreshing = false | 				refreshing = false | ||||||
| 			} else { | 			} 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") | 				console.log("no syncing, turn off spinner") | ||||||
| 				refreshing = false | 				refreshing = false | ||||||
| 			} | 			} | ||||||
|  | @ -339,7 +339,8 @@ Kirigami.ScrollablePage { | ||||||
| 	StartPage { | 	StartPage { | ||||||
| 		id: startPage | 		id: startPage | ||||||
| 		anchors.fill: parent | 		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 | 		visible: opacity > 0 | ||||||
| 		Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } | 		Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } | ||||||
| 		function setupActions() { | 		function setupActions() { | ||||||
|  | @ -347,7 +348,8 @@ Kirigami.ScrollablePage { | ||||||
| 				page.actions.main = null | 				page.actions.main = null | ||||||
| 				page.actions.right = null | 				page.actions.right = null | ||||||
| 				page.title = qsTr("Cloud credentials") | 				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.main = page.downloadFromDCAction | ||||||
| 				page.actions.right = page.addDiveAction | 				page.actions.right = page.addDiveAction | ||||||
| 				page.title = qsTr("Dive list") | 				page.title = qsTr("Dive list") | ||||||
|  | @ -424,8 +426,9 @@ Kirigami.ScrollablePage { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	onBackRequested: { | 	onBackRequested: { | ||||||
| 		if (startPage.visible && diveListView.count > 0 && manager.credentialStatus !== QMLManager.CS_INCORRECT_USER_PASSWD) { | 		if (startPage.visible && diveListView.count > 0 && | ||||||
| 			manager.credentialStatus = oldStatus | 			prefs.credentialStatus !== QMLPrefs.CS_INCORRECT_USER_PASSWD) { | ||||||
|  | 			prefs.credentialStatus = oldStatus | ||||||
| 			event.accepted = true; | 			event.accepted = true; | ||||||
| 		} | 		} | ||||||
| 		if (!startPage.visible) { | 		if (!startPage.visible) { | ||||||
|  |  | ||||||
|  | @ -42,7 +42,8 @@ Kirigami.ScrollablePage { | ||||||
| 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | ||||||
| 			} | 			} | ||||||
| 			Controls.Label { | 			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.alignment: Qt.AlignRight | ||||||
| 				Layout.preferredWidth: gridWidth * 0.60 | 				Layout.preferredWidth: gridWidth * 0.60 | ||||||
| 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | ||||||
|  | @ -63,7 +64,7 @@ Kirigami.ScrollablePage { | ||||||
| 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | ||||||
| 			} | 			} | ||||||
| 			Controls.Label { | 			Controls.Label { | ||||||
| 				text: describe[manager.credentialStatus] | 				text: describe[prefs.credentialStatus] | ||||||
| 				Layout.alignment: Qt.AlignRight | 				Layout.alignment: Qt.AlignRight | ||||||
| 				Layout.preferredWidth: gridWidth * 0.60 | 				Layout.preferredWidth: gridWidth * 0.60 | ||||||
| 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | 				Layout.preferredHeight: Kirigami.Units.gridUnit * 2 | ||||||
|  | @ -136,8 +137,8 @@ Kirigami.ScrollablePage { | ||||||
| 				enabled: subsurfaceTheme.currentTheme !== "Blue" | 				enabled: subsurfaceTheme.currentTheme !== "Blue" | ||||||
| 				onClicked: { | 				onClicked: { | ||||||
| 					blueTheme() | 					blueTheme() | ||||||
| 					manager.theme = subsurfaceTheme.currentTheme | 					prefs.theme = subsurfaceTheme.currentTheme | ||||||
| 					manager.savePreferences() | 					prefs.savePreferences() | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -189,8 +190,8 @@ Kirigami.ScrollablePage { | ||||||
| 				enabled: subsurfaceTheme.currentTheme !== "Pink" | 				enabled: subsurfaceTheme.currentTheme !== "Pink" | ||||||
| 				onClicked: { | 				onClicked: { | ||||||
| 					pinkTheme() | 					pinkTheme() | ||||||
| 					manager.theme = subsurfaceTheme.currentTheme | 					prefs.theme = subsurfaceTheme.currentTheme | ||||||
| 					manager.savePreferences() | 					prefs.savePreferences() | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -241,8 +242,8 @@ Kirigami.ScrollablePage { | ||||||
| 				enabled: subsurfaceTheme.currentTheme !== "Dark" | 				enabled: subsurfaceTheme.currentTheme !== "Dark" | ||||||
| 				onClicked: { | 				onClicked: { | ||||||
| 					darkTheme() | 					darkTheme() | ||||||
| 					manager.theme = subsurfaceTheme.currentTheme | 					prefs.theme = subsurfaceTheme.currentTheme | ||||||
| 					manager.savePreferences() | 					prefs.savePreferences() | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | @ -275,11 +276,11 @@ Kirigami.ScrollablePage { | ||||||
| 
 | 
 | ||||||
| 			Controls.TextField { | 			Controls.TextField { | ||||||
| 				id: distanceThreshold | 				id: distanceThreshold | ||||||
| 				text: manager.distanceThreshold | 				text: prefs.distanceThreshold | ||||||
| 				Layout.preferredWidth: gridWidth * 0.25 | 				Layout.preferredWidth: gridWidth * 0.25 | ||||||
| 				onEditingFinished: { | 				onEditingFinished: { | ||||||
| 					manager.distanceThreshold = distanceThreshold.text | 					prefs.distanceThreshold = distanceThreshold.text | ||||||
| 					manager.savePreferences() | 					prefs.savePreferences() | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -291,11 +292,11 @@ Kirigami.ScrollablePage { | ||||||
| 
 | 
 | ||||||
| 			Controls.TextField { | 			Controls.TextField { | ||||||
| 				id: timeThreshold | 				id: timeThreshold | ||||||
| 				text: manager.timeThreshold | 				text: prefs.timeThreshold | ||||||
| 				Layout.preferredWidth: gridWidth * 0.25 | 				Layout.preferredWidth: gridWidth * 0.25 | ||||||
| 				onEditingFinished: { | 				onEditingFinished: { | ||||||
| 					manager.timeThreshold = timeThreshold.text | 					prefs.timeThreshold = timeThreshold.text | ||||||
| 					manager.savePreferences() | 					prefs.savePreferences() | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -325,10 +326,10 @@ Kirigami.ScrollablePage { | ||||||
| 			} | 			} | ||||||
| 			SsrfSwitch { | 			SsrfSwitch { | ||||||
| 				id: developerButton | 				id: developerButton | ||||||
| 				checked: manager.developer | 				checked: prefs.developer | ||||||
| 				Layout.preferredWidth: gridWidth * 0.25 | 				Layout.preferredWidth: gridWidth * 0.25 | ||||||
| 				onClicked: { | 				onClicked: { | ||||||
| 					manager.developer = checked | 					prefs.developer = checked | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -20,11 +20,11 @@ Kirigami.ApplicationWindow { | ||||||
| 		maximumHeight: Kirigami.Units.gridUnit * 2 | 		maximumHeight: Kirigami.Units.gridUnit * 2 | ||||||
| 		background: Rectangle { color: subsurfaceTheme.primaryColor } | 		background: Rectangle { color: subsurfaceTheme.primaryColor } | ||||||
| 	} | 	} | ||||||
| 	property alias oldStatus: manager.oldStatus | 	property alias oldStatus: prefs.oldStatus | ||||||
| 	property alias notificationText: manager.notificationText | 	property alias notificationText: manager.notificationText | ||||||
| 	property alias syncToCloud: manager.syncToCloud | 	property alias syncToCloud: manager.syncToCloud | ||||||
| 	property alias locationServiceEnabled: manager.locationServiceEnabled | 	property alias locationServiceEnabled: manager.locationServiceEnabled | ||||||
| 	property alias showPin: manager.showPin | 	property alias showPin: prefs.showPin | ||||||
| 	onNotificationTextChanged: { | 	onNotificationTextChanged: { | ||||||
| 		if (notificationText != "") { | 		if (notificationText != "") { | ||||||
| 			// there's a risk that we have a >5 second gap in update events; | 			// there's a risk that we have a >5 second gap in update events; | ||||||
|  | @ -119,12 +119,12 @@ Kirigami.ApplicationWindow { | ||||||
| 				} | 				} | ||||||
| 				text: qsTr("Dive list") | 				text: qsTr("Dive list") | ||||||
| 				onTriggered: { | 				onTriggered: { | ||||||
| 					manager.appendTextToLog("requested dive list with credential status " + manager.credentialStatus) | 					manager.appendTextToLog("requested dive list with credential status " + prefs.credentialStatus) | ||||||
| 					if (manager.credentialStatus == QMLManager.CS_UNKNOWN) { | 					if (prefs.credentialStatus == QMLPrefs.CS_UNKNOWN) { | ||||||
| 						// the user has asked to change credentials - if the credentials before that | 						// the user has asked to change credentials - if the credentials before that | ||||||
| 						// were valid, go back to dive list | 						// were valid, go back to dive list | ||||||
| 						if (oldStatus == QMLManager.CS_VERIFIED) { | 						if (oldStatus == QMLPrefs.CS_VERIFIED) { | ||||||
| 							manager.credentialStatus = oldStatus | 							prefs.credentialStatus = oldStatus | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 					returnTopPage() | 					returnTopPage() | ||||||
|  | @ -150,7 +150,8 @@ Kirigami.ApplicationWindow { | ||||||
| 						name: ":/icons/ic_add.svg" | 						name: ":/icons/ic_add.svg" | ||||||
| 					} | 					} | ||||||
| 					text: qsTr("Add dive manually") | 					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: { | 					onTriggered: { | ||||||
| 						globalDrawer.close() | 						globalDrawer.close() | ||||||
| 						returnTopPage()  // otherwise odd things happen with the page stack | 						returnTopPage()  // otherwise odd things happen with the page stack | ||||||
|  | @ -184,13 +185,14 @@ Kirigami.ApplicationWindow { | ||||||
| 						name: ":/icons/cloud_sync.svg" | 						name: ":/icons/cloud_sync.svg" | ||||||
| 					} | 					} | ||||||
| 					text: qsTr("Manual sync with cloud") | 					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: { | 					onTriggered: { | ||||||
| 						if (manager.credentialStatus === QMLManager.CS_NOCLOUD) { | 						if (prefs.credentialStatus === QMLPrefs.CS_NOCLOUD) { | ||||||
| 							returnTopPage() | 							returnTopPage() | ||||||
| 							oldStatus = manager.credentialStatus | 							oldStatus = prefs.credentialStatus | ||||||
| 							manager.startPageText = "Enter valid cloud storage credentials" | 							manager.startPageText = "Enter valid cloud storage credentials" | ||||||
| 							manager.credentialStatus = QMLManager.CS_UNKNOWN | 							prefs.credentialStatus = QMLPrefs.CS_UNKNOWN | ||||||
| 							globalDrawer.close() | 							globalDrawer.close() | ||||||
| 						} else { | 						} else { | ||||||
| 							globalDrawer.close() | 							globalDrawer.close() | ||||||
|  | @ -205,7 +207,7 @@ Kirigami.ApplicationWindow { | ||||||
| 					name: syncToCloud ?  ":/icons/ic_cloud_off.svg" : ":/icons/ic_cloud_done.svg" | 					name: syncToCloud ?  ":/icons/ic_cloud_off.svg" : ":/icons/ic_cloud_done.svg" | ||||||
| 				} | 				} | ||||||
| 				text: syncToCloud ? qsTr("Disable auto cloud sync") : qsTr("Enable auto cloud sync") | 				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: { | 					onTriggered: { | ||||||
| 						syncToCloud = !syncToCloud | 						syncToCloud = !syncToCloud | ||||||
| 						if (!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" | 					name: ":/icons/ic_adb.svg" | ||||||
| 				} | 				} | ||||||
| 				text: qsTr("Developer") | 				text: qsTr("Developer") | ||||||
| 				visible: manager.developer | 				visible: prefs.developer | ||||||
| 				Kirigami.Action { | 				Kirigami.Action { | ||||||
| 					text: qsTr("App log") | 					text: qsTr("App log") | ||||||
| 					onTriggered: { | 					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 | 		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: { | 		Component.onCompleted: { | ||||||
| 			// this needs to pick the theme from persistent preference settings | 			// this needs to pick the theme from persistent preference settings | ||||||
| 			var theme = manager.theme | 			var theme = prefs.theme | ||||||
| 			if (theme == "Blue") | 			if (theme == "Blue") | ||||||
| 				blueTheme() | 				blueTheme() | ||||||
| 			else if (theme == "Pink") | 			else if (theme == "Pink") | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| // SPDX-License-Identifier: GPL-2.0
 | // SPDX-License-Identifier: GPL-2.0
 | ||||||
| #include "qmlmanager.h" | #include "qmlmanager.h" | ||||||
|  | #include "qmlprefs.h" | ||||||
| #include <QUrl> | #include <QUrl> | ||||||
| #include <QSettings> | #include <QSettings> | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
|  | @ -22,15 +23,16 @@ | ||||||
| #include "qt-models/messagehandlermodel.h" | #include "qt-models/messagehandlermodel.h" | ||||||
| #include "core/divelist.h" | #include "core/divelist.h" | ||||||
| #include "core/device.h" | #include "core/device.h" | ||||||
| #include "core/pref.h" |  | ||||||
| #include "core/qthelper.h" | #include "core/qthelper.h" | ||||||
| #include "core/qt-gui.h" | #include "core/qt-gui.h" | ||||||
| #include "core/git-access.h" | #include "core/git-access.h" | ||||||
| #include "core/cloudstorage.h" | #include "core/cloudstorage.h" | ||||||
| #include "core/subsurface-qt/SettingsObjectWrapper.h" |  | ||||||
| #include "core/membuffer.h" | #include "core/membuffer.h" | ||||||
| #include "qt-models/tankinfomodel.h" | #include "qt-models/tankinfomodel.h" | ||||||
| #include "core/downloadfromdcthread.h" | #include "core/downloadfromdcthread.h" | ||||||
|  | #include "core/subsurface-string.h" | ||||||
|  | #include "core/pref.h" | ||||||
|  | #include "core/subsurface-qt/SettingsObjectWrapper.h" | ||||||
| 
 | 
 | ||||||
| #include "core/ssrf.h" | #include "core/ssrf.h" | ||||||
| 
 | 
 | ||||||
|  | @ -134,7 +136,6 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), | ||||||
| 	deletedTrip(0), | 	deletedTrip(0), | ||||||
| 	m_updateSelectedDive(-1), | 	m_updateSelectedDive(-1), | ||||||
| 	m_selectedDiveTimestamp(0), | 	m_selectedDiveTimestamp(0), | ||||||
| 	m_credentialStatus(CS_UNKNOWN), |  | ||||||
| 	alreadySaving(false), | 	alreadySaving(false), | ||||||
| 	m_device_data(new DCDeviceData) | 	m_device_data(new DCDeviceData) | ||||||
| { | { | ||||||
|  | @ -183,7 +184,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), | ||||||
| 	LOG_STP("qmlmgr bt available"); | 	LOG_STP("qmlmgr bt available"); | ||||||
| 	connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged, | 	connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged, | ||||||
| 		this, &QMLManager::btHostModeChange); | 		this, &QMLManager::btHostModeChange); | ||||||
| 	setShowPin(false); | 	QMLPrefs::instance()->setShowPin(false); | ||||||
| 	// create location manager service
 | 	// create location manager service
 | ||||||
| 	locationProvider = new GpsLocation(&appendTextToLogStandalone, this); | 	locationProvider = new GpsLocation(&appendTextToLogStandalone, this); | ||||||
| 	progress_callback = &progressCallback; | 	progress_callback = &progressCallback; | ||||||
|  | @ -246,12 +247,12 @@ void QMLManager::openLocalThenRemote(QString url) | ||||||
| 		 *    no cloud repo solves this. | 		 *    no cloud repo solves this. | ||||||
| 		 */ | 		 */ | ||||||
| 
 | 
 | ||||||
| 		if (m_credentialStatus != CS_NOCLOUD) | 		if (QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_NOCLOUD) | ||||||
| 			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 (m_credentialStatus == CS_UNKNOWN) | 		if (QMLPrefs::instance()->credentialStatus() == QMLPrefs::CS_UNKNOWN) | ||||||
| 			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; | ||||||
|  | @ -269,11 +270,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 (m_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")); | ||||||
| 		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
 | 		// 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")); | ||||||
|  | @ -304,42 +305,6 @@ void QMLManager::mergeLocalRepo() | ||||||
| 	process_dives(true, false); | 	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() | void QMLManager::copyAppLogToClipboard() | ||||||
| { | { | ||||||
| 	/*
 | 	/*
 | ||||||
|  | @ -369,21 +334,22 @@ void QMLManager::copyAppLogToClipboard() | ||||||
| void QMLManager::finishSetup() | void QMLManager::finishSetup() | ||||||
| { | { | ||||||
| 	// Initialize cloud credentials.
 | 	// Initialize cloud credentials.
 | ||||||
| 	setCloudUserName(prefs.cloud_storage_email); | 	QMLPrefs::instance()->setCloudUserName(prefs.cloud_storage_email); | ||||||
| 	setCloudPassword(prefs.cloud_storage_password); | 	QMLPrefs::instance()->setCloudPassword(prefs.cloud_storage_password); | ||||||
| 	setSyncToCloud(!prefs.git_local_only); | 	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
 | 	// if the cloud credentials are valid, we should get the GPS Webservice ID as well
 | ||||||
| 	QString url; | 	QString url; | ||||||
| 	if (!m_cloudUserName.isEmpty() && | 	if (!QMLPrefs::instance()->cloudUserName().isEmpty() && | ||||||
| 	    !m_cloudPassword.isEmpty() && | 	    !QMLPrefs::instance()->cloudPassword().isEmpty() && | ||||||
| 	    getCloudURL(url) == 0) { | 	    getCloudURL(url) == 0) { | ||||||
| 		// we know that we are the first ones to access git storage, so we don't need to test,
 | 		// 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
 | 		// but we need to make sure we stay the only ones accessing git storage
 | ||||||
| 		alreadySaving = true; | 		alreadySaving = true; | ||||||
| 		openLocalThenRemote(url); | 		openLocalThenRemote(url); | ||||||
| 	} else if (!empty_string(existing_filename) && m_credentialStatus != CS_UNKNOWN) { | 	} else if (!empty_string(existing_filename) && | ||||||
| 		setCredentialStatus(CS_NOCLOUD); | 				QMLPrefs::instance()->credentialStatus() != QMLPrefs::CS_UNKNOWN) { | ||||||
|  | 		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); | ||||||
|  | @ -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)); | 			appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename)); | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		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); | ||||||
| 	} | 	} | ||||||
| 	setDistanceThreshold(prefs.distance_threshold); | 	QMLPrefs::instance()->setDistanceThreshold(prefs.distance_threshold); | ||||||
| 	setTimeThreshold(prefs.time_threshold / 60); | 	QMLPrefs::instance()->setTimeThreshold(prefs.time_threshold / 60); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QMLManager::~QMLManager() | QMLManager::~QMLManager() | ||||||
|  | @ -421,9 +387,9 @@ QMLManager *QMLManager::instance() | ||||||
| 
 | 
 | ||||||
| void QMLManager::savePreferences() | void QMLManager::savePreferences() | ||||||
| { | { | ||||||
| 	auto location = SettingsObjectWrapper::instance()->location_settings; |     auto location = SettingsObjectWrapper::instance()->location_settings; | ||||||
| 	location->setTimeThreshold(m_timeThreshold * 60); |     location->setTimeThreshold(QMLPrefs::instance()->timeThreshold() * 60); | ||||||
| 	location->setDistanceThreshold(m_distanceThreshold); |     location->setDistanceThreshold(QMLPrefs::instance()->distanceThreshold()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #define CLOUDURL QString(prefs.cloud_base_url) | #define CLOUDURL QString(prefs.cloud_base_url) | ||||||
|  | @ -435,42 +401,49 @@ 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 (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.
 | 		// 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); | 			setStartPageText(RED_FONT + tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.") + END_FONT); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		// use the same simplistic regex as the backend to check email addresses
 | 		// 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]+"); | 		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); | 			setStartPageText(RED_FONT + tr("Invalid format for email address") + END_FONT); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	s.beginGroup("CloudStorage"); | 	s.beginGroup("CloudStorage"); | ||||||
| 	s.setValue("email", m_cloudUserName); | 	s.setValue("email", QMLPrefs::instance()->cloudUserName()); | ||||||
| 	s.setValue("password", m_cloudPassword); | 	s.setValue("password", QMLPrefs::instance()->cloudPassword()); | ||||||
| 	s.setValue("cloud_verification_status", m_credentialStatus); | 	s.setValue("cloud_verification_status", QMLPrefs::instance()->credentialStatus()); | ||||||
| 	s.sync(); | 	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); | 		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 = 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
 | 		// 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); | 		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); | 		setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); | ||||||
| 	} else if (cloudCredentialsChanged) { | 	} else if (cloudCredentialsChanged) { | ||||||
| 		// let's make sure there are no unsaved changes
 | 		// let's make sure there are no unsaved changes
 | ||||||
|  | @ -493,7 +466,8 @@ 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 && !m_cloudPin.isEmpty()) { | 	} else if (prefs.cloud_verification_status == QMLPrefs::CS_NEED_TO_VERIFY && | ||||||
|  | 				!QMLPrefs::instance()->cloudPin().isEmpty()) { | ||||||
| 		// the user entered a PIN?
 | 		// the user entered a PIN?
 | ||||||
| 		tryRetrieveDataFromBackend(); | 		tryRetrieveDataFromBackend(); | ||||||
| 	} | 	} | ||||||
|  | @ -508,7 +482,8 @@ void QMLManager::tryRetrieveDataFromBackend() | ||||||
| 		setStartPageText(tr("Testing cloud credentials")); | 		setStartPageText(tr("Testing cloud credentials")); | ||||||
| 		appendTextToLog("Have credentials, let's see if they are valid"); | 		appendTextToLog("Have credentials, let's see if they are valid"); | ||||||
| 		CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this); | 		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
 | 		// let's wait here for the signal to avoid too many more nested functions
 | ||||||
| 		QTimer myTimer; | 		QTimer myTimer; | ||||||
| 		myTimer.setSingleShot(true); | 		myTimer.setSingleShot(true); | ||||||
|  | @ -524,7 +499,7 @@ void QMLManager::tryRetrieveDataFromBackend() | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		myTimer.stop(); | 		myTimer.stop(); | ||||||
| 		setCloudPin(""); | 		QMLPrefs::instance()->setCloudPin(""); | ||||||
| 		if (prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD) { | 		if (prefs.cloud_verification_status == 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); | ||||||
|  | @ -535,11 +510,11 @@ void QMLManager::tryRetrieveDataFromBackend() | ||||||
| 			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); | ||||||
| 			revertToNoCloudIfNeeded(); | 			revertToNoCloudIfNeeded(); | ||||||
| 			setShowPin(true); | 			QMLPrefs::instance()->setShowPin(true); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		if (m_showPin) | 		if (QMLPrefs::instance()->showPin()) | ||||||
| 			setShowPin(false); | 			QMLPrefs::instance()->setShowPin(false); | ||||||
| 
 | 
 | ||||||
| 		// now check the redirect URL to make sure everything is set up on the cloud server
 | 		// 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); | 		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
 | 		// 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); | ||||||
| 		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(); | ||||||
|  | @ -605,7 +580,7 @@ void QMLManager::retrieveUserid() | ||||||
| 		revertToNoCloudIfNeeded(); | 		revertToNoCloudIfNeeded(); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	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)) { | ||||||
|  | @ -624,7 +599,7 @@ void QMLManager::retrieveUserid() | ||||||
| 		s.setValue("subsurface_webservice_uid", prefs.userid); | 		s.setValue("subsurface_webservice_uid", prefs.userid); | ||||||
| 		s.sync(); | 		s.sync(); | ||||||
| 	} | 	} | ||||||
| 	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(); | ||||||
|  | @ -674,7 +649,7 @@ successful_exit: | ||||||
| 	setLoadFromCloud(true); | 	setLoadFromCloud(true); | ||||||
| 	// if we came from local storage mode, let's merge the local data into the local cache
 | 	// 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
 | 	// 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)"))); | 		git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)"))); | ||||||
| 		dive_table.preexisting = dive_table.nr; | 		dive_table.preexisting = dive_table.nr; | ||||||
| 		mergeLocalRepo(); | 		mergeLocalRepo(); | ||||||
|  | @ -702,7 +677,7 @@ void QMLManager::revertToNoCloudIfNeeded() | ||||||
| 		currentGitLocalOnly = false; | 		currentGitLocalOnly = false; | ||||||
| 		prefs.git_local_only = true; | 		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,
 | 		// 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
 | ||||||
|  | @ -716,9 +691,9 @@ void QMLManager::revertToNoCloudIfNeeded() | ||||||
| 		prefs.cloud_storage_email = NULL; | 		prefs.cloud_storage_email = NULL; | ||||||
| 		free((void *)prefs.cloud_storage_password); | 		free((void *)prefs.cloud_storage_password); | ||||||
| 		prefs.cloud_storage_password = NULL; | 		prefs.cloud_storage_password = NULL; | ||||||
| 		setCloudUserName(""); | 		QMLPrefs::instance()->setCloudUserName(""); | ||||||
| 		setCloudPassword(""); | 		QMLPrefs::instance()->setCloudPassword(""); | ||||||
| 		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); | ||||||
| 	} | 	} | ||||||
|  | @ -1183,7 +1158,7 @@ void QMLManager::openNoCloudRepo() | ||||||
| void QMLManager::saveChangesLocal() | void QMLManager::saveChangesLocal() | ||||||
| { | { | ||||||
| 	if (unsaved_changes()) { | 	if (unsaved_changes()) { | ||||||
| 		if (m_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); | ||||||
|  | @ -1426,52 +1401,6 @@ void QMLManager::setVerboseEnabled(bool verboseMode) | ||||||
| 	emit verboseEnabledChanged(); | 	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() | void QMLManager::syncLoadFromCloud() | ||||||
| { | { | ||||||
| 	QSettings s; | 	QSettings s; | ||||||
|  | @ -1494,28 +1423,6 @@ void QMLManager::setStartPageText(const QString& text) | ||||||
| 	emit startPageTextChanged(); | 	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) | QString QMLManager::getNumber(const QString& diveId) | ||||||
| { | { | ||||||
| 	int dive_id = diveId.toInt(); | 	int dive_id = diveId.toInt(); | ||||||
|  | @ -1647,24 +1554,12 @@ QStringList QMLManager::cylinderInit() const | ||||||
| 	return cylinders; | 	return cylinders; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void QMLManager::setShowPin(bool enable) |  | ||||||
| { |  | ||||||
| 	m_showPin = enable; |  | ||||||
| 	emit showPinChanged(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void QMLManager::setProgressMessage(QString text) | void QMLManager::setProgressMessage(QString text) | ||||||
| { | { | ||||||
| 	m_progressMessage = text; | 	m_progressMessage = text; | ||||||
| 	emit progressMessageChanged(); | 	emit progressMessageChanged(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void QMLManager::setDeveloper(bool value) |  | ||||||
| { |  | ||||||
| 	m_developer = value; |  | ||||||
| 	emit developerChanged(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void QMLManager::setBtEnabled(bool value) | void QMLManager::setBtEnabled(bool value) | ||||||
| { | { | ||||||
| 	m_btEnabled = value; | 	m_btEnabled = value; | ||||||
|  |  | ||||||
|  | @ -21,21 +21,12 @@ | ||||||
| 
 | 
 | ||||||
| class QMLManager : public QObject { | class QMLManager : public QObject { | ||||||
| 	Q_OBJECT | 	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(QString logText READ logText WRITE setLogText NOTIFY logTextChanged) | ||||||
| 	Q_PROPERTY(bool locationServiceEnabled MEMBER m_locationServiceEnabled WRITE setLocationServiceEnabled NOTIFY locationServiceEnabledChanged) | 	Q_PROPERTY(bool locationServiceEnabled MEMBER m_locationServiceEnabled WRITE setLocationServiceEnabled NOTIFY locationServiceEnabledChanged) | ||||||
| 	Q_PROPERTY(bool locationServiceAvailable MEMBER m_locationServiceAvailable WRITE setLocationServiceAvailable NOTIFY locationServiceAvailableChanged) | 	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(bool loadFromCloud MEMBER m_loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged) | ||||||
| 	Q_PROPERTY(QString startPageText MEMBER m_startPageText WRITE setStartPageText NOTIFY startPageTextChanged) | 	Q_PROPERTY(QString startPageText MEMBER m_startPageText WRITE setStartPageText NOTIFY startPageTextChanged) | ||||||
| 	Q_PROPERTY(bool verboseEnabled MEMBER m_verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged) | 	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(QString notificationText MEMBER m_notificationText WRITE setNotificationText NOTIFY notificationTextChanged) | ||||||
| 	Q_PROPERTY(bool syncToCloud MEMBER m_syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) | 	Q_PROPERTY(bool syncToCloud MEMBER m_syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) | ||||||
| 	Q_PROPERTY(int updateSelectedDive MEMBER m_updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged) | 	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 divemasterList READ divemasterList NOTIFY divemasterListChanged) | ||||||
| 	Q_PROPERTY(QStringList locationList READ locationList NOTIFY locationListChanged) | 	Q_PROPERTY(QStringList locationList READ locationList NOTIFY locationListChanged) | ||||||
| 	Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT) | 	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(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(bool btEnabled MEMBER m_btEnabled WRITE setBtEnabled NOTIFY btEnabledChanged) | ||||||
| 
 | 
 | ||||||
| 	Q_PROPERTY(QString DC_vendor READ DC_vendor WRITE DC_setVendor) | 	Q_PROPERTY(QString DC_vendor READ DC_vendor WRITE DC_setVendor) | ||||||
|  | @ -106,27 +95,10 @@ public: | ||||||
| 	Q_INVOKABLE int getDetectedVendorIndex(); | 	Q_INVOKABLE int getDetectedVendorIndex(); | ||||||
| 	Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText); | 	Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText); | ||||||
| public: | public: | ||||||
| 	enum cloud_status_qml { |  | ||||||
| 		CS_UNKNOWN, |  | ||||||
| 		CS_INCORRECT_USER_PASSWD, |  | ||||||
| 		CS_NEED_TO_VERIFY, |  | ||||||
| 		CS_VERIFIED, |  | ||||||
| 		CS_NOCLOUD |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	static QMLManager *instance(); | 	static QMLManager *instance(); | ||||||
| 	Q_INVOKABLE void registerError(QString error); | 	Q_INVOKABLE void registerError(QString error); | ||||||
| 	QString consumeError(); | 	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; | 	bool locationServiceEnabled() const; | ||||||
| 	void setLocationServiceEnabled(bool locationServiceEnable); | 	void setLocationServiceEnabled(bool locationServiceEnable); | ||||||
| 
 | 
 | ||||||
|  | @ -136,15 +108,6 @@ public: | ||||||
| 	bool verboseEnabled() const; | 	bool verboseEnabled() const; | ||||||
| 	void setVerboseEnabled(bool verboseMode); | 	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; | 	bool loadFromCloud() const; | ||||||
| 	void setLoadFromCloud(bool done); | 	void setLoadFromCloud(bool done); | ||||||
| 	void syncLoadFromCloud(); | 	void syncLoadFromCloud(); | ||||||
|  | @ -152,12 +115,6 @@ public: | ||||||
| 	QString startPageText() const; | 	QString startPageText() const; | ||||||
| 	void setStartPageText(const QString& text); | 	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; | 	QString logText() const; | ||||||
| 	void setLogText(const QString &logText); | 	void setLogText(const QString &logText); | ||||||
| 
 | 
 | ||||||
|  | @ -176,9 +133,6 @@ public: | ||||||
| 	QString progressMessage() const; | 	QString progressMessage() const; | ||||||
| 	void setProgressMessage(QString text); | 	void setProgressMessage(QString text); | ||||||
| 
 | 
 | ||||||
| 	bool developer() const; |  | ||||||
| 	void setDeveloper(bool value); |  | ||||||
| 
 |  | ||||||
| 	bool btEnabled() const; | 	bool btEnabled() const; | ||||||
| 	void setBtEnabled(bool value); | 	void setBtEnabled(bool value); | ||||||
| 
 | 
 | ||||||
|  | @ -189,8 +143,6 @@ public: | ||||||
| 	QStringList divemasterList() const; | 	QStringList divemasterList() const; | ||||||
| 	QStringList locationList() const; | 	QStringList locationList() const; | ||||||
| 	QStringList cylinderInit() const; | 	QStringList cylinderInit() const; | ||||||
| 	bool showPin() const; |  | ||||||
| 	void setShowPin(bool enable); |  | ||||||
| 	Q_INVOKABLE void setStatusbarColor(QColor color); | 	Q_INVOKABLE void setStatusbarColor(QColor color); | ||||||
| 	void btHostModeChange(QBluetoothLocalDevice::HostMode state); | 	void btHostModeChange(QBluetoothLocalDevice::HostMode state); | ||||||
| 
 | 
 | ||||||
|  | @ -227,8 +179,6 @@ public slots: | ||||||
| 	void populateGpsData(); | 	void populateGpsData(); | ||||||
| 	void cancelDownloadDC(); | 	void cancelDownloadDC(); | ||||||
| 	void clearGpsData(); | 	void clearGpsData(); | ||||||
| 	void clearCredentials(); |  | ||||||
| 	void cancelCredentialsPinSetup(); |  | ||||||
| 	void copyAppLogToClipboard(); | 	void copyAppLogToClipboard(); | ||||||
| 	void finishSetup(); | 	void finishSetup(); | ||||||
| 	void openLocalThenRemote(QString url); | 	void openLocalThenRemote(QString url); | ||||||
|  | @ -256,9 +206,6 @@ private: | ||||||
| 	SuitCompletionModel suitModel; | 	SuitCompletionModel suitModel; | ||||||
| 	DiveMasterCompletionModel divemasterModel; | 	DiveMasterCompletionModel divemasterModel; | ||||||
| 	LocationInformationModel locationModel; | 	LocationInformationModel locationModel; | ||||||
| 	QString m_cloudUserName; |  | ||||||
| 	QString m_cloudPassword; |  | ||||||
| 	QString m_cloudPin; |  | ||||||
| 	QString m_ssrfGpsWebUserid; | 	QString m_ssrfGpsWebUserid; | ||||||
| 	QString m_startPageText; | 	QString m_startPageText; | ||||||
| 	QString m_logText; | 	QString m_logText; | ||||||
|  | @ -266,8 +213,6 @@ private: | ||||||
| 	bool m_locationServiceEnabled; | 	bool m_locationServiceEnabled; | ||||||
| 	bool m_locationServiceAvailable; | 	bool m_locationServiceAvailable; | ||||||
| 	bool m_verboseEnabled; | 	bool m_verboseEnabled; | ||||||
| 	int m_distanceThreshold; |  | ||||||
| 	int m_timeThreshold; |  | ||||||
| 	GpsLocation *locationProvider; | 	GpsLocation *locationProvider; | ||||||
| 	bool m_loadFromCloud; | 	bool m_loadFromCloud; | ||||||
| 	static QMLManager *m_instance; | 	static QMLManager *m_instance; | ||||||
|  | @ -277,8 +222,6 @@ private: | ||||||
| 	bool m_syncToCloud; | 	bool m_syncToCloud; | ||||||
| 	int m_updateSelectedDive; | 	int m_updateSelectedDive; | ||||||
| 	int m_selectedDiveTimestamp; | 	int m_selectedDiveTimestamp; | ||||||
| 	cloud_status_qml m_credentialStatus; |  | ||||||
| 	cloud_status_qml m_oldStatus; |  | ||||||
| 	qreal m_lastDevicePixelRatio; | 	qreal m_lastDevicePixelRatio; | ||||||
| 	QElapsedTimer timer; | 	QElapsedTimer timer; | ||||||
| 	bool alreadySaving; | 	bool alreadySaving; | ||||||
|  | @ -287,10 +230,8 @@ private: | ||||||
| 	bool checkDuration(DiveObjectHelper *myDive, struct dive *d, QString duration); | 	bool checkDuration(DiveObjectHelper *myDive, struct dive *d, QString duration); | ||||||
| 	bool checkDepth(DiveObjectHelper *myDive, struct dive *d, QString depth); | 	bool checkDepth(DiveObjectHelper *myDive, struct dive *d, QString depth); | ||||||
| 	bool currentGitLocalOnly; | 	bool currentGitLocalOnly; | ||||||
| 	bool m_showPin; |  | ||||||
| 	Q_INVOKABLE DCDeviceData *m_device_data; | 	Q_INVOKABLE DCDeviceData *m_device_data; | ||||||
| 	QString m_progressMessage; | 	QString m_progressMessage; | ||||||
| 	bool m_developer; |  | ||||||
| 	bool m_btEnabled; | 	bool m_btEnabled; | ||||||
| 	void updateAllGlobalLists(); | 	void updateAllGlobalLists(); | ||||||
| 
 | 
 | ||||||
|  | @ -301,28 +242,18 @@ private: | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
| 	void cloudUserNameChanged(); |  | ||||||
| 	void cloudPasswordChanged(); |  | ||||||
| 	void cloudPinChanged(); |  | ||||||
| 	void locationServiceEnabledChanged(); | 	void locationServiceEnabledChanged(); | ||||||
| 	void locationServiceAvailableChanged(); | 	void locationServiceAvailableChanged(); | ||||||
| 	void verboseEnabledChanged(); | 	void verboseEnabledChanged(); | ||||||
| 	void logTextChanged(); | 	void logTextChanged(); | ||||||
| 	void timeThresholdChanged(); |  | ||||||
| 	void themeChanged(); |  | ||||||
| 	void distanceThresholdChanged(); |  | ||||||
| 	void loadFromCloudChanged(); | 	void loadFromCloudChanged(); | ||||||
| 	void startPageTextChanged(); | 	void startPageTextChanged(); | ||||||
| 	void credentialStatusChanged(); |  | ||||||
| 	void oldStatusChanged(); |  | ||||||
| 	void notificationTextChanged(); | 	void notificationTextChanged(); | ||||||
| 	void syncToCloudChanged(); | 	void syncToCloudChanged(); | ||||||
| 	void updateSelectedDiveChanged(); | 	void updateSelectedDiveChanged(); | ||||||
| 	void selectedDiveTimestampChanged(); | 	void selectedDiveTimestampChanged(); | ||||||
| 	void showPinChanged(); |  | ||||||
| 	void sendScreenChanged(QScreen *screen); | 	void sendScreenChanged(QScreen *screen); | ||||||
| 	void progressMessageChanged(); | 	void progressMessageChanged(); | ||||||
| 	void developerChanged(); |  | ||||||
| 	void btEnabledChanged(); | 	void btEnabledChanged(); | ||||||
| 	void suitListChanged(); | 	void suitListChanged(); | ||||||
| 	void buddyListChanged(); | 	void buddyListChanged(); | ||||||
|  |  | ||||||
|  | @ -1,11 +1,25 @@ | ||||||
| // SPDX-License-Identifier: GPL-2.0
 | // SPDX-License-Identifier: GPL-2.0
 | ||||||
| #include "qmlprefs.h" | #include "qmlprefs.h" | ||||||
|  | #include "qmlmanager.h" | ||||||
| 
 | 
 | ||||||
|  | #include "core/membuffer.h" | ||||||
|  | #include "core/subsurface-qt/SettingsObjectWrapper.h" | ||||||
|  | #include "core/gpslocation.h" | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /*** Global and constructors ***/ | ||||||
| QMLPrefs *QMLPrefs::m_instance = NULL; | 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) | 	if (!m_instance) | ||||||
| 		m_instance = this; | 		m_instance = this; | ||||||
| } | } | ||||||
|  | @ -19,3 +33,164 @@ QMLPrefs *QMLPrefs::instance() | ||||||
| { | { | ||||||
| 	return m_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); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -7,6 +7,47 @@ | ||||||
| 
 | 
 | ||||||
| class QMLPrefs : public QObject { | class QMLPrefs : public QObject { | ||||||
| 	Q_OBJECT | 	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: | public: | ||||||
| 	QMLPrefs(); | 	QMLPrefs(); | ||||||
|  | @ -14,12 +55,70 @@ 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; | ||||||
|  | 	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: | public slots: | ||||||
|  | 	void cancelCredentialsPinSetup(); | ||||||
|  | 	void clearCredentials(); | ||||||
| 
 | 
 | ||||||
| private: | 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; | 	static QMLPrefs *m_instance; | ||||||
|  | 	cloud_status_qml m_oldStatus; | ||||||
|  | 	bool m_showPin; | ||||||
|  | 	int m_timeThreshold; | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|  | 	void cloudPasswordChanged(); | ||||||
|  | 	void cloudPinChanged(); | ||||||
|  | 	void cloudUserNameChanged(); | ||||||
|  | 	void credentialStatusChanged(); | ||||||
|  | 	void distanceThresholdChanged(); | ||||||
|  | 	void developerChanged(); | ||||||
|  | 	void oldStatusChanged(); | ||||||
|  | 	void showPinChanged(); | ||||||
|  | 	void themeChanged(); | ||||||
|  | 	void timeThresholdChanged(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue