]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Autodetect jogshuttle device, improve handling
[kdenlive] / src / kdenlivesettingsdialog.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include <QDir>
21 #include <QTimer>
22
23 #include <KStandardDirs>
24 #include <KDebug>
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <linux/input.h>
31
32 #include "profilesdialog.h"
33 #include "kdenlivesettings.h"
34 #include "kdenlivesettingsdialog.h"
35
36 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
37
38     QWidget *p1 = new QWidget;
39     m_configMisc.setupUi(p1);
40     page1 = addPage(p1, i18n("Misc"), "configure");
41
42     QWidget *p3 = new QWidget;
43     m_configDisplay.setupUi(p3);
44     page3 = addPage(p3, i18n("Display"), "display");
45
46     QWidget *p2 = new QWidget;
47     m_configEnv.setupUi(p2);
48     m_configEnv.mltpathurl->setMode(KFile::Directory);
49     m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
50     m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
51     m_configEnv.tmppathurl->setMode(KFile::Directory);
52     m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
53     m_configEnv.capturefolderurl->setMode(KFile::Directory);
54     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
55     page2 = addPage(p2, i18n("Environnement"), "terminal");
56
57     QWidget *p4 = new QWidget;
58     m_configCapture.setupUi(p4);
59     page4 = addPage(p4, i18n("Capture"), "audio-card");
60
61     QWidget *p5 = new QWidget;
62     m_configShuttle.setupUi(p5);
63     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
64     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
65     slotCheckShuttle(KdenliveSettings::enableshuttle());
66     page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
67
68     QStringList actions;
69     actions << i18n("Do nothing");
70     actions << i18n("Play / Pause");
71     actions << i18n("Cut");
72     m_configShuttle.kcfg_shuttle1->addItems(actions);
73     m_configShuttle.kcfg_shuttle2->addItems(actions);
74     m_configShuttle.kcfg_shuttle3->addItems(actions);
75     m_configShuttle.kcfg_shuttle4->addItems(actions);
76     m_configShuttle.kcfg_shuttle5->addItems(actions);
77
78     connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
79     connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
80     connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
81     connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
82     connect(m_configCapture.kcfg_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
83     connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
84     connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
85     connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
86
87     QStringList profilesNames = ProfilesDialog::getProfileNames();
88     m_configMisc.profiles_list->addItems(profilesNames);
89     m_defaulfProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description");
90     if (profilesNames.contains(m_defaulfProfile)) m_configMisc.profiles_list->setCurrentItem(m_defaulfProfile);
91     slotUpdateDisplay();
92     connect(m_configMisc.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
93 }
94
95 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
96
97
98 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
99     m_configShuttle.config_group->setEnabled(state);
100     if (m_configShuttle.shuttledevicelist->count() == 0) {
101         // parse devices
102         QString baseName = "/dev/input/event";
103         int fd;
104         for (int i = 0; i < 30; i++) {
105             QString filename = baseName + QString::number(i);
106             kDebug() << "/// CHECKING OFR: " << filename;
107
108             char name[256] = "unknown";
109             fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
110             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
111                 m_configShuttle.shuttledevicelist->addItem(name, filename);
112             }
113             ::close(fd);
114         }
115         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
116     }
117 }
118
119 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
120     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
121     //KdenliveSettings::setShuttledevice(device);
122     m_configShuttle.kcfg_shuttledevice->setText(device);
123 }
124
125 void KdenliveSettingsDialog::rebuildVideo4Commands() {
126     QString captureCommand;
127     if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
128
129     captureCommand +=  " -f " + m_configCapture.kcfg_video4vformat->text() + " -s " + m_configCapture.kcfg_video4size->text() + " -r " + QString::number(m_configCapture.kcfg_video4rate->value()) + " -i " + m_configCapture.kcfg_video4vdevice->text() + " -f " + m_configCapture.kcfg_video4vencoding->text();
130     m_configCapture.kcfg_video4capture->setText(captureCommand);
131
132     QString playbackCommand;
133     playbackCommand =  "-f " + m_configCapture.kcfg_video4vencoding->text();
134     m_configCapture.kcfg_video4playback->setText(playbackCommand);
135 }
136
137 bool KdenliveSettingsDialog::hasChanged() {
138     kDebug() << "// // // KCONFIG hasChanged called";
139     if (m_configMisc.profiles_list->currentText() != m_defaulfProfile) return true;
140     return KConfigDialog::hasChanged();
141 }
142
143 void KdenliveSettingsDialog::slotUpdateDisplay() {
144     QString currentProfile = m_configMisc.profiles_list->currentText();
145     QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile);
146     m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
147     m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
148     m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
149     m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
150     if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
151     else m_configMisc.p_progressive->setText(i18n("Progressive"));
152 }
153
154
155 #include "kdenlivesettingsdialog.moc"
156
157