]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Big update to the proxy clips, fixing several issues. They can now be deleted in...
[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 #include <QThread>
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <fcntl.h>
43 #ifndef NO_JOGSHUTTLE
44 #include "jogaction.h"
45 #include "jogshuttleconfig.h"
46 #include <linux/input.h>
47 #endif /* NO_JOGSHUTTLE */
48
49
50 KdenliveSettingsDialog::KdenliveSettingsDialog(const QMap<QString, QString>& mappable_actions, QWidget * parent) :
51     KConfigDialog(parent, "settings", KdenliveSettings::self()),
52     m_modified(false),
53     m_shuttleModified(false),
54     m_mappable_actions(mappable_actions)
55 {
56
57     QWidget *p1 = new QWidget;
58     m_configMisc.setupUi(p1);
59     m_page1 = addPage(p1, i18n("Misc"), "configure");
60
61     // Hide multi tab option until Kdenlive really supports it
62     m_configMisc.kcfg_activatetabs->setVisible(false);
63
64     QWidget *p8 = new QWidget;
65     m_configProject.setupUi(p8);
66     m_page8 = addPage(p8, i18n("Project Defaults"), "document-new");
67     connect(m_configProject.kcfg_enableproxy, SIGNAL(toggled(bool)), m_configProject.proxy_frame, SLOT(setEnabled(bool)));
68     m_configProject.proxy_frame->setEnabled(KdenliveSettings::enableproxy());
69
70     QWidget *p3 = new QWidget;
71     m_configTimeline.setupUi(p3);
72     m_page3 = addPage(p3, i18n("Timeline"), "video-display");
73
74     QWidget *p2 = new QWidget;
75     m_configEnv.setupUi(p2);
76     m_configEnv.mltpathurl->setMode(KFile::Directory);
77     m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
78     m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
79     m_configEnv.kcfg_mltthreads->setMaximum(QThread::idealThreadCount());
80     m_configEnv.tmppathurl->setMode(KFile::Directory);
81     m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
82     m_configEnv.projecturl->setMode(KFile::Directory);
83     m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
84     m_configEnv.capturefolderurl->setMode(KFile::Directory);
85     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
86     m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
87     connect(m_configEnv.kcfg_capturetoprojectfolder, SIGNAL(clicked()), this, SLOT(slotEnableCaptureFolder()));
88     m_page2 = addPage(p2, i18n("Environment"), "application-x-executable-script");
89
90     QWidget *p4 = new QWidget;
91     m_configCapture.setupUi(p4);
92
93 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
94     V4lCaptureHandler v4l(NULL);
95     // Video 4 Linux device detection
96     for (int i = 0; i < 10; i++) {
97         QString path = "/dev/video" + QString::number(i);
98         if (QFile::exists(path)) {
99             QStringList deviceInfo = v4l.getDeviceName(path);
100             if (!deviceInfo.isEmpty()) {
101                 m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
102                 m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
103             }
104         }
105     }
106     connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice()));
107 #endif
108
109     m_page4 = addPage(p4, i18n("Capture"), "media-record");
110     m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
111 #ifdef Q_WS_MAC
112     m_configCapture.tabWidget->setEnabled(false);
113     m_configCapture.kcfg_defaultcapture->setEnabled(false);
114     m_configCapture.label->setText(i18n("Capture is not yet available on OS X."));
115 #endif
116
117     QWidget *p5 = new QWidget;
118     m_configShuttle.setupUi(p5);
119 #ifdef NO_JOGSHUTTLE
120     m_configShuttle.kcfg_enableshuttle->hide();
121     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
122 #else
123     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
124     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
125     slotCheckShuttle(KdenliveSettings::enableshuttle());
126     m_configShuttle.shuttledisabled->hide();
127
128     // Store the button pointers into an array for easier handling them in the other functions.
129     m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
130     m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
131     m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
132     m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
133     m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
134
135     // populate the buttons with the current configuration. The items are sorted
136     // according to the user-selected language, so they do not appear in random order.
137     QList<QString> action_names = mappable_actions.keys();
138     qSort(action_names);
139
140     // Here we need to compute the action_id -> index-in-action_names. We iterate over the
141     // action_names, as the sorting may depend on the user-language.
142     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
143     QMap<QString, int> action_pos;
144     foreach (const QString& action_id, actions_map) {
145       // This loop find out at what index is the string that would map to the action_id.
146       for (int i = 0; i < action_names.size(); i++) {
147           if (mappable_actions[action_names[i]] == action_id) {
148               action_pos[action_id] = i;
149               break;
150           }
151       }
152     }
153
154     int i = 0;
155     foreach (KComboBox* button, m_shuttle_buttons) {
156       button->addItems(action_names);
157       connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
158       ++i;
159       if (i < actions_map.size())
160         button->setCurrentIndex(action_pos[actions_map[i]]);
161     }
162 #endif /* NO_JOGSHUTTLE */
163     m_page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
164
165     QWidget *p6 = new QWidget;
166     m_configSdl.setupUi(p6);
167
168 #if not defined(Q_WS_MAC) && not defined(USE_OPEN_GL)
169     m_configSdl.kcfg_openglmonitors->setHidden(true);
170 #endif
171
172     m_page6 = addPage(p6, i18n("Playback"), "media-playback-start");
173
174     QWidget *p7 = new QWidget;
175     m_configTranscode.setupUi(p7);
176     m_page7 = addPage(p7, i18n("Transcode"), "edit-copy");
177     connect(m_configTranscode.button_add, SIGNAL(clicked()), this, SLOT(slotAddTranscode()));
178     connect(m_configTranscode.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteTranscode()));
179     connect(m_configTranscode.profiles_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotDialogModified()));
180     
181     connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
182     connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
183     connect(m_configCapture.kcfg_video4vcodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
184     connect(m_configCapture.kcfg_video4acodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
185     connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
186     connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
187     connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
188     connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
189
190     connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
191
192     m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
193
194     connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
195     connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
196     connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
197
198     checkProfile();
199
200     slotUpdateDisplay();
201
202     connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
203     initDevices();
204     connect(m_configProject.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
205     connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
206
207     slotUpdateRmdRegionStatus();
208     loadTranscodeProfiles();
209
210
211     //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
212     //   --timestamp option without bug
213
214     if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
215         QString dvgrabpath = KStandardDirs::findExe("dvgrab");
216         KdenliveSettings::setDvgrab_path(dvgrabpath);
217     }
218
219
220     BMInterface::getBlackMagicDeviceList(m_configCapture.kcfg_hdmi_capturedevice, m_configCapture.kcfg_hdmi_capturemode);
221     connect(m_configCapture.kcfg_hdmi_capturedevice, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHDMIModes()));
222
223     if (BMInterface::getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
224         // Found blackmagic card
225     } else m_configSdl.kcfg_external_display->setEnabled(false);
226
227     double dvgrabVersion = 0;
228     if (!KdenliveSettings::dvgrab_path().isEmpty()) {
229         QProcess *versionCheck = new QProcess;
230         versionCheck->setProcessChannelMode(QProcess::MergedChannels);
231         versionCheck->start("dvgrab", QStringList() << "--version");
232         if (versionCheck->waitForFinished()) {
233             QString version = QString(versionCheck->readAll()).simplified();
234             if (version.contains(' ')) version = version.section(' ', -1);
235             dvgrabVersion = version.toDouble();
236
237             kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
238         }
239         delete versionCheck;
240         if (dvgrabVersion < 3.3) {
241             KdenliveSettings::setFirewiretimestamp(false);
242             m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
243         }
244         m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
245     } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
246
247     if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
248         QString rmdpath = KStandardDirs::findExe("recordmydesktop");
249         KdenliveSettings::setRmd_path(rmdpath);
250     }
251     if (KdenliveSettings::rmd_path().isEmpty())
252         m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
253     else
254         m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
255 }
256
257 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
258
259 void KdenliveSettingsDialog::slotUpdateHDMIModes()
260 {
261     QStringList modes = m_configCapture.kcfg_hdmi_capturedevice->itemData(m_configCapture.kcfg_hdmi_capturedevice->currentIndex()).toStringList();
262     m_configCapture.kcfg_hdmi_capturemode->clear();
263     m_configCapture.kcfg_hdmi_capturemode->insertItems(0, modes);
264 }
265
266 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
267 {
268     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
269 }
270
271 void KdenliveSettingsDialog::slotEnableCaptureFolder()
272 {
273     m_configEnv.capturefolderurl->setEnabled(!m_configEnv.kcfg_capturetoprojectfolder->isChecked());
274 }
275
276 void KdenliveSettingsDialog::checkProfile()
277 {
278     m_configProject.kcfg_profiles_list->clear();
279     QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
280     QMapIterator<QString, QString> i(profilesInfo);
281     while (i.hasNext()) {
282         i.next();
283         m_configProject.kcfg_profiles_list->addItem(i.key(), i.value());
284     }
285
286     if (!KdenliveSettings::default_profile().isEmpty()) {
287         for (int i = 0; i < m_configProject.kcfg_profiles_list->count(); i++) {
288             if (m_configProject.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
289                 m_configProject.kcfg_profiles_list->setCurrentIndex(i);
290                 KdenliveSettings::setProfiles_list(i);
291                 break;
292             }
293         }
294     }
295 }
296
297 void KdenliveSettingsDialog::initDevices()
298 {
299     // Fill audio drivers
300     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
301 #ifndef Q_WS_MAC
302     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
303     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
304     m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
305     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
306     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
307     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
308 #endif
309
310     if (!KdenliveSettings::audiodrivername().isEmpty())
311         for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); i++) {
312             if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
313                 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
314                 KdenliveSettings::setAudio_driver((uint) i);
315             }
316         }
317
318     // Fill video drivers
319     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
320 #ifndef Q_WS_MAC
321     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
322     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
323     m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
324     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
325     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
326     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
327     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
328     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
329     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
330 #endif
331
332     // Fill the list of audio playback devices
333     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
334     m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
335     if (!KStandardDirs::findExe("aplay").isEmpty()) {
336         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
337         m_readProcess.setProgram("aplay", QStringList() << "-l");
338         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
339         m_readProcess.execute(5000);
340     } else {
341         // If aplay is not installed on the system, parse the /proc/asound/pcm file
342         QFile file("/proc/asound/pcm");
343         if (file.open(QIODevice::ReadOnly)) {
344             QTextStream stream(&file);
345             QString line;
346             QString deviceId;
347             while (!stream.atEnd()) {
348                 line = stream.readLine();
349                 if (line.contains("playback")) {
350                     deviceId = line.section(':', 0, 0);
351                     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()));
352                 }
353                 if (line.contains("capture")) {
354                     deviceId = line.section(':', 0, 0);
355                     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()));
356                 }
357             }
358             file.close();
359         }
360     }
361     if (!KdenliveSettings::audiodevicename().isEmpty()) {
362         // Select correct alsa device
363         int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
364         m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
365         KdenliveSettings::setAudio_device(ix);
366     }
367     if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
368         // Select correct alsa device
369         int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
370         m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
371         KdenliveSettings::setRmd_alsa_device(ix);
372     }
373 }
374
375
376 void KdenliveSettingsDialog::slotReadAudioDevices()
377 {
378     QString result = QString(m_readProcess.readAllStandardOutput());
379     kDebug() << "// / / / / / READING APLAY: ";
380     kDebug() << result;
381     QStringList lines = result.split('\n');
382     foreach(const QString & data, lines) {
383         kDebug() << "// READING LINE: " << data;
384         if (data.simplified().startsWith("card")) {
385             QString card = data.section(':', 0, 0).section(' ', -1);
386             QString device = data.section(':', 1, 1).section(' ', -1);
387             m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
388             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
389         }
390     }
391 }
392
393 void KdenliveSettingsDialog::showPage(int page, int option)
394 {
395     switch (page) {
396     case 1:
397         setCurrentPage(m_page1);
398         break;
399     case 2:
400         setCurrentPage(m_page2);
401         break;
402     case 3:
403         setCurrentPage(m_page3);
404         break;
405     case 4:
406         setCurrentPage(m_page4);
407         m_configCapture.tabWidget->setCurrentIndex(option);
408         break;
409     case 5:
410         setCurrentPage(m_page5);
411         break;
412     case 6:
413         setCurrentPage(m_page6);
414         break;
415     case 7:
416         setCurrentPage(m_page7);
417         break;
418     default:
419         setCurrentPage(m_page1);
420     }
421 }
422
423 void KdenliveSettingsDialog::slotEditVideoApplication()
424 {
425     KService::Ptr service;
426     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
427     if (dlg.exec() != QDialog::Accepted)
428         return;
429
430     service = dlg.service();
431     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
432 }
433
434 void KdenliveSettingsDialog::slotEditAudioApplication()
435 {
436     KService::Ptr service;
437     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
438     if (dlg.exec() != QDialog::Accepted)
439         return;
440
441     service = dlg.service();
442     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
443 }
444
445 void KdenliveSettingsDialog::slotEditImageApplication()
446 {
447     KService::Ptr service;
448     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
449     if (dlg.exec() != QDialog::Accepted)
450         return;
451
452     service = dlg.service();
453     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
454 }
455
456 #ifndef NO_JOGSHUTTLE
457 void KdenliveSettingsDialog::slotCheckShuttle(int state)
458 {
459     m_configShuttle.config_group->setEnabled(state);
460     if (m_configShuttle.shuttledevicelist->count() == 0) {
461         // parse devices
462         QString baseName = "/dev/input/event";
463         int fd;
464         for (int i = 0; i < 30; i++) {
465             QString filename = baseName + QString::number(i);
466             kDebug() << "/// CHECKING OFR: " << filename;
467
468             char name[256] = "unknown";
469             fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
470             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
471                 m_configShuttle.shuttledevicelist->addItem(name, filename);
472             }
473             ::close(fd);
474         }
475         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
476     }
477 }
478
479 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
480 {
481     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
482     //KdenliveSettings::setShuttledevice(device);
483     m_configShuttle.kcfg_shuttledevice->setText(device);
484 }
485
486 #endif /* NO_JOGSHUTTLE */
487
488 void KdenliveSettingsDialog::rebuildVideo4Commands()
489 {
490     QString captureCommand;
491     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();
492
493     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();
494     m_configCapture.kcfg_video4capture->setText(captureCommand);
495 }
496 void KdenliveSettingsDialog::updateWidgets()
497 {
498     // Revert widgets to last saved state (for example when user pressed "Cancel")
499     // kDebug() << "// // // KCONFIG Revert called";
500 #ifndef NO_JOGSHUTTLE
501     // revert jog shuttle device
502     if (m_configShuttle.shuttledevicelist->count() > 0) {
503         for (int i = 0; i < m_configShuttle.shuttledevicelist->count(); i++) {
504             if (m_configShuttle.shuttledevicelist->itemData(i) == KdenliveSettings::shuttledevice()) {
505                 m_configShuttle.shuttledevicelist->setCurrentIndex(i);
506                 break;
507             }
508         }
509     }
510
511     // Revert jog shuttle buttons
512     QList<QString> action_names = m_mappable_actions.keys();
513     qSort(action_names);
514     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
515     QMap<QString, int> action_pos;
516     foreach (const QString& action_id, actions_map) {
517       // This loop find out at what index is the string that would map to the action_id.
518       for (int i = 0; i < action_names.size(); i++) {
519           if (m_mappable_actions[action_names[i]] == action_id) {
520               action_pos[action_id] = i;
521               break;
522           }
523       }
524     }
525     int i = 0;
526     foreach (KComboBox* button, m_shuttle_buttons) {
527       ++i;
528       if (i < actions_map.size())
529         button->setCurrentIndex(action_pos[actions_map[i]]);
530     }
531 #endif
532 }
533
534 void KdenliveSettingsDialog::updateSettings()
535 {
536     // Save changes to settings (for example when user pressed "Apply" or "Ok")
537     // kDebug() << "// // // KCONFIG UPDATE called";
538     m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
539     KdenliveSettings::setDefault_profile(m_defaultPath);
540
541     bool resetProfile = false;
542     bool updateCapturePath = false;
543     
544     /*if (m_configShuttle.shuttledevicelist->count() > 0) {
545         QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
546         if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
547     }*/
548
549     if (m_configEnv.kcfg_capturetoprojectfolder->isChecked() != KdenliveSettings::capturetoprojectfolder()) {
550         KdenliveSettings::setCapturetoprojectfolder(m_configEnv.kcfg_capturetoprojectfolder->isChecked());
551         updateCapturePath = true;
552     }
553
554     if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
555         KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
556         updateCapturePath = true;
557     }
558
559     if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
560         KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
561         updateCapturePath = true;
562     }
563
564     if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
565         KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
566         updateCapturePath = true;
567     }
568
569     if (updateCapturePath) emit updateCaptureFolder();
570
571     QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
572     if (value != KdenliveSettings::rmd_alsadevicename()) {
573         KdenliveSettings::setRmd_alsadevicename(value);
574     }
575
576     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
577     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
578     if (value != KdenliveSettings::rmd_freq()) {
579         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
580         KdenliveSettings::setRmd_freq(value);
581     }
582
583     if (m_configSdl.kcfg_external_display->isChecked() != KdenliveSettings::external_display()) {
584         KdenliveSettings::setExternal_display(m_configSdl.kcfg_external_display->isChecked());
585         resetProfile = true;
586     }
587
588     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
589     if (value != KdenliveSettings::audiodrivername()) {
590         KdenliveSettings::setAudiodrivername(value);
591         resetProfile = true;
592     }
593
594     if (value == "alsa") {
595         // Audio device setting is only valid for alsa driver
596         value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
597         if (value != KdenliveSettings::audiodevicename()) {
598             KdenliveSettings::setAudiodevicename(value);
599             resetProfile = true;
600         }
601     } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
602         KdenliveSettings::setAudiodevicename(QString::null);
603         resetProfile = true;
604     }
605
606     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
607     if (value != KdenliveSettings::videodrivername()) {
608         KdenliveSettings::setVideodrivername(value);
609         resetProfile = true;
610     }
611
612     if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
613         KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
614         resetProfile = true;
615     }
616
617     if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
618         KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
619         resetProfile = true;
620     }
621     
622     if (m_configProject.kcfg_enableproxy->isChecked() != KdenliveSettings::enableproxy()) {
623         KdenliveSettings::setEnableproxy(m_configProject.kcfg_enableproxy->isChecked());
624     }
625     
626     if (m_configProject.kcfg_generateproxy->isChecked() != KdenliveSettings::generateproxy()) {
627         KdenliveSettings::setGenerateproxy(m_configProject.kcfg_generateproxy->isChecked());
628     }
629     
630     if (m_configProject.kcfg_proxyminsize->value() != KdenliveSettings::proxyminsize()) {
631         KdenliveSettings::setProxyminsize(m_configProject.kcfg_proxyminsize->value());
632     }
633
634     if (m_modified) {
635         // The transcoding profiles were modified, save.
636         m_modified = false;
637         saveTranscodeProfiles();
638     }
639
640 #ifndef NO_JOGSHUTTLE
641     m_shuttleModified = false;
642
643     QStringList actions;
644     actions << "monitor_pause";  // the Job rest position action.
645     foreach (KComboBox* button, m_shuttle_buttons) {
646         actions << m_mappable_actions[button->currentText()];
647     }
648     QString maps = JogShuttleConfig::actionMap(actions);
649     //fprintf(stderr, "Shuttle config: %s\n", JogShuttleConfig::actionMap(actions).toAscii().constData());
650     if (KdenliveSettings::shuttlebuttons() != maps)
651         KdenliveSettings::setShuttlebuttons(maps);
652 #endif
653
654 #if KDE_IS_VERSION(4,3,0)
655     KConfigDialog::settingsChangedSlot();
656 #endif
657
658     //KConfigDialog::updateSettings();
659     if (resetProfile) emit doResetProfile();
660 }
661
662 void KdenliveSettingsDialog::slotUpdateDisplay()
663 {
664     QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
665     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
666     m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
667     m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
668     m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
669     m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
670     if (values.value("progressive").toInt() == 0)
671         m_configProject.p_progressive->setText(i18n("Interlaced"));
672     else
673         m_configProject.p_progressive->setText(i18n("Progressive"));
674     m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
675     m_defaultPath = currentProfile;
676 }
677
678 void KdenliveSettingsDialog::slotCheckAlsaDriver()
679 {
680     QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
681     m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
682 }
683
684 void KdenliveSettingsDialog::loadTranscodeProfiles()
685 {
686     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
687     KConfigGroup transConfig(config, "Transcoding");
688     // read the entries
689     m_configTranscode.profiles_list->blockSignals(true);
690     QMap< QString, QString > profiles = transConfig.entryMap();
691     QMapIterator<QString, QString> i(profiles);
692     while (i.hasNext()) {
693         i.next();
694         QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
695         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
696     }
697     m_configTranscode.profiles_list->blockSignals(false);
698 }
699
700 void KdenliveSettingsDialog::saveTranscodeProfiles()
701 {
702     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
703     //KSharedConfigPtr config = KGlobal::config();
704     KConfigGroup transConfig(config, "Transcoding");
705     // read the entries
706     transConfig.deleteGroup();
707     int max = m_configTranscode.profiles_list->topLevelItemCount();
708     for (int i = 0; i < max; i++) {
709         QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
710         transConfig.writeEntry(item->text(0), item->text(1));
711     }
712     config->sync();
713 }
714
715 void KdenliveSettingsDialog::slotAddTranscode()
716 {
717     QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
718     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
719     m_configTranscode.profiles_list->setCurrentItem(item);
720     m_configTranscode.profiles_list->editItem(item);
721     slotDialogModified();
722 }
723
724 void KdenliveSettingsDialog::slotDeleteTranscode()
725 {
726     QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
727     if (item == NULL) return;
728     delete item;
729     slotDialogModified();
730 }
731
732 void KdenliveSettingsDialog::slotShuttleModified()
733 {
734 #ifndef NO_JOGSHUTTLE
735     QStringList actions;
736     actions << "monitor_pause";  // the Job rest position action.
737     foreach (KComboBox* button, m_shuttle_buttons) {
738         actions << m_mappable_actions[button->currentText()];
739     }
740     QString maps = JogShuttleConfig::actionMap(actions);
741     m_shuttleModified = KdenliveSettings::shuttlebuttons() != maps;
742 #endif
743 #if KDE_IS_VERSION(4,3,0)
744     KConfigDialog::updateButtons();
745 #endif
746 }
747
748 void KdenliveSettingsDialog::slotDialogModified()
749 {
750     m_modified = true;
751 #if KDE_IS_VERSION(4,3,0)
752     KConfigDialog::updateButtons();
753 #endif
754 }
755
756 //virtual
757 bool KdenliveSettingsDialog::hasChanged()
758 {
759     if (m_modified || m_shuttleModified) return true;
760     return KConfigDialog::hasChanged();
761 }
762
763 void KdenliveSettingsDialog::slotUpdatev4lDevice()
764 {
765     QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
766     if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device);
767     QString size = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
768     if (!size.isEmpty()) m_configCapture.kcfg_video4size->setText(size);
769     rebuildVideo4Commands();
770 }
771
772
773 #include "kdenlivesettingsdialog.moc"
774
775