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