]> sigrok.org Git - pulseview.git/blob - samplingbar.cpp
43b6e5e9eeb1b2f01101d99a1dcba399b298cecb
[pulseview.git] / samplingbar.cpp
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 extern "C" {
22 #include <libsigrok/libsigrok.h>
23 }
24
25 #include "samplingbar.h"
26
27 SamplingBar::SamplingBar(QWidget *parent) :
28         QToolBar("Sampling Bar", parent),
29         _device_selector(this)
30 {
31         addWidget(&_device_selector);
32
33         update_device_selector();
34 }
35
36 struct sr_dev_inst* SamplingBar::get_selected_device() const
37 {
38         const int index = _device_selector.currentIndex();
39         if(index < 0)
40                 return NULL;
41
42         return (sr_dev_inst*)_device_selector.itemData(
43                 index).value<void*>();
44 }
45
46 void SamplingBar::update_device_selector()
47 {
48         GSList *devices = NULL;
49
50         /* Scan all drivers for all devices. */
51         struct sr_dev_driver **const drivers = sr_driver_list();
52         for (struct sr_dev_driver **driver = drivers; *driver; driver++) {
53                 GSList *tmpdevs = sr_driver_scan(*driver, NULL);
54                 for (GSList *l = tmpdevs; l; l = l->next)
55                         devices = g_slist_append(devices, l->data);
56                 g_slist_free(tmpdevs);
57         }
58
59         for (GSList *l = devices; l; l = l->next) {
60                 sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
61
62                 QString title;
63                 if (sdi->vendor && sdi->vendor[0])
64                         title += sdi->vendor + QString(" ");
65                 if (sdi->model && sdi->model[0])
66                         title += sdi->model + QString(" ");
67                 if (sdi->version && sdi->version[0])
68                         title += sdi->version + QString(" ");
69
70                 _device_selector.addItem(title, qVariantFromValue(
71                         (void*)sdi));
72         }
73
74         g_slist_free(devices);
75 }