summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@gmail.com>2016-08-10 18:10:15 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-08-27 11:40:44 -0700
commitdb8e8957abc8b8dc407a94835e686f649c9643a6 (patch)
tree5c21bd7e9a4174704e1c53752146c1229464b2bc
parentb264c3e36704c83a6c9353fe5eac3dc0eb3c9a80 (diff)
downloadsubsurface-db8e8957abc8b8dc407a94835e686f649c9643a6.tar.gz
Settings update: Add "Dive Computer" settings to SettingsObjectWrapper
For some reason, the dive computer settings weren't in the settings prefs. This moves it, makes the boilerplate on Settings ObjectWrapper and make things compile. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/divecomputer.cpp59
-rw-r--r--core/helpers.h3
-rw-r--r--core/pref.h8
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp62
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h32
-rw-r--r--desktop-widgets/configuredivecomputerdialog.cpp9
-rw-r--r--desktop-widgets/downloadfromdivecomputer.cpp31
-rw-r--r--desktop-widgets/mainwindow.cpp20
-rw-r--r--subsurface-desktop-helper.cpp3
9 files changed, 132 insertions, 95 deletions
diff --git a/core/divecomputer.cpp b/core/divecomputer.cpp
index e4081e1cd..5a79f3981 100644
--- a/core/divecomputer.cpp
+++ b/core/divecomputer.cpp
@@ -1,12 +1,9 @@
#include "divecomputer.h"
#include "dive.h"
+#include "subsurface-qt/SettingsObjectWrapper.h"
#include <QSettings>
-const char *default_dive_computer_vendor;
-const char *default_dive_computer_product;
-const char *default_dive_computer_device;
-int default_dive_computer_download_mode;
DiveComputerList dcList;
DiveComputerList::DiveComputerList()
@@ -144,60 +141,14 @@ extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *
extern "C" int is_default_dive_computer(const char *vendor, const char *product)
{
- return default_dive_computer_vendor && !strcmp(vendor, default_dive_computer_vendor) &&
- default_dive_computer_product && !strcmp(product, default_dive_computer_product);
+ auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
+ return dc->dc_vendor() == vendor && dc->dc_product() == product;
}
extern "C" int is_default_dive_computer_device(const char *name)
{
- return default_dive_computer_device && !strcmp(name, default_dive_computer_device);
-}
-
-void set_default_dive_computer(const char *vendor, const char *product)
-{
- QSettings s;
-
- if (!vendor || !*vendor)
- return;
- if (!product || !*product)
- return;
- if (is_default_dive_computer(vendor, product))
- return;
-
- free((void *)default_dive_computer_vendor);
- free((void *)default_dive_computer_product);
- default_dive_computer_vendor = strdup(vendor);
- default_dive_computer_product = strdup(product);
- s.beginGroup("DiveComputer");
- s.setValue("dive_computer_vendor", vendor);
- s.setValue("dive_computer_product", product);
- s.endGroup();
-}
-
-void set_default_dive_computer_device(const char *name)
-{
- QSettings s;
-
- if (!name || !*name)
- return;
- if (is_default_dive_computer_device(name))
- return;
-
- free((void *)default_dive_computer_device);
- default_dive_computer_device = strdup(name);
- s.beginGroup("DiveComputer");
- s.setValue("dive_computer_device", name);
- s.endGroup();
-}
-
-void set_default_dive_computer_download_mode(int download_mode)
-{
- QSettings s;
-
- default_dive_computer_download_mode = download_mode;
- s.beginGroup("DiveComputer");
- s.setValue("dive_computer_download_mode", download_mode);
- s.endGroup();
+ auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
+ return dc->dc_device() == name;
}
extern "C" void set_dc_nickname(struct dive *dive)
diff --git a/core/helpers.h b/core/helpers.h
index b9f7f50ca..a4a903ea6 100644
--- a/core/helpers.h
+++ b/core/helpers.h
@@ -22,9 +22,6 @@ QString get_volume_string(volume_t volume, bool showunit = false);
QString get_volume_unit();
QString get_pressure_string(pressure_t pressure, bool showunit = false);
QString get_pressure_unit();
-void set_default_dive_computer(const char *vendor, const char *product);
-void set_default_dive_computer_device(const char *name);
-void set_default_dive_computer_download_mode(int downloadMode);
QString getSubsurfaceDataPath(QString folderToFind);
QString getPrintingTemplatePathUser();
QString getPrintingTemplatePathBundle();
diff --git a/core/pref.h b/core/pref.h
index 304bc0b63..c6c30878d 100644
--- a/core/pref.h
+++ b/core/pref.h
@@ -49,6 +49,13 @@ typedef struct {
char *next_check;
} update_manager_prefs_t;
+typedef struct {
+ char *vendor;
+ char *product;
+ char *device;
+ int download_mode;
+} dive_computer_prefs_t;
+
struct preferences {
const char *divelist_font;
const char *default_filename;
@@ -141,6 +148,7 @@ struct preferences {
short cloud_timeout;
locale_prefs_t locale; //: TODO: move the rest of locale based info here.
update_manager_prefs_t update_manager;
+ dive_computer_prefs_t dive_computer;
};
enum unit_system_values {
METRIC,
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 6d66c9864..7c6001984 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -6,6 +6,65 @@
#include "../dive.h" // TODO: remove copy_string from dive.h
+DiveComputerSettings::DiveComputerSettings(QObject *parent):
+ QObject(parent), group(QStringLiteral("DiveComputer"))
+{
+}
+
+QString DiveComputerSettings::dc_vendor() const
+{
+ return prefs.dive_computer.vendor;
+}
+
+QString DiveComputerSettings::dc_product() const
+{
+ return prefs.dive_computer.product;
+}
+
+QString DiveComputerSettings::dc_device() const
+{
+ return prefs.dive_computer.device;
+}
+
+int DiveComputerSettings::downloadMode() const
+{
+ return prefs.dive_computer.download_mode;
+}
+
+void DiveComputerSettings::setVendor(const QString& vendor)
+{
+ QSettings s;
+ s.beginGroup(group);
+ s.setValue("dive_computer_vendor", vendor);
+ free(prefs.dive_computer.vendor);
+ prefs.dive_computer.vendor = copy_string(qPrintable(vendor));
+}
+
+void DiveComputerSettings::setProduct(const QString& product)
+{
+ QSettings s;
+ s.beginGroup(group);
+ s.setValue("dive_computer_product", product);
+ free(prefs.dive_computer.product);
+ prefs.dive_computer.product = copy_string(qPrintable(product));
+}
+
+void DiveComputerSettings::setDevice(const QString& device)
+{
+ QSettings s;
+ s.beginGroup(group);
+ s.setValue("dive_computer_device", device);
+ free(prefs.dive_computer.device);
+ prefs.dive_computer.device = copy_string(qPrintable(device));
+}
+
+void DiveComputerSettings::setDownloadMode(int mode)
+{
+ QSettings s;
+ s.beginGroup(group);
+ s.setValue("dive_computer_download_mode", mode);
+ prefs.dive_computer.download_mode = mode;
+}
UpdateManagerSettings::UpdateManagerSettings(QObject *parent) : QObject(parent), group("UpdateManager")
{
@@ -1679,7 +1738,8 @@ QObject(parent),
language_settings(new LanguageSettingsObjectWrapper(this)),
animation_settings(new AnimationsSettingsObjectWrapper(this)),
location_settings(new LocationServiceSettingsObjectWrapper(this)),
- update_manager_settings(new UpdateManagerSettings(this))
+ update_manager_settings(new UpdateManagerSettings(this)),
+ dive_computer_settings(new DiveComputerSettings(this))
{
}
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index 392bf068b..472150a42 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -11,6 +11,34 @@
* and QWidget frontends. This class will be huge, since
* I need tons of properties, one for each option. */
+class DiveComputerSettings : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString vendor READ dc_vendor WRITE setVendor NOTIFY vendorChanged)
+ Q_PROPERTY(QString product READ dc_product WRITE setProduct NOTIFY productChanged)
+ Q_PROPERTY(QString device READ dc_device WRITE setDevice NOTIFY deviceChanged)
+ Q_PROPERTY(int download_mode READ downloadMode WRITE setDownloadMode NOTIFY downloadModeChanged)
+public:
+ DiveComputerSettings(QObject *parent);
+ QString dc_vendor() const;
+ QString dc_product() const;
+ QString dc_device() const;
+ int downloadMode() const;
+
+public slots:
+ void setVendor(const QString& vendor);
+ void setProduct(const QString& product);
+ void setDevice(const QString& device);
+ void setDownloadMode(int mode);
+
+signals:
+ void vendorChanged(const QString& vendor);
+ void productChanged(const QString& product);
+ void deviceChanged(const QString& device);
+ void downloadModeChanged(int mode);
+private:
+ QString group;
+
+};
class UpdateManagerSettings : public QObject {
Q_OBJECT
Q_PROPERTY(bool dont_check_for_updates READ dontCheckForUpdates WRITE setDontCheckForUpdates NOTIFY dontCheckForUpdatesChanged)
@@ -647,7 +675,7 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT)
Q_PROPERTY(UpdateManagerSettings* update MEMBER update_manager_settings CONSTANT)
-
+ Q_PROPERTY(DiveComputerSettings* dive_computer MEMBER dive_computer_settings CONSTANT)
public:
static SettingsObjectWrapper *instance();
@@ -665,6 +693,8 @@ public:
AnimationsSettingsObjectWrapper *animation_settings;
LocationServiceSettingsObjectWrapper *location_settings;
UpdateManagerSettings *update_manager_settings;
+ DiveComputerSettings *dive_computer_settings;
+
private:
SettingsObjectWrapper(QObject *parent = NULL);
};
diff --git a/desktop-widgets/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp
index 471db9a65..79cdcaf2f 100644
--- a/desktop-widgets/configuredivecomputerdialog.cpp
+++ b/desktop-widgets/configuredivecomputerdialog.cpp
@@ -3,6 +3,7 @@
#include "core/helpers.h"
#include "desktop-widgets/mainwindow.h"
#include "core/display.h"
+#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QFileDialog>
#include <QMessageBox>
@@ -150,8 +151,9 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia
memset(&device_data, 0, sizeof(device_data));
fill_computer_list();
- if (default_dive_computer_device)
- ui.device->setEditText(default_dive_computer_device);
+ auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
+ if (!dc->dc_device().isEmpty())
+ ui.device->setEditText(dc->dc_device());
ui.DiveComputerList->setCurrentRow(0);
on_DiveComputerList_currentRowChanged(0);
@@ -775,7 +777,8 @@ void ConfigureDiveComputerDialog::getDeviceData()
device_data.descriptor = descriptorLookup[selected_vendor + selected_product];
device_data.deviceid = device_data.diveid = 0;
- set_default_dive_computer_device(device_data.devname);
+ auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
+ dc->setDevice(device_data.devname);
}
void ConfigureDiveComputerDialog::on_cancel_clicked()
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index 7ef4e1e28..d58589636 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -4,6 +4,7 @@
#include "desktop-widgets/divelistview.h"
#include "core/display.h"
#include "core/uemis.h"
+#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include "qt-models/models.h"
#include <QTimer>
@@ -78,15 +79,17 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
connect(ui.unselectAllButton, SIGNAL(clicked()), diveImportedModel, SLOT(selectNone()));
vendorModel = new QStringListModel(vendorList);
ui.vendor->setModel(vendorModel);
- if (default_dive_computer_vendor) {
- ui.vendor->setCurrentIndex(ui.vendor->findText(default_dive_computer_vendor));
- productModel = new QStringListModel(productList[default_dive_computer_vendor]);
+
+ auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
+ if (!dc->dc_vendor().isEmpty()) {
+ ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor()));
+ productModel = new QStringListModel(productList[dc->dc_vendor()]);
ui.product->setModel(productModel);
- if (default_dive_computer_product)
- ui.product->setCurrentIndex(ui.product->findText(default_dive_computer_product));
+ if (!dc->dc_product().isEmpty())
+ ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
}
- if (default_dive_computer_device)
- ui.device->setEditText(default_dive_computer_device);
+ if (!dc->dc_device().isEmpty())
+ ui.device->setEditText(dc->dc_device());
timer->setInterval(200);
connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
@@ -102,7 +105,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
ui.bluetoothMode->setText(tr("Choose Bluetooth download mode"));
- ui.bluetoothMode->setChecked(default_dive_computer_download_mode == DC_TRANSPORT_BLUETOOTH);
+ ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH);
btDeviceSelectionDialog = 0;
ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
@@ -337,16 +340,20 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
data.create_new_trip = ui.createNewTrip->isChecked();
data.trip = NULL;
data.deviceid = data.diveid = 0;
- set_default_dive_computer(data.vendor, data.product);
- set_default_dive_computer_device(data.devname);
+
+ auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
+ dc->setVendor(data.vendor);
+ dc->setProduct(data.product);
+ dc->setDevice(data.devname);
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
- set_default_dive_computer_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
+ dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
#endif
- thread = new DownloadThread(this, &data);
+ thread = new DownloadThread(this, &data);
connect(thread, SIGNAL(finished()),
this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
+ //TODO: Don't call mainwindow.
MainWindow *w = MainWindow::instance();
connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 868545600..78faaadc5 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -1305,33 +1305,17 @@ void MainWindow::initialUiSetup()
show();
}
-const char *getSetting(const QSettings &s,const QString& name)
-{
- QVariant v;
- v = s.value(name);
- if (v.isValid()) {
- return strdup(v.toString().toUtf8().data());
- }
- return NULL;
-}
-
void MainWindow::readSettings()
{
static bool firstRun = true;
-
- QSettings s; //WARNING: Why those prefs are not on the prefs struct?
- s.beginGroup("DiveComputer");
- default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
- default_dive_computer_product = getSetting(s, "dive_computer_product");
- default_dive_computer_device = getSetting(s, "dive_computer_device");
- default_dive_computer_download_mode = s.value("dive_computer_download_mode").toInt();
- s.endGroup();
init_proxy();
// now make sure that the cloud menu items are enabled IFF cloud account is verified
enableDisableCloudActions();
#if !defined(SUBSURFACE_MOBILE)
+ QSettings s; //TODO: this 's' exists only for the loadRecentFiles, remove it.
+
loadRecentFiles(&s);
if (firstRun) {
checkSurvey(&s);
diff --git a/subsurface-desktop-helper.cpp b/subsurface-desktop-helper.cpp
index ef349ad3d..f8d8ba1c7 100644
--- a/subsurface-desktop-helper.cpp
+++ b/subsurface-desktop-helper.cpp
@@ -50,9 +50,6 @@ void exit_ui()
delete window;
delete qApp;
free((void *)existing_filename);
- free((void *)default_dive_computer_vendor);
- free((void *)default_dive_computer_product);
- free((void *)default_dive_computer_device);
}
double get_screen_dpi()