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");
61 QWidget *p5 = new QWidget;
62 m_configShuttle.setupUi(p5);
63 connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int)));
64 connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
65 slotCheckShuttle(KdenliveSettings::enableshuttle());
66 page5 = addPage(p5, i18n("JogShuttle"), "input-mouse");
69 actions << i18n("Do nothing");
70 actions << i18n("Play / Pause");
71 actions << i18n("Cut");
72 m_configShuttle.kcfg_shuttle1->addItems(actions);
73 m_configShuttle.kcfg_shuttle2->addItems(actions);
74 m_configShuttle.kcfg_shuttle3->addItems(actions);
75 m_configShuttle.kcfg_shuttle4->addItems(actions);
76 m_configShuttle.kcfg_shuttle5->addItems(actions);
78 connect(m_configCapture.kcfg_video4vdevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
79 connect(m_configCapture.kcfg_video4adevice, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
80 connect(m_configCapture.kcfg_video4vformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
81 connect(m_configCapture.kcfg_video4aformat, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
82 connect(m_configCapture.kcfg_video4vencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
83 connect(m_configCapture.kcfg_video4aencoding, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
84 connect(m_configCapture.kcfg_video4size, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
85 connect(m_configCapture.kcfg_video4rate, SIGNAL(editingFinished()), this, SLOT(rebuildVideo4Commands()));
88 QStringList profilesNames = ProfilesDialog::getProfileNames();
89 m_configMisc.kcfg_profiles_list->addItems(profilesNames);
90 m_defaultProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description");
91 if (profilesNames.contains(m_defaultProfile)) {
92 m_configMisc.kcfg_profiles_list->setCurrentItem(m_defaultProfile);
93 KdenliveSettings::setProfiles_list(profilesNames.indexOf(m_defaultProfile));
98 connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
101 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
104 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
105 m_configShuttle.config_group->setEnabled(state);
106 if (m_configShuttle.shuttledevicelist->count() == 0) {
108 QString baseName = "/dev/input/event";
110 for (int i = 0; i < 30; i++) {
111 QString filename = baseName + QString::number(i);
112 kDebug() << "/// CHECKING OFR: " << filename;
114 char name[256] = "unknown";
115 fd = ::open((char *) filename.toUtf8().data(), O_RDONLY);
116 if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) {
117 m_configShuttle.shuttledevicelist->addItem(name, filename);
121 if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
125 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) {
126 QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
127 //KdenliveSettings::setShuttledevice(device);
128 m_configShuttle.kcfg_shuttledevice->setText(device);
131 void KdenliveSettingsDialog::rebuildVideo4Commands() {
132 QString captureCommand;
133 if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text();
135 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();
136 m_configCapture.kcfg_video4capture->setText(captureCommand);
138 QString playbackCommand;
139 playbackCommand = "-f " + m_configCapture.kcfg_video4vencoding->text();
140 m_configCapture.kcfg_video4playback->setText(playbackCommand);
143 bool KdenliveSettingsDialog::hasChanged() {
144 kDebug() << "// // // KCONFIG hasChanged called: " << m_configMisc.kcfg_profiles_list->currentText() << ", " << m_defaultProfile;
145 if (m_configMisc.kcfg_profiles_list->currentText() != m_defaultProfile) return true;
146 return KConfigDialog::hasChanged();
149 void KdenliveSettingsDialog::updateSettings() {
150 kDebug() << "// // // KCONFIG UPDATE called";
151 m_defaultProfile = m_configMisc.kcfg_profiles_list->currentText();
152 KdenliveSettings::setDefault_profile(m_defaultPath);
153 KConfigDialog::updateSettings();
156 void KdenliveSettingsDialog::slotUpdateDisplay() {
157 QString currentProfile = m_configMisc.kcfg_profiles_list->currentText();
158 QMap< QString, QString > values = ProfilesDialog::getSettingsForProfile(currentProfile);
159 m_configMisc.p_size->setText(values.value("width") + "x" + values.value("height"));
160 m_configMisc.p_fps->setText(values.value("frame_rate_num") + "/" + values.value("frame_rate_den"));
161 m_configMisc.p_aspect->setText(values.value("sample_aspect_num") + "/" + values.value("sample_aspect_den"));
162 m_configMisc.p_display->setText(values.value("display_aspect_num") + "/" + values.value("display_aspect_den"));
163 if (values.value("progressive").toInt() == 0) m_configMisc.p_progressive->setText(i18n("Interlaced"));
164 else m_configMisc.p_progressive->setText(i18n("Progressive"));
165 m_defaultPath = values.value("path");
169 #include "kdenlivesettingsdialog.moc"