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