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