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