]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
- Settings dialog: rename "Display" tab to "Timeline"
[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"), "document-new");
60
61     QWidget *p3 = new QWidget;
62     m_configTimeline.setupUi(p3);
63     m_page3 = addPage(p3, i18n("Timeline"), "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())
190         m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
191     else
192         m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
193 }
194
195 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
196
197 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
198 {
199     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
200 }
201
202 void KdenliveSettingsDialog::checkProfile()
203 {
204     m_configProject.kcfg_profiles_list->clear();
205     QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
206     QMapIterator<QString, QString> i(profilesInfo);
207     while (i.hasNext()) {
208         i.next();
209         m_configProject.kcfg_profiles_list->addItem(i.key(), i.value());
210     }
211
212     if (!KdenliveSettings::default_profile().isEmpty()) {
213         for (int i = 0; i < m_configProject.kcfg_profiles_list->count(); i++) {
214             if (m_configProject.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
215                 m_configProject.kcfg_profiles_list->setCurrentIndex(i);
216                 KdenliveSettings::setProfiles_list(i);
217                 break;
218             }
219         }
220     }
221 }
222
223 void KdenliveSettingsDialog::initDevices()
224 {
225     // Fill audio drivers
226     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
227 #ifndef Q_WS_MAC
228     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
229     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
230     m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
231     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
232     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
233     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
234 #endif
235
236     if (!KdenliveSettings::audiodrivername().isEmpty())
237         for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); i++) {
238             if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
239                 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
240                 KdenliveSettings::setAudio_driver((uint) i);
241             }
242         }
243
244     // Fill video drivers
245     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
246 #ifndef Q_WS_MAC
247     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
248     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
249     m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
250     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
251     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
252     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
253     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
254     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
255     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
256 #endif
257
258     // Fill the list of audio playback devices
259     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
260     m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
261     if (!KStandardDirs::findExe("aplay").isEmpty()) {
262         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
263         m_readProcess.setProgram("aplay", QStringList() << "-l");
264         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
265         m_readProcess.execute(5000);
266     } else {
267         // If aplay is not installed on the system, parse the /proc/asound/pcm file
268         QFile file("/proc/asound/pcm");
269         if (file.open(QIODevice::ReadOnly)) {
270             QTextStream stream(&file);
271             QString line;
272             QString deviceId;
273             while (!stream.atEnd()) {
274                 line = stream.readLine();
275                 if (line.contains("playback")) {
276                     deviceId = line.section(':', 0, 0);
277                     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()));
278                 }
279                 if (line.contains("capture")) {
280                     deviceId = line.section(':', 0, 0);
281                     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()));
282                 }
283             }
284             file.close();
285         }
286     }
287     if (!KdenliveSettings::audiodevicename().isEmpty()) {
288         // Select correct alsa device
289         int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
290         m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
291         KdenliveSettings::setAudio_device(ix);
292     }
293     if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
294         // Select correct alsa device
295         int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
296         m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
297         KdenliveSettings::setRmd_alsa_device(ix);
298     }
299 }
300
301
302 void KdenliveSettingsDialog::slotReadAudioDevices()
303 {
304     QString result = QString(m_readProcess.readAllStandardOutput());
305     kDebug() << "// / / / / / READING APLAY: ";
306     kDebug() << result;
307     QStringList lines = result.split('\n');
308     foreach(const QString &data, lines) {
309         kDebug() << "// READING LINE: " << data;
310         if (data.simplified().startsWith("card")) {
311             QString card = data.section(':', 0, 0).section(' ', -1);
312             QString device = data.section(':', 1, 1).section(' ', -1);
313             m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
314             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
315         }
316     }
317 }
318
319 void KdenliveSettingsDialog::showPage(int page, int option)
320 {
321     switch (page) {
322     case 1:
323         setCurrentPage(m_page1);
324         break;
325     case 2:
326         setCurrentPage(m_page2);
327         break;
328     case 3:
329         setCurrentPage(m_page3);
330         break;
331     case 4:
332         setCurrentPage(m_page4);
333         m_configCapture.tabWidget->setCurrentIndex(option);
334         break;
335     case 5:
336         setCurrentPage(m_page5);
337         break;
338     case 6:
339         setCurrentPage(m_page6);
340         break;
341     case 7:
342         setCurrentPage(m_page7);
343         break;
344     default:
345         setCurrentPage(m_page1);
346     }
347 }
348
349 void KdenliveSettingsDialog::slotEditVideoApplication()
350 {
351     KService::Ptr service;
352     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
353     if (dlg.exec() != QDialog::Accepted)
354         return;
355
356     service = dlg.service();
357     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
358 }
359
360 void KdenliveSettingsDialog::slotEditAudioApplication()
361 {
362     KService::Ptr service;
363     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
364     if (dlg.exec() != QDialog::Accepted)
365         return;
366
367     service = dlg.service();
368     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
369 }
370
371 void KdenliveSettingsDialog::slotEditImageApplication()
372 {
373     KService::Ptr service;
374     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
375     if (dlg.exec() != QDialog::Accepted)
376         return;
377
378     service = dlg.service();
379     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
380 }
381
382 #ifndef NO_JOGSHUTTLE
383 void KdenliveSettingsDialog::slotCheckShuttle(int state)
384 {
385     m_configShuttle.config_group->setEnabled(state);
386     if (m_configShuttle.shuttledevicelist->count() == 0) {
387         // parse devices
388         QString baseName = "/dev/input/event";
389         int fd;
390         for (int i = 0; i < 30; i++) {
391             QString filename = baseName + QString::number(i);
392             kDebug() << "/// CHECKING OFR: " << filename;
393
394             char name[256] = "unknown";
395             fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
396             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
397                 m_configShuttle.shuttledevicelist->addItem(name, filename);
398             }
399             ::close(fd);
400         }
401         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
402     }
403 }
404
405 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
406 {
407     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
408     //KdenliveSettings::setShuttledevice(device);
409     m_configShuttle.kcfg_shuttledevice->setText(device);
410 }
411 #endif /* NO_JOGSHUTTLE */
412
413 void KdenliveSettingsDialog::rebuildVideo4Commands()
414 {
415     QString captureCommand;
416     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();
417
418     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();
419     m_configCapture.kcfg_video4capture->setText(captureCommand);
420 }
421
422
423 void KdenliveSettingsDialog::updateSettings()
424 {
425     //kDebug() << "// // // KCONFIG UPDATE called";
426
427     m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
428     KdenliveSettings::setDefault_profile(m_defaultPath);
429
430     bool resetProfile = false;
431     bool updateCapturePath = false;
432
433     if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
434         KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
435         updateCapturePath = true;
436     }
437
438     if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
439         KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
440         updateCapturePath = true;
441     }
442
443     if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
444         KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
445         updateCapturePath = true;
446     }
447
448     if (updateCapturePath) emit updateCaptureFolder();
449
450     QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
451     if (value != KdenliveSettings::rmd_alsadevicename()) {
452         KdenliveSettings::setRmd_alsadevicename(value);
453     }
454
455     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
456     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
457     if (value != KdenliveSettings::rmd_freq()) {
458         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
459         KdenliveSettings::setRmd_freq(value);
460     }
461
462     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
463     if (value != KdenliveSettings::audiodrivername()) {
464         KdenliveSettings::setAudiodrivername(value);
465         resetProfile = true;
466     }
467
468     if (value == "alsa") {
469         // Audio device setting is only valid for alsa driver
470         value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
471         if (value != KdenliveSettings::audiodevicename()) {
472             KdenliveSettings::setAudiodevicename(value);
473             resetProfile = true;
474         }
475     } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
476         KdenliveSettings::setAudiodevicename(QString::null);
477         resetProfile = true;
478     }
479
480     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
481     if (value != KdenliveSettings::videodrivername()) {
482         KdenliveSettings::setVideodrivername(value);
483         resetProfile = true;
484     }
485
486     if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
487         KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
488         resetProfile = true;
489     }
490
491     if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
492         KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
493         resetProfile = true;
494     }
495
496     bool updatePreview = false;
497     if (m_configSdl.kcfg_dropbframes->isChecked() != KdenliveSettings::dropbframes()) {
498         KdenliveSettings::setDropbframes(m_configSdl.kcfg_dropbframes->isChecked());
499         updatePreview = true;
500     }
501
502     if (m_modified) {
503         // The transcoding profiles were modified, save.
504         m_modified = false;
505         saveTranscodeProfiles();
506     }
507
508 #if KDE_IS_VERSION(4,3,0)
509     KConfigDialog::settingsChangedSlot();
510 #endif
511
512     //KConfigDialog::updateSettings();
513     if (resetProfile) emit doResetProfile();
514     if (updatePreview) emit updatePreviewSettings();
515 }
516
517 void KdenliveSettingsDialog::slotUpdateDisplay()
518 {
519     QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
520     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
521     m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
522     m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
523     m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
524     m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
525     if (values.value("progressive").toInt() == 0)
526         m_configProject.p_progressive->setText(i18n("Interlaced"));
527     else
528         m_configProject.p_progressive->setText(i18n("Progressive"));
529     m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
530     m_defaultPath = currentProfile;
531 }
532
533 void KdenliveSettingsDialog::slotCheckAlsaDriver()
534 {
535     QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
536     m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
537 }
538
539 void KdenliveSettingsDialog::loadTranscodeProfiles()
540 {
541     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
542     KConfigGroup transConfig(config, "Transcoding");
543     // read the entries
544     m_configTranscode.profiles_list->blockSignals(true);
545     QMap< QString, QString > profiles = transConfig.entryMap();
546     QMapIterator<QString, QString> i(profiles);
547     while (i.hasNext()) {
548         i.next();
549         QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
550         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
551     }
552     m_configTranscode.profiles_list->blockSignals(false);
553 }
554
555 void KdenliveSettingsDialog::saveTranscodeProfiles()
556 {
557     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
558     //KSharedConfigPtr config = KGlobal::config();
559     KConfigGroup transConfig(config, "Transcoding");
560     // read the entries
561     transConfig.deleteGroup();
562     int max = m_configTranscode.profiles_list->topLevelItemCount();
563     for (int i = 0; i < max; i++) {
564         QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
565         transConfig.writeEntry(item->text(0), item->text(1));
566     }
567     config->sync();
568 }
569
570 void KdenliveSettingsDialog::slotAddTranscode()
571 {
572     QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
573     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
574     m_configTranscode.profiles_list->setCurrentItem(item);
575     m_configTranscode.profiles_list->editItem(item);
576     slotDialogModified();
577 }
578
579 void KdenliveSettingsDialog::slotDeleteTranscode()
580 {
581     QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
582     if (item == NULL) return;
583     delete item;
584     slotDialogModified();
585 }
586
587 void KdenliveSettingsDialog::slotDialogModified()
588 {
589     m_modified = true;
590 #if KDE_IS_VERSION(4,3,0)
591     KConfigDialog::updateButtons();
592 #endif
593 }
594
595 //virtual
596 bool KdenliveSettingsDialog::hasChanged()
597 {
598     if (m_modified) return true;
599     return KConfigDialog::hasChanged();
600 }
601
602
603
604 #include "kdenlivesettingsdialog.moc"
605
606