From 581dc2315a4c2addcae0cd9112bb95136f2ca155 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Wed, 8 Jul 2015 18:25:43 +0200 Subject: [PATCH] Do not build the string displayed in the device list ComboBox directly in the DeviceProber. --- deviceprober.cpp | 7 +++---- deviceprober.h | 2 +- mainwindow.cpp | 12 ++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/deviceprober.cpp b/deviceprober.cpp index bbba7e8..541129e 100644 --- a/deviceprober.cpp +++ b/deviceprober.cpp @@ -36,11 +36,10 @@ DeviceProber::DeviceList DeviceProber::listDevices() dinfo.path = devicePath; ret = ioctl(fd, EVIOCGNAME(64), deviceName); - if (ret < 0) { + if (ret < 0) qDebug() << "Cannot get name of device" << d << strerror(errno); - dinfo.tag = QString("[%1]").arg(d); - } else - dinfo.tag = QString("%1 [%2]").arg(deviceName).arg(d); + else + dinfo.name = deviceName; list.append(dinfo); } diff --git a/deviceprober.h b/deviceprober.h index 0314a7a..778d28e 100644 --- a/deviceprober.h +++ b/deviceprober.h @@ -12,7 +12,7 @@ class DeviceProber : public QObject public: struct DeviceInfo { QString path; - QString tag; + QString name; }; typedef QList DeviceList; diff --git a/mainwindow.cpp b/mainwindow.cpp index 36a221a..000c114 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -83,8 +83,16 @@ void MainWindow::fillDeviceList() { ui->cbox_devices->clear(); - for (const DeviceProber::DeviceInfo& dinfo : m_prober->listDevices()) - ui->cbox_devices->addItem(dinfo.tag, dinfo.path); + for (const DeviceProber::DeviceInfo& dinfo : m_prober->listDevices()) { + QString name; + if (dinfo.name.length() == 0) + name = "(no name)"; + else + name = dinfo.name; + + QString tag = QString("%1 [%2]").arg(name).arg(dinfo.path); + ui->cbox_devices->addItem(tag, dinfo.path); + } } void MainWindow::fillEffectSlotsList(const int effectCount) -- 2.43.5