]> git.sesse.net Git - kdenlive/commitdiff
Autodetect jogshuttle device, improve handling
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 17 Mar 2008 23:41:28 +0000 (23:41 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 17 Mar 2008 23:41:28 +0000 (23:41 +0000)
svn path=/branches/KDE4/; revision=2072

src/jogshuttle.cpp
src/kdenlivesettings.kcfg
src/kdenlivesettingsdialog.cpp
src/kdenlivesettingsdialog.h
src/mainwindow.cpp
src/widgets/configjogshuttle_ui.ui

index 6988045af09571d83a82c95734c920347271513b..f53f49166d750db849c15c6be3b84cc9be60c724 100644 (file)
 #define JOG_STOP 10009
 
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include <QFile>
-#include <QTextStream>
 #include <QApplication>
 #include <QEvent>
 
 #include <KDebug>
 
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <linux/input.h>
+
+
 
 #include "jogshuttle.h"
 
 
-/*unsigned short  jogvalue = 0xffff;
-int   shuttlevalue = 0xffff;
-struct timeval  last_shuttle;
-int   need_synthetic_shuttle;
-*/
-
 void ShuttleThread::init(QObject *parent, QString device) {
     m_parent = parent;
     m_device = device;
@@ -92,18 +87,23 @@ bool ShuttleThread::isWorking() {
 void ShuttleThread::run() {
     kDebug() << "-------  STARTING SHUTTLE: " << m_device;
 
+    const int fd = open((char *) m_device.toUtf8().data(), O_RDONLY);
+    if (fd < 0) {
+        fprintf(stderr, "Can't open Jog Shuttle FILE DESCRIPTOR\n");
+        return;;
+    }
     EV ev;
-    FILE * fd = fopen((char *) m_device.toUtf8().data(), "r");
 
-    if (!fd) {
-        fprintf(stderr, "Can't open file\n");
-        exit(1);
+    if (ioctl(fd, EVIOCGRAB, 1) < 0) {
+        fprintf(stderr, "Can't get exclusive access on  Jog Shuttle FILE DESCRIPTOR\n");
+        return;;
     }
 
     while (!stop_me) {
-        while (fread(&ev, sizeof(ev), 1, fd) == 1) handle_event(ev);
+        read(fd, &ev, sizeof(ev));
+        handle_event(ev);
     }
-
+    close(fd);
 
 }
 
index ff442bb7e131814fbfe5558665784e82aa8cafbb..144478af405077bb06a5d844b74227efc30a2e63 100644 (file)
 
     <entry name="shuttledevice" type="String">
       <label>Path to shuttle device.</label>
-      <default>/dev/input/event0</default>
+      <default></default>
     </entry>
 
     <entry name="shuttle1" type="UInt">
index 4a73a877a18556a17d63ffc9bd0276fe74f48df8..431f9170fa9b5137c5c7e95ba6f84ddcbdf3f665 100644 (file)
  ***************************************************************************/
 
 #include <QDir>
+#include <QTimer>
 
 #include <KStandardDirs>
 #include <KDebug>
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <linux/input.h>
+
 #include "profilesdialog.h"
 #include "kdenlivesettings.h"
 #include "kdenlivesettingsdialog.h"
@@ -53,6 +60,9 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(
 
     QWidget *p5 = new QWidget;
     m_configShuttle.setupUi(p5);
+    connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
+    connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
+    slotCheckShuttle(KdenliveSettings::enableshuttle());
     page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
 
     QStringList actions;
@@ -78,7 +88,6 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(
     m_configMisc.profiles_list->addItems(profilesNames);
     m_defaulfProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description");
     if (profilesNames.contains(m_defaulfProfile)) m_configMisc.profiles_list->setCurrentItem(m_defaulfProfile);
-
     slotUpdateDisplay();
     connect(m_configMisc.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
 }
@@ -86,6 +95,33 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(
 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
 
 
+void KdenliveSettingsDialog::slotCheckShuttle(int state) {
+    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 OFR: " << filename;
+
+            char name[256] = "unknown";
+            fd = ::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()));
+    }
+}
+
+void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
+    QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
+    //KdenliveSettings::setShuttledevice(device);
+    m_configShuttle.kcfg_shuttledevice->setText(device);
+}
+
 void KdenliveSettingsDialog::rebuildVideo4Commands() {
     QString captureCommand;
     if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
index cd82bf13c7c771526f2d52139ed4decc04c4fdd2..c74e66c02c51d0881751f2f134cbc66b8064ca0a 100644 (file)
@@ -44,6 +44,8 @@ protected:
 private slots:
     void slotUpdateDisplay();
     void rebuildVideo4Commands();
+    void slotCheckShuttle(int state = 0);
+    void slotUpdateShuttleDevice(int ix = 0);
 
 private:
     KPageWidgetItem *page1;
index 899ce8840b214972ca98c7a00a16474bcc742264..4860a5152f2cbe3e1d6741a283ac0dc9a156a29e 100644 (file)
@@ -295,7 +295,7 @@ void MainWindow::slotShuttleButton(int code) {
 void MainWindow::slotShuttleAction(int code) {
     switch (code) {
     case 0:
-       return;
+        return;
     case 1:
         m_monitorManager->slotPlay();
         break;
index 0c2dafaadf9f192629d9778a5d0edcbf6c7fcd3c..9abb022f395f59a34b05fa485e32549ef8f9dec0 100644 (file)
@@ -5,12 +5,12 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>299</width>
-    <height>260</height>
+    <width>325</width>
+    <height>285</height>
    </rect>
   </property>
-  <layout class="QGridLayout" name="gridLayout" >
-   <item row="0" column="0" colspan="2" >
+  <layout class="QGridLayout" name="gridLayout_2" >
+   <item row="0" column="0" >
     <widget class="QCheckBox" name="kcfg_enableshuttle" >
      <property name="text" >
       <string>Enable Jog Shuttle device</string>
     </widget>
    </item>
    <item row="1" column="0" >
-    <widget class="QLabel" name="label" >
-     <property name="text" >
-      <string>Device path</string>
+    <widget class="QGroupBox" name="config_group" >
+     <property name="enabled" >
+      <bool>false</bool>
      </property>
-    </widget>
-   </item>
-   <item row="1" column="1" >
-    <widget class="KLineEdit" name="kcfg_shuttledevice" >
-     <property name="text" >
-      <string>/dev/input/event1</string>
+     <property name="title" >
+      <string>Device configuration</string>
      </property>
+     <layout class="QGridLayout" name="gridLayout" >
+      <item row="0" column="0" >
+       <widget class="QLabel" name="label" >
+        <property name="text" >
+         <string>Device</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1" >
+       <widget class="KComboBox" name="shuttledevicelist" />
+      </item>
+      <item row="0" column="2" >
+       <widget class="KLineEdit" name="kcfg_shuttledevice" >
+        <property name="text" >
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0" >
+       <widget class="QLabel" name="label_2" >
+        <property name="text" >
+         <string>Button 1</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1" colspan="2" >
+       <widget class="KComboBox" name="kcfg_shuttle1" />
+      </item>
+      <item row="2" column="0" >
+       <widget class="QLabel" name="label_4" >
+        <property name="text" >
+         <string>Button 2</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1" colspan="2" >
+       <widget class="KComboBox" name="kcfg_shuttle2" />
+      </item>
+      <item row="3" column="0" >
+       <widget class="QLabel" name="label_3" >
+        <property name="text" >
+         <string>Button 3</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1" colspan="2" >
+       <widget class="KComboBox" name="kcfg_shuttle3" />
+      </item>
+      <item row="4" column="0" >
+       <widget class="QLabel" name="label_7" >
+        <property name="text" >
+         <string>Button 4</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="1" colspan="2" >
+       <widget class="KComboBox" name="kcfg_shuttle4" />
+      </item>
+      <item row="5" column="0" >
+       <widget class="QLabel" name="label_5" >
+        <property name="text" >
+         <string>Button 5</string>
+        </property>
+       </widget>
+      </item>
+      <item row="5" column="1" colspan="2" >
+       <widget class="KComboBox" name="kcfg_shuttle5" />
+      </item>
+     </layout>
     </widget>
    </item>
    <item row="2" column="0" >
-    <widget class="QLabel" name="label_2" >
-     <property name="text" >
-      <string>Button 1</string>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="1" >
-    <widget class="KComboBox" name="kcfg_shuttle1" />
-   </item>
-   <item row="3" column="0" >
-    <widget class="QLabel" name="label_4" >
-     <property name="text" >
-      <string>Button 2</string>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="1" >
-    <widget class="KComboBox" name="kcfg_shuttle2" />
-   </item>
-   <item row="4" column="0" >
-    <widget class="QLabel" name="label_3" >
-     <property name="text" >
-      <string>Button 3</string>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="1" >
-    <widget class="KComboBox" name="kcfg_shuttle3" />
-   </item>
-   <item row="5" column="0" >
-    <widget class="QLabel" name="label_7" >
-     <property name="text" >
-      <string>Button 4</string>
-     </property>
-    </widget>
-   </item>
-   <item row="5" column="1" >
-    <widget class="KComboBox" name="kcfg_shuttle4" />
-   </item>
-   <item row="6" column="0" >
-    <widget class="QLabel" name="label_5" >
-     <property name="text" >
-      <string>Button 5</string>
-     </property>
-    </widget>
-   </item>
-   <item row="6" column="1" >
-    <widget class="KComboBox" name="kcfg_shuttle5" />
-   </item>
-   <item row="7" column="1" >
     <spacer name="verticalSpacer" >
      <property name="orientation" >
       <enum>Qt::Vertical</enum>