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