mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Now use our table when downloading from the dive computer
We pass a different table to libdivecomputer (and the uemis code) and have that table filled. And then we simply copy the dives from that table into the real dive_table when the user accepts the download. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e43ea018fa
commit
7357633905
3 changed files with 19 additions and 41 deletions
|
@ -597,7 +597,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
|
||||||
}
|
}
|
||||||
|
|
||||||
dive->downloaded = true;
|
dive->downloaded = true;
|
||||||
record_dive(dive);
|
record_dive_to_table(dive, devdata->download_table);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -399,26 +399,12 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
|
||||||
updateState(DONE);
|
updateState(DONE);
|
||||||
else
|
else
|
||||||
updateState(ERROR);
|
updateState(ERROR);
|
||||||
|
} else if (currentState == CANCELLING) {
|
||||||
// I'm not sure if we should really call process_dives even
|
updateState(DONE);
|
||||||
// if there's an error
|
}
|
||||||
if (import_thread_cancelled) {
|
// regardless, if we got dives, we should show them to the user
|
||||||
// walk backwards so we don't keep moving the dives
|
if (downloadTable.nr) {
|
||||||
// down in the dive_table
|
diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1);
|
||||||
for (int i = dive_table.nr - 1; i >= previousLast; i--)
|
|
||||||
delete_single_dive(i);
|
|
||||||
} else if (dive_table.nr && previousLast < dive_table.nr) {
|
|
||||||
diveImportedModel->setImportedDivesIndexes(previousLast, dive_table.nr - 1);
|
|
||||||
}
|
|
||||||
ui.startDownload->setEnabled(false);
|
|
||||||
} else if (currentState == CANCELLING || currentState == CANCELLED) {
|
|
||||||
if (import_thread_cancelled) {
|
|
||||||
// walk backwards so we don't keep moving the dives
|
|
||||||
// down in the dive_table
|
|
||||||
for (int i = dive_table.nr - 1; i >= previousLast; i--)
|
|
||||||
delete_single_dive(i);
|
|
||||||
}
|
|
||||||
updateState(CANCELLED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,8 +413,13 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
if (currentState != DONE)
|
if (currentState != DONE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// remove all unselected dives from the dive-list.
|
// record all the dives in the 'real' dive_table
|
||||||
diveImportedModel->removeUnused();
|
for (int i = 0; i < downloadTable.nr; i++) {
|
||||||
|
if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked)
|
||||||
|
record_dive(downloadTable.dives[i]);
|
||||||
|
downloadTable.dives[i] = NULL;
|
||||||
|
}
|
||||||
|
downloadTable.nr = 0;
|
||||||
|
|
||||||
int uniqId, idx;
|
int uniqId, idx;
|
||||||
// remember the last downloaded dive (on most dive computers this will be the chronologically
|
// remember the last downloaded dive (on most dive computers this will be the chronologically
|
||||||
|
@ -521,6 +512,7 @@ void DownloadThread::run()
|
||||||
{
|
{
|
||||||
const char *errorText;
|
const char *errorText;
|
||||||
import_thread_cancelled = false;
|
import_thread_cancelled = false;
|
||||||
|
data->download_table = &downloadTable;
|
||||||
if (!strcmp(data->vendor, "Uemis"))
|
if (!strcmp(data->vendor, "Uemis"))
|
||||||
errorText = do_uemis_import(data);
|
errorText = do_uemis_import(data);
|
||||||
else
|
else
|
||||||
|
@ -571,7 +563,9 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
|
||||||
if (index.row() + firstIndex > lastIndex)
|
if (index.row() + firstIndex > lastIndex)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
struct dive *d = get_dive(index.row() + firstIndex);
|
struct dive *d = get_dive_from_table(index.row() + firstIndex, &downloadTable);
|
||||||
|
if (!d)
|
||||||
|
return QVariant();
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -627,19 +621,3 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last)
|
||||||
memset(checkStates, true, last - first + 1);
|
memset(checkStates, true, last - first + 1);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveImportedModel::removeUnused()
|
|
||||||
{
|
|
||||||
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
|
|
||||||
endRemoveRows();
|
|
||||||
|
|
||||||
for (int i = lastIndex; i >= firstIndex; i--) {
|
|
||||||
if (!checkStates[i - firstIndex]) {
|
|
||||||
delete_single_dive(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastIndex = 0;
|
|
||||||
firstIndex = 0;
|
|
||||||
delete[] checkStates;
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ static void record_uemis_dive(device_data_t *devdata, struct dive *dive)
|
||||||
else
|
else
|
||||||
add_dive_to_trip(dive, devdata->trip);
|
add_dive_to_trip(dive, devdata->trip);
|
||||||
}
|
}
|
||||||
record_dive(dive);
|
record_dive_to_table(dive, devdata->download_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send text to the importer progress bar */
|
/* send text to the importer progress bar */
|
||||||
|
|
Loading…
Reference in a new issue