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