summaryrefslogtreecommitdiffstats
path: root/qt-gui.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-22 23:24:33 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-22 23:24:33 -0700
commitc917a99eb2973701a79ba8bdb6002bb6ec0ad880 (patch)
tree12fe6edd7571812e92d0451f00081f513152f404 /qt-gui.cpp
parent115e5e5fbc5fcf190ceafaa2b800160cec93d52e (diff)
downloadsubsurface-c917a99eb2973701a79ba8bdb6002bb6ec0ad880.tar.gz
Implement default dive computer and device
The data is saved in the settings and the correct dive computer (vendor and product) and device are picked when the download dialog is openend. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r--qt-gui.cpp96
1 files changed, 78 insertions, 18 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 7aeea36a3..38038bf61 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -20,6 +20,7 @@
#include "version.h"
#include "libdivecomputer.h"
#include "qt-ui/mainwindow.h"
+#include "helpers.h"
#include <QApplication>
#include <QFileDialog>
@@ -30,6 +31,10 @@
#include <QSettings>
#include <QDesktopWidget>
+const char *default_dive_computer_vendor;
+const char *default_dive_computer_product;
+const char *default_dive_computer_device;
+
class Translator: public QTranslator
{
Q_OBJECT
@@ -66,6 +71,18 @@ void init_qt_ui(int *argcp, char ***argvp, char *errormessage)
window->show();
}
+const char *getSetting(QSettings &s, char *name)
+{
+ QVariant v;
+ QString text;
+ v = s.value(name);
+ if (v.isValid()) {
+ text = v.toString();
+ return strdup(text.toUtf8());
+ }
+ return NULL;
+}
+
void init_ui(int *argcp, char ***argvp)
{
QVariant v;
@@ -82,22 +99,15 @@ void init_ui(int *argcp, char ***argvp)
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
QCoreApplication::setApplicationName("Subsurface");
- QSettings settings;
- settings.beginGroup("GeneralSettings");
- v = settings.value(QString("default_filename"));
- if (v.isValid()) {
- QString name = v.toString();
- prefs.default_filename = strdup(name.toUtf8());
- }
- settings.endGroup();
-
-#if 0
-
- /* these still need to be handled in QSettings */
- default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor");
- default_dive_computer_product = subsurface_get_conf("dive_computer_product");
- default_dive_computer_device = subsurface_get_conf("dive_computer_device");
-#endif
+ QSettings s;
+ s.beginGroup("GeneralSettings");
+ prefs.default_filename = getSetting(s, "default_filename");
+ s.endGroup();
+ 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");
+ s.endGroup();
return;
}
@@ -111,8 +121,8 @@ void exit_ui(void)
delete application;
if (existing_filename)
free((void *)existing_filename);
-// if (default_dive_computer_device)
-// free((void *)default_dive_computer_device);
+ if (default_dive_computer_device)
+ free((void *)default_dive_computer_device);
}
void set_filename(const char *filename, gboolean force)
@@ -205,4 +215,54 @@ double get_screen_dpi()
QDesktopWidget *mydesk = application->desktop();
return mydesk->physicalDpiX();
}
+
+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);
+}
+
+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;
+ if (default_dive_computer_vendor)
+ free((void *)default_dive_computer_vendor);
+ if (default_dive_computer_product)
+ 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;
+ if (default_dive_computer_device)
+ free((void *)default_dive_computer_device);
+ default_dive_computer_device = strdup(name);
+ s.beginGroup("DiveComputer");
+ s.setValue("dive_computer_device", name);
+ s.endGroup();
+}
+
#include "qt-gui.moc"