summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp101
1 files changed, 44 insertions, 57 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 5ede64152..91beb3c84 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -2,7 +2,6 @@
#include "qmlmanager.h"
#include "qmlprefs.h"
#include <QUrl>
-#include <QSettings>
#include <QDebug>
#include <QNetworkAccessManager>
#include <QAuthenticator>
@@ -33,7 +32,7 @@
#include "core/downloadfromdcthread.h"
#include "core/subsurface-string.h"
#include "core/pref.h"
-#include "core/subsurface-qt/SettingsObjectWrapper.h"
+#include "core/settings/qPref.h"
#include "core/ssrf.h"
@@ -253,10 +252,10 @@ void QMLManager::openLocalThenRemote(QString url)
clear_dive_file_data();
setNotificationText(tr("Open local dive data file"));
QByteArray fileNamePrt = QFile::encodeName(url);
- bool glo = prefs.git_local_only;
+ bool glo = qPrefCloudStorage::git_local_only();
prefs.git_local_only = true;
- int error = parse_file(fileNamePrt.data());
- prefs.git_local_only = glo;
+ int error = parse_file(fileNamePrt.data(), &dive_table);
+ qPrefCloudStorage::set_git_local_only(glo);
if (error) {
appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error));
setNotificationText(tr("Opening local data file failed"));
@@ -277,16 +276,16 @@ void QMLManager::openLocalThenRemote(QString url)
if (QMLPrefs::instance()->credentialStatus() == qPref::CS_UNKNOWN)
QMLPrefs::instance()->setCredentialStatus(qPref::CS_VERIFIED);
prefs.unit_system = git_prefs.unit_system;
- if (git_prefs.unit_system == IMPERIAL)
+ if (qPrefUnits::unit_system() == IMPERIAL)
git_prefs.units = IMPERIAL_units;
else if (git_prefs.unit_system == METRIC)
git_prefs.units = SI_units;
prefs.units = git_prefs.units;
- prefs.tankbar = git_prefs.tankbar;
- prefs.dcceiling = git_prefs.dcceiling;
- prefs.show_ccr_setpoint = git_prefs.show_ccr_setpoint;
- prefs.show_ccr_sensors = git_prefs.show_ccr_sensors;
- prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2;
+ qPrefTechnicalDetails::set_tankbar(git_prefs.tankbar);
+ qPrefTechnicalDetails::set_dcceiling(git_prefs.dcceiling);
+ qPrefTechnicalDetails::set_show_ccr_setpoint(git_prefs.show_ccr_setpoint);
+ qPrefTechnicalDetails::set_show_ccr_sensors(git_prefs.show_ccr_sensors);
+ qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2);
process_dives(false, false);
DiveListModel::instance()->clear();
DiveListModel::instance()->addAllDives();
@@ -299,11 +298,11 @@ void QMLManager::openLocalThenRemote(QString url)
}
if (QMLPrefs::instance()->oldStatus() == qPref::CS_NOCLOUD) {
// if we switch to credentials from CS_NOCLOUD, we take things online temporarily
- prefs.git_local_only = false;
+ qPrefCloudStorage::set_git_local_only(false);
appendTextToLog(QStringLiteral("taking things online to be able to switch to cloud account"));
}
set_filename(fileNamePrt.data());
- if (prefs.git_local_only) {
+ if (qPrefCloudStorage::git_local_only()) {
appendTextToLog(QStringLiteral("have cloud credentials, but user asked not to connect to network"));
alreadySaving = false;
} else {
@@ -324,7 +323,7 @@ void QMLManager::updateAllGlobalLists()
void QMLManager::mergeLocalRepo()
{
char *filename = NOCLOUD_LOCALSTORAGE;
- parse_file(filename);
+ parse_file(filename, &dive_table);
process_dives(true, false);
}
@@ -371,9 +370,9 @@ void QMLManager::copyAppLogToClipboard()
void QMLManager::finishSetup()
{
// Initialize cloud credentials.
- QMLPrefs::instance()->setCloudUserName(prefs.cloud_storage_email);
- QMLPrefs::instance()->setCloudPassword(prefs.cloud_storage_password);
- setSyncToCloud(!prefs.git_local_only);
+ QMLPrefs::instance()->setCloudUserName(qPrefCloudStorage::cloud_storage_email());
+ QMLPrefs::instance()->setCloudPassword(qPrefCloudStorage::cloud_storage_password());
+ setSyncToCloud(!qPrefCloudStorage::git_local_only());
QMLPrefs::instance()->setCredentialStatus((qPref::cloud_status) prefs.cloud_verification_status);
// if the cloud credentials are valid, we should get the GPS Webservice ID as well
QString url;
@@ -389,7 +388,7 @@ void QMLManager::finishSetup()
QMLPrefs::instance()->setCredentialStatus(qPref::CS_NOCLOUD);
saveCloudCredentials();
appendTextToLog(tr("working in no-cloud mode"));
- int error = parse_file(existing_filename);
+ int error = parse_file(existing_filename, &dive_table);
if (error) {
// we got an error loading the local file
setNotificationText(tr("Error parsing local storage, giving up"));
@@ -404,8 +403,8 @@ void QMLManager::finishSetup()
appendTextToLog(tr("no cloud credentials"));
setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
}
- QMLPrefs::instance()->setDistanceThreshold(prefs.distance_threshold);
- QMLPrefs::instance()->setTimeThreshold(prefs.time_threshold / 60);
+ QMLPrefs::instance()->setDistanceThreshold(qPrefLocationService::distance_threshold());
+ QMLPrefs::instance()->setTimeThreshold(qPrefLocationService::time_threshold() / 60);
}
QMLManager::~QMLManager()
@@ -424,9 +423,8 @@ QMLManager *QMLManager::instance()
void QMLManager::savePreferences()
{
- auto location = SettingsObjectWrapper::instance()->location_settings;
- location->set_time_threshold(QMLPrefs::instance()->timeThreshold() * 60);
- location->set_distance_threshold(QMLPrefs::instance()->distanceThreshold());
+ qPrefLocationService::set_time_threshold(QMLPrefs::instance()->timeThreshold() * 60);
+ qPrefLocationService::set_distance_threshold(QMLPrefs::instance()->distanceThreshold());
}
#define CLOUDURL QString(prefs.cloud_base_url)
@@ -434,7 +432,6 @@ void QMLManager::savePreferences()
void QMLManager::saveCloudCredentials()
{
- QSettings s;
bool cloudCredentialsChanged = false;
// make sure we only have letters, numbers, and +-_. in password and email address
QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$");
@@ -453,11 +450,9 @@ void QMLManager::saveCloudCredentials()
return;
}
}
- s.beginGroup("CloudStorage");
- s.setValue("email", QMLPrefs::instance()->cloudUserName());
- s.setValue("password", QMLPrefs::instance()->cloudPassword());
- s.setValue("cloud_verification_status", QMLPrefs::instance()->credentialStatus());
- s.sync();
+ qPrefCloudStorage::set_cloud_storage_email(QMLPrefs::instance()->cloudUserName());
+ qPrefCloudStorage::set_cloud_storage_password(QMLPrefs::instance()->cloudPassword());
+ qPrefCloudStorage::set_cloud_verification_status(QMLPrefs::instance()->credentialStatus());
if (!same_string(prefs.cloud_storage_email,
qPrintable(QMLPrefs::instance()->cloudUserName()))) {
free((void *)prefs.cloud_storage_email);
@@ -638,9 +633,7 @@ void QMLManager::retrieveUserid()
// overwrite the existing userid
free((void *)prefs.userid);
prefs.userid = copy_qstring(userid);
- QSettings s;
- s.setValue("subsurface_webservice_uid", prefs.userid);
- s.sync();
+ qPrefCloudStorage::set_userid(prefs.userid);
}
QMLPrefs::instance()->setCredentialStatus(qPref::CS_VERIFIED);
setStartPageText(tr("Cloud credentials valid, loading dives..."));
@@ -679,7 +672,7 @@ void QMLManager::loadDivesWithValidCredentials()
error = git_load_dives(git, branch);
} else {
appendTextToLog(QString("didn't receive valid git repo, try again"));
- error = parse_file(fileNamePrt.data());
+ error = parse_file(fileNamePrt.data(), &dive_table);
}
if (!error) {
report_error("filename is now %s", fileNamePrt.data());
@@ -1041,7 +1034,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
}
// not sure what we'd do if there was more than one weight system
// defined - for now just ignore that case
- if (weightsystem_none((void *)&d->weightsystem[1])) {
+ if (weightsystem_none(&d->weightsystem[1])) {
if (myDive->sumWeight() != weight) {
diveChanged = true;
d->weightsystem[0].weight.grams = parseWeightToGrams(weight);
@@ -1210,9 +1203,9 @@ void QMLManager::openNoCloudRepo()
if (git == dummy_git_repository) {
git_create_local_repo(filename);
set_filename(filename);
- auto s = SettingsObjectWrapper::instance()->general_settings;
- s->setDefaultFilename(filename);
- s->setDefaultFileBehavior(LOCAL_DEFAULT_FILE);
+ auto s = qPrefGeneral::instance();
+ s->set_default_filename(filename);
+ s->set_default_file_behavior(LOCAL_DEFAULT_FILE);
}
openLocalThenRemote(filename);
@@ -1226,9 +1219,9 @@ void QMLManager::saveChangesLocal()
char *filename = NOCLOUD_LOCALSTORAGE;
git_create_local_repo(filename);
set_filename(filename);
- auto s = SettingsObjectWrapper::instance()->general_settings;
- s->setDefaultFilename(filename);
- s->setDefaultFileBehavior(LOCAL_DEFAULT_FILE);
+ auto s = qPrefGeneral::instance();
+ s->set_default_filename(filename);
+ s->set_default_file_behavior(LOCAL_DEFAULT_FILE);
}
} else if (!m_loadFromCloud) {
// this seems silly, but you need a common ancestor in the repository in
@@ -1466,16 +1459,12 @@ void QMLManager::setVerboseEnabled(bool verboseMode)
void QMLManager::syncLoadFromCloud()
{
- QSettings s;
- QString cloudMarker = QLatin1Literal("loadFromCloud") + QString(prefs.cloud_storage_email);
- m_loadFromCloud = s.contains(cloudMarker) && s.value(cloudMarker).toBool();
+ m_loadFromCloud = qPrefCloudStorage::loadFromCloud(prefs.cloud_storage_email);
}
void QMLManager::setLoadFromCloud(bool done)
{
- QSettings s;
- QString cloudMarker = QLatin1Literal("loadFromCloud") + QString(prefs.cloud_storage_email);
- s.setValue(cloudMarker, done);
+ qPrefCloudStorage::set_loadFromCloud(prefs.cloud_storage_email, done);
m_loadFromCloud = done;
emit loadFromCloudChanged();
}
@@ -1537,9 +1526,7 @@ void QMLManager::setSyncToCloud(bool status)
{
m_syncToCloud = status;
prefs.git_local_only = !status;
- QSettings s;
- s.beginGroup("CloudStorage");
- s.setValue("git_local_only", prefs.git_local_only);
+ qPrefCloudStorage::set_git_local_only(prefs.git_local_only);
emit syncToCloudChanged();
}
@@ -1837,47 +1824,47 @@ void QMLManager::showDownloadPage(QString deviceString)
.arg(productList["Atomic Aquatics"].indexOf("Cobalt"))
.arg(connectionListModel.indexOf("USB device"));
}
- } else if (deviceString.contains("mVendorId=5267") &&
+ } else if (deviceString.contains("mVendorId=5267") && // 0x1493 / 0x0030
deviceString.contains("mProductId=48")) {
name = QString("%1;%2;%3")
.arg(connectionListModel.indexOf("Suunto"))
.arg(productList["Suunto"].indexOf("EON Steel"))
.arg(connectionListModel.indexOf("USB device"));
- } else if (deviceString.contains("mVendorId=5267") &&
+ } else if (deviceString.contains("mVendorId=5267") && // 0x1493 / 0x0033
deviceString.contains("mProductId=51")) {
name = QString("%1;%2;%3")
.arg(connectionListModel.indexOf("Suunto"))
.arg(productList["Suunto"].indexOf("EON Core"))
.arg(connectionListModel.indexOf("USB device"));
- } else if (deviceString.contains("mVendorId=11884") &&
+ } else if (deviceString.contains("mVendorId=11884") && // 0x2e6c / 0x3201
deviceString.contains("mProductId=12801")) {
name = QString("%1;%2;%3")
.arg(connectionListModel.indexOf("Scubapro"))
.arg(productList["Suunto"].indexOf("G2"))
.arg(connectionListModel.indexOf("USB device"));
- } else if (deviceString.contains("mVendorId=49745") &&
+ } else if (deviceString.contains("mVendorId=49745") && // 0xc251 / 0x2006
deviceString.contains("mProductId=8198")) {
name = QString("%1;%2;%3")
.arg(connectionListModel.indexOf("Scubapro"))
.arg(productList["Suunto"].indexOf("Aladin Square"))
.arg(connectionListModel.indexOf("USB device"));
- } else if (deviceString.contains("mVendorId=1027") &&
+ } else if (deviceString.contains("mVendorId=1027") && // 0x0403 / 0x6001,0x6010,0x6011,0x6015
(deviceString.contains("mProductId=24577") ||
deviceString.contains("mProductId=24592") ||
deviceString.contains("mProductId=24593") ||
deviceString.contains("mProductId=24597"))) {
name = QString("-1;-1;%1").arg(connectionListModel.indexOf("FTDI"));
- } else if (deviceString.contains("mVendorId=1027") &&
+ } else if (deviceString.contains("mVendorId=1027") && // 0x0403 / 0xf460
deviceString.contains("mProductId=62560")) {
name = QString("%1;-1;%2")
.arg(vendorList.indexOf("Oceanic"))
.arg(connectionListModel.indexOf("FTDI"));
- } else if (deviceString.contains("mVendorId=1027") &&
+ } else if (deviceString.contains("mVendorId=1027") && // 0x0403 / 0xf680
deviceString.contains("mProductId=63104")) {
name = QString("%1;-1;%2")
.arg(vendorList.indexOf("Suunto"))
.arg(connectionListModel.indexOf("FTDI"));
- } else if (deviceString.contains("mVendorId=1027") &&
+ } else if (deviceString.contains("mVendorId=1027") && // 0x0403 / 0x87d0
deviceString.contains("mProductId=34768")) {
name = QString("%1;-1;%2")
.arg(vendorList.indexOf("Cressi"))