summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/downloadfromdivecomputer.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-04-22 13:49:03 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-04-22 13:49:07 -0700
commit82d37e7451b4e7a11974f840cc4acdab4e389d76 (patch)
tree69b13f41a4d20a37f4268e3343d19ef4c1debdf5 /desktop-widgets/downloadfromdivecomputer.cpp
parent0bd02bf1f093835ed6cd14682a7900f738bb6736 (diff)
downloadsubsurface-82d37e7451b4e7a11974f840cc4acdab4e389d76.tar.gz
Download from divecomputer: don't show bogus progress text
On some divecomputers we download all the data from the device and then parse the data afterwards just in memory (at which point the progress bar has already run all the way to 100%). So don't try to show the dive number and time in that case. Fixes #335 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/downloadfromdivecomputer.cpp')
-rw-r--r--desktop-widgets/downloadfromdivecomputer.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index 1a3a0fda9..30df77581 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -121,12 +121,22 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
void DownloadFromDCWidget::updateProgressBar()
{
- if (*progress_bar_text != '\0') {
+ static char *last_text = NULL;
+
+ if (same_string(last_text, "")) {
+ // if we get the first actual text after the download is finished
+ // (which happens for example on the OSTC), then don't bother
+ if (!same_string(progress_bar_text, "") && IS_FP_SAME(progress_bar_fraction, 1.0))
+ progress_bar_text = NULL;
+ }
+ if (!same_string(progress_bar_text , "")) {
ui.progressBar->setFormat(progress_bar_text);
} else {
ui.progressBar->setFormat("%p%");
}
ui.progressBar->setValue(lrint(progress_bar_fraction * 100));
+ free(last_text);
+ last_text = strdup(progress_bar_text);
}
void DownloadFromDCWidget::updateState(states state)
@@ -139,6 +149,7 @@ void DownloadFromDCWidget::updateState(states state)
ui.progressBar->hide();
markChildrenAsEnabled();
timer->stop();
+ progress_bar_text = "";
}
// tries to cancel an on going download
@@ -160,6 +171,7 @@ void DownloadFromDCWidget::updateState(states state)
ui.progressBar->setValue(0);
ui.progressBar->hide();
markChildrenAsEnabled();
+ progress_bar_text = "";
}
// DOWNLOAD is finally done, but we don't know if there was an error as libdivecomputer doesn't pass
@@ -172,6 +184,7 @@ void DownloadFromDCWidget::updateState(states state)
markChildrenAsEnabled();
progress_bar_text = "";
} else {
+ progress_bar_text = "";
ui.progressBar->setValue(100);
markChildrenAsEnabled();
}
@@ -191,6 +204,7 @@ void DownloadFromDCWidget::updateState(states state)
timer->stop();
QMessageBox::critical(this, TITLE_OR_TEXT(tr("Error"), this->thread->error), QMessageBox::Ok);
markChildrenAsEnabled();
+ progress_bar_text = "";
ui.progressBar->hide();
}