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>
This commit is contained in:
Dirk Hohndel 2017-04-22 13:49:03 -07:00
parent 0bd02bf1f0
commit 82d37e7451

View file

@ -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();
}