X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fdialogs%2Fconnect.cpp;h=d238d681097bc5fcfd87c2351e87949f09dc16de;hb=5fbf231e831ed4ff39599c4336f60eaa2f568442;hp=af01b6cf6e47e6f07ae251b5104d90d7d3e6b599;hpb=26f209b713171014a4f6dc3546b64bf691727cfd;p=pulseview.git
diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp
index af01b6cf..d238d681 100644
--- a/pv/dialogs/connect.cpp
+++ b/pv/dialogs/connect.cpp
@@ -14,15 +14,16 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
#include
#include
+#include
#include
+#include
#include "connect.hpp"
@@ -40,7 +41,6 @@ using Glib::VariantBase;
using sigrok::ConfigKey;
using sigrok::Driver;
-using sigrok::Error;
using pv::devices::HardwareDevice;
@@ -49,10 +49,6 @@ namespace dialogs {
Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
QDialog(parent),
- tcp_endpoint_(&form_),
- tcp_endpoint_layout_(&tcp_endpoint_),
- tcp_host_(&tcp_endpoint_),
- tcp_port_(&tcp_endpoint_),
device_manager_(device_manager),
layout_(this),
form_(this),
@@ -70,33 +66,96 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
connect(&button_box_, SIGNAL(rejected()), this, SLOT(reject()));
populate_drivers();
- connect(&drivers_, SIGNAL(activated(int)),
- this, SLOT(device_selected(int)));
+ connect(&drivers_, SIGNAL(activated(int)), this, SLOT(driver_selected(int)));
form_.setLayout(&form_layout_);
- form_layout_.addRow(tr("&Driver"), &drivers_);
- form_layout_.addRow(tr("Serial &Port"), &serial_devices_);
- serial_devices_.setEditable(true);
+ QVBoxLayout *vbox_drv = new QVBoxLayout;
+ vbox_drv->addWidget(&drivers_);
+ QGroupBox *groupbox_drv = new QGroupBox(tr("Step 1: Choose the driver"));
+ groupbox_drv->setLayout(vbox_drv);
+ form_layout_.addRow(groupbox_drv);
+
+ QRadioButton *radiobtn_usb = new QRadioButton(tr("&USB"), this);
+ QRadioButton *radiobtn_serial = new QRadioButton(tr("Serial &Port"), this);
+ QRadioButton *radiobtn_tcp = new QRadioButton(tr("&TCP/IP"), this);
- tcp_host_.setPlaceholderText("192.168.1.100");
- tcp_endpoint_layout_.addWidget(&tcp_host_);
- tcp_endpoint_layout_.addWidget(new QLabel(":"));
- tcp_port_.setRange(1, 65535);
- tcp_port_.setValue(5555);
- tcp_endpoint_layout_.addWidget(&tcp_port_);
- tcp_endpoint_layout_.setContentsMargins(0, 0, 0, 0);
- form_layout_.addRow(tr("TCP &Endpoint"), &tcp_endpoint_);
+ radiobtn_usb->setChecked(true);
+
+ serial_config_ = new QWidget();
+ QHBoxLayout *serial_config_layout = new QHBoxLayout(serial_config_);
+
+ serial_devices_.setEditable(true);
+ serial_devices_.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+ serial_baudrate_.setEditable(true);
+ serial_baudrate_.addItem("");
+ serial_baudrate_.addItem("921600");
+ serial_baudrate_.addItem("115200");
+ serial_baudrate_.addItem("57600");
+ serial_baudrate_.addItem("19200");
+ serial_baudrate_.addItem("9600");
+
+ serial_config_layout->addWidget(&serial_devices_);
+ serial_config_layout->addWidget(&serial_baudrate_);
+ serial_config_layout->addWidget(new QLabel("baud"));
+ serial_config_->setEnabled(false);
+
+ tcp_config_ = new QWidget();
+ QHBoxLayout *tcp_config_layout = new QHBoxLayout(tcp_config_);
+ tcp_host_ = new QLineEdit;
+ tcp_host_->setText("192.168.1.100");
+ tcp_config_layout->addWidget(tcp_host_);
+ tcp_config_layout->addWidget(new QLabel(":"));
+ tcp_port_ = new QSpinBox;
+ tcp_port_->setRange(1, 65535);
+ tcp_port_->setValue(5555);
+ tcp_config_layout->addWidget(tcp_port_);
+
+ tcp_config_layout->addSpacing(30);
+ tcp_config_layout->addWidget(new QLabel(tr("Protocol:")));
+ tcp_protocol_ = new QComboBox();
+ tcp_protocol_->addItem("Raw TCP", QVariant("tcp-raw/%1/%2"));
+ tcp_protocol_->addItem("VXI", QVariant("vxi/%1/%2"));
+ tcp_config_layout->addWidget(tcp_protocol_);
+ tcp_config_layout->setContentsMargins(0, 0, 0, 0);
+ tcp_config_->setEnabled(false);
+
+ // Let the device list occupy only the minimum space needed
+ device_list_.setMaximumHeight(device_list_.minimumSizeHint().height());
+
+ QVBoxLayout *vbox_if = new QVBoxLayout;
+ vbox_if->addWidget(radiobtn_usb);
+ vbox_if->addWidget(radiobtn_serial);
+ vbox_if->addWidget(serial_config_);
+ vbox_if->addWidget(radiobtn_tcp);
+ vbox_if->addWidget(tcp_config_);
+
+ QGroupBox *groupbox_if = new QGroupBox(tr("Step 2: Choose the interface"));
+ groupbox_if->setLayout(vbox_if);
+ form_layout_.addRow(groupbox_if);
+
+ QVBoxLayout *vbox_scan = new QVBoxLayout;
+ vbox_scan->addWidget(&scan_button_);
+ QGroupBox *groupbox_scan = new QGroupBox(tr("Step 3: Scan for devices"));
+ groupbox_scan->setLayout(vbox_scan);
+ form_layout_.addRow(groupbox_scan);
+
+ QVBoxLayout *vbox_select = new QVBoxLayout;
+ vbox_select->addWidget(&device_list_);
+ QGroupBox *groupbox_select = new QGroupBox(tr("Step 4: Select the device"));
+ groupbox_select->setLayout(vbox_select);
+ form_layout_.addRow(groupbox_select);
unset_connection();
- connect(&scan_button_, SIGNAL(pressed()),
- this, SLOT(scan_pressed()));
+ connect(radiobtn_serial, SIGNAL(toggled(bool)), this, SLOT(serial_toggled(bool)));
+ connect(radiobtn_tcp, SIGNAL(toggled(bool)), this, SLOT(tcp_toggled(bool)));
+ connect(&scan_button_, SIGNAL(pressed()), this, SLOT(scan_pressed()));
setLayout(&layout_);
+
layout_.addWidget(&form_);
- layout_.addWidget(&scan_button_);
- layout_.addWidget(&device_list_);
layout_.addWidget(&button_box_);
}
@@ -111,7 +170,7 @@ shared_ptr Connect::get_selected_device() const
void Connect::populate_drivers()
{
- for (auto entry : device_manager_.context()->drivers()) {
+ for (auto& entry : device_manager_.context()->drivers()) {
auto name = entry.first;
auto driver = entry.second;
/**
@@ -136,7 +195,7 @@ void Connect::populate_drivers()
void Connect::populate_serials(shared_ptr driver)
{
serial_devices_.clear();
- for (auto serial : device_manager_.context()->serials(driver))
+ for (auto& serial : device_manager_.context()->serials(driver))
serial_devices_.addItem(QString("%1 (%2)").arg(
serial.first.c_str(), serial.second.c_str()),
QString::fromStdString(serial.first));
@@ -145,26 +204,19 @@ void Connect::populate_serials(shared_ptr driver)
void Connect::unset_connection()
{
device_list_.clear();
- serial_devices_.hide();
- form_layout_.labelForField(&serial_devices_)->hide();
- tcp_endpoint_.hide();
- form_layout_.labelForField(&tcp_endpoint_)->hide();
button_box_.button(QDialogButtonBox::Ok)->setDisabled(true);
}
-void Connect::set_serial_connection(shared_ptr driver)
+void Connect::serial_toggled(bool checked)
{
- populate_serials(driver);
- serial_devices_.show();
- form_layout_.labelForField(&serial_devices_)->show();
+ serial_devices_.setEnabled(checked);
+ serial_baudrate_.setEnabled(checked);
+ serial_config_->setEnabled(checked);
}
-void Connect::set_tcp_connection(shared_ptr driver)
+void Connect::tcp_toggled(bool checked)
{
- (void)driver;
-
- tcp_endpoint_.show();
- form_layout_.labelForField(&tcp_endpoint_)->show();
+ tcp_config_->setEnabled(checked);
}
void Connect::scan_pressed()
@@ -182,23 +234,33 @@ void Connect::scan_pressed()
map drvopts;
- if (serial_devices_.isVisible()) {
+ if (serial_config_->isEnabled()) {
QString serial;
const int index = serial_devices_.currentIndex();
if (index >= 0 && index < serial_devices_.count() &&
serial_devices_.currentText() == serial_devices_.itemText(index))
- serial = serial_devices_.itemData(index).value();
+ serial = serial_devices_.itemData(index).toString();
else
serial = serial_devices_.currentText();
+
drvopts[ConfigKey::CONN] = Variant::create(
serial.toUtf8().constData());
+
+ // Set baud rate if specified
+ if (serial_baudrate_.currentText().length() > 0)
+ drvopts[ConfigKey::SERIALCOMM] = Variant::create(
+ QString("%1/8n1").arg(serial_baudrate_.currentText()).toUtf8().constData());
}
- if (tcp_endpoint_.isVisible()) {
- QString host = tcp_host_.text();
- QString port = tcp_port_.text();
- if(!host.isEmpty()) {
- QString conn = QString("tcp-raw/%1/%2").arg(host, port);
+ if (tcp_config_->isEnabled()) {
+ QString host = tcp_host_->text();
+ QString port = tcp_port_->text();
+ if (!host.isEmpty()) {
+ QString conn =
+ tcp_protocol_->itemData(tcp_protocol_->currentIndex()).toString();
+
+ conn = conn.arg(host, port);
+
drvopts[ConfigKey::CONN] = Variant::create(
conn.toUtf8().constData());
}
@@ -207,16 +269,13 @@ void Connect::scan_pressed()
const list< shared_ptr > devices =
device_manager_.driver_scan(driver, drvopts);
- for (shared_ptr device : devices) {
+ for (const shared_ptr& device : devices) {
assert(device);
- QString text = QString::fromStdString(
- device->display_name(device_manager_));
- text += QString(" with %1 channels").arg(
- device->device()->channels().size());
+ QString text = QString::fromStdString(device->display_name(device_manager_));
+ text += QString(" with %1 channels").arg(device->device()->channels().size());
- QListWidgetItem *const item = new QListWidgetItem(text,
- &device_list_);
+ QListWidgetItem *const item = new QListWidgetItem(text, &device_list_);
item->setData(Qt::UserRole, qVariantFromValue(device));
device_list_.addItem(item);
}
@@ -225,18 +284,14 @@ void Connect::scan_pressed()
button_box_.button(QDialogButtonBox::Ok)->setDisabled(device_list_.count() == 0);
}
-void Connect::device_selected(int index)
+void Connect::driver_selected(int index)
{
shared_ptr driver =
drivers_.itemData(index).value>();
unset_connection();
- if (driver->scan_options().count(ConfigKey::SERIALCOMM))
- set_serial_connection(driver);
-
- if (driver->name() == "rigol-ds") // NBNB
- set_tcp_connection(driver);
+ populate_serials(driver);
}
} // namespace dialogs