]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Handle device selection failure
authorJoel Holdsworth <redacted>
Sat, 22 Nov 2014 16:25:19 +0000 (16:25 +0000)
committerJoel Holdsworth <redacted>
Sat, 22 Nov 2014 17:15:34 +0000 (17:15 +0000)
This fixes bug #455

pv/mainwindow.cpp
pv/mainwindow.hpp
pv/sigsession.cpp
pv/toolbars/samplingbar.cpp

index f9aa81dfdc4e7bc2e4e843543091709821d96a0a..cc0e0d25cdf550538df677ddf762aac93804cf1c 100644 (file)
@@ -110,6 +110,20 @@ void MainWindow::run_stop()
        }
 }
 
+void MainWindow::select_device(shared_ptr<Device> 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();
 }
index c7859d0a4cb43ec9f7256d8fcdaf5153c4e931a6..8a67c615ca0718ec16e37f8cab203bc087edab5b 100644 (file)
@@ -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<sigrok::Device> device);
+
 private:
        void setup_ui();
 
index 87ba9afa5d484eace490524d5d9247a0ab5061ef..84c75896d42d01f60ee8e0cd1ef2e04b2d28d9f4 100644 (file)
@@ -137,22 +137,30 @@ void Session::set_device(shared_ptr<Device> 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> device, shared_ptr<Packet> packet) {
                                data_feed_in(device, packet);
                        });
                update_signals(device);
-       }
+       } else
+               device_ = nullptr;
 
        device_selected();
 }
index cddfa5f5d39f8d9a8b327038757e690d598d877e..b5a2aee513c7a12026b94e7bd3720894fd9e735e 100644 (file)
@@ -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();
 }