+QString JogShuttle::canonicalDevice(const QString& device)
+{
+ return QDir(device).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::canonicalDevice(devFullPath);
+ kDebug() << QString(" [%1] ").arg(fileName);
+ kDebug() << QString(" [%1] ").arg(fileLink);
+
+ struct media_ctrl mc;
+ media_ctrl_open2(&mc, (char*)fileLink.toUtf8().data());
+ if (mc.fd > 0 && mc.device) {
+ devs.insert(QString(mc.device->name), devFullPath);
+ kDebug() << QString(" [keys-count=%1] ").arg(
+ media_ctrl_get_keys_count(&mc));
+ }
+ media_ctrl_close(&mc);
+ }
+
+ return devs;
+}
+
+int JogShuttle::keysCount(const QString& devPath)
+{
+ struct media_ctrl mc;
+ int keysCount = 0;
+
+ QString fileLink = canonicalDevice(devPath);
+ media_ctrl_open2(&mc, (char*)fileLink.toUtf8().data());
+ if (mc.fd > 0 && mc.device) {
+ keysCount = media_ctrl_get_keys_count(&mc);
+ }