+ GVariant *gvar_opts;
+
+ for (int i = 0; drivers[i]; ++i) {
+ /**
+ * We currently only support devices that can deliver
+ * samples at a fixed samplerate i.e. oscilloscopes and
+ * logic analysers.
+ * @todo Add support for non-monotonic devices i.e. DMMs
+ * and sensors.
+ */
+ bool supported_device = false;
+ if ((sr_config_list(drivers[i], SR_CONF_DEVICE_OPTIONS,
+ &gvar_opts, NULL) == SR_OK))
+ hwopts = (const int32_t *)g_variant_get_fixed_array(gvar_opts,
+ &num_opts, sizeof(int32_t));
+ for (unsigned int j = 0; j < num_opts; j++)
+ if (hwopts[j] == SR_CONF_SAMPLERATE) {
+ supported_device = true;
+ break;
+ }
+
+ if (supported_device)
+ _drivers.addItem(QString("%1 (%2)").arg(
+ drivers[i]->longname).arg(drivers[i]->name),
+ qVariantFromValue((void*)drivers[i]));
+ }
+}
+
+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()
+{
+ _serial_device.show();
+ _form_layout.labelForField(&_serial_device)->show();
+}
+
+void Connect::scan_pressed()
+{
+ _device_list.clear();
+
+ const int index = _drivers.currentIndex();
+ if (index == -1)
+ return;
+
+ sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData(
+ index).value<void*>();
+
+ GSList *drvopts = NULL;
+
+ if (_serial_device.isVisible()) {
+ sr_config *const src = (sr_config*)g_try_malloc(sizeof(sr_config));
+ src->key = SR_CONF_CONN;
+ const QByteArray byteArray = _serial_device.text().toUtf8();
+ src->data = g_variant_new_string((const gchar*)byteArray.constData());
+ drvopts = g_slist_append(drvopts, src);
+ }
+
+ GSList *const devices = sr_driver_scan(driver, drvopts);
+
+ for (GSList *l = devices; l; l = l->next) {
+
+ sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
+
+ QString text;
+ if (sdi->vendor && sdi->vendor[0])
+ text += QString("%1 ").arg(sdi->vendor);
+ if (sdi->model && sdi->model[0])
+ text += QString("%1 ").arg(sdi->model);
+ if (sdi->version && sdi->version[0])
+ text += QString("%1 ").arg(sdi->version);
+ if (sdi->probes) {
+ text += QString("with %1 probes").arg(
+ g_slist_length(sdi->probes));
+ }
+
+ 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);