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>
30 #include <linux/input.h>
32 #include "profilesdialog.h"
33 #include "kdenlivesettings.h"
34 #include "kdenlivesettingsdialog.h"
36 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
38 QWidget *p1 = new QWidget;
39 m_configMisc.setupUi(p1);
40 page1 = addPage(p1, i18n("Misc"), "configure");
42 QWidget *p3 = new QWidget;
43 m_configDisplay.setupUi(p3);
44 page3 = addPage(p3, i18n("Display"), "display");
46 QWidget *p2 = new QWidget;
47 m_configEnv.setupUi(p2);
48 m_configEnv.mltpathurl->setMode(KFile::Directory);
49 m_configEnv.mltpathurl->lineEdit()->setObjectName("kcfg_mltpath");
50 m_configEnv.rendererpathurl->lineEdit()->setObjectName("kcfg_rendererpath");
51 m_configEnv.tmppathurl->setMode(KFile::Directory);
52 m_configEnv.tmppathurl->lineEdit()->setObjectName("kcfg_currenttmpfolder");
53 m_configEnv.capturefolderurl->setMode(KFile::Directory);
54 m_configEnv.capturefolderurl->lineEdit()->setObjectName("kcfg_capturefolder");
55 page2 = addPage(p2, i18n("Environnement"), "terminal");
57 QWidget *p4 = new QWidget;
58 m_configCapture.setupUi(p4);
59 page4 = addPage(p4, i18n("Capture"), "audio-card");
60 m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
62 QWidget *p5 = new QWidget;
63 m_configShuttle.setupUi(p5);
64 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
65 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
66 slotCheckShuttle(KdenliveSettings::enableshuttle());
67 page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
70 actions << i18n("Do nothing");
71 actions << i18n("Play / Pause");
72 actions << i18n("Cut");
73 m_configShuttle.kcfg_shuttle1->addItems(actions);
74 m_configShuttle.kcfg_shuttle2->addItems(actions);
75 m_configShuttle.kcfg_shuttle3->addItems(actions);
76 m_configShuttle.kcfg_shuttle4->addItems(actions);
77 m_configShuttle.kcfg_shuttle5->addItems(actions);
79 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
80 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
81 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
82 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
83 connect(m_configCapture.kcfg_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
84 connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
85 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
86 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
89 QStringList profilesNames = ProfilesDialog::getProfileNames();
90 m_configMisc.kcfg_profiles_list->addItems(profilesNames);
91 m_defaultProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description");
92 if (profilesNames.contains(m_defaultProfile)) {
93 m_configMisc.kcfg_profiles_list->setCurrentItem(m_defaultProfile);
94 KdenliveSettings::setProfiles_list(profilesNames.indexOf(m_defaultProfile));
99 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
102 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
105 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
106 m_configShuttle.config_group->setEnabled(state);
107 if (m_configShuttle.shuttledevicelist->count() == 0) {
109 QString baseName = "/dev/input/event";
111 for (int i = 0; i < 30; i++) {
112 QString filename = baseName + QString::number(i);
113 kDebug() << "/// CHECKING OFR: " << filename;
115 char name[256] = "unknown";
116 fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
117 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
118 m_configShuttle.shuttledevicelist->addItem(name, filename);
122 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
126 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
127 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
128 //KdenliveSettings::setShuttledevice(device);
129 m_configShuttle.kcfg_shuttledevice->setText(device);
132 void KdenliveSettingsDialog::rebuildVideo4Commands() {
133 QString captureCommand;
134 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
136 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();
137 m_configCapture.kcfg_video4capture->setText(captureCommand);
139 QString playbackCommand;
140 playbackCommand = "-f " + m_configCapture.kcfg_video4vencoding->text();
141 m_configCapture.kcfg_video4playback->setText(playbackCommand);
144 bool KdenliveSettingsDialog::hasChanged() {
145 kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
146 if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
147 return KConfigDialog::hasChanged();
150 void KdenliveSettingsDialog::updateSettings() {
151 kDebug() << "// // // KCONFIG UPDATE called";
152 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
153 KdenliveSettings::setDefault_profile(m_defaultPath);
154 KConfigDialog::updateSettings();
157 void KdenliveSettingsDialog::slotUpdateDisplay() {
158 QString currentProfile = m_configMisc.kcfg_profiles_list->currentText();
159 QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile);
160 m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
161 m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
162 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
163 m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
164 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
165 else m_configMisc.p_progressive->setText(i18n("Progressive"));
166 m_defaultPath = values.value("path");
170 #include "kdenlivesettingsdialog.moc"