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_enableproxy, SIGNAL(toggled(bool)), m_configProject.proxy_frame, SLOT(setEnabled(bool)));
68 m_configProject.proxy_frame->setEnabled(KdenliveSettings::enableproxy());
70 QWidget *p3 = new QWidget;
71 m_configTimeline.setupUi(p3);
72 m_page3 = addPage(p3, i18n("Timeline"), "video-display");
74 QWidget *p2 = new QWidget;
75 m_configEnv.setupUi(p2);
76 m_configEnv.mltpathurl->setMode(KFile::Directory);
77 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
78 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
79 m_configEnv.kcfg_mltthreads->setMaximum(QThread::idealThreadCount());
80 m_configEnv.tmppathurl->setMode(KFile::Directory);
81 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
82 m_configEnv.projecturl->setMode(KFile::Directory);
83 m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
84 m_configEnv.capturefolderurl->setMode(KFile::Directory);
85 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
86 m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
87 connect(m_configEnv.kcfg_capturetoprojectfolder, SIGNAL(clicked()), this, SLOT(slotEnableCaptureFolder()));
88 m_page2 = addPage(p2, i18n("Environment"), "application-x-executable-script");
90 QWidget *p4 = new QWidget;
91 m_configCapture.setupUi(p4);
93 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
94 V4lCaptureHandler v4l(NULL);
95 // Video 4 Linux device detection
96 for (int i = 0; i < 10; i++) {
97 QString path = "/dev/video" + QString::number(i);
98 if (QFile::exists(path)) {
99 QStringList deviceInfo = v4l.getDeviceName(path);
100 if (!deviceInfo.isEmpty()) {
101 m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
102 m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
106 connect(m_configCapture.kcfg_detectedv4ldevices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdatev4lDevice()));
109 m_page4 = addPage(p4, i18n("Capture"), "media-record");
110 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
112 m_configCapture.tabWidget->setEnabled(false);
113 m_configCapture.kcfg_defaultcapture->setEnabled(false);
114 m_configCapture.label->setText(i18n("Capture is not yet available on OS X."));
117 QWidget *p5 = new QWidget;
118 m_configShuttle.setupUi(p5);
120 m_configShuttle.kcfg_enableshuttle->hide();
121 m_configShuttle.kcfg_enableshuttle->setDisabled(true);
123 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
124 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
125 slotCheckShuttle(KdenliveSettings::enableshuttle());
126 m_configShuttle.shuttledisabled->hide();
128 // Store the button pointers into an array for easier handling them in the other functions.
129 m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
130 m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
131 m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
132 m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
133 m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
135 // populate the buttons with the current configuration. The items are sorted
136 // according to the user-selected language, so they do not appear in random order.
137 QList<QString> action_names = mappable_actions.keys();
140 // Here we need to compute the action_id -> index-in-action_names. We iterate over the
141 // action_names, as the sorting may depend on the user-language.
142 QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
143 QMap<QString, int> action_pos;
144 foreach (const QString& action_id, actions_map) {
145 // This loop find out at what index is the string that would map to the action_id.
146 for (int i = 0; i < action_names.size(); i++) {
147 if (mappable_actions[action_names[i]] == action_id) {
148 action_pos[action_id] = i;
155 foreach (KComboBox* button, m_shuttle_buttons) {
156 button->addItems(action_names);
157 connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
159 if (i < actions_map.size())
160 button->setCurrentIndex(action_pos[actions_map[i]]);
162 #endif /* NO_JOGSHUTTLE */
163 m_page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
165 QWidget *p6 = new QWidget;
166 m_configSdl.setupUi(p6);
168 #if not defined(Q_WS_MAC) && not defined(USE_OPEN_GL)
169 m_configSdl.kcfg_openglmonitors->setHidden(true);
172 m_page6 = addPage(p6, i18n("Playback"), "media-playback-start");
174 QWidget *p7 = new QWidget;
175 m_configTranscode.setupUi(p7);
176 m_page7 = addPage(p7, i18n("Transcode"), "edit-copy");
177 connect(m_configTranscode.button_add, SIGNAL(clicked()), this, SLOT(slotAddTranscode()));
178 connect(m_configTranscode.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteTranscode()));
179 connect(m_configTranscode.profiles_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotDialogModified()));
181 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
182 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
183 connect(m_configCapture.kcfg_video4vcodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
184 connect(m_configCapture.kcfg_video4acodec, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
185 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
186 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
187 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
188 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
190 connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
192 m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
194 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
195 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
196 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
202 connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
204 connect(m_configProject.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
205 connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
207 slotUpdateRmdRegionStatus();
208 loadTranscodeProfiles();
211 //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
212 // --timestamp option without bug
214 if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
215 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
216 KdenliveSettings::setDvgrab_path(dvgrabpath);
220 BMInterface::getBlackMagicDeviceList(m_configCapture.kcfg_hdmi_capturedevice, m_configCapture.kcfg_hdmi_capturemode);
221 connect(m_configCapture.kcfg_hdmi_capturedevice, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHDMIModes()));
223 if (BMInterface::getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
224 // Found blackmagic card
225 } else m_configSdl.kcfg_external_display->setEnabled(false);
227 double dvgrabVersion = 0;
228 if (!KdenliveSettings::dvgrab_path().isEmpty()) {
229 QProcess *versionCheck = new QProcess;
230 versionCheck->setProcessChannelMode(QProcess::MergedChannels);
231 versionCheck->start("dvgrab", QStringList() << "--version");
232 if (versionCheck->waitForFinished()) {
233 QString version = QString(versionCheck->readAll()).simplified();
234 if (version.contains(' ')) version = version.section(' ', -1);
235 dvgrabVersion = version.toDouble();
237 kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
240 if (dvgrabVersion < 3.3) {
241 KdenliveSettings::setFirewiretimestamp(false);
242 m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
244 m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
245 } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
247 if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
248 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
249 KdenliveSettings::setRmd_path(rmdpath);
251 if (KdenliveSettings::rmd_path().isEmpty())
252 m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
254 m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
257 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
259 void KdenliveSettingsDialog::slotUpdateHDMIModes()
261 QStringList modes = m_configCapture.kcfg_hdmi_capturedevice->itemData(m_configCapture.kcfg_hdmi_capturedevice->currentIndex()).toStringList();
262 m_configCapture.kcfg_hdmi_capturemode->clear();
263 m_configCapture.kcfg_hdmi_capturemode->insertItems(0, modes);
266 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
268 m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
271 void KdenliveSettingsDialog::slotEnableCaptureFolder()
273 m_configEnv.capturefolderurl->setEnabled(!m_configEnv.kcfg_capturetoprojectfolder->isChecked());
276 void KdenliveSettingsDialog::checkProfile()
278 m_configProject.kcfg_profiles_list->clear();
279 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
280 QMapIterator<QString, QString> i(profilesInfo);
281 while (i.hasNext()) {
283 m_configProject.kcfg_profiles_list->addItem(i.key(), i.value());
286 if (!KdenliveSettings::default_profile().isEmpty()) {
287 for (int i = 0; i < m_configProject.kcfg_profiles_list->count(); i++) {
288 if (m_configProject.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
289 m_configProject.kcfg_profiles_list->setCurrentIndex(i);
290 KdenliveSettings::setProfiles_list(i);
297 void KdenliveSettingsDialog::initDevices()
299 // Fill audio drivers
300 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
302 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
303 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
304 m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
305 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
306 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
307 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
310 if (!KdenliveSettings::audiodrivername().isEmpty())
311 for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); i++) {
312 if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
313 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
314 KdenliveSettings::setAudio_driver((uint) i);
318 // Fill video drivers
319 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
321 m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
322 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
323 m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
324 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
325 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
326 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
327 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
328 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
329 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
332 // Fill the list of audio playback devices
333 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
334 m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
335 if (!KStandardDirs::findExe("aplay").isEmpty()) {
336 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
337 m_readProcess.setProgram("aplay", QStringList() << "-l");
338 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
339 m_readProcess.execute(5000);
341 // If aplay is not installed on the system, parse the /proc/asound/pcm file
342 QFile file("/proc/asound/pcm");
343 if (file.open(QIODevice::ReadOnly)) {
344 QTextStream stream(&file);
347 while (!stream.atEnd()) {
348 line = stream.readLine();
349 if (line.contains("playback")) {
350 deviceId = line.section(':', 0, 0);
351 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()));
353 if (line.contains("capture")) {
354 deviceId = line.section(':', 0, 0);
355 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()));
361 if (!KdenliveSettings::audiodevicename().isEmpty()) {
362 // Select correct alsa device
363 int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
364 m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
365 KdenliveSettings::setAudio_device(ix);
367 if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
368 // Select correct alsa device
369 int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
370 m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
371 KdenliveSettings::setRmd_alsa_device(ix);
376 void KdenliveSettingsDialog::slotReadAudioDevices()
378 QString result = QString(m_readProcess.readAllStandardOutput());
379 kDebug() << "// / / / / / READING APLAY: ";
381 QStringList lines = result.split('\n');
382 foreach(const QString & data, lines) {
383 kDebug() << "// READING LINE: " << data;
384 if (data.simplified().startsWith("card")) {
385 QString card = data.section(':', 0, 0).section(' ', -1);
386 QString device = data.section(':', 1, 1).section(' ', -1);
387 m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
388 m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
393 void KdenliveSettingsDialog::showPage(int page, int option)
397 setCurrentPage(m_page1);
400 setCurrentPage(m_page2);
403 setCurrentPage(m_page3);
406 setCurrentPage(m_page4);
407 m_configCapture.tabWidget->setCurrentIndex(option);
410 setCurrentPage(m_page5);
413 setCurrentPage(m_page6);
416 setCurrentPage(m_page7);
419 setCurrentPage(m_page1);
423 void KdenliveSettingsDialog::slotEditVideoApplication()
425 KService::Ptr service;
426 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
427 if (dlg.exec() != QDialog::Accepted)
430 service = dlg.service();
431 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
434 void KdenliveSettingsDialog::slotEditAudioApplication()
436 KService::Ptr service;
437 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
438 if (dlg.exec() != QDialog::Accepted)
441 service = dlg.service();
442 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
445 void KdenliveSettingsDialog::slotEditImageApplication()
447 KService::Ptr service;
448 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
449 if (dlg.exec() != QDialog::Accepted)
452 service = dlg.service();
453 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
456 #ifndef NO_JOGSHUTTLE
457 void KdenliveSettingsDialog::slotCheckShuttle(int state)
459 m_configShuttle.config_group->setEnabled(state);
460 if (m_configShuttle.shuttledevicelist->count() == 0) {
462 QString baseName = "/dev/input/event";
464 for (int i = 0; i < 30; i++) {
465 QString filename = baseName + QString::number(i);
466 kDebug() << "/// CHECKING OFR: " << filename;
468 char name[256] = "unknown";
469 fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
470 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
471 m_configShuttle.shuttledevicelist->addItem(name, filename);
475 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
479 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
481 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
482 //KdenliveSettings::setShuttledevice(device);
483 m_configShuttle.kcfg_shuttledevice->setText(device);
486 #endif /* NO_JOGSHUTTLE */
488 void KdenliveSettingsDialog::rebuildVideo4Commands()
490 QString captureCommand;
491 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();
493 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();
494 m_configCapture.kcfg_video4capture->setText(captureCommand);
496 void KdenliveSettingsDialog::updateWidgets()
498 // Revert widgets to last saved state (for example when user pressed "Cancel")
499 // kDebug() << "// // // KCONFIG Revert called";
500 #ifndef NO_JOGSHUTTLE
501 // revert jog shuttle device
502 if (m_configShuttle.shuttledevicelist->count() > 0) {
503 for (int i = 0; i < m_configShuttle.shuttledevicelist->count(); i++) {
504 if (m_configShuttle.shuttledevicelist->itemData(i) == KdenliveSettings::shuttledevice()) {
505 m_configShuttle.shuttledevicelist->setCurrentIndex(i);
511 // Revert jog shuttle buttons
512 QList<QString> action_names = m_mappable_actions.keys();
514 QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
515 QMap<QString, int> action_pos;
516 foreach (const QString& action_id, actions_map) {
517 // This loop find out at what index is the string that would map to the action_id.
518 for (int i = 0; i < action_names.size(); i++) {
519 if (m_mappable_actions[action_names[i]] == action_id) {
520 action_pos[action_id] = i;
526 foreach (KComboBox* button, m_shuttle_buttons) {
528 if (i < actions_map.size())
529 button->setCurrentIndex(action_pos[actions_map[i]]);
534 void KdenliveSettingsDialog::updateSettings()
536 // Save changes to settings (for example when user pressed "Apply" or "Ok")
537 // kDebug() << "// // // KCONFIG UPDATE called";
538 m_defaultProfile = m_configProject.kcfg_profiles_list->currentText();
539 KdenliveSettings::setDefault_profile(m_defaultPath);
541 bool resetProfile = false;
542 bool updateCapturePath = false;
544 /*if (m_configShuttle.shuttledevicelist->count() > 0) {
545 QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
546 if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
549 if (m_configEnv.kcfg_capturetoprojectfolder->isChecked() != KdenliveSettings::capturetoprojectfolder()) {
550 KdenliveSettings::setCapturetoprojectfolder(m_configEnv.kcfg_capturetoprojectfolder->isChecked());
551 updateCapturePath = true;
554 if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
555 KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
556 updateCapturePath = true;
559 if (m_configCapture.kcfg_dvgrabfilename->text() != KdenliveSettings::dvgrabfilename()) {
560 KdenliveSettings::setDvgrabfilename(m_configCapture.kcfg_dvgrabfilename->text());
561 updateCapturePath = true;
564 if ((uint) m_configCapture.kcfg_firewireformat->currentIndex() != KdenliveSettings::firewireformat()) {
565 KdenliveSettings::setFirewireformat(m_configCapture.kcfg_firewireformat->currentIndex());
566 updateCapturePath = true;
569 if (updateCapturePath) emit updateCaptureFolder();
571 QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
572 if (value != KdenliveSettings::rmd_alsadevicename()) {
573 KdenliveSettings::setRmd_alsadevicename(value);
576 value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
577 kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
578 if (value != KdenliveSettings::rmd_freq()) {
579 kDebug() << "// SETTING AUDIO FREQ TO: " << value;
580 KdenliveSettings::setRmd_freq(value);
583 if (m_configSdl.kcfg_external_display->isChecked() != KdenliveSettings::external_display()) {
584 KdenliveSettings::setExternal_display(m_configSdl.kcfg_external_display->isChecked());
588 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
589 if (value != KdenliveSettings::audiodrivername()) {
590 KdenliveSettings::setAudiodrivername(value);
594 if (value == "alsa") {
595 // Audio device setting is only valid for alsa driver
596 value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
597 if (value != KdenliveSettings::audiodevicename()) {
598 KdenliveSettings::setAudiodevicename(value);
601 } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
602 KdenliveSettings::setAudiodevicename(QString::null);
606 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
607 if (value != KdenliveSettings::videodrivername()) {
608 KdenliveSettings::setVideodrivername(value);
612 if (m_configSdl.kcfg_window_background->color() != KdenliveSettings::window_background()) {
613 KdenliveSettings::setWindow_background(m_configSdl.kcfg_window_background->color());
617 if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
618 KdenliveSettings::setVolume(m_configSdl.kcfg_volume->value());
622 if (m_configProject.kcfg_enableproxy->isChecked() != KdenliveSettings::enableproxy()) {
623 KdenliveSettings::setEnableproxy(m_configProject.kcfg_enableproxy->isChecked());
626 if (m_configProject.kcfg_generateproxy->isChecked() != KdenliveSettings::generateproxy()) {
627 KdenliveSettings::setGenerateproxy(m_configProject.kcfg_generateproxy->isChecked());
630 if (m_configProject.kcfg_proxyminsize->value() != KdenliveSettings::proxyminsize()) {
631 KdenliveSettings::setProxyminsize(m_configProject.kcfg_proxyminsize->value());
635 // The transcoding profiles were modified, save.
637 saveTranscodeProfiles();
640 #ifndef NO_JOGSHUTTLE
641 m_shuttleModified = false;
644 actions << "monitor_pause"; // the Job rest position action.
645 foreach (KComboBox* button, m_shuttle_buttons) {
646 actions << m_mappable_actions[button->currentText()];
648 QString maps = JogShuttleConfig::actionMap(actions);
649 //fprintf(stderr, "Shuttle config: %s\n", JogShuttleConfig::actionMap(actions).toAscii().constData());
650 if (KdenliveSettings::shuttlebuttons() != maps)
651 KdenliveSettings::setShuttlebuttons(maps);
654 #if KDE_IS_VERSION(4,3,0)
655 KConfigDialog::settingsChangedSlot();
658 //KConfigDialog::updateSettings();
659 if (resetProfile) emit doResetProfile();
662 void KdenliveSettingsDialog::slotUpdateDisplay()
664 QString currentProfile = m_configProject.kcfg_profiles_list->itemData(m_configProject.kcfg_profiles_list->currentIndex()).toString();
665 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
666 m_configProject.p_size->setText(values.value("width") + 'x' + values.value("height"));
667 m_configProject.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
668 m_configProject.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
669 m_configProject.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
670 if (values.value("progressive").toInt() == 0)
671 m_configProject.p_progressive->setText(i18n("Interlaced"));
673 m_configProject.p_progressive->setText(i18n("Progressive"));
674 m_defaultProfile = m_configProject.kcfg_profiles_list->itemText(m_configProject.kcfg_profiles_list->currentIndex());
675 m_defaultPath = currentProfile;
678 void KdenliveSettingsDialog::slotCheckAlsaDriver()
680 QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
681 m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
684 void KdenliveSettingsDialog::loadTranscodeProfiles()
686 KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
687 KConfigGroup transConfig(config, "Transcoding");
689 m_configTranscode.profiles_list->blockSignals(true);
690 QMap< QString, QString > profiles = transConfig.entryMap();
691 QMapIterator<QString, QString> i(profiles);
692 while (i.hasNext()) {
694 QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i.key() << i.value());
695 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
697 m_configTranscode.profiles_list->blockSignals(false);
700 void KdenliveSettingsDialog::saveTranscodeProfiles()
702 KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
703 //KSharedConfigPtr config = KGlobal::config();
704 KConfigGroup transConfig(config, "Transcoding");
706 transConfig.deleteGroup();
707 int max = m_configTranscode.profiles_list->topLevelItemCount();
708 for (int i = 0; i < max; i++) {
709 QTreeWidgetItem *item = m_configTranscode.profiles_list->topLevelItem(i);
710 transConfig.writeEntry(item->text(0), item->text(1));
715 void KdenliveSettingsDialog::slotAddTranscode()
717 QTreeWidgetItem *item = new QTreeWidgetItem(m_configTranscode.profiles_list, QStringList() << i18n("Name") << i18n("Parameters"));
718 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
719 m_configTranscode.profiles_list->setCurrentItem(item);
720 m_configTranscode.profiles_list->editItem(item);
721 slotDialogModified();
724 void KdenliveSettingsDialog::slotDeleteTranscode()
726 QTreeWidgetItem *item = m_configTranscode.profiles_list->currentItem();
727 if (item == NULL) return;
729 slotDialogModified();
732 void KdenliveSettingsDialog::slotShuttleModified()
734 #ifndef NO_JOGSHUTTLE
736 actions << "monitor_pause"; // the Job rest position action.
737 foreach (KComboBox* button, m_shuttle_buttons) {
738 actions << m_mappable_actions[button->currentText()];
740 QString maps = JogShuttleConfig::actionMap(actions);
741 m_shuttleModified = KdenliveSettings::shuttlebuttons() != maps;
743 #if KDE_IS_VERSION(4,3,0)
744 KConfigDialog::updateButtons();
748 void KdenliveSettingsDialog::slotDialogModified()
751 #if KDE_IS_VERSION(4,3,0)
752 KConfigDialog::updateButtons();
757 bool KdenliveSettingsDialog::hasChanged()
759 if (m_modified || m_shuttleModified) return true;
760 return KConfigDialog::hasChanged();
763 void KdenliveSettingsDialog::slotUpdatev4lDevice()
765 QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
766 if (!device.isEmpty()) m_configCapture.kcfg_video4vdevice->setText(device);
767 QString size = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
768 if (!size.isEmpty()) m_configCapture.kcfg_video4size->setText(size);
769 rebuildVideo4Commands();
773 #include "kdenlivesettingsdialog.moc"