]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Screen grab now uses recordmydesktop
[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 #include <kopenwithdialog.h>
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #ifndef NO_JOGSHUTTLE
32 #include <linux/input.h>
33 #endif /* NO_JOGSHUTTLE */
34
35 #include "profilesdialog.h"
36 #include "kdenlivesettings.h"
37 #include "kdenlivesettingsdialog.h"
38
39 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
40
41     QWidget *p1 = new QWidget;
42     m_configMisc.setupUi(p1);
43     page1 = addPage(p1, i18n("Misc"), "configure");
44
45     QWidget *p3 = new QWidget;
46     m_configDisplay.setupUi(p3);
47     page3 = addPage(p3, i18n("Display"), "display");
48
49     QWidget *p2 = new QWidget;
50     m_configEnv.setupUi(p2);
51     m_configEnv.mltpathurl->setMode(KFile::Directory);
52     m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
53     m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
54     m_configEnv.tmppathurl->setMode(KFile::Directory);
55     m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
56     m_configEnv.capturefolderurl->setMode(KFile::Directory);
57     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
58     page2 = addPage(p2, i18n("Environment"), "terminal");
59
60     QWidget *p4 = new QWidget;
61     m_configCapture.setupUi(p4);
62     page4 = addPage(p4, i18n("Capture"), "audio-card");
63     m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
64
65     QWidget *p5 = new QWidget;
66     m_configShuttle.setupUi(p5);
67 #ifndef NO_JOGSHUTTLE
68     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
69     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
70     slotCheckShuttle(KdenliveSettings::enableshuttle());
71     m_configShuttle.shuttledisabled->hide();
72 #else
73     m_configShuttle.kcfg_enableshuttle->hide();
74     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
75 #endif /* NO_JOGSHUTTLE */
76     page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
77
78     QWidget *p6 = new QWidget;
79     m_configSdl.setupUi(p6);
80     page6 = addPage(p6, i18n("Playback"), "audio-card");
81
82     QStringList actions;
83     actions << i18n("Do nothing");
84     actions << i18n("Play / Pause");
85     actions << i18n("Cut");
86     m_configShuttle.kcfg_shuttle1->addItems(actions);
87     m_configShuttle.kcfg_shuttle2->addItems(actions);
88     m_configShuttle.kcfg_shuttle3->addItems(actions);
89     m_configShuttle.kcfg_shuttle4->addItems(actions);
90     m_configShuttle.kcfg_shuttle5->addItems(actions);
91
92     connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
93     connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
94     connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
95     connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
96     connect(m_configCapture.kcfg_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
97     connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
98     connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
99     connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
100
101     connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
102
103     m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
104
105     connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
106     connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
107     connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
108
109
110
111     QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
112     QMapIterator<QString, QString> i(profilesInfo);
113     while (i.hasNext()) {
114         i.next();
115         m_configMisc.kcfg_profiles_list->addItem(i.key(), i.value());
116     }
117
118     checkProfile();
119     slotUpdateDisplay();
120
121     initDevices();
122     connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
123
124     connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
125
126     slotUpdateRmdRegionStatus();
127
128
129     //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
130     //   --timestamp option without bug
131     double dvgrabVersion = 0;
132
133     QProcess *versionCheck = new QProcess;
134     versionCheck->setProcessChannelMode(QProcess::MergedChannels);
135     versionCheck->start("dvgrab", QStringList() << "--version");
136     if (versionCheck->waitForFinished()) {
137         QString version = QString(versionCheck->readAll()).simplified();
138         if (version.contains(' ')) version = version.section(' ', -1);
139         dvgrabVersion = version.toDouble();
140
141         kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
142     }
143     if (versionCheck) delete versionCheck;
144     if (dvgrabVersion < 3.3) {
145         KdenliveSettings::setFirewiretimestamp(false);
146         m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
147     }
148
149     QString rmdpath = KStandardDirs::findExe("recordmydesktop");
150     if (rmdpath.isEmpty()) {
151         KdenliveSettings::setRmd_path(QString());
152         m_configCapture.rmd_info->setText(i18n("Recordmydesktop utility not found, please install it for screen grabs"));
153     } else {
154         KdenliveSettings::setRmd_path(rmdpath);
155         m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", rmdpath));
156     }
157 }
158
159 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
160
161 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus() {
162     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
163 }
164
165 void KdenliveSettingsDialog::checkProfile() {
166     if (!KdenliveSettings::default_profile().isEmpty()) {
167         for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
168             if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
169                 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
170                 KdenliveSettings::setProfiles_list(i);
171                 break;
172             }
173         }
174     }
175 }
176
177 void KdenliveSettingsDialog::initDevices() {
178     // Fill audio drivers
179     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
180     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
181     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
182     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
183     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
184     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
185
186     /*if (!KdenliveSettings::audiodriver().isEmpty())
187     for (uint i = 1;i < m_configDisplay.kcfg_audio_driver->count(); i++) {
188      if (m_configDisplay.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodriver())
189     m_configDisplay.kcfg_audio_driver->setCurrentIndex(i);
190     }*/
191
192     // Fill video drivers
193     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
194     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
195     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
196     m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga");
197     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
198     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
199     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
200     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
201     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
202     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
203
204     // Fill the list of audio playback devices
205     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
206     m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
207     if (KStandardDirs::findExe("aplay") != QString::null) {
208         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
209         m_readProcess.setProgram("aplay", QStringList() << "-l");
210         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
211         m_readProcess.execute(5000);
212     } else {
213         // If aplay is not installed on the system, parse the /proc/asound/pcm file
214         QFile file("/proc/asound/pcm");
215         if (file.open(QIODevice::ReadOnly)) {
216             QTextStream stream(&file);
217             QString line;
218             QString deviceId;
219             while (!stream.atEnd()) {
220                 line = stream.readLine();
221                 if (line.contains("playback")) {
222                     deviceId = line.section(":", 0, 0);
223                     m_configSdl.kcfg_audio_device->addItem(line.section(":", 1, 1), "plughw:" + QString::number(deviceId.section("-", 0, 0).toInt()) + "," + QString::number(deviceId.section("-", 1, 1).toInt()));
224                 }
225                 if (line.contains("capture")) {
226                     deviceId = line.section(":", 0, 0);
227                     m_configCapture.kcfg_rmd_alsa_device->addItem(line.section(":", 1, 1), "plughw:" + QString::number(deviceId.section("-", 0, 0).toInt()) + "," + QString::number(deviceId.section("-", 1, 1).toInt()));
228                 }
229             }
230             file.close();
231         }
232     }
233 }
234
235
236 void KdenliveSettingsDialog::slotReadAudioDevices() {
237     QString result = QString(m_readProcess.readAllStandardOutput());
238     kDebug() << "// / / / / / READING APLAY: ";
239     kDebug() << result;
240     QStringList lines = result.split('\n');
241     foreach(QString data, lines) {
242         kDebug() << "// READING LINE: " << data;
243         if (data.simplified().startsWith("card")) {
244             QString card = data.section(":", 0, 0).section(" ", -1);
245             QString device = data.section(":", 1, 1).section(" ", -1);
246             m_configSdl.kcfg_audio_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
247             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
248         }
249     }
250 }
251
252 void KdenliveSettingsDialog::showPage(int page, int option) {
253     switch (page) {
254     case 1:
255         setCurrentPage(page1);
256         break;
257     case 2:
258         setCurrentPage(page2);
259         break;
260     case 3:
261         setCurrentPage(page3);
262         break;
263     case 4:
264         setCurrentPage(page4);
265         m_configCapture.tabWidget->setCurrentIndex(option);
266         break;
267     case 5:
268         setCurrentPage(page5);
269         break;
270
271     }
272 }
273
274 void KdenliveSettingsDialog::slotEditVideoApplication() {
275     KService::Ptr service;
276     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
277     if (dlg.exec() != QDialog::Accepted)
278         return;
279
280     service = dlg.service();
281     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
282 }
283
284 void KdenliveSettingsDialog::slotEditAudioApplication() {
285     KService::Ptr service;
286     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
287     if (dlg.exec() != QDialog::Accepted)
288         return;
289
290     service = dlg.service();
291     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
292 }
293
294 void KdenliveSettingsDialog::slotEditImageApplication() {
295     KService::Ptr service;
296     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
297     if (dlg.exec() != QDialog::Accepted)
298         return;
299
300     service = dlg.service();
301     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
302 }
303
304 #ifndef NO_JOGSHUTTLE
305 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
306     m_configShuttle.config_group->setEnabled(state);
307     if (m_configShuttle.shuttledevicelist->count() == 0) {
308         // parse devices
309         QString baseName = "/dev/input/event";
310         int fd;
311         for (int i = 0; i < 30; i++) {
312             QString filename = baseName + QString::number(i);
313             kDebug() << "/// CHECKING OFR: " << filename;
314
315             char name[256] = "unknown";
316             fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
317             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
318                 m_configShuttle.shuttledevicelist->addItem(name, filename);
319             }
320             ::close(fd);
321         }
322         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
323     }
324 }
325
326 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
327     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
328     //KdenliveSettings::setShuttledevice(device);
329     m_configShuttle.kcfg_shuttledevice->setText(device);
330 }
331 #endif /* NO_JOGSHUTTLE */
332
333 void KdenliveSettingsDialog::rebuildVideo4Commands() {
334     QString captureCommand;
335     if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
336
337     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();
338     m_configCapture.kcfg_video4capture->setText(captureCommand);
339
340     QString playbackCommand;
341     playbackCommand =  "-f " + m_configCapture.kcfg_video4vencoding->text();
342     m_configCapture.kcfg_video4playback->setText(playbackCommand);
343 }
344
345
346 // virtual protected
347 bool KdenliveSettingsDialog::isDefault() {
348     return KConfigDialog::isDefault();
349 }
350
351 // virtual protected
352 bool KdenliveSettingsDialog::hasChanged() {
353     kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
354
355     if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
356     return KConfigDialog::hasChanged();
357 }
358
359 void KdenliveSettingsDialog::updateSettings() {
360     kDebug() << "// // // KCONFIG UPDATE called";
361     m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
362     KdenliveSettings::setDefault_profile(m_defaultPath);
363
364     bool resetProfile = false;
365     QString value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
366     if (value != KdenliveSettings::audiodevicename()) {
367         KdenliveSettings::setAudiodevicename(value);
368         resetProfile = true;
369     }
370
371     value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
372     if (value != KdenliveSettings::rmd_alsadevicename()) {
373         KdenliveSettings::setRmd_alsadevicename(value);
374     }
375
376     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
377     if (value != KdenliveSettings::audiodrivername()) {
378         KdenliveSettings::setAudiodrivername(value);
379         resetProfile = true;
380     }
381
382     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
383     if (value != KdenliveSettings::videodrivername()) {
384         KdenliveSettings::setVideodrivername(value);
385         resetProfile = true;
386     }
387
388     KConfigDialog::updateSettings();
389     if (resetProfile) emit doResetProfile();
390 }
391
392 void KdenliveSettingsDialog::slotUpdateDisplay() {
393     QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
394     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
395     m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
396     m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
397     m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
398     m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
399     if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
400     else m_configMisc.p_progressive->setText(i18n("Progressive"));
401     m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
402     m_defaultPath = currentProfile;
403 }
404
405
406 #include "kdenlivesettingsdialog.moc"
407
408