]> sigrok.org Git - pulseview.git/commitdiff
Added device selector combo box
authorJoel Holdsworth <redacted>
Wed, 27 Jun 2012 21:36:23 +0000 (22:36 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:05 +0000 (13:59 +0100)
main.cpp
samplingbar.cpp
samplingbar.h

index bb95f9ba4ef8e0e0ad9467ba6e8b0829b847e901..3d6b86e3651b3004c95d87c8d7d0c77c41024613 100644 (file)
--- 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();
index 8159a69a4a67c0b17f09d869f6d80608dac3da2f..43b6e5e9eeb1b2f01101d99a1dcba399b298cecb 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+extern "C" {
+#include <libsigrok/libsigrok.h>
+}
+
 #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*>();
+}
+
+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);
 }
index ca6a09216f8ba83ad086fb8af2960d3765477f7c..99957f977b4ca5062bde5201c8e3d394d1d1ed90 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef SAMPLINGBAR_H
 #define SAMPLINGBAR_H
 
+#include <QComboBox>
 #include <QToolBar>
 
 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