]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
0653346aed522b17be1dd6943b544d11045dd6ba
[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.projecturl->setMode(KFile::Directory);
57     m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
58     m_configEnv.capturefolderurl->setMode(KFile::Directory);
59     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
60     page2 = addPage(p2, i18n("Environment"), "terminal");
61
62     QWidget *p4 = new QWidget;
63     m_configCapture.setupUi(p4);
64     page4 = addPage(p4, i18n("Capture"), "audio-card");
65     m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
66
67     QWidget *p5 = new QWidget;
68     m_configShuttle.setupUi(p5);
69 #ifndef NO_JOGSHUTTLE
70     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
71     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
72     slotCheckShuttle(KdenliveSettings::enableshuttle());
73     m_configShuttle.shuttledisabled->hide();
74 #else
75     m_configShuttle.kcfg_enableshuttle->hide();
76     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
77 #endif /* NO_JOGSHUTTLE */
78     page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
79
80     QWidget *p6 = new QWidget;
81     m_configSdl.setupUi(p6);
82     page6 = addPage(p6, i18n("Playback"), "audio-card");
83
84     QStringList actions;
85     actions << i18n("Do nothing");
86     actions << i18n("Play / Pause");
87     actions << i18n("Cut");
88     m_configShuttle.kcfg_shuttle1->addItems(actions);
89     m_configShuttle.kcfg_shuttle2->addItems(actions);
90     m_configShuttle.kcfg_shuttle3->addItems(actions);
91     m_configShuttle.kcfg_shuttle4->addItems(actions);
92     m_configShuttle.kcfg_shuttle5->addItems(actions);
93
94     connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
95     connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
96     connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
97     connect(m_configCapture.kcfg_video4aformat, 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
132     if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
133         QString dvgrabpath = KStandardDirs::findExe("dvgrab");
134         KdenliveSettings::setDvgrab_path(dvgrabpath);
135     }
136
137
138     double dvgrabVersion = 0;
139     if (!KdenliveSettings::dvgrab_path().isEmpty()) {
140         QProcess *versionCheck = new QProcess;
141         versionCheck->setProcessChannelMode(QProcess::MergedChannels);
142         versionCheck->start("dvgrab", QStringList() << "--version");
143         if (versionCheck->waitForFinished()) {
144             QString version = QString(versionCheck->readAll()).simplified();
145             if (version.contains(' ')) version = version.section(' ', -1);
146             dvgrabVersion = version.toDouble();
147
148             kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
149         }
150         if (versionCheck) delete versionCheck;
151         if (dvgrabVersion < 3.3) {
152             KdenliveSettings::setFirewiretimestamp(false);
153             m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
154         }
155         m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
156     } else m_configCapture.dvgrab_info->setText("<strong>" + i18n("<em>dvgrab</em> utility not found, please install it for firewire capture") + "</strong>");
157
158     if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
159         QString rmdpath = KStandardDirs::findExe("recordmydesktop");
160         KdenliveSettings::setRmd_path(rmdpath);
161     }
162     if (KdenliveSettings::rmd_path().isEmpty()) m_configCapture.rmd_info->setText("<strong>" + i18n("<em>Recordmydesktop</em> utility not found, please install it for screen grabs") + "</strong>");
163     else m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
164 }
165
166 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
167
168 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus() {
169     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
170 }
171
172 void KdenliveSettingsDialog::checkProfile() {
173     if (!KdenliveSettings::default_profile().isEmpty()) {
174         for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
175             if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
176                 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
177                 KdenliveSettings::setProfiles_list(i);
178                 break;
179             }
180         }
181     }
182 }
183
184 void KdenliveSettingsDialog::initDevices() {
185     // Fill audio drivers
186     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
187     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
188     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
189     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
190     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
191     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
192
193     /*if (!KdenliveSettings::audiodriver().isEmpty())
194     for (uint i = 1;i < m_configDisplay.kcfg_audio_driver->count(); i++) {
195      if (m_configDisplay.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodriver())
196     m_configDisplay.kcfg_audio_driver->setCurrentIndex(i);
197     }*/
198
199     // Fill video drivers
200     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
201     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
202     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
203     m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga");
204     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
205     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
206     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
207     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
208     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
209     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
210
211     // Fill the list of audio playback devices
212     m_configSdl.audio_device->addItem(i18n("Default"), QString());
213     m_configCapture.rmd_alsa_device->addItem(i18n("Default"), QString());
214     if (KStandardDirs::findExe("aplay") != QString::null) {
215         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
216         m_readProcess.setProgram("aplay", QStringList() << "-l");
217         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
218         m_readProcess.execute(5000);
219     } else {
220         // If aplay is not installed on the system, parse the /proc/asound/pcm file
221         QFile file("/proc/asound/pcm");
222         if (file.open(QIODevice::ReadOnly)) {
223             QTextStream stream(&file);
224             QString line;
225             QString deviceId;
226             while (!stream.atEnd()) {
227                 line = stream.readLine();
228                 if (line.contains("playback")) {
229                     deviceId = line.section(":", 0, 0);
230                     m_configSdl.audio_device->addItem(line.section(":", 1, 1), "plughw:" + QString::number(deviceId.section("-", 0, 0).toInt()) + "," + QString::number(deviceId.section("-", 1, 1).toInt()));
231                 }
232                 if (line.contains("capture")) {
233                     deviceId = line.section(":", 0, 0);
234                     m_configCapture.rmd_alsa_device->addItem(line.section(":", 1, 1), "plughw:" + QString::number(deviceId.section("-", 0, 0).toInt()) + "," + QString::number(deviceId.section("-", 1, 1).toInt()));
235                 }
236             }
237             file.close();
238         }
239     }
240     if (!KdenliveSettings::audiodevicename().isEmpty()) {
241         // Select correct alsa device
242         int ix = m_configSdl.audio_device->findData(KdenliveSettings::audiodevicename());
243         if (ix > 0) m_configSdl.audio_device->setCurrentIndex(ix);
244     }
245     if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
246         // Select correct alsa device
247         int ix = m_configCapture.rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
248         if (ix > 0) m_configCapture.rmd_alsa_device->setCurrentIndex(ix);
249     }
250 }
251
252
253 void KdenliveSettingsDialog::slotReadAudioDevices() {
254     QString result = QString(m_readProcess.readAllStandardOutput());
255     kDebug() << "// / / / / / READING APLAY: ";
256     kDebug() << result;
257     QStringList lines = result.split('\n');
258     foreach(QString data, lines) {
259         kDebug() << "// READING LINE: " << data;
260         if (data.simplified().startsWith("card")) {
261             QString card = data.section(":", 0, 0).section(" ", -1);
262             QString device = data.section(":", 1, 1).section(" ", -1);
263             m_configSdl.audio_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
264             m_configCapture.rmd_alsa_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
265         }
266     }
267 }
268
269 void KdenliveSettingsDialog::showPage(int page, int option) {
270     switch (page) {
271     case 1:
272         setCurrentPage(page1);
273         break;
274     case 2:
275         setCurrentPage(page2);
276         break;
277     case 3:
278         setCurrentPage(page3);
279         break;
280     case 4:
281         setCurrentPage(page4);
282         m_configCapture.tabWidget->setCurrentIndex(option);
283         break;
284     case 5:
285         setCurrentPage(page5);
286         break;
287
288     }
289 }
290
291 void KdenliveSettingsDialog::slotEditVideoApplication() {
292     KService::Ptr service;
293     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
294     if (dlg.exec() != QDialog::Accepted)
295         return;
296
297     service = dlg.service();
298     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
299 }
300
301 void KdenliveSettingsDialog::slotEditAudioApplication() {
302     KService::Ptr service;
303     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
304     if (dlg.exec() != QDialog::Accepted)
305         return;
306
307     service = dlg.service();
308     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
309 }
310
311 void KdenliveSettingsDialog::slotEditImageApplication() {
312     KService::Ptr service;
313     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
314     if (dlg.exec() != QDialog::Accepted)
315         return;
316
317     service = dlg.service();
318     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
319 }
320
321 #ifndef NO_JOGSHUTTLE
322 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
323     m_configShuttle.config_group->setEnabled(state);
324     if (m_configShuttle.shuttledevicelist->count() == 0) {
325         // parse devices
326         QString baseName = "/dev/input/event";
327         int fd;
328         for (int i = 0; i < 30; i++) {
329             QString filename = baseName + QString::number(i);
330             kDebug() << "/// CHECKING OFR: " << filename;
331
332             char name[256] = "unknown";
333             fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
334             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
335                 m_configShuttle.shuttledevicelist->addItem(name, filename);
336             }
337             ::close(fd);
338         }
339         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
340     }
341 }
342
343 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
344     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
345     //KdenliveSettings::setShuttledevice(device);
346     m_configShuttle.kcfg_shuttledevice->setText(device);
347 }
348 #endif /* NO_JOGSHUTTLE */
349
350 void KdenliveSettingsDialog::rebuildVideo4Commands() {
351     QString captureCommand;
352     if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
353
354     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();
355     m_configCapture.kcfg_video4capture->setText(captureCommand);
356 }
357
358
359 // virtual protected
360 bool KdenliveSettingsDialog::isDefault() {
361     return KConfigDialog::isDefault();
362 }
363
364 // virtual protected
365 bool KdenliveSettingsDialog::hasChanged() {
366     kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
367
368     if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
369     return KConfigDialog::hasChanged();
370 }
371
372 void KdenliveSettingsDialog::updateSettings() {
373     kDebug() << "// // // KCONFIG UPDATE called";
374     m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
375     KdenliveSettings::setDefault_profile(m_defaultPath);
376
377     bool resetProfile = false;
378     QString value = m_configSdl.audio_device->itemData(m_configSdl.audio_device->currentIndex()).toString();
379     if (value != KdenliveSettings::audiodevicename()) {
380         KdenliveSettings::setAudiodevicename(value);
381         resetProfile = true;
382     }
383
384     value = m_configCapture.rmd_alsa_device->itemData(m_configCapture.rmd_alsa_device->currentIndex()).toString();
385     if (value != KdenliveSettings::rmd_alsadevicename()) {
386         KdenliveSettings::setRmd_alsadevicename(value);
387     }
388
389     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
390     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
391     if (value != KdenliveSettings::rmd_freq()) {
392         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
393         KdenliveSettings::setRmd_freq(value);
394     }
395
396     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
397     if (value != KdenliveSettings::audiodrivername()) {
398         KdenliveSettings::setAudiodrivername(value);
399         resetProfile = true;
400     }
401
402     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
403     if (value != KdenliveSettings::videodrivername()) {
404         KdenliveSettings::setVideodrivername(value);
405         resetProfile = true;
406     }
407
408     bool updatePreview = false;
409     if (m_configSdl.kcfg_dropbframes->isChecked() != KdenliveSettings::dropbframes()) {
410         KdenliveSettings::setDropbframes(m_configSdl.kcfg_dropbframes->isChecked());
411         updatePreview = true;
412     }
413
414     KConfigDialog::updateSettings();
415     if (resetProfile) emit doResetProfile();
416     if (updatePreview) emit updatePreviewSettings();
417 }
418
419 void KdenliveSettingsDialog::slotUpdateDisplay() {
420     QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
421     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
422     m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
423     m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
424     m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
425     m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
426     if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
427     else m_configMisc.p_progressive->setText(i18n("Progressive"));
428     m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
429     m_defaultPath = currentProfile;
430 }
431
432
433 #include "kdenlivesettingsdialog.moc"
434
435