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 "kdenlivesettings.h"
24 #include <KStandardDirs>
26 #include <kopenwithdialog.h>
27 #include <KConfigDialogManager>
29 #include <KIO/NetAccess>
39 #include <linux/input.h>
40 #endif /* NO_JOGSHUTTLE */
43 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent) :
44 KConfigDialog(parent, "settings", KdenliveSettings::self())
47 QWidget *p1 = new QWidget;
48 m_configMisc.setupUi(p1);
49 page1 = addPage(p1, i18n("Misc"), "configure");
51 // Hide multi tab option until Kdenlive really supports it
52 m_configMisc.kcfg_activatetabs->setVisible(false);
54 QWidget *p3 = new QWidget;
55 m_configDisplay.setupUi(p3);
56 page3 = addPage(p3, i18n("Display"), "video-display");
58 QWidget *p2 = new QWidget;
59 m_configEnv.setupUi(p2);
60 m_configEnv.mltpathurl->setMode(KFile::Directory);
61 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
62 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
63 m_configEnv.tmppathurl->setMode(KFile::Directory);
64 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
65 m_configEnv.projecturl->setMode(KFile::Directory);
66 m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
67 m_configEnv.capturefolderurl->setMode(KFile::Directory);
68 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
69 page2 = addPage(p2, i18n("Environment"), "terminal");
71 m_captureFolder = KdenliveSettings::capturefolder();
72 QWidget *p4 = new QWidget;
73 m_configCapture.setupUi(p4);
74 page4 = addPage(p4, i18n("Capture"), "audio-card");
75 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
77 QWidget *p5 = new QWidget;
78 m_configShuttle.setupUi(p5);
80 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
81 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
82 slotCheckShuttle(KdenliveSettings::enableshuttle());
83 m_configShuttle.shuttledisabled->hide();
85 m_configShuttle.kcfg_enableshuttle->hide();
86 m_configShuttle.kcfg_enableshuttle->setDisabled(true);
87 #endif /* NO_JOGSHUTTLE */
88 page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
90 QWidget *p6 = new QWidget;
91 m_configSdl.setupUi(p6);
92 page6 = addPage(p6, i18n("Playback"), "audio-card");
95 actions << i18n("Do nothing");
96 actions << i18n("Play / Pause");
97 actions << i18n("Cut");
98 m_configShuttle.kcfg_shuttle1->addItems(actions);
99 m_configShuttle.kcfg_shuttle2->addItems(actions);
100 m_configShuttle.kcfg_shuttle3->addItems(actions);
101 m_configShuttle.kcfg_shuttle4->addItems(actions);
102 m_configShuttle.kcfg_shuttle5->addItems(actions);
104 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
105 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
106 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
107 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
108 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
109 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
111 connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
113 m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
115 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
116 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
117 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
123 connect(m_configSdl.kcfg_audio_driver, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckAlsaDriver()));
125 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
126 connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
128 slotUpdateRmdRegionStatus();
131 //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
132 // --timestamp option without bug
134 if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
135 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
136 KdenliveSettings::setDvgrab_path(dvgrabpath);
140 double dvgrabVersion = 0;
141 if (!KdenliveSettings::dvgrab_path().isEmpty()) {
142 QProcess *versionCheck = new QProcess;
143 versionCheck->setProcessChannelMode(QProcess::MergedChannels);
144 versionCheck->start("dvgrab", QStringList() << "--version");
145 if (versionCheck->waitForFinished()) {
146 QString version = QString(versionCheck->readAll()).simplified();
147 if (version.contains(' ')) version = version.section(' ', -1);
148 dvgrabVersion = version.toDouble();
150 kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
152 if (versionCheck) delete versionCheck;
153 if (dvgrabVersion < 3.3) {
154 KdenliveSettings::setFirewiretimestamp(false);
155 m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
157 m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
158 } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
160 if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
161 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
162 KdenliveSettings::setRmd_path(rmdpath);
164 if (KdenliveSettings::rmd_path().isEmpty()) m_configCapture.rmd_info->setText(i18n("<strong><em>Recordmydesktop</em> utility not found, please install it for screen grabs</strong>"));
165 else m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
168 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
170 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus()
172 m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
175 void KdenliveSettingsDialog::checkProfile()
177 m_configMisc.kcfg_profiles_list->clear();
178 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
179 QMapIterator<QString, QString> i(profilesInfo);
180 while (i.hasNext()) {
182 m_configMisc.kcfg_profiles_list->addItem(i.key(), i.value());
185 if (!KdenliveSettings::default_profile().isEmpty()) {
186 for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
187 if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
188 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
189 KdenliveSettings::setProfiles_list(i);
196 void KdenliveSettingsDialog::initDevices()
198 // Fill audio drivers
199 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
200 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
201 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
202 m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
203 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
204 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
205 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
207 if (!KdenliveSettings::audiodrivername().isEmpty())
208 for (int i = 1;i < m_configSdl.kcfg_audio_driver->count(); i++) {
209 if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
210 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
211 KdenliveSettings::setAudio_driver((uint) i);
215 // Fill video drivers
216 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
217 m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
218 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
219 m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
220 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
221 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
222 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
223 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
224 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
225 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
227 // Fill the list of audio playback devices
228 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
229 m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
230 if (!KStandardDirs::findExe("aplay").isEmpty()) {
231 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
232 m_readProcess.setProgram("aplay", QStringList() << "-l");
233 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
234 m_readProcess.execute(5000);
236 // If aplay is not installed on the system, parse the /proc/asound/pcm file
237 QFile file("/proc/asound/pcm");
238 if (file.open(QIODevice::ReadOnly)) {
239 QTextStream stream(&file);
242 while (!stream.atEnd()) {
243 line = stream.readLine();
244 if (line.contains("playback")) {
245 deviceId = line.section(':', 0, 0);
246 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()));
248 if (line.contains("capture")) {
249 deviceId = line.section(':', 0, 0);
250 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()));
256 if (!KdenliveSettings::audiodevicename().isEmpty()) {
257 // Select correct alsa device
258 int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
259 m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
260 KdenliveSettings::setAudio_device(ix);
262 if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
263 // Select correct alsa device
264 int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
265 m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
266 KdenliveSettings::setRmd_alsa_device(ix);
271 void KdenliveSettingsDialog::slotReadAudioDevices()
273 QString result = QString(m_readProcess.readAllStandardOutput());
274 kDebug() << "// / / / / / READING APLAY: ";
276 QStringList lines = result.split('\n');
277 foreach(const QString &data, lines) {
278 kDebug() << "// READING LINE: " << data;
279 if (data.simplified().startsWith("card")) {
280 QString card = data.section(':', 0, 0).section(' ', -1);
281 QString device = data.section(':', 1, 1).section(' ', -1);
282 m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
283 m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
288 void KdenliveSettingsDialog::showPage(int page, int option)
292 setCurrentPage(page1);
295 setCurrentPage(page2);
298 setCurrentPage(page3);
301 setCurrentPage(page4);
302 m_configCapture.tabWidget->setCurrentIndex(option);
305 setCurrentPage(page5);
311 void KdenliveSettingsDialog::slotEditVideoApplication()
313 KService::Ptr service;
314 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
315 if (dlg.exec() != QDialog::Accepted)
318 service = dlg.service();
319 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
322 void KdenliveSettingsDialog::slotEditAudioApplication()
324 KService::Ptr service;
325 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
326 if (dlg.exec() != QDialog::Accepted)
329 service = dlg.service();
330 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
333 void KdenliveSettingsDialog::slotEditImageApplication()
335 KService::Ptr service;
336 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
337 if (dlg.exec() != QDialog::Accepted)
340 service = dlg.service();
341 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
344 #ifndef NO_JOGSHUTTLE
345 void KdenliveSettingsDialog::slotCheckShuttle(int state)
347 m_configShuttle.config_group->setEnabled(state);
348 if (m_configShuttle.shuttledevicelist->count() == 0) {
350 QString baseName = "/dev/input/event";
352 for (int i = 0; i < 30; i++) {
353 QString filename = baseName + QString::number(i);
354 kDebug() << "/// CHECKING OFR: " << filename;
356 char name[256] = "unknown";
357 fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
358 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
359 m_configShuttle.shuttledevicelist->addItem(name, filename);
363 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
367 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
369 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
370 //KdenliveSettings::setShuttledevice(device);
371 m_configShuttle.kcfg_shuttledevice->setText(device);
373 #endif /* NO_JOGSHUTTLE */
375 void KdenliveSettingsDialog::rebuildVideo4Commands()
377 QString captureCommand;
378 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
380 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();
381 m_configCapture.kcfg_video4capture->setText(captureCommand);
385 void KdenliveSettingsDialog::updateSettings()
387 kDebug() << "// // // KCONFIG UPDATE called";
388 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
389 KdenliveSettings::setDefault_profile(m_defaultPath);
391 bool resetProfile = false;
393 if (m_configEnv.capturefolderurl->url().path() != KdenliveSettings::capturefolder()) {
394 kDebug() << "/// CAPT FOLDER UPDATED";
395 KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().path());
396 emit updateCaptureFolder();
399 QString value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
400 if (value != KdenliveSettings::rmd_alsadevicename()) {
401 KdenliveSettings::setRmd_alsadevicename(value);
404 value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
405 kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
406 if (value != KdenliveSettings::rmd_freq()) {
407 kDebug() << "// SETTING AUDIO FREQ TO: " << value;
408 KdenliveSettings::setRmd_freq(value);
411 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
412 if (value != KdenliveSettings::audiodrivername()) {
413 KdenliveSettings::setAudiodrivername(value);
417 if (value == "alsa") {
418 // Audio device setting is only valid for alsa driver
419 value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
420 if (value != KdenliveSettings::audiodevicename()) {
421 KdenliveSettings::setAudiodevicename(value);
424 } else if (KdenliveSettings::audiodevicename().isEmpty() == false) {
425 KdenliveSettings::setAudiodevicename(QString::null);
429 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
430 if (value != KdenliveSettings::videodrivername()) {
431 KdenliveSettings::setVideodrivername(value);
435 bool updatePreview = false;
436 if (m_configSdl.kcfg_dropbframes->isChecked() != KdenliveSettings::dropbframes()) {
437 KdenliveSettings::setDropbframes(m_configSdl.kcfg_dropbframes->isChecked());
438 updatePreview = true;
441 KConfigDialog::updateSettings();
442 if (resetProfile) emit doResetProfile();
443 if (updatePreview) emit updatePreviewSettings();
446 void KdenliveSettingsDialog::slotUpdateDisplay()
448 QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
449 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
450 m_configMisc.p_size->setText(values.value("width") + 'x' + values.value("height"));
451 m_configMisc.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
452 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
453 m_configMisc.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
454 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
455 else m_configMisc.p_progressive->setText(i18n("Progressive"));
456 m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
457 m_defaultPath = currentProfile;
460 void KdenliveSettingsDialog::slotCheckAlsaDriver()
462 QString value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
463 m_configSdl.kcfg_audio_device->setEnabled(value == "alsa");
466 #include "kdenlivesettingsdialog.moc"