]> sigrok.org Git - pulseview.git/commitdiff
Centralize session error notification
authorSoeren Apel <redacted>
Sat, 14 Apr 2018 17:35:20 +0000 (19:35 +0200)
committerSoeren Apel <redacted>
Sun, 15 Apr 2018 06:19:59 +0000 (08:19 +0200)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/session.cpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp
test/CMakeLists.txt

index 19caab32e2d8d63265758eee8b0bc0b28d2168ed..c08576caff7a7bb18beaf5af10d32c81df0322a9 100644 (file)
@@ -92,6 +92,18 @@ MainWindow::~MainWindow()
                remove_session(sessions_.front());
 }
 
+void MainWindow::show_session_error(const QString text, const QString info_text)
+{
+       qDebug().noquote() << "Notifying user of session error:" << info_text;
+
+       QMessageBox msg;
+       msg.setText(text);
+       msg.setInformativeText(info_text);
+       msg.setStandardButtons(QMessageBox::Ok);
+       msg.setIcon(QMessageBox::Warning);
+       msg.exec();
+}
+
 shared_ptr<views::ViewBase> MainWindow::get_active_view() const
 {
        // If there's only one view, use it...
@@ -561,25 +573,6 @@ bool MainWindow::restoreState(const QByteArray &state, int version)
        return false;
 }
 
-void MainWindow::session_error(const QString text, const QString info_text)
-{
-       qDebug().noquote() << "Notifying user of session error:" << info_text;
-
-       QMetaObject::invokeMethod(this, "show_session_error",
-               Qt::QueuedConnection, Q_ARG(QString, text),
-               Q_ARG(QString, info_text));
-}
-
-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_add_view(const QString &title, views::ViewType type,
        Session *session)
 {
@@ -641,7 +634,7 @@ void MainWindow::on_run_stop_clicked()
        switch (session->get_capture_state()) {
        case Session::Stopped:
                session->start_capture([&](QString message) {
-                       session_error("Capture failed", message); });
+                       show_session_error("Capture failed", message); });
                break;
        case Session::AwaitingTrigger:
        case Session::Running:
index 3cffb54b47ce85f36a49d5a2c85216714751d0ea..5f4609d90b42e3824d3116b1431cc05abcfc1ab3 100644 (file)
@@ -75,6 +75,8 @@ public:
 
        ~MainWindow();
 
+       static void show_session_error(const QString text, const QString info_text);
+
        shared_ptr<views::ViewBase> get_active_view() const;
 
        shared_ptr<views::ViewBase> add_view(const QString &title,
@@ -109,11 +111,7 @@ private:
 
        virtual bool restoreState(const QByteArray &state, int version = 0);
 
-       void session_error(const QString text, const QString info_text);
-
 private Q_SLOTS:
-       void show_session_error(const QString text, const QString info_text);
-
        void on_add_view(const QString &title, views::ViewType type,
                Session *session);
 
index cbf24e235acc274c478c79481bfc5b446c80939f..87e9b3a5e1060223d27a67f0a17cab94db6e9fcc 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 
 #include "devicemanager.hpp"
+#include "mainwindow.hpp"
 #include "session.hpp"
 
 #include "data/analog.hpp"
@@ -352,7 +353,7 @@ void Session::select_device(shared_ptr<devices::Device> device)
                else
                        set_default_device();
        } catch (const QString &e) {
-               main_bar_->session_error(tr("Failed to select device"), e);
+               MainWindow::show_session_error(tr("Failed to select device"), e);
        }
 }
 
@@ -400,7 +401,7 @@ void Session::set_device(shared_ptr<devices::Device> device)
                device_->open();
        } catch (const QString &e) {
                device_.reset();
-               main_bar_->session_error(tr("Failed to open device"), e);
+               MainWindow::show_session_error(tr("Failed to open device"), e);
        }
 
        if (device_) {
@@ -490,7 +491,7 @@ void Session::load_init_file(const string &file_name, const string &format)
                        [&](const pair<string, shared_ptr<InputFormat> > f) {
                                return f.first == user_name; });
                if (iter == formats.end()) {
-                       main_bar_->session_error(tr("Error"),
+                       MainWindow::show_session_error(tr("Error"),
                                tr("Unexpected input format: %s").arg(QString::fromStdString(format)));
                        return;
                }
@@ -522,7 +523,7 @@ void Session::load_file(QString file_name,
                                        device_manager_.context(),
                                        file_name.toStdString())));
        } catch (Error& e) {
-               main_bar_->session_error(tr("Failed to load ") + file_name, e.what());
+               MainWindow::show_session_error(tr("Failed to load ") + file_name, e.what());
                set_default_device();
                main_bar_->update_device_list();
                return;
@@ -531,7 +532,7 @@ void Session::load_file(QString file_name,
        main_bar_->update_device_list();
 
        start_capture([&, errorMessage](QString infoMessage) {
-               main_bar_->session_error(errorMessage, infoMessage); });
+               MainWindow::show_session_error(errorMessage, infoMessage); });
 
        set_name(QFileInfo(file_name).fileName());
 }
index 1797e0a43e7de836b3695cfde24cf09647b6d150..3c8b71e2f7b59a8162fcf39f23135c2d819cd46b 100644 (file)
@@ -540,13 +540,6 @@ void MainBar::commit_sample_count()
        update_sample_rate_selector();
 }
 
-void MainBar::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 MainBar::show_session_error(const QString text, const QString info_text)
 {
        QMessageBox msg(this);
index 810cab27919f3cca59ed450710ec9701d1bb8e17..e938dbbc01d1dc4c877be7bb7e42b07a460fd5f1 100644 (file)
@@ -100,8 +100,6 @@ public:
        QAction* action_save_selection_as() const;
        QAction* action_connect() const;
 
-       void session_error(const QString text, const QString info_text);
-
 private:
        void run_stop();
 
index b787cc92c1d0078d45b49608cb22556a0d0bc000..b4d3458f52a24cb2e2042a28422348622a26c3bd 100644 (file)
@@ -21,6 +21,8 @@
 set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/devicemanager.cpp
        ${PROJECT_SOURCE_DIR}/pv/globalsettings.cpp
+       ${PROJECT_SOURCE_DIR}/pv/logging.cpp
+       ${PROJECT_SOURCE_DIR}/pv/mainwindow.cpp
        ${PROJECT_SOURCE_DIR}/pv/session.cpp
        ${PROJECT_SOURCE_DIR}/pv/storesession.cpp
        ${PROJECT_SOURCE_DIR}/pv/util.cpp
@@ -41,6 +43,7 @@ set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/devices/sessionfile.cpp
        ${PROJECT_SOURCE_DIR}/pv/dialogs/connect.cpp
        ${PROJECT_SOURCE_DIR}/pv/dialogs/inputoutputoptions.cpp
+       ${PROJECT_SOURCE_DIR}/pv/dialogs/settings.cpp
        ${PROJECT_SOURCE_DIR}/pv/dialogs/storeprogress.cpp
        ${PROJECT_SOURCE_DIR}/pv/prop/bool.cpp
        ${PROJECT_SOURCE_DIR}/pv/prop/double.cpp
@@ -97,7 +100,10 @@ set(pulseview_TEST_SOURCES
 
 # This list includes only QObject derived class headers.
 set(pulseview_TEST_HEADERS
+       ${PROJECT_SOURCE_DIR}/pv/devicemanager.hpp
        ${PROJECT_SOURCE_DIR}/pv/globalsettings.hpp
+       ${PROJECT_SOURCE_DIR}/pv/logging.hpp
+       ${PROJECT_SOURCE_DIR}/pv/mainwindow.hpp
        ${PROJECT_SOURCE_DIR}/pv/session.hpp
        ${PROJECT_SOURCE_DIR}/pv/storesession.hpp
        ${PROJECT_SOURCE_DIR}/pv/binding/device.hpp
@@ -109,6 +115,7 @@ set(pulseview_TEST_HEADERS
        ${PROJECT_SOURCE_DIR}/pv/devices/device.hpp
        ${PROJECT_SOURCE_DIR}/pv/dialogs/connect.hpp
        ${PROJECT_SOURCE_DIR}/pv/dialogs/inputoutputoptions.hpp
+       ${PROJECT_SOURCE_DIR}/pv/dialogs/settings.hpp
        ${PROJECT_SOURCE_DIR}/pv/dialogs/storeprogress.hpp
        ${PROJECT_SOURCE_DIR}/pv/popups/channels.hpp
        ${PROJECT_SOURCE_DIR}/pv/popups/deviceoptions.hpp