]> sigrok.org Git - pulseview.git/blobdiff - pv/mainwindow.cpp
Moved session creation into DevInst objects
[pulseview.git] / pv / mainwindow.cpp
index e0ef3aa297e4f71e7f3678cc0bbd151ce27696ff..57e9c51f8d51b647e8ea6164d61834c1d832d11a 100644 (file)
@@ -25,6 +25,9 @@
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 
+#include <algorithm>
+#include <iterator>
+
 #include <QAction>
 #include <QApplication>
 #include <QButtonGroup>
@@ -39,6 +42,7 @@
 #include "mainwindow.h"
 
 #include "devicemanager.h"
+#include "device/device.h"
 #include "dialogs/about.h"
 #include "dialogs/connect.h"
 #include "dialogs/storeprogress.h"
@@ -57,6 +61,7 @@
 #include <glib.h>
 #include <libsigrok/libsigrok.h>
 
+using boost::shared_ptr;
 using std::list;
 
 namespace pv {
@@ -282,11 +287,15 @@ void MainWindow::session_error(
                Q_ARG(QString, info_text));
 }
 
-void MainWindow::update_device_list(struct sr_dev_inst *selected_device)
+void MainWindow::update_device_list(
+       shared_ptr<pv::device::DevInst> selected_device)
 {
        assert(_sampling_bar);
 
-       const list<sr_dev_inst*> &devices = _device_manager.devices();
+       list< shared_ptr<device::DevInst> > devices;
+       std::copy(_device_manager.devices().begin(),
+               _device_manager.devices().end(), std::back_inserter(devices));
+
        _sampling_bar->set_device_list(devices);
 
        if (!selected_device && !devices.empty()) {
@@ -294,15 +303,17 @@ void MainWindow::update_device_list(struct sr_dev_inst *selected_device)
                selected_device = devices.front();
 
                // Try and find the demo device and select that by default
-               BOOST_FOREACH (struct sr_dev_inst *sdi, devices)
-                       if (strcmp(sdi->driver->name, "demo") == 0) {
-                               selected_device = sdi;
+               BOOST_FOREACH (shared_ptr<pv::device::DevInst> dev_inst, devices)
+                       if (strcmp(dev_inst->dev_inst()->driver->name,
+                               "demo") == 0) {
+                               selected_device = dev_inst;
                        }
        }
 
        if (selected_device) {
+               // Setting the selected device in the sampling bar, generates
+               // an event which updates the selected device in the SigSession.
                _sampling_bar->set_selected_device(selected_device);
-               _session.set_device(selected_device);
        }
 }
 
@@ -311,9 +322,15 @@ void MainWindow::load_file(QString file_name)
        const QString errorMessage(
                QString("Failed to load file %1").arg(file_name));
        const QString infoMessage;
-       _session.load_file(file_name.toStdString(),
-               boost::bind(&MainWindow::session_error, this,
-                       errorMessage, infoMessage));
+
+       try {
+               _session.set_file(file_name.toStdString());
+       } catch(QString e) {
+               show_session_error(tr("Failed to load ") + file_name, e);
+       }
+
+       _session.start_capture(boost::bind(&MainWindow::session_error, this,
+               errorMessage, infoMessage));
 }
 
 void MainWindow::show_session_error(
@@ -365,10 +382,10 @@ void MainWindow::on_actionConnect_triggered()
 
        // If the user selected a device, select it in the device list. Select the
        // current device otherwise.
-       struct sr_dev_inst *const sdi = dlg.exec() ?
+       shared_ptr<device::DevInst> dev_inst = dlg.exec() ?
                dlg.get_selected_device() : _session.get_device();
 
-       update_device_list(sdi);
+       update_device_list(dev_inst);
 }
 
 void MainWindow::on_actionQuit_triggered()