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