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