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