summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/downloadfromdcthread.cpp1
-rw-r--r--desktop-widgets/downloadfromdivecomputer.cpp27
-rw-r--r--qt-models/diveimportedmodel.cpp23
-rw-r--r--qt-models/diveimportedmodel.h3
4 files changed, 21 insertions, 33 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index fd423438f..bf2e9ca7e 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -424,7 +424,6 @@ bool DCDeviceData::saveLog() const
return data.libdc_log;
}
-
device_data_t *DCDeviceData::internalData()
{
return &data;
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index a14a8a665..cf3aad492 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -525,26 +525,13 @@ void DownloadFromDCWidget::on_ok_clicked()
if (currentState != DONE && currentState != ERRORED)
return;
- // delete non-selected dives
- diveImportedModel->deleteDeselected();
-
- // TODO: use structured bindings once we go C++17
- std::pair<struct dive_table, struct dive_site_table> tables = diveImportedModel->consumeTables();
- if (tables.first.nr > 0) {
- auto data = diveImportedModel->thread.data();
- int flags = IMPORT_IS_DOWNLOADED;
- if (preferDownloaded())
- flags |= IMPORT_PREFER_IMPORTED;
- if (ui.createNewTrip->isChecked())
- flags |= IMPORT_ADD_TO_NEW_TRIP;
- Command::importDives(&tables.first, nullptr, &tables.second, flags, data->devName());
- } else {
- clear_dive_site_table(&tables.second);
- }
- // The dives and dive sites have been consumed, but the arrays of the tables
- // still exist. Free them.
- free(tables.first.dives);
- free(tables.second.dive_sites);
+ int flags = IMPORT_IS_DOWNLOADED;
+ if (preferDownloaded())
+ flags |= IMPORT_PREFER_IMPORTED;
+ if (ui.createNewTrip->isChecked())
+ flags |= IMPORT_ADD_TO_NEW_TRIP;
+
+ diveImportedModel->recordDives(flags);
if (ostcFirmwareCheck && currentState == DONE)
ostcFirmwareCheck->checkLatest(this, diveImportedModel->thread.data()->internalData());
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index b6b5f2402..393e220d6 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -1,6 +1,7 @@
#include "diveimportedmodel.h"
#include "core/qthelper.h"
#include "core/divelist.h"
+#include "commands/command.h"
DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
diveTable(empty_dive_table),
@@ -184,21 +185,21 @@ void DiveImportedModel::deleteDeselected()
}
// Note: this function is only used from mobile - perhaps move it there or unify.
-void DiveImportedModel::recordDives()
+void DiveImportedModel::recordDives(int flags)
{
+ // delete non-selected dives
deleteDeselected();
- if (diveTable.nr == 0)
- // nothing to do, just exit
- return;
-
- // Consume the tables. They will be consumed by add_imported_dives() anyway.
- // But let's do it in a controlled way with a proper model-reset so that the
- // model doesn't become inconsistent.
+ // TODO: use structured bindings once we go C++17
std::pair<struct dive_table, struct dive_site_table> tables = consumeTables();
-
- // TODO: Might want to let the user select IMPORT_ADD_TO_NEW_TRIP
- add_imported_dives(&tables.first, nullptr, &tables.second, IMPORT_PREFER_IMPORTED | IMPORT_IS_DOWNLOADED);
+ if (tables.first.nr > 0) {
+ auto data = thread.data();
+ Command::importDives(&tables.first, nullptr, &tables.second, flags, data->devName());
+ } else {
+ clear_dive_site_table(&tables.second);
+ }
+ // The dives and dive sites have been consumed, but the arrays of the tables
+ // still exist. Free them.
free(tables.first.dives);
free(tables.second.dive_sites);
}
diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h
index 612bee8c7..58d073e37 100644
--- a/qt-models/diveimportedmodel.h
+++ b/qt-models/diveimportedmodel.h
@@ -4,6 +4,7 @@
#include <QAbstractTableModel>
#include <vector>
#include "core/divesite.h"
+#include "core/divelist.h"
#include "core/downloadfromdcthread.h"
class DiveImportedModel : public QAbstractTableModel
@@ -25,7 +26,7 @@ public:
std::pair<struct dive_table, struct dive_site_table> consumeTables(); // Returns dives and sites and resets model.
int numDives() const;
- Q_INVOKABLE void recordDives();
+ Q_INVOKABLE void recordDives(int flags = IMPORT_PREFER_IMPORTED | IMPORT_IS_DOWNLOADED);
Q_INVOKABLE void startDownload();
DownloadThread thread;