]> sigrok.org Git - pulseview.git/commitdiff
Added UI error handling for file loading and capturing
authorJoel Holdsworth <redacted>
Mon, 11 Mar 2013 23:24:42 +0000 (23:24 +0000)
committerJoel Holdsworth <redacted>
Mon, 11 Mar 2013 23:24:42 +0000 (23:24 +0000)
pv/mainwindow.cpp
pv/mainwindow.h
pv/sigsession.cpp
pv/sigsession.h

index da01858748a74704888a9d851b8fb270b0c9d5df..90ac324bab1ed7bbffde9fe7c8a8d1d5cd7243d0 100644 (file)
 
 #include <sigrokdecode.h>
 
+#include <boost/bind.hpp>
+
 #include <QAction>
 #include <QApplication>
 #include <QButtonGroup>
 #include <QFileDialog>
+#include <QMessageBox>
 #include <QMenu>
 #include <QMenuBar>
 #include <QStatusBar>
@@ -210,9 +213,33 @@ void MainWindow::scan_devices()
        _sampling_bar->set_device_list(_devices);
 }
 
+void MainWindow::session_error(
+       const QString text, const QString info_text)
+{
+       QMetaObject::invokeMethod(this, "show_session_error",
+               Qt::QueuedConnection, Q_ARG(QString, text),
+               Q_ARG(QString, info_text));
+}
+
 void MainWindow::load_file(QString file_name)
 {
-       _session.load_file(file_name.toStdString());
+       const QString errorMessage(
+               QString("Failed to load file %1").arg(file_name));
+       const QString infoMessage;
+       _session.load_file(file_name.toStdString(),
+               boost::bind(&MainWindow::session_error, this,
+                       errorMessage, infoMessage));
+}
+
+void MainWindow::show_session_error(
+       const QString text, const QString info_text)
+{
+       QMessageBox msg(this);
+       msg.setText(text);
+       msg.setInformativeText(info_text);
+       msg.setStandardButtons(QMessageBox::Ok);
+       msg.setIcon(QMessageBox::Warning);
+       msg.exec();
 }
 
 void MainWindow::on_actionOpen_triggered()
@@ -272,7 +299,9 @@ void MainWindow::run_stop()
        case SigSession::Stopped:
                _session.start_capture(
                        _sampling_bar->get_selected_device(),
-                       _sampling_bar->get_record_length());
+                       _sampling_bar->get_record_length(),
+                       boost::bind(&MainWindow::session_error, this,
+                               QString("Capture failed"), _1));
                break;
 
        case SigSession::Running:
index ac48852e4949e452c86e64d13051d4ff128f44e2..8b7973744a881a19f421d91c1046394d3c6938f8 100644 (file)
@@ -55,6 +55,8 @@ private:
        void setup_ui();
        void scan_devices();
 
+       void session_error(const QString text, const QString info_text);
+
 private:
 
        SigSession _session;
@@ -85,6 +87,10 @@ private:
 private slots:
        void load_file(QString file_name);
 
+
+       void show_session_error(
+               const QString text, const QString info_text);
+
        void on_actionOpen_triggered();
        void on_actionQuit_triggered();
 
index b2670b6fbfcc908089ae7cc5b52704773ac33db3..8ab7dab845708a1cc1c818e549096a1807b647b3 100644 (file)
@@ -27,8 +27,6 @@
 #include "view/analogsignal.h"
 #include "view/logicsignal.h"
 
-#include <QDebug>
-
 #include <assert.h>
 
 using namespace boost;
@@ -58,11 +56,13 @@ SigSession::~SigSession()
        _session = NULL;
 }
 
-void SigSession::load_file(const string &name)
+void SigSession::load_file(const string &name,
+       function<void (const QString)> error_handler)
 {
        stop_capture();
        _sampling_thread.reset(new boost::thread(
-               &SigSession::load_thread_proc, this, name));
+               &SigSession::load_thread_proc, this, name,
+               error_handler));
 }
 
 SigSession::capture_state SigSession::get_capture_state() const
@@ -72,13 +72,14 @@ SigSession::capture_state SigSession::get_capture_state() const
 }
 
 void SigSession::start_capture(struct sr_dev_inst *sdi,
-       uint64_t record_length)
+       uint64_t record_length,
+       function<void (const QString)> error_handler)
 {
        stop_capture();
 
        _sampling_thread.reset(new boost::thread(
                &SigSession::sample_thread_proc, this, sdi,
-               record_length));
+               record_length, error_handler));
 }
 
 void SigSession::stop_capture()
@@ -112,17 +113,18 @@ void SigSession::set_capture_state(capture_state state)
        capture_state_changed(state);
 }
 
-void SigSession::load_thread_proc(const string name)
+void SigSession::load_thread_proc(const string name,
+       function<void (const QString)> error_handler)
 {
        if (sr_session_load(name.c_str()) != SR_OK) {
-               qDebug() << "Failed to load file.";
+               error_handler(tr("Failed to load file."));
                return;
        }
 
        sr_session_datafeed_callback_add(data_feed_in_proc);
 
        if (sr_session_start() != SR_OK) {
-               qDebug() << "Failed to start session.";
+               error_handler(tr("Failed to start session."));
                return;
        }
 
@@ -135,15 +137,17 @@ void SigSession::load_thread_proc(const string name)
 }
 
 void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
-       uint64_t record_length)
+       uint64_t record_length,
+       function<void (const QString)> error_handler)
 {
        assert(sdi);
+       assert(error_handler);
 
        sr_session_new();
        sr_session_datafeed_callback_add(data_feed_in_proc);
 
        if (sr_session_dev_add(sdi) != SR_OK) {
-               qDebug() << "Failed to use device.";
+               error_handler(tr("Failed to use device."));
                sr_session_destroy();
                return;
        }
@@ -151,13 +155,14 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
        // Set the sample limit
        if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES,
                &record_length) != SR_OK) {
-               qDebug() << "Failed to configure time-based sample limit.";
+               error_handler(tr("Failed to configure "
+                       "time-based sample limit."));
                sr_session_destroy();
                return;
        }
 
        if (sr_session_start() != SR_OK) {
-               qDebug() << "Failed to start session.";
+               error_handler(tr("Failed to start session."));
                return;
        }
 
index 7805eec65085ee24d7d2f8917eb09f0eca774172..b2dc467612655e59e1e189f78e813832f9b6bac4 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef PULSEVIEW_PV_SIGSESSION_H
 #define PULSEVIEW_PV_SIGSESSION_H
 
+#include <boost/function.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/thread.hpp>
 
@@ -29,6 +30,7 @@
 #include <vector>
 
 #include <QObject>
+#include <QString>
 
 #include <libsigrok/libsigrok.h>
 
@@ -60,12 +62,14 @@ public:
 
        ~SigSession();
 
-       void load_file(const std::string &name);
+       void load_file(const std::string &name,
+               boost::function<void (const QString)> error_handler);
 
        capture_state get_capture_state() const;
 
        void start_capture(struct sr_dev_inst* sdi,
-               uint64_t record_length);
+               uint64_t record_length,
+               boost::function<void (const QString)> error_handler);
 
        void stop_capture();
 
@@ -78,10 +82,12 @@ private:
        void set_capture_state(capture_state state);
 
 private:
-       void load_thread_proc(const std::string name);
+       void load_thread_proc(const std::string name,
+               boost::function<void (const QString)> error_handler);
 
        void sample_thread_proc(struct sr_dev_inst *sdi,
-               uint64_t record_length);
+               uint64_t record_length,
+               boost::function<void (const QString)> error_handler);
 
        void feed_in_header(const sr_dev_inst *sdi);