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 Wizard::Wizard(QWidget *parent): QWizard(parent) {
35 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
37 QWizardPage *page1 = new QWizardPage;
38 page1->setTitle(i18n("Welcome"));
39 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..."));
40 label->setWordWrap(true);
41 m_startLayout = new QVBoxLayout;
42 m_startLayout->addWidget(label);
43 page1->setLayout(m_startLayout);
46 QWizardPage *page4 = new QWizardPage;
47 page4->setTitle(i18n("Checking MLT engine"));
48 m_mltCheck.setupUi(page4);
51 WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
52 m_mltCheck.programList->setItemDelegate(listViewDelegate);
54 QWizardPage *page2 = new QWizardPage;
55 page2->setTitle(i18n("Video Standard"));
56 m_standard.setupUi(page2);
58 // build profiles lists
59 m_profilesInfo = ProfilesDialog::getProfilesInfo();
60 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
61 while (i != m_profilesInfo.constEnd()) {
62 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
63 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
64 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
65 else m_otherProfiles.append(i.key());
69 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
70 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
71 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
72 m_standard.button_all->setChecked(true);
73 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
75 // select default profile
76 QList<QListWidgetItem *> profiles = m_standard.profiles_list->findItems(ProfilesDialog::getProfileDescription(KdenliveSettings::default_profile()), Qt::MatchExactly);
77 if (profiles.count() > 0) m_standard.profiles_list->setCurrentItem(profiles.at(0));
80 QWizardPage *page3 = new QWizardPage;
81 page3->setTitle(i18n("Additional Settings"));
82 m_extra.setupUi(page3);
83 m_extra.projectfolder->setMode(KFile::Directory);
84 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
85 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
86 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
87 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
88 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
89 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
94 QWizardPage *page5 = new QWizardPage;
95 page5->setTitle(i18n("Checking system"));
96 m_check.setupUi(page5);
100 listViewDelegate = new WizardDelegate(m_check.programList);
101 m_check.programList->setItemDelegate(listViewDelegate);
103 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
107 void Wizard::checkMltComponents() {
108 m_mltCheck.programList->setColumnCount(2);
109 m_mltCheck.programList->setRootIsDecorated(false);
110 m_mltCheck.programList->setHeaderHidden(true);
111 QSize itemSize(20, this->fontMetrics().height() * 2.5);
112 KIcon okIcon("dialog-ok");
113 KIcon missingIcon("dialog-close");
114 m_mltCheck.programList->setColumnWidth(0, 30);
115 m_mltCheck.programList->setIconSize(QSize(24, 24));
118 QTreeWidgetItem *item = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Inigo") + " (" + KdenliveSettings::rendererpath() + ')');
119 item->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
120 item->setSizeHint(0, itemSize);
121 item->setIcon(0, okIcon);
123 // Check MLT's installed producers
124 QProcess checkProcess;
125 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
126 if (!checkProcess.waitForStarted()) {
127 item->setIcon(0, missingIcon);
128 item->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (inigo)"));
129 button(QWizard::NextButton)->setEnabled(false);
131 checkProcess.waitForFinished();
132 QByteArray result = checkProcess.readAllStandardError();
134 // Check MLT avformat module
135 QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
136 avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
137 avformatItem->setSizeHint(0, itemSize);
138 if (!result.contains("- avformat")) {
139 avformatItem->setIcon(0, missingIcon);
140 m_mltCheck.tabWidget->setTabEnabled(1, false);
142 avformatItem->setIcon(0, okIcon);
143 // Make sure we have MLT > 0.3.4
144 bool recentMlt = false;
146 QString exepath = KStandardDirs::findExe("pkg-config");
147 if (!exepath.isEmpty()) {
148 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt-framework");
149 if (!checkProcess.waitForStarted()) {
150 kDebug() << "// Error querying MLT's version";
152 checkProcess.waitForFinished();
153 QString mltVersion = checkProcess.readAllStandardOutput();
154 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
155 kDebug() << "// FOUND MLT's pkgconfig version: " << version;
156 if (version > 34) recentMlt = true;
160 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
161 if (!checkProcess.waitForStarted()) {
162 kDebug() << "// Error querying MLT's version";
164 checkProcess.waitForFinished();
165 QString mltVersion = checkProcess.readAllStandardError();
166 mltVersion = mltVersion.section('\n', 0, 0).simplified();
167 mltVersion = mltVersion.section(' ', -1).simplified();
168 version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
169 kDebug() << "// FOUND MLT version: " << version;
170 if (version > 34) recentMlt = true;
175 // Check installed audio codecs
176 QProcess checkProcess2;
177 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
178 if (!checkProcess2.waitForStarted()) {
179 m_mltCheck.tabWidget->setTabEnabled(1, false);
180 kDebug() << "// Error parsing MLT's avformat codecs";
182 checkProcess2.waitForFinished();
183 QByteArray codecList = checkProcess2.readAllStandardError();
184 QString acodecList(codecList);
186 QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
187 for (int i = 0; i < alist.count(); i++) {
188 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
190 m_mltCheck.acodecs_list->addItems(result);
191 KdenliveSettings::setAudiocodecs(result);
192 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
194 // Check video codecs
195 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
196 if (!checkProcess2.waitForStarted()) {
197 kDebug() << "// Error parsing MLT's avformat codecs";
199 checkProcess2.waitForFinished();
200 QByteArray codecList = checkProcess2.readAllStandardError();
201 QString vcodecList(codecList);
203 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
204 for (int i = 0; i < vlist.count(); i++) {
205 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
207 m_mltCheck.vcodecs_list->addItems(result);
208 KdenliveSettings::setVideocodecs(result);
209 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
212 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
213 if (!checkProcess2.waitForStarted()) {
214 kDebug() << "// Error parsing MLT's avformat codecs";
216 checkProcess2.waitForFinished();
217 QByteArray codecList = checkProcess2.readAllStandardError();
218 QString vcodecList(codecList);
220 QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
221 for (int i = 0; i < vlist.count(); i++) {
222 if (vlist.at(i).contains("- ")) {
223 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
224 if (format.contains(',')) {
225 QStringList sub = format.split(',', QString::SkipEmptyParts);
226 for (int j = 0; j < sub.count(); j++)
227 result.append(sub.at(j));
228 } else result.append(format);
231 m_mltCheck.formats_list->addItems(result);
232 KdenliveSettings::setSupportedformats(result);
233 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
239 // Check MLT dv module
240 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
241 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
242 dvItem->setSizeHint(0, itemSize);
243 if (!result.contains("- libdv")) {
244 dvItem->setIcon(0, missingIcon);
246 dvItem->setIcon(0, okIcon);
249 // Check MLT image format module
250 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
251 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
252 imageItem->setSizeHint(0, itemSize);
253 if (!result.contains("- qimage")) {
254 imageItem->setIcon(0, missingIcon);
255 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
256 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
257 imageItem->setSizeHint(0, itemSize);
258 if (!result.contains("- pixbuf")) imageItem->setIcon(0, missingIcon);
259 else imageItem->setIcon(0, okIcon);
261 imageItem->setIcon(0, okIcon);
266 void Wizard::slotCheckPrograms() {
267 m_check.programList->setColumnCount(2);
268 m_check.programList->setRootIsDecorated(false);
269 m_check.programList->setHeaderHidden(true);
270 QSize itemSize(20, this->fontMetrics().height() * 2.5);
271 KIcon okIcon("dialog-ok");
272 KIcon missingIcon("dialog-close");
273 m_check.programList->setColumnWidth(0, 30);
274 m_check.programList->setIconSize(QSize(24, 24));
276 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
277 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
278 item->setSizeHint(0, itemSize);
279 QString exepath = KStandardDirs::findExe("ffmpeg");
280 if (exepath.isEmpty()) item->setIcon(0, missingIcon);
281 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, missingIcon);
282 else item->setIcon(0, okIcon);
284 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
285 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
286 item->setSizeHint(0, itemSize);
287 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, missingIcon);
288 else item->setIcon(0, okIcon);
290 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
291 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
292 item->setSizeHint(0, itemSize);
293 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, missingIcon);
294 else item->setIcon(0, okIcon);
296 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
297 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
298 item->setSizeHint(0, itemSize);
299 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, missingIcon);
300 else item->setIcon(0, okIcon);
302 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
303 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD iso images"));
304 item->setSizeHint(0, itemSize);
305 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, missingIcon);
306 else item->setIcon(0, okIcon);
310 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
311 QString mimefile = baseName;
312 mimefile.replace('/', '-');
313 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
315 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
317 QStringList extensions = mime->patterns();
318 QString comment = mime->comment();
319 foreach(const QString &glob, globs) {
320 if (!extensions.contains(glob)) extensions << glob;
322 kDebug() << "EXTS: " << extensions;
323 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
324 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
325 QFile packageFile(packageFileName);
326 if (!packageFile.open(QIODevice::WriteOnly)) {
327 kError() << "Couldn't open" << packageFileName << "for writing";
330 QXmlStreamWriter writer(&packageFile);
331 writer.setAutoFormatting(true);
332 writer.writeStartDocument();
334 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
335 writer.writeDefaultNamespace(nsUri);
336 writer.writeStartElement("mime-info");
337 writer.writeStartElement(nsUri, "mime-type");
338 writer.writeAttribute("type", baseName);
340 if (!comment.isEmpty()) {
341 writer.writeStartElement(nsUri, "comment");
342 writer.writeCharacters(comment);
343 writer.writeEndElement(); // comment
346 foreach(const QString& pattern, extensions) {
347 writer.writeStartElement(nsUri, "glob");
348 writer.writeAttribute("pattern", pattern);
349 writer.writeEndElement(); // glob
352 writer.writeEndElement(); // mime-info
353 writer.writeEndElement(); // mime-type
354 writer.writeEndDocument();
358 void Wizard::runUpdateMimeDatabase() {
359 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
360 //Q_ASSERT(!localPackageDir.isEmpty());
362 proc << "update-mime-database";
363 proc << localPackageDir;
364 const int exitCode = proc.execute();
366 kWarning() << proc.program() << "exited with error code" << exitCode;
370 void Wizard::slotCheckThumbs() {
371 QString pixname = "timeline_vthumbs.png";
372 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
373 pixname = "timeline_nothumbs.png";
374 } else if (m_extra.audiothumbs->isChecked()) {
375 if (m_extra.videothumbs->isChecked())
376 pixname = "timeline_avthumbs.png";
377 else pixname = "timeline_athumbs.png";
380 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
383 void Wizard::slotCheckStandard() {
384 m_standard.profiles_list->clear();
385 QStringList profiles;
386 if (m_standard.button_dv->isChecked()) {
388 m_standard.profiles_list->addItems(m_dvProfiles);
389 } else if (m_standard.button_hdv->isChecked()) {
391 m_standard.profiles_list->addItems(m_hdvProfiles);
393 m_standard.profiles_list->addItems(m_dvProfiles);
394 m_standard.profiles_list->addItems(m_hdvProfiles);
395 m_standard.profiles_list->addItems(m_otherProfiles);
396 //m_standard.profiles_list->sortItems();
399 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
400 QListWidgetItem *item = m_standard.profiles_list->item(i);
401 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
402 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));
403 item->setToolTip(infoString);
406 m_standard.profiles_list->setSortingEnabled(true);
407 m_standard.profiles_list->setCurrentRow(0);
410 void Wizard::slotCheckSelectedItem() {
411 // Make sure we always have an item highlighted
412 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
416 void Wizard::adjustSettings() {
417 if (m_extra.installmimes->isChecked()) {
419 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
420 installExtraMimes("video/mpeg", globs);
423 installExtraMimes("video/dv", globs);
424 runUpdateMimeDatabase();
426 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
427 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
428 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
429 if (m_standard.profiles_list->currentItem()) {
430 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
431 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
432 KdenliveSettings::setDefault_profile(selectedProfile);
434 QString path = m_extra.projectfolder->url().path();
435 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
436 KdenliveSettings::setDefaultprojectfolder(path);
440 void Wizard::slotCheckMlt() {
441 QString errorMessage;
442 if (KdenliveSettings::rendererpath().isEmpty()) {
443 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
445 /*QProcess checkProcess;
446 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
447 if (!checkProcess.waitForStarted())
448 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
450 checkProcess.waitForFinished();
452 QByteArray result = checkProcess.readAllStandardError();
453 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");*/
455 QProcess checkProcess2;
456 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
457 if (!checkProcess2.waitForStarted())
458 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + '\n');
460 checkProcess2.waitForFinished();
462 QByteArray result = checkProcess2.readAllStandardError();
463 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');
465 if (!errorMessage.isEmpty()) {
466 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
467 QLabel *pix = new QLabel();
468 pix->setPixmap(KIcon("dialog-error").pixmap(30));
469 QLabel *label = new QLabel(errorMessage);
470 label->setWordWrap(true);
471 m_startLayout->addSpacing(40);
472 m_startLayout->addWidget(pix);
473 m_startLayout->addWidget(label);
474 m_systemCheckIsOk = false;
475 button(QWizard::NextButton)->setEnabled(false);
476 } else m_systemCheckIsOk = true;
478 if (m_systemCheckIsOk) checkMltComponents();
481 bool Wizard::isOk() const {
482 return m_systemCheckIsOk;
485 #include "wizard.moc"