mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Import: don't add to new trip while downloading
Since process_imported_dives() can add dives to a newly generated trip, this need not be done in the downloading code. This makes data flow distinctly simpler, as no trip table and no add-new-trip flag has to be passed down to the libdivecomputer glue code. Moreover, since now the trip creation is done at the import step rather than the download step, the latest status of the "add to new trip" checkbox will be considered. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
1cd0863cca
commit
ff9506b21b
12 changed files with 18 additions and 74 deletions
|
@ -1661,8 +1661,10 @@ bool try_to_merge_trip(struct dive_trip *trip_import, struct dive_table *import_
|
||||||
* 3) Trips to be added
|
* 3) Trips to be added
|
||||||
* The dives to be added are owning (i.e. the caller is responsible
|
* The dives to be added are owning (i.e. the caller is responsible
|
||||||
* for freeing them).
|
* for freeing them).
|
||||||
* The dives and trips in import_table and import_trip table are
|
* The dives and trips in "import_table" and "import_trip_table" are
|
||||||
* consumed. On return, both tables have size 0.
|
* consumed. On return, both tables have size 0.
|
||||||
|
* "import_trip_table" may be NULL if all dives are not associated
|
||||||
|
* with a trip.
|
||||||
* The output parameters should be empty - if not, their content
|
* The output parameters should be empty - if not, their content
|
||||||
* will be cleared!
|
* will be cleared!
|
||||||
*
|
*
|
||||||
|
@ -1690,6 +1692,13 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
||||||
bool sequence_changed = false;
|
bool sequence_changed = false;
|
||||||
bool new_dive_has_number = false;
|
bool new_dive_has_number = false;
|
||||||
|
|
||||||
|
/* If the caller didn't pass an import_trip_table because all
|
||||||
|
* dives are tripless, provide a local table. This may be
|
||||||
|
* necessary if the trips are autogrouped */
|
||||||
|
struct trip_table local_trip_table = { 0 };
|
||||||
|
if (!import_trip_table)
|
||||||
|
import_trip_table = &local_trip_table;
|
||||||
|
|
||||||
/* Make sure that output parameters don't contain garbage */
|
/* Make sure that output parameters don't contain garbage */
|
||||||
clear_table(dives_to_add);
|
clear_table(dives_to_add);
|
||||||
clear_table(dives_to_remove);
|
clear_table(dives_to_remove);
|
||||||
|
|
|
@ -60,7 +60,6 @@ static void updateRememberedDCs()
|
||||||
|
|
||||||
|
|
||||||
DownloadThread::DownloadThread() : downloadTable({ 0 }),
|
DownloadThread::DownloadThread() : downloadTable({ 0 }),
|
||||||
tripTable({ 0 }),
|
|
||||||
m_data(DCDeviceData::instance())
|
m_data(DCDeviceData::instance())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -70,7 +69,6 @@ void DownloadThread::run()
|
||||||
auto internalData = m_data->internalData();
|
auto internalData = m_data->internalData();
|
||||||
internalData->descriptor = descriptorLookup[m_data->vendor() + m_data->product()];
|
internalData->descriptor = descriptorLookup[m_data->vendor() + m_data->product()];
|
||||||
internalData->download_table = &downloadTable;
|
internalData->download_table = &downloadTable;
|
||||||
internalData->trip_table = &tripTable;
|
|
||||||
internalData->btname = strdup(m_data->devBluetoothName().toUtf8());
|
internalData->btname = strdup(m_data->devBluetoothName().toUtf8());
|
||||||
if (!internalData->descriptor) {
|
if (!internalData->descriptor) {
|
||||||
qDebug() << "No download possible when DC type is unknown";
|
qDebug() << "No download possible when DC type is unknown";
|
||||||
|
@ -83,10 +81,6 @@ void DownloadThread::run()
|
||||||
#endif
|
#endif
|
||||||
qDebug() << "Starting download from " << (internalData->bluetooth_mode ? "BT" : internalData->devname);
|
qDebug() << "Starting download from " << (internalData->bluetooth_mode ? "BT" : internalData->devname);
|
||||||
clear_table(&downloadTable);
|
clear_table(&downloadTable);
|
||||||
if (tripTable.nr > 0) {
|
|
||||||
qWarning() << "DownloadThread::run(): Trip table not empty after reset";
|
|
||||||
tripTable.nr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(internalData->download_table != nullptr);
|
Q_ASSERT(internalData->download_table != nullptr);
|
||||||
const char *errorText;
|
const char *errorText;
|
||||||
|
@ -265,7 +259,6 @@ DCDeviceData::DCDeviceData()
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
data.trip = nullptr;
|
data.trip = nullptr;
|
||||||
data.download_table = nullptr;
|
data.download_table = nullptr;
|
||||||
data.trip_table = nullptr;
|
|
||||||
data.diveid = 0;
|
data.diveid = 0;
|
||||||
data.deviceid = 0;
|
data.deviceid = 0;
|
||||||
#if defined(BT_SUPPORT)
|
#if defined(BT_SUPPORT)
|
||||||
|
@ -274,7 +267,6 @@ DCDeviceData::DCDeviceData()
|
||||||
data.bluetooth_mode = false;
|
data.bluetooth_mode = false;
|
||||||
#endif
|
#endif
|
||||||
data.force_download = false;
|
data.force_download = false;
|
||||||
data.create_new_trip = false;
|
|
||||||
data.libdc_dump = false;
|
data.libdc_dump = false;
|
||||||
#if defined(SUBSURFACE_MOBILE)
|
#if defined(SUBSURFACE_MOBILE)
|
||||||
data.libdc_log = true;
|
data.libdc_log = true;
|
||||||
|
@ -314,11 +306,6 @@ struct dive_table *DownloadThread::table()
|
||||||
return &downloadTable;
|
return &downloadTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct trip_table *DownloadThread::trips()
|
|
||||||
{
|
|
||||||
return &tripTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DCDeviceData::vendor() const
|
QString DCDeviceData::vendor() const
|
||||||
{
|
{
|
||||||
return data.vendor;
|
return data.vendor;
|
||||||
|
@ -354,11 +341,6 @@ bool DCDeviceData::forceDownload() const
|
||||||
return data.force_download;
|
return data.force_download;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DCDeviceData::createNewTrip() const
|
|
||||||
{
|
|
||||||
return data.create_new_trip;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DCDeviceData::deviceId() const
|
int DCDeviceData::deviceId() const
|
||||||
{
|
{
|
||||||
return data.deviceid;
|
return data.deviceid;
|
||||||
|
@ -415,11 +397,6 @@ void DCDeviceData::setForceDownload(bool force)
|
||||||
data.force_download = force;
|
data.force_download = force;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCDeviceData::setCreateNewTrip(bool create)
|
|
||||||
{
|
|
||||||
data.create_new_trip = create;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DCDeviceData::setDeviceId(int deviceId)
|
void DCDeviceData::setDeviceId(int deviceId)
|
||||||
{
|
{
|
||||||
data.deviceid = deviceId;
|
data.deviceid = deviceId;
|
||||||
|
|
|
@ -26,7 +26,6 @@ public:
|
||||||
QString devBluetoothName() const;
|
QString devBluetoothName() const;
|
||||||
QString descriptor() const;
|
QString descriptor() const;
|
||||||
bool forceDownload() const;
|
bool forceDownload() const;
|
||||||
bool createNewTrip() const;
|
|
||||||
bool saveLog() const;
|
bool saveLog() const;
|
||||||
int deviceId() const;
|
int deviceId() const;
|
||||||
int diveId() const;
|
int diveId() const;
|
||||||
|
@ -48,7 +47,6 @@ public:
|
||||||
void setDevBluetoothName(const QString& devBluetoothName);
|
void setDevBluetoothName(const QString& devBluetoothName);
|
||||||
void setBluetoothMode(bool mode);
|
void setBluetoothMode(bool mode);
|
||||||
void setForceDownload(bool force);
|
void setForceDownload(bool force);
|
||||||
void setCreateNewTrip(bool create);
|
|
||||||
void setSaveDump(bool dumpMode);
|
void setSaveDump(bool dumpMode);
|
||||||
void setSaveLog(bool saveLog);
|
void setSaveLog(bool saveLog);
|
||||||
private:
|
private:
|
||||||
|
@ -61,7 +59,6 @@ private:
|
||||||
class DownloadThread : public QThread {
|
class DownloadThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(dive_table_t *table READ table CONSTANT)
|
Q_PROPERTY(dive_table_t *table READ table CONSTANT)
|
||||||
Q_PROPERTY(trip_table_t *trips READ trips CONSTANT)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DownloadThread();
|
DownloadThread();
|
||||||
|
@ -69,7 +66,6 @@ public:
|
||||||
|
|
||||||
DCDeviceData *data();
|
DCDeviceData *data();
|
||||||
struct dive_table *table();
|
struct dive_table *table();
|
||||||
struct trip_table *trips();
|
|
||||||
QString error;
|
QString error;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -824,13 +824,6 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
||||||
dive->dc.sample[0].temperature.mkelvin = 0;
|
dive->dc.sample[0].temperature.mkelvin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devdata->create_new_trip) {
|
|
||||||
if (!devdata->trip)
|
|
||||||
devdata->trip = create_and_hookup_trip_from_dive(dive, devdata->trip_table);
|
|
||||||
else
|
|
||||||
add_dive_to_trip(dive, devdata->trip);
|
|
||||||
}
|
|
||||||
|
|
||||||
record_dive_to_table(dive, devdata->download_table);
|
record_dive_to_table(dive, devdata->download_table);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -41,13 +41,11 @@ typedef struct dc_user_device_t
|
||||||
struct dive_trip *trip;
|
struct dive_trip *trip;
|
||||||
int preexisting;
|
int preexisting;
|
||||||
bool force_download;
|
bool force_download;
|
||||||
bool create_new_trip;
|
|
||||||
bool libdc_log;
|
bool libdc_log;
|
||||||
bool libdc_dump;
|
bool libdc_dump;
|
||||||
bool bluetooth_mode;
|
bool bluetooth_mode;
|
||||||
FILE *libdc_logfile;
|
FILE *libdc_logfile;
|
||||||
struct dive_table *download_table;
|
struct dive_table *download_table;
|
||||||
struct trip_table *trip_table;
|
|
||||||
} device_data_t;
|
} device_data_t;
|
||||||
|
|
||||||
const char *errmsg (dc_status_t rc);
|
const char *errmsg (dc_status_t rc);
|
||||||
|
|
|
@ -211,17 +211,6 @@ static struct dive *get_dive_by_uemis_diveid(device_data_t *devdata, uint32_t ob
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void record_uemis_dive(device_data_t *devdata, struct dive *dive)
|
|
||||||
{
|
|
||||||
if (devdata->create_new_trip) {
|
|
||||||
if (!devdata->trip)
|
|
||||||
devdata->trip = create_and_hookup_trip_from_dive(dive, &trip_table);
|
|
||||||
else
|
|
||||||
add_dive_to_trip(dive, devdata->trip);
|
|
||||||
}
|
|
||||||
record_dive_to_table(dive, devdata->download_table);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send text to the importer progress bar */
|
/* send text to the importer progress bar */
|
||||||
static void uemis_info(const char *fmt, ...)
|
static void uemis_info(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
@ -1024,14 +1013,14 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
|
||||||
* be a short read because of some error */
|
* be a short read because of some error */
|
||||||
if (done && ++bp < endptr && *bp != '{' && strstr(bp, "{{")) {
|
if (done && ++bp < endptr && *bp != '{' && strstr(bp, "{{")) {
|
||||||
done = false;
|
done = false;
|
||||||
record_uemis_dive(devdata, dive);
|
record_dive_to_table(dive, devdata->download_table);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
dive = uemis_start_dive(deviceid);
|
dive = uemis_start_dive(deviceid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_log) {
|
if (is_log) {
|
||||||
if (dive->dc.diveid) {
|
if (dive->dc.diveid) {
|
||||||
record_uemis_dive(devdata, dive);
|
record_dive_to_table(dive, devdata->download_table);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
} else { /* partial dive */
|
} else { /* partial dive */
|
||||||
free(dive);
|
free(dive);
|
||||||
|
|
|
@ -384,7 +384,6 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
data->setForceDownload(ui.forceDownload->isChecked());
|
data->setForceDownload(ui.forceDownload->isChecked());
|
||||||
data->setCreateNewTrip(ui.createNewTrip->isChecked());
|
|
||||||
data->setSaveLog(ui.logToFile->isChecked());
|
data->setSaveLog(ui.logToFile->isChecked());
|
||||||
data->setSaveDump(ui.dumpToFile->isChecked());
|
data->setSaveDump(ui.dumpToFile->isChecked());
|
||||||
|
|
||||||
|
@ -486,7 +485,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
|
||||||
}
|
}
|
||||||
ui.downloadCancelRetryButton->setText(tr("Retry download"));
|
ui.downloadCancelRetryButton->setText(tr("Retry download"));
|
||||||
ui.downloadCancelRetryButton->setEnabled(true);
|
ui.downloadCancelRetryButton->setEnabled(true);
|
||||||
diveImportedModel->repopulate(thread.table(), thread.trips());
|
diveImportedModel->repopulate(thread.table());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::on_cancel_clicked()
|
void DownloadFromDCWidget::on_cancel_clicked()
|
||||||
|
@ -504,7 +503,6 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
if (currentState != DONE && currentState != ERROR)
|
if (currentState != DONE && currentState != ERROR)
|
||||||
return;
|
return;
|
||||||
struct dive_table *table = thread.table();
|
struct dive_table *table = thread.table();
|
||||||
struct trip_table *trips = thread.trips();
|
|
||||||
|
|
||||||
// delete non-selected dives
|
// delete non-selected dives
|
||||||
int total = table->nr;
|
int total = table->nr;
|
||||||
|
@ -518,7 +516,7 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
|
|
||||||
if (table->nr > 0) {
|
if (table->nr > 0) {
|
||||||
auto data = thread.data();
|
auto data = thread.data();
|
||||||
Command::importDives(table, trips, preferDownloaded(), true, false, ui.createNewTrip->isChecked(), data->devName());
|
Command::importDives(table, nullptr, preferDownloaded(), true, false, ui.createNewTrip->isChecked(), data->devName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ostcFirmwareCheck && currentState == DONE)
|
if (ostcFirmwareCheck && currentState == DONE)
|
||||||
|
|
|
@ -28,7 +28,7 @@ Kirigami.Page {
|
||||||
id: downloadThread
|
id: downloadThread
|
||||||
|
|
||||||
onFinished : {
|
onFinished : {
|
||||||
importModel.repopulate(table, trips)
|
importModel.repopulate(table)
|
||||||
progressBar.visible = false
|
progressBar.visible = false
|
||||||
if (dcImportModel.rowCount() > 0) {
|
if (dcImportModel.rowCount() > 0) {
|
||||||
console.log(dcImportModel.rowCount() + " dive downloaded")
|
console.log(dcImportModel.rowCount() + " dive downloaded")
|
||||||
|
|
|
@ -1803,11 +1803,6 @@ bool QMLManager::DC_bluetoothMode() const
|
||||||
return DCDeviceData::instance()->bluetoothMode();
|
return DCDeviceData::instance()->bluetoothMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QMLManager::DC_createNewTrip() const
|
|
||||||
{
|
|
||||||
return DCDeviceData::instance()->createNewTrip();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QMLManager::DC_saveDump() const
|
bool QMLManager::DC_saveDump() const
|
||||||
{
|
{
|
||||||
return DCDeviceData::instance()->saveDump();
|
return DCDeviceData::instance()->saveDump();
|
||||||
|
@ -1853,11 +1848,6 @@ void QMLManager::DC_setForceDownload(bool force)
|
||||||
DCDeviceData::instance()->setForceDownload(force);
|
DCDeviceData::instance()->setForceDownload(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::DC_setCreateNewTrip(bool create)
|
|
||||||
{
|
|
||||||
DCDeviceData::instance()->setCreateNewTrip(create);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QMLManager::DC_setSaveDump(bool dumpMode)
|
void QMLManager::DC_setSaveDump(bool dumpMode)
|
||||||
{
|
{
|
||||||
DCDeviceData::instance()->setSaveDump(dumpMode);
|
DCDeviceData::instance()->setSaveDump(dumpMode);
|
||||||
|
|
|
@ -45,7 +45,6 @@ class QMLManager : public QObject {
|
||||||
Q_PROPERTY(QString descriptor READ DC_descriptor)
|
Q_PROPERTY(QString descriptor READ DC_descriptor)
|
||||||
Q_PROPERTY(bool DC_forceDownload READ DC_forceDownload WRITE DC_setForceDownload)
|
Q_PROPERTY(bool DC_forceDownload READ DC_forceDownload WRITE DC_setForceDownload)
|
||||||
Q_PROPERTY(bool DC_bluetoothMode READ DC_bluetoothMode WRITE DC_setBluetoothMode)
|
Q_PROPERTY(bool DC_bluetoothMode READ DC_bluetoothMode WRITE DC_setBluetoothMode)
|
||||||
Q_PROPERTY(bool DC_createNewTrip READ DC_createNewTrip WRITE DC_setCreateNewTrip)
|
|
||||||
Q_PROPERTY(bool DC_saveDump READ DC_saveDump WRITE DC_setSaveDump)
|
Q_PROPERTY(bool DC_saveDump READ DC_saveDump WRITE DC_setSaveDump)
|
||||||
Q_PROPERTY(int DC_deviceId READ DC_deviceId WRITE DC_setDeviceId)
|
Q_PROPERTY(int DC_deviceId READ DC_deviceId WRITE DC_setDeviceId)
|
||||||
Q_PROPERTY(QString pluggedInDeviceName MEMBER m_pluggedInDeviceName NOTIFY pluggedInDeviceNameChanged)
|
Q_PROPERTY(QString pluggedInDeviceName MEMBER m_pluggedInDeviceName NOTIFY pluggedInDeviceNameChanged)
|
||||||
|
@ -75,9 +74,6 @@ public:
|
||||||
bool DC_bluetoothMode() const;
|
bool DC_bluetoothMode() const;
|
||||||
void DC_setBluetoothMode(bool mode);
|
void DC_setBluetoothMode(bool mode);
|
||||||
|
|
||||||
bool DC_createNewTrip() const;
|
|
||||||
void DC_setCreateNewTrip(bool create);
|
|
||||||
|
|
||||||
bool DC_saveDump() const;
|
bool DC_saveDump() const;
|
||||||
void DC_setSaveDump(bool dumpMode);
|
void DC_setSaveDump(bool dumpMode);
|
||||||
|
|
||||||
|
|
|
@ -127,12 +127,11 @@ void DiveImportedModel::clearTable()
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveImportedModel::repopulate(dive_table_t *table, trip_table_t *trips)
|
void DiveImportedModel::repopulate(dive_table_t *table)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
diveTable = table;
|
diveTable = table;
|
||||||
tripTable = trips;
|
|
||||||
firstIndex = 0;
|
firstIndex = 0;
|
||||||
lastIndex = diveTable->nr - 1;
|
lastIndex = diveTable->nr - 1;
|
||||||
checkStates.resize(diveTable->nr);
|
checkStates.resize(diveTable->nr);
|
||||||
|
@ -159,7 +158,7 @@ void DiveImportedModel::recordDives()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Might want to let the user select "add_to_new_trip"
|
// TODO: Might want to let the user select "add_to_new_trip"
|
||||||
add_imported_dives(diveTable, tripTable, true, true, false, false);
|
add_imported_dives(diveTable, nullptr, true, true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> DiveImportedModel::roleNames() const {
|
QHash<int, QByteArray> DiveImportedModel::roleNames() const {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
Q_INVOKABLE void clearTable();
|
Q_INVOKABLE void clearTable();
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
Q_INVOKABLE void repopulate(dive_table_t *table, trip_table_t *trips);
|
Q_INVOKABLE void repopulate(dive_table_t *table);
|
||||||
Q_INVOKABLE void recordDives();
|
Q_INVOKABLE void recordDives();
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
|
@ -34,7 +34,6 @@ private:
|
||||||
int lastIndex;
|
int lastIndex;
|
||||||
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
|
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
|
||||||
struct dive_table *diveTable;
|
struct dive_table *diveTable;
|
||||||
struct trip_table *tripTable;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue