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