diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2018-09-21 12:17:24 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-23 11:49:30 -0700 |
commit | 99261775ceede62e19422f6c909439a619d65ee0 (patch) | |
tree | 21c4e746c5cc976fdb1b10b8cf13f4c0c4442701 /desktop-widgets | |
parent | e2ee8c57dfd85d26c3697f5c5f0e7f45e462be1e (diff) | |
download | subsurface-99261775ceede62e19422f6c909439a619d65ee0.tar.gz |
Desktop/remember DCs: remember dive computers that were used
The algorithm tries to keep the order of the buttons the same. So if a dive
computer was used that's already remembered, don't reorder the buttons. But if
a new dive computer is used, add it as the first one and move the others back,
potentially dropping the oldest one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 44 | ||||
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.h | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 2929a25da..41acae7c5 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -331,6 +331,8 @@ 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 @@ -353,6 +355,48 @@ 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(); diff --git a/desktop-widgets/downloadfromdivecomputer.h b/desktop-widgets/downloadfromdivecomputer.h index b357f186f..f9cc83e64 100644 --- a/desktop-widgets/downloadfromdivecomputer.h +++ b/desktop-widgets/downloadfromdivecomputer.h @@ -59,6 +59,7 @@ private: void markChildrenAsDisabled(); void markChildrenAsEnabled(); void updateDeviceEnabled(); + void updateRememberedDCs(); QStringListModel vendorModel; QStringListModel productModel; |