core: activate qPrefDiveComputer

remove DiveComputer from SettingsObjectWrapper and reference qPrefDiveComputer

update files using SettingsObjectWrapper/DiveComputer to use qPrefDiveComputer

this activated qPrefDiveComputer and removed the similar class from
SettingsObjectWrapper.

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-07-22 16:19:22 +02:00 committed by Dirk Hohndel
parent 98820cf970
commit 3d6848b22c
9 changed files with 56 additions and 180 deletions

View file

@ -125,13 +125,13 @@ 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)
{
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
return dc->dc_vendor() == vendor && dc->dc_product() == product;
return dc->vendor() == vendor && dc->product() == product;
}
extern "C" int is_default_dive_computer_device(const char *name)
{
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
return dc->dc_device() == name;
return dc->device() == name;
}
extern "C" void set_dc_nickname(struct dive *dive)

View file

@ -56,10 +56,10 @@ void DownloadThread::run()
qDebug() << "Finishing download thread:" << downloadTable.nr << "dives downloaded";
}
auto dcs = SettingsObjectWrapper::instance()->dive_computer_settings;
dcs->setVendor(internalData->vendor);
dcs->setProduct(internalData->product);
dcs->setDevice(internalData->devname);
dcs->setDeviceName(m_data->devBluetoothName());
dcs->set_vendor(internalData->vendor);
dcs->set_product(internalData->product);
dcs->set_device(internalData->devname);
dcs->set_device_name(m_data->devBluetoothName());
}
static void fill_supported_mobile_list()
@ -247,12 +247,12 @@ QStringList DCDeviceData::getProductListFromVendor(const QString &vendor)
int DCDeviceData::getMatchingAddress(const QString &vendor, const QString &product)
{
auto dcs = SettingsObjectWrapper::instance()->dive_computer_settings;
if (dcs->dc_vendor() == vendor &&
dcs->dc_product() == product) {
if (dcs->vendor() == vendor &&
dcs->product() == product) {
// we are trying to show the last dive computer selected
for (int i = 0; i < connectionListModel.rowCount(); i++) {
QString address = connectionListModel.address(i);
if (address.contains(dcs->dc_device()))
if (address.contains(dcs->device()))
return i;
}
}
@ -410,10 +410,10 @@ device_data_t* DCDeviceData::internalData()
int DCDeviceData::getDetectedVendorIndex()
{
auto dcs = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dcs->dc_vendor().isEmpty()) {
if (!dcs->vendor().isEmpty()) {
// use the last one
for (int i = 0; i < vendorList.length(); i++) {
if (vendorList[i] == dcs->dc_vendor())
if (vendorList[i] == dcs->vendor())
return i;
}
}
@ -431,11 +431,11 @@ int DCDeviceData::getDetectedVendorIndex()
int DCDeviceData::getDetectedProductIndex(const QString &currentVendorText)
{
auto dcs = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dcs->dc_vendor().isEmpty()) {
if (dcs->dc_vendor() == currentVendorText) {
if (!dcs->vendor().isEmpty()) {
if (dcs->vendor() == currentVendorText) {
// we are trying to show the last dive computer selected
for (int i = 0; i < productList[currentVendorText].length(); i++) {
if (productList[currentVendorText][i] == dcs->dc_product())
if (productList[currentVendorText][i] == dcs->product())
return i;
}
}

View file

@ -18,6 +18,7 @@ void qPref::loadSync(bool doSync)
qPrefAnimations::instance()->loadSync(doSync);
qPrefCloudStorage::instance()->loadSync(doSync);
qPrefDisplay::instance()->loadSync(doSync);
qPrefDiveComputer::instance()->loadSync(doSync);
}
const QString qPref::canonical_version() const

View file

@ -9,95 +9,6 @@
#include "core/qthelper.h"
#include "core/prefs-macros.h"
DiveComputerSettings::DiveComputerSettings(QObject *parent):
QObject(parent)
{
}
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;
}
QString DiveComputerSettings::dc_device_name() const
{
return prefs.dive_computer.device_name;
}
int DiveComputerSettings::downloadMode() const
{
return prefs.dive_computer.download_mode;
}
void DiveComputerSettings::setVendor(const QString& vendor)
{
if (vendor == prefs.dive_computer.vendor)
return;
QSettings s;
s.beginGroup(group);
s.setValue("dive_computer_vendor", vendor);
free((void *)prefs.dive_computer.vendor);
prefs.dive_computer.vendor = copy_qstring(vendor);
}
void DiveComputerSettings::setProduct(const QString& product)
{
if (product == prefs.dive_computer.product)
return;
QSettings s;
s.beginGroup(group);
s.setValue("dive_computer_product", product);
free((void *)prefs.dive_computer.product);
prefs.dive_computer.product = copy_qstring(product);
}
void DiveComputerSettings::setDevice(const QString& device)
{
if (device == prefs.dive_computer.device)
return;
QSettings s;
s.beginGroup(group);
s.setValue("dive_computer_device", device);
free((void *)prefs.dive_computer.device);
prefs.dive_computer.device = copy_qstring(device);
}
void DiveComputerSettings::setDeviceName(const QString& device_name)
{
if (device_name == prefs.dive_computer.device_name)
return;
QSettings s;
s.beginGroup(group);
s.setValue("dive_computer_device_name", device_name);
free((void *)prefs.dive_computer.device_name);
prefs.dive_computer.device_name = copy_qstring(device_name);
}
void DiveComputerSettings::setDownloadMode(int mode)
{
if (mode == prefs.dive_computer.download_mode)
return;
QSettings s;
s.beginGroup(group);
s.setValue("dive_computer_download_mode", mode);
prefs.dive_computer.download_mode = mode;
}
UpdateManagerSettings::UpdateManagerSettings(QObject *parent) : QObject(parent)
{
@ -1930,7 +1841,7 @@ QObject(parent),
animation_settings(new qPrefAnimations(this)),
location_settings(new LocationServiceSettingsObjectWrapper(this)),
update_manager_settings(new UpdateManagerSettings(this)),
dive_computer_settings(new DiveComputerSettings(this))
dive_computer_settings(new qPrefDiveComputer(this))
{
}
@ -2077,13 +1988,7 @@ void SettingsObjectWrapper::load()
prefs.planner_deco_mode = deco_mode(s.value("deco_mode", default_prefs.planner_deco_mode).toInt());
s.endGroup();
s.beginGroup("DiveComputer");
GET_TXT("dive_computer_vendor",dive_computer.vendor);
GET_TXT("dive_computer_product", dive_computer.product);
GET_TXT("dive_computer_device", dive_computer.device);
GET_TXT("dive_computer_device_name", dive_computer.device_name);
GET_INT("dive_computer_download_mode", dive_computer.download_mode);
s.endGroup();
qPrefDiveComputer::instance()->load();
s.beginGroup("UpdateManager");
prefs.update_manager.dont_check_exists = s.contains("DontCheckForUpdates");

View file

@ -13,39 +13,6 @@
* 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(QString device_name READ dc_device_name WRITE setDeviceName NOTIFY deviceNameChanged)
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;
QString dc_device_name() const;
int downloadMode() const;
public slots:
void setVendor(const QString& vendor);
void setProduct(const QString& product);
void setDevice(const QString& device);
void setDeviceName(const QString& device_name);
void setDownloadMode(int mode);
signals:
void vendorChanged(const QString& vendor);
void productChanged(const QString& product);
void deviceChanged(const QString& device);
void deviceNameChanged(const QString& device_name);
void downloadModeChanged(int mode);
private:
const QString group = QStringLiteral("DiveComputer");
};
class UpdateManagerSettings : public QObject {
Q_OBJECT
Q_PROPERTY(bool dont_check_for_updates READ dontCheckForUpdates WRITE setDontCheckForUpdates NOTIFY dontCheckForUpdatesChanged)
@ -620,7 +587,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)
Q_PROPERTY(qPrefDiveComputer* dive_computer MEMBER dive_computer_settings CONSTANT)
public:
static SettingsObjectWrapper *instance();
@ -638,7 +605,7 @@ public:
qPrefAnimations *animation_settings;
LocationServiceSettingsObjectWrapper *location_settings;
UpdateManagerSettings *update_manager_settings;
DiveComputerSettings *dive_computer_settings;
qPrefDiveComputer *dive_computer_settings;
void sync();
void load();

View file

@ -133,8 +133,8 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia
memset(&device_data, 0, sizeof(device_data));
fill_computer_list();
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dc->dc_device().isEmpty())
ui.device->setEditText(dc->dc_device());
if (!dc->device().isEmpty())
ui.device->setEditText(dc->device());
ui.DiveComputerList->setCurrentRow(0);
on_DiveComputerList_currentRowChanged(0);
@ -912,10 +912,10 @@ void ConfigureDiveComputerDialog::getDeviceData()
device_data.deviceid = device_data.diveid = 0;
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
dc->setDevice(device_data.devname);
dc->set_device(device_data.devname);
#ifdef BT_SUPPORT
if (ui.bluetoothMode && btDeviceSelectionDialog)
dc->setDeviceName(btDeviceSelectionDialog->getSelectedDeviceName());
dc->set_device_name(btDeviceSelectionDialog->getSelectedDeviceName());
#endif
}

View file

@ -72,11 +72,11 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
connect(&thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dc->dc_vendor().isEmpty()) {
ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor()));
productModel.setStringList(productList[dc->dc_vendor()]);
if (!dc->dc_product().isEmpty())
ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
if (!dc->vendor().isEmpty()) {
ui.vendor->setCurrentIndex(ui.vendor->findText(dc->vendor()));
productModel.setStringList(productList[dc->vendor()]);
if (!dc->product().isEmpty())
ui.product->setCurrentIndex(ui.product->findText(dc->product()));
}
updateState(INITIAL);
@ -84,16 +84,16 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
ui.downloadCancelRetryButton->setEnabled(true);
ui.downloadCancelRetryButton->setText(tr("Download"));
QString deviceText = dc->dc_device();
QString deviceText = dc->device();
#if defined(BT_SUPPORT)
ui.bluetoothMode->setText(tr("Choose Bluetooth download mode"));
ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH);
ui.bluetoothMode->setChecked(dc->download_mode() == DC_TRANSPORT_BLUETOOTH);
btDeviceSelectionDialog = 0;
connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice()));
ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
if (ui.bluetoothMode->isChecked())
deviceText = BtDeviceSelectionDialog::formatDeviceText(dc->dc_device(), dc->dc_device_name());
deviceText = BtDeviceSelectionDialog::formatDeviceText(dc->device(), dc->device_name());
#else
ui.bluetoothMode->hide();
ui.chooseBluetoothDevice->hide();
@ -289,8 +289,8 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
data->setDevBluetoothName(btDeviceSelectionDialog->getSelectedDeviceName());
} else {
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
data->setDevName(dc->dc_device());
data->setDevBluetoothName(dc->dc_device_name());
data->setDevName(dc->device());
data->setDevBluetoothName(dc->device_name());
}
} else
// this breaks an "else if" across lines... not happy...
@ -314,12 +314,12 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
data->setSaveDump(ui.dumpToFile->isChecked());
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
dc->setVendor(data->vendor());
dc->setProduct(data->product());
dc->setDevice(data->devName());
dc->set_vendor(data->vendor());
dc->set_product(data->product());
dc->set_device(data->devName());
#if defined(BT_SUPPORT)
dc->setDownloadMode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
dc->set_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
#endif
// before we start, remember where the dive_table ended

View file

@ -162,6 +162,9 @@ void register_qml_types()
rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
rc = qmlRegisterType<qPrefDiveComputer>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDiveComputerPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register DiveComputerPrefs (class qPrefDiveComputer), QML will not work!!";
#ifndef SUBSURFACE_TEST_DATA
#ifdef SUBSURFACE_MOBILE

View file

@ -468,25 +468,25 @@ void TestPreferences::testPreferences()
TEST(update->nextCheck(), date);
auto dc = pref->dive_computer_settings;
dc->setDevice("TomazComputer");
TEST(dc->dc_device(), QStringLiteral("TomazComputer"));
dc->setDevice("Deepwater");
TEST(dc->dc_device(), QStringLiteral("Deepwater"));
dc->set_device("TomazComputer");
TEST(dc->device(), QStringLiteral("TomazComputer"));
dc->set_device("Deepwater");
TEST(dc->device(), QStringLiteral("Deepwater"));
dc->setDownloadMode(0);
TEST(dc->downloadMode(), 0);
dc->setDownloadMode(1);
TEST(dc->downloadMode(), 1);
dc->set_download_mode(0);
TEST(dc->download_mode(), 0);
dc->set_download_mode(1);
TEST(dc->download_mode(), 1);
dc->setProduct("Thingy1");
TEST(dc->dc_product(), QStringLiteral("Thingy1"));
dc->setProduct("Thingy2");
TEST(dc->dc_product(), QStringLiteral("Thingy2"));
dc->set_product("Thingy1");
TEST(dc->product(), QStringLiteral("Thingy1"));
dc->set_product("Thingy2");
TEST(dc->product(), QStringLiteral("Thingy2"));
dc->setVendor("Sharewater");
TEST(dc->dc_vendor(), QStringLiteral("Sharewater"));
dc->setVendor("OSTS");
TEST(dc->dc_vendor(), QStringLiteral("OSTS"));
dc->set_vendor("Sharewater");
TEST(dc->vendor(), QStringLiteral("Sharewater"));
dc->set_vendor("OSTS");
TEST(dc->vendor(), QStringLiteral("OSTS"));
}
QTEST_MAIN(TestPreferences)