mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
mobile: unify download code on mobile and desktop
Use the undo-command for importing dives also on mobile. This should make the whole disconnect-model shenigans unnecessary. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3b6b9951ae
commit
b6f821886b
4 changed files with 20 additions and 32 deletions
|
@ -424,7 +424,6 @@ bool DCDeviceData::saveLog() const
|
|||
return data.libdc_log;
|
||||
}
|
||||
|
||||
|
||||
device_data_t *DCDeviceData::internalData()
|
||||
{
|
||||
return &data;
|
||||
|
|
|
@ -525,26 +525,13 @@ void DownloadFromDCWidget::on_ok_clicked()
|
|||
if (currentState != DONE && currentState != ERRORED)
|
||||
return;
|
||||
|
||||
// delete non-selected dives
|
||||
diveImportedModel->deleteDeselected();
|
||||
int flags = IMPORT_IS_DOWNLOADED;
|
||||
if (preferDownloaded())
|
||||
flags |= IMPORT_PREFER_IMPORTED;
|
||||
if (ui.createNewTrip->isChecked())
|
||||
flags |= IMPORT_ADD_TO_NEW_TRIP;
|
||||
|
||||
// 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);
|
||||
diveImportedModel->recordDives(flags);
|
||||
|
||||
if (ostcFirmwareCheck && currentState == DONE)
|
||||
ostcFirmwareCheck->checkLatest(this, diveImportedModel->thread.data()->internalData());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue