]> sigrok.org Git - pulseview.git/commitdiff
Moved device enumeration out of pv::SamplingBar into pv::MainWindow
authorJoel Holdsworth <redacted>
Thu, 7 Mar 2013 22:39:55 +0000 (22:39 +0000)
committerUwe Hermann <redacted>
Sat, 9 Mar 2013 10:43:03 +0000 (11:43 +0100)
pv/mainwindow.cpp
pv/mainwindow.h
pv/samplingbar.cpp
pv/samplingbar.h

index 82087ee080164f28cdfc9b3273ba2049d11dfe95..c9fa4c1a25fc749a9d47804ea369b8c9ff3e1ad1 100644 (file)
@@ -179,6 +179,7 @@ void MainWindow::setup_ui()
        addToolBar(_toolbar);
 
        _sampling_bar = new SamplingBar(this);
+       scan_devices();
        connect(_sampling_bar, SIGNAL(run_stop()), this,
                SLOT(run_stop()));
        addToolBar(_sampling_bar);
@@ -192,6 +193,23 @@ void MainWindow::setup_ui()
 
 }
 
+void MainWindow::scan_devices()
+{
+       _devices.clear();
+
+       /* Scan all drivers for all devices. */
+       struct sr_dev_driver **const drivers = sr_driver_list();
+       for (struct sr_dev_driver **driver = drivers; *driver; driver++) {
+               GSList *const devices = sr_driver_scan(*driver, NULL);
+               for (GSList *l = devices; l; l = l->next)
+                       _devices.push_back((sr_dev_inst*)l->data);
+               g_slist_free(devices);
+       }
+
+       assert(_sampling_bar);
+       _sampling_bar->set_device_list(_devices);
+}
+
 void MainWindow::load_file(QString file_name)
 {
        _session.load_file(file_name.toStdString());
index 993c608493a39a6b4a1b4a1f75486ee822985e57..ac48852e4949e452c86e64d13051d4ff128f44e2 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef PULSEVIEW_PV_MAINWINDOW_H
 #define PULSEVIEW_PV_MAINWINDOW_H
 
+#include <list>
+
 #include <QMainWindow>
 
 #include "sigsession.h"
@@ -51,10 +53,13 @@ public:
 
 private:
        void setup_ui();
+       void scan_devices();
 
 private:
 
        SigSession _session;
+       std::list<sr_dev_inst*> _devices;
+
        pv::view::View *_view;
 
        QMenuBar *_menu_bar;
index d3b23c0f21a7586c8acc7cd9d43c3aced74d68f0..4ea2686b4d2b522c2203dab01a00cfee86e4951b 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <assert.h>
 
+#include <boost/foreach.hpp>
+
 #include <libsigrok/libsigrok.h>
 
 #include <QAction>
@@ -104,15 +106,33 @@ SamplingBar::SamplingBar(QWidget *parent) :
        _sample_rate_value_action = addWidget(&_sample_rate_value);
        addWidget(&_run_stop_button);
 
-       update_device_selector();
-
-       update_sample_rate_selector();
        connect(&_sample_rate_list, SIGNAL(currentIndexChanged(int)),
                this, SLOT(on_sample_rate_changed()));
-       connect(&_sample_rate_value, SIGNAL(valueChanged(double)),
+       connect(&_sample_rate_value, SIGNAL(editingFinished()),
                this, SLOT(on_sample_rate_changed()));
 }
 
+void SamplingBar::set_device_list(
+       const std::list<struct sr_dev_inst*> &devices)
+{
+       _device_selector.clear();
+
+       BOOST_FOREACH (sr_dev_inst *sdi, devices) {
+               QString title;
+               if (sdi->vendor && sdi->vendor[0])
+                       title += sdi->vendor + QString(" ");
+               if (sdi->model && sdi->model[0])
+                       title += sdi->model + QString(" ");
+               if (sdi->version && sdi->version[0])
+                       title += sdi->version + QString(" ");
+
+               _device_selector.addItem(title, qVariantFromValue(
+                       (void*)sdi));
+       }
+
+       update_sample_rate_selector();
+}
+
 struct sr_dev_inst* SamplingBar::get_selected_device() const
 {
        const int index = _device_selector.currentIndex();
@@ -138,37 +158,6 @@ void SamplingBar::set_sampling(bool sampling)
        _run_stop_button.setText(sampling ? "Stop" : "Run");
 }
 
-void SamplingBar::update_device_selector()
-{
-       GSList *devices = NULL;
-
-       /* Scan all drivers for all devices. */
-       struct sr_dev_driver **const drivers = sr_driver_list();
-       for (struct sr_dev_driver **driver = drivers; *driver; driver++) {
-               GSList *tmpdevs = sr_driver_scan(*driver, NULL);
-               for (GSList *l = tmpdevs; l; l = l->next)
-                       devices = g_slist_append(devices, l->data);
-               g_slist_free(tmpdevs);
-       }
-
-       for (GSList *l = devices; l; l = l->next) {
-               sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
-
-               QString title;
-               if (sdi->vendor && sdi->vendor[0])
-                       title += sdi->vendor + QString(" ");
-               if (sdi->model && sdi->model[0])
-                       title += sdi->model + QString(" ");
-               if (sdi->version && sdi->version[0])
-                       title += sdi->version + QString(" ");
-
-               _device_selector.addItem(title, qVariantFromValue(
-                       (void*)sdi));
-       }
-
-       g_slist_free(devices);
-}
-
 void SamplingBar::update_sample_rate_selector()
 {
        const sr_dev_inst *const sdi = get_selected_device();
index ade457e5cc56db0a73f0004c63b57a13ff05754e..8d646c5d55b5104eddcccb2cfcf6d6a1a1d82d25 100644 (file)
 
 #include <stdint.h>
 
+#include <list>
+
 #include <QComboBox>
 #include <QDoubleSpinBox>
 #include <QToolBar>
 #include <QToolButton>
 
+struct st_dev_inst;
 class QAction;
 
 namespace pv {
@@ -43,7 +46,10 @@ private:
 public:
        SamplingBar(QWidget *parent);
 
+       void set_device_list(const std::list<struct sr_dev_inst*> &devices);
+
        struct sr_dev_inst* get_selected_device() const;
+
        uint64_t get_record_length() const;
 
        void set_sampling(bool sampling);
@@ -52,7 +58,6 @@ signals:
        void run_stop();
 
 private:
-       void update_device_selector();
        void update_sample_rate_selector();
        void update_sample_rate_selector_value();
        void commit_sample_rate();