]> sigrok.org Git - pulseview.git/blobdiff - pv/mainwindow.cpp
Snapshot: Renamed to Segment
[pulseview.git] / pv / mainwindow.cpp
index 142eb3f1c08960a8db7be4cbfe964574c5aa8d1c..cc0e0d25cdf550538df677ddf762aac93804cf1c 100644 (file)
@@ -95,6 +95,35 @@ MainWindow::MainWindow(DeviceManager &device_manager,
        }
 }
 
+void MainWindow::run_stop()
+{
+       switch(session_.get_capture_state()) {
+       case Session::Stopped:
+               session_.start_capture([&](QString message) {
+                       session_error("Capture failed", message); });
+               break;
+
+       case Session::AwaitingTrigger:
+       case Session::Running:
+               session_.stop_capture();
+               break;
+       }
+}
+
+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"));
@@ -255,13 +284,11 @@ void MainWindow::setup_ui()
        addToolBar(toolbar);
 
        // Setup the sampling bar
-       sampling_bar_ = new toolbars::SamplingBar(session_, this);
+       sampling_bar_ = new toolbars::SamplingBar(session_, *this);
 
        // Populate the device list and select the initially selected device
        update_device_list();
 
-       connect(sampling_bar_, SIGNAL(run_stop()), this,
-               SLOT(run_stop()));
        addToolBar(sampling_bar_);
 
        // Set the title
@@ -351,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();
        }
 
@@ -484,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();
 }
@@ -541,24 +568,9 @@ void MainWindow::add_decoder(srd_decoder *decoder)
 #endif
 }
 
-void MainWindow::run_stop()
-{
-       switch(session_.get_capture_state()) {
-       case SigSession::Stopped:
-               session_.start_capture([&](QString message) {
-                       session_error("Capture failed", message); });
-               break;
-
-       case SigSession::AwaitingTrigger:
-       case SigSession::Running:
-               session_.stop_capture();
-               break;
-       }
-}
-
 void MainWindow::capture_state_changed(int state)
 {
-       sampling_bar_->set_capture_state((pv::SigSession::capture_state)state);
+       sampling_bar_->set_capture_state((pv::Session::capture_state)state);
 }
 
 void MainWindow::device_selected()