From: Joel Holdsworth Date: Sat, 22 Nov 2014 16:25:19 +0000 (+0000) Subject: MainWindow: Handle device selection failure X-Git-Tag: pulseview-0.3.0~430 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=51cf49fe312f92cccde3e861d357e4b459976c0d;p=pulseview.git MainWindow: Handle device selection failure This fixes bug #455 --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index f9aa81df..cc0e0d25 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -110,6 +110,20 @@ void MainWindow::run_stop() } } +void MainWindow::select_device(shared_ptr device) +{ + try { + session_.set_device(device); + } catch(const QString &e) { + QMessageBox msg(this); + msg.setText(e); + msg.setInformativeText(tr("Failed to Select Device")); + msg.setStandardButtons(QMessageBox::Ok); + msg.setIcon(QMessageBox::Warning); + msg.exec(); + } +} + void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); @@ -364,7 +378,7 @@ void MainWindow::restore_ui_settings() device = device_manager_.find_device_from_info(dev_info); if (device) { - session_.set_device(device); + select_device(device); update_device_list(); } @@ -497,7 +511,7 @@ void MainWindow::on_actionConnect_triggered() // If the user selected a device, select it in the device list. Select the // current device otherwise. if (dlg.exec()) - session_.set_device(dlg.get_selected_device()); + select_device(dlg.get_selected_device()); update_device_list(); } diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index c7859d0a..8a67c615 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -32,6 +32,10 @@ struct srd_decoder; class QVBoxLayout; +namespace sigrok { +class Device; +} + namespace pv { class DeviceManager; @@ -60,6 +64,8 @@ public: void run_stop(); + void select_device(std::shared_ptr device); + private: void setup_ui(); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 87ba9afa..84c75896 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -137,22 +137,30 @@ void Session::set_device(shared_ptr device) if (session_device) session_ = session_device->parent(); - device_ = device; decode_traces_.clear(); if (device) { if (!session_device) { session_ = device_manager_.context()->create_session(); - device->open(); + + try { + device->open(); + } catch(const sigrok::Error &e) { + throw QString(e.what()); + } + session_->add_device(device); } + + device_ = device; session_->add_datafeed_callback([=] (shared_ptr device, shared_ptr packet) { data_feed_in(device, packet); }); update_signals(device); - } + } else + device_ = nullptr; device_selected(); } diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index cddfa5f5..b5a2aee5 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -432,7 +432,7 @@ void SamplingBar::on_device_selected() if (!device) return; - session_.set_device(device); + main_window_.select_device(device); update_device_config_widgets(); }