X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=samplingbar.cpp;h=43b6e5e9eeb1b2f01101d99a1dcba399b298cecb;hp=8159a69a4a67c0b17f09d869f6d80608dac3da2f;hb=6fb67b27a85f19002d43b8c8498ca7d2979401b0;hpb=d4984fe7119c2fc9bf94b13cc38cc735887e377d;ds=inline diff --git a/samplingbar.cpp b/samplingbar.cpp index 8159a69a..43b6e5e9 100644 --- a/samplingbar.cpp +++ b/samplingbar.cpp @@ -18,9 +18,58 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +extern "C" { +#include +} + #include "samplingbar.h" SamplingBar::SamplingBar(QWidget *parent) : - QToolBar("Sampling Bar", parent) + QToolBar("Sampling Bar", parent), + _device_selector(this) +{ + addWidget(&_device_selector); + + update_device_selector(); +} + +struct sr_dev_inst* SamplingBar::get_selected_device() const { + const int index = _device_selector.currentIndex(); + if(index < 0) + return NULL; + + return (sr_dev_inst*)_device_selector.itemData( + index).value(); +} + +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); }