]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Fix several issues with spacer tool + some indent fixes
[kdenlive] / src / kdenlivesettingsdialog.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include <QDir>
21 #include <QTimer>
22
23 #include <KStandardDirs>
24 #include <KDebug>
25 #include <kopenwithdialog.h>
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #ifndef NO_JOGSHUTTLE
32 #include <linux/input.h>
33 #endif /* NO_JOGSHUTTLE */
34
35 #include "profilesdialog.h"
36 #include "kdenlivesettings.h"
37 #include "kdenlivesettingsdialog.h"
38
39 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
40
41     QWidget *p1 = new QWidget;
42     m_configMisc.setupUi(p1);
43     page1 = addPage(p1, i18n("Misc"), "configure");
44
45     QWidget *p3 = new QWidget;
46     m_configDisplay.setupUi(p3);
47     page3 = addPage(p3, i18n("Display"), "display");
48
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");
59
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());
64
65     QWidget *p5 = new QWidget;
66     m_configShuttle.setupUi(p5);
67 #ifndef NO_JOGSHUTTLE
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();
72 #else
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");
77
78     QWidget *p6 = new QWidget;
79     m_configSdl.setupUi(p6);
80     page6 = addPage(p6, i18n("Playback"), "audio-card");
81
82     QStringList actions;
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);
91
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_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
97     connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
98     connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
99     connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
100
101     connect(m_configCapture.kcfg_rmd_capture_audio, SIGNAL(clicked(bool)), m_configCapture.audio_group, SLOT(setVisible(bool)));
102
103     m_configCapture.audio_group->setVisible(KdenliveSettings::rmd_capture_audio());
104
105     connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
106     connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
107     connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
108
109
110
111     QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
112     QMapIterator<QString, QString> i(profilesInfo);
113     while (i.hasNext()) {
114         i.next();
115         m_configMisc.kcfg_profiles_list->addItem(i.key(), i.value());
116     }
117
118     checkProfile();
119     slotUpdateDisplay();
120
121     initDevices();
122     connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
123
124     connect(m_configCapture.kcfg_rmd_capture_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateRmdRegionStatus()));
125
126     slotUpdateRmdRegionStatus();
127
128
129     //HACK: check dvgrab version, because only dvgrab >= 3.3 supports
130     //   --timestamp option without bug
131
132     if (KdenliveSettings::dvgrab_path().isEmpty() || !QFile::exists(KdenliveSettings::dvgrab_path())) {
133         QString dvgrabpath = KStandardDirs::findExe("dvgrab");
134         KdenliveSettings::setDvgrab_path(dvgrabpath);
135     }
136
137
138     double dvgrabVersion = 0;
139     if (!KdenliveSettings::dvgrab_path().isEmpty()) {
140         QProcess *versionCheck = new QProcess;
141         versionCheck->setProcessChannelMode(QProcess::MergedChannels);
142         versionCheck->start("dvgrab", QStringList() << "--version");
143         if (versionCheck->waitForFinished()) {
144             QString version = QString(versionCheck->readAll()).simplified();
145             if (version.contains(' ')) version = version.section(' ', -1);
146             dvgrabVersion = version.toDouble();
147
148             kDebug() << "// FOUND DVGRAB VERSION: " << dvgrabVersion;
149         }
150         if (versionCheck) delete versionCheck;
151         if (dvgrabVersion < 3.3) {
152             KdenliveSettings::setFirewiretimestamp(false);
153             m_configCapture.kcfg_firewiretimestamp->setEnabled(false);
154         }
155         m_configCapture.dvgrab_info->setText(i18n("dvgrab version %1 at %2", dvgrabVersion, KdenliveSettings::dvgrab_path()));
156     } else m_configCapture.dvgrab_info->setText(i18n("<b>dvgrab utility not found, please install it for firewire capture</b>"));
157
158     if (KdenliveSettings::rmd_path().isEmpty() || !QFile::exists(KdenliveSettings::rmd_path())) {
159         QString rmdpath = KStandardDirs::findExe("recordmydesktop");
160         KdenliveSettings::setRmd_path(rmdpath);
161     }
162     if (KdenliveSettings::rmd_path().isEmpty()) m_configCapture.rmd_info->setText(i18n("<b>Recordmydesktop utility not found, please install it for screen grabs</b>"));
163     else m_configCapture.rmd_info->setText(i18n("Recordmydesktop found at: %1", KdenliveSettings::rmd_path()));
164 }
165
166 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
167
168 void KdenliveSettingsDialog::slotUpdateRmdRegionStatus() {
169     m_configCapture.region_group->setHidden(m_configCapture.kcfg_rmd_capture_type->currentIndex() != 1);
170 }
171
172 void KdenliveSettingsDialog::checkProfile() {
173     if (!KdenliveSettings::default_profile().isEmpty()) {
174         for (int i = 0; i < m_configMisc.kcfg_profiles_list->count(); i++) {
175             if (m_configMisc.kcfg_profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
176                 m_configMisc.kcfg_profiles_list->setCurrentIndex(i);
177                 KdenliveSettings::setProfiles_list(i);
178                 break;
179             }
180         }
181     }
182 }
183
184 void KdenliveSettingsDialog::initDevices() {
185     // Fill audio drivers
186     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
187     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
188     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
189     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
190     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
191     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
192
193     /*if (!KdenliveSettings::audiodriver().isEmpty())
194     for (uint i = 1;i < m_configDisplay.kcfg_audio_driver->count(); i++) {
195      if (m_configDisplay.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodriver())
196     m_configDisplay.kcfg_audio_driver->setCurrentIndex(i);
197     }*/
198
199     // Fill video drivers
200     m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString());
201     m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11");
202     m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel");
203     m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga");
204     m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox");
205     m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon");
206     m_configSdl.kcfg_video_driver->addItem(i18n("Direct FB"), "directfb");
207     m_configSdl.kcfg_video_driver->addItem(i18n("SVGAlib"), "svgalib");
208     m_configSdl.kcfg_video_driver->addItem(i18n("General graphics interface"), "ggi");
209     m_configSdl.kcfg_video_driver->addItem(i18n("Ascii art library"), "aalib");
210
211     // Fill the list of audio playback devices
212     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
213     m_configCapture.kcfg_rmd_alsa_device->addItem(i18n("Default"), QString());
214     if (KStandardDirs::findExe("aplay") != QString::null) {
215         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
216         m_readProcess.setProgram("aplay", QStringList() << "-l");
217         connect(&m_readProcess, SIGNAL(readyReadStandardOutput()) , this, SLOT(slotReadAudioDevices()));
218         m_readProcess.execute(5000);
219     } else {
220         // If aplay is not installed on the system, parse the /proc/asound/pcm file
221         QFile file("/proc/asound/pcm");
222         if (file.open(QIODevice::ReadOnly)) {
223             QTextStream stream(&file);
224             QString line;
225             QString deviceId;
226             while (!stream.atEnd()) {
227                 line = stream.readLine();
228                 if (line.contains("playback")) {
229                     deviceId = line.section(":", 0, 0);
230                     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()));
231                 }
232                 if (line.contains("capture")) {
233                     deviceId = line.section(":", 0, 0);
234                     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()));
235                 }
236             }
237             file.close();
238         }
239     }
240 }
241
242
243 void KdenliveSettingsDialog::slotReadAudioDevices() {
244     QString result = QString(m_readProcess.readAllStandardOutput());
245     kDebug() << "// / / / / / READING APLAY: ";
246     kDebug() << result;
247     QStringList lines = result.split('\n');
248     foreach(QString data, lines) {
249         kDebug() << "// READING LINE: " << data;
250         if (data.simplified().startsWith("card")) {
251             QString card = data.section(":", 0, 0).section(" ", -1);
252             QString device = data.section(":", 1, 1).section(" ", -1);
253             m_configSdl.kcfg_audio_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
254             m_configCapture.kcfg_rmd_alsa_device->addItem(data.section(":", -1), "plughw:" + card + "," + device);
255         }
256     }
257 }
258
259 void KdenliveSettingsDialog::showPage(int page, int option) {
260     switch (page) {
261     case 1:
262         setCurrentPage(page1);
263         break;
264     case 2:
265         setCurrentPage(page2);
266         break;
267     case 3:
268         setCurrentPage(page3);
269         break;
270     case 4:
271         setCurrentPage(page4);
272         m_configCapture.tabWidget->setCurrentIndex(option);
273         break;
274     case 5:
275         setCurrentPage(page5);
276         break;
277
278     }
279 }
280
281 void KdenliveSettingsDialog::slotEditVideoApplication() {
282     KService::Ptr service;
283     KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
284     if (dlg.exec() != QDialog::Accepted)
285         return;
286
287     service = dlg.service();
288     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
289 }
290
291 void KdenliveSettingsDialog::slotEditAudioApplication() {
292     KService::Ptr service;
293     KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
294     if (dlg.exec() != QDialog::Accepted)
295         return;
296
297     service = dlg.service();
298     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
299 }
300
301 void KdenliveSettingsDialog::slotEditImageApplication() {
302     KService::Ptr service;
303     KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
304     if (dlg.exec() != QDialog::Accepted)
305         return;
306
307     service = dlg.service();
308     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
309 }
310
311 #ifndef NO_JOGSHUTTLE
312 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
313     m_configShuttle.config_group->setEnabled(state);
314     if (m_configShuttle.shuttledevicelist->count() == 0) {
315         // parse devices
316         QString baseName = "/dev/input/event";
317         int fd;
318         for (int i = 0; i < 30; i++) {
319             QString filename = baseName + QString::number(i);
320             kDebug() << "/// CHECKING OFR: " << filename;
321
322             char name[256] = "unknown";
323             fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
324             if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
325                 m_configShuttle.shuttledevicelist->addItem(name, filename);
326             }
327             ::close(fd);
328         }
329         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
330     }
331 }
332
333 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
334     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
335     //KdenliveSettings::setShuttledevice(device);
336     m_configShuttle.kcfg_shuttledevice->setText(device);
337 }
338 #endif /* NO_JOGSHUTTLE */
339
340 void KdenliveSettingsDialog::rebuildVideo4Commands() {
341     QString captureCommand;
342     if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
343
344     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();
345     m_configCapture.kcfg_video4capture->setText(captureCommand);
346
347     QString playbackCommand;
348     playbackCommand =  "-f " + m_configCapture.kcfg_video4vencoding->text();
349     m_configCapture.kcfg_video4playback->setText(playbackCommand);
350 }
351
352
353 // virtual protected
354 bool KdenliveSettingsDialog::isDefault() {
355     return KConfigDialog::isDefault();
356 }
357
358 // virtual protected
359 bool KdenliveSettingsDialog::hasChanged() {
360     kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
361
362     if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
363     return KConfigDialog::hasChanged();
364 }
365
366 void KdenliveSettingsDialog::updateSettings() {
367     kDebug() << "// // // KCONFIG UPDATE called";
368     m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
369     KdenliveSettings::setDefault_profile(m_defaultPath);
370
371     bool resetProfile = false;
372     QString value = m_configSdl.kcfg_audio_device->itemData(m_configSdl.kcfg_audio_device->currentIndex()).toString();
373     if (value != KdenliveSettings::audiodevicename()) {
374         KdenliveSettings::setAudiodevicename(value);
375         resetProfile = true;
376     }
377
378     value = m_configCapture.kcfg_rmd_alsa_device->itemData(m_configCapture.kcfg_rmd_alsa_device->currentIndex()).toString();
379     if (value != KdenliveSettings::rmd_alsadevicename()) {
380         KdenliveSettings::setRmd_alsadevicename(value);
381     }
382
383     value = m_configCapture.kcfg_rmd_audio_freq->itemText(m_configCapture.kcfg_rmd_audio_freq->currentIndex());
384     kDebug() << "// AUDIO FREQ VALUE: " << value << ", CURRENT: " << KdenliveSettings::rmd_freq() << ", IX: " << m_configCapture.kcfg_rmd_audio_freq->currentIndex();
385     if (value != KdenliveSettings::rmd_freq()) {
386         kDebug() << "// SETTING AUDIO FREQ TO: " << value;
387         KdenliveSettings::setRmd_freq(value);
388     }
389
390     value = m_configSdl.kcfg_audio_driver->itemData(m_configSdl.kcfg_audio_driver->currentIndex()).toString();
391     if (value != KdenliveSettings::audiodrivername()) {
392         KdenliveSettings::setAudiodrivername(value);
393         resetProfile = true;
394     }
395
396     value = m_configSdl.kcfg_video_driver->itemData(m_configSdl.kcfg_video_driver->currentIndex()).toString();
397     if (value != KdenliveSettings::videodrivername()) {
398         KdenliveSettings::setVideodrivername(value);
399         resetProfile = true;
400     }
401
402     KConfigDialog::updateSettings();
403     if (resetProfile) emit doResetProfile();
404 }
405
406 void KdenliveSettingsDialog::slotUpdateDisplay() {
407     QString currentProfile = m_configMisc.kcfg_profiles_list->itemData(m_configMisc.kcfg_profiles_list->currentIndex()).toString();
408     QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
409     m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
410     m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
411     m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
412     m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
413     if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
414     else m_configMisc.p_progressive->setText(i18n("Progressive"));
415     m_defaultProfile = m_configMisc.kcfg_profiles_list->itemText(m_configMisc.kcfg_profiles_list->currentIndex());
416     m_defaultPath = currentProfile;
417 }
418
419
420 #include "kdenlivesettingsdialog.moc"
421
422