]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivesettingsdialog.cpp
jogshuttle: decode events with mediactrl
[kdenlive] / src / kdenlivesettingsdialog.cpp
index 50e3dea68dac03d19639c04feee447a3fef1639e..b298e8c6ddaa1a597f7d8e104244df12a4bb3808 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
+
 #ifdef USE_JOGSHUTTLE
-#include "jogaction.h"
-#include "jogshuttleconfig.h"
-#include <linux/input.h>
+  #include "jogaction.h"
+  #include "jogshuttleconfig.h"
+  #include <linux/input.h>
 #endif
 
 
@@ -132,9 +133,12 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(const QMap<QString, QString>& map
 
     QWidget *p5 = new QWidget;
     m_configShuttle.setupUi(p5);
+    m_configShuttle.toolBtnReload->setIcon(KIcon("view-refresh"));
 #ifdef USE_JOGSHUTTLE
     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
+    connect(m_configShuttle.toolBtnReload, SIGNAL(clicked(bool)), this, SLOT(slotReloadShuttleDevices()));
+
     slotCheckShuttle(KdenliveSettings::enableshuttle());
     m_configShuttle.shuttledisabled->hide();
 
@@ -487,14 +491,11 @@ void KdenliveSettingsDialog::slotEditVideoApplication()
 {
     KService::Ptr service;
     QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
-    if (dlg->exec() != QDialog::Accepted)
-    {
-        delete dlg;
-        return;
+    if (dlg->exec() == QDialog::Accepted) {
+        service = dlg->service();
+        m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
     }
 
-    service = dlg->service();
-    m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
     delete dlg;
 }
 
@@ -502,14 +503,11 @@ void KdenliveSettingsDialog::slotEditAudioApplication()
 {
     KService::Ptr service;
     QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
-    if (dlg->exec() != QDialog::Accepted)
-    {
-        delete dlg;
-        return;
+    if (dlg->exec() == QDialog::Accepted) {
+        service = dlg->service();
+        m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
     }
 
-    service = dlg->service();
-    m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
     delete dlg;
 }
 
@@ -517,13 +515,10 @@ void KdenliveSettingsDialog::slotEditImageApplication()
 {
     KService::Ptr service;
     QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
-    if (dlg->exec() != QDialog::Accepted)
-    {
-        delete dlg;
-        return;
+    if (dlg->exec() == QDialog::Accepted) {
+        service = dlg->service();
+        m_configEnv.kcfg_defaultimageapp->setText(service->exec());
     }
-    service = dlg->service();
-    m_configEnv.kcfg_defaultimageapp->setText(service->exec());
     delete dlg;
 }
 
@@ -531,22 +526,17 @@ void KdenliveSettingsDialog::slotCheckShuttle(int state)
 {
 #ifdef USE_JOGSHUTTLE
     m_configShuttle.config_group->setEnabled(state);
-    if (m_configShuttle.shuttledevicelist->count() == 0) {
-        // 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 (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
+    m_configShuttle.shuttledevicelist->clear();
+
+    QStringList devNames = KdenliveSettings::shuttledevicenames();
+    QStringList devPaths = KdenliveSettings::shuttledevicepaths();
+
+    if (devNames.count() != devPaths.count()) {
+        return;
+    }
+    for (int i = 0; i < devNames.count(); i++) {
+        m_configShuttle.shuttledevicelist->addItem(
+                devNames.at(i), devPaths.at(i));
     }
 #endif /* USE_JOGSHUTTLE */
 }
@@ -1132,6 +1122,46 @@ void KdenliveSettingsDialog::slotReloadBlackMagic()
     }
     m_configSdl.kcfg_external_display->setEnabled(KdenliveSettings::decklink_device_found());
 }
+
+void KdenliveSettingsDialog::slotReloadShuttleDevices()
+{
+#ifdef USE_JOGSHUTTLE
+    QString devDirStr = "/dev/input/by-id";
+    QDir devDir(devDirStr);
+    if (!devDir.exists()) {
+        devDirStr = "/dev/input";
+    }
+
+    DeviceMap devMap = JogShuttle::enumerateDevices(devDirStr);
+    if (!devMap.isEmpty()) {
+        m_configShuttle.shuttledevicelist->clear();
+    }
+
+    QStringList devNamesList;
+    QStringList devPathList;
+    DeviceMapIter iter = devMap.begin();
+    if (iter == devMap.end()) {
+        KdenliveSettings::shuttledevicenames().clear();
+        KdenliveSettings::shuttledevicepaths().clear();
+        m_configShuttle.shuttledevicelist->clear();
+    }
+    while (iter != devMap.end()) {
+        kDebug() << iter.key() << ": " << iter.value();
+        m_configShuttle.shuttledevicelist->addItem(iter.key(), iter.value());
+        devNamesList << iter.key();
+        devPathList << iter.value();
+        ++iter;
+    }
+
+    KdenliveSettings::setShuttledevicenames(devNamesList);
+    KdenliveSettings::setShuttledevicepaths(devPathList);
+    QTimer::singleShot(200, this, SLOT(slotUpdateShuttleDevice()));
+
+    kDebug() << "Devices reloded";
+
+#endif //USE_JOGSHUTTLE
+}
+
 #include "kdenlivesettingsdialog.moc"