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