]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Display webcam pixel format in wizard
[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 "v4l/v4lcapture.h"
23 #include "blackmagic/devices.h"
24 #include "kdenlivesettings.h"
25
26 #include <KStandardDirs>
27 #include <KDebug>
28 #include <kopenwithdialog.h>
29 #include <KConfigDialogManager>
30 #include <kde_file.h>
31 #include <KIO/NetAccess>
32 #include <kdeversion.h>
33
34 #include <QDir>
35 #include <QTimer>
36 #include <QTreeWidgetItem>
37
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <unistd.h>
41 #include <fcntl.h>
42 #ifndef NO_JOGSHUTTLE
43 #include <linux/input.h>
44 #endif /* NO_JOGSHUTTLE */
45
46
47 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent) :
48     KConfigDialog(parent, "settings", KdenliveSettings::self()),
49     m_modified(false)
50 {
51
52     QWidget *p1 = new QWidget;
53     m_configMisc.setupUi(p1);
54     m_page1 = addPage(p1, i18n("Misc"), "configure");
55
56     // Hide multi tab option until Kdenlive really supports it
57     m_configMisc.kcfg_activatetabs->setVisible(false);
58
59     QWidget *p8 = new QWidget;
60     m_configProject.setupUi(p8);
61     m_page8 = addPage(p8, i18n("Project Defaults"), "document-new");
62
63     QWidget *p3 = new QWidget;
64     m_configTimeline.setupUi(p3);
65     m_page3 = addPage(p3, i18n("Timeline"), "video-display");
66
67     QWidget *p2 = new QWidget;
68     m_configEnv.setupUi(p2);
69     m_configEnv.mltpathurl->setMode(KFile::Directory);
70     m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
71     m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
72     m_configEnv.tmppathurl->setMode(KFile::Directory);
73     m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
74     m_configEnv.projecturl->setMode(KFile::Directory);
75     m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
76     m_configEnv.capturefolderurl->setMode(KFile::Directory);
77     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
78     m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
79     connect(m_configEnv.kcfg_capturetoprojectfolder, SIGNAL(clicked()), this, SLOT(slotEnableCaptureFolder()));
80     m_page2 = addPage(p2, i18n("Environment"), "application-x-executable-script");
81
82     QWidget *p4 = new QWidget;
83     m_configCapture.setupUi(p4);
84
85     V4lCaptureHandler v4l(NULL);
86     // Video 4 Linux device detection
87     for (int i = 0; i < 10; i++) {
88         QString path = "/dev/video" + QString::number(i);
89         if (QFile::exists(path)) {
90             QStringList deviceInfo = v4l.getDeviceName(path);
91             m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
92             m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
93         }
94     }
95     connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice()));
96
97
98     m_page4 = addPage(p4, i18n("Capture"), "media-record");
99     m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
100 #ifdef Q_WS_MAC
101     m_configCapture.tabWidget->setEnabled(false);
102     m_configCapture.kcfg_defaultcapture->setEnabled(false);
103     m_configCapture.label->setText(i18n("Capture is not yet available on OS X."));
104 #endif
105
106     QWidget *p5 = new QWidget;
107     m_configShuttle.setupUi(p5);
108 #ifndef NO_JOGSHUTTLE
109     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
110     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
111     slotCheckShuttle(KdenliveSettings::enableshuttle());
112     m_configShuttle.shuttledisabled->hide();
113 #else
114     m_configShuttle.kcfg_enableshuttle->hide();
115     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
116 #endif /* NO_JOGSHUTTLE */
117     m_page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
118
119     QWidget *p6 = new QWidget;
120     m_configSdl.setupUi(p6);
121
122     // Disable drop B frames, see Kdenlive issue #1330
123     m_configSdl.groupBox->setHidden(true);
124 #if not defined(Q_WS_MAC) && not defined(USE_OPEN_GL)
125     m_configSdl.kcfg_openglmonitors->setHidden(true);
126 #endif
127
128     m_page6 = addPage(p6, i18n("Playback"), "media-playback-start");
129
130     QWidget *p7 = new QWidget;
131     m_configTranscode.setupUi(p7);
132     m_page7 = addPage(p7, i18n("Transcode"), "edit-copy");
133     connect(m_configTranscode.button_add, SIGNAL(clicked()), this, SLOT(slotAddTranscode()));
134     connect(m_configTranscode.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteTranscode()));
135     connect(m_configTranscode.profiles_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotDialogModified()));
136
137     QStringList actions;
138     actions << i18n("Do nothing");
139     actions << i18n("Play / Pause");
140     actions << i18n("Cut");
141     m_configShuttle.kcfg_shuttle1->addItems(actions);
142     m_configShuttle.kcfg_shuttle2->addItems(actions);
143     m_configShuttle.kcfg_shuttle3->addItems(actions);
144     m_configShuttle.kcfg_shuttle4->addItems(actions);
145     m_configShuttle.kcfg_shuttle5->addItems(actions);
146
147     connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
148     connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
149     connect(m_configCapture.kcfg_video4vcodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
150     connect(m_configCapture.kcfg_video4acodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
151     connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
152     connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
153     connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
154     connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
155
156     connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
157
158     m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
159
160     connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
161     connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
162     connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
163
164     checkProfile();
165
166     slotUpdateDisplay();
167
168     connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
169     initDevices();
170     connect(m_configProject.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
171     connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
172
173     slotUpdateRmdRegionStatus();
174     loadTranscodeProfiles();
175
176
177     //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
178     //   --timestamp option without bug
179
180     if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
181         QString dvgrabpath = KStandardDirs::findExe("dvgrab");
182         KdenliveSettings::setDvgrab_path(dvgrabpath);
183     }
184
185
186     BMInterface::getBlackMagicDeviceList(m_configCapture.kcfg_hdmi_capturedevice, m_configCapture.kcfg_hdmi_capturemode);
187     connect(m_configCapture.kcfg_hdmi_capturedevice, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHDMIModes()));
188
189     double dvgrabVersion = 0;
190     if (!KdenliveSettings::dvgrab_path().isEmpty()) {
191         QProcess *versionCheck = new QProcess;
192         versionCheck->setProcessChannelMode(QProcess::MergedChannels);
193         versionCheck->start("dvgrab", QStringList() << "--version");
194         if (versionCheck->waitForFinished()) {
195             QString version = QString(versionCheck->readAll()).simplified();
196             if (version.contains(' ')) version = version.section(' ', -1);
197             dvgrabVersion = version.toDouble();
198
199             kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
200         }
201         delete versionCheck;
202         if (dvgrabVersion < 3.3) {
203             KdenliveSettings::setFirewiretimestamp(false);
204             m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
205         }
206         m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
207     } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
208
209     if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
210         QString rmdpath = KStandardDirs::findExe("recordmydesktop");
211         KdenliveSettings::setRmd_path(rmdpath);
212     }
213     if (KdenliveSettings::rmd_path().isEmpty())
214         m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
215     else
216         m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
217 }
218
219 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
220
221 void KdenliveSettingsDialog::slotUpdateHDMIModes()
222 {
223     QStringList modes = m_configCapture.kcfg_hdmi_capturedevice->itemData(m_configCapture.kcfg_hdmi_capturedevice->currentIndex()).toStringList();
224     m_configCapture.kcfg_hdmi_capturemode->clear();
225     m_configCapture.kcfg_hdmi_capturemode->insertItems(0, modes);
226 }
227
228 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
229 {
230     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
231 }
232
233 void KdenliveSettingsDialog::slotEnableCaptureFolder()
234 {
235     m_configEnv.capturefolderurl->setEnabled(!m_configEnv.kcfg_capturetoprojectfolder->isChecked());
236 }
237
238 void KdenliveSettingsDialog::checkProfile()
239 {
240     m_configProject.kcfg_profiles_list->clear();
241     QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
242     QMapIterator<QString, QString> i(profilesInfo);
243     while (i.hasNext()) {
244         i.next();
245         m_configProject.kcfg_profiles_list->addItem(i.key(), i.value());
246     }
247
248     if (!KdenliveSettings::default_profile().isEmpty()) {
249         for (int i = 0; i < m_configProject.kcfg_profiles_list->count(); i++) {
250             if (m_configProject.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
251                 m_configProject.kcfg_profiles_list->setCurrentIndex(i);
252                 KdenliveSettings::setProfiles_list(i);
253                 break;
254             }
255         }
256     }
257 }
258
259 void KdenliveSettingsDialog::initDevices()
260 {
261     // Fill audio drivers
262     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
263 #ifndef Q_WS_MAC
264     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
265     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
266     m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
267     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
268     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
269     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
270 #endif
271
272     if (!KdenliveSettings::audiodrivername().isEmpty())
273         for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); i++) {
274             if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
275                 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
276                 KdenliveSettings::setAudio_driver((uint) i);
277             }
278         }
279
280     // Fill video drivers
281     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
282 #ifndef Q_WS_MAC
283     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
284     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
285     m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
286     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
287     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
288     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
289     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
290     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
291     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
292 #endif
293
294     // Fill the list of audio playback devices
295     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
296     m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
297     if (!KStandardDirs::findExe("aplay").isEmpty()) {
298         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
299         m_readProcess.setProgram("aplay", QStringList() << "-l");
300         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
301         m_readProcess.execute(5000);
302     } else {
303         // If aplay is not installed on the system, parse the /proc/asound/pcm file
304         QFile file("/proc/asound/pcm");
305         if (file.open(QIODevice::ReadOnly)) {
306             QTextStream stream(&file);
307             QString line;
308             QString deviceId;
309             while (!stream.atEnd()) {
310                 line = stream.readLine();
311                 if (line.contains("playback")) {
312                     deviceId = line.section(':', 0, 0);
313                     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()));
314                 }
315                 if (line.contains("capture")) {
316                     deviceId = line.section(':', 0, 0);
317                     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()));
318                 }
319             }
320             file.close();
321         }
322     }
323     if (!KdenliveSettings::audiodevicename().isEmpty()) {
324         // Select correct alsa device
325         int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
326         m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
327         KdenliveSettings::setAudio_device(ix);
328     }
329     if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
330         // Select correct alsa device
331         int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
332         m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
333         KdenliveSettings::setRmd_alsa_device(ix);
334     }
335 }
336
337
338 void KdenliveSettingsDialog::slotReadAudioDevices()
339 {
340     QString result = QString(m_readProcess.readAllStandardOutput());
341     kDebug() << "// / / / / / READING APLAY: ";
342     kDebug() << result;
343     QStringList lines = result.split('\n');
344     foreach(const QString & data, lines) {
345         kDebug() << "// READING LINE: " << data;
346         if (data.simplified().startsWith("card")) {
347             QString card = data.section(':', 0, 0).section(' ', -1);
348             QString device = data.section(':', 1, 1).section(' ', -1);
349             m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
350             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
351         }
352     }
353 }
354
355 void KdenliveSettingsDialog::showPage(int page, int option)
356 {
357     switch (page) {
358     case 1:
359         setCurrentPage(m_page1);
360         break;
361     case 2:
362         setCurrentPage(m_page2);
363         break;
364     case 3:
365         setCurrentPage(m_page3);
366         break;
367     case 4:
368         setCurrentPage(m_page4);
369         m_configCapture.tabWidget->setCurrentIndex(option);
370         break;
371     case 5:
372         setCurrentPage(m_page5);
373         break;
374     case 6:
375         setCurrentPage(m_page6);
376         break;
377     case 7:
378         setCurrentPage(m_page7);
379         break;
380     default:
381         setCurrentPage(m_page1);
382     }
383 }
384
385 void KdenliveSettingsDialog::slotEditVideoApplication()
386 {
387     KService::Ptr service;
388     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
389     if (dlg.exec() != QDialog::Accepted)
390         return;
391
392     service = dlg.service();
393     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
394 }
395
396 void KdenliveSettingsDialog::slotEditAudioApplication()
397 {
398     KService::Ptr service;
399     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
400     if (dlg.exec() != QDialog::Accepted)
401         return;
402
403     service = dlg.service();
404     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
405 }
406
407 void KdenliveSettingsDialog::slotEditImageApplication()
408 {
409     KService::Ptr service;
410     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
411     if (dlg.exec() != QDialog::Accepted)
412         return;
413
414     service = dlg.service();
415     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
416 }
417
418 #ifndef NO_JOGSHUTTLE
419 void KdenliveSettingsDialog::slotCheckShuttle(int state)
420 {
421     m_configShuttle.config_group->setEnabled(state);
422     if (m_configShuttle.shuttledevicelist->count() == 0) {
423         // parse devices
424         QString baseName = "/dev/input/event";
425         int fd;
426         for (int i = 0; i < 30; i++) {
427             QString filename = baseName + QString::number(i);
428             kDebug() << "/// CHECKING OFR: " << filename;
429
430             char name[256] = "unknown";
431             fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
432             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
433                 m_configShuttle.shuttledevicelist->addItem(name, filename);
434             }
435             ::close(fd);
436         }
437         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
438     }
439 }
440
441 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
442 {
443     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
444     //KdenliveSettings::setShuttledevice(device);
445     m_configShuttle.kcfg_shuttledevice->setText(device);
446 }
447 #endif /* NO_JOGSHUTTLE */
448
449 void KdenliveSettingsDialog::rebuildVideo4Commands()
450 {
451     QString captureCommand;
452     if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text() + " -acodec " + m_configCapture.kcfg_video4acodec->text();
453
454     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() + " -vcodec " + m_configCapture.kcfg_video4vcodec->text();
455     m_configCapture.kcfg_video4capture->setText(captureCommand);
456 }
457
458
459 void KdenliveSettingsDialog::updateSettings()
460 {
461     //kDebug() << "// // // KCONFIG UPDATE called";
462
463     m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
464     KdenliveSettings::setDefault_profile(m_defaultPath);
465
466     bool resetProfile = false;
467     bool updateCapturePath = false;
468
469     if (m_configEnv.kcfg_capturetoprojectfolder->isChecked() != KdenliveSettings::capturetoprojectfolder()) {
470         KdenliveSettings::setCapturetoprojectfolder(m_configEnv.kcfg_capturetoprojectfolder->isChecked());
471         updateCapturePath = true;
472     }
473
474     if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
475         KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
476         updateCapturePath = true;
477     }
478
479     if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
480         KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
481         updateCapturePath = true;
482     }
483
484     if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
485         KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
486         updateCapturePath = true;
487     }
488
489     if (updateCapturePath) emit updateCaptureFolder();
490
491     QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
492     if (value != KdenliveSettings::rmd_alsadevicename()) {
493         KdenliveSettings::setRmd_alsadevicename(value);
494     }
495
496     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
497     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
498     if (value != KdenliveSettings::rmd_freq()) {
499         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
500         KdenliveSettings::setRmd_freq(value);
501     }
502
503     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
504     if (value != KdenliveSettings::audiodrivername()) {
505         KdenliveSettings::setAudiodrivername(value);
506         resetProfile = true;
507     }
508
509     if (value == "alsa") {
510         // Audio device setting is only valid for alsa driver
511         value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
512         if (value != KdenliveSettings::audiodevicename()) {
513             KdenliveSettings::setAudiodevicename(value);
514             resetProfile = true;
515         }
516     } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
517         KdenliveSettings::setAudiodevicename(QString::null);
518         resetProfile = true;
519     }
520
521     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
522     if (value != KdenliveSettings::videodrivername()) {
523         KdenliveSettings::setVideodrivername(value);
524         resetProfile = true;
525     }
526
527     if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
528         KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
529         resetProfile = true;
530     }
531
532     if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
533         KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
534         resetProfile = true;
535     }
536
537     bool updatePreview = false;
538     if (m_configSdl.kcfg_dropbframes->isChecked() != KdenliveSettings::dropbframes()) {
539         KdenliveSettings::setDropbframes(m_configSdl.kcfg_dropbframes->isChecked());
540         updatePreview = true;
541     }
542
543     if (m_modified) {
544         // The transcoding profiles were modified, save.
545         m_modified = false;
546         saveTranscodeProfiles();
547     }
548
549 #if KDE_IS_VERSION(4,3,0)
550     KConfigDialog::settingsChangedSlot();
551 #endif
552
553     //KConfigDialog::updateSettings();
554     if (resetProfile) emit doResetProfile();
555     if (updatePreview) emit updatePreviewSettings();
556 }
557
558 void KdenliveSettingsDialog::slotUpdateDisplay()
559 {
560     QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
561     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
562     m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
563     m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
564     m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
565     m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
566     if (values.value("progressive").toInt() == 0)
567         m_configProject.p_progressive->setText(i18n("Interlaced"));
568     else
569         m_configProject.p_progressive->setText(i18n("Progressive"));
570     m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
571     m_defaultPath = currentProfile;
572 }
573
574 void KdenliveSettingsDialog::slotCheckAlsaDriver()
575 {
576     QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
577     m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
578 }
579
580 void KdenliveSettingsDialog::loadTranscodeProfiles()
581 {
582     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
583     KConfigGroup transConfig(config, "Transcoding");
584     // read the entries
585     m_configTranscode.profiles_list->blockSignals(true);
586     QMap< QString, QString > profiles = transConfig.entryMap();
587     QMapIterator<QString, QString> i(profiles);
588     while (i.hasNext()) {
589         i.next();
590         QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
591         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
592     }
593     m_configTranscode.profiles_list->blockSignals(false);
594 }
595
596 void KdenliveSettingsDialog::saveTranscodeProfiles()
597 {
598     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
599     //KSharedConfigPtr config = KGlobal::config();
600     KConfigGroup transConfig(config, "Transcoding");
601     // read the entries
602     transConfig.deleteGroup();
603     int max = m_configTranscode.profiles_list->topLevelItemCount();
604     for (int i = 0; i < max; i++) {
605         QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
606         transConfig.writeEntry(item->text(0), item->text(1));
607     }
608     config->sync();
609 }
610
611 void KdenliveSettingsDialog::slotAddTranscode()
612 {
613     QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
614     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
615     m_configTranscode.profiles_list->setCurrentItem(item);
616     m_configTranscode.profiles_list->editItem(item);
617     slotDialogModified();
618 }
619
620 void KdenliveSettingsDialog::slotDeleteTranscode()
621 {
622     QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
623     if (item == NULL) return;
624     delete item;
625     slotDialogModified();
626 }
627
628 void KdenliveSettingsDialog::slotDialogModified()
629 {
630     m_modified = true;
631 #if KDE_IS_VERSION(4,3,0)
632     KConfigDialog::updateButtons();
633 #endif
634 }
635
636 //virtual
637 bool KdenliveSettingsDialog::hasChanged()
638 {
639     if (m_modified) return true;
640     return KConfigDialog::hasChanged();
641 }
642
643 void KdenliveSettingsDialog::slotUpdatev4lDevice()
644 {
645     QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
646     if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device);
647     QString size = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
648     if (!size.isEmpty()) m_configCapture.kcfg_video4size->setText(size);
649 }
650
651
652 #include "kdenlivesettingsdialog.moc"
653
654