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