summaryrefslogtreecommitdiffstats
path: root/qt-ui/downloadfromdivecomputer.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-09 14:44:38 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-09 15:06:25 -0800
commit7357633905cf3bb33a99f7c0b54d214f49373411 (patch)
tree8edcba679c45b6275e321e8033979710cea37031 /qt-ui/downloadfromdivecomputer.cpp
parente43ea018fa2faecfc6ebb5a7831bafbfefca183d (diff)
downloadsubsurface-7357633905cf3bb33a99f7c0b54d214f49373411.tar.gz
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>
Diffstat (limited to 'qt-ui/downloadfromdivecomputer.cpp')
-rw-r--r--qt-ui/downloadfromdivecomputer.cpp56
1 files changed, 17 insertions, 39 deletions
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp
index 87529456b..7921acc23 100644
--- a/qt-ui/downloadfromdivecomputer.cpp
+++ b/qt-ui/downloadfromdivecomputer.cpp
@@ -399,26 +399,12 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
updateState(DONE);
else
updateState(ERROR);
-
- // I'm not sure if we should really call process_dives even
- // if there's an error
- 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);
- } 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);
+ } else if (currentState == CANCELLING) {
+ updateState(DONE);
+ }
+ // regardless, if we got dives, we should show them to the user
+ if (downloadTable.nr) {
+ diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1);
}
}
@@ -427,8 +413,13 @@ void DownloadFromDCWidget::on_ok_clicked()
if (currentState != DONE)
return;
- // remove all unselected dives from the dive-list.
- diveImportedModel->removeUnused();
+ // record all the dives in the 'real' dive_table
+ 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;
// remember the last downloaded dive (on most dive computers this will be the chronologically
@@ -521,6 +512,7 @@ void DownloadThread::run()
{
const char *errorText;
import_thread_cancelled = false;
+ data->download_table = &downloadTable;
if (!strcmp(data->vendor, "Uemis"))
errorText = do_uemis_import(data);
else
@@ -571,7 +563,9 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
if (index.row() + firstIndex > lastIndex)
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) {
switch (index.column()) {
case 0:
@@ -627,19 +621,3 @@ void DiveImportedModel::setImportedDivesIndexes(int first, int last)
memset(checkStates, true, last - first + 1);
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;
-}