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 *page4 = new QWizardPage;
48 page4->setTitle(i18n("Checking MLT engine"));
49 m_mltCheck.setupUi(page4);
52 WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
53 m_mltCheck.programList->setItemDelegate(listViewDelegate);
55 QWizardPage *page2 = new QWizardPage;
56 page2->setTitle(i18n("Video Standard"));
57 m_standard.setupUi(page2);
59 // build profiles lists
60 m_profilesInfo = ProfilesDialog::getProfilesInfo();
61 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
62 while (i != m_profilesInfo.constEnd()) {
63 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
64 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
65 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
66 else m_otherProfiles.append(i.key());
70 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
71 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
72 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
73 m_standard.button_all->setChecked(true);
74 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
76 // select default profile
77 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
78 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
81 QWizardPage *page3 = new QWizardPage;
82 page3->setTitle(i18n("Additional Settings"));
83 m_extra.setupUi(page3);
84 m_extra.projectfolder->setMode(KFile::Directory);
85 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
86 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
87 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
88 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
89 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
90 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
95 QWizardPage *page5 = new QWizardPage;
96 page5->setTitle(i18n("Checking system"));
97 m_check.setupUi(page5);
101 listViewDelegate = new WizardDelegate(m_check.programList);
102 m_check.programList->setItemDelegate(listViewDelegate);
104 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
108 void Wizard::checkMltComponents() {
109 m_mltCheck.programList->setColumnCount(2);
110 m_mltCheck.programList->setRootIsDecorated(false);
111 m_mltCheck.programList->setHeaderHidden(true);
112 QSize itemSize(20, this->fontMetrics().height() * 2.5);
113 KIcon okIcon("dialog-ok");
114 KIcon missingIcon("dialog-close");
115 m_mltCheck.programList->setColumnWidth(0, 30);
116 m_mltCheck.programList->setIconSize(QSize(24, 24));
119 QTreeWidgetItem *item = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Inigo") + " (" + KdenliveSettings::rendererpath() + ')');
120 item->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
121 item->setSizeHint(0, itemSize);
122 item->setIcon(0, okIcon);
124 // Check MLT's installed producers
125 QProcess checkProcess;
126 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
127 if (!checkProcess.waitForStarted()) {
128 item->setIcon(0, missingIcon);
129 item->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (inigo)"));
130 button(QWizard::NextButton)->setEnabled(false);
132 checkProcess.waitForFinished();
133 QByteArray result = checkProcess.readAllStandardError();
135 // Check MLT avformat module
136 QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
137 avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
138 avformatItem->setSizeHint(0, itemSize);
139 if (!result.contains("- avformat")) {
140 avformatItem->setIcon(0, missingIcon);
141 m_mltCheck.tabWidget->setTabEnabled(1, false);
143 avformatItem->setIcon(0, okIcon);
144 // Make sure we have MLT > 0.3.4
145 bool recentMlt = false;
147 QString exepath = KStandardDirs::findExe("pkg-config");
148 if (!exepath.isEmpty()) {
149 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt-framework");
150 if (!checkProcess.waitForStarted()) {
151 kDebug() << "// Error querying MLT's version";
153 checkProcess.waitForFinished();
154 QString mltVersion = checkProcess.readAllStandardOutput();
155 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
156 kDebug() << "// FOUND MLT's pkgconfig version: " << version;
157 if (version > 34) recentMlt = true;
161 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
162 if (!checkProcess.waitForStarted()) {
163 kDebug() << "// Error querying MLT's version";
165 checkProcess.waitForFinished();
166 QString mltVersion = checkProcess.readAllStandardError();
167 mltVersion = mltVersion.section("\n", 0, 0).simplified();
168 mltVersion = mltVersion.section(' ', -1).simplified();
169 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
170 kDebug() << "// FOUND MLT version: " << version;
171 if (version > 34) recentMlt = true;
176 // Check installed audio codecs
177 QProcess checkProcess2;
178 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
179 if (!checkProcess2.waitForStarted()) {
180 m_mltCheck.tabWidget->setTabEnabled(1, false);
181 kDebug() << "// Error parsing MLT's avformat codecs";
183 checkProcess2.waitForFinished();
184 QByteArray codecList = checkProcess2.readAllStandardError();
185 QString acodecList(codecList);
187 QStringList alist = acodecList.split("\n", QString::SkipEmptyParts);
188 for (int i = 0; i < alist.count(); i++) {
189 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
191 m_mltCheck.acodecs_list->addItems(result);
192 KdenliveSettings::setAudiocodecs(result);
193 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
195 // Check video codecs
196 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
197 if (!checkProcess2.waitForStarted()) {
198 kDebug() << "// Error parsing MLT's avformat codecs";
200 checkProcess2.waitForFinished();
201 QByteArray codecList = checkProcess2.readAllStandardError();
202 QString vcodecList(codecList);
204 QStringList vlist = vcodecList.split("\n", QString::SkipEmptyParts);
205 for (int i = 0; i < vlist.count(); i++) {
206 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
208 m_mltCheck.vcodecs_list->addItems(result);
209 KdenliveSettings::setVideocodecs(result);
210 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
213 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
214 if (!checkProcess2.waitForStarted()) {
215 kDebug() << "// Error parsing MLT's avformat codecs";
217 checkProcess2.waitForFinished();
218 QByteArray codecList = checkProcess2.readAllStandardError();
219 QString vcodecList(codecList);
221 QStringList vlist = vcodecList.split("\n", QString::SkipEmptyParts);
222 for (int i = 0; i < vlist.count(); i++) {
223 if (vlist.at(i).contains("- ")) {
224 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
225 if (format.contains(',')) {
226 QStringList sub = format.split(',', QString::SkipEmptyParts);
227 for (int j = 0; j < sub.count(); j++)
228 result.append(sub.at(j));
229 } else result.append(format);
232 m_mltCheck.formats_list->addItems(result);
233 KdenliveSettings::setSupportedformats(result);
234 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
240 // Check MLT dv module
241 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
242 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
243 dvItem->setSizeHint(0, itemSize);
244 if (!result.contains("- libdv")) {
245 dvItem->setIcon(0, missingIcon);
247 dvItem->setIcon(0, okIcon);
250 // Check MLT image format module
251 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
252 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
253 imageItem->setSizeHint(0, itemSize);
254 if (!result.contains("- qimage")) {
255 imageItem->setIcon(0, missingIcon);
256 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
257 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
258 imageItem->setSizeHint(0, itemSize);
259 if (!result.contains("- pixbuf")) imageItem->setIcon(0, missingIcon);
260 else imageItem->setIcon(0, okIcon);
262 imageItem->setIcon(0, okIcon);
267 void Wizard::slotCheckPrograms() {
268 m_check.programList->setColumnCount(2);
269 m_check.programList->setRootIsDecorated(false);
270 m_check.programList->setHeaderHidden(true);
271 QSize itemSize(20, this->fontMetrics().height() * 2.5);
272 KIcon okIcon("dialog-ok");
273 KIcon missingIcon("dialog-close");
274 m_check.programList->setColumnWidth(0, 30);
275 m_check.programList->setIconSize(QSize(24, 24));
277 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
278 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
279 item->setSizeHint(0, itemSize);
280 QString exepath = KStandardDirs::findExe("ffmpeg");
281 if (exepath.isEmpty()) item->setIcon(0, missingIcon);
282 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, missingIcon);
283 else item->setIcon(0, okIcon);
285 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
286 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
287 item->setSizeHint(0, itemSize);
288 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, missingIcon);
289 else item->setIcon(0, okIcon);
291 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
292 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
293 item->setSizeHint(0, itemSize);
294 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, missingIcon);
295 else item->setIcon(0, okIcon);
297 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
298 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
299 item->setSizeHint(0, itemSize);
300 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, missingIcon);
301 else item->setIcon(0, okIcon);
303 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
304 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD iso images"));
305 item->setSizeHint(0, itemSize);
306 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, missingIcon);
307 else item->setIcon(0, okIcon);
311 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
312 QString mimefile = baseName;
313 mimefile.replace('/', '-');
314 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
316 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
318 QStringList extensions = mime->patterns();
319 QString comment = mime->comment();
320 foreach(const QString &glob, globs) {
321 if (!extensions.contains(glob)) extensions << glob;
323 kDebug() << "EXTS: " << extensions;
324 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
325 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
326 QFile packageFile(packageFileName);
327 if (!packageFile.open(QIODevice::WriteOnly)) {
328 kError() << "Couldn't open" << packageFileName << "for writing";
331 QXmlStreamWriter writer(&packageFile);
332 writer.setAutoFormatting(true);
333 writer.writeStartDocument();
335 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
336 writer.writeDefaultNamespace(nsUri);
337 writer.writeStartElement("mime-info");
338 writer.writeStartElement(nsUri, "mime-type");
339 writer.writeAttribute("type", baseName);
341 if (!comment.isEmpty()) {
342 writer.writeStartElement(nsUri, "comment");
343 writer.writeCharacters(comment);
344 writer.writeEndElement(); // comment
347 foreach(const QString& pattern, extensions) {
348 writer.writeStartElement(nsUri, "glob");
349 writer.writeAttribute("pattern", pattern);
350 writer.writeEndElement(); // glob
353 writer.writeEndElement(); // mime-info
354 writer.writeEndElement(); // mime-type
355 writer.writeEndDocument();
359 void Wizard::runUpdateMimeDatabase() {
360 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
361 //Q_ASSERT(!localPackageDir.isEmpty());
363 proc << "update-mime-database";
364 proc << localPackageDir;
365 const int exitCode = proc.execute();
367 kWarning() << proc.program() << "exited with error code" << exitCode;
371 void Wizard::slotCheckThumbs() {
372 QString pixname = "timeline_vthumbs.png";
373 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
374 pixname = "timeline_nothumbs.png";
375 } else if (m_extra.audiothumbs->isChecked()) {
376 if (m_extra.videothumbs->isChecked())
377 pixname = "timeline_avthumbs.png";
378 else pixname = "timeline_athumbs.png";
381 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
384 void Wizard::slotCheckStandard() {
385 m_standard.profiles_list->clear();
386 QStringList profiles;
387 if (m_standard.button_dv->isChecked()) {
389 m_standard.profiles_list->addItems(m_dvProfiles);
390 } else if (m_standard.button_hdv->isChecked()) {
392 m_standard.profiles_list->addItems(m_hdvProfiles);
394 m_standard.profiles_list->addItems(m_dvProfiles);
395 m_standard.profiles_list->addItems(m_hdvProfiles);
396 m_standard.profiles_list->addItems(m_otherProfiles);
397 //m_standard.profiles_list->sortItems();
400 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
401 QListWidgetItem *item = m_standard.profiles_list->item(i);
402 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
403 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));
404 item->setToolTip(infoString);
407 m_standard.profiles_list->setSortingEnabled(true);
408 m_standard.profiles_list->setCurrentRow(0);
411 void Wizard::slotCheckSelectedItem() {
412 // Make sure we always have an item highlighted
413 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
417 void Wizard::adjustSettings() {
418 if (m_extra.installmimes->isChecked()) {
420 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
421 installExtraMimes("video/mpeg", globs);
424 installExtraMimes("video/dv", globs);
425 runUpdateMimeDatabase();
427 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
428 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
429 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
430 if (m_standard.profiles_list->currentItem()) {
431 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
432 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
433 KdenliveSettings::setDefault_profile(selectedProfile);
435 QString path = m_extra.projectfolder->url().path();
436 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
437 KdenliveSettings::setDefaultprojectfolder(path);
441 void Wizard::slotCheckMlt() {
442 QString errorMessage;
443 if (KdenliveSettings::rendererpath().isEmpty()) {
444 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
446 /*QProcess checkProcess;
447 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
448 if (!checkProcess.waitForStarted())
449 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
451 checkProcess.waitForFinished();
453 QByteArray result = checkProcess.readAllStandardError();
454 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");*/
456 QProcess checkProcess2;
457 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
458 if (!checkProcess2.waitForStarted())
459 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + "\n");
461 checkProcess2.waitForFinished();
463 QByteArray result = checkProcess2.readAllStandardError();
464 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");
466 if (!errorMessage.isEmpty()) {
467 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
468 QLabel *pix = new QLabel();
469 pix->setPixmap(KIcon("dialog-error").pixmap(30));
470 QLabel *label = new QLabel(errorMessage);
471 label->setWordWrap(true);
472 m_startLayout->addSpacing(40);
473 m_startLayout->addWidget(pix);
474 m_startLayout->addWidget(label);
475 m_systemCheckIsOk = false;
476 button(QWizard::NextButton)->setEnabled(false);
477 } else m_systemCheckIsOk = true;
479 if (m_systemCheckIsOk) checkMltComponents();
482 bool Wizard::isOk() const {
483 return m_systemCheckIsOk;
486 #include "wizard.moc"