]> sigrok.org Git - pulseview.git/commitdiff
Connect: List available serial ports in a combobox.
authorAurelien Jacobs <redacted>
Sat, 6 Dec 2014 23:59:52 +0000 (00:59 +0100)
committerJoel Holdsworth <redacted>
Sun, 4 Jan 2015 17:52:40 +0000 (17:52 +0000)
pv/dialogs/connect.cpp
pv/dialogs/connect.hpp

index 3ced06dc9ee1aa6b70e49a15725c4b03e5dbf8ed..fcb2103bedf77737d23f1c5e48b09f4af8199ef6 100644 (file)
@@ -50,7 +50,7 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        form_(this),
        form_layout_(&form_),
        drivers_(&form_),
-       serial_device_(&form_),
+       serial_devices_(&form_),
        scan_button_(tr("&Scan for Devices"), this),
        device_list_(this),
        button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
@@ -68,7 +68,8 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        form_.setLayout(&form_layout_);
        form_layout_.addRow(tr("&Driver"), &drivers_);
 
-       form_layout_.addRow(tr("Serial &Port"), &serial_device_);
+       form_layout_.addRow(tr("Serial &Port"), &serial_devices_);
+       serial_devices_.setEditable(true);
 
        unset_connection();
 
@@ -115,18 +116,28 @@ void Connect::populate_drivers()
        }
 }
 
+void Connect::populate_serials(shared_ptr<Driver> driver)
+{
+       serial_devices_.clear();
+       for (auto serial : device_manager_.context()->serials(driver))
+               serial_devices_.addItem(QString("%1 (%2)").arg(
+                       serial.first.c_str()).arg(serial.second.c_str()),
+                       QString::fromStdString(serial.first));
+}
+
 void Connect::unset_connection()
 {
        device_list_.clear();
-       serial_device_.hide();
-       form_layout_.labelForField(&serial_device_)->hide();
+       serial_devices_.hide();
+       form_layout_.labelForField(&serial_devices_)->hide();
        button_box_.button(QDialogButtonBox::Ok)->setDisabled(true);
 }
 
-void Connect::set_serial_connection()
+void Connect::set_serial_connection(shared_ptr<Driver> driver)
 {
-       serial_device_.show();
-       form_layout_.labelForField(&serial_device_)->show();
+       populate_serials(driver);
+       serial_devices_.show();
+       form_layout_.labelForField(&serial_devices_)->show();
 }
 
 void Connect::scan_pressed()
@@ -144,9 +155,17 @@ void Connect::scan_pressed()
 
        map<const ConfigKey *, VariantBase> drvopts;
 
-       if (serial_device_.isVisible())
+       if (serial_devices_.isVisible()) {
+               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<QString>();
+               else
+                       serial = serial_devices_.currentText();
                drvopts[ConfigKey::CONN] = Variant<ustring>::create(
-                       serial_device_.text().toUtf8().constData());
+                       serial.toUtf8().constData());
+       }
 
        list< shared_ptr<HardwareDevice> > devices =
                device_manager_.driver_scan(driver, drvopts);
@@ -177,7 +196,7 @@ void Connect::device_selected(int index)
        unset_connection();
 
        if (driver->config_check(ConfigKey::SERIALCOMM, ConfigKey::SCAN_OPTIONS))
-                       set_serial_connection();
+               set_serial_connection(driver);
 }
 
 } // namespace dialogs
index b46da06fdfc28ce55645323750b94e5a95dc7a69..ba8339c7cc56d11cd250baa13d12384631ed3cfd 100644 (file)
@@ -58,9 +58,11 @@ public:
 private:
        void populate_drivers();
 
+       void populate_serials(std::shared_ptr<sigrok::Driver> driver);
+
        void unset_connection();
 
-       void set_serial_connection();
+       void set_serial_connection(std::shared_ptr<sigrok::Driver> driver);
 
 private Q_SLOTS:
        void device_selected(int index);
@@ -77,7 +79,7 @@ private:
 
        QComboBox drivers_;
 
-       QLineEdit serial_device_;
+       QComboBox serial_devices_;
 
        QPushButton scan_button_;
        QListWidget device_list_;