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): QWizard(parent)
38 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
40 QWizardPage *page1 = new QWizardPage;
41 page1->setTitle(i18n("Welcome"));
44 label = new QLabel(i18n("Your Kdenlive version was upgraded. Please take some time to review the basic settings"));
46 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..."));
47 label->setWordWrap(true);
48 m_startLayout = new QVBoxLayout;
49 m_startLayout->addWidget(label);
50 page1->setLayout(m_startLayout);
53 QWizardPage *page4 = new QWizardPage;
54 page4->setTitle(i18n("Checking MLT engine"));
55 m_mltCheck.setupUi(page4);
58 WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
59 m_mltCheck.programList->setItemDelegate(listViewDelegate);
61 QWizardPage *page2 = new QWizardPage;
62 page2->setTitle(i18n("Video Standard"));
63 m_standard.setupUi(page2);
65 m_okIcon = KIcon("dialog-ok");
66 m_badIcon = KIcon("dialog-close");
68 // build profiles lists
69 m_profilesInfo = ProfilesDialog::getProfilesInfo();
70 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
71 while (i != m_profilesInfo.constEnd()) {
72 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
73 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
74 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
75 else m_otherProfiles.append(i.key());
79 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
80 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
81 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
82 m_standard.button_all->setChecked(true);
83 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
85 // select default profile
86 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
87 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
90 QWizardPage *page3 = new QWizardPage;
91 page3->setTitle(i18n("Additional Settings"));
92 m_extra.setupUi(page3);
93 m_extra.projectfolder->setMode(KFile::Directory);
94 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
95 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
96 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
97 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
98 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
99 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
104 QWizardPage *page5 = new QWizardPage;
105 page5->setTitle(i18n("Checking system"));
106 m_check.setupUi(page5);
109 listViewDelegate = new WizardDelegate(m_check.programList);
110 m_check.programList->setItemDelegate(listViewDelegate);
112 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
116 void Wizard::checkMltComponents()
118 m_mltCheck.programList->setColumnCount(2);
119 m_mltCheck.programList->setRootIsDecorated(false);
120 m_mltCheck.programList->setHeaderHidden(true);
121 QSize itemSize(20, fontMetrics().height() * 2.5);
122 m_mltCheck.programList->setColumnWidth(0, 30);
123 m_mltCheck.programList->setIconSize(QSize(24, 24));
126 QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);
128 QTreeWidgetItem *inigoitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Inigo") + " (" + KdenliveSettings::rendererpath() + ')');
129 inigoitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
130 inigoitem->setSizeHint(0, itemSize);
131 inigoitem->setIcon(0, m_okIcon);
133 // Check MLT's installed producers
134 QProcess checkProcess;
135 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
136 if (!checkProcess.waitForStarted()) {
137 inigoitem->setIcon(0, m_badIcon);
138 inigoitem->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (inigo)"));
139 button(QWizard::NextButton)->setEnabled(false);
141 checkProcess.waitForFinished();
142 QByteArray result = checkProcess.readAllStandardError();
144 // Check MLT avformat module
145 QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
146 avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
147 avformatItem->setSizeHint(0, itemSize);
148 if (!result.contains("- avformat")) {
149 avformatItem->setIcon(0, m_badIcon);
150 m_mltCheck.tabWidget->setTabEnabled(1, false);
152 avformatItem->setIcon(0, m_okIcon);
153 // Make sure we have MLT > 0.3.4
154 bool recentMlt = false;
157 QString exepath = KStandardDirs::findExe("pkg-config");
158 if (!exepath.isEmpty()) {
159 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt-framework");
160 if (!checkProcess.waitForStarted()) {
161 kDebug() << "// Error querying MLT's version";
163 checkProcess.waitForFinished();
164 mltVersion = checkProcess.readAllStandardOutput();
165 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
166 kDebug() << "// FOUND MLT's pkgconfig version: " << version;
167 if (version > 34) recentMlt = true;
171 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
172 if (!checkProcess.waitForStarted()) {
173 kDebug() << "// Error querying MLT's version";
175 checkProcess.waitForFinished();
176 mltVersion = checkProcess.readAllStandardError();
177 mltVersion = mltVersion.section('\n', 0, 0).simplified();
178 mltVersion = mltVersion.section(' ', -1).simplified();
179 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
180 kDebug() << "// FOUND MLT version: " << version;
181 if (version > 34) recentMlt = true;
185 mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
186 mltitem->setSizeHint(0, itemSize);
187 if (version < recommendedMltVersion) {
188 mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to the latest MLT version"));
189 mltitem->setIcon(0, m_badIcon);
191 mltitem->setData(1, Qt::UserRole, i18n("MLT version is correct"));
192 mltitem->setIcon(0, m_okIcon);
196 // Check installed audio codecs
197 QProcess checkProcess2;
198 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
199 if (!checkProcess2.waitForStarted()) {
200 m_mltCheck.tabWidget->setTabEnabled(1, false);
201 kDebug() << "// Error parsing MLT's avformat codecs";
203 checkProcess2.waitForFinished();
204 QByteArray codecList = checkProcess2.readAllStandardError();
205 QString acodecList(codecList);
207 QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
208 for (int i = 0; i < alist.count(); i++) {
209 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
211 m_mltCheck.acodecs_list->addItems(result);
212 KdenliveSettings::setAudiocodecs(result);
213 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
215 // Check video codecs
216 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
217 if (!checkProcess2.waitForStarted()) {
218 kDebug() << "// Error parsing MLT's avformat codecs";
220 checkProcess2.waitForFinished();
221 QByteArray codecList = checkProcess2.readAllStandardError();
222 QString vcodecList(codecList);
224 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
225 for (int i = 0; i < vlist.count(); i++) {
226 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
228 m_mltCheck.vcodecs_list->addItems(result);
229 KdenliveSettings::setVideocodecs(result);
230 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
233 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
234 if (!checkProcess2.waitForStarted()) {
235 kDebug() << "// Error parsing MLT's avformat codecs";
237 checkProcess2.waitForFinished();
238 QByteArray codecList = checkProcess2.readAllStandardError();
239 QString vcodecList(codecList);
241 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
242 for (int i = 0; i < vlist.count(); i++) {
243 if (vlist.at(i).contains("- ")) {
244 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
245 if (format.contains(',')) {
246 QStringList sub = format.split(',', QString::SkipEmptyParts);
247 for (int j = 0; j < sub.count(); j++)
248 result.append(sub.at(j));
249 } else result.append(format);
252 m_mltCheck.formats_list->addItems(result);
253 KdenliveSettings::setSupportedformats(result);
254 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
260 // Check MLT dv module
261 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
262 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
263 dvItem->setSizeHint(0, itemSize);
264 if (!result.contains("- libdv")) {
265 dvItem->setIcon(0, m_badIcon);
267 dvItem->setIcon(0, m_okIcon);
270 // Check MLT image format module
271 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
272 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
273 imageItem->setSizeHint(0, itemSize);
274 if (!result.contains("- qimage")) {
275 imageItem->setIcon(0, m_badIcon);
276 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
277 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
278 imageItem->setSizeHint(0, itemSize);
279 if (!result.contains("- pixbuf")) imageItem->setIcon(0, m_badIcon);
280 else imageItem->setIcon(0, m_okIcon);
282 imageItem->setIcon(0, m_okIcon);
287 void Wizard::slotCheckPrograms()
289 m_check.programList->setColumnCount(2);
290 m_check.programList->setRootIsDecorated(false);
291 m_check.programList->setHeaderHidden(true);
292 QSize itemSize(20, fontMetrics().height() * 2.5);
293 m_check.programList->setColumnWidth(0, 30);
294 m_check.programList->setIconSize(QSize(24, 24));
296 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
297 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
298 item->setSizeHint(0, itemSize);
299 QString exepath = KStandardDirs::findExe("ffmpeg");
300 if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
301 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
302 else item->setIcon(0, m_okIcon);
304 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
305 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
306 item->setSizeHint(0, itemSize);
307 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
308 else item->setIcon(0, m_okIcon);
310 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
311 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
312 item->setSizeHint(0, itemSize);
313 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
314 else item->setIcon(0, m_okIcon);
316 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
317 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
318 item->setSizeHint(0, itemSize);
319 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
320 else item->setIcon(0, m_okIcon);
322 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
323 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
324 item->setSizeHint(0, itemSize);
325 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, m_badIcon);
326 else item->setIcon(0, m_okIcon);
330 void Wizard::installExtraMimes(QString baseName, QStringList globs)
332 QString mimefile = baseName;
333 mimefile.replace('/', '-');
334 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
336 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
338 QStringList extensions = mime->patterns();
339 QString comment = mime->comment();
340 foreach(const QString &glob, globs) {
341 if (!extensions.contains(glob)) extensions << glob;
343 kDebug() << "EXTS: " << extensions;
344 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
345 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
346 QFile packageFile(packageFileName);
347 if (!packageFile.open(QIODevice::WriteOnly)) {
348 kError() << "Couldn't open" << packageFileName << "for writing";
351 QXmlStreamWriter writer(&packageFile);
352 writer.setAutoFormatting(true);
353 writer.writeStartDocument();
355 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
356 writer.writeDefaultNamespace(nsUri);
357 writer.writeStartElement("mime-info");
358 writer.writeStartElement(nsUri, "mime-type");
359 writer.writeAttribute("type", baseName);
361 if (!comment.isEmpty()) {
362 writer.writeStartElement(nsUri, "comment");
363 writer.writeCharacters(comment);
364 writer.writeEndElement(); // comment
367 foreach(const QString& pattern, extensions) {
368 writer.writeStartElement(nsUri, "glob");
369 writer.writeAttribute("pattern", pattern);
370 writer.writeEndElement(); // glob
373 writer.writeEndElement(); // mime-info
374 writer.writeEndElement(); // mime-type
375 writer.writeEndDocument();
379 void Wizard::runUpdateMimeDatabase()
381 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
382 //Q_ASSERT(!localPackageDir.isEmpty());
384 proc << "update-mime-database";
385 proc << localPackageDir;
386 const int exitCode = proc.execute();
388 kWarning() << proc.program() << "exited with error code" << exitCode;
392 void Wizard::slotCheckThumbs()
394 QString pixname = "timeline_vthumbs.png";
395 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
396 pixname = "timeline_nothumbs.png";
397 } else if (m_extra.audiothumbs->isChecked()) {
398 if (m_extra.videothumbs->isChecked())
399 pixname = "timeline_avthumbs.png";
400 else pixname = "timeline_athumbs.png";
403 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
406 void Wizard::slotCheckStandard()
408 m_standard.profiles_list->clear();
409 QStringList profiles;
410 if (m_standard.button_dv->isChecked()) {
412 m_standard.profiles_list->addItems(m_dvProfiles);
413 } else if (m_standard.button_hdv->isChecked()) {
415 m_standard.profiles_list->addItems(m_hdvProfiles);
417 m_standard.profiles_list->addItems(m_dvProfiles);
418 m_standard.profiles_list->addItems(m_hdvProfiles);
419 m_standard.profiles_list->addItems(m_otherProfiles);
420 //m_standard.profiles_list->sortItems();
423 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
424 QListWidgetItem *item = m_standard.profiles_list->item(i);
425 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
426 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));
427 item->setToolTip(infoString);
430 m_standard.profiles_list->setSortingEnabled(true);
431 m_standard.profiles_list->setCurrentRow(0);
434 void Wizard::slotCheckSelectedItem()
436 // Make sure we always have an item highlighted
437 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
441 void Wizard::adjustSettings()
443 if (m_extra.installmimes->isChecked()) {
445 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
446 installExtraMimes("video/mpeg", globs);
449 installExtraMimes("video/dv", globs);
450 runUpdateMimeDatabase();
452 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
453 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
454 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
455 if (m_standard.profiles_list->currentItem()) {
456 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
457 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
458 KdenliveSettings::setDefault_profile(selectedProfile);
460 QString path = m_extra.projectfolder->url().path();
461 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
462 KdenliveSettings::setDefaultprojectfolder(path);
466 void Wizard::slotCheckMlt()
468 QString errorMessage;
469 if (KdenliveSettings::rendererpath().isEmpty()) {
470 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
472 /*QProcess checkProcess;
473 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
474 if (!checkProcess.waitForStarted())
475 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
477 checkProcess.waitForFinished();
479 QByteArray result = checkProcess.readAllStandardError();
480 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");*/
482 QProcess checkProcess2;
483 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
484 if (!checkProcess2.waitForStarted())
485 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + '\n');
487 checkProcess2.waitForFinished();
489 QByteArray result = checkProcess2.readAllStandardError();
490 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');
492 if (!errorMessage.isEmpty()) {
493 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
494 QLabel *pix = new QLabel();
495 pix->setPixmap(KIcon("dialog-error").pixmap(30));
496 QLabel *label = new QLabel(errorMessage);
497 label->setWordWrap(true);
498 m_startLayout->addSpacing(40);
499 m_startLayout->addWidget(pix);
500 m_startLayout->addWidget(label);
501 m_systemCheckIsOk = false;
502 button(QWizard::NextButton)->setEnabled(false);
503 } else m_systemCheckIsOk = true;
505 if (m_systemCheckIsOk) checkMltComponents();
509 bool Wizard::isOk() const
511 return m_systemCheckIsOk;
514 #include "wizard.moc"