]> git.sesse.net Git - kdenlive/blob - src/kdenlivesettingsdialog.cpp
Fix typos
[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 #include <linux/input.h>
32
33 #include "profilesdialog.h"
34 #include "kdenlivesettings.h"
35 #include "kdenlivesettingsdialog.h"
36
37 KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog(parent, "settings", KdenliveSettings::self()) {
38
39     QWidget *p1 = new QWidget;
40     m_configMisc.setupUi(p1);
41     page1 = addPage(p1, i18n("Misc"), "configure");
42
43     QWidget *p3 = new QWidget;
44     m_configDisplay.setupUi(p3);
45     page3 = addPage(p3, i18n("Display"), "display");
46
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");
57
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());
62
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");
69
70     QStringList actions;
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);
79
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()));
88
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()));
92
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));
99     }
100
101     slotUpdateDisplay();
102
103     connect(m_configMisc.kcfg_profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
104 }
105
106 KdenliveSettingsDialog::~KdenliveSettingsDialog() {}
107
108
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)
113         return;
114
115     service = dlg.service();
116     m_configEnv.kcfg_defaultplayerapp->setText(service->exec());
117 }
118
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)
123         return;
124
125     service = dlg.service();
126     m_configEnv.kcfg_defaultaudioapp->setText(service->exec());
127 }
128
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)
133         return;
134
135     service = dlg.service();
136     m_configEnv.kcfg_defaultimageapp->setText(service->exec());
137 }
138
139 void KdenliveSettingsDialog::slotCheckShuttle(int state) {
140     m_configShuttle.config_group->setEnabled(state);
141     if (m_configShuttle.shuttledevicelist->count() == 0) {
142         // parse devices
143         QString baseName = "/dev/input/event";
144         int fd;
145         for (int i = 0; i < 30; i++) {
146             QString filename = baseName + QString::number(i);
147             kDebug() << "/// CHECKING OFR: " << filename;
148
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);
153             }
154             ::close(fd);
155         }
156         if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice()));
157     }
158 }
159
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);
164 }
165
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();
169
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);
172
173     QString playbackCommand;
174     playbackCommand =  "-f " + m_configCapture.kcfg_video4vencoding->text();
175     m_configCapture.kcfg_video4playback->setText(playbackCommand);
176 }
177
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();
182 }
183
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();
189 }
190
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");
201 }
202
203
204 #include "kdenlivesettingsdialog.moc"
205
206