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");
71 actions << i18n("Do nothing");
72 actions << i18n("Play / Pause");
73 actions << i18n("Cut");
74 m_configShuttle.kcfg_shuttle1->addItems(actions);
75 m_configShuttle.kcfg_shuttle2->addItems(actions);
76 m_configShuttle.kcfg_shuttle3->addItems(actions);
77 m_configShuttle.kcfg_shuttle4->addItems(actions);
78 m_configShuttle.kcfg_shuttle5->addItems(actions);
80 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
81 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
82 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
83 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
84 connect(m_configCapture.kcfg_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
85 connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
86 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
87 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
89 connect(m_configEnv.kp_image, SIGNAL(clicked()), this, SLOT(slotEditImageApplication()));
90 connect(m_configEnv.kp_audio, SIGNAL(clicked()), this, SLOT(slotEditAudioApplication()));
91 connect(m_configEnv.kp_player, SIGNAL(clicked()), this, SLOT(slotEditVideoApplication()));
93 QStringList profilesNames = ProfilesDialog::getProfileNames();
94 m_configMisc.kcfg_profiles_list->addItems(profilesNames);
95 m_defaultProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description");
96 if (profilesNames.contains(m_defaultProfile)) {
97 m_configMisc.kcfg_profiles_list->setCurrentItem(m_defaultProfile);
98 KdenliveSettings::setProfiles_list(profilesNames.indexOf(m_defaultProfile));
103 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
106 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
109 void KdenliveSettingsDialog::slotEditVideoApplication() {
110 KService::Ptr service;
111 KOpenWithDialog dlg(KUrl::List(), i18n("Select default video player"), m_configEnv.kcfg_defaultplayerapp->text(), this);
112 if (dlg.exec() != QDialog::Accepted)
115 service = dlg.service();
116 m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
119 void KdenliveSettingsDialog::slotEditAudioApplication() {
120 KService::Ptr service;
121 KOpenWithDialog dlg(KUrl::List(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
122 if (dlg.exec() != QDialog::Accepted)
125 service = dlg.service();
126 m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
129 void KdenliveSettingsDialog::slotEditImageApplication() {
130 KService::Ptr service;
131 KOpenWithDialog dlg(KUrl::List(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
132 if (dlg.exec() != QDialog::Accepted)
135 service = dlg.service();
136 m_configEnv.kcfg_defaultimageapp->setText(service->exec());
139 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
140 m_configShuttle.config_group->setEnabled(state);
141 if (m_configShuttle.shuttledevicelist->count() == 0) {
143 QString baseName = "/dev/input/event";
145 for (int i = 0; i < 30; i++) {
146 QString filename = baseName + QString::number(i);
147 kDebug() << "/// CHECKING OFR: " << filename;
149 char name[256] = "unknown";
150 fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
151 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
152 m_configShuttle.shuttledevicelist->addItem(name, filename);
156 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
160 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
161 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
162 //KdenliveSettings::setShuttledevice(device);
163 m_configShuttle.kcfg_shuttledevice->setText(device);
166 void KdenliveSettingsDialog::rebuildVideo4Commands() {
167 QString captureCommand;
168 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
170 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();
171 m_configCapture.kcfg_video4capture->setText(captureCommand);
173 QString playbackCommand;
174 playbackCommand = "-f " + m_configCapture.kcfg_video4vencoding->text();
175 m_configCapture.kcfg_video4playback->setText(playbackCommand);
178 bool KdenliveSettingsDialog::hasChanged() {
179 kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
180 if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
181 return KConfigDialog::hasChanged();
184 void KdenliveSettingsDialog::updateSettings() {
185 kDebug() << "// // // KCONFIG UPDATE called";
186 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
187 KdenliveSettings::setDefault_profile(m_defaultPath);
188 KConfigDialog::updateSettings();
191 void KdenliveSettingsDialog::slotUpdateDisplay() {
192 QString currentProfile = m_configMisc.kcfg_profiles_list->currentText();
193 QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile);
194 m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
195 m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
196 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
197 m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
198 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
199 else m_configMisc.p_progressive->setText(i18n("Progressive"));
200 m_defaultPath = values.value("path");
204 #include "kdenlivesettingsdialog.moc"