mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Desktop/remember DCs: move non-UI-specific code into the core layer
This way we can use the same functionality from the mobile UI as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4eb8ed1b29
commit
413b05ab89
3 changed files with 60 additions and 57 deletions
|
@ -24,6 +24,42 @@ static QString str_error(const char *fmt, ...)
|
|||
return str;
|
||||
}
|
||||
|
||||
|
||||
static void updateRememberedDCs()
|
||||
{
|
||||
QString current = qPrefDiveComputer::vendor() + " - " + qPrefDiveComputer::product();
|
||||
QStringList dcs = {
|
||||
qPrefDiveComputer::vendor1() + " - " + qPrefDiveComputer::product1(),
|
||||
qPrefDiveComputer::vendor2() + " - " + qPrefDiveComputer::product2(),
|
||||
qPrefDiveComputer::vendor3() + " - " + qPrefDiveComputer::product3(),
|
||||
qPrefDiveComputer::vendor4() + " - " + qPrefDiveComputer::product4()
|
||||
};
|
||||
if (dcs.contains(current))
|
||||
// already in the list
|
||||
return;
|
||||
// add the current one as the first remembered one and drop the 4th one
|
||||
// don't get confused by 0-based and 1-based indices!
|
||||
if (dcs[2] != " - ") {
|
||||
qPrefDiveComputer::set_vendor4(qPrefDiveComputer::vendor3());
|
||||
qPrefDiveComputer::set_product4(qPrefDiveComputer::product3());
|
||||
qPrefDiveComputer::set_device4(qPrefDiveComputer::device3());
|
||||
}
|
||||
if (dcs[1] != " - ") {
|
||||
qPrefDiveComputer::set_vendor3(qPrefDiveComputer::vendor2());
|
||||
qPrefDiveComputer::set_product3(qPrefDiveComputer::product2());
|
||||
qPrefDiveComputer::set_device3(qPrefDiveComputer::device2());
|
||||
}
|
||||
if (dcs[0] != " - ") {
|
||||
qPrefDiveComputer::set_vendor2(qPrefDiveComputer::vendor1());
|
||||
qPrefDiveComputer::set_product2(qPrefDiveComputer::product1());
|
||||
qPrefDiveComputer::set_device2(qPrefDiveComputer::device1());
|
||||
}
|
||||
qPrefDiveComputer::set_vendor1(qPrefDiveComputer::vendor());
|
||||
qPrefDiveComputer::set_product1(qPrefDiveComputer::product());
|
||||
qPrefDiveComputer::set_device1(qPrefDiveComputer::device());
|
||||
}
|
||||
|
||||
|
||||
DownloadThread::DownloadThread()
|
||||
{
|
||||
m_data = DCDeviceData::instance();
|
||||
|
@ -61,6 +97,8 @@ void DownloadThread::run()
|
|||
qPrefDiveComputer::set_product(internalData->product);
|
||||
qPrefDiveComputer::set_device(internalData->devname);
|
||||
qPrefDiveComputer::set_device_name(m_data->devBluetoothName());
|
||||
|
||||
updateRememberedDCs();
|
||||
}
|
||||
|
||||
static void fill_supported_mobile_list()
|
||||
|
|
|
@ -79,18 +79,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
|
|||
}
|
||||
|
||||
// now lets set the four shortcuts for previously used dive computers
|
||||
#define SETUPDC(num) \
|
||||
if (!qPrefDiveComputer::vendor##num().isEmpty()) { \
|
||||
ui.DC##num->setVisible(true); \
|
||||
ui.DC##num->setText(qPrefDiveComputer::vendor##num() + " - " + qPrefDiveComputer::product##num()); \
|
||||
connect(ui.DC##num, &QPushButton::clicked, this, &DownloadFromDCWidget::DC##num##Clicked); \
|
||||
} else { \
|
||||
ui.DC##num->setVisible(false); \
|
||||
}
|
||||
SETUPDC(1)
|
||||
SETUPDC(2)
|
||||
SETUPDC(3)
|
||||
SETUPDC(4)
|
||||
showRememberedDCs();
|
||||
|
||||
updateState(INITIAL);
|
||||
ui.ok->setEnabled(false);
|
||||
|
@ -115,6 +104,23 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
|
|||
ui.device->setEditText(deviceText);
|
||||
}
|
||||
|
||||
#define SETUPDC(num) \
|
||||
if (!qPrefDiveComputer::vendor##num().isEmpty()) { \
|
||||
ui.DC##num->setVisible(true); \
|
||||
ui.DC##num->setText(qPrefDiveComputer::vendor##num() + " - " + qPrefDiveComputer::product##num()); \
|
||||
connect(ui.DC##num, &QPushButton::clicked, this, &DownloadFromDCWidget::DC##num##Clicked, Qt::UniqueConnection); \
|
||||
} else { \
|
||||
ui.DC##num->setVisible(false); \
|
||||
}
|
||||
|
||||
void DownloadFromDCWidget::showRememberedDCs()
|
||||
{
|
||||
SETUPDC(1)
|
||||
SETUPDC(2)
|
||||
SETUPDC(3)
|
||||
SETUPDC(4)
|
||||
}
|
||||
|
||||
// DC button slots
|
||||
#define DCBUTTON(num) \
|
||||
void DownloadFromDCWidget::DC##num##Clicked() \
|
||||
|
@ -354,8 +360,6 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
|||
qPrefDiveComputer::set_product(data->product());
|
||||
qPrefDiveComputer::set_device(data->devName());
|
||||
|
||||
updateRememberedDCs();
|
||||
|
||||
#if defined(BT_SUPPORT)
|
||||
qPrefDiveComputer::set_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
|
||||
#endif
|
||||
|
@ -378,48 +382,6 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
|||
}
|
||||
}
|
||||
|
||||
void DownloadFromDCWidget::updateRememberedDCs()
|
||||
{
|
||||
QString current = qPrefDiveComputer::vendor() + " - " + qPrefDiveComputer::product();
|
||||
QStringList dcs = {
|
||||
qPrefDiveComputer::vendor1() + " - " + qPrefDiveComputer::product1(),
|
||||
qPrefDiveComputer::vendor2() + " - " + qPrefDiveComputer::product2(),
|
||||
qPrefDiveComputer::vendor3() + " - " + qPrefDiveComputer::product3(),
|
||||
qPrefDiveComputer::vendor4() + " - " + qPrefDiveComputer::product4()
|
||||
};
|
||||
if (dcs.contains(current))
|
||||
// already in the list
|
||||
return;
|
||||
// add the current one as the first remembered one and drop the 4th one
|
||||
// don't get confused by 0-based and 1-based indices!
|
||||
if (dcs[2] != " - ") {
|
||||
qPrefDiveComputer::set_vendor4(qPrefDiveComputer::vendor3());
|
||||
qPrefDiveComputer::set_product4(qPrefDiveComputer::product3());
|
||||
qPrefDiveComputer::set_device4(qPrefDiveComputer::device3());
|
||||
ui.DC4->setText(dcs[2]);
|
||||
ui.DC4->setVisible(true);
|
||||
}
|
||||
if (dcs[1] != " - ") {
|
||||
qPrefDiveComputer::set_vendor3(qPrefDiveComputer::vendor2());
|
||||
qPrefDiveComputer::set_product3(qPrefDiveComputer::product2());
|
||||
qPrefDiveComputer::set_device3(qPrefDiveComputer::device2());
|
||||
ui.DC3->setText(dcs[1]);
|
||||
ui.DC3->setVisible(true);
|
||||
}
|
||||
if (dcs[0] != " - ") {
|
||||
qPrefDiveComputer::set_vendor2(qPrefDiveComputer::vendor1());
|
||||
qPrefDiveComputer::set_product2(qPrefDiveComputer::product1());
|
||||
qPrefDiveComputer::set_device2(qPrefDiveComputer::device1());
|
||||
ui.DC2->setText(dcs[0]);
|
||||
ui.DC2->setVisible(true);
|
||||
}
|
||||
qPrefDiveComputer::set_vendor1(qPrefDiveComputer::vendor());
|
||||
qPrefDiveComputer::set_product1(qPrefDiveComputer::product());
|
||||
qPrefDiveComputer::set_device1(qPrefDiveComputer::device());
|
||||
ui.DC1->setText(current);
|
||||
ui.DC1->setVisible(true);
|
||||
}
|
||||
|
||||
bool DownloadFromDCWidget::preferDownloaded()
|
||||
{
|
||||
return ui.preferDownloaded->isChecked();
|
||||
|
@ -483,6 +445,9 @@ void DownloadFromDCWidget::reject()
|
|||
|
||||
void DownloadFromDCWidget::onDownloadThreadFinished()
|
||||
{
|
||||
// let's update the remembered DCs
|
||||
showRememberedDCs();
|
||||
|
||||
if (currentState == DOWNLOADING) {
|
||||
if (thread.error.isEmpty())
|
||||
updateState(DONE);
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
void markChildrenAsDisabled();
|
||||
void markChildrenAsEnabled();
|
||||
void updateDeviceEnabled();
|
||||
void updateRememberedDCs();
|
||||
void showRememberedDCs();
|
||||
|
||||
QStringListModel vendorModel;
|
||||
QStringListModel productModel;
|
||||
|
|
Loading…
Add table
Reference in a new issue