1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
20 #include "kdenlivesettingsdialog.h"
21 #include "profilesdialog.h"
22 #include "v4l/v4lcapture.h"
23 #include "blackmagic/devices.h"
24 #include "kdenlivesettings.h"
26 #include <KStandardDirs>
28 #include <kopenwithdialog.h>
29 #include <KConfigDialogManager>
31 #include <KIO/NetAccess>
32 #include <kdeversion.h>
36 #include <QTreeWidgetItem>
44 #include "jogaction.h"
45 #include "jogshuttleconfig.h"
46 #include <linux/input.h>
47 #endif /* NO_JOGSHUTTLE */
50 KdenliveSettingsDialog::KdenliveSettingsDialog(const QMap<QString, QString>& mappable_actions, QWidget * parent) :
51 KConfigDialog(parent, "settings", KdenliveSettings::self()),
53 m_shuttleModified(false),
54 m_mappable_actions(mappable_actions)
57 QWidget *p1 = new QWidget;
58 m_configMisc.setupUi(p1);
59 m_page1 = addPage(p1, i18n("Misc"), "configure");
61 // Hide multi tab option until Kdenlive really supports it
62 m_configMisc.kcfg_activatetabs->setVisible(false);
64 QWidget *p8 = new QWidget;
65 m_configProject.setupUi(p8);
66 m_page8 = addPage(p8, i18n("Project Defaults"), "document-new");
67 connect(m_configProject.kcfg_generateproxy, SIGNAL(toggled(bool)), m_configProject.kcfg_proxyminsize, SLOT(setEnabled(bool)));
68 m_configProject.kcfg_proxyminsize->setEnabled(KdenliveSettings::generateproxy());
69 m_configProject.kcfg_proxyparams->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
71 QWidget *p3 = new QWidget;
72 m_configTimeline.setupUi(p3);
73 m_page3 = addPage(p3, i18n("Timeline"), "video-display");
75 QWidget *p2 = new QWidget;
76 m_configEnv.setupUi(p2);
77 m_configEnv.mltpathurl->setMode(KFile::Directory);
78 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
79 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
80 m_configEnv.kcfg_mltthreads->setMaximum(QThread::idealThreadCount());
81 m_configEnv.tmppathurl->setMode(KFile::Directory);
82 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
83 m_configEnv.projecturl->setMode(KFile::Directory);
84 m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
85 m_configEnv.capturefolderurl->setMode(KFile::Directory);
86 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
87 m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
88 connect(m_configEnv.kcfg_capturetoprojectfolder, SIGNAL(clicked()), this, SLOT(slotEnableCaptureFolder()));
89 m_page2 = addPage(p2, i18n("Environment"), "application-x-executable-script");
91 QWidget *p4 = new QWidget;
92 m_configCapture.setupUi(p4);
94 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
95 V4lCaptureHandler v4l(NULL);
96 // Video 4 Linux device detection
97 for (int i = 0; i < 10; i++) {
98 QString path = "/dev/video" + QString::number(i);
99 if (QFile::exists(path)) {
100 QStringList deviceInfo = v4l.getDeviceName(path);
101 if (!deviceInfo.isEmpty()) {
102 m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
103 m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
107 connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice()));
110 m_page4 = addPage(p4, i18n("Capture"), "media-record");
111 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
113 m_configCapture.tabWidget->setEnabled(false);
114 m_configCapture.kcfg_defaultcapture->setEnabled(false);
115 m_configCapture.label->setText(i18n("Capture is not yet available on OS X."));
118 QWidget *p5 = new QWidget;
119 m_configShuttle.setupUi(p5);
121 m_configShuttle.kcfg_enableshuttle->hide();
122 m_configShuttle.kcfg_enableshuttle->setDisabled(true);
124 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
125 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
126 slotCheckShuttle(KdenliveSettings::enableshuttle());
127 m_configShuttle.shuttledisabled->hide();
129 // Store the button pointers into an array for easier handling them in the other functions.
130 m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
131 m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
132 m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
133 m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
134 m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
136 // populate the buttons with the current configuration. The items are sorted
137 // according to the user-selected language, so they do not appear in random order.
138 QList<QString> action_names = mappable_actions.keys();
141 // Here we need to compute the action_id -> index-in-action_names. We iterate over the
142 // action_names, as the sorting may depend on the user-language.
143 QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
144 QMap<QString, int> action_pos;
145 foreach (const QString& action_id, actions_map) {
146 // This loop find out at what index is the string that would map to the action_id.
147 for (int i = 0; i < action_names.size(); i++) {
148 if (mappable_actions[action_names[i]] == action_id) {
149 action_pos[action_id] = i;
156 foreach (KComboBox* button, m_shuttle_buttons) {
157 button->addItems(action_names);
158 connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
160 if (i < actions_map.size())
161 button->setCurrentIndex(action_pos[actions_map[i]]);
163 #endif /* NO_JOGSHUTTLE */
164 m_page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
166 QWidget *p6 = new QWidget;
167 m_configSdl.setupUi(p6);
169 #if not defined(Q_WS_MAC) && not defined(USE_OPEN_GL)
170 m_configSdl.kcfg_openglmonitors->setHidden(true);
173 m_page6 = addPage(p6, i18n("Playback"), "media-playback-start");
175 QWidget *p7 = new QWidget;
176 m_configTranscode.setupUi(p7);
177 m_page7 = addPage(p7, i18n("Transcode"), "edit-copy");
178 connect(m_configTranscode.button_add, SIGNAL(clicked()), this, SLOT(slotAddTranscode()));
179 connect(m_configTranscode.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteTranscode()));
180 connect(m_configTranscode.profiles_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotDialogModified()));
182 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
183 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
184 connect(m_configCapture.kcfg_video4vcodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
185 connect(m_configCapture.kcfg_video4acodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
186 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
187 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
188 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
189 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
191 connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
193 m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
195 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
196 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
197 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
203 connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
205 connect(m_configProject.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
206 connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
208 slotUpdateRmdRegionStatus();
209 loadTranscodeProfiles();
212 //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
213 // --timestamp option without bug
215 if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
216 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
217 KdenliveSettings::setDvgrab_path(dvgrabpath);
221 BMInterface::getBlackMagicDeviceList(m_configCapture.kcfg_hdmi_capturedevice, m_configCapture.kcfg_hdmi_capturemode);
222 connect(m_configCapture.kcfg_hdmi_capturedevice, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHDMIModes()));
224 if (BMInterface::getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
225 // Found blackmagic card
226 } else m_configSdl.kcfg_external_display->setEnabled(false);
228 double dvgrabVersion = 0;
229 if (!KdenliveSettings::dvgrab_path().isEmpty()) {
230 QProcess *versionCheck = new QProcess;
231 versionCheck->setProcessChannelMode(QProcess::MergedChannels);
232 versionCheck->start("dvgrab", QStringList() << "--version");
233 if (versionCheck->waitForFinished()) {
234 QString version = QString(versionCheck->readAll()).simplified();
235 if (version.contains(' ')) version = version.section(' ', -1);
236 dvgrabVersion = version.toDouble();
238 kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
241 if (dvgrabVersion < 3.3) {
242 KdenliveSettings::setFirewiretimestamp(false);
243 m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
245 m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
246 } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
248 if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
249 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
250 KdenliveSettings::setRmd_path(rmdpath);
252 if (KdenliveSettings::rmd_path().isEmpty())
253 m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
255 m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
258 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
260 void KdenliveSettingsDialog::slotUpdateHDMIModes()
262 QStringList modes = m_configCapture.kcfg_hdmi_capturedevice->itemData(m_configCapture.kcfg_hdmi_capturedevice->currentIndex()).toStringList();
263 m_configCapture.kcfg_hdmi_capturemode->clear();
264 m_configCapture.kcfg_hdmi_capturemode->insertItems(0, modes);
267 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
269 m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
272 void KdenliveSettingsDialog::slotEnableCaptureFolder()
274 m_configEnv.capturefolderurl->setEnabled(!m_configEnv.kcfg_capturetoprojectfolder->isChecked());
277 void KdenliveSettingsDialog::checkProfile()
279 m_configProject.kcfg_profiles_list->clear();
280 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
281 QMapIterator<QString, QString> i(profilesInfo);
282 while (i.hasNext()) {
284 m_configProject.kcfg_profiles_list->addItem(i.key(), i.value());
287 if (!KdenliveSettings::default_profile().isEmpty()) {
288 for (int i = 0; i < m_configProject.kcfg_profiles_list->count(); i++) {
289 if (m_configProject.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
290 m_configProject.kcfg_profiles_list->setCurrentIndex(i);
291 KdenliveSettings::setProfiles_list(i);
298 void KdenliveSettingsDialog::initDevices()
300 // Fill audio drivers
301 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
303 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
304 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
305 m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
306 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
307 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
308 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
311 if (!KdenliveSettings::audiodrivername().isEmpty())
312 for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); i++) {
313 if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
314 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
315 KdenliveSettings::setAudio_driver((uint) i);
319 // Fill video drivers
320 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
322 m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
323 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
324 m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
325 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
326 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
327 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
328 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
329 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
330 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
333 // Fill the list of audio playback devices
334 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
335 m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
336 if (!KStandardDirs::findExe("aplay").isEmpty()) {
337 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
338 m_readProcess.setProgram("aplay", QStringList() << "-l");
339 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
340 m_readProcess.execute(5000);
342 // If aplay is not installed on the system, parse the /proc/asound/pcm file
343 QFile file("/proc/asound/pcm");
344 if (file.open(QIODevice::ReadOnly)) {
345 QTextStream stream(&file);
348 while (!stream.atEnd()) {
349 line = stream.readLine();
350 if (line.contains("playback")) {
351 deviceId = line.section(':', 0, 0);
352 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()));
354 if (line.contains("capture")) {
355 deviceId = line.section(':', 0, 0);
356 m_configCapture.kcfg_rmd_alsa_device->addItem(line.section(':', 1, 1), "plughw:" + QString::number(deviceId.section('-', 0, 0).toInt()) + ',' + QString::number(deviceId.section('-', 1, 1).toInt()));
362 if (!KdenliveSettings::audiodevicename().isEmpty()) {
363 // Select correct alsa device
364 int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
365 m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
366 KdenliveSettings::setAudio_device(ix);
368 if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
369 // Select correct alsa device
370 int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
371 m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
372 KdenliveSettings::setRmd_alsa_device(ix);
377 void KdenliveSettingsDialog::slotReadAudioDevices()
379 QString result = QString(m_readProcess.readAllStandardOutput());
380 kDebug() << "// / / / / / READING APLAY: ";
382 QStringList lines = result.split('\n');
383 foreach(const QString & data, lines) {
384 kDebug() << "// READING LINE: " << data;
385 if (data.simplified().startsWith("card")) {
386 QString card = data.section(':', 0, 0).section(' ', -1);
387 QString device = data.section(':', 1, 1).section(' ', -1);
388 m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
389 m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
394 void KdenliveSettingsDialog::showPage(int page, int option)
398 setCurrentPage(m_page1);
401 setCurrentPage(m_page2);
404 setCurrentPage(m_page3);
407 setCurrentPage(m_page4);
408 m_configCapture.tabWidget->setCurrentIndex(option);
411 setCurrentPage(m_page5);
414 setCurrentPage(m_page6);
417 setCurrentPage(m_page7);
420 setCurrentPage(m_page1);
424 void KdenliveSettingsDialog::slotEditVideoApplication()
426 KService::Ptr service;
427 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
428 if (dlg.exec() != QDialog::Accepted)
431 service = dlg.service();
432 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
435 void KdenliveSettingsDialog::slotEditAudioApplication()
437 KService::Ptr service;
438 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
439 if (dlg.exec() != QDialog::Accepted)
442 service = dlg.service();
443 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
446 void KdenliveSettingsDialog::slotEditImageApplication()
448 KService::Ptr service;
449 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
450 if (dlg.exec() != QDialog::Accepted)
453 service = dlg.service();
454 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
457 #ifndef NO_JOGSHUTTLE
458 void KdenliveSettingsDialog::slotCheckShuttle(int state)
460 m_configShuttle.config_group->setEnabled(state);
461 if (m_configShuttle.shuttledevicelist->count() == 0) {
463 QString baseName = "/dev/input/event";
465 for (int i = 0; i < 30; i++) {
466 QString filename = baseName + QString::number(i);
467 kDebug() << "/// CHECKING OFR: " << filename;
469 char name[256] = "unknown";
470 fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
471 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
472 m_configShuttle.shuttledevicelist->addItem(name, filename);
476 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
480 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
482 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
483 //KdenliveSettings::setShuttledevice(device);
484 m_configShuttle.kcfg_shuttledevice->setText(device);
487 #endif /* NO_JOGSHUTTLE */
489 void KdenliveSettingsDialog::rebuildVideo4Commands()
491 QString captureCommand;
492 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text() + " -acodec " + m_configCapture.kcfg_video4acodec->text();
494 captureCommand += " -f " + m_configCapture.kcfg_video4vformat->text() + " -s " + m_configCapture.kcfg_video4size->text() + " -r " + QString::number(m_configCapture.kcfg_video4rate->value()) + " -i " + m_configCapture.kcfg_video4vdevice->text() + " -vcodec " + m_configCapture.kcfg_video4vcodec->text();
495 m_configCapture.kcfg_video4capture->setText(captureCommand);
497 void KdenliveSettingsDialog::updateWidgets()
499 // Revert widgets to last saved state (for example when user pressed "Cancel")
500 // kDebug() << "// // // KCONFIG Revert called";
501 #ifndef NO_JOGSHUTTLE
502 // revert jog shuttle device
503 if (m_configShuttle.shuttledevicelist->count() > 0) {
504 for (int i = 0; i < m_configShuttle.shuttledevicelist->count(); i++) {
505 if (m_configShuttle.shuttledevicelist->itemData(i) == KdenliveSettings::shuttledevice()) {
506 m_configShuttle.shuttledevicelist->setCurrentIndex(i);
512 // Revert jog shuttle buttons
513 QList<QString> action_names = m_mappable_actions.keys();
515 QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
516 QMap<QString, int> action_pos;
517 foreach (const QString& action_id, actions_map) {
518 // This loop find out at what index is the string that would map to the action_id.
519 for (int i = 0; i < action_names.size(); i++) {
520 if (m_mappable_actions[action_names[i]] == action_id) {
521 action_pos[action_id] = i;
527 foreach (KComboBox* button, m_shuttle_buttons) {
529 if (i < actions_map.size())
530 button->setCurrentIndex(action_pos[actions_map[i]]);
535 void KdenliveSettingsDialog::updateSettings()
537 // Save changes to settings (for example when user pressed "Apply" or "Ok")
538 // kDebug() << "// // // KCONFIG UPDATE called";
539 m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
540 KdenliveSettings::setDefault_profile(m_defaultPath);
542 bool resetProfile = false;
543 bool updateCapturePath = false;
545 /*if (m_configShuttle.shuttledevicelist->count() > 0) {
546 QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
547 if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
550 if (m_configEnv.kcfg_capturetoprojectfolder->isChecked() != KdenliveSettings::capturetoprojectfolder()) {
551 KdenliveSettings::setCapturetoprojectfolder(m_configEnv.kcfg_capturetoprojectfolder->isChecked());
552 updateCapturePath = true;
555 if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
556 KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
557 updateCapturePath = true;
560 if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
561 KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
562 updateCapturePath = true;
565 if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
566 KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
567 updateCapturePath = true;
570 if (updateCapturePath) emit updateCaptureFolder();
572 QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
573 if (value != KdenliveSettings::rmd_alsadevicename()) {
574 KdenliveSettings::setRmd_alsadevicename(value);
577 value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
578 kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
579 if (value != KdenliveSettings::rmd_freq()) {
580 kDebug() << "// SETTING AUDIO FREQ TO: " << value;
581 KdenliveSettings::setRmd_freq(value);
584 if (m_configSdl.kcfg_external_display->isChecked() != KdenliveSettings::external_display()) {
585 KdenliveSettings::setExternal_display(m_configSdl.kcfg_external_display->isChecked());
589 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
590 if (value != KdenliveSettings::audiodrivername()) {
591 KdenliveSettings::setAudiodrivername(value);
595 if (value == "alsa") {
596 // Audio device setting is only valid for alsa driver
597 value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
598 if (value != KdenliveSettings::audiodevicename()) {
599 KdenliveSettings::setAudiodevicename(value);
602 } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
603 KdenliveSettings::setAudiodevicename(QString::null);
607 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
608 if (value != KdenliveSettings::videodrivername()) {
609 KdenliveSettings::setVideodrivername(value);
613 if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
614 KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
618 if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
619 KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
623 if (m_configProject.kcfg_enableproxy->isChecked() != KdenliveSettings::enableproxy()) {
624 KdenliveSettings::setEnableproxy(m_configProject.kcfg_enableproxy->isChecked());
627 if (m_configProject.kcfg_generateproxy->isChecked() != KdenliveSettings::generateproxy()) {
628 KdenliveSettings::setGenerateproxy(m_configProject.kcfg_generateproxy->isChecked());
631 if (m_configProject.kcfg_proxyminsize->value() != KdenliveSettings::proxyminsize()) {
632 KdenliveSettings::setProxyminsize(m_configProject.kcfg_proxyminsize->value());
636 // The transcoding profiles were modified, save.
638 saveTranscodeProfiles();
641 #ifndef NO_JOGSHUTTLE
642 m_shuttleModified = false;
645 actions << "monitor_pause"; // the Job rest position action.
646 foreach (KComboBox* button, m_shuttle_buttons) {
647 actions << m_mappable_actions[button->currentText()];
649 QString maps = JogShuttleConfig::actionMap(actions);
650 //fprintf(stderr, "Shuttle config: %s\n", JogShuttleConfig::actionMap(actions).toAscii().constData());
651 if (KdenliveSettings::shuttlebuttons() != maps)
652 KdenliveSettings::setShuttlebuttons(maps);
655 #if KDE_IS_VERSION(4,3,0)
656 KConfigDialog::settingsChangedSlot();
659 //KConfigDialog::updateSettings();
660 if (resetProfile) emit doResetProfile();
663 void KdenliveSettingsDialog::slotUpdateDisplay()
665 QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
666 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
667 m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
668 m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
669 m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
670 m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
671 if (values.value("progressive").toInt() == 0)
672 m_configProject.p_progressive->setText(i18n("Interlaced"));
674 m_configProject.p_progressive->setText(i18n("Progressive"));
675 m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
676 m_defaultPath = currentProfile;
679 void KdenliveSettingsDialog::slotCheckAlsaDriver()
681 QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
682 m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
685 void KdenliveSettingsDialog::loadTranscodeProfiles()
687 KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
688 KConfigGroup transConfig(config, "Transcoding");
690 m_configTranscode.profiles_list->blockSignals(true);
691 QMap< QString, QString > profiles = transConfig.entryMap();
692 QMapIterator<QString, QString> i(profiles);
693 while (i.hasNext()) {
695 QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
696 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
698 m_configTranscode.profiles_list->blockSignals(false);
701 void KdenliveSettingsDialog::saveTranscodeProfiles()
703 KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
704 //KSharedConfigPtr config = KGlobal::config();
705 KConfigGroup transConfig(config, "Transcoding");
707 transConfig.deleteGroup();
708 int max = m_configTranscode.profiles_list->topLevelItemCount();
709 for (int i = 0; i < max; i++) {
710 QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
711 transConfig.writeEntry(item->text(0), item->text(1));
716 void KdenliveSettingsDialog::slotAddTranscode()
718 QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
719 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
720 m_configTranscode.profiles_list->setCurrentItem(item);
721 m_configTranscode.profiles_list->editItem(item);
722 slotDialogModified();
725 void KdenliveSettingsDialog::slotDeleteTranscode()
727 QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
728 if (item == NULL) return;
730 slotDialogModified();
733 void KdenliveSettingsDialog::slotShuttleModified()
735 #ifndef NO_JOGSHUTTLE
737 actions << "monitor_pause"; // the Job rest position action.
738 foreach (KComboBox* button, m_shuttle_buttons) {
739 actions << m_mappable_actions[button->currentText()];
741 QString maps = JogShuttleConfig::actionMap(actions);
742 m_shuttleModified = KdenliveSettings::shuttlebuttons() != maps;
744 #if KDE_IS_VERSION(4,3,0)
745 KConfigDialog::updateButtons();
749 void KdenliveSettingsDialog::slotDialogModified()
752 #if KDE_IS_VERSION(4,3,0)
753 KConfigDialog::updateButtons();
758 bool KdenliveSettingsDialog::hasChanged()
760 if (m_modified || m_shuttleModified) return true;
761 return KConfigDialog::hasChanged();
764 void KdenliveSettingsDialog::slotUpdatev4lDevice()
766 QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
767 if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device);
768 QString size = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
769 if (!size.isEmpty()) m_configCapture.kcfg_video4size->setText(size);
770 rebuildVideo4Commands();
774 #include "kdenlivesettingsdialog.moc"