From 82d37e7451b4e7a11974f840cc4acdab4e389d76 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 22 Apr 2017 13:49:03 -0700 Subject: 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 --- desktop-widgets/downloadfromdivecomputer.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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(); } -- cgit v1.2.3-70-g09d2