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