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(QWidget *parent): QWizard(parent) {
37 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
39 QWizardPage *page1 = new QWizardPage;
40 page1->setTitle(i18n("Welcome"));
41 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..."));
42 label->setWordWrap(true);
43 m_startLayout = new QVBoxLayout;
44 m_startLayout->addWidget(label);
45 page1->setLayout(m_startLayout);
48 QWizardPage *page4 = new QWizardPage;
49 page4->setTitle(i18n("Checking MLT engine"));
50 m_mltCheck.setupUi(page4);
53 WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
54 m_mltCheck.programList->setItemDelegate(listViewDelegate);
56 QWizardPage *page2 = new QWizardPage;
57 page2->setTitle(i18n("Video Standard"));
58 m_standard.setupUi(page2);
60 m_okIcon = KIcon("dialog-ok");
61 m_badIcon = KIcon("dialog-close");
63 // build profiles lists
64 m_profilesInfo = ProfilesDialog::getProfilesInfo();
65 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
66 while (i != m_profilesInfo.constEnd()) {
67 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
68 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
69 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
70 else m_otherProfiles.append(i.key());
74 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
75 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
76 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
77 m_standard.button_all->setChecked(true);
78 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
80 // select default profile
81 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
82 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
85 QWizardPage *page3 = new QWizardPage;
86 page3->setTitle(i18n("Additional Settings"));
87 m_extra.setupUi(page3);
88 m_extra.projectfolder->setMode(KFile::Directory);
89 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
90 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
91 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
92 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
93 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
94 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
99 QWizardPage *page5 = new QWizardPage;
100 page5->setTitle(i18n("Checking system"));
101 m_check.setupUi(page5);
105 listViewDelegate = new WizardDelegate(m_check.programList);
106 m_check.programList->setItemDelegate(listViewDelegate);
108 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
112 void Wizard::checkMltComponents() {
113 m_mltCheck.programList->setColumnCount(2);
114 m_mltCheck.programList->setRootIsDecorated(false);
115 m_mltCheck.programList->setHeaderHidden(true);
116 QSize itemSize(20, this->fontMetrics().height() * 2.5);
117 m_mltCheck.programList->setColumnWidth(0, 30);
118 m_mltCheck.programList->setIconSize(QSize(24, 24));
121 QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);
123 QTreeWidgetItem *inigoitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Inigo") + " (" + KdenliveSettings::rendererpath() + ')');
124 inigoitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
125 inigoitem->setSizeHint(0, itemSize);
126 inigoitem->setIcon(0, m_okIcon);
128 // Check MLT's installed producers
129 QProcess checkProcess;
130 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
131 if (!checkProcess.waitForStarted()) {
132 inigoitem->setIcon(0, m_badIcon);
133 inigoitem->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (inigo)"));
134 button(QWizard::NextButton)->setEnabled(false);
136 checkProcess.waitForFinished();
137 QByteArray result = checkProcess.readAllStandardError();
139 // Check MLT avformat module
140 QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
141 avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
142 avformatItem->setSizeHint(0, itemSize);
143 if (!result.contains("- avformat")) {
144 avformatItem->setIcon(0, m_badIcon);
145 m_mltCheck.tabWidget->setTabEnabled(1, false);
147 avformatItem->setIcon(0, m_okIcon);
148 // Make sure we have MLT > 0.3.4
149 bool recentMlt = false;
152 QString exepath = KStandardDirs::findExe("pkg-config");
153 if (!exepath.isEmpty()) {
154 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt-framework");
155 if (!checkProcess.waitForStarted()) {
156 kDebug() << "// Error querying MLT's version";
158 checkProcess.waitForFinished();
159 mltVersion = checkProcess.readAllStandardOutput();
160 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
161 kDebug() << "// FOUND MLT's pkgconfig version: " << version;
162 if (version > 34) recentMlt = true;
166 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
167 if (!checkProcess.waitForStarted()) {
168 kDebug() << "// Error querying MLT's version";
170 checkProcess.waitForFinished();
171 mltVersion = checkProcess.readAllStandardError();
172 mltVersion = mltVersion.section('\n', 0, 0).simplified();
173 mltVersion = mltVersion.section(' ', -1).simplified();
174 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
175 kDebug() << "// FOUND MLT version: " << version;
176 if (version > 34) recentMlt = true;
180 mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
181 mltitem->setSizeHint(0, itemSize);
182 if (version < recommendedMltVersion) {
183 mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to the latest MLT version"));
184 mltitem->setIcon(0, m_badIcon);
186 mltitem->setData(1, Qt::UserRole, i18n("MLT version is correct"));
187 mltitem->setIcon(0, m_okIcon);
191 // Check installed audio codecs
192 QProcess checkProcess2;
193 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
194 if (!checkProcess2.waitForStarted()) {
195 m_mltCheck.tabWidget->setTabEnabled(1, false);
196 kDebug() << "// Error parsing MLT's avformat codecs";
198 checkProcess2.waitForFinished();
199 QByteArray codecList = checkProcess2.readAllStandardError();
200 QString acodecList(codecList);
202 QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
203 for (int i = 0; i < alist.count(); i++) {
204 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
206 m_mltCheck.acodecs_list->addItems(result);
207 KdenliveSettings::setAudiocodecs(result);
208 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
210 // Check video codecs
211 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
212 if (!checkProcess2.waitForStarted()) {
213 kDebug() << "// Error parsing MLT's avformat codecs";
215 checkProcess2.waitForFinished();
216 QByteArray codecList = checkProcess2.readAllStandardError();
217 QString vcodecList(codecList);
219 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
220 for (int i = 0; i < vlist.count(); i++) {
221 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
223 m_mltCheck.vcodecs_list->addItems(result);
224 KdenliveSettings::setVideocodecs(result);
225 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
228 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
229 if (!checkProcess2.waitForStarted()) {
230 kDebug() << "// Error parsing MLT's avformat codecs";
232 checkProcess2.waitForFinished();
233 QByteArray codecList = checkProcess2.readAllStandardError();
234 QString vcodecList(codecList);
236 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
237 for (int i = 0; i < vlist.count(); i++) {
238 if (vlist.at(i).contains("- ")) {
239 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
240 if (format.contains(',')) {
241 QStringList sub = format.split(',', QString::SkipEmptyParts);
242 for (int j = 0; j < sub.count(); j++)
243 result.append(sub.at(j));
244 } else result.append(format);
247 m_mltCheck.formats_list->addItems(result);
248 KdenliveSettings::setSupportedformats(result);
249 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
255 // Check MLT dv module
256 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
257 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
258 dvItem->setSizeHint(0, itemSize);
259 if (!result.contains("- libdv")) {
260 dvItem->setIcon(0, m_badIcon);
262 dvItem->setIcon(0, m_okIcon);
265 // Check MLT image format module
266 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
267 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
268 imageItem->setSizeHint(0, itemSize);
269 if (!result.contains("- qimage")) {
270 imageItem->setIcon(0, m_badIcon);
271 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
272 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
273 imageItem->setSizeHint(0, itemSize);
274 if (!result.contains("- pixbuf")) imageItem->setIcon(0, m_badIcon);
275 else imageItem->setIcon(0, m_okIcon);
277 imageItem->setIcon(0, m_okIcon);
282 void Wizard::slotCheckPrograms() {
283 m_check.programList->setColumnCount(2);
284 m_check.programList->setRootIsDecorated(false);
285 m_check.programList->setHeaderHidden(true);
286 QSize itemSize(20, this->fontMetrics().height() * 2.5);
287 m_check.programList->setColumnWidth(0, 30);
288 m_check.programList->setIconSize(QSize(24, 24));
290 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
291 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
292 item->setSizeHint(0, itemSize);
293 QString exepath = KStandardDirs::findExe("ffmpeg");
294 if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
295 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
296 else item->setIcon(0, m_okIcon);
298 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
299 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
300 item->setSizeHint(0, itemSize);
301 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
302 else item->setIcon(0, m_okIcon);
304 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
305 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
306 item->setSizeHint(0, itemSize);
307 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
308 else item->setIcon(0, m_okIcon);
310 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
311 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
312 item->setSizeHint(0, itemSize);
313 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
314 else item->setIcon(0, m_okIcon);
316 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
317 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD iso images"));
318 item->setSizeHint(0, itemSize);
319 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, m_badIcon);
320 else item->setIcon(0, m_okIcon);
324 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
325 QString mimefile = baseName;
326 mimefile.replace('/', '-');
327 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
329 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
331 QStringList extensions = mime->patterns();
332 QString comment = mime->comment();
333 foreach(const QString &glob, globs) {
334 if (!extensions.contains(glob)) extensions << glob;
336 kDebug() << "EXTS: " << extensions;
337 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
338 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
339 QFile packageFile(packageFileName);
340 if (!packageFile.open(QIODevice::WriteOnly)) {
341 kError() << "Couldn't open" << packageFileName << "for writing";
344 QXmlStreamWriter writer(&packageFile);
345 writer.setAutoFormatting(true);
346 writer.writeStartDocument();
348 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
349 writer.writeDefaultNamespace(nsUri);
350 writer.writeStartElement("mime-info");
351 writer.writeStartElement(nsUri, "mime-type");
352 writer.writeAttribute("type", baseName);
354 if (!comment.isEmpty()) {
355 writer.writeStartElement(nsUri, "comment");
356 writer.writeCharacters(comment);
357 writer.writeEndElement(); // comment
360 foreach(const QString& pattern, extensions) {
361 writer.writeStartElement(nsUri, "glob");
362 writer.writeAttribute("pattern", pattern);
363 writer.writeEndElement(); // glob
366 writer.writeEndElement(); // mime-info
367 writer.writeEndElement(); // mime-type
368 writer.writeEndDocument();
372 void Wizard::runUpdateMimeDatabase() {
373 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
374 //Q_ASSERT(!localPackageDir.isEmpty());
376 proc << "update-mime-database";
377 proc << localPackageDir;
378 const int exitCode = proc.execute();
380 kWarning() << proc.program() << "exited with error code" << exitCode;
384 void Wizard::slotCheckThumbs() {
385 QString pixname = "timeline_vthumbs.png";
386 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
387 pixname = "timeline_nothumbs.png";
388 } else if (m_extra.audiothumbs->isChecked()) {
389 if (m_extra.videothumbs->isChecked())
390 pixname = "timeline_avthumbs.png";
391 else pixname = "timeline_athumbs.png";
394 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
397 void Wizard::slotCheckStandard() {
398 m_standard.profiles_list->clear();
399 QStringList profiles;
400 if (m_standard.button_dv->isChecked()) {
402 m_standard.profiles_list->addItems(m_dvProfiles);
403 } else if (m_standard.button_hdv->isChecked()) {
405 m_standard.profiles_list->addItems(m_hdvProfiles);
407 m_standard.profiles_list->addItems(m_dvProfiles);
408 m_standard.profiles_list->addItems(m_hdvProfiles);
409 m_standard.profiles_list->addItems(m_otherProfiles);
410 //m_standard.profiles_list->sortItems();
413 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
414 QListWidgetItem *item = m_standard.profiles_list->item(i);
415 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
416 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));
417 item->setToolTip(infoString);
420 m_standard.profiles_list->setSortingEnabled(true);
421 m_standard.profiles_list->setCurrentRow(0);
424 void Wizard::slotCheckSelectedItem() {
425 // Make sure we always have an item highlighted
426 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
430 void Wizard::adjustSettings() {
431 if (m_extra.installmimes->isChecked()) {
433 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
434 installExtraMimes("video/mpeg", globs);
437 installExtraMimes("video/dv", globs);
438 runUpdateMimeDatabase();
440 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
441 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
442 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
443 if (m_standard.profiles_list->currentItem()) {
444 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
445 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
446 KdenliveSettings::setDefault_profile(selectedProfile);
448 QString path = m_extra.projectfolder->url().path();
449 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
450 KdenliveSettings::setDefaultprojectfolder(path);
454 void Wizard::slotCheckMlt() {
455 QString errorMessage;
456 if (KdenliveSettings::rendererpath().isEmpty()) {
457 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
459 /*QProcess checkProcess;
460 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
461 if (!checkProcess.waitForStarted())
462 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
464 checkProcess.waitForFinished();
466 QByteArray result = checkProcess.readAllStandardError();
467 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");*/
469 QProcess checkProcess2;
470 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
471 if (!checkProcess2.waitForStarted())
472 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + '\n');
474 checkProcess2.waitForFinished();
476 QByteArray result = checkProcess2.readAllStandardError();
477 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');
479 if (!errorMessage.isEmpty()) {
480 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
481 QLabel *pix = new QLabel();
482 pix->setPixmap(KIcon("dialog-error").pixmap(30));
483 QLabel *label = new QLabel(errorMessage);
484 label->setWordWrap(true);
485 m_startLayout->addSpacing(40);
486 m_startLayout->addWidget(pix);
487 m_startLayout->addWidget(label);
488 m_systemCheckIsOk = false;
489 button(QWizard::NextButton)->setEnabled(false);
490 } else m_systemCheckIsOk = true;
492 if (m_systemCheckIsOk) checkMltComponents();
495 bool Wizard::isOk() const {
496 return m_systemCheckIsOk;
499 #include "wizard.moc"