From: Soeren Apel Date: Sat, 14 Apr 2018 17:35:20 +0000 (+0200) Subject: Centralize session error notification X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5e685656d6686eb66a39450d1b324f6382fc60c5;p=pulseview.git Centralize session error notification --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 19caab32..c08576ca 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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 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: diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 3cffb54b..5f4609d9 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -75,6 +75,8 @@ public: ~MainWindow(); + static void show_session_error(const QString text, const QString info_text); + shared_ptr get_active_view() const; shared_ptr 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); diff --git a/pv/session.cpp b/pv/session.cpp index cbf24e23..87e9b3a5 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -28,6 +28,7 @@ #include #include "devicemanager.hpp" +#include "mainwindow.hpp" #include "session.hpp" #include "data/analog.hpp" @@ -352,7 +353,7 @@ void Session::select_device(shared_ptr 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 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 > 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()); } diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 1797e0a4..3c8b71e2 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -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); diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index 810cab27..e938dbbc 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -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(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b787cc92..b4d3458f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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