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 ***************************************************************************/
23 #include <KStandardDirs>
25 #include <kopenwithdialog.h>
32 #include <linux/input.h>
33 #endif /* NO_JOGSHUTTLE */
35 #include "profilesdialog.h"
36 #include "kdenlivesettings.h"
37 #include "kdenlivesettingsdialog.h"
39 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
41 QWidget *p1 = new QWidget;
42 m_configMisc.setupUi(p1);
43 page1 = addPage(p1, i18n("Misc"), "configure");
45 QWidget *p3 = new QWidget;
46 m_configDisplay.setupUi(p3);
47 page3 = addPage(p3, i18n("Display"), "display");
49 QWidget *p2 = new QWidget;
50 m_configEnv.setupUi(p2);
51 m_configEnv.mltpathurl->setMode(KFile::Directory);
52 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
53 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
54 m_configEnv.tmppathurl->setMode(KFile::Directory);
55 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
56 m_configEnv.capturefolderurl->setMode(KFile::Directory);
57 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
58 page2 = addPage(p2, i18n("Environment"), "terminal");
60 QWidget *p4 = new QWidget;
61 m_configCapture.setupUi(p4);
62 page4 = addPage(p4, i18n("Capture"), "audio-card");
63 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
65 QWidget *p5 = new QWidget;
66 m_configShuttle.setupUi(p5);
68 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
69 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
70 slotCheckShuttle(KdenliveSettings::enableshuttle());
71 m_configShuttle.shuttledisabled->hide();
73 m_configShuttle.kcfg_enableshuttle->hide();
74 m_configShuttle.kcfg_enableshuttle->setDisabled(true);
75 #endif /* NO_JOGSHUTTLE */
76 page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
78 QWidget *p6 = new QWidget;
79 m_configSdl.setupUi(p6);
80 page6 = addPage(p6, i18n("Playback"), "audio-card");
83 actions << i18n("Do nothing");
84 actions << i18n("Play / Pause");
85 actions << i18n("Cut");
86 m_configShuttle.kcfg_shuttle1->addItems(actions);
87 m_configShuttle.kcfg_shuttle2->addItems(actions);
88 m_configShuttle.kcfg_shuttle3->addItems(actions);
89 m_configShuttle.kcfg_shuttle4->addItems(actions);
90 m_configShuttle.kcfg_shuttle5->addItems(actions);
92 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
93 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
94 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
95 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
96 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
97 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
99 connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
101 m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
103 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
104 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
105 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
109 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
110 QMapIterator<QString, QString> i(profilesInfo);
111 while (i.hasNext()) {
113 m_configMisc.kcfg_profiles_list->addItem(i.key(), i.value());
120 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
122 connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
124 slotUpdateRmdRegionStatus();
127 //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
128 // --timestamp option without bug
130 if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
131 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
132 KdenliveSettings::setDvgrab_path(dvgrabpath);
136 double dvgrabVersion = 0;
137 if (!KdenliveSettings::dvgrab_path().isEmpty()) {
138 QProcess *versionCheck = new QProcess;
139 versionCheck->setProcessChannelMode(QProcess::MergedChannels);
140 versionCheck->start("dvgrab", QStringList() << "--version");
141 if (versionCheck->waitForFinished()) {
142 QString version = QString(versionCheck->readAll()).simplified();
143 if (version.contains(' ')) version = version.section(' ', -1);
144 dvgrabVersion = version.toDouble();
146 kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
148 if (versionCheck) delete versionCheck;
149 if (dvgrabVersion < 3.3) {
150 KdenliveSettings::setFirewiretimestamp(false);
151 m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
153 m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
154 } else m_configCapture.dvgrab_info->setText(i18n("<b>dvgrab utility not found, please install it for firewire capture</b>"));
156 if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
157 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
158 KdenliveSettings::setRmd_path(rmdpath);
160 if (KdenliveSettings::rmd_path().isEmpty()) m_configCapture.rmd_info->setText(i18n("<b>Recordmydesktop utility not found, please install it for screen grabs</b>"));
161 else m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
164 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
166 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus() {
167 m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
170 void KdenliveSettingsDialog::checkProfile() {
171 if (!KdenliveSettings::default_profile().isEmpty()) {
172 for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
173 if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
174 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
175 KdenliveSettings::setProfiles_list(i);
182 void KdenliveSettingsDialog::initDevices() {
183 // Fill audio drivers
184 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
185 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
186 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
187 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
188 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
189 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
191 /*if (!KdenliveSettings::audiodriver().isEmpty())
192 for (uint i = 1;i < m_configDisplay.kcfg_audio_driver->count(); i++) {
193 if (m_configDisplay.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodriver())
194 m_configDisplay.kcfg_audio_driver->setCurrentIndex(i);
197 // Fill video drivers
198 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
199 m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
200 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
201 m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga");
202 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
203 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
204 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
205 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
206 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
207 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
209 // Fill the list of audio playback devices
210 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
211 m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
212 if (KStandardDirs::findExe("aplay") != QString::null) {
213 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
214 m_readProcess.setProgram("aplay", QStringList() << "-l");
215 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
216 m_readProcess.execute(5000);
218 // If aplay is not installed on the system, parse the /proc/asound/pcm file
219 QFile file("/proc/asound/pcm");
220 if (file.open(QIODevice::ReadOnly)) {
221 QTextStream stream(&file);
224 while (!stream.atEnd()) {
225 line = stream.readLine();
226 if (line.contains("playback")) {
227 deviceId = line.section(":", 0, 0);
228 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()));
230 if (line.contains("capture")) {
231 deviceId = line.section(":", 0, 0);
232 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()));
241 void KdenliveSettingsDialog::slotReadAudioDevices() {
242 QString result = QString(m_readProcess.readAllStandardOutput());
243 kDebug() << "// / / / / / READING APLAY: ";
245 QStringList lines = result.split('\n');
246 foreach(QString data, lines) {
247 kDebug() << "// READING LINE: " << data;
248 if (data.simplified().startsWith("card")) {
249 QString card = data.section(":", 0, 0).section(" ", -1);
250 QString device = data.section(":", 1, 1).section(" ", -1);
251 m_configSdl.kcfg_audio_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
252 m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
257 void KdenliveSettingsDialog::showPage(int page, int option) {
260 setCurrentPage(page1);
263 setCurrentPage(page2);
266 setCurrentPage(page3);
269 setCurrentPage(page4);
270 m_configCapture.tabWidget->setCurrentIndex(option);
273 setCurrentPage(page5);
279 void KdenliveSettingsDialog::slotEditVideoApplication() {
280 KService::Ptr service;
281 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
282 if (dlg.exec() != QDialog::Accepted)
285 service = dlg.service();
286 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
289 void KdenliveSettingsDialog::slotEditAudioApplication() {
290 KService::Ptr service;
291 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
292 if (dlg.exec() != QDialog::Accepted)
295 service = dlg.service();
296 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
299 void KdenliveSettingsDialog::slotEditImageApplication() {
300 KService::Ptr service;
301 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
302 if (dlg.exec() != QDialog::Accepted)
305 service = dlg.service();
306 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
309 #ifndef NO_JOGSHUTTLE
310 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
311 m_configShuttle.config_group->setEnabled(state);
312 if (m_configShuttle.shuttledevicelist->count() == 0) {
314 QString baseName = "/dev/input/event";
316 for (int i = 0; i < 30; i++) {
317 QString filename = baseName + QString::number(i);
318 kDebug() << "/// CHECKING OFR: " << filename;
320 char name[256] = "unknown";
321 fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
322 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
323 m_configShuttle.shuttledevicelist->addItem(name, filename);
327 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
331 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
332 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
333 //KdenliveSettings::setShuttledevice(device);
334 m_configShuttle.kcfg_shuttledevice->setText(device);
336 #endif /* NO_JOGSHUTTLE */
338 void KdenliveSettingsDialog::rebuildVideo4Commands() {
339 QString captureCommand;
340 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
342 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();
343 m_configCapture.kcfg_video4capture->setText(captureCommand);
348 bool KdenliveSettingsDialog::isDefault() {
349 return KConfigDialog::isDefault();
353 bool KdenliveSettingsDialog::hasChanged() {
354 kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
356 if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
357 return KConfigDialog::hasChanged();
360 void KdenliveSettingsDialog::updateSettings() {
361 kDebug() << "// // // KCONFIG UPDATE called";
362 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
363 KdenliveSettings::setDefault_profile(m_defaultPath);
365 bool resetProfile = false;
366 QString value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
367 if (value != KdenliveSettings::audiodevicename()) {
368 KdenliveSettings::setAudiodevicename(value);
372 value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
373 if (value != KdenliveSettings::rmd_alsadevicename()) {
374 KdenliveSettings::setRmd_alsadevicename(value);
377 value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
378 kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
379 if (value != KdenliveSettings::rmd_freq()) {
380 kDebug() << "// SETTING AUDIO FREQ TO: " << value;
381 KdenliveSettings::setRmd_freq(value);
384 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
385 if (value != KdenliveSettings::audiodrivername()) {
386 KdenliveSettings::setAudiodrivername(value);
390 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
391 if (value != KdenliveSettings::videodrivername()) {
392 KdenliveSettings::setVideodrivername(value);
396 KConfigDialog::updateSettings();
397 if (resetProfile) emit doResetProfile();
400 void KdenliveSettingsDialog::slotUpdateDisplay() {
401 QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
402 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
403 m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
404 m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
405 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
406 m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
407 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
408 else m_configMisc.p_progressive->setText(i18n("Progressive"));
409 m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
410 m_defaultPath = currentProfile;
414 #include "kdenlivesettingsdialog.moc"