2 * This file is part of the PulseView project.
4 * Copyright (C) 2012-2013 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
24 /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
25 #define __STDC_FORMAT_MACROS
27 #include <libsigrok/libsigrok.h>
33 Connect::Connect(QWidget *parent) :
39 _serial_device(&_form),
40 _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
43 setWindowTitle(tr("Connect to Device"));
45 connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
46 connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
49 connect(&_drivers, SIGNAL(activated(int)),
50 this, SLOT(device_selected(int)));
52 _form.setLayout(&_form_layout);
53 _form_layout.addRow(tr("Driver"), &_drivers);
55 _form_layout.addRow(tr("Serial Port"), &_serial_device);
60 _layout.addWidget(&_form);
61 _layout.addWidget(&_button_box);
64 void Connect::populate_drivers()
66 struct sr_dev_driver **drivers = sr_driver_list();
67 for (int i = 0; drivers[i]; ++i)
68 _drivers.addItem(QString("%1 (%2)").arg(
69 drivers[i]->longname).arg(drivers[i]->name),
70 qVariantFromValue((void*)drivers[i]));
73 void Connect::device_selected(int index)
76 const struct sr_hwcap_option *hwo;
77 sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData(
78 index).value<void*>();
82 if ((sr_config_list(driver, SR_CONF_SCAN_OPTIONS,
83 (const void **)&hwopts, NULL) == SR_OK) && hwopts) {
85 for (int i = 0; hwopts[i]; i++) {
87 case SR_CONF_SERIALCOMM:
88 set_serial_connection();
100 void Connect::unset_connection()
102 _serial_device.hide();
103 _form_layout.labelForField(&_serial_device)->hide();
106 void Connect::set_serial_connection()
108 _serial_device.show();
109 _form_layout.labelForField(&_serial_device)->show();
113 } // namespace dialogs