From 4f332f85fe29846d15d5006d66fe03ebe09b556c Mon Sep 17 00:00:00 2001 From: Ed Rogalsky Date: Fri, 28 Feb 2014 16:52:07 +0100 Subject: [PATCH] jogshuttle: add support for shuttles on newer systems - part2 --- src/jogshuttle.cpp | 29 ++++++++++++++++++-- src/jogshuttle.h | 6 ++++- src/kdenlivesettingsdialog.cpp | 48 +++++++++++++--------------------- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/jogshuttle.cpp b/src/jogshuttle.cpp index 44517d77..73985e56 100644 --- a/src/jogshuttle.cpp +++ b/src/jogshuttle.cpp @@ -344,13 +344,38 @@ void JogShuttle::customEvent(QEvent* e) emit button(e->type() - KEY_EVENT_OFFSET); } -QString JogShuttle::enumerateDevice(const QString &device) +QString JogShuttle::enumerateDevice(const QString& device) { QDir canonDir(device); - //return QDir::canonicalPath(device); return canonDir.canonicalPath(); } +DeviceMap JogShuttle::enumerateDevices(const QString& devPath) +{ + DeviceMap devs; + QDir devDir(devPath); + + if (!devDir.exists()) { + return devs; + } + + QStringList fileList = devDir.entryList(QDir::System | QDir::Files); + foreach (const QString &fileName, fileList) { + QString devFullPath = devDir.absoluteFilePath(fileName); + QString fileLink = JogShuttle::enumerateDevice(devFullPath); + kDebug() << QString(" [%1] ").arg(fileName); + kDebug() << QString(" [%1] ").arg(fileLink); + char name[256] = "unknown"; + int fd = KDE_open((char*)fileLink.toUtf8().data(), O_RDONLY); + if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) { + devs.insert(name, devFullPath); + } + ::close(fd); + } + + return devs; +} + // #include "jogshuttle.moc" diff --git a/src/jogshuttle.h b/src/jogshuttle.h index 1a337868..d1cf185b 100644 --- a/src/jogshuttle.h +++ b/src/jogshuttle.h @@ -23,6 +23,7 @@ #include #include +#include #include @@ -51,6 +52,8 @@ private: void key(unsigned short code, unsigned int value); }; +typedef QMap DeviceMap; +typedef QMap::iterator DeviceMapIter; class JogShuttle: public QObject { @@ -60,7 +63,8 @@ public: ~JogShuttle(); void stopDevice(); void initDevice(const QString &device); - static QString enumerateDevice(const QString &device); + static QString enumerateDevice(const QString& device); + static DeviceMap enumerateDevices(const QString& devPath); protected: virtual void customEvent(QEvent * e); diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index 42e58133..8e97b33d 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -524,37 +524,25 @@ void KdenliveSettingsDialog::slotCheckShuttle(int state) #ifdef USE_JOGSHUTTLE m_configShuttle.config_group->setEnabled(state); if (m_configShuttle.shuttledevicelist->count() == 0) { - QString devDirStr = "/dev/input/by-id/"; + QString devDirStr = "/dev/input/by-id"; QDir devDir(devDirStr); - if (devDir.exists()) { - QStringList fileList = devDir.entryList(QDir::Files); - foreach (const QString &fileName, fileList) { - QString devFullPath(devDirStr + fileName); - QString fileLink = JogShuttle::enumerateDevice(devFullPath); - kDebug() << QString(" [%1] ").arg(fileName); - kDebug() << QString(" [%1] ").arg(fileLink); - char name[256] = "unknown"; - int fd = KDE_open((char*)fileLink.toUtf8().data(), O_RDONLY); - if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) { - m_configShuttle.shuttledevicelist->addItem(name, devFullPath); - } - ::close(fd); - } - } else { - // parse devices - QString baseName = "/dev/input/event"; - int fd; - for (int i = 0; i < 30; ++i) { - QString filename = baseName + QString::number(i); - kDebug() << "/// CHECKING device: " << filename; - - char name[256] = "unknown"; - fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY); - if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) { - m_configShuttle.shuttledevicelist->addItem(name, filename); - } - ::close(fd); - } + if (!devDir.exists()) { + devDirStr = "/dev/input"; + } + + DeviceMap devMap = JogShuttle::enumerateDevices(devDirStr); +#if 0 + if (!devMap.isEmpty()) { + m_configShuttle.shuttledevicelist->clear(); + } +#endif + DeviceMapIter iter = devMap.begin(); + while (iter != devMap.end()) { + kDebug() << iter.key() << ": " << iter.value(); + m_configShuttle.shuttledevicelist->addItem( + iter.key(), + iter.value()); + ++iter; } if (KdenliveSettings::shuttledevice().isEmpty()) { -- 2.39.2