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