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 // Check installed audio codecs
145 QProcess checkProcess2;
146 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
147 if (!checkProcess2.waitForStarted()) {
148 m_mltCheck.tabWidget->setTabEnabled(1, false);
149 kDebug() << "// Error parsing MLT's avformat codecs";
151 checkProcess2.waitForFinished();
152 QByteArray codecList = checkProcess2.readAllStandardError();
153 QString acodecList(codecList);
155 QStringList alist = acodecList.split("\n", QString::SkipEmptyParts);
156 for (int i = 0; i < alist.count(); i++) {
157 if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
159 m_mltCheck.acodecs_list->addItems(result);
160 KdenliveSettings::setAudiocodecs(result);
161 //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
163 // Check video codecs
164 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
165 if (!checkProcess2.waitForStarted()) {
166 kDebug() << "// Error parsing MLT's avformat codecs";
168 checkProcess2.waitForFinished();
169 QByteArray codecList = checkProcess2.readAllStandardError();
170 QString vcodecList(codecList);
172 QStringList vlist = vcodecList.split("\n", QString::SkipEmptyParts);
173 for (int i = 0; i < vlist.count(); i++) {
174 if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
176 m_mltCheck.vcodecs_list->addItems(result);
177 KdenliveSettings::setVideocodecs(result);
178 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
181 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
182 if (!checkProcess2.waitForStarted()) {
183 kDebug() << "// Error parsing MLT's avformat codecs";
185 checkProcess2.waitForFinished();
186 QByteArray codecList = checkProcess2.readAllStandardError();
187 QString vcodecList(codecList);
189 QStringList vlist = vcodecList.split("\n", QString::SkipEmptyParts);
190 for (int i = 0; i < vlist.count(); i++) {
191 if (vlist.at(i).contains("- ")) {
192 QString format = vlist.at(i).section("- ", 1).simplified().toLower();
193 if (format.contains(',')) {
194 QStringList sub = format.split(',', QString::SkipEmptyParts);
195 for (int j = 0; j < sub.count(); j++)
196 result.append(sub.at(j));
197 } else result.append(format);
200 m_mltCheck.formats_list->addItems(result);
201 KdenliveSettings::setSupportedformats(result);
202 //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
208 // Check MLT dv module
209 QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
210 dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
211 dvItem->setSizeHint(0, itemSize);
212 if (!result.contains("- libdv")) {
213 dvItem->setIcon(0, missingIcon);
215 dvItem->setIcon(0, okIcon);
218 // Check MLT image format module
219 QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
220 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
221 imageItem->setSizeHint(0, itemSize);
222 if (!result.contains("- qimage")) {
223 imageItem->setIcon(0, missingIcon);
224 imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
225 imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
226 imageItem->setSizeHint(0, itemSize);
227 if (!result.contains("- pixbuf")) imageItem->setIcon(0, missingIcon);
228 else imageItem->setIcon(0, okIcon);
230 imageItem->setIcon(0, okIcon);
235 void Wizard::slotCheckPrograms() {
236 m_check.programList->setColumnCount(2);
237 m_check.programList->setRootIsDecorated(false);
238 m_check.programList->setHeaderHidden(true);
239 QSize itemSize(20, this->fontMetrics().height() * 2.5);
240 KIcon okIcon("dialog-ok");
241 KIcon missingIcon("dialog-close");
242 m_check.programList->setColumnWidth(0, 30);
243 m_check.programList->setIconSize(QSize(24, 24));
245 QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
246 item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
247 item->setSizeHint(0, itemSize);
248 QString exepath = KStandardDirs::findExe("ffmpeg");
249 if (exepath.isEmpty()) item->setIcon(0, missingIcon);
250 else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, missingIcon);
251 else item->setIcon(0, okIcon);
253 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Recordmydesktop"));
254 item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
255 item->setSizeHint(0, itemSize);
256 if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, missingIcon);
257 else item->setIcon(0, okIcon);
259 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvgrab"));
260 item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
261 item->setSizeHint(0, itemSize);
262 if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, missingIcon);
263 else item->setIcon(0, okIcon);
265 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Dvdauthor"));
266 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
267 item->setSizeHint(0, itemSize);
268 if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, missingIcon);
269 else item->setIcon(0, okIcon);
271 item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("Mkisofs"));
272 item->setData(1, Qt::UserRole, i18n("Required for creation of DVD iso images"));
273 item->setSizeHint(0, itemSize);
274 if (KStandardDirs::findExe("mkisofs").isEmpty()) item->setIcon(0, missingIcon);
275 else item->setIcon(0, okIcon);
279 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
280 QString mimefile = baseName;
281 mimefile.replace('/', '-');
282 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
284 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
286 QStringList extensions = mime->patterns();
287 QString comment = mime->comment();
288 foreach(const QString &glob, globs) {
289 if (!extensions.contains(glob)) extensions << glob;
291 kDebug() << "EXTS: " << extensions;
292 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
293 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
294 QFile packageFile(packageFileName);
295 if (!packageFile.open(QIODevice::WriteOnly)) {
296 kError() << "Couldn't open" << packageFileName << "for writing";
299 QXmlStreamWriter writer(&packageFile);
300 writer.setAutoFormatting(true);
301 writer.writeStartDocument();
303 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
304 writer.writeDefaultNamespace(nsUri);
305 writer.writeStartElement("mime-info");
306 writer.writeStartElement(nsUri, "mime-type");
307 writer.writeAttribute("type", baseName);
309 if (!comment.isEmpty()) {
310 writer.writeStartElement(nsUri, "comment");
311 writer.writeCharacters(comment);
312 writer.writeEndElement(); // comment
315 foreach(const QString& pattern, extensions) {
316 writer.writeStartElement(nsUri, "glob");
317 writer.writeAttribute("pattern", pattern);
318 writer.writeEndElement(); // glob
321 writer.writeEndElement(); // mime-info
322 writer.writeEndElement(); // mime-type
323 writer.writeEndDocument();
327 void Wizard::runUpdateMimeDatabase() {
328 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
329 //Q_ASSERT(!localPackageDir.isEmpty());
331 proc << "update-mime-database";
332 proc << localPackageDir;
333 const int exitCode = proc.execute();
335 kWarning() << proc.program() << "exited with error code" << exitCode;
339 void Wizard::slotCheckThumbs() {
340 QString pixname = "timeline_vthumbs.png";
341 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
342 pixname = "timeline_nothumbs.png";
343 } else if (m_extra.audiothumbs->isChecked()) {
344 if (m_extra.videothumbs->isChecked())
345 pixname = "timeline_avthumbs.png";
346 else pixname = "timeline_athumbs.png";
349 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
352 void Wizard::slotCheckStandard() {
353 m_standard.profiles_list->clear();
354 QStringList profiles;
355 if (m_standard.button_dv->isChecked()) {
357 m_standard.profiles_list->addItems(m_dvProfiles);
358 } else if (m_standard.button_hdv->isChecked()) {
360 m_standard.profiles_list->addItems(m_hdvProfiles);
362 m_standard.profiles_list->addItems(m_dvProfiles);
363 m_standard.profiles_list->addItems(m_hdvProfiles);
364 m_standard.profiles_list->addItems(m_otherProfiles);
365 //m_standard.profiles_list->sortItems();
368 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
369 QListWidgetItem *item = m_standard.profiles_list->item(i);
370 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
371 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));
372 item->setToolTip(infoString);
375 m_standard.profiles_list->setSortingEnabled(true);
376 m_standard.profiles_list->setCurrentRow(0);
379 void Wizard::slotCheckSelectedItem() {
380 // Make sure we always have an item highlighted
381 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
385 void Wizard::adjustSettings() {
386 if (m_extra.installmimes->isChecked()) {
388 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
389 installExtraMimes("video/mpeg", globs);
392 installExtraMimes("video/dv", globs);
393 runUpdateMimeDatabase();
395 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
396 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
397 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
398 if (m_standard.profiles_list->currentItem()) {
399 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
400 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
401 KdenliveSettings::setDefault_profile(selectedProfile);
403 QString path = m_extra.projectfolder->url().path();
404 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
405 KdenliveSettings::setDefaultprojectfolder(path);
409 void Wizard::slotCheckMlt() {
410 QString errorMessage;
411 if (KdenliveSettings::rendererpath().isEmpty()) {
412 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
414 /*QProcess checkProcess;
415 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
416 if (!checkProcess.waitForStarted())
417 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
419 checkProcess.waitForFinished();
421 QByteArray result = checkProcess.readAllStandardError();
422 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");*/
424 QProcess checkProcess2;
425 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
426 if (!checkProcess2.waitForStarted())
427 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + "\n");
429 checkProcess2.waitForFinished();
431 QByteArray result = checkProcess2.readAllStandardError();
432 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");
434 if (!errorMessage.isEmpty()) {
435 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
436 QLabel *pix = new QLabel();
437 pix->setPixmap(KIcon("dialog-error").pixmap(30));
438 QLabel *label = new QLabel(errorMessage);
439 label->setWordWrap(true);
440 m_startLayout->addSpacing(40);
441 m_startLayout->addWidget(pix);
442 m_startLayout->addWidget(label);
443 m_systemCheckIsOk = false;
444 button(QWizard::NextButton)->setEnabled(false);
445 } else m_systemCheckIsOk = true;
447 if (m_systemCheckIsOk) checkMltComponents();
450 bool Wizard::isOk() const {
451 return m_systemCheckIsOk;
454 #include "wizard.moc"