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