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) {
37 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
39 QWizardPage *page1 = new QWizardPage;
40 page1->setTitle(i18n("Welcome"));
43 label = new QLabel(i18n("Your Kdenlive version was upgraded. Please take some time to review the basic settings"));
45 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..."));
46 label->setWordWrap(true);
47 m_startLayout = new QVBoxLayout;
48 m_startLayout->addWidget(label);
49 page1->setLayout(m_startLayout);
52 QWizardPage *page4 = new QWizardPage;
53 page4->setTitle(i18n("Checking MLT engine"));
54 m_mltCheck.setupUi(page4);
57 WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
58 m_mltCheck.programList->setItemDelegate(listViewDelegate);
60 QWizardPage *page2 = new QWizardPage;
61 page2->setTitle(i18n("Video Standard"));
62 m_standard.setupUi(page2);
64 m_okIcon = KIcon("dialog-ok");
65 m_badIcon = KIcon("dialog-close");
67 // build profiles lists
68 m_profilesInfo = ProfilesDialog::getProfilesInfo();
69 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
70 while (i != m_profilesInfo.constEnd()) {
71 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
72 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
73 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
74 else m_otherProfiles.append(i.key());
78 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
79 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
80 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
81 m_standard.button_all->setChecked(true);
82 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
84 // select default profile
85 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
86 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
89 QWizardPage *page3 = new QWizardPage;
90 page3->setTitle(i18n("Additional Settings"));
91 m_extra.setupUi(page3);
92 m_extra.projectfolder->setMode(KFile::Directory);
93 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
94 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
95 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
96 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
97 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
98 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
103 QWizardPage *page5 = new QWizardPage;
104 page5->setTitle(i18n("Checking system"));
105 m_check.setupUi(page5);
108 listViewDelegate = new WizardDelegate(m_check.programList);
109 m_check.programList->setItemDelegate(listViewDelegate);
111 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
115 void Wizard::checkMltComponents() {
116 m_mltCheck.programList->setColumnCount(2);
117 m_mltCheck.programList->setRootIsDecorated(false);
118 m_mltCheck.programList->setHeaderHidden(true);
119 QSize itemSize(20, fontMetrics().height() * 2.5);
120 m_mltCheck.programList->setColumnWidth(0, 30);
121 m_mltCheck.programList->setIconSize(QSize(24, 24));
124 QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);
126 QTreeWidgetItem *inigoitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Inigo") + " (" + KdenliveSettings::rendererpath() + ')');
127 inigoitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
128 inigoitem->setSizeHint(0, itemSize);
129 inigoitem->setIcon(0, m_okIcon);
131 // Check MLT's installed producers
132 QProcess checkProcess;
133 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
134 if (!checkProcess.waitForStarted()) {
135 inigoitem->setIcon(0, m_badIcon);
136 inigoitem->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (inigo)"));
137 button(QWizard::NextButton)->setEnabled(false);
139 checkProcess.waitForFinished();
140 QByteArray result = checkProcess.readAllStandardError();
142 // Check MLT avformat module
143 QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
144 avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
145 avformatItem->setSizeHint(0, itemSize);
146 if (!result.contains("- avformat")) {
147 avformatItem->setIcon(0, m_badIcon);
148 m_mltCheck.tabWidget->setTabEnabled(1, false);
150 avformatItem->setIcon(0, m_okIcon);
151 // Make sure we have MLT > 0.3.4
152 bool recentMlt = false;
155 QString exepath = KStandardDirs::findExe("pkg-config");
156 if (!exepath.isEmpty()) {
157 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt-framework");
158 if (!checkProcess.waitForStarted()) {
159 kDebug() << "// Error querying MLT's version";
161 checkProcess.waitForFinished();
162 mltVersion = checkProcess.readAllStandardOutput();
163 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
164 kDebug() << "// FOUND MLT's pkgconfig version: " << version;
165 if (version > 34) recentMlt = true;
169 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
170 if (!checkProcess.waitForStarted()) {
171 kDebug() << "// Error querying MLT's version";
173 checkProcess.waitForFinished();
174 mltVersion = checkProcess.readAllStandardError();
175 mltVersion = mltVersion.section('\n', 0, 0).simplified();
176 mltVersion = mltVersion.section(' ', -1).simplified();
177 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
178 kDebug() << "// FOUND MLT version: " << version;
179 if (version > 34) recentMlt = true;
183 mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
184 mltitem->setSizeHint(0, itemSize);
185 if (version < recommendedMltVersion) {
186 mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to the latest MLT version"));
187 mltitem->setIcon(0, m_badIcon);
189 mltitem->setData(1, Qt::UserRole, i18n("MLT version is correct"));
190 mltitem->setIcon(0, m_okIcon);
194 // Check installed audio codecs
195 QProcess checkProcess2;
196 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
197 if (!checkProcess2.waitForStarted()) {
198 m_mltCheck.tabWidget->setTabEnabled(1, false);
199 kDebug() << "// Error parsing MLT's avformat codecs";
201 checkProcess2.waitForFinished();
202 QByteArray codecList = checkProcess2.readAllStandardError();
203 QString acodecList(codecList);
205 QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
206 for (int i = 0; i < alist.count(); i++) {
207 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
209 m_mltCheck.acodecs_list->addItems(result);
210 KdenliveSettings::setAudiocodecs(result);
211 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
213 // Check video codecs
214 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
215 if (!checkProcess2.waitForStarted()) {
216 kDebug() << "// Error parsing MLT's avformat codecs";
218 checkProcess2.waitForFinished();
219 QByteArray codecList = checkProcess2.readAllStandardError();
220 QString vcodecList(codecList);
222 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
223 for (int i = 0; i < vlist.count(); i++) {
224 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
226 m_mltCheck.vcodecs_list->addItems(result);
227 KdenliveSettings::setVideocodecs(result);
228 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
231 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
232 if (!checkProcess2.waitForStarted()) {
233 kDebug() << "// Error parsing MLT's avformat codecs";
235 checkProcess2.waitForFinished();
236 QByteArray codecList = checkProcess2.readAllStandardError();
237 QString vcodecList(codecList);
239 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
240 for (int i = 0; i < vlist.count(); i++) {
241 if (vlist.at(i).contains("- ")) {
242 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
243 if (format.contains(',')) {
244 QStringList sub = format.split(',', QString::SkipEmptyParts);
245 for (int j = 0; j < sub.count(); j++)
246 result.append(sub.at(j));
247 } else result.append(format);
250 m_mltCheck.formats_list->addItems(result);
251 KdenliveSettings::setSupportedformats(result);
252 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
258 // Check MLT dv module
259 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
260 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
261 dvItem->setSizeHint(0, itemSize);
262 if (!result.contains("- libdv")) {
263 dvItem->setIcon(0, m_badIcon);
265 dvItem->setIcon(0, m_okIcon);
268 // Check MLT image format module
269 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
270 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
271 imageItem->setSizeHint(0, itemSize);
272 if (!result.contains("- qimage")) {
273 imageItem->setIcon(0, m_badIcon);
274 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
275 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
276 imageItem->setSizeHint(0, itemSize);
277 if (!result.contains("- pixbuf")) imageItem->setIcon(0, m_badIcon);
278 else imageItem->setIcon(0, m_okIcon);
280 imageItem->setIcon(0, m_okIcon);
285 void Wizard::slotCheckPrograms() {
286 m_check.programList->setColumnCount(2);
287 m_check.programList->setRootIsDecorated(false);
288 m_check.programList->setHeaderHidden(true);
289 QSize itemSize(20, fontMetrics().height() * 2.5);
290 m_check.programList->setColumnWidth(0, 30);
291 m_check.programList->setIconSize(QSize(24, 24));
293 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
294 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
295 item->setSizeHint(0, itemSize);
296 QString exepath = KStandardDirs::findExe("ffmpeg");
297 if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
298 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
299 else item->setIcon(0, m_okIcon);
301 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
302 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
303 item->setSizeHint(0, itemSize);
304 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
305 else item->setIcon(0, m_okIcon);
307 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
308 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
309 item->setSizeHint(0, itemSize);
310 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
311 else item->setIcon(0, m_okIcon);
313 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
314 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
315 item->setSizeHint(0, itemSize);
316 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
317 else item->setIcon(0, m_okIcon);
319 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
320 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
321 item->setSizeHint(0, itemSize);
322 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, m_badIcon);
323 else item->setIcon(0, m_okIcon);
327 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
328 QString mimefile = baseName;
329 mimefile.replace('/', '-');
330 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
332 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
334 QStringList extensions = mime->patterns();
335 QString comment = mime->comment();
336 foreach(const QString &glob, globs) {
337 if (!extensions.contains(glob)) extensions << glob;
339 kDebug() << "EXTS: " << extensions;
340 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
341 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
342 QFile packageFile(packageFileName);
343 if (!packageFile.open(QIODevice::WriteOnly)) {
344 kError() << "Couldn't open" << packageFileName << "for writing";
347 QXmlStreamWriter writer(&packageFile);
348 writer.setAutoFormatting(true);
349 writer.writeStartDocument();
351 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
352 writer.writeDefaultNamespace(nsUri);
353 writer.writeStartElement("mime-info");
354 writer.writeStartElement(nsUri, "mime-type");
355 writer.writeAttribute("type", baseName);
357 if (!comment.isEmpty()) {
358 writer.writeStartElement(nsUri, "comment");
359 writer.writeCharacters(comment);
360 writer.writeEndElement(); // comment
363 foreach(const QString& pattern, extensions) {
364 writer.writeStartElement(nsUri, "glob");
365 writer.writeAttribute("pattern", pattern);
366 writer.writeEndElement(); // glob
369 writer.writeEndElement(); // mime-info
370 writer.writeEndElement(); // mime-type
371 writer.writeEndDocument();
375 void Wizard::runUpdateMimeDatabase() {
376 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
377 //Q_ASSERT(!localPackageDir.isEmpty());
379 proc << "update-mime-database";
380 proc << localPackageDir;
381 const int exitCode = proc.execute();
383 kWarning() << proc.program() << "exited with error code" << exitCode;
387 void Wizard::slotCheckThumbs() {
388 QString pixname = "timeline_vthumbs.png";
389 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
390 pixname = "timeline_nothumbs.png";
391 } else if (m_extra.audiothumbs->isChecked()) {
392 if (m_extra.videothumbs->isChecked())
393 pixname = "timeline_avthumbs.png";
394 else pixname = "timeline_athumbs.png";
397 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
400 void Wizard::slotCheckStandard() {
401 m_standard.profiles_list->clear();
402 QStringList profiles;
403 if (m_standard.button_dv->isChecked()) {
405 m_standard.profiles_list->addItems(m_dvProfiles);
406 } else if (m_standard.button_hdv->isChecked()) {
408 m_standard.profiles_list->addItems(m_hdvProfiles);
410 m_standard.profiles_list->addItems(m_dvProfiles);
411 m_standard.profiles_list->addItems(m_hdvProfiles);
412 m_standard.profiles_list->addItems(m_otherProfiles);
413 //m_standard.profiles_list->sortItems();
416 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
417 QListWidgetItem *item = m_standard.profiles_list->item(i);
418 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
419 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));
420 item->setToolTip(infoString);
423 m_standard.profiles_list->setSortingEnabled(true);
424 m_standard.profiles_list->setCurrentRow(0);
427 void Wizard::slotCheckSelectedItem() {
428 // Make sure we always have an item highlighted
429 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
433 void Wizard::adjustSettings() {
434 if (m_extra.installmimes->isChecked()) {
436 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
437 installExtraMimes("video/mpeg", globs);
440 installExtraMimes("video/dv", globs);
441 runUpdateMimeDatabase();
443 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
444 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
445 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
446 if (m_standard.profiles_list->currentItem()) {
447 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
448 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
449 KdenliveSettings::setDefault_profile(selectedProfile);
451 QString path = m_extra.projectfolder->url().path();
452 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
453 KdenliveSettings::setDefaultprojectfolder(path);
457 void Wizard::slotCheckMlt() {
458 QString errorMessage;
459 if (KdenliveSettings::rendererpath().isEmpty()) {
460 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
462 /*QProcess checkProcess;
463 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
464 if (!checkProcess.waitForStarted())
465 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
467 checkProcess.waitForFinished();
469 QByteArray result = checkProcess.readAllStandardError();
470 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");*/
472 QProcess checkProcess2;
473 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
474 if (!checkProcess2.waitForStarted())
475 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + '\n');
477 checkProcess2.waitForFinished();
479 QByteArray result = checkProcess2.readAllStandardError();
480 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');
482 if (!errorMessage.isEmpty()) {
483 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
484 QLabel *pix = new QLabel();
485 pix->setPixmap(KIcon("dialog-error").pixmap(30));
486 QLabel *label = new QLabel(errorMessage);
487 label->setWordWrap(true);
488 m_startLayout->addSpacing(40);
489 m_startLayout->addWidget(pix);
490 m_startLayout->addWidget(label);
491 m_systemCheckIsOk = false;
492 button(QWizard::NextButton)->setEnabled(false);
493 } else m_systemCheckIsOk = true;
495 if (m_systemCheckIsOk) checkMltComponents();
499 bool Wizard::isOk() const {
500 return m_systemCheckIsOk;
503 #include "wizard.moc"