Dive d/l UI: redo the states, the flow, the buttons

This is bigger and more invasive then I wanted, but it's hard to break it
down into smaller pieces. Here's what it does:

The former "Download" button becomes the "Download", "Cancel download" and
"Retry" button. So this button controls your interaction with the dive
computer.

The other two buttons are now purely "OK" and "Cancel" for the dialog.
"Cancel" discards what happened (much easier now that we download into a
different table), and "OK" adds the dives that were selected in our
selection UI (by default all downloaded dives) to the real dive_table.

And while redoing all this, I also redid some of the state machine
underlying the dialog. The biggest change that the user will see is that
partial downloads (after canceling or after an error) will still offer the
dives that were completely downloaded up to that point in the selection
menu.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-01-09 15:01:48 -08:00
parent f10b66237e
commit 762f33bd13
3 changed files with 30 additions and 19 deletions

View file

@ -105,7 +105,8 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
ui.ok->setEnabled(false);
ui.startDownload->setEnabled(true);
ui.downloadCancelRetryButton->setEnabled(true);
ui.downloadCancelRetryButton->setText(tr("Download"));
}
void DownloadFromDCWidget::updateProgressBar()
@ -133,21 +134,19 @@ void DownloadFromDCWidget::updateState(states state)
// tries to cancel an on going download
else if (currentState == DOWNLOADING && state == CANCELLING) {
import_thread_cancelled = true;
ui.cancel->setEnabled(false);
ui.downloadCancelRetryButton->setEnabled(false);
}
// user pressed cancel but the application isn't doing anything.
// means close the window
else if ((currentState == INITIAL || currentState == CANCELLED || currentState == DONE || currentState == ERROR) && state == CANCELLING) {
else if ((currentState == INITIAL || currentState == DONE || currentState == ERROR) && state == CANCELLING) {
timer->stop();
reject();
ui.ok->setText(tr("OK"));
}
// the cancelation process is finished
else if (currentState == CANCELLING && (state == DONE || state == CANCELLED)) {
else if (currentState == CANCELLING && state == DONE) {
timer->stop();
state = CANCELLED;
ui.progressBar->setValue(0);
ui.progressBar->hide();
markChildrenAsEnabled();
@ -162,11 +161,9 @@ void DownloadFromDCWidget::updateState(states state)
updateProgressBar();
markChildrenAsEnabled();
progress_bar_text = "";
ui.ok->setText(tr("Retry"));
} else {
ui.progressBar->setValue(100);
markChildrenAsEnabled();
ui.ok->setText(tr("OK"));
}
}
@ -185,7 +182,6 @@ void DownloadFromDCWidget::updateState(states state)
markChildrenAsEnabled();
ui.progressBar->hide();
ui.ok->setText(tr("Retry"));
}
// properly updating the widget state
@ -284,15 +280,18 @@ void DownloadFromDCWidget::on_search_clicked()
}
}
void DownloadFromDCWidget::on_cancel_clicked()
{
updateState(CANCELLING);
}
void DownloadFromDCWidget::on_startDownload_clicked()
void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
{
if (currentState == DOWNLOADING) {
updateState(CANCELLING);
return;
}
updateState(DOWNLOADING);
// you cannot cancel the dialog, just the download
ui.cancel->setEnabled(false);
ui.downloadCancelRetryButton->setText("Cancel download");
// I don't really think that create/destroy the thread
// is really necessary.
if (thread) {
@ -402,10 +401,23 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
} else if (currentState == CANCELLING) {
updateState(DONE);
}
ui.downloadCancelRetryButton->setText(tr("Retry"));
ui.downloadCancelRetryButton->setEnabled(true);
// regardless, if we got dives, we should show them to the user
if (downloadTable.nr) {
diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1);
}
}
void DownloadFromDCWidget::on_cancel_clicked()
{
if (currentState == DOWNLOADING || currentState == CANCELLING)
return;
// now discard all the dives
clear_table(&downloadTable);
done(-1);
}
void DownloadFromDCWidget::on_ok_clicked()

View file

@ -60,14 +60,13 @@ public:
INITIAL,
DOWNLOADING,
CANCELLING,
CANCELLED,
ERROR,
DONE,
};
public
slots:
void on_startDownload_clicked();
void on_downloadCancelRetryButton_clicked();
void on_ok_clicked();
void on_cancel_clicked();
void on_search_clicked();

View file

@ -135,7 +135,7 @@
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="startDownloadLayout">
<layout class="QHBoxLayout" name="downloadCancelRetryLayout">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@ -150,7 +150,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="startDownload">
<widget class="QPushButton" name="downloadCancelRetryButton">
<property name="text">
<string>Download</string>
</property>