Hi,

[PATCH] Improved usability for "Connect to Device" dialog in pulseview

This patch adds improved usability for "Connect to Device" dialog in pulseview:

* pv/mainwindow.cpp:
1) adds a shortcut key for "Connect to Device" menu entry in the File menu.
2) adds a "Connect to Device" (using the sigrok-logo) icon to the main toolbar.

* pv/dialogs/connect.cpp:
1) Adds shortcut keys for "Driver", "Serial Port" and "Scan for devices" GUI items 2) Adds a pseudo "autodetect" driver to the top of the driver list. This will present the user with an overview of autodetected devices (those that can be detected).

I hope that this patch is accepted - it makes my work with multiple devices in pulseview much easier.

Kind regards Uffe Jakobsen

>From aff4092779990addd236903d9d4adab3505cf52c Mon Sep 17 00:00:00 2001
From: Uffe Jakobsen <[email protected]>
Date: Sun, 28 Dec 2014 02:47:57 +0100
Subject: [PATCH] Improved usability for "Connect to Device" dialog in
 pulseview:

* pv/mainwindow.cpp:

1) adds a shortcut key for "Connect to Device" menu-entry in the File menu.
2) adds a "Connect to Device" sigrok-logo-icon to the pulseview main toolbar.

* pv/dialogs/connect.cpp:

1) Adds shortcut keys for "Driver", "Serial Port" and "Scan for devices" GUI items.
2) Adds a pseudo "autodetect" driver to the top of the driver list. This will present the user with an overview of autodetected devices (those that can be detected).
---
 pv/dialogs/connect.cpp | 84 +++++++++++++++++++++++++++++++++-----------------
 pv/mainwindow.cpp      |  5 +++
 2 files changed, 60 insertions(+), 29 deletions(-)

diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp
index f7b0fc7..e788d31 100644
--- a/pv/dialogs/connect.cpp
+++ b/pv/dialogs/connect.cpp
@@ -2,6 +2,7 @@
  * This file is part of the PulseView project.
  *
  * Copyright (C) 2012-2013 Joel Holdsworth <[email protected]>
+ * Copyright (C) 2014 Uffe Jakobsen <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -51,7 +52,7 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
 	form_layout_(&form_),
 	drivers_(&form_),
 	serial_device_(&form_),
-	scan_button_(tr("Scan for Devices"), this),
+	scan_button_(tr("&Scan for Devices"), this),
 	device_list_(this),
 	button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
 		Qt::Horizontal, this)
@@ -66,9 +67,9 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
 		this, SLOT(device_selected(int)));
 
 	form_.setLayout(&form_layout_);
-	form_layout_.addRow(tr("Driver"), &drivers_);
+	form_layout_.addRow(tr("&Driver"), &drivers_);
 
-	form_layout_.addRow(tr("Serial Port"), &serial_device_);
+	form_layout_.addRow(tr("Serial &Port"), &serial_device_);
 
 	unset_connection();
 
@@ -80,6 +81,8 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
 	layout_.addWidget(&scan_button_);
 	layout_.addWidget(&device_list_);
 	layout_.addWidget(&button_box_);
+
+	device_selected(0);
 }
 
 shared_ptr<HardwareDevice> Connect::get_selected_device() const
@@ -93,6 +96,8 @@ shared_ptr<HardwareDevice> Connect::get_selected_device() const
 
 void Connect::populate_drivers()
 {
+	drivers_.addItem(QString("Autodetected devices"), qVariantFromValue(NULL));
+
 	for (auto entry : device_manager_.context()->drivers()) {
 		auto name = entry.first;
 		auto driver = entry.second;
@@ -133,36 +138,52 @@ void Connect::scan_pressed()
 {
 	device_list_.clear();
 
-	const int index = drivers_.currentIndex();
-	if (index == -1)
+	const int index_cur = drivers_.currentIndex();
+	if (index_cur == -1)
 		return;
 
-	shared_ptr<Driver> driver =
-		drivers_.itemData(index).value<shared_ptr<Driver>>();
+	int index, index_max;
+	// Using pseudo autodetect driver (index 0): setup indexes for real driver scan
+	if (index_cur == 0) {
+		index = 1;
+		index_max = drivers_.count()-1;
+	} else {
+		index = index_max = index_cur;
+	}
+
+	for(; index <= index_max; index++) {
+
+		shared_ptr<Driver> driver =
+			drivers_.itemData(index).value<shared_ptr<Driver>>();
 
-	assert(driver);
+		assert(driver);
 
-	map<const ConfigKey *, VariantBase> drvopts;
+		map<const ConfigKey *, VariantBase> drvopts;
 
-	if (serial_device_.isVisible())
-		drvopts[ConfigKey::CONN] = Variant<ustring>::create(
-			serial_device_.text().toUtf8().constData());
+		if (serial_device_.isVisible())
+			drvopts[ConfigKey::CONN] = Variant<ustring>::create(
+				serial_device_.text().toUtf8().constData());
 
-	list< shared_ptr<HardwareDevice> > devices =
-		device_manager_.driver_scan(driver, drvopts);
+		list< shared_ptr<HardwareDevice> > devices =
+			device_manager_.driver_scan(driver, drvopts);
 
-	for (shared_ptr<HardwareDevice> device : devices)
-	{
-		assert(device);
+		for (shared_ptr<HardwareDevice> device : devices)
+		{
+			assert(device);
 
-		QString text = QString::fromStdString(
-			device_manager_.get_display_name(device));
-		text += QString(" with %1 channels").arg(device->channels().size());
+			QString text = QString::fromStdString(
+				device_manager_.get_display_name(device));
+			text += QString(" with %1 channels").arg(device->channels().size());
 
-		QListWidgetItem *const item = new QListWidgetItem(text,
-			&device_list_);
-		item->setData(Qt::UserRole, qVariantFromValue(device));
-		device_list_.addItem(item);
+			// If autodetecting - show originating driver short name
+			if (index_cur == 0)
+				text += QString(" (%1)").arg(driver->name().c_str());
+
+			QListWidgetItem *const item = new QListWidgetItem(text,
+				&device_list_);
+			item->setData(Qt::UserRole, qVariantFromValue(device));
+			device_list_.addItem(item);
+		}
 	}
 
 	device_list_.setCurrentRow(0);
@@ -171,13 +192,18 @@ void Connect::scan_pressed()
 
 void Connect::device_selected(int index)
 {
-	shared_ptr<Driver> driver =
-		drivers_.itemData(index).value<shared_ptr<Driver>>();
-
 	unset_connection();
 
-	if (driver->config_check(ConfigKey::SERIALCOMM, ConfigKey::SCAN_OPTIONS))
-			set_serial_connection();
+	// avoid pseudo autodetect driver (index 0)
+	if (index >= 1) {
+		shared_ptr<Driver> driver =
+			drivers_.itemData(index).value<shared_ptr<Driver>>();
+
+		if (driver->config_check(ConfigKey::SERIALCOMM, ConfigKey::SCAN_OPTIONS))
+				set_serial_connection();
+	}
+
+	scan_pressed();
 }
 
 } // namespace dialogs
diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp
index b7f360f..ff4fb45 100644
--- a/pv/mainwindow.cpp
+++ b/pv/mainwindow.cpp
@@ -172,6 +172,9 @@ void MainWindow::setup_ui()
 
 	QAction *const action_connect = new QAction(this);
 	action_connect->setText(tr("&Connect to Device..."));
+	action_connect->setIcon(QIcon::fromTheme("application-connect",
+		QIcon(":/icons/sigrok-logo-notext.png")));
+	action_connect->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
 	action_connect->setObjectName(QString::fromUtf8("actionConnect"));
 	menu_file->addAction(action_connect);
 
@@ -273,6 +276,8 @@ void MainWindow::setup_ui()
 	// Setup the toolbar
 	QToolBar *const toolbar = new QToolBar(tr("Main Toolbar"), this);
 	toolbar->setObjectName(QString::fromUtf8("MainToolbar"));
+	toolbar->addAction(action_connect);
+	toolbar->addSeparator();
 	toolbar->addAction(action_open);
 	toolbar->addAction(action_save_as);
 	toolbar->addSeparator();
-- 
2.2.1

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to