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