From: Joel Holdsworth Date: Thu, 7 Mar 2013 22:39:55 +0000 (+0000) Subject: Moved device enumeration out of pv::SamplingBar into pv::MainWindow X-Git-Tag: pulseview-0.1.0~98 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=18203d86e200131f50e9830c4f16a9edba96d669 Moved device enumeration out of pv::SamplingBar into pv::MainWindow --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 82087ee0..c9fa4c1a 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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()); diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 993c6084..ac48852e 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -21,6 +21,8 @@ #ifndef PULSEVIEW_PV_MAINWINDOW_H #define PULSEVIEW_PV_MAINWINDOW_H +#include + #include #include "sigsession.h" @@ -51,10 +53,13 @@ public: private: void setup_ui(); + void scan_devices(); private: SigSession _session; + std::list _devices; + pv::view::View *_view; QMenuBar *_menu_bar; diff --git a/pv/samplingbar.cpp b/pv/samplingbar.cpp index d3b23c0f..4ea2686b 100644 --- a/pv/samplingbar.cpp +++ b/pv/samplingbar.cpp @@ -22,6 +22,8 @@ #include +#include + #include #include @@ -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 &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(); diff --git a/pv/samplingbar.h b/pv/samplingbar.h index ade457e5..8d646c5d 100644 --- a/pv/samplingbar.h +++ b/pv/samplingbar.h @@ -23,11 +23,14 @@ #include +#include + #include #include #include #include +struct st_dev_inst; class QAction; namespace pv { @@ -43,7 +46,10 @@ private: public: SamplingBar(QWidget *parent); + void set_device_list(const std::list &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();