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()));
97 QStringList profilesNames = ProfilesDialog::getProfileNames();
98 m_configMisc.kcfg_profiles_list->addItems(profilesNames);
99 m_defaultProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description");
100 if (profilesNames.contains(m_defaultProfile)) {
101 m_configMisc.kcfg_profiles_list->setCurrentItem(m_defaultProfile);
102 KdenliveSettings::setProfiles_list(profilesNames.indexOf(m_defaultProfile));
106 m_audioDevice = KdenliveSettings::audio_device();
108 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
111 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
113 void KdenliveSettingsDialog::initDevices()
115 // Fill audio drivers
116 m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
117 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
118 m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
119 m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
120 m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
121 m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
123 /*if (!KdenliveSettings::audiodriver().isEmpty())
124 for (uint i = 1;i < m_configDisplay.kcfg_audio_driver->count(); i++) {
125 if (m_configDisplay.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodriver())
126 m_configDisplay.kcfg_audio_driver->setCurrentIndex(i);
129 // Fill video drivers
130 m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
131 m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11");
132 m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga");
133 m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
134 m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
135 m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
136 m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
137 m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
138 m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
140 // Fill the list of audio playback devices
141 m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
142 if (KStandardDirs::findExe("aplay") != QString::null) {
143 m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
144 m_readProcess.setProgram("aplay", QStringList() << "-l");
145 connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) ,this, SLOT(slotReadAudioDevices()));
146 m_readProcess.execute(5000);
149 // If aplay is not installed on the system, parse the /proc/asound/pcm file
150 QFile file("/proc/asound/pcm");
151 if ( file.open( QIODevice::ReadOnly ) ) {
152 QTextStream stream( &file );
154 while ( !stream.atEnd() ) {
155 line = stream.readLine();
156 if (line.contains("playback")) {
157 QString deviceId = line.section(":", 0, 0);
158 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()));
167 void KdenliveSettingsDialog::slotReadAudioDevices()
169 QString result = QString(m_readProcess.readAllStandardOutput());
170 kDebug()<<"// / / / / / READING APLAY: ";
172 QStringList lines = result.split('\n');
173 foreach (QString data, lines) {
174 kDebug()<<"// READING LINE: "<<data;
175 if (data.simplified().startsWith("card")) {
176 QString card = data.section(":", 0, 0).section(" ", -1);
177 QString device = data.section(":", 1, 1).section(" ", -1);
178 m_configSdl.kcfg_audio_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
183 void KdenliveSettingsDialog::showPage(int page, int option) {
186 setCurrentPage(page1);
189 setCurrentPage(page2);
192 setCurrentPage(page3);
195 setCurrentPage(page4);
196 m_configCapture.tabWidget->setCurrentIndex(option);
199 setCurrentPage(page5);
205 void KdenliveSettingsDialog::slotEditVideoApplication() {
206 KService::Ptr service;
207 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
208 if (dlg.exec() != QDialog::Accepted)
211 service = dlg.service();
212 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
215 void KdenliveSettingsDialog::slotEditAudioApplication() {
216 KService::Ptr service;
217 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
218 if (dlg.exec() != QDialog::Accepted)
221 service = dlg.service();
222 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
225 void KdenliveSettingsDialog::slotEditImageApplication() {
226 KService::Ptr service;
227 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
228 if (dlg.exec() != QDialog::Accepted)
231 service = dlg.service();
232 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
235 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
236 m_configShuttle.config_group->setEnabled(state);
237 if (m_configShuttle.shuttledevicelist->count() == 0) {
239 QString baseName = "/dev/input/event";
241 for (int i = 0; i < 30; i++) {
242 QString filename = baseName + QString::number(i);
243 kDebug() << "/// CHECKING OFR: " << filename;
245 char name[256] = "unknown";
246 fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
247 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
248 m_configShuttle.shuttledevicelist->addItem(name, filename);
252 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
256 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
257 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
258 //KdenliveSettings::setShuttledevice(device);
259 m_configShuttle.kcfg_shuttledevice->setText(device);
262 void KdenliveSettingsDialog::rebuildVideo4Commands() {
263 QString captureCommand;
264 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
266 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();
267 m_configCapture.kcfg_video4capture->setText(captureCommand);
269 QString playbackCommand;
270 playbackCommand = "-f " + m_configCapture.kcfg_video4vencoding->text();
271 m_configCapture.kcfg_video4playback->setText(playbackCommand);
276 bool KdenliveSettingsDialog::isDefault() {
277 return KConfigDialog::isDefault();
281 bool KdenliveSettingsDialog::hasChanged() {
282 kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
284 if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
285 return KConfigDialog::hasChanged();
288 void KdenliveSettingsDialog::updateSettings() {
289 kDebug() << "// // // KCONFIG UPDATE called";
290 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
291 KdenliveSettings::setDefault_profile(m_defaultPath);
293 bool resetProfile = false;
294 QString value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
295 if (value != KdenliveSettings::audiodevicename()) {
296 KdenliveSettings::setAudiodevicename(value);
300 value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
301 if (value != KdenliveSettings::audiodrivername()) {
302 KdenliveSettings::setAudiodrivername(value);
306 value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
307 if (value != KdenliveSettings::videodrivername()) {
308 KdenliveSettings::setVideodrivername(value);
312 KConfigDialog::updateSettings();
313 if (resetProfile) emit doResetProfile();
316 void KdenliveSettingsDialog::slotUpdateDisplay() {
317 QString currentProfile = m_configMisc.kcfg_profiles_list->currentText();
318 QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile);
319 m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
320 m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
321 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
322 m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
323 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
324 else m_configMisc.p_progressive->setText(i18n("Progressive"));
325 m_defaultPath = values.value("path");
329 #include "kdenlivesettingsdialog.moc"