]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Fix proxy settings sometimes broken (missing extension)
[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) && !defined(Q_OS_KFREEBSD)
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     // Hide avformat-novalidate trick, causes crash (bug #2205 and #2206)
67     m_configMisc.kcfg_projectloading_avformatnovalidate->setVisible(false);
68
69     QWidget *p8 = new QWidget;
70     m_configProject.setupUi(p8);
71     m_page8 = addPage(p8, i18n("Project Defaults"), "document-new");
72     connect(m_configProject.kcfg_generateproxy, SIGNAL(toggled(bool)), m_configProject.kcfg_proxyminsize, SLOT(setEnabled(bool)));
73     m_configProject.kcfg_proxyminsize->setEnabled(KdenliveSettings::generateproxy());
74     connect(m_configProject.kcfg_generateimageproxy, SIGNAL(toggled(bool)), m_configProject.kcfg_proxyimageminsize, SLOT(setEnabled(bool)));
75     m_configProject.kcfg_proxyimageminsize->setEnabled(KdenliveSettings::generateimageproxy());
76
77     QWidget *p3 = new QWidget;
78     m_configTimeline.setupUi(p3);
79     m_page3 = addPage(p3, i18n("Timeline"), "video-display");
80
81     QWidget *p2 = new QWidget;
82     m_configEnv.setupUi(p2);
83     m_configEnv.mltpathurl->setMode(KFile::Directory);
84     m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
85     m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
86     m_configEnv.kcfg_mltthreads->setMaximum( QThread::idealThreadCount() < 4 ? QThread::idealThreadCount() : 3 );
87     m_configEnv.tmppathurl->setMode(KFile::Directory);
88     m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
89     m_configEnv.projecturl->setMode(KFile::Directory);
90     m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
91     m_configEnv.capturefolderurl->setMode(KFile::Directory);
92     m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
93     m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
94     connect(m_configEnv.kcfg_capturetoprojectfolder, SIGNAL(clicked()), this, SLOT(slotEnableCaptureFolder()));
95     m_page2 = addPage(p2, i18n("Environment"), "application-x-executable-script");
96
97     QWidget *p4 = new QWidget;
98     m_configCapture.setupUi(p4);
99
100 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD) && !defined(Q_OS_KFREEBSD)
101
102     // Video 4 Linux device detection
103     for (int i = 0; i < 10; i++) {
104         QString path = "/dev/video" + QString::number(i);
105         if (QFile::exists(path)) {
106             QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path.toUtf8().constData());
107             if (!deviceInfo.isEmpty()) {
108                 m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
109                 m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
110             }
111         }
112     }
113     connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice()));
114     connect(m_configCapture.kcfg_v4l_format, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lCaptureProfile()));
115     connect(m_configCapture.kcfg_v4l_captureaudio, SIGNAL(toggled(bool)), m_configCapture.kcfg_v4l_alsadevice, SLOT(setEnabled(bool)));
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 OS X."));
127 #endif
128
129     QWidget *p5 = new QWidget;
130     m_configShuttle.setupUi(p5);
131 #ifdef NO_JOGSHUTTLE
132     m_configShuttle.kcfg_enableshuttle->hide();
133     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
134 #else
135     connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
136     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
137     slotCheckShuttle(KdenliveSettings::enableshuttle());
138     m_configShuttle.shuttledisabled->hide();
139
140     // Store the button pointers into an array for easier handling them in the other functions.
141     m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
142     m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
143     m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
144     m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
145     m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
146
147     // populate the buttons with the current configuration. The items are sorted
148     // according to the user-selected language, so they do not appear in random order.
149     QList<QString> action_names = mappable_actions.keys();
150     qSort(action_names);
151
152     // Here we need to compute the action_id -> index-in-action_names. We iterate over the
153     // action_names, as the sorting may depend on the user-language.
154     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
155     QMap<QString, int> action_pos;
156     foreach (const QString& action_id, actions_map) {
157       // This loop find out at what index is the string that would map to the action_id.
158       for (int i = 0; i < action_names.size(); i++) {
159           if (mappable_actions[action_names[i]] == action_id) {
160               action_pos[action_id] = i;
161               break;
162           }
163       }
164     }
165
166     int i = 0;
167     foreach (KComboBox* button, m_shuttle_buttons) {
168       button->addItems(action_names);
169       connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
170       ++i;
171       if (i < actions_map.size())
172         button->setCurrentIndex(action_pos[actions_map[i]]);
173     }
174 #endif /* NO_JOGSHUTTLE */
175     m_page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
176
177     QWidget *p6 = new QWidget;
178     m_configSdl.setupUi(p6);
179
180 #if not defined(Q_WS_MAC) && not defined(USE_OPEN_GL)
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(QTreeWidgetItem *, int)), this, SLOT(slotDialogModified()));
192
193     connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
194
195     m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
196
197     connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
198     connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
199     connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
200
201     loadEncodingProfiles();
202     checkProfile();
203
204     slotUpdateDisplay();
205
206     connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
207     initDevices();
208     connect(m_configProject.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
209     connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
210
211     slotUpdateRmdRegionStatus();
212     loadTranscodeProfiles();
213
214
215     //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
216     //   --timestamp option without bug
217
218     if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
219         QString dvgrabpath = KStandardDirs::findExe("dvgrab");
220         KdenliveSettings::setDvgrab_path(dvgrabpath);
221     }
222
223     // decklink profile
224     m_configCapture.decklink_showprofileinfo->setIcon(KIcon("help-about"));
225     m_configCapture.decklink_manageprofile->setIcon(KIcon("configure"));
226     m_configCapture.decklink_parameters->setVisible(false);
227     m_configCapture.decklink_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
228     m_configCapture.decklink_parameters->setPlainText(KdenliveSettings::decklink_parameters());
229     connect(m_configCapture.decklink_manageprofile, SIGNAL(clicked(bool)), this, SLOT(slotManageEncodingProfile()));
230     connect(m_configCapture.kcfg_decklink_profile, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDecklinkProfile()));
231     connect(m_configCapture.decklink_showprofileinfo, SIGNAL(clicked(bool)), m_configCapture.decklink_parameters, SLOT(setVisible(bool)));
232
233     // v4l profile
234     m_configCapture.v4l_showprofileinfo->setIcon(KIcon("help-about"));
235     m_configCapture.v4l_manageprofile->setIcon(KIcon("configure"));
236     m_configCapture.v4l_parameters->setVisible(false);
237     m_configCapture.v4l_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
238     m_configCapture.v4l_parameters->setPlainText(KdenliveSettings::v4l_parameters());
239     connect(m_configCapture.v4l_manageprofile, SIGNAL(clicked(bool)), this, SLOT(slotManageEncodingProfile()));
240     connect(m_configCapture.kcfg_v4l_profile, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateV4lProfile()));
241     connect(m_configCapture.v4l_showprofileinfo, SIGNAL(clicked(bool)), m_configCapture.v4l_parameters, SLOT(setVisible(bool)));
242
243     // proxy profile stuff
244     m_configProject.proxy_showprofileinfo->setIcon(KIcon("help-about"));
245     m_configProject.proxy_manageprofile->setIcon(KIcon("configure"));
246     m_configProject.proxyparams->setVisible(false);
247     m_configProject.proxyparams->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
248     m_configProject.proxyparams->setPlainText(KdenliveSettings::proxyparams());
249     connect(m_configProject.proxy_manageprofile, SIGNAL(clicked(bool)), this, SLOT(slotManageEncodingProfile()));
250     connect(m_configProject.proxy_showprofileinfo, SIGNAL(clicked(bool)), m_configProject.proxyparams, SLOT(setVisible(bool)));
251     connect(m_configProject.kcfg_proxy_profile, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateProxyProfile()));
252
253
254     slotUpdateProxyProfile(-1);
255     slotUpdateV4lProfile(-1);
256     slotUpdateDecklinkProfile(-1);
257
258     BMInterface::getBlackMagicDeviceList(m_configCapture.kcfg_decklink_capturedevice);
259     if (m_configCapture.kcfg_decklink_capturedevice->count() > 0) {
260         QStringList modes = m_configCapture.kcfg_decklink_capturedevice->itemData(m_configCapture.kcfg_decklink_capturedevice->currentIndex()).toStringList();
261         m_configCapture.kcfg_decklink_capturedevice->setToolTip(i18n("Supported capture modes:\n") + modes.join("\n"));
262     }
263     connect(m_configCapture.kcfg_decklink_capturedevice, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHDMIModes()));
264
265     if (BMInterface::getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
266         // Found blackmagic card
267     } else m_configSdl.kcfg_external_display->setEnabled(false);
268
269     double dvgrabVersion = 0;
270     if (!KdenliveSettings::dvgrab_path().isEmpty()) {
271         QProcess *versionCheck = new QProcess;
272         versionCheck->setProcessChannelMode(QProcess::MergedChannels);
273         versionCheck->start("dvgrab", QStringList() << "--version");
274         if (versionCheck->waitForFinished()) {
275             QString version = QString(versionCheck->readAll()).simplified();
276             if (version.contains(' ')) version = version.section(' ', -1);
277             dvgrabVersion = version.toDouble();
278
279             kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
280         }
281         delete versionCheck;
282         if (dvgrabVersion < 3.3) {
283             KdenliveSettings::setFirewiretimestamp(false);
284             m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
285         }
286         m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
287     } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
288
289     if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
290         QString rmdpath = KStandardDirs::findExe("recordmydesktop");
291         KdenliveSettings::setRmd_path(rmdpath);
292     }
293     if (KdenliveSettings::rmd_path().isEmpty())
294         m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
295     else
296         m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
297 }
298
299 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
300
301 void KdenliveSettingsDialog::slotUpdateHDMIModes()
302 {
303     QStringList modes = m_configCapture.kcfg_decklink_capturedevice->itemData(m_configCapture.kcfg_decklink_capturedevice->currentIndex()).toStringList();
304     m_configCapture.kcfg_decklink_capturedevice->setToolTip(i18n("Supported capture modes:\n") + modes.join("\n"));
305 }
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), "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), "hw:" + QString::number(deviceId.section('-', 0, 0).toInt()) + ',' + QString::number(deviceId.section('-', 1, 1).toInt()));
398                 }
399             }
400             file.close();
401         }
402     }
403     if (!KdenliveSettings::audiodevicename().isEmpty()) {
404         // Select correct alsa device
405         int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
406         m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
407         KdenliveSettings::setAudio_device(ix);
408     }
409
410     if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
411         // Select correct alsa device
412         int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
413         m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
414         KdenliveSettings::setRmd_alsa_device(ix);
415     }
416
417     if (!KdenliveSettings::v4l_alsadevicename().isEmpty()) {
418         // Select correct alsa device
419         int ix = m_configCapture.kcfg_v4l_alsadevice->findData(KdenliveSettings::v4l_alsadevicename());
420         m_configCapture.kcfg_v4l_alsadevice->setCurrentIndex(ix);
421         KdenliveSettings::setV4l_alsadevice(ix);
422     }
423
424     loadCurrentV4lProfileInfo();
425 }
426
427
428 void KdenliveSettingsDialog::slotReadAudioDevices()
429 {
430     QString result = QString(m_readProcess.readAllStandardOutput());
431     kDebug() << "// / / / / / READING APLAY: ";
432     kDebug() << result;
433     QStringList lines = result.split('\n');
434     foreach(const QString & data, lines) {
435         //kDebug() << "// READING LINE: " << data;
436         if (!data.startsWith(" ") && data.count(':') > 1) {
437             QString card = data.section(':', 0, 0).section(' ', -1);
438             QString device = data.section(':', 1, 1).section(' ', -1);
439             m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
440             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
441             m_configCapture.kcfg_v4l_alsadevice->addItem(data.section(':', -1), "hw:" + card + ',' + device);
442         }
443     }
444 }
445
446 void KdenliveSettingsDialog::showPage(int page, int option)
447 {
448     switch (page) {
449     case 1:
450         setCurrentPage(m_page1);
451         break;
452     case 2:
453         setCurrentPage(m_page2);
454         break;
455     case 3:
456         setCurrentPage(m_page3);
457         break;
458     case 4:
459         setCurrentPage(m_page4);
460         m_configCapture.tabWidget->setCurrentIndex(option);
461         break;
462     case 5:
463         setCurrentPage(m_page5);
464         break;
465     case 6:
466         setCurrentPage(m_page6);
467         break;
468     case 7:
469         setCurrentPage(m_page7);
470         break;
471     default:
472         setCurrentPage(m_page1);
473     }
474 }
475
476 void KdenliveSettingsDialog::slotEditVideoApplication()
477 {
478     KService::Ptr service;
479     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
480     if (dlg.exec() != QDialog::Accepted)
481         return;
482
483     service = dlg.service();
484     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
485 }
486
487 void KdenliveSettingsDialog::slotEditAudioApplication()
488 {
489     KService::Ptr service;
490     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
491     if (dlg.exec() != QDialog::Accepted)
492         return;
493
494     service = dlg.service();
495     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
496 }
497
498 void KdenliveSettingsDialog::slotEditImageApplication()
499 {
500     KService::Ptr service;
501     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
502     if (dlg.exec() != QDialog::Accepted)
503         return;
504
505     service = dlg.service();
506     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
507 }
508
509 #ifndef NO_JOGSHUTTLE
510 void KdenliveSettingsDialog::slotCheckShuttle(int state)
511 {
512     m_configShuttle.config_group->setEnabled(state);
513     if (m_configShuttle.shuttledevicelist->count() == 0) {
514         // parse devices
515         QString baseName = "/dev/input/event";
516         int fd;
517         for (int i = 0; i < 30; i++) {
518             QString filename = baseName + QString::number(i);
519             kDebug() << "/// CHECKING OFR: " << filename;
520
521             char name[256] = "unknown";
522             fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
523             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
524                 m_configShuttle.shuttledevicelist->addItem(name, filename);
525             }
526             ::close(fd);
527         }
528         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
529     }
530 }
531
532 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
533 {
534     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
535     //KdenliveSettings::setShuttledevice(device);
536     m_configShuttle.kcfg_shuttledevice->setText(device);
537 }
538
539 #endif /* NO_JOGSHUTTLE */
540
541 void KdenliveSettingsDialog::updateWidgets()
542 {
543     // Revert widgets to last saved state (for example when user pressed "Cancel")
544     // kDebug() << "// // // KCONFIG Revert called";
545 #ifndef NO_JOGSHUTTLE
546     // revert jog shuttle device
547     if (m_configShuttle.shuttledevicelist->count() > 0) {
548         for (int i = 0; i < m_configShuttle.shuttledevicelist->count(); i++) {
549             if (m_configShuttle.shuttledevicelist->itemData(i) == KdenliveSettings::shuttledevice()) {
550                 m_configShuttle.shuttledevicelist->setCurrentIndex(i);
551                 break;
552             }
553         }
554     }
555
556     // Revert jog shuttle buttons
557     QList<QString> action_names = m_mappable_actions.keys();
558     qSort(action_names);
559     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
560     QMap<QString, int> action_pos;
561     foreach (const QString& action_id, actions_map) {
562       // This loop find out at what index is the string that would map to the action_id.
563       for (int i = 0; i < action_names.size(); i++) {
564           if (m_mappable_actions[action_names[i]] == action_id) {
565               action_pos[action_id] = i;
566               break;
567           }
568       }
569     }
570     int i = 0;
571     foreach (KComboBox* button, m_shuttle_buttons) {
572       ++i;
573       if (i < actions_map.size())
574         button->setCurrentIndex(action_pos[actions_map[i]]);
575     }
576 #endif
577 }
578
579 void KdenliveSettingsDialog::updateSettings()
580 {
581     // Save changes to settings (for example when user pressed "Apply" or "Ok")
582     // kDebug() << "// // // KCONFIG UPDATE called";
583     m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
584     KdenliveSettings::setDefault_profile(m_defaultPath);
585
586     bool resetProfile = false;
587     bool updateCapturePath = false;
588
589     /*if (m_configShuttle.shuttledevicelist->count() > 0) {
590         QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
591         if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
592     }*/
593
594     if (m_configEnv.kcfg_capturetoprojectfolder->isChecked() != KdenliveSettings::capturetoprojectfolder()) {
595         KdenliveSettings::setCapturetoprojectfolder(m_configEnv.kcfg_capturetoprojectfolder->isChecked());
596         updateCapturePath = true;
597     }
598
599     if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
600         KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
601         updateCapturePath = true;
602     }
603
604     if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
605         KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
606         updateCapturePath = true;
607     }
608
609     if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
610         KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
611         updateCapturePath = true;
612     }
613
614     if ((uint) m_configCapture.kcfg_v4l_format->currentIndex() != KdenliveSettings::v4l_format()) {
615         saveCurrentV4lProfile();
616         KdenliveSettings::setV4l_format(0);
617     }
618
619     // Check encoding profiles
620     QString data = m_configCapture.kcfg_v4l_profile->itemData(m_configCapture.kcfg_v4l_profile->currentIndex()).toString();
621     if (!data.isEmpty() && (data.section(";", 0, 0) != KdenliveSettings::v4l_parameters() || data.section(";", 1, 1) != KdenliveSettings::v4l_extension())) {
622         KdenliveSettings::setV4l_parameters(data.section(";", 0, 0));
623         KdenliveSettings::setV4l_extension(data.section(";", 1, 1));
624     }
625     data = m_configCapture.kcfg_decklink_profile->itemData(m_configCapture.kcfg_decklink_profile->currentIndex()).toString();
626     if (!data.isEmpty() && (data.section(";", 0, 0) != KdenliveSettings::decklink_parameters() || data.section(";", 1, 1) != KdenliveSettings::decklink_extension())) {
627         KdenliveSettings::setDecklink_parameters(data.section(";", 0, 0));
628         KdenliveSettings::setDecklink_extension(data.section(";", 1, 1));
629     }
630     data = m_configProject.kcfg_proxy_profile->itemData(m_configProject.kcfg_proxy_profile->currentIndex()).toString();
631     if (!data.isEmpty() && (data.section(";", 0, 0) != KdenliveSettings::proxyparams() || data.section(";", 1, 1) != KdenliveSettings::proxyextension())) {
632         KdenliveSettings::setProxyparams(data.section(";", 0, 0));
633         KdenliveSettings::setProxyextension(data.section(";", 1, 1));
634     }
635
636
637     if (updateCapturePath) emit updateCaptureFolder();
638
639     QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
640     if (value != KdenliveSettings::rmd_alsadevicename()) {
641         KdenliveSettings::setRmd_alsadevicename(value);
642     }
643
644     value = m_configCapture.kcfg_v4l_alsadevice->itemData(m_configCapture.kcfg_v4l_alsadevice->currentIndex()).toString();
645     if (value != KdenliveSettings::v4l_alsadevicename()) {
646         KdenliveSettings::setV4l_alsadevicename(value);
647     }
648
649     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
650     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
651     if (value != KdenliveSettings::rmd_freq()) {
652         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
653         KdenliveSettings::setRmd_freq(value);
654     }
655
656     if (m_configSdl.kcfg_external_display->isChecked() != KdenliveSettings::external_display()) {
657         KdenliveSettings::setExternal_display(m_configSdl.kcfg_external_display->isChecked());
658         resetProfile = true;
659     }
660
661     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
662     if (value != KdenliveSettings::audiodrivername()) {
663         KdenliveSettings::setAudiodrivername(value);
664         resetProfile = true;
665     }
666
667     if (value == "alsa") {
668         // Audio device setting is only valid for alsa driver
669         value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
670         if (value != KdenliveSettings::audiodevicename()) {
671             KdenliveSettings::setAudiodevicename(value);
672             resetProfile = true;
673         }
674     } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
675         KdenliveSettings::setAudiodevicename(QString::null);
676         resetProfile = true;
677     }
678
679     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
680     if (value != KdenliveSettings::videodrivername()) {
681         KdenliveSettings::setVideodrivername(value);
682         resetProfile = true;
683     }
684
685     if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
686         KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
687         resetProfile = true;
688     }
689
690     if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
691         KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
692         resetProfile = true;
693     }
694
695     if (m_modified) {
696         // The transcoding profiles were modified, save.
697         m_modified = false;
698         saveTranscodeProfiles();
699     }
700
701 #ifndef NO_JOGSHUTTLE
702     m_shuttleModified = false;
703
704     QStringList actions;
705     actions << "monitor_pause";  // the Job rest position action.
706     foreach (KComboBox* button, m_shuttle_buttons) {
707         actions << m_mappable_actions[button->currentText()];
708     }
709     QString maps = JogShuttleConfig::actionMap(actions);
710     //fprintf(stderr, "Shuttle config: %s\n", JogShuttleConfig::actionMap(actions).toAscii().constData());
711     if (KdenliveSettings::shuttlebuttons() != maps)
712         KdenliveSettings::setShuttlebuttons(maps);
713 #endif
714
715 #if KDE_IS_VERSION(4,3,0)
716     KConfigDialog::settingsChangedSlot();
717 #endif
718
719     //KConfigDialog::updateSettings();
720     if (resetProfile) emit doResetProfile();
721 }
722
723 void KdenliveSettingsDialog::slotUpdateDisplay()
724 {
725     QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
726     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
727     m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
728     m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
729     m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
730     m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
731     if (values.value("progressive").toInt() == 0)
732         m_configProject.p_progressive->setText(i18n("Interlaced"));
733     else
734         m_configProject.p_progressive->setText(i18n("Progressive"));
735     m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
736     m_defaultPath = currentProfile;
737 }
738
739 void KdenliveSettingsDialog::slotCheckAlsaDriver()
740 {
741     QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
742     m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
743 }
744
745 void KdenliveSettingsDialog::loadTranscodeProfiles()
746 {
747     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
748     KConfigGroup transConfig(config, "Transcoding");
749     // read the entries
750     m_configTranscode.profiles_list->blockSignals(true);
751     QMap< QString, QString > profiles = transConfig.entryMap();
752     QMapIterator<QString, QString> i(profiles);
753     while (i.hasNext()) {
754         i.next();
755         QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
756         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
757     }
758     m_configTranscode.profiles_list->blockSignals(false);
759 }
760
761 void KdenliveSettingsDialog::saveTranscodeProfiles()
762 {
763     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
764     //KSharedConfigPtr config = KGlobal::config();
765     KConfigGroup transConfig(config, "Transcoding");
766     // read the entries
767     transConfig.deleteGroup();
768     int max = m_configTranscode.profiles_list->topLevelItemCount();
769     for (int i = 0; i < max; i++) {
770         QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
771         transConfig.writeEntry(item->text(0), item->text(1));
772     }
773     config->sync();
774 }
775
776 void KdenliveSettingsDialog::slotAddTranscode()
777 {
778     QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
779     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
780     m_configTranscode.profiles_list->setCurrentItem(item);
781     m_configTranscode.profiles_list->editItem(item);
782     slotDialogModified();
783 }
784
785 void KdenliveSettingsDialog::slotDeleteTranscode()
786 {
787     QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
788     if (item == NULL) return;
789     delete item;
790     slotDialogModified();
791 }
792
793 void KdenliveSettingsDialog::slotShuttleModified()
794 {
795 #ifndef NO_JOGSHUTTLE
796     QStringList actions;
797     actions << "monitor_pause";  // the Job rest position action.
798     foreach (KComboBox* button, m_shuttle_buttons) {
799         actions << m_mappable_actions[button->currentText()];
800     }
801     QString maps = JogShuttleConfig::actionMap(actions);
802     m_shuttleModified = KdenliveSettings::shuttlebuttons() != maps;
803 #endif
804 #if KDE_IS_VERSION(4,3,0)
805     KConfigDialog::updateButtons();
806 #endif
807 }
808
809 void KdenliveSettingsDialog::slotDialogModified()
810 {
811     m_modified = true;
812 #if KDE_IS_VERSION(4,3,0)
813     KConfigDialog::updateButtons();
814 #endif
815 }
816
817 //virtual
818 bool KdenliveSettingsDialog::hasChanged()
819 {
820     if (m_modified || m_shuttleModified) return true;
821     return KConfigDialog::hasChanged();
822 }
823
824 void KdenliveSettingsDialog::slotUpdatev4lDevice()
825 {
826     QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
827     if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device);
828     QString info = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
829
830     m_configCapture.kcfg_v4l_format->blockSignals(true);
831     m_configCapture.kcfg_v4l_format->clear();
832
833     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
834     if (QFile::exists(vl4ProfilePath)) {
835         m_configCapture.kcfg_v4l_format->addItem(i18n("Current settings"));
836     }
837
838     QStringList pixelformats = info.split(">", QString::SkipEmptyParts);
839     QString itemSize;
840     QString pixelFormat;
841     QStringList itemRates;
842     for (int i = 0; i < pixelformats.count(); i++) {
843         QString format = pixelformats.at(i).section(':', 0, 0);
844         QStringList sizes = pixelformats.at(i).split(":", QString::SkipEmptyParts);
845         pixelFormat = sizes.takeFirst();
846         for (int j = 0; j < sizes.count(); j++) {
847             itemSize = sizes.at(j).section("=", 0, 0);
848             itemRates = sizes.at(j).section("=", 1, 1).split(",", QString::SkipEmptyParts);
849             for (int k = 0; k < itemRates.count(); k++) {
850                 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));
851             }
852         }
853     }
854     m_configCapture.kcfg_v4l_format->blockSignals(false);
855     slotUpdatev4lCaptureProfile();
856 }
857
858 void KdenliveSettingsDialog::slotUpdatev4lCaptureProfile()
859 {
860     QStringList info = m_configCapture.kcfg_v4l_format->itemData(m_configCapture.kcfg_v4l_format->currentIndex(), Qt::UserRole).toStringList();
861     if (info.isEmpty()) {
862         // No auto info, display the current ones
863         loadCurrentV4lProfileInfo();
864         return;
865     }
866     m_configCapture.p_size->setText(info.at(1) + 'x' + info.at(2));
867     m_configCapture.p_fps->setText(info.at(3) + '/' + info.at(4));
868     m_configCapture.p_aspect->setText("1/1");
869     m_configCapture.p_display->setText(info.at(1) + '/' + info.at(2));
870     m_configCapture.p_colorspace->setText(ProfilesDialog::getColorspaceDescription(601));
871     m_configCapture.p_progressive->setText(i18n("Progressive"));
872
873     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
874     if (!QFile::exists(vl4ProfilePath)) saveCurrentV4lProfile();
875 }
876
877 void KdenliveSettingsDialog::loadCurrentV4lProfileInfo()
878 {
879     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
880     MltVideoProfile prof;
881     if (!QFile::exists(vl4ProfilePath)) {
882         // No default formats found, build one
883         prof.width = 320;
884         prof.height = 200;
885         prof.frame_rate_num = 15;
886         prof.frame_rate_den = 1;
887         prof.display_aspect_num = 4;
888         prof.display_aspect_den = 3;
889         prof.sample_aspect_num = 1;
890         prof.sample_aspect_den = 1;
891         prof.progressive = 1;
892         prof.colorspace = 601;
893         ProfilesDialog::saveProfile(prof, vl4ProfilePath);
894     }
895     else prof = ProfilesDialog::getVideoProfile(vl4ProfilePath);
896     m_configCapture.p_size->setText(QString::number(prof.width) + 'x' + QString::number(prof.height));
897     m_configCapture.p_fps->setText(QString::number(prof.frame_rate_num) + '/' + QString::number(prof.frame_rate_den));
898     m_configCapture.p_aspect->setText(QString::number(prof.sample_aspect_num) + '/' + QString::number(prof.sample_aspect_den));
899     m_configCapture.p_display->setText(QString::number(prof.display_aspect_num) + '/' + QString::number(prof.display_aspect_den));
900     m_configCapture.p_colorspace->setText(ProfilesDialog::getColorspaceDescription(prof.colorspace));
901     if (prof.progressive) m_configCapture.p_progressive->setText(i18n("Progressive"));
902 }
903
904 void KdenliveSettingsDialog::saveCurrentV4lProfile()
905 {
906     MltVideoProfile profile;
907     profile.description = "Video4Linux capture";
908     profile.colorspace = ProfilesDialog::getColorspaceFromDescription(m_configCapture.p_colorspace->text());
909     profile.width = m_configCapture.p_size->text().section('x', 0, 0).toInt();
910     profile.height = m_configCapture.p_size->text().section('x', 1, 1).toInt();
911     profile.sample_aspect_num = m_configCapture.p_aspect->text().section('/', 0, 0).toInt();
912     profile.sample_aspect_den = m_configCapture.p_aspect->text().section('/', 1, 1).toInt();
913     profile.display_aspect_num = m_configCapture.p_display->text().section('/', 0, 0).toInt();
914     profile.display_aspect_den = m_configCapture.p_display->text().section('/', 1, 1).toInt();
915     profile.frame_rate_num = m_configCapture.p_fps->text().section('/', 0, 0).toInt();
916     profile.frame_rate_den = m_configCapture.p_fps->text().section('/', 1, 1).toInt();
917     profile.progressive = m_configCapture.p_progressive->text() == i18n("Progressive");
918     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
919     ProfilesDialog::saveProfile(profile, vl4ProfilePath);
920 }
921
922 void KdenliveSettingsDialog::slotManageEncodingProfile()
923 {
924     int type = 0;
925     if (currentPage() == m_page4) {
926         if (m_configCapture.tabWidget->currentIndex() == 1) type = 1;
927         else if (m_configCapture.tabWidget->currentIndex() == 3) type = 2;
928     }
929     EncodingProfilesDialog *d = new EncodingProfilesDialog(type);
930     d->exec();
931     delete d;
932     loadEncodingProfiles();
933 }
934
935 void KdenliveSettingsDialog::loadEncodingProfiles()
936 {
937     KConfig conf("encodingprofiles.rc", KConfig::FullConfig, "appdata");
938
939     // Load v4l profiles
940     m_configCapture.kcfg_v4l_profile->blockSignals(true);
941     QString currentItem = m_configCapture.kcfg_v4l_profile->currentText();
942     m_configCapture.kcfg_v4l_profile->clear();
943     KConfigGroup group(&conf, "video4linux");
944     QMap< QString, QString > values = group.entryMap();
945     QMapIterator<QString, QString> i(values);
946     while (i.hasNext()) {
947         i.next();
948         if (!i.key().isEmpty()) m_configCapture.kcfg_v4l_profile->addItem(i.key(), i.value());
949     }
950     m_configCapture.kcfg_v4l_profile->blockSignals(false);
951     if (!currentItem.isEmpty()) m_configCapture.kcfg_v4l_profile->setCurrentIndex(m_configCapture.kcfg_v4l_profile->findText(currentItem));
952
953     // Load Decklink profiles
954     m_configCapture.kcfg_decklink_profile->blockSignals(true);
955     currentItem = m_configCapture.kcfg_decklink_profile->currentText();
956     m_configCapture.kcfg_decklink_profile->clear();
957     KConfigGroup group2(&conf, "decklink");
958     values = group2.entryMap();
959     QMapIterator<QString, QString> j(values);
960     while (j.hasNext()) {
961         j.next();
962         if (!j.key().isEmpty()) m_configCapture.kcfg_decklink_profile->addItem(j.key(), j.value());
963     }
964     m_configCapture.kcfg_decklink_profile->blockSignals(false);
965     if (!currentItem.isEmpty()) m_configCapture.kcfg_decklink_profile->setCurrentIndex(m_configCapture.kcfg_decklink_profile->findText(currentItem));
966
967     // Load Proxy profiles
968     m_configProject.kcfg_proxy_profile->blockSignals(true);
969     currentItem = m_configProject.kcfg_proxy_profile->currentText();
970     m_configProject.kcfg_proxy_profile->clear();
971     KConfigGroup group3(&conf, "proxy");
972     values = group3.entryMap();
973     QMapIterator<QString, QString> k(values);
974     while (k.hasNext()) {
975         k.next();
976         if (!k.key().isEmpty()) m_configProject.kcfg_proxy_profile->addItem(k.key(), k.value());
977     }
978     if (!currentItem.isEmpty()) m_configProject.kcfg_proxy_profile->setCurrentIndex(m_configProject.kcfg_proxy_profile->findText(currentItem));
979     m_configProject.kcfg_proxy_profile->blockSignals(false);
980     slotUpdateProxyProfile();
981     
982 }
983
984 void KdenliveSettingsDialog::slotUpdateDecklinkProfile(int ix)
985 {
986     if (ix == -1) ix = KdenliveSettings::decklink_profile();
987     else ix = m_configCapture.kcfg_decklink_profile->currentIndex();
988     QString data = m_configCapture.kcfg_decklink_profile->itemData(ix).toString();
989     if (data.isEmpty()) return;
990     m_configCapture.decklink_parameters->setPlainText(data.section(";", 0, 0));
991     //
992 }
993
994 void KdenliveSettingsDialog::slotUpdateV4lProfile(int ix)
995 {
996     if (ix == -1) ix = KdenliveSettings::v4l_profile();
997     else ix = m_configCapture.kcfg_v4l_profile->currentIndex();
998     QString data = m_configCapture.kcfg_v4l_profile->itemData(ix).toString();
999     if (data.isEmpty()) return;
1000     m_configCapture.v4l_parameters->setPlainText(data.section(";", 0, 0));
1001     //
1002 }
1003
1004 void KdenliveSettingsDialog::slotUpdateProxyProfile(int ix)
1005 {
1006     if (ix == -1) ix = KdenliveSettings::v4l_profile();
1007     else ix = m_configProject.kcfg_proxy_profile->currentIndex();
1008     QString data = m_configProject.kcfg_proxy_profile->itemData(ix).toString();
1009     if (data.isEmpty()) return;
1010     m_configProject.proxyparams->setPlainText(data.section(";", 0, 0));
1011     //
1012 }
1013
1014 void KdenliveSettingsDialog::slotEditVideo4LinuxProfile()
1015 {
1016     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
1017     ProfilesDialog *w = new ProfilesDialog(vl4ProfilePath);
1018     if (w->exec() == QDialog::Accepted) {
1019         // save and update profile
1020         loadCurrentV4lProfileInfo();
1021     }
1022     delete w;
1023 }
1024
1025 #include "kdenlivesettingsdialog.moc"
1026
1027