1 /***************************************************************************
2 * Copyright (C) 2007 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 ***************************************************************************/
22 #include <QXmlStreamWriter>
23 #include <QApplication>
26 #include <KStandardDirs>
29 #include <kmimetype.h>
31 #include "kdenlivesettings.h"
32 #include "profilesdialog.h"
35 Wizard::Wizard(QWidget *parent): QWizard(parent) {
36 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
38 QWizardPage *page1 = new QWizardPage;
39 page1->setTitle(i18n("Welcome"));
40 QLabel *label = new QLabel(i18n("This is the first time you run Kdenlive. This wizard will let you adjust some basic settings, you will be ready to edit your first movie in a few seconds..."));
41 label->setWordWrap(true);
42 m_startLayout = new QVBoxLayout;
43 m_startLayout->addWidget(label);
44 page1->setLayout(m_startLayout);
47 QWizardPage *page2 = new QWizardPage;
48 page2->setTitle(i18n("Video Standard"));
49 m_standard.setupUi(page2);
51 // build profiles lists
52 m_profilesInfo = ProfilesDialog::getProfilesInfo();
53 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
54 while (i != m_profilesInfo.constEnd()) {
55 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
56 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
57 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
58 else m_otherProfiles.append(i.key());
62 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
63 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
64 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
65 m_standard.button_all->setChecked(true);
66 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
68 // select default profile
69 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
70 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
73 QWizardPage *page3 = new QWizardPage;
74 page3->setTitle(i18n("Additional Settings"));
75 m_extra.setupUi(page3);
76 m_extra.projectfolder->setMode(KFile::Directory);
77 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
78 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
79 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
80 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
81 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
82 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
87 QWizardPage *page4 = new QWizardPage;
88 page4->setTitle(i18n("Checking system"));
89 m_check.setupUi(page4);
93 WizardDelegate *listViewDelegate = new WizardDelegate(m_check.programList);
94 m_check.programList->setItemDelegate(listViewDelegate);
96 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
99 void Wizard::slotCheckPrograms() {
100 m_check.programList->setColumnCount(2);
101 m_check.programList->setRootIsDecorated(false);
102 m_check.programList->setHeaderHidden(true);
103 QSize itemSize(20, this->fontMetrics().height() * 2.5);
104 KIcon okIcon("dialog-ok");
105 KIcon missingIcon("dialog-close");
106 m_check.programList->setColumnWidth(0, 30);
107 m_check.programList->setIconSize(QSize(24, 24));
108 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
109 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
110 item->setSizeHint(0, itemSize);
111 QString exepath = KStandardDirs::findExe("ffmpeg");
112 if (exepath.isEmpty()) item->setIcon(0, missingIcon);
113 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, missingIcon);
114 else item->setIcon(0, okIcon);
116 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
117 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
118 item->setSizeHint(0, itemSize);
119 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, missingIcon);
120 else item->setIcon(0, okIcon);
122 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
123 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
124 item->setSizeHint(0, itemSize);
125 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, missingIcon);
126 else item->setIcon(0, okIcon);
128 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Inigo"));
129 item->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
130 item->setSizeHint(0, itemSize);
131 if (KStandardDirs::findExe("inigo").isEmpty()) item->setIcon(0, missingIcon);
132 else item->setIcon(0, okIcon);
135 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
136 QString mimefile = baseName;
137 mimefile.replace('/', '-');
138 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
140 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
142 QStringList extensions = mime->patterns();
143 QString comment = mime->comment();
144 foreach(const QString &glob, globs) {
145 if (!extensions.contains(glob)) extensions << glob;
147 kDebug() << "EXTS: " << extensions;
148 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
149 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
150 QFile packageFile(packageFileName);
151 if (!packageFile.open(QIODevice::WriteOnly)) {
152 kError() << "Couldn't open" << packageFileName << "for writing";
155 QXmlStreamWriter writer(&packageFile);
156 writer.setAutoFormatting(true);
157 writer.writeStartDocument();
159 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
160 writer.writeDefaultNamespace(nsUri);
161 writer.writeStartElement("mime-info");
162 writer.writeStartElement(nsUri, "mime-type");
163 writer.writeAttribute("type", baseName);
165 if (!comment.isEmpty()) {
166 writer.writeStartElement(nsUri, "comment");
167 writer.writeCharacters(comment);
168 writer.writeEndElement(); // comment
171 foreach(const QString& pattern, extensions) {
172 writer.writeStartElement(nsUri, "glob");
173 writer.writeAttribute("pattern", pattern);
174 writer.writeEndElement(); // glob
177 writer.writeEndElement(); // mime-info
178 writer.writeEndElement(); // mime-type
179 writer.writeEndDocument();
183 void Wizard::runUpdateMimeDatabase() {
184 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
185 //Q_ASSERT(!localPackageDir.isEmpty());
187 proc << "update-mime-database";
188 proc << localPackageDir;
189 const int exitCode = proc.execute();
191 kWarning() << proc.program() << "exited with error code" << exitCode;
195 void Wizard::slotCheckThumbs() {
196 QString pixname = "timeline_vthumbs.png";
197 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
198 pixname = "timeline_nothumbs.png";
199 } else if (m_extra.audiothumbs->isChecked()) {
200 if (m_extra.videothumbs->isChecked())
201 pixname = "timeline_avthumbs.png";
202 else pixname = "timeline_athumbs.png";
205 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
208 void Wizard::slotCheckStandard() {
209 m_standard.profiles_list->clear();
210 QStringList profiles;
211 if (m_standard.button_dv->isChecked()) {
213 m_standard.profiles_list->addItems(m_dvProfiles);
214 } else if (m_standard.button_hdv->isChecked()) {
216 m_standard.profiles_list->addItems(m_hdvProfiles);
218 m_standard.profiles_list->addItems(m_dvProfiles);
219 m_standard.profiles_list->addItems(m_hdvProfiles);
220 m_standard.profiles_list->addItems(m_otherProfiles);
221 //m_standard.profiles_list->sortItems();
224 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
225 QListWidgetItem *item = m_standard.profiles_list->item(i);
226 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
227 const QString infoString = i18n("<b>Frame size:</b>%1x%2<br><b>Frame rate:</b>%3/%4<br><b>Aspect ratio:</b>%5/%6<br><b>Display ratio:</b>%7/%8").arg(QString::number(prof.width), QString::number(prof.height), QString::number(prof.frame_rate_num), QString::number(prof.frame_rate_den), QString::number(prof.sample_aspect_num), QString::number(prof.sample_aspect_den), QString::number(prof.display_aspect_num), QString::number(prof.display_aspect_den));
228 item->setToolTip(infoString);
231 m_standard.profiles_list->setSortingEnabled(true);
232 m_standard.profiles_list->setCurrentRow(0);
235 void Wizard::slotCheckSelectedItem() {
236 // Make sure we always have an item highlighted
237 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
241 void Wizard::adjustSettings() {
242 if (m_extra.installmimes->isChecked()) {
244 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
245 installExtraMimes("video/mpeg", globs);
248 installExtraMimes("video/dv", globs);
249 runUpdateMimeDatabase();
251 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
252 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
253 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
254 if (m_standard.profiles_list->currentItem()) {
255 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
256 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
257 KdenliveSettings::setDefault_profile(selectedProfile);
259 QString path = m_extra.projectfolder->url().path();
260 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
261 KdenliveSettings::setDefaultprojectfolder(path);
265 void Wizard::slotCheckMlt() {
266 QString errorMessage;
267 if (KdenliveSettings::rendererpath().isEmpty()) {
268 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
270 QProcess checkProcess;
271 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
272 if (!checkProcess.waitForStarted())
273 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
275 checkProcess.waitForFinished();
277 QByteArray result = checkProcess.readAllStandardError();
278 if (!result.contains("- avformat")) errorMessage.append(i18n("MLT's avformat (FFMPEG) module not found. Please check your FFMPEG and MLT install. Kdenlive will not work until this issue is fixed.") + "\n");
280 QProcess checkProcess2;
281 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
282 if (!checkProcess2.waitForStarted())
283 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + "\n");
285 checkProcess2.waitForFinished();
287 result = checkProcess2.readAllStandardError();
288 if (!result.contains("sdl") || !result.contains("sdl_preview")) errorMessage.append(i18n("MLT's SDL module not found. Please check your MLT install. Kdenlive will not work until this issue is fixed.") + "\n");
290 if (!errorMessage.isEmpty()) {
291 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
292 QLabel *pix = new QLabel();
293 pix->setPixmap(KIcon("dialog-error").pixmap(30));
294 QLabel *label = new QLabel(errorMessage);
295 label->setWordWrap(true);
296 m_startLayout->addSpacing(40);
297 m_startLayout->addWidget(pix);
298 m_startLayout->addWidget(label);
299 m_systemCheckIsOk = false;
300 button(QWizard::NextButton)->setEnabled(false);
301 } else m_systemCheckIsOk = true;
304 bool Wizard::isOk() const {
305 return m_systemCheckIsOk;
308 #include "wizard.moc"