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