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