]> sigrok.org Git - pulseview.git/blobdiff - pv/dialogs/storeprogress.cpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / dialogs / storeprogress.cpp
index 2bca3476c434b53ff65e99b4774145dbff248592..0bcfbf2c75ca772510068b0309a4053e74fef5a3 100644 (file)
@@ -43,12 +43,14 @@ StoreProgress::StoreProgress(const QString &file_name,
        const Session &session, QWidget *parent) :
        QProgressDialog(tr("Saving..."), tr("Cancel"), 0, 0, parent),
        session_(file_name.toStdString(), output_format, options, sample_range,
-               session)
+               session),
+       showing_error_(false)
 {
        connect(&session_, SIGNAL(progress_updated()),
                this, SLOT(on_progress_updated()));
        connect(&session_, SIGNAL(store_successful()),
                &session, SLOT(on_data_saved()));
+       connect(this, SIGNAL(canceled()), this, SLOT(on_cancel()));
 
        // Since we're not setting any progress in case of an error, the dialog
        // will pop up after the minimumDuration time has been reached - 4000 ms
@@ -79,6 +81,8 @@ void StoreProgress::run()
 
 void StoreProgress::show_error()
 {
+       showing_error_ = true;
+
        qDebug() << "Error trying to save:" << session_.error();
 
        QMessageBox msg(parentWidget());
@@ -109,11 +113,17 @@ void StoreProgress::on_progress_updated()
                setMaximum(p.second);
        } else {
                const QString err = session_.error();
-               if (!err.isEmpty())
+               if (err.isEmpty())
+                       close();
+               else if (!showing_error_)
                        show_error();
-               close();
        }
 }
 
+void StoreProgress::on_cancel()
+{
+       session_.cancel();
+}
+
 }  // namespace dialogs
 }  // namespace pv