diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-09-09 13:02:39 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-09 13:02:39 -0700 |
commit | 2025bc1b2bd2e52f27edb67a418e1519d3d664d8 (patch) | |
tree | 68c3991f21abdbdc9801c434b8d841c217d65d43 /qt-ui/mainwindow.cpp | |
parent | 2c74a8c315441b95da98e3f4b35db1b9eefb76ff (diff) | |
download | subsurface-2025bc1b2bd2e52f27edb67a418e1519d3d664d8.tar.gz |
Replace the spinner with a progress dialog for cloud storage access
Since the spinner caused all kinds of problems inside VMs, wasn't shown at
all for some people on Win10 and appeared to get stuck a lot and still
left people with the perception that Subsurface was hung, this patch takes
a more traditional approach and gives the user a progress dialog.
An additional benefit of this is that the user now can cancel a hung
transfer.
The slightly weird passing in of the callback allows for the separation of
UI and core logic code...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r-- | qt-ui/mainwindow.cpp | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index c9f15ee12..d26ad2a3b 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -51,6 +51,16 @@ #include <qthelper.h> #include <QtConcurrentRun> +QProgressDialog *progressDialog = NULL; +bool progressDialogCanceled = false; + +extern "C" int updateProgress(int percent) +{ + if (progressDialog) + progressDialog->setValue(percent); + return progressDialogCanceled; +} + MainWindow *MainWindow::m_Instance = NULL; MainWindow::MainWindow() : QMainWindow(), @@ -58,8 +68,7 @@ MainWindow::MainWindow() : QMainWindow(), actionPreviousDive(0), helpView(0), state(VIEWALL), - survey(0), - spinner(0) + survey(0) { Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!"); m_Instance = this; @@ -227,7 +236,7 @@ MainWindow::MainWindow() : QMainWindow(), #endif ui.menubar->show(); - + set_git_update_cb(&updateProgress); } MainWindow::~MainWindow() @@ -386,7 +395,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() int error; - startSpinner(); + showProgressBar(); QByteArray fileNamePtr = QFile::encodeName(filename); error = parse_file(fileNamePtr.data()); if (!error) { @@ -395,7 +404,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() } getNotificationWidget()->hideNotification(); process_dives(false, false); - stopSpinner(); + hideProgressBar(); refreshDisplay(); ui.actionAutoGroup->setChecked(autogroup); } @@ -411,14 +420,14 @@ void MainWindow::on_actionCloudstoragesave_triggered() if (information()->isEditing()) information()->acceptChanges(); - startSpinner(); + showProgressBar(); if (save_dives(filename.toUtf8().data())) { getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); return; } - stopSpinner(); + hideProgressBar(); getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error); set_filename(filename.toUtf8().data(), true); @@ -1783,23 +1792,28 @@ void MainWindow::setApplicationState(const QByteArray& state) { #undef SET_CURRENT_INDEX } -void MainWindow::startSpinner() +void MainWindow::showProgressBar() { - if (!spinner) { - spinner = new QtWaitingSpinner(Qt::WindowModal, this, true); - spinner->setRevolutionsPerSecond(1); - spinner->setColor(WHITE1); - spinner->setLineWidth(7); - spinner->setRoundness(40.0); - spinner->setMinimumTrailOpacity(0.25); - } - int shorterEdge = MIN(this->geometry().height(), this->geometry().width()); - spinner->setInnerRadius(shorterEdge / 12); - spinner->setLineLength(shorterEdge / 8); - spinner->start(); + if (progressDialog) + delete progressDialog; + + progressDialog = new QProgressDialog(tr("Contacting cloud service..."), tr("Cancel"), 0, 100, this); + progressDialog->setWindowModality(Qt::WindowModal); + progressDialog->setMinimumDuration(0); + progressDialogCanceled = false; + connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelCloudStorageOperation())); } -void MainWindow::stopSpinner() +void MainWindow::cancelCloudStorageOperation() { - spinner->stop(); + progressDialogCanceled = true; +} + +void MainWindow::hideProgressBar() +{ + if (progressDialog) { + progressDialog->setValue(100); + progressDialog->deleteLater(); + progressDialog = NULL; + } } |