X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fdialogs%2Fconnect.cpp;h=cb83b3d7b55cadbbcd74db66d159109d783b9ae0;hb=793f8096c486d0fba871227d9772a510f7496c08;hp=f7a75da0c6e081840ee9cd597c90a31d1605d4ac;hpb=c9de8b3297469aad87554ad6fcc6909223424f54;p=pulseview.git diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp index f7a75da0..cb83b3d7 100644 --- a/pv/dialogs/connect.cpp +++ b/pv/dialogs/connect.cpp @@ -70,6 +70,15 @@ Connect::Connect(QWidget *parent) : _layout.addWidget(&_button_box); } +struct sr_dev_inst* Connect::get_selected_device() const +{ + const QListWidgetItem *const item = _device_list.currentItem(); + if (!item) + return NULL; + + return (sr_dev_inst*)item->data(Qt::UserRole).value(); +} + void Connect::populate_drivers() { const int *hwopts; @@ -86,12 +95,12 @@ void Connect::populate_drivers() if ((sr_config_list(drivers[i], SR_CONF_DEVICE_OPTIONS, (const void **)&hwopts, NULL) == SR_OK) && hwopts) for (int j = 0; hwopts[j]; j++) - if(hwopts[j] == SR_CONF_SAMPLERATE) { + if (hwopts[j] == SR_CONF_SAMPLERATE) { supported_device = true; break; } - if(supported_device) + if (supported_device) _drivers.addItem(QString("%1 (%2)").arg( drivers[i]->longname).arg(drivers[i]->name), qVariantFromValue((void*)drivers[i])); @@ -103,6 +112,7 @@ void Connect::unset_connection() _device_list.clear(); _serial_device.hide(); _form_layout.labelForField(&_serial_device)->hide(); + _button_box.button(QDialogButtonBox::Ok)->setDisabled(true); } void Connect::set_serial_connection() @@ -116,7 +126,7 @@ void Connect::scan_pressed() _device_list.clear(); const int index = _drivers.currentIndex(); - if(index == -1) + if (index == -1) return; sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData( @@ -150,11 +160,17 @@ void Connect::scan_pressed() g_slist_length(sdi->probes)); } - _device_list.addItem(text); + QListWidgetItem *const item = new QListWidgetItem(text, + &_device_list); + item->setData(Qt::UserRole, qVariantFromValue((void*)sdi)); + _device_list.addItem(item); } g_slist_free(devices); g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts); + + _device_list.setCurrentRow(0); + _button_box.button(QDialogButtonBox::Ok)->setDisabled(false); } void Connect::device_selected(int index)