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>
This commit is contained in:
Dirk Hohndel 2018-09-21 12:17:24 -07:00
parent e2ee8c57df
commit 99261775ce
2 changed files with 45 additions and 0 deletions

View file

@ -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();

View file

@ -59,6 +59,7 @@ private:
void markChildrenAsDisabled();
void markChildrenAsEnabled();
void updateDeviceEnabled();
void updateRememberedDCs();
QStringListModel vendorModel;
QStringListModel productModel;