From: Joel Holdsworth Date: Wed, 27 Jun 2012 21:36:23 +0000 (+0100) Subject: Added device selector combo box X-Git-Tag: pulseview-0.1.0~332 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6fb67b27a85f19002d43b8c8498ca7d2979401b0;p=pulseview.git Added device selector combo box --- diff --git a/main.cpp b/main.cpp index bb95f9ba..3d6b86e3 100644 --- a/main.cpp +++ b/main.cpp @@ -52,6 +52,16 @@ int main(int argc, char *argv[]) /* Load the protocol decoders */ srd_decoder_load_all(); + /* Initialize all libsigrok drivers. */ + sr_dev_driver **const drivers = sr_driver_list(); + for (sr_dev_driver **driver = drivers; *driver; driver++) { + if (sr_driver_init(*driver) != SR_OK) { + qDebug("Failed to initialize driver %s", + (*driver)->name); + return 1; + } + } + /* Initialise the main window */ MainWindow w; w.show(); 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); } diff --git a/samplingbar.h b/samplingbar.h index ca6a0921..99957f97 100644 --- a/samplingbar.h +++ b/samplingbar.h @@ -21,6 +21,7 @@ #ifndef SAMPLINGBAR_H #define SAMPLINGBAR_H +#include #include class SamplingBar : public QToolBar @@ -29,6 +30,14 @@ class SamplingBar : public QToolBar public: SamplingBar(QWidget *parent); + + struct sr_dev_inst* get_selected_device() const; + +private: + void update_device_selector(); + +private: + QComboBox _device_selector; }; #endif // SAMPLINGBAR_H