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