]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Second part of the capture rewrite. Decklink capture now seems to work with latest MLT
[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 "encodingprofilesdialog.h"
25 #include "kdenlivesettings.h"
26
27 #include <KStandardDirs>
28 #include <KDebug>
29 #include <kopenwithdialog.h>
30 #include <KConfigDialogManager>
31 #include <kde_file.h>
32 #include <KIO/NetAccess>
33 #include <kdeversion.h>
34
35 #include <QDir>
36 #include <QTimer>
37 #include <QTreeWidgetItem>
38 #include <QThread>
39
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <unistd.h>
43 #include <fcntl.h>
44 #ifndef NO_JOGSHUTTLE
45 #include "jogaction.h"
46 #include "jogshuttleconfig.h"
47 #include <linux/input.h>
48 #endif /* NO_JOGSHUTTLE */
49
50
51 KdenliveSettingsDialog::KdenliveSettingsDialog(const QMap<QString, QString>& mappable_actions, QWidget * parent) :
52     KConfigDialog(parent, "settings", KdenliveSettings::self()),
53     m_modified(false),
54     m_shuttleModified(false),
55     m_mappable_actions(mappable_actions)
56 {
57     KdenliveSettings::setV4l_format(0);
58     QWidget *p1 = new QWidget;
59     m_configMisc.setupUi(p1);
60     m_page1 = addPage(p1, i18n("Misc"), "configure");
61
62     // Hide multi tab option until Kdenlive really supports it
63     m_configMisc.kcfg_activatetabs->setVisible(false);
64
65     QWidget *p8 = new QWidget;
66     m_configProject.setupUi(p8);
67     m_page8 = addPage(p8, i18n("Project Defaults"), "document-new");
68     connect(m_configProject.kcfg_generateproxy, SIGNAL(toggled(bool)), m_configProject.kcfg_proxyminsize, SLOT(setEnabled(bool)));
69     m_configProject.kcfg_proxyminsize->setEnabled(KdenliveSettings::generateproxy());
70     connect(m_configProject.kcfg_generateimageproxy, SIGNAL(toggled(bool)), m_configProject.kcfg_proxyimageminsize, SLOT(setEnabled(bool)));
71     m_configProject.kcfg_proxyimageminsize->setEnabled(KdenliveSettings::generateimageproxy());
72
73     QWidget *p3 = new QWidget;
74     m_configTimeline.setupUi(p3);
75     m_page3 = addPage(p3, i18n("Timeline"), "video-display");
76
77     QWidget *p2 = new QWidget;
78     m_configEnv.setupUi(p2);
79     m_configEnv.mltpathurl->setMode(KFile::Directory);
80     m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
81     m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
82     m_configEnv.kcfg_mltthreads->setMaximum(QThread::idealThreadCount());
83     m_configEnv.tmppathurl->setMode(KFile::Directory);
84     m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
85     m_configEnv.projecturl->setMode(KFile::Directory);
86     m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
87     m_configEnv.capturefolderurl->setMode(KFile::Directory);
88     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
89     m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
90     connect(m_configEnv.kcfg_capturetoprojectfolder, SIGNAL(clicked()), this, SLOT(slotEnableCaptureFolder()));
91     m_page2 = addPage(p2, i18n("Environment"), "application-x-executable-script");
92
93     QWidget *p4 = new QWidget;
94     m_configCapture.setupUi(p4);
95
96 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
97
98     // Video 4 Linux device detection
99     for (int i = 0; i < 10; i++) {
100         QString path = "/dev/video" + QString::number(i);
101         if (QFile::exists(path)) {
102             QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path.toUtf8().constData());
103             if (!deviceInfo.isEmpty()) {
104                 m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
105                 m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
106             }
107         }
108     }
109     connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice()));
110     connect(m_configCapture.kcfg_v4l_format, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lCaptureProfile()));
111     connect(m_configCapture.kcfg_v4l_captureaudio, SIGNAL(toggled(bool)), m_configCapture.kcfg_v4l_alsadevice, SLOT(setEnabled(bool)));
112
113     slotUpdatev4lDevice();
114 #endif
115
116     m_page4 = addPage(p4, i18n("Capture"), "media-record");
117     m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
118 #ifdef Q_WS_MAC
119     m_configCapture.tabWidget->setEnabled(false);
120     m_configCapture.kcfg_defaultcapture->setEnabled(false);
121     m_configCapture.label->setText(i18n("Capture is not yet available on OS X."));
122 #endif
123
124     QWidget *p5 = new QWidget;
125     m_configShuttle.setupUi(p5);
126 #ifdef NO_JOGSHUTTLE
127     m_configShuttle.kcfg_enableshuttle->hide();
128     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
129 #else
130     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
131     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
132     slotCheckShuttle(KdenliveSettings::enableshuttle());
133     m_configShuttle.shuttledisabled->hide();
134
135     // Store the button pointers into an array for easier handling them in the other functions.
136     m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
137     m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
138     m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
139     m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
140     m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
141
142     // populate the buttons with the current configuration. The items are sorted
143     // according to the user-selected language, so they do not appear in random order.
144     QList<QString> action_names = mappable_actions.keys();
145     qSort(action_names);
146
147     // Here we need to compute the action_id -> index-in-action_names. We iterate over the
148     // action_names, as the sorting may depend on the user-language.
149     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
150     QMap<QString, int> action_pos;
151     foreach (const QString& action_id, actions_map) {
152       // This loop find out at what index is the string that would map to the action_id.
153       for (int i = 0; i < action_names.size(); i++) {
154           if (mappable_actions[action_names[i]] == action_id) {
155               action_pos[action_id] = i;
156               break;
157           }
158       }
159     }
160
161     int i = 0;
162     foreach (KComboBox* button, m_shuttle_buttons) {
163       button->addItems(action_names);
164       connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
165       ++i;
166       if (i < actions_map.size())
167         button->setCurrentIndex(action_pos[actions_map[i]]);
168     }
169 #endif /* NO_JOGSHUTTLE */
170     m_page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
171
172     QWidget *p6 = new QWidget;
173     m_configSdl.setupUi(p6);
174
175 #if not defined(Q_WS_MAC) && not defined(USE_OPEN_GL)
176     m_configSdl.kcfg_openglmonitors->setHidden(true);
177 #endif
178
179     m_page6 = addPage(p6, i18n("Playback"), "media-playback-start");
180
181     QWidget *p7 = new QWidget;
182     m_configTranscode.setupUi(p7);
183     m_page7 = addPage(p7, i18n("Transcode"), "edit-copy");
184     connect(m_configTranscode.button_add, SIGNAL(clicked()), this, SLOT(slotAddTranscode()));
185     connect(m_configTranscode.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteTranscode()));
186     connect(m_configTranscode.profiles_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotDialogModified()));
187     
188     connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
189
190     m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
191
192     connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
193     connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
194     connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
195
196     loadEncodingProfiles();
197     checkProfile();
198
199     slotUpdateDisplay();
200
201     connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
202     initDevices();
203     connect(m_configProject.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
204     connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
205
206     slotUpdateRmdRegionStatus();
207     loadTranscodeProfiles();
208
209
210     //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
211     //   --timestamp option without bug
212
213     if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
214         QString dvgrabpath = KStandardDirs::findExe("dvgrab");
215         KdenliveSettings::setDvgrab_path(dvgrabpath);
216     }
217
218     // decklink profile
219     m_configCapture.decklink_showprofileinfo->setIcon(KIcon("help-about"));
220     m_configCapture.decklink_manageprofile->setIcon(KIcon("configure"));
221     m_configCapture.decklink_parameters->setVisible(false);
222     m_configCapture.decklink_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
223     m_configCapture.decklink_parameters->setPlainText(KdenliveSettings::decklink_parameters());
224     connect(m_configCapture.decklink_manageprofile, SIGNAL(clicked(bool)), this, SLOT(slotManageEncodingProfile()));
225     connect(m_configCapture.kcfg_decklink_profile, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDecklinkProfile()));
226     connect(m_configCapture.decklink_showprofileinfo, SIGNAL(clicked(bool)), m_configCapture.decklink_parameters, SLOT(setVisible(bool)));
227
228     // v4l profile
229     m_configCapture.v4l_showprofileinfo->setIcon(KIcon("help-about"));
230     m_configCapture.v4l_manageprofile->setIcon(KIcon("configure"));
231     m_configCapture.v4l_parameters->setVisible(false);
232     m_configCapture.v4l_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
233     m_configCapture.v4l_parameters->setPlainText(KdenliveSettings::v4l_parameters());
234     connect(m_configCapture.v4l_manageprofile, SIGNAL(clicked(bool)), this, SLOT(slotManageEncodingProfile()));
235     connect(m_configCapture.kcfg_v4l_profile, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateV4lProfile()));
236     connect(m_configCapture.v4l_showprofileinfo, SIGNAL(clicked(bool)), m_configCapture.v4l_parameters, SLOT(setVisible(bool)));
237     
238     // proxy profile stuff
239     m_configProject.proxy_showprofileinfo->setIcon(KIcon("help-about"));
240     m_configProject.proxy_manageprofile->setIcon(KIcon("configure"));
241     m_configProject.proxyparams->setVisible(false);
242     m_configProject.proxyparams->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
243     m_configProject.proxyparams->setPlainText(KdenliveSettings::proxyparams());
244     connect(m_configProject.proxy_manageprofile, SIGNAL(clicked(bool)), this, SLOT(slotManageEncodingProfile()));
245     connect(m_configProject.proxy_showprofileinfo, SIGNAL(clicked(bool)), m_configProject.proxyparams, SLOT(setVisible(bool)));
246     connect(m_configProject.kcfg_proxy_profile, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateProxyProfile()));
247
248
249     slotUpdateProxyProfile(-1);
250     slotUpdateV4lProfile(-1);
251     slotUpdateDecklinkProfile(-1);
252     
253     BMInterface::getBlackMagicDeviceList(m_configCapture.kcfg_decklink_capturedevice);
254     if (m_configCapture.kcfg_decklink_capturedevice->count() > 0) {
255         QStringList modes = m_configCapture.kcfg_decklink_capturedevice->itemData(m_configCapture.kcfg_decklink_capturedevice->currentIndex()).toStringList();
256         m_configCapture.kcfg_decklink_capturedevice->setToolTip(i18n("Supported capture modes:\n") + modes.join("\n"));
257     }
258     connect(m_configCapture.kcfg_decklink_capturedevice, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHDMIModes()));
259
260     if (BMInterface::getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
261         // Found blackmagic card
262     } else m_configSdl.kcfg_external_display->setEnabled(false);
263
264     double dvgrabVersion = 0;
265     if (!KdenliveSettings::dvgrab_path().isEmpty()) {
266         QProcess *versionCheck = new QProcess;
267         versionCheck->setProcessChannelMode(QProcess::MergedChannels);
268         versionCheck->start("dvgrab", QStringList() << "--version");
269         if (versionCheck->waitForFinished()) {
270             QString version = QString(versionCheck->readAll()).simplified();
271             if (version.contains(' ')) version = version.section(' ', -1);
272             dvgrabVersion = version.toDouble();
273
274             kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
275         }
276         delete versionCheck;
277         if (dvgrabVersion < 3.3) {
278             KdenliveSettings::setFirewiretimestamp(false);
279             m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
280         }
281         m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
282     } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
283
284     if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
285         QString rmdpath = KStandardDirs::findExe("recordmydesktop");
286         KdenliveSettings::setRmd_path(rmdpath);
287     }
288     if (KdenliveSettings::rmd_path().isEmpty())
289         m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
290     else
291         m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
292 }
293
294 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
295
296 void KdenliveSettingsDialog::slotUpdateHDMIModes()
297 {
298     QStringList modes = m_configCapture.kcfg_decklink_capturedevice->itemData(m_configCapture.kcfg_decklink_capturedevice->currentIndex()).toStringList();
299     m_configCapture.kcfg_decklink_capturedevice->setToolTip(i18n("Supported capture modes:\n") + modes.join("\n"));
300 }
301
302 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
303 {
304     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
305 }
306
307 void KdenliveSettingsDialog::slotEnableCaptureFolder()
308 {
309     m_configEnv.capturefolderurl->setEnabled(!m_configEnv.kcfg_capturetoprojectfolder->isChecked());
310 }
311
312 void KdenliveSettingsDialog::checkProfile()
313 {
314     m_configProject.kcfg_profiles_list->clear();
315     QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
316     QMapIterator<QString, QString> i(profilesInfo);
317     while (i.hasNext()) {
318         i.next();
319         m_configProject.kcfg_profiles_list->addItem(i.key(), i.value());
320     }
321
322     if (!KdenliveSettings::default_profile().isEmpty()) {
323         for (int i = 0; i < m_configProject.kcfg_profiles_list->count(); i++) {
324             if (m_configProject.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
325                 m_configProject.kcfg_profiles_list->setCurrentIndex(i);
326                 KdenliveSettings::setProfiles_list(i);
327                 break;
328             }
329         }
330     }
331 }
332
333 void KdenliveSettingsDialog::initDevices()
334 {
335     // Fill audio drivers
336     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
337 #ifndef Q_WS_MAC
338     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
339     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
340     m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
341     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
342     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
343     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
344 #endif
345
346     if (!KdenliveSettings::audiodrivername().isEmpty())
347         for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); i++) {
348             if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
349                 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
350                 KdenliveSettings::setAudio_driver((uint) i);
351             }
352         }
353
354     // Fill video drivers
355     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
356 #ifndef Q_WS_MAC
357     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
358     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
359     m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
360     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
361     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
362     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
363     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
364     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
365     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
366 #endif
367
368     // Fill the list of audio playback devices
369     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
370     m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
371     if (!KStandardDirs::findExe("aplay").isEmpty()) {
372         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
373         m_readProcess.setProgram("aplay", QStringList() << "-l");
374         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
375         m_readProcess.execute(5000);
376     } else {
377         // If aplay is not installed on the system, parse the /proc/asound/pcm file
378         QFile file("/proc/asound/pcm");
379         if (file.open(QIODevice::ReadOnly)) {
380             QTextStream stream(&file);
381             QString line;
382             QString deviceId;
383             while (!stream.atEnd()) {
384                 line = stream.readLine();
385                 if (line.contains("playback")) {
386                     deviceId = line.section(':', 0, 0);
387                     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()));
388                 }
389                 if (line.contains("capture")) {
390                     deviceId = line.section(':', 0, 0);
391                     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()));
392                     m_configCapture.kcfg_v4l_alsadevice->addItem(line.section(':', 1, 1), "hw:" + QString::number(deviceId.section('-', 0, 0).toInt()) + ',' + QString::number(deviceId.section('-', 1, 1).toInt()));
393                 }
394             }
395             file.close();
396         }
397     }
398     if (!KdenliveSettings::audiodevicename().isEmpty()) {
399         // Select correct alsa device
400         int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
401         m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
402         KdenliveSettings::setAudio_device(ix);
403     }
404     
405     if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
406         // Select correct alsa device
407         int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
408         m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
409         KdenliveSettings::setRmd_alsa_device(ix);
410     }
411
412     if (!KdenliveSettings::v4l_alsadevicename().isEmpty()) {
413         // Select correct alsa device
414         int ix = m_configCapture.kcfg_v4l_alsadevice->findData(KdenliveSettings::v4l_alsadevicename());
415         m_configCapture.kcfg_v4l_alsadevice->setCurrentIndex(ix);
416         KdenliveSettings::setV4l_alsadevice(ix);
417     }
418
419     loadCurrentV4lProfileInfo();
420 }
421
422
423 void KdenliveSettingsDialog::slotReadAudioDevices()
424 {
425     QString result = QString(m_readProcess.readAllStandardOutput());
426     kDebug() << "// / / / / / READING APLAY: ";
427     kDebug() << result;
428     QStringList lines = result.split('\n');
429     foreach(const QString & data, lines) {
430         kDebug() << "// READING LINE: " << data;
431         if (data.simplified().startsWith("card")) {
432             QString card = data.section(':', 0, 0).section(' ', -1);
433             QString device = data.section(':', 1, 1).section(' ', -1);
434             m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
435             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
436             m_configCapture.kcfg_v4l_alsadevice->addItem(data.section(':', -1), "hw:" + card + ',' + device);
437         }
438     }
439 }
440
441 void KdenliveSettingsDialog::showPage(int page, int option)
442 {
443     switch (page) {
444     case 1:
445         setCurrentPage(m_page1);
446         break;
447     case 2:
448         setCurrentPage(m_page2);
449         break;
450     case 3:
451         setCurrentPage(m_page3);
452         break;
453     case 4:
454         setCurrentPage(m_page4);
455         m_configCapture.tabWidget->setCurrentIndex(option);
456         break;
457     case 5:
458         setCurrentPage(m_page5);
459         break;
460     case 6:
461         setCurrentPage(m_page6);
462         break;
463     case 7:
464         setCurrentPage(m_page7);
465         break;
466     default:
467         setCurrentPage(m_page1);
468     }
469 }
470
471 void KdenliveSettingsDialog::slotEditVideoApplication()
472 {
473     KService::Ptr service;
474     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
475     if (dlg.exec() != QDialog::Accepted)
476         return;
477
478     service = dlg.service();
479     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
480 }
481
482 void KdenliveSettingsDialog::slotEditAudioApplication()
483 {
484     KService::Ptr service;
485     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
486     if (dlg.exec() != QDialog::Accepted)
487         return;
488
489     service = dlg.service();
490     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
491 }
492
493 void KdenliveSettingsDialog::slotEditImageApplication()
494 {
495     KService::Ptr service;
496     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
497     if (dlg.exec() != QDialog::Accepted)
498         return;
499
500     service = dlg.service();
501     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
502 }
503
504 #ifndef NO_JOGSHUTTLE
505 void KdenliveSettingsDialog::slotCheckShuttle(int state)
506 {
507     m_configShuttle.config_group->setEnabled(state);
508     if (m_configShuttle.shuttledevicelist->count() == 0) {
509         // parse devices
510         QString baseName = "/dev/input/event";
511         int fd;
512         for (int i = 0; i < 30; i++) {
513             QString filename = baseName + QString::number(i);
514             kDebug() << "/// CHECKING OFR: " << filename;
515
516             char name[256] = "unknown";
517             fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
518             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
519                 m_configShuttle.shuttledevicelist->addItem(name, filename);
520             }
521             ::close(fd);
522         }
523         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
524     }
525 }
526
527 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
528 {
529     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
530     //KdenliveSettings::setShuttledevice(device);
531     m_configShuttle.kcfg_shuttledevice->setText(device);
532 }
533
534 #endif /* NO_JOGSHUTTLE */
535
536 void KdenliveSettingsDialog::updateWidgets()
537 {
538     // Revert widgets to last saved state (for example when user pressed "Cancel")
539     // kDebug() << "// // // KCONFIG Revert called";
540 #ifndef NO_JOGSHUTTLE
541     // revert jog shuttle device
542     if (m_configShuttle.shuttledevicelist->count() > 0) {
543         for (int i = 0; i < m_configShuttle.shuttledevicelist->count(); i++) {
544             if (m_configShuttle.shuttledevicelist->itemData(i) == KdenliveSettings::shuttledevice()) {
545                 m_configShuttle.shuttledevicelist->setCurrentIndex(i);
546                 break;
547             }
548         }
549     }
550
551     // Revert jog shuttle buttons
552     QList<QString> action_names = m_mappable_actions.keys();
553     qSort(action_names);
554     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
555     QMap<QString, int> action_pos;
556     foreach (const QString& action_id, actions_map) {
557       // This loop find out at what index is the string that would map to the action_id.
558       for (int i = 0; i < action_names.size(); i++) {
559           if (m_mappable_actions[action_names[i]] == action_id) {
560               action_pos[action_id] = i;
561               break;
562           }
563       }
564     }
565     int i = 0;
566     foreach (KComboBox* button, m_shuttle_buttons) {
567       ++i;
568       if (i < actions_map.size())
569         button->setCurrentIndex(action_pos[actions_map[i]]);
570     }
571 #endif
572 }
573
574 void KdenliveSettingsDialog::updateSettings()
575 {
576     // Save changes to settings (for example when user pressed "Apply" or "Ok")
577     // kDebug() << "// // // KCONFIG UPDATE called";
578     m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
579     KdenliveSettings::setDefault_profile(m_defaultPath);
580
581     bool resetProfile = false;
582     bool updateCapturePath = false;
583     
584     /*if (m_configShuttle.shuttledevicelist->count() > 0) {
585         QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
586         if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
587     }*/
588
589     if (m_configEnv.kcfg_capturetoprojectfolder->isChecked() != KdenliveSettings::capturetoprojectfolder()) {
590         KdenliveSettings::setCapturetoprojectfolder(m_configEnv.kcfg_capturetoprojectfolder->isChecked());
591         updateCapturePath = true;
592     }
593
594     if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
595         KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
596         updateCapturePath = true;
597     }
598
599     if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
600         KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
601         updateCapturePath = true;
602     }
603
604     if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
605         KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
606         updateCapturePath = true;
607     }
608
609     if ((uint) m_configCapture.kcfg_v4l_format->currentIndex() != KdenliveSettings::v4l_format()) {
610         saveCurrentV4lProfile();
611         KdenliveSettings::setV4l_format(0);
612     }
613     
614     // Check encoding profiles
615     QString data = m_configCapture.kcfg_v4l_profile->itemData(m_configCapture.kcfg_v4l_profile->currentIndex()).toString();
616     if (!data.isEmpty() && data.section(";", 0, 0) != KdenliveSettings::v4l_parameters()) {
617         KdenliveSettings::setV4l_parameters(data.section(";", 0, 0));
618         KdenliveSettings::setV4l_extension(data.section(";", 1, 1));
619     }
620     data = m_configCapture.kcfg_decklink_profile->itemData(m_configCapture.kcfg_decklink_profile->currentIndex()).toString();
621     if (!data.isEmpty() && data.section(";", 0, 0) != KdenliveSettings::decklink_parameters()) {
622         KdenliveSettings::setDecklink_parameters(data.section(";", 0, 0));
623         KdenliveSettings::setDecklink_extension(data.section(";", 1, 1));
624     }
625     data = m_configProject.kcfg_proxy_profile->itemData(m_configProject.kcfg_proxy_profile->currentIndex()).toString();
626     if (!data.isEmpty() && data.section(";", 0, 0) != KdenliveSettings::proxyparams()) {
627         KdenliveSettings::setProxyparams(data.section(";", 0, 0));
628         KdenliveSettings::setProxyextension(data.section(";", 1, 1));
629     }
630     
631
632     if (updateCapturePath) emit updateCaptureFolder();
633
634     QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
635     if (value != KdenliveSettings::rmd_alsadevicename()) {
636         KdenliveSettings::setRmd_alsadevicename(value);
637     }
638
639     value = m_configCapture.kcfg_v4l_alsadevice->itemData(m_configCapture.kcfg_v4l_alsadevice->currentIndex()).toString();
640     if (value != KdenliveSettings::v4l_alsadevicename()) {
641         KdenliveSettings::setV4l_alsadevicename(value);
642     }
643
644     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
645     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
646     if (value != KdenliveSettings::rmd_freq()) {
647         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
648         KdenliveSettings::setRmd_freq(value);
649     }
650
651     if (m_configSdl.kcfg_external_display->isChecked() != KdenliveSettings::external_display()) {
652         KdenliveSettings::setExternal_display(m_configSdl.kcfg_external_display->isChecked());
653         resetProfile = true;
654     }
655
656     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
657     if (value != KdenliveSettings::audiodrivername()) {
658         KdenliveSettings::setAudiodrivername(value);
659         resetProfile = true;
660     }
661
662     if (value == "alsa") {
663         // Audio device setting is only valid for alsa driver
664         value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
665         if (value != KdenliveSettings::audiodevicename()) {
666             KdenliveSettings::setAudiodevicename(value);
667             resetProfile = true;
668         }
669     } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
670         KdenliveSettings::setAudiodevicename(QString::null);
671         resetProfile = true;
672     }
673
674     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
675     if (value != KdenliveSettings::videodrivername()) {
676         KdenliveSettings::setVideodrivername(value);
677         resetProfile = true;
678     }
679
680     if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
681         KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
682         resetProfile = true;
683     }
684
685     if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
686         KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
687         resetProfile = true;
688     }
689     
690     if (m_modified) {
691         // The transcoding profiles were modified, save.
692         m_modified = false;
693         saveTranscodeProfiles();
694     }
695
696 #ifndef NO_JOGSHUTTLE
697     m_shuttleModified = false;
698
699     QStringList actions;
700     actions << "monitor_pause";  // the Job rest position action.
701     foreach (KComboBox* button, m_shuttle_buttons) {
702         actions << m_mappable_actions[button->currentText()];
703     }
704     QString maps = JogShuttleConfig::actionMap(actions);
705     //fprintf(stderr, "Shuttle config: %s\n", JogShuttleConfig::actionMap(actions).toAscii().constData());
706     if (KdenliveSettings::shuttlebuttons() != maps)
707         KdenliveSettings::setShuttlebuttons(maps);
708 #endif
709
710 #if KDE_IS_VERSION(4,3,0)
711     KConfigDialog::settingsChangedSlot();
712 #endif
713
714     //KConfigDialog::updateSettings();
715     if (resetProfile) emit doResetProfile();
716 }
717
718 void KdenliveSettingsDialog::slotUpdateDisplay()
719 {
720     QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
721     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
722     m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
723     m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
724     m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
725     m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
726     if (values.value("progressive").toInt() == 0)
727         m_configProject.p_progressive->setText(i18n("Interlaced"));
728     else
729         m_configProject.p_progressive->setText(i18n("Progressive"));
730     m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
731     m_defaultPath = currentProfile;
732 }
733
734 void KdenliveSettingsDialog::slotCheckAlsaDriver()
735 {
736     QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
737     m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
738 }
739
740 void KdenliveSettingsDialog::loadTranscodeProfiles()
741 {
742     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
743     KConfigGroup transConfig(config, "Transcoding");
744     // read the entries
745     m_configTranscode.profiles_list->blockSignals(true);
746     QMap< QString, QString > profiles = transConfig.entryMap();
747     QMapIterator<QString, QString> i(profiles);
748     while (i.hasNext()) {
749         i.next();
750         QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
751         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
752     }
753     m_configTranscode.profiles_list->blockSignals(false);
754 }
755
756 void KdenliveSettingsDialog::saveTranscodeProfiles()
757 {
758     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
759     //KSharedConfigPtr config = KGlobal::config();
760     KConfigGroup transConfig(config, "Transcoding");
761     // read the entries
762     transConfig.deleteGroup();
763     int max = m_configTranscode.profiles_list->topLevelItemCount();
764     for (int i = 0; i < max; i++) {
765         QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
766         transConfig.writeEntry(item->text(0), item->text(1));
767     }
768     config->sync();
769 }
770
771 void KdenliveSettingsDialog::slotAddTranscode()
772 {
773     QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
774     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
775     m_configTranscode.profiles_list->setCurrentItem(item);
776     m_configTranscode.profiles_list->editItem(item);
777     slotDialogModified();
778 }
779
780 void KdenliveSettingsDialog::slotDeleteTranscode()
781 {
782     QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
783     if (item == NULL) return;
784     delete item;
785     slotDialogModified();
786 }
787
788 void KdenliveSettingsDialog::slotShuttleModified()
789 {
790 #ifndef NO_JOGSHUTTLE
791     QStringList actions;
792     actions << "monitor_pause";  // the Job rest position action.
793     foreach (KComboBox* button, m_shuttle_buttons) {
794         actions << m_mappable_actions[button->currentText()];
795     }
796     QString maps = JogShuttleConfig::actionMap(actions);
797     m_shuttleModified = KdenliveSettings::shuttlebuttons() != maps;
798 #endif
799 #if KDE_IS_VERSION(4,3,0)
800     KConfigDialog::updateButtons();
801 #endif
802 }
803
804 void KdenliveSettingsDialog::slotDialogModified()
805 {
806     m_modified = true;
807 #if KDE_IS_VERSION(4,3,0)
808     KConfigDialog::updateButtons();
809 #endif
810 }
811
812 //virtual
813 bool KdenliveSettingsDialog::hasChanged()
814 {
815     if (m_modified || m_shuttleModified) return true;
816     return KConfigDialog::hasChanged();
817 }
818
819 void KdenliveSettingsDialog::slotUpdatev4lDevice()
820 {
821     QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
822     if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device);
823     QString info = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
824
825     m_configCapture.kcfg_v4l_format->blockSignals(true);
826     m_configCapture.kcfg_v4l_format->clear();
827
828     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
829     if (QFile::exists(vl4ProfilePath)) m_configCapture.kcfg_v4l_format->addItem(i18n("Current settings"));
830     
831     QStringList pixelformats = info.split(">", QString::SkipEmptyParts);
832     QString itemSize;
833     QString pixelFormat;
834     QStringList itemRates;
835     for (int i = 0; i < pixelformats.count(); i++) {
836         QString format = pixelformats.at(i).section(':', 0, 0);
837         QStringList sizes = pixelformats.at(i).split(":", QString::SkipEmptyParts);
838         pixelFormat = sizes.takeFirst();
839         for (int j = 0; j < sizes.count(); j++) {
840             itemSize = sizes.at(j).section("=", 0, 0);
841             itemRates = sizes.at(j).section("=", 1, 1).split(",", QString::SkipEmptyParts);
842             for (int k = 0; k < itemRates.count(); k++) {
843                 m_configCapture.kcfg_v4l_format->addItem("[" + format + "] " + itemSize + " (" + itemRates.at(k) + ")", QStringList() << format << itemSize.section('x', 0, 0) << itemSize.section('x', 1, 1) << itemRates.at(k).section('/', 0, 0) << itemRates.at(k).section('/', 1, 1));
844             }
845         }
846     }
847     m_configCapture.kcfg_v4l_format->blockSignals(false);
848     slotUpdatev4lCaptureProfile();
849 }
850
851 void KdenliveSettingsDialog::slotUpdatev4lCaptureProfile()
852 {
853     QStringList info = m_configCapture.kcfg_v4l_format->itemData(m_configCapture.kcfg_v4l_format->currentIndex(), Qt::UserRole).toStringList();
854     if (info.isEmpty()) {
855         // No auto info, display the current ones
856         loadCurrentV4lProfileInfo();
857         return;
858     }
859     m_configCapture.p_size->setText(info.at(1) + 'x' + info.at(2));
860     m_configCapture.p_fps->setText(info.at(3) + '/' + info.at(4));
861     m_configCapture.p_aspect->setText("1/1");
862     m_configCapture.p_display->setText(info.at(1) + '/' + info.at(2));
863     m_configCapture.p_colorspace->setText(ProfilesDialog::getColorspaceDescription(601));
864     m_configCapture.p_progressive->setText(i18n("Progressive"));
865
866     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
867     if (!QFile::exists(vl4ProfilePath)) saveCurrentV4lProfile();
868 }
869
870 void KdenliveSettingsDialog::loadCurrentV4lProfileInfo()
871 {
872     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
873     MltVideoProfile prof;
874     if (!QFile::exists(vl4ProfilePath)) {
875         // No default formats found, build one
876         prof.width = 320;
877         prof.height = 200;
878         prof.frame_rate_num = 15;
879         prof.frame_rate_den = 1;
880         prof.display_aspect_num = 4;
881         prof.display_aspect_den = 3;
882         prof.sample_aspect_num = 1;
883         prof.sample_aspect_den = 1;
884         prof.progressive = 1;
885         prof.colorspace = 601;
886         ProfilesDialog::saveProfile(prof, vl4ProfilePath);
887     }
888     else prof = ProfilesDialog::getVideoProfile(vl4ProfilePath);
889     m_configCapture.p_size->setText(QString::number(prof.width) + 'x' + QString::number(prof.height));
890     m_configCapture.p_fps->setText(QString::number(prof.frame_rate_num) + '/' + QString::number(prof.frame_rate_den));
891     m_configCapture.p_aspect->setText(QString::number(prof.sample_aspect_num) + '/' + QString::number(prof.sample_aspect_den));
892     m_configCapture.p_display->setText(QString::number(prof.display_aspect_num) + '/' + QString::number(prof.display_aspect_den));
893     m_configCapture.p_colorspace->setText(ProfilesDialog::getColorspaceDescription(prof.colorspace));
894     if (prof.progressive) m_configCapture.p_progressive->setText(i18n("Progressive"));
895 }
896
897 void KdenliveSettingsDialog::saveCurrentV4lProfile()
898 {
899     MltVideoProfile profile;
900     profile.description = "Video4Linux capture";
901     profile.colorspace = ProfilesDialog::getColorspaceFromDescription(m_configCapture.p_colorspace->text());
902     profile.width = m_configCapture.p_size->text().section('x', 0, 0).toInt();
903     profile.height = m_configCapture.p_size->text().section('x', 1, 1).toInt();
904     profile.sample_aspect_num = m_configCapture.p_aspect->text().section('/', 0, 0).toInt();
905     profile.sample_aspect_den = m_configCapture.p_aspect->text().section('/', 1, 1).toInt();
906     profile.display_aspect_num = m_configCapture.p_display->text().section('/', 0, 0).toInt();
907     profile.display_aspect_den = m_configCapture.p_display->text().section('/', 1, 1).toInt();
908     profile.frame_rate_num = m_configCapture.p_fps->text().section('/', 0, 0).toInt();
909     profile.frame_rate_den = m_configCapture.p_fps->text().section('/', 1, 1).toInt();
910     profile.progressive = m_configCapture.p_progressive->text() == i18n("Progressive");
911     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
912     ProfilesDialog::saveProfile(profile, vl4ProfilePath);
913 }
914
915 void KdenliveSettingsDialog::slotManageEncodingProfile()
916 {
917     int type = 0;
918     if (currentPage() == m_page4) {
919         if (m_configCapture.tabWidget->currentIndex() == 1) type = 1;
920         else if (m_configCapture.tabWidget->currentIndex() == 3) type = 2;
921     }
922     EncodingProfilesDialog *d = new EncodingProfilesDialog(type);
923     d->exec();
924     delete d;
925     loadEncodingProfiles();
926 }
927
928 void KdenliveSettingsDialog::loadEncodingProfiles()
929 {
930     QString profileFile = KStandardDirs::locateLocal("appdata", "encodingprofiles.rc");
931     KConfig conf(profileFile, KConfig::SimpleConfig);
932     if (!QFile::exists(profileFile)) {
933         KConfigGroup g1(&conf, "video4linux");
934         g1.writeEntry("Normal MPEG", KdenliveSettings::v4l_parameters() + ";" + KdenliveSettings::v4l_extension());
935         KConfigGroup g2(&conf, "decklink");
936         g2.writeEntry("Normal MPEG", KdenliveSettings::decklink_parameters() + ";" + KdenliveSettings::decklink_extension());
937         KConfigGroup g3(&conf, "proxy");
938         g3.writeEntry("Normal MPEG", KdenliveSettings::proxyparams() + ";" + KdenliveSettings::proxyextension());
939     }
940
941     // Load v4l profiles
942     m_configCapture.kcfg_v4l_profile->blockSignals(true);
943     QString currentItem = m_configCapture.kcfg_v4l_profile->currentText();
944     m_configCapture.kcfg_v4l_profile->clear();
945     KConfigGroup group(&conf, "video4linux");
946     QMap< QString, QString > values = group.entryMap();
947     QMapIterator<QString, QString> i(values);
948     while (i.hasNext()) {
949         i.next();
950         if (!i.key().isEmpty()) m_configCapture.kcfg_v4l_profile->addItem(i.key(), i.value());
951     }
952     m_configCapture.kcfg_v4l_profile->blockSignals(false);
953     if (!currentItem.isEmpty()) m_configCapture.kcfg_v4l_profile->setCurrentIndex(m_configCapture.kcfg_v4l_profile->findText(currentItem));
954     
955     // Load Decklink profiles
956     m_configCapture.kcfg_decklink_profile->blockSignals(true);
957     currentItem = m_configCapture.kcfg_decklink_profile->currentText();
958     m_configCapture.kcfg_decklink_profile->clear();
959     KConfigGroup group2(&conf, "decklink");
960     values = group2.entryMap();
961     QMapIterator<QString, QString> j(values);
962     while (j.hasNext()) {
963         j.next();
964         if (!j.key().isEmpty()) m_configCapture.kcfg_decklink_profile->addItem(j.key(), j.value());
965     }
966     m_configCapture.kcfg_decklink_profile->blockSignals(false);
967     if (!currentItem.isEmpty()) m_configCapture.kcfg_decklink_profile->setCurrentIndex(m_configCapture.kcfg_decklink_profile->findText(currentItem));
968     
969     // Load Proxy profiles
970     m_configProject.kcfg_proxy_profile->blockSignals(true);
971     currentItem = m_configProject.kcfg_proxy_profile->currentText();
972     m_configProject.kcfg_proxy_profile->clear();
973     KConfigGroup group3(&conf, "proxy");
974     values = group3.entryMap();
975     QMapIterator<QString, QString> k(values);
976     while (k.hasNext()) {
977         k.next();
978         if (!k.key().isEmpty()) m_configProject.kcfg_proxy_profile->addItem(k.key(), k.value());
979     }
980     m_configProject.kcfg_proxy_profile->blockSignals(false);
981     if (!currentItem.isEmpty()) m_configProject.kcfg_proxy_profile->setCurrentIndex(m_configProject.kcfg_proxy_profile->findText(currentItem));
982 }
983
984 void KdenliveSettingsDialog::slotUpdateDecklinkProfile(int ix)
985 {
986     if (ix == -1) ix = KdenliveSettings::decklink_profile();
987     else ix = m_configCapture.kcfg_decklink_profile->currentIndex();
988     QString data = m_configCapture.kcfg_decklink_profile->itemData(ix).toString();
989     if (data.isEmpty()) return;
990     m_configCapture.decklink_parameters->setPlainText(data.section(";", 0, 0));
991     //
992 }
993
994 void KdenliveSettingsDialog::slotUpdateV4lProfile(int ix)
995 {
996     if (ix == -1) ix = KdenliveSettings::v4l_profile();
997     else ix = m_configCapture.kcfg_v4l_profile->currentIndex();
998     QString data = m_configCapture.kcfg_v4l_profile->itemData(ix).toString();
999     if (data.isEmpty()) return;
1000     m_configCapture.v4l_parameters->setPlainText(data.section(";", 0, 0));
1001     //
1002 }
1003
1004 void KdenliveSettingsDialog::slotUpdateProxyProfile(int ix)
1005 {
1006     if (ix == -1) ix = KdenliveSettings::v4l_profile();
1007     else ix = m_configProject.kcfg_proxy_profile->currentIndex();
1008     QString data = m_configProject.kcfg_proxy_profile->itemData(ix).toString();
1009     if (data.isEmpty()) return;
1010     m_configProject.proxyparams->setPlainText(data.section(";", 0, 0));
1011     //
1012 }
1013
1014 #include "kdenlivesettingsdialog.moc"
1015
1016