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): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
45 QWidget *p1 = new QWidget;
46 m_configMisc.setupUi(p1);
47 page1 = addPage(p1, i18n("Misc"), "configure");
49 // Hide multi tab option until Kdenlive really supports it
50 m_configMisc.kcfg_activatetabs->setVisible(false);
52 QWidget *p3 = new QWidget;
53 m_configDisplay.setupUi(p3);
54 page3 = addPage(p3, i18n("Display"), "display");
56 QWidget *p2 = new QWidget;
57 m_configEnv.setupUi(p2);
58 m_configEnv.mltpathurl->setMode(KFile::Directory);
59 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
60 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
61 m_configEnv.tmppathurl->setMode(KFile::Directory);
62 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
63 m_configEnv.projecturl->setMode(KFile::Directory);
64 m_configEnv.projecturl->lineEdit()->setObjectName("kcfg_defaultprojectfolder");
65 m_configEnv.capturefolderurl->setMode(KFile::Directory);
66 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
67 page2 = addPage(p2, i18n("Environment"), "terminal");
69 m_captureFolder = KdenliveSettings::capturefolder();
70 QWidget *p4 = new QWidget;
71 m_configCapture.setupUi(p4);
72 page4 = addPage(p4, i18n("Capture"), "audio-card");
73 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
75 QWidget *p5 = new QWidget;
76 m_configShuttle.setupUi(p5);
78 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
79 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
80 slotCheckShuttle(KdenliveSettings::enableshuttle());
81 m_configShuttle.shuttledisabled->hide();
83 m_configShuttle.kcfg_enableshuttle->hide();
84 m_configShuttle.kcfg_enableshuttle->setDisabled(true);
85 #endif /* NO_JOGSHUTTLE */
86 page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
88 QWidget *p6 = new QWidget;
89 m_configSdl.setupUi(p6);
90 page6 = addPage(p6, i18n("Playback"), "audio-card");
93 actions << i18n("Do nothing");
94 actions << i18n("Play / Pause");
95 actions << i18n("Cut");
96 m_configShuttle.kcfg_shuttle1->addItems(actions);
97 m_configShuttle.kcfg_shuttle2->addItems(actions);
98 m_configShuttle.kcfg_shuttle3->addItems(actions);
99 m_configShuttle.kcfg_shuttle4->addItems(actions);
100 m_configShuttle.kcfg_shuttle5->addItems(actions);
102 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
103 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
104 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
105 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
106 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
107 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
109 connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
111 m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
113 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
114 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
115 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
122 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
123 connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
125 slotUpdateRmdRegionStatus();
128 //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
129 // --timestamp option without bug
131 if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
132 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
133 KdenliveSettings::setDvgrab_path(dvgrabpath);
137 double dvgrabVersion = 0;
138 if (!KdenliveSettings::dvgrab_path().isEmpty()) {
139 QProcess *versionCheck = new QProcess;
140 versionCheck->setProcessChannelMode(QProcess::MergedChannels);
141 versionCheck->start("dvgrab", QStringList() << "--version");
142 if (versionCheck->waitForFinished()) {
143 QString version = QString(versionCheck->readAll()).simplified();
144 if (version.contains(' ')) version = version.section(' ', -1);
145 dvgrabVersion = version.toDouble();
147 kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
149 if (versionCheck) delete versionCheck;
150 if (dvgrabVersion < 3.3) {
151 KdenliveSettings::setFirewiretimestamp(false);
152 m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
154 m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
155 } else m_configCapture.dvgrab_info->setText(i18n("<strong><em>dvgrab</em> utility not found, please install it for firewire capture</strong>"));
157 if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
158 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
159 KdenliveSettings::setRmd_path(rmdpath);
161 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>"));
162 else m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
165 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
167 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus() {
168 m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
171 void KdenliveSettingsDialog::checkProfile() {
172 m_configMisc.kcfg_profiles_list->clear();
173 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
174 QMapIterator<QString, QString> i(profilesInfo);
175 while (i.hasNext()) {
177 m_configMisc.kcfg_profiles_list->addItem(i.key(), i.value());
180 if (!KdenliveSettings::default_profile().isEmpty()) {
181 for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
182 if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
183 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
184 KdenliveSettings::setProfiles_list(i);
191 void KdenliveSettingsDialog::initDevices() {
192 // Fill audio drivers
193 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
194 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
195 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
196 m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulse");
197 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
198 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
199 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
201 if (!KdenliveSettings::audiodrivername().isEmpty())
202 for (int i = 1;i < m_configSdl.kcfg_audio_driver->count(); i++) {
203 if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
204 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
205 KdenliveSettings::setAudio_driver((uint) i);
209 // Fill video drivers
210 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
211 m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
212 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
213 m_configSdl.kcfg_video_driver->addItem(i18n("XFree86 DGA 2.0"), "dga");
214 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
215 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
216 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
217 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
218 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
219 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
221 // Fill the list of audio playback devices
222 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
223 m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
224 if (!KStandardDirs::findExe("aplay").isEmpty()) {
225 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
226 m_readProcess.setProgram("aplay", QStringList() << "-l");
227 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
228 m_readProcess.execute(5000);
230 // If aplay is not installed on the system, parse the /proc/asound/pcm file
231 QFile file("/proc/asound/pcm");
232 if (file.open(QIODevice::ReadOnly)) {
233 QTextStream stream(&file);
236 while (!stream.atEnd()) {
237 line = stream.readLine();
238 if (line.contains("playback")) {
239 deviceId = line.section(':', 0, 0);
240 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()));
242 if (line.contains("capture")) {
243 deviceId = line.section(':', 0, 0);
244 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()));
250 if (!KdenliveSettings::audiodevicename().isEmpty()) {
251 // Select correct alsa device
252 int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
253 m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
254 KdenliveSettings::setAudio_device(ix);
256 if (!KdenliveSettings::rmd_alsadevicename().isEmpty()) {
257 // Select correct alsa device
258 int ix = m_configCapture.kcfg_rmd_alsa_device->findData(KdenliveSettings::rmd_alsadevicename());
259 m_configCapture.kcfg_rmd_alsa_device->setCurrentIndex(ix);
260 KdenliveSettings::setRmd_alsa_device(ix);
265 void KdenliveSettingsDialog::slotReadAudioDevices() {
266 QString result = QString(m_readProcess.readAllStandardOutput());
267 kDebug() << "// / / / / / READING APLAY: ";
269 QStringList lines = result.split('\n');
270 foreach(const QString &data, lines) {
271 kDebug() << "// READING LINE: " << data;
272 if (data.simplified().startsWith("card")) {
273 QString card = data.section(':', 0, 0).section(' ', -1);
274 QString device = data.section(':', 1, 1).section(' ', -1);
275 m_configSdl.kcfg_audio_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
276 m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(':', -1), "plughw:" + card + ',' + device);
281 void KdenliveSettingsDialog::showPage(int page, int option) {
284 setCurrentPage(page1);
287 setCurrentPage(page2);
290 setCurrentPage(page3);
293 setCurrentPage(page4);
294 m_configCapture.tabWidget->setCurrentIndex(option);
297 setCurrentPage(page5);
303 void KdenliveSettingsDialog::slotEditVideoApplication() {
304 KService::Ptr service;
305 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
306 if (dlg.exec() != QDialog::Accepted)
309 service = dlg.service();
310 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
313 void KdenliveSettingsDialog::slotEditAudioApplication() {
314 KService::Ptr service;
315 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
316 if (dlg.exec() != QDialog::Accepted)
319 service = dlg.service();
320 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
323 void KdenliveSettingsDialog::slotEditImageApplication() {
324 KService::Ptr service;
325 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
326 if (dlg.exec() != QDialog::Accepted)
329 service = dlg.service();
330 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
333 #ifndef NO_JOGSHUTTLE
334 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
335 m_configShuttle.config_group->setEnabled(state);
336 if (m_configShuttle.shuttledevicelist->count() == 0) {
338 QString baseName = "/dev/input/event";
340 for (int i = 0; i < 30; i++) {
341 QString filename = baseName + QString::number(i);
342 kDebug() << "/// CHECKING OFR: " << filename;
344 char name[256] = "unknown";
345 fd = KDE_open((char *) filename.toUtf8().data(), O_RDONLY);
346 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
347 m_configShuttle.shuttledevicelist->addItem(name, filename);
351 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
355 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
356 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
357 //KdenliveSettings::setShuttledevice(device);
358 m_configShuttle.kcfg_shuttledevice->setText(device);
360 #endif /* NO_JOGSHUTTLE */
362 void KdenliveSettingsDialog::rebuildVideo4Commands() {
363 QString captureCommand;
364 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
366 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();
367 m_configCapture.kcfg_video4capture->setText(captureCommand);
371 void KdenliveSettingsDialog::updateSettings() {
372 kDebug() << "// // // KCONFIG UPDATE called";
373 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
374 KdenliveSettings::setDefault_profile(m_defaultPath);
376 bool resetProfile = false;
377 QString value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
378 if (value != KdenliveSettings::audiodevicename()) {
379 KdenliveSettings::setAudiodevicename(value);
383 if (m_configEnv.capturefolderurl->text() != KdenliveSettings::capturefolder()) {
384 kDebug() << "/// CAPT FOLDER UPDATED";
385 KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->text());
386 emit updateCaptureFolder();
389 value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
390 if (value != KdenliveSettings::rmd_alsadevicename()) {
391 KdenliveSettings::setRmd_alsadevicename(value);
394 value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
395 kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
396 if (value != KdenliveSettings::rmd_freq()) {
397 kDebug() << "// SETTING AUDIO FREQ TO: " << value;
398 KdenliveSettings::setRmd_freq(value);
401 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
402 if (value != KdenliveSettings::audiodrivername()) {
403 KdenliveSettings::setAudiodrivername(value);
407 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
408 if (value != KdenliveSettings::videodrivername()) {
409 KdenliveSettings::setVideodrivername(value);
413 bool updatePreview = false;
414 if (m_configSdl.kcfg_dropbframes->isChecked() != KdenliveSettings::dropbframes()) {
415 KdenliveSettings::setDropbframes(m_configSdl.kcfg_dropbframes->isChecked());
416 updatePreview = true;
419 KConfigDialog::updateSettings();
420 if (resetProfile) emit doResetProfile();
421 if (updatePreview) emit updatePreviewSettings();
424 void KdenliveSettingsDialog::slotUpdateDisplay() {
425 QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
426 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
427 m_configMisc.p_size->setText(values.value("width") + 'x' + values.value("height"));
428 m_configMisc.p_fps->setText(values.value("frame_rate_num") + '/' + values.value("frame_rate_den"));
429 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + '/' + values.value("sample_aspect_den"));
430 m_configMisc.p_display->setText(values.value("display_aspect_num") + '/' + values.value("display_aspect_den"));
431 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
432 else m_configMisc.p_progressive->setText(i18n("Progressive"));
433 m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
434 m_defaultPath = currentProfile;
439 #include "kdenlivesettingsdialog.moc"