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