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 ***************************************************************************/
21 #include "kdenlivesettings.h"
22 #include "profilesdialog.h"
24 #include <KStandardDirs>
27 #include <kmimetype.h>
31 #include <QXmlStreamWriter>
34 const double recommendedMltVersion = 36;
36 Wizard::Wizard(bool upgrade, QWidget *parent) :
39 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
41 QWizardPage *page1 = new QWizardPage;
42 page1->setTitle(i18n("Welcome"));
45 label = new QLabel(i18n("Your Kdenlive version was upgraded. Please take some time to review the basic settings"));
47 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..."));
48 label->setWordWrap(true);
49 m_startLayout = new QVBoxLayout;
50 m_startLayout->addWidget(label);
51 page1->setLayout(m_startLayout);
54 QWizardPage *page4 = new QWizardPage;
55 page4->setTitle(i18n("Checking MLT engine"));
56 m_mltCheck.setupUi(page4);
59 WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
60 m_mltCheck.programList->setItemDelegate(listViewDelegate);
62 QWizardPage *page2 = new QWizardPage;
63 page2->setTitle(i18n("Video Standard"));
64 m_standard.setupUi(page2);
66 m_okIcon = KIcon("dialog-ok");
67 m_badIcon = KIcon("dialog-close");
69 // build profiles lists
70 m_profilesInfo = ProfilesDialog::getProfilesInfo();
71 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
72 while (i != m_profilesInfo.constEnd()) {
73 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
74 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
75 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
76 else m_otherProfiles.append(i.key());
80 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
81 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
82 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
83 m_standard.button_all->setChecked(true);
84 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
86 // select default profile
87 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
88 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
91 QWizardPage *page3 = new QWizardPage;
92 page3->setTitle(i18n("Additional Settings"));
93 m_extra.setupUi(page3);
94 m_extra.projectfolder->setMode(KFile::Directory);
95 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
96 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
97 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
98 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
99 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
100 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
105 QWizardPage *page5 = new QWizardPage;
106 page5->setTitle(i18n("Checking system"));
107 m_check.setupUi(page5);
110 listViewDelegate = new WizardDelegate(m_check.programList);
111 m_check.programList->setItemDelegate(listViewDelegate);
113 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
117 void Wizard::checkMltComponents()
119 m_mltCheck.programList->setColumnCount(2);
120 m_mltCheck.programList->setRootIsDecorated(false);
121 m_mltCheck.programList->setHeaderHidden(true);
122 QSize itemSize(20, fontMetrics().height() * 2.5);
123 m_mltCheck.programList->setColumnWidth(0, 30);
124 m_mltCheck.programList->setIconSize(QSize(24, 24));
127 QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);
129 QTreeWidgetItem *inigoitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Inigo") + " (" + KdenliveSettings::rendererpath() + ')');
130 inigoitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
131 inigoitem->setSizeHint(0, itemSize);
132 inigoitem->setIcon(0, m_okIcon);
134 // Check MLT's installed producers
135 QProcess checkProcess;
136 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
137 if (!checkProcess.waitForStarted()) {
138 inigoitem->setIcon(0, m_badIcon);
139 inigoitem->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (inigo)"));
140 button(QWizard::NextButton)->setEnabled(false);
142 checkProcess.waitForFinished();
143 QByteArray result = checkProcess.readAllStandardError();
145 // Check MLT avformat module
146 QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
147 avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
148 avformatItem->setSizeHint(0, itemSize);
149 if (!result.contains("- avformat")) {
150 avformatItem->setIcon(0, m_badIcon);
151 m_mltCheck.tabWidget->setTabEnabled(1, false);
153 avformatItem->setIcon(0, m_okIcon);
154 // Make sure we have MLT > 0.3.4
155 bool recentMlt = false;
158 QString exepath = KStandardDirs::findExe("pkg-config");
159 if (!exepath.isEmpty()) {
160 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt-framework");
161 if (!checkProcess.waitForStarted()) {
162 kDebug() << "// Error querying MLT's version";
164 checkProcess.waitForFinished();
165 mltVersion = checkProcess.readAllStandardOutput();
166 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
167 kDebug() << "// FOUND MLT's pkgconfig version: " << version;
168 if (version > 34) recentMlt = true;
172 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
173 if (!checkProcess.waitForStarted()) {
174 kDebug() << "// Error querying MLT's version";
176 checkProcess.waitForFinished();
177 mltVersion = checkProcess.readAllStandardError();
178 mltVersion = mltVersion.section('\n', 0, 0).simplified();
179 mltVersion = mltVersion.section(' ', -1).simplified();
180 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
181 kDebug() << "// FOUND MLT version: " << version;
182 if (version > 34) recentMlt = true;
186 mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
187 mltitem->setSizeHint(0, itemSize);
188 if (version < recommendedMltVersion) {
189 mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to the latest MLT version"));
190 mltitem->setIcon(0, m_badIcon);
192 mltitem->setData(1, Qt::UserRole, i18n("MLT version is correct"));
193 mltitem->setIcon(0, m_okIcon);
197 // Check installed audio codecs
198 QProcess checkProcess2;
199 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
200 if (!checkProcess2.waitForStarted()) {
201 m_mltCheck.tabWidget->setTabEnabled(1, false);
202 kDebug() << "// Error parsing MLT's avformat codecs";
204 checkProcess2.waitForFinished();
205 QByteArray codecList = checkProcess2.readAllStandardError();
206 QString acodecList(codecList);
208 QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
209 for (int i = 0; i < alist.count(); i++) {
210 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
212 m_mltCheck.acodecs_list->addItems(result);
213 KdenliveSettings::setAudiocodecs(result);
214 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
216 // Check video codecs
217 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
218 if (!checkProcess2.waitForStarted()) {
219 kDebug() << "// Error parsing MLT's avformat codecs";
221 checkProcess2.waitForFinished();
222 QByteArray codecList = checkProcess2.readAllStandardError();
223 QString vcodecList(codecList);
225 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
226 for (int i = 0; i < vlist.count(); i++) {
227 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
229 m_mltCheck.vcodecs_list->addItems(result);
230 KdenliveSettings::setVideocodecs(result);
231 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
234 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
235 if (!checkProcess2.waitForStarted()) {
236 kDebug() << "// Error parsing MLT's avformat codecs";
238 checkProcess2.waitForFinished();
239 QByteArray codecList = checkProcess2.readAllStandardError();
240 QString vcodecList(codecList);
242 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
243 for (int i = 0; i < vlist.count(); i++) {
244 if (vlist.at(i).contains("- ")) {
245 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
246 if (format.contains(',')) {
247 QStringList sub = format.split(',', QString::SkipEmptyParts);
248 for (int j = 0; j < sub.count(); j++)
249 result.append(sub.at(j));
250 } else result.append(format);
253 m_mltCheck.formats_list->addItems(result);
254 KdenliveSettings::setSupportedformats(result);
255 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
261 // Check MLT dv module
262 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
263 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
264 dvItem->setSizeHint(0, itemSize);
265 if (!result.contains("- libdv")) {
266 dvItem->setIcon(0, m_badIcon);
268 dvItem->setIcon(0, m_okIcon);
271 // Check MLT image format module
272 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
273 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
274 imageItem->setSizeHint(0, itemSize);
275 if (!result.contains("- qimage")) {
276 imageItem->setIcon(0, m_badIcon);
277 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
278 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
279 imageItem->setSizeHint(0, itemSize);
280 if (!result.contains("- pixbuf")) imageItem->setIcon(0, m_badIcon);
281 else imageItem->setIcon(0, m_okIcon);
283 imageItem->setIcon(0, m_okIcon);
288 void Wizard::slotCheckPrograms()
290 m_check.programList->setColumnCount(2);
291 m_check.programList->setRootIsDecorated(false);
292 m_check.programList->setHeaderHidden(true);
293 QSize itemSize(20, fontMetrics().height() * 2.5);
294 m_check.programList->setColumnWidth(0, 30);
295 m_check.programList->setIconSize(QSize(24, 24));
297 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
298 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
299 item->setSizeHint(0, itemSize);
300 QString exepath = KStandardDirs::findExe("ffmpeg");
301 if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
302 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
303 else item->setIcon(0, m_okIcon);
305 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
306 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
307 item->setSizeHint(0, itemSize);
308 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
309 else item->setIcon(0, m_okIcon);
311 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
312 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
313 item->setSizeHint(0, itemSize);
314 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
315 else item->setIcon(0, m_okIcon);
317 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
318 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
319 item->setSizeHint(0, itemSize);
320 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
321 else item->setIcon(0, m_okIcon);
323 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
324 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
325 item->setSizeHint(0, itemSize);
326 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, m_badIcon);
327 else item->setIcon(0, m_okIcon);
331 void Wizard::installExtraMimes(QString baseName, QStringList globs)
333 QString mimefile = baseName;
334 mimefile.replace('/', '-');
335 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
337 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
339 QStringList extensions = mime->patterns();
340 QString comment = mime->comment();
341 foreach(const QString &glob, globs) {
342 if (!extensions.contains(glob)) extensions << glob;
344 kDebug() << "EXTS: " << extensions;
345 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
346 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
347 QFile packageFile(packageFileName);
348 if (!packageFile.open(QIODevice::WriteOnly)) {
349 kError() << "Couldn't open" << packageFileName << "for writing";
352 QXmlStreamWriter writer(&packageFile);
353 writer.setAutoFormatting(true);
354 writer.writeStartDocument();
356 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
357 writer.writeDefaultNamespace(nsUri);
358 writer.writeStartElement("mime-info");
359 writer.writeStartElement(nsUri, "mime-type");
360 writer.writeAttribute("type", baseName);
362 if (!comment.isEmpty()) {
363 writer.writeStartElement(nsUri, "comment");
364 writer.writeCharacters(comment);
365 writer.writeEndElement(); // comment
368 foreach(const QString& pattern, extensions) {
369 writer.writeStartElement(nsUri, "glob");
370 writer.writeAttribute("pattern", pattern);
371 writer.writeEndElement(); // glob
374 writer.writeEndElement(); // mime-info
375 writer.writeEndElement(); // mime-type
376 writer.writeEndDocument();
380 void Wizard::runUpdateMimeDatabase()
382 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
383 //Q_ASSERT(!localPackageDir.isEmpty());
385 proc << "update-mime-database";
386 proc << localPackageDir;
387 const int exitCode = proc.execute();
389 kWarning() << proc.program() << "exited with error code" << exitCode;
393 void Wizard::slotCheckThumbs()
395 QString pixname = "timeline_vthumbs.png";
396 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
397 pixname = "timeline_nothumbs.png";
398 } else if (m_extra.audiothumbs->isChecked()) {
399 if (m_extra.videothumbs->isChecked())
400 pixname = "timeline_avthumbs.png";
401 else pixname = "timeline_athumbs.png";
404 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
407 void Wizard::slotCheckStandard()
409 m_standard.profiles_list->clear();
410 QStringList profiles;
411 if (m_standard.button_dv->isChecked()) {
413 m_standard.profiles_list->addItems(m_dvProfiles);
414 } else if (m_standard.button_hdv->isChecked()) {
416 m_standard.profiles_list->addItems(m_hdvProfiles);
418 m_standard.profiles_list->addItems(m_dvProfiles);
419 m_standard.profiles_list->addItems(m_hdvProfiles);
420 m_standard.profiles_list->addItems(m_otherProfiles);
421 //m_standard.profiles_list->sortItems();
424 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
425 QListWidgetItem *item = m_standard.profiles_list->item(i);
426 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
427 const QString infoString = ("<strong>" + i18n("Frame size:") + " </strong>%1x%2<br /><strong>" + i18n("Frame rate:") + " </strong>%3/%4<br /><strong>" + i18n("Pixel aspect ratio:") + "</strong>%5/%6<br /><strong>" + i18n("Display aspect ratio:") + " </strong>%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));
428 item->setToolTip(infoString);
431 m_standard.profiles_list->setSortingEnabled(true);
432 m_standard.profiles_list->setCurrentRow(0);
435 void Wizard::slotCheckSelectedItem()
437 // Make sure we always have an item highlighted
438 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
442 void Wizard::adjustSettings()
444 if (m_extra.installmimes->isChecked()) {
446 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
447 installExtraMimes("video/mpeg", globs);
450 installExtraMimes("video/dv", globs);
451 runUpdateMimeDatabase();
453 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
454 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
455 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
456 if (m_standard.profiles_list->currentItem()) {
457 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
458 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
459 KdenliveSettings::setDefault_profile(selectedProfile);
461 QString path = m_extra.projectfolder->url().path();
462 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
463 KdenliveSettings::setDefaultprojectfolder(path);
467 void Wizard::slotCheckMlt()
469 QString errorMessage;
470 if (KdenliveSettings::rendererpath().isEmpty()) {
471 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
473 /*QProcess checkProcess;
474 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
475 if (!checkProcess.waitForStarted())
476 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
478 checkProcess.waitForFinished();
480 QByteArray result = checkProcess.readAllStandardError();
481 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");*/
483 QProcess checkProcess2;
484 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
485 if (!checkProcess2.waitForStarted())
486 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + '\n');
488 checkProcess2.waitForFinished();
490 QByteArray result = checkProcess2.readAllStandardError();
491 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');
493 if (!errorMessage.isEmpty()) {
494 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
495 QLabel *pix = new QLabel();
496 pix->setPixmap(KIcon("dialog-error").pixmap(30));
497 QLabel *label = new QLabel(errorMessage);
498 label->setWordWrap(true);
499 m_startLayout->addSpacing(40);
500 m_startLayout->addWidget(pix);
501 m_startLayout->addWidget(label);
502 m_systemCheckIsOk = false;
503 button(QWizard::NextButton)->setEnabled(false);
504 } else m_systemCheckIsOk = true;
506 if (m_systemCheckIsOk) checkMltComponents();
510 bool Wizard::isOk() const
512 return m_systemCheckIsOk;
515 #include "wizard.moc"