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>
31 #include <linux/input.h>
33 #include "profilesdialog.h"
34 #include "kdenlivesettings.h"
35 #include "kdenlivesettingsdialog.h"
37 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
39 QWidget *p1 = new QWidget;
40 m_configMisc.setupUi(p1);
41 page1 = addPage(p1, i18n("Misc"), "configure");
43 QWidget *p3 = new QWidget;
44 m_configDisplay.setupUi(p3);
45 page3 = addPage(p3, i18n("Display"), "display");
47 QWidget *p2 = new QWidget;
48 m_configEnv.setupUi(p2);
49 m_configEnv.mltpathurl->setMode(KFile::Directory);
50 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
51 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
52 m_configEnv.tmppathurl->setMode(KFile::Directory);
53 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
54 m_configEnv.capturefolderurl->setMode(KFile::Directory);
55 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
56 page2 = addPage(p2, i18n("Environment"), "terminal");
58 QWidget *p4 = new QWidget;
59 m_configCapture.setupUi(p4);
60 page4 = addPage(p4, i18n("Capture"), "audio-card");
61 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
63 QWidget *p5 = new QWidget;
64 m_configShuttle.setupUi(p5);
65 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
66 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
67 slotCheckShuttle(KdenliveSettings::enableshuttle());
68 page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
70 QWidget *p6 = new QWidget;
71 m_configSdl.setupUi(p6);
72 page6 = addPage(p6, i18n("Playback"), "audio-card");
75 actions << i18n("Do nothing");
76 actions << i18n("Play / Pause");
77 actions << i18n("Cut");
78 m_configShuttle.kcfg_shuttle1->addItems(actions);
79 m_configShuttle.kcfg_shuttle2->addItems(actions);
80 m_configShuttle.kcfg_shuttle3->addItems(actions);
81 m_configShuttle.kcfg_shuttle4->addItems(actions);
82 m_configShuttle.kcfg_shuttle5->addItems(actions);
84 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
85 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
86 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
87 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
88 connect(m_configCapture.kcfg_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
89 connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
90 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
91 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
93 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
94 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
95 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
99 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
100 QMapIterator<QString, QString> i(profilesInfo);
101 while (i.hasNext()) {
103 m_configMisc.kcfg_profiles_list->addItem(i.key(), i.value());
106 if (!KdenliveSettings::default_profile().isEmpty()) {
107 for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
108 if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
109 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
110 KdenliveSettings::setProfiles_list(i);
117 m_audioDevice = KdenliveSettings::audio_device();
119 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
122 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
124 void KdenliveSettingsDialog::initDevices() {
125 // Fill audio drivers
126 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
127 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
128 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
129 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
130 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
131 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
133 /*if (!KdenliveSettings::audiodriver().isEmpty())
134 for (uint i = 1;i < m_configDisplay.kcfg_audio_driver->count(); i++) {
135 if (m_configDisplay.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodriver())
136 m_configDisplay.kcfg_audio_driver->setCurrentIndex(i);
139 // Fill video drivers
140 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
141 m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
142 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
143 m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga");
144 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
145 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
146 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
147 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
148 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
149 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
151 // Fill the list of audio playback devices
152 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
153 if (KStandardDirs::findExe("aplay") != QString::null) {
154 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
155 m_readProcess.setProgram("aplay", QStringList() << "-l");
156 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
157 m_readProcess.execute(5000);
159 // If aplay is not installed on the system, parse the /proc/asound/pcm file
160 QFile file("/proc/asound/pcm");
161 if (file.open(QIODevice::ReadOnly)) {
162 QTextStream stream(&file);
164 while (!stream.atEnd()) {
165 line = stream.readLine();
166 if (line.contains("playback")) {
167 QString deviceId = line.section(":", 0, 0);
168 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()));
177 void KdenliveSettingsDialog::slotReadAudioDevices() {
178 QString result = QString(m_readProcess.readAllStandardOutput());
179 kDebug() << "// / / / / / READING APLAY: ";
181 QStringList lines = result.split('\n');
182 foreach(QString data, lines) {
183 kDebug() << "// READING LINE: " << data;
184 if (data.simplified().startsWith("card")) {
185 QString card = data.section(":", 0, 0).section(" ", -1);
186 QString device = data.section(":", 1, 1).section(" ", -1);
187 m_configSdl.kcfg_audio_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
192 void KdenliveSettingsDialog::showPage(int page, int option) {
195 setCurrentPage(page1);
198 setCurrentPage(page2);
201 setCurrentPage(page3);
204 setCurrentPage(page4);
205 m_configCapture.tabWidget->setCurrentIndex(option);
208 setCurrentPage(page5);
214 void KdenliveSettingsDialog::slotEditVideoApplication() {
215 KService::Ptr service;
216 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
217 if (dlg.exec() != QDialog::Accepted)
220 service = dlg.service();
221 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
224 void KdenliveSettingsDialog::slotEditAudioApplication() {
225 KService::Ptr service;
226 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
227 if (dlg.exec() != QDialog::Accepted)
230 service = dlg.service();
231 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
234 void KdenliveSettingsDialog::slotEditImageApplication() {
235 KService::Ptr service;
236 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
237 if (dlg.exec() != QDialog::Accepted)
240 service = dlg.service();
241 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
244 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
245 m_configShuttle.config_group->setEnabled(state);
246 if (m_configShuttle.shuttledevicelist->count() == 0) {
248 QString baseName = "/dev/input/event";
250 for (int i = 0; i < 30; i++) {
251 QString filename = baseName + QString::number(i);
252 kDebug() << "/// CHECKING OFR: " << filename;
254 char name[256] = "unknown";
255 fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
256 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
257 m_configShuttle.shuttledevicelist->addItem(name, filename);
261 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
265 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
266 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
267 //KdenliveSettings::setShuttledevice(device);
268 m_configShuttle.kcfg_shuttledevice->setText(device);
271 void KdenliveSettingsDialog::rebuildVideo4Commands() {
272 QString captureCommand;
273 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
275 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() + " -f " + m_configCapture.kcfg_video4vencoding->text();
276 m_configCapture.kcfg_video4capture->setText(captureCommand);
278 QString playbackCommand;
279 playbackCommand = "-f " + m_configCapture.kcfg_video4vencoding->text();
280 m_configCapture.kcfg_video4playback->setText(playbackCommand);
285 bool KdenliveSettingsDialog::isDefault() {
286 return KConfigDialog::isDefault();
290 bool KdenliveSettingsDialog::hasChanged() {
291 kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
293 if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
294 return KConfigDialog::hasChanged();
297 void KdenliveSettingsDialog::updateSettings() {
298 kDebug() << "// // // KCONFIG UPDATE called";
299 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
300 KdenliveSettings::setDefault_profile(m_defaultPath);
302 bool resetProfile = false;
303 QString value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
304 if (value != KdenliveSettings::audiodevicename()) {
305 KdenliveSettings::setAudiodevicename(value);
309 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
310 if (value != KdenliveSettings::audiodrivername()) {
311 KdenliveSettings::setAudiodrivername(value);
315 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
316 if (value != KdenliveSettings::videodrivername()) {
317 KdenliveSettings::setVideodrivername(value);
321 KConfigDialog::updateSettings();
322 if (resetProfile) emit doResetProfile();
325 void KdenliveSettingsDialog::slotUpdateDisplay() {
326 QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
327 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
328 m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
329 m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
330 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
331 m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
332 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
333 else m_configMisc.p_progressive->setText(i18n("Progressive"));
334 m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
335 m_defaultPath = currentProfile;
339 #include "kdenlivesettingsdialog.moc"