diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-01-09 15:01:48 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-09 15:06:25 -0800 |
commit | 762f33bd13e91e2c187035a87eda0b4d6efd93c8 (patch) | |
tree | 9864e1fac5bdd4de64bd694ef1ba3ff161a51b10 | |
parent | f10b66237e10f77d026335e9d39ad8a99a8f01bf (diff) | |
download | subsurface-762f33bd13e91e2c187035a87eda0b4d6efd93c8.tar.gz |
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>
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 42 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.h | 3 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.ui | 4 |
3 files changed, 30 insertions, 19 deletions
diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 7921acc23..da3bb136b 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -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() diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h index 70b3c8e62..c92190b78 100644 --- a/qt-ui/downloadfromdivecomputer.h +++ b/qt-ui/downloadfromdivecomputer.h @@ -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(); diff --git a/qt-ui/downloadfromdivecomputer.ui b/qt-ui/downloadfromdivecomputer.ui index 66de6006d..004895038 100644 --- a/qt-ui/downloadfromdivecomputer.ui +++ b/qt-ui/downloadfromdivecomputer.ui @@ -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> |