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