]> sigrok.org Git - pulseview.git/blame - pv/dialogs/connect.cpp
Initial manual connect dialog with a serial port selector
[pulseview.git] / pv / dialogs / connect.cpp
CommitLineData
9663c82b
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012-2013 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#include "connect.h"
22
23extern "C" {
24/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
25#define __STDC_FORMAT_MACROS
26#include <glib.h>
27#include <libsigrok/libsigrok.h>
28}
29
30namespace pv {
31namespace dialogs {
32
33Connect::Connect(QWidget *parent) :
34 QDialog(parent),
35 _layout(this),
36 _form(this),
37 _form_layout(&_form),
38 _drivers(&_form),
39 _serial_device(&_form),
40 _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
41 Qt::Horizontal, this)
42{
43 setWindowTitle(tr("Connect to Device"));
44
45 connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
46 connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
47
48 populate_drivers();
49 connect(&_drivers, SIGNAL(activated(int)),
50 this, SLOT(device_selected(int)));
51
52 _form.setLayout(&_form_layout);
53 _form_layout.addRow(tr("Driver"), &_drivers);
54
55 _form_layout.addRow(tr("Serial Port"), &_serial_device);
56
57 unset_connection();
58
59 setLayout(&_layout);
60 _layout.addWidget(&_form);
61 _layout.addWidget(&_button_box);
62}
63
64void Connect::populate_drivers()
65{
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]));
71}
72
73void Connect::device_selected(int index)
74{
75 const int *hwopts;
76 const struct sr_hwcap_option *hwo;
77 sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData(
78 index).value<void*>();
79
80 unset_connection();
81
82 if ((sr_config_list(driver, SR_CONF_SCAN_OPTIONS,
83 (const void **)&hwopts, NULL) == SR_OK) && hwopts) {
84
85 for (int i = 0; hwopts[i]; i++) {
86 switch(hwopts[i]) {
87 case SR_CONF_SERIALCOMM:
88 set_serial_connection();
89 break;
90
91 default:
92 continue;
93 }
94
95 break;
96 }
97 }
98}
99
100void Connect::unset_connection()
101{
102 _serial_device.hide();
103 _form_layout.labelForField(&_serial_device)->hide();
104}
105
106void Connect::set_serial_connection()
107{
108 _serial_device.show();
109 _form_layout.labelForField(&_serial_device)->show();
110}
111
112
113} // namespace dialogs
114} // namespace pv