Changeset db8e8957 in subsurface


Ignore:
Timestamp:
Aug 27, 2016, 11:40:44 AM (10 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
ee91002
Parents:
b264c3e
git-author:
Tomaz Canabrava <tomaz.canabrava@…> (08/10/16 14:10:15)
git-committer:
Dirk Hohndel <dirk@…> (08/27/16 11:40:44)
Message:

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@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • core/divecomputer.cpp

    r7be962b rdb8e8957  
    11#include "divecomputer.h"
    22#include "dive.h"
     3#include "subsurface-qt/SettingsObjectWrapper.h"
    34
    45#include <QSettings>
    56
    6 const char *default_dive_computer_vendor;
    7 const char *default_dive_computer_product;
    8 const char *default_dive_computer_device;
    9 int default_dive_computer_download_mode;
    107DiveComputerList dcList;
    118
     
    145142extern "C" int is_default_dive_computer(const char *vendor, const char *product)
    146143{
    147         return default_dive_computer_vendor && !strcmp(vendor, default_dive_computer_vendor) &&
    148                default_dive_computer_product && !strcmp(product, default_dive_computer_product);
     144        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     145        return dc->dc_vendor() == vendor && dc->dc_product() == product;
    149146}
    150147
    151148extern "C" int is_default_dive_computer_device(const char *name)
    152149{
    153         return default_dive_computer_device && !strcmp(name, default_dive_computer_device);
    154 }
    155 
    156 void set_default_dive_computer(const char *vendor, const char *product)
    157 {
    158         QSettings s;
    159 
    160         if (!vendor || !*vendor)
    161                 return;
    162         if (!product || !*product)
    163                 return;
    164         if (is_default_dive_computer(vendor, product))
    165                 return;
    166 
    167         free((void *)default_dive_computer_vendor);
    168         free((void *)default_dive_computer_product);
    169         default_dive_computer_vendor = strdup(vendor);
    170         default_dive_computer_product = strdup(product);
    171         s.beginGroup("DiveComputer");
    172         s.setValue("dive_computer_vendor", vendor);
    173         s.setValue("dive_computer_product", product);
    174         s.endGroup();
    175 }
    176 
    177 void set_default_dive_computer_device(const char *name)
    178 {
    179         QSettings s;
    180 
    181         if (!name || !*name)
    182                 return;
    183         if (is_default_dive_computer_device(name))
    184                 return;
    185 
    186         free((void *)default_dive_computer_device);
    187         default_dive_computer_device = strdup(name);
    188         s.beginGroup("DiveComputer");
    189         s.setValue("dive_computer_device", name);
    190         s.endGroup();
    191 }
    192 
    193 void set_default_dive_computer_download_mode(int download_mode)
    194 {
    195         QSettings s;
    196 
    197         default_dive_computer_download_mode = download_mode;
    198         s.beginGroup("DiveComputer");
    199         s.setValue("dive_computer_download_mode", download_mode);
    200         s.endGroup();
     150        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     151        return dc->dc_device() == name;
    201152}
    202153
  • core/helpers.h

    rff8392d rdb8e8957  
    2323QString get_pressure_string(pressure_t pressure, bool showunit = false);
    2424QString get_pressure_unit();
    25 void set_default_dive_computer(const char *vendor, const char *product);
    26 void set_default_dive_computer_device(const char *name);
    27 void set_default_dive_computer_download_mode(int downloadMode);
    2825QString getSubsurfaceDataPath(QString folderToFind);
    2926QString getPrintingTemplatePathUser();
  • core/pref.h

    r5c8b87b rdb8e8957  
    4949        char *next_check;
    5050} update_manager_prefs_t;
     51
     52typedef struct {
     53        char *vendor;
     54        char *product;
     55        char *device;
     56        int download_mode;
     57} dive_computer_prefs_t;
    5158
    5259struct preferences {
     
    142149        locale_prefs_t locale; //: TODO: move the rest of locale based info here.
    143150        update_manager_prefs_t update_manager;
     151        dive_computer_prefs_t dive_computer;
    144152};
    145153enum unit_system_values {
  • core/subsurface-qt/SettingsObjectWrapper.cpp

    r5c8b87b rdb8e8957  
    77#include "../dive.h" // TODO: remove copy_string from dive.h
    88
     9DiveComputerSettings::DiveComputerSettings(QObject *parent):
     10        QObject(parent), group(QStringLiteral("DiveComputer"))
     11{
     12}
     13
     14QString DiveComputerSettings::dc_vendor() const
     15{
     16        return prefs.dive_computer.vendor;
     17}
     18
     19QString DiveComputerSettings::dc_product() const
     20{
     21        return prefs.dive_computer.product;
     22}
     23
     24QString DiveComputerSettings::dc_device() const
     25{
     26        return prefs.dive_computer.device;
     27}
     28
     29int DiveComputerSettings::downloadMode() const
     30{
     31        return prefs.dive_computer.download_mode;
     32}
     33
     34void DiveComputerSettings::setVendor(const QString& vendor)
     35{
     36        QSettings s;
     37        s.beginGroup(group);
     38        s.setValue("dive_computer_vendor", vendor);
     39        free(prefs.dive_computer.vendor);
     40        prefs.dive_computer.vendor = copy_string(qPrintable(vendor));
     41}
     42
     43void DiveComputerSettings::setProduct(const QString& product)
     44{
     45        QSettings s;
     46        s.beginGroup(group);
     47        s.setValue("dive_computer_product", product);
     48        free(prefs.dive_computer.product);
     49        prefs.dive_computer.product = copy_string(qPrintable(product));
     50}
     51
     52void DiveComputerSettings::setDevice(const QString& device)
     53{
     54        QSettings s;
     55        s.beginGroup(group);
     56        s.setValue("dive_computer_device", device);
     57        free(prefs.dive_computer.device);
     58        prefs.dive_computer.device = copy_string(qPrintable(device));
     59}
     60
     61void DiveComputerSettings::setDownloadMode(int mode)
     62{
     63        QSettings s;
     64        s.beginGroup(group);
     65        s.setValue("dive_computer_download_mode", mode);
     66        prefs.dive_computer.download_mode = mode;
     67}
    968
    1069UpdateManagerSettings::UpdateManagerSettings(QObject *parent) : QObject(parent), group("UpdateManager")
     
    16801739        animation_settings(new AnimationsSettingsObjectWrapper(this)),
    16811740        location_settings(new LocationServiceSettingsObjectWrapper(this)),
    1682         update_manager_settings(new UpdateManagerSettings(this))
     1741        update_manager_settings(new UpdateManagerSettings(this)),
     1742        dive_computer_settings(new DiveComputerSettings(this))
    16831743{
    16841744}
  • core/subsurface-qt/SettingsObjectWrapper.h

    r5c8b87b rdb8e8957  
    1212 * I need tons of properties, one for each option. */
    1313
     14class DiveComputerSettings : public QObject {
     15        Q_OBJECT
     16        Q_PROPERTY(QString vendor READ dc_vendor WRITE setVendor NOTIFY vendorChanged)
     17        Q_PROPERTY(QString product READ dc_product WRITE setProduct NOTIFY productChanged)
     18        Q_PROPERTY(QString device READ dc_device WRITE setDevice NOTIFY deviceChanged)
     19        Q_PROPERTY(int download_mode READ downloadMode WRITE setDownloadMode NOTIFY downloadModeChanged)
     20public:
     21        DiveComputerSettings(QObject *parent);
     22        QString dc_vendor() const;
     23        QString dc_product() const;
     24        QString dc_device() const;
     25        int downloadMode() const;
     26
     27public slots:
     28        void setVendor(const QString& vendor);
     29        void setProduct(const QString& product);
     30        void setDevice(const QString& device);
     31        void setDownloadMode(int mode);
     32
     33signals:
     34        void vendorChanged(const QString& vendor);
     35        void productChanged(const QString& product);
     36        void deviceChanged(const QString& device);
     37        void downloadModeChanged(int mode);
     38private:
     39        QString group;
     40
     41};
    1442class UpdateManagerSettings : public QObject {
    1543        Q_OBJECT
     
    648676
    649677        Q_PROPERTY(UpdateManagerSettings* update MEMBER update_manager_settings CONSTANT)
    650 
     678        Q_PROPERTY(DiveComputerSettings* dive_computer MEMBER dive_computer_settings CONSTANT)
    651679public:
    652680        static SettingsObjectWrapper *instance();
     
    666694        LocationServiceSettingsObjectWrapper *location_settings;
    667695        UpdateManagerSettings *update_manager_settings;
     696        DiveComputerSettings *dive_computer_settings;
     697
    668698private:
    669699        SettingsObjectWrapper(QObject *parent = NULL);
  • desktop-widgets/configuredivecomputerdialog.cpp

    r7be962b rdb8e8957  
    44#include "desktop-widgets/mainwindow.h"
    55#include "core/display.h"
     6#include "core/subsurface-qt/SettingsObjectWrapper.h"
    67
    78#include <QFileDialog>
     
    151152        memset(&device_data, 0, sizeof(device_data));
    152153        fill_computer_list();
    153         if (default_dive_computer_device)
    154                 ui.device->setEditText(default_dive_computer_device);
     154        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     155        if (!dc->dc_device().isEmpty())
     156                ui.device->setEditText(dc->dc_device());
    155157
    156158        ui.DiveComputerList->setCurrentRow(0);
     
    776778        device_data.deviceid = device_data.diveid = 0;
    777779
    778         set_default_dive_computer_device(device_data.devname);
     780        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     781        dc->setDevice(device_data.devname);
    779782}
    780783
  • desktop-widgets/downloadfromdivecomputer.cpp

    r7be962b rdb8e8957  
    55#include "core/display.h"
    66#include "core/uemis.h"
     7#include "core/subsurface-qt/SettingsObjectWrapper.h"
    78#include "qt-models/models.h"
    89
     
    7980        vendorModel = new QStringListModel(vendorList);
    8081        ui.vendor->setModel(vendorModel);
    81         if (default_dive_computer_vendor) {
    82                 ui.vendor->setCurrentIndex(ui.vendor->findText(default_dive_computer_vendor));
    83                 productModel = new QStringListModel(productList[default_dive_computer_vendor]);
     82
     83        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     84        if (!dc->dc_vendor().isEmpty()) {
     85                ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor()));
     86                productModel = new QStringListModel(productList[dc->dc_vendor()]);
    8487                ui.product->setModel(productModel);
    85                 if (default_dive_computer_product)
    86                         ui.product->setCurrentIndex(ui.product->findText(default_dive_computer_product));
    87         }
    88         if (default_dive_computer_device)
    89                 ui.device->setEditText(default_dive_computer_device);
     88                if (!dc->dc_product().isEmpty())
     89                        ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
     90        }
     91        if (!dc->dc_device().isEmpty())
     92                ui.device->setEditText(dc->dc_device());
    9093
    9194        timer->setInterval(200);
     
    103106#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
    104107        ui.bluetoothMode->setText(tr("Choose Bluetooth download mode"));
    105         ui.bluetoothMode->setChecked(default_dive_computer_download_mode == DC_TRANSPORT_BLUETOOTH);
     108        ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH);
    106109        btDeviceSelectionDialog = 0;
    107110        ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
     
    338341        data.trip = NULL;
    339342        data.deviceid = data.diveid = 0;
    340         set_default_dive_computer(data.vendor, data.product);
    341         set_default_dive_computer_device(data.devname);
     343
     344        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
     345        dc->setVendor(data.vendor);
     346        dc->setProduct(data.product);
     347        dc->setDevice(data.devname);
    342348#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_SERIAL)
    343         set_default_dive_computer_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
     349        dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
    344350#endif
     351
    345352        thread = new DownloadThread(this, &data);
    346 
    347353        connect(thread, SIGNAL(finished()),
    348354                this, SLOT(onDownloadThreadFinished()), Qt::QueuedConnection);
    349355
     356        //TODO: Don't call mainwindow.
    350357        MainWindow *w = MainWindow::instance();
    351358        connect(thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
  • desktop-widgets/mainwindow.cpp

    r430f5b7 rdb8e8957  
    13061306}
    13071307
    1308 const char *getSetting(const QSettings &s,const QString& name)
    1309 {
    1310         QVariant v;
    1311         v = s.value(name);
    1312         if (v.isValid()) {
    1313                 return strdup(v.toString().toUtf8().data());
    1314         }
    1315         return NULL;
    1316 }
    1317 
    13181308void MainWindow::readSettings()
    13191309{
    13201310        static bool firstRun = true;
    1321 
    1322         QSettings s; //WARNING: Why those prefs are not on the prefs struct?
    1323         s.beginGroup("DiveComputer");
    1324         default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
    1325         default_dive_computer_product = getSetting(s, "dive_computer_product");
    1326         default_dive_computer_device = getSetting(s, "dive_computer_device");
    1327         default_dive_computer_download_mode = s.value("dive_computer_download_mode").toInt();
    1328         s.endGroup();
    13291311        init_proxy();
    13301312
     
    13331315
    13341316#if !defined(SUBSURFACE_MOBILE)
     1317        QSettings s; //TODO: this 's' exists only for the loadRecentFiles, remove it.
     1318
    13351319        loadRecentFiles(&s);
    13361320        if (firstRun) {
  • subsurface-desktop-helper.cpp

    r7be962b rdb8e8957  
    5151        delete qApp;
    5252        free((void *)existing_filename);
    53         free((void *)default_dive_computer_vendor);
    54         free((void *)default_dive_computer_product);
    55         free((void *)default_dive_computer_device);
    5653}
    5754
Note: See TracChangeset for help on using the changeset viewer.