]> git.sesse.net Git - kdenlive/blob - src/wizard.cpp
Basic webcam (video4linux) autodetection
[kdenlive] / src / wizard.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "wizard.h"
21 #include "kdenlivesettings.h"
22 #include "profilesdialog.h"
23 #include "v4l/v4lcapture.h"
24 #include "kdenlive-config.h"
25
26 #include <KStandardDirs>
27 #include <KLocale>
28 #include <KProcess>
29 #include <kmimetype.h>
30 #include <KRun>
31 #include <KService>
32 #include <KMimeTypeTrader>
33
34 #include <QLabel>
35 #include <QFile>
36 #include <QXmlStreamWriter>
37 #include <QTimer>
38
39 const double recommendedMltVersion = 510;
40 static const char kdenlive_version[] = VERSION;
41
42 Wizard::Wizard(bool upgrade, QWidget *parent) :
43     QWizard(parent)
44 {
45     setWindowTitle(i18n("Config Wizard"));
46     setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
47
48     QWizardPage *page1 = new QWizardPage;
49     page1->setTitle(i18n("Welcome"));
50     QLabel *label;
51     if (upgrade)
52         label = new QLabel(i18n("Your Kdenlive version was upgraded to version %1. Please take some time to review the basic settings", QString(kdenlive_version).section(' ', 0, 0)));
53     else
54         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..."));
55     label->setWordWrap(true);
56     m_startLayout = new QVBoxLayout;
57     m_startLayout->addWidget(label);
58     QPushButton *but = new QPushButton(KIcon("help-about"), i18n("Discover the features of this Kdenlive release"), this);
59     connect(but, SIGNAL(clicked()), this, SLOT(slotShowWebInfos()));
60     m_startLayout->addStretch();
61     m_startLayout->addWidget(but);
62
63
64     page1->setLayout(m_startLayout);
65     addPage(page1);
66
67     QWizardPage *page4 = new QWizardPage;
68     page4->setTitle(i18n("Checking MLT engine"));
69     m_mltCheck.setupUi(page4);
70     addPage(page4);
71
72     WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
73     m_mltCheck.programList->setItemDelegate(listViewDelegate);
74
75     QWizardPage *page2 = new QWizardPage;
76     page2->setTitle(i18n("Video Standard"));
77     m_standard.setupUi(page2);
78
79     m_okIcon = KIcon("dialog-ok");
80     m_badIcon = KIcon("dialog-close");
81
82     // build profiles lists
83     QMap<QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
84     QMap<QString, QString>::const_iterator i = profilesInfo.constBegin();
85     while (i != profilesInfo.constEnd()) {
86         QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
87         if (profileData.value("width") == "720") m_dvProfiles.insert(i.key(), i.value());
88         else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.insert(i.key(), i.value());
89         else m_otherProfiles.insert(i.key(), i.value());
90         ++i;
91     }
92
93     m_standard.button_all->setChecked(true);
94     connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
95     connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
96     connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
97     slotCheckStandard();
98     connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
99
100     // select default profile
101     if (!KdenliveSettings::default_profile().isEmpty()) {
102         for (int i = 0; i < m_standard.profiles_list->count(); i++) {
103             if (m_standard.profiles_list->item(i)->data(Qt::UserRole).toString() == KdenliveSettings::default_profile()) {
104                 m_standard.profiles_list->setCurrentRow(i);
105                 m_standard.profiles_list->scrollToItem(m_standard.profiles_list->currentItem());
106                 break;
107             }
108         }
109     }
110
111     addPage(page2);
112
113     QWizardPage *page3 = new QWizardPage;
114     page3->setTitle(i18n("Additional Settings"));
115     m_extra.setupUi(page3);
116     m_extra.projectfolder->setMode(KFile::Directory);
117     m_extra.projectfolder->setUrl(KUrl(KdenliveSettings::defaultprojectfolder()));
118     m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
119     m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
120     m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
121     connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
122     connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
123     slotCheckThumbs();
124     addPage(page3);
125
126     QWizardPage *page6 = new QWizardPage;
127     page6->setTitle(i18n("Webcam"));
128     m_capture.setupUi(page6);
129     connect(m_capture.button_reload, SIGNAL(clicked()), this, SLOT(slotDetectWebcam()));
130     connect(m_capture.device_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateCaptureParameters()));
131     m_capture.button_reload->setIcon(KIcon("view-refresh"));
132
133     addPage(page6);
134
135
136     QWizardPage *page5 = new QWizardPage;
137     page5->setTitle(i18n("Checking system"));
138     m_check.setupUi(page5);
139     addPage(page5);
140
141     listViewDelegate = new WizardDelegate(m_check.programList);
142     m_check.programList->setItemDelegate(listViewDelegate);
143     slotDetectWebcam();
144     QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
145 }
146
147 void Wizard::slotDetectWebcam()
148 {
149     m_capture.device_list->clear();
150
151     // Video 4 Linux device detection
152     V4lCaptureHandler v4l(NULL);
153     int width = 0;
154     int height = 0;
155     for (int i = 0; i < 10; i++) {
156         QString path = "/dev/video" + QString::number(i);
157         if (QFile::exists(path)) {
158             QString deviceName = v4l.getDeviceName(path.toUtf8().constData(), &width, &height);
159             QString captureSize;
160             if (width > 0) captureSize = QString::number(width) + "x" + QString::number(height);
161             if (!deviceName.isEmpty()) {
162                 QTreeWidgetItem *item = new QTreeWidgetItem(m_capture.device_list, QStringList() << deviceName << captureSize);
163                 item->setData(0, Qt::UserRole, path);
164                 if (!captureSize.isEmpty()) item->setData(0, Qt::UserRole + 1, captureSize);
165             }
166         }
167     }
168     if (m_capture.device_list->topLevelItemCount() > 0) {
169         m_capture.v4l_status->setText(i18n("Select your default video4linux device"));
170         // select default device
171         bool found = false;
172         for (int i = 0; i < m_capture.device_list->topLevelItemCount(); i++) {
173             QTreeWidgetItem * item = m_capture.device_list->topLevelItem(i);
174             if (item && item->data(0, Qt::UserRole).toString() == KdenliveSettings::video4vdevice()) {
175                 m_capture.device_list->setCurrentItem(item);
176                 found = true;
177                 break;
178             }
179         }
180         if (!found) m_capture.device_list->setCurrentItem(m_capture.device_list->topLevelItem(0));
181     } else m_capture.v4l_status->setText(i18n("No device found, plug your webcam and refresh."));
182 }
183
184 void Wizard::slotUpdateCaptureParameters()
185 {
186     QTreeWidgetItem * item = m_capture.device_list->currentItem();
187     if (!item) return;
188     QString device = item->data(0, Qt::UserRole).toString();
189     if (!device.isEmpty()) KdenliveSettings::setVideo4vdevice(device);
190
191     QString size = item->data(0, Qt::UserRole + 1).toString();
192     if (!size.isEmpty()) KdenliveSettings::setVideo4size(size);
193 }
194
195 void Wizard::checkMltComponents()
196 {
197     QSize itemSize(20, fontMetrics().height() * 2.5);
198     m_mltCheck.programList->setColumnWidth(0, 30);
199     m_mltCheck.programList->setIconSize(QSize(24, 24));
200
201
202     QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);
203
204     QTreeWidgetItem *meltitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Melt") + " (" + KdenliveSettings::rendererpath() + ')');
205     meltitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
206     meltitem->setSizeHint(0, itemSize);
207     meltitem->setIcon(0, m_okIcon);
208
209     // Check MLT's installed producers
210     QProcess checkProcess;
211     checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
212     if (!checkProcess.waitForStarted()) {
213         meltitem->setIcon(0, m_badIcon);
214         meltitem->setData(1, Qt::UserRole, i18n("Error starting MLT's command line player (melt)"));
215         button(QWizard::NextButton)->setEnabled(false);
216     } else {
217         checkProcess.waitForFinished();
218         QByteArray result = checkProcess.readAllStandardError();
219
220         // Check MLT avformat module
221         QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
222         avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
223         avformatItem->setSizeHint(0, itemSize);
224         if (!result.contains("- avformat")) {
225             avformatItem->setIcon(0, m_badIcon);
226             m_mltCheck.tabWidget->setTabEnabled(1, false);
227         } else {
228             avformatItem->setIcon(0, m_okIcon);
229             // Make sure we have MLT > 0.3.4
230             int version = 0;
231             QString mltVersion;
232             QString exepath = KStandardDirs::findExe("pkg-config");
233             if (!exepath.isEmpty()) {
234                 checkProcess.start(exepath, QStringList() << "--variable=version" << "mlt++");
235                 if (!checkProcess.waitForStarted()) {
236                     kDebug() << "// Error querying MLT's version";
237                 } else {
238                     checkProcess.waitForFinished();
239                     mltVersion = checkProcess.readAllStandardOutput();
240                     version = 1000 * mltVersion.section('.', 0, 0).toInt() + 100 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
241                     kDebug() << "// FOUND MLT's pkgconfig version: " << version;
242                 }
243             }
244             if (version == 0) {
245                 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "--version");
246                 if (!checkProcess.waitForStarted()) {
247                     kDebug() << "// Error querying MLT's version";
248                 } else {
249                     checkProcess.waitForFinished();
250                     mltVersion = checkProcess.readAllStandardError();
251                     mltVersion = mltVersion.section('\n', 0, 0).simplified();
252                     mltVersion = mltVersion.section(' ', -1).simplified();
253                     version = 1000 * mltVersion.section('.', 0, 0).toInt() + 100 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
254                     kDebug() << "// FOUND MLT version: " << version;
255                 }
256             }
257
258             mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
259             mltitem->setSizeHint(0, itemSize);
260             if (version < 506) {
261                 mltitem->setData(1, Qt::UserRole, i18n("Your MLT version is unsupported!!!"));
262                 mltitem->setIcon(0, m_badIcon);
263             } else {
264                 if (version < recommendedMltVersion) {
265                     mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to the latest MLT version"));
266                     mltitem->setIcon(0, m_badIcon);
267                 } else {
268                     mltitem->setData(1, Qt::UserRole, i18n("MLT version is correct"));
269                     mltitem->setIcon(0, m_okIcon);
270                 }
271                 // Check installed audio codecs
272                 QProcess checkProcess2;
273                 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "acodec=list");
274                 if (!checkProcess2.waitForStarted()) {
275                     m_mltCheck.tabWidget->setTabEnabled(1, false);
276                     kDebug() << "// Error parsing MLT's avformat codecs";
277                 } else {
278                     checkProcess2.waitForFinished();
279                     QByteArray codecList = checkProcess2.readAllStandardError();
280                     QString acodecList(codecList);
281                     QStringList result;
282                     QStringList alist = acodecList.split('\n', QString::SkipEmptyParts);
283                     for (int i = 0; i < alist.count(); i++) {
284                         if (alist.at(i).contains("- ")) result.append(alist.at(i).section("- ", 1).simplified().toLower());
285                     }
286                     m_mltCheck.acodecs_list->addItems(result);
287                     KdenliveSettings::setAudiocodecs(result);
288                     //kDebug()<<"// FOUND LIST:\n\n"<<m_audioCodecs<<"\n\n++++++++++++++++++++";
289                 }
290                 // Check video codecs
291                 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "vcodec=list");
292                 if (!checkProcess2.waitForStarted()) {
293                     kDebug() << "// Error parsing MLT's avformat codecs";
294                 } else {
295                     checkProcess2.waitForFinished();
296                     QByteArray codecList = checkProcess2.readAllStandardError();
297                     QString vcodecList(codecList);
298                     QStringList result;
299                     QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
300                     for (int i = 0; i < vlist.count(); i++) {
301                         if (vlist.at(i).contains("- ")) result.append(vlist.at(i).section("- ", 1).simplified().toLower());
302                     }
303                     m_mltCheck.vcodecs_list->addItems(result);
304                     KdenliveSettings::setVideocodecs(result);
305                     //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
306                 }
307                 // Check formats
308                 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "noise:" << "-consumer" << "avformat" << "f=list");
309                 if (!checkProcess2.waitForStarted()) {
310                     kDebug() << "// Error parsing MLT's avformat codecs";
311                 } else {
312                     checkProcess2.waitForFinished();
313                     QByteArray codecList = checkProcess2.readAllStandardError();
314                     QString vcodecList(codecList);
315                     QStringList result;
316                     QStringList vlist = vcodecList.split('\n', QString::SkipEmptyParts);
317                     for (int i = 0; i < vlist.count(); i++) {
318                         if (vlist.at(i).contains("- ")) {
319                             QString format = vlist.at(i).section("- ", 1).simplified().toLower();
320                             if (format.contains(',')) {
321                                 QStringList sub = format.split(',', QString::SkipEmptyParts);
322                                 for (int j = 0; j < sub.count(); j++)
323                                     result.append(sub.at(j));
324                             } else result.append(format);
325                         }
326                     }
327                     m_mltCheck.formats_list->addItems(result);
328                     KdenliveSettings::setSupportedformats(result);
329                     //kDebug()<<"// FOUND LIST:\n\n"<<m_videoCodecs<<"\n\n++++++++++++++++++++";
330                 }
331             }
332
333         }
334
335         // Check MLT dv module
336         QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
337         dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
338         dvItem->setSizeHint(0, itemSize);
339         if (!result.contains("- libdv")) {
340             dvItem->setIcon(0, m_badIcon);
341         } else {
342             dvItem->setIcon(0, m_okIcon);
343         }
344
345         // Check MLT image format module
346         QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
347         imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
348         imageItem->setSizeHint(0, itemSize);
349         if (!result.contains("- qimage")) {
350             imageItem->setIcon(0, m_badIcon);
351             imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
352             imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
353             imageItem->setSizeHint(0, itemSize);
354             if (!result.contains("- pixbuf")) imageItem->setIcon(0, m_badIcon);
355             else imageItem->setIcon(0, m_okIcon);
356         } else {
357             imageItem->setIcon(0, m_okIcon);
358         }
359
360         // Check MLT title module
361         QTreeWidgetItem *titleItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Title module"));
362         titleItem->setData(1, Qt::UserRole, i18n("Required to work with titles"));
363         titleItem->setSizeHint(0, itemSize);
364         if (!result.contains("- kdenlivetitle")) {
365             KdenliveSettings::setHastitleproducer(false);
366             titleItem->setIcon(0, m_badIcon);
367         } else {
368             titleItem->setIcon(0, m_okIcon);
369             KdenliveSettings::setHastitleproducer(true);
370         }
371     }
372 }
373
374 void Wizard::slotCheckPrograms()
375 {
376     QSize itemSize(20, fontMetrics().height() * 2.5);
377     m_check.programList->setColumnWidth(0, 30);
378     m_check.programList->setIconSize(QSize(24, 24));
379
380     QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
381     item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
382     item->setSizeHint(0, itemSize);
383     QString exepath = KStandardDirs::findExe("ffmpeg");
384     if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
385     else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
386     else item->setIcon(0, m_okIcon);
387
388 #ifndef Q_WS_MAC
389     item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("recordmydesktop"));
390     item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
391     item->setSizeHint(0, itemSize);
392     if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
393     else item->setIcon(0, m_okIcon);
394
395     item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("dvgrab"));
396     item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
397     item->setSizeHint(0, itemSize);
398     if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
399     else item->setIcon(0, m_okIcon);
400 #endif
401
402     item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("dvdauthor"));
403     item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
404     item->setSizeHint(0, itemSize);
405     if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
406     else item->setIcon(0, m_okIcon);
407
408
409     item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("genisoimage or mkisofs"));
410     item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
411     item->setSizeHint(0, itemSize);
412     if (KStandardDirs::findExe("genisoimage").isEmpty()) {
413         // no GenIso, check for mkisofs
414         if (!KStandardDirs::findExe("mkisofs").isEmpty()) {
415             item->setIcon(0, m_okIcon);
416         } else item->setIcon(0, m_badIcon);
417     } else item->setIcon(0, m_okIcon);
418
419     // set up some default applications
420     QString program;
421     if (KdenliveSettings::defaultimageapp().isEmpty()) {
422         program = KStandardDirs::findExe("gimp");
423         if (program.isEmpty()) program = KStandardDirs::findExe("krita");
424         if (!program.isEmpty()) KdenliveSettings::setDefaultimageapp(program);
425     }
426     if (KdenliveSettings::defaultaudioapp().isEmpty()) {
427         program = KStandardDirs::findExe("audacity");
428         if (program.isEmpty()) program = KStandardDirs::findExe("traverso");
429         if (!program.isEmpty()) KdenliveSettings::setDefaultaudioapp(program);
430     }
431     if (KdenliveSettings::defaultplayerapp().isEmpty()) {
432         KService::Ptr offer = KMimeTypeTrader::self()->preferredService("video/mpeg");
433         if (offer)
434             KdenliveSettings::setDefaultplayerapp(KRun::binaryName(offer->exec(), true));
435     }
436 }
437
438 void Wizard::installExtraMimes(QString baseName, QStringList globs)
439 {
440     QString mimefile = baseName;
441     mimefile.replace('/', '-');
442     KMimeType::Ptr mime = KMimeType::mimeType(baseName);
443     if (!mime) {
444         kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
445     } else {
446         QStringList extensions = mime->patterns();
447         QString comment = mime->comment();
448         foreach(const QString & glob, globs) {
449             if (!extensions.contains(glob)) extensions << glob;
450         }
451         kDebug() << "EXTS: " << extensions;
452         QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
453         kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
454         QFile packageFile(packageFileName);
455         if (!packageFile.open(QIODevice::WriteOnly)) {
456             kError() << "Couldn't open" << packageFileName << "for writing";
457             return;
458         }
459         QXmlStreamWriter writer(&packageFile);
460         writer.setAutoFormatting(true);
461         writer.writeStartDocument();
462
463         const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
464         writer.writeDefaultNamespace(nsUri);
465         writer.writeStartElement("mime-info");
466         writer.writeStartElement(nsUri, "mime-type");
467         writer.writeAttribute("type", baseName);
468
469         if (!comment.isEmpty()) {
470             writer.writeStartElement(nsUri, "comment");
471             writer.writeCharacters(comment);
472             writer.writeEndElement(); // comment
473         }
474
475         foreach(const QString & pattern, extensions) {
476             writer.writeStartElement(nsUri, "glob");
477             writer.writeAttribute("pattern", pattern);
478             writer.writeEndElement(); // glob
479         }
480
481         writer.writeEndElement(); // mime-info
482         writer.writeEndElement(); // mime-type
483         writer.writeEndDocument();
484     }
485 }
486
487 void Wizard::runUpdateMimeDatabase()
488 {
489     const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
490     //Q_ASSERT(!localPackageDir.isEmpty());
491     KProcess proc;
492     proc << "update-mime-database";
493     proc << localPackageDir;
494     const int exitCode = proc.execute();
495     if (exitCode) {
496         kWarning() << proc.program() << "exited with error code" << exitCode;
497     }
498 }
499
500 void Wizard::slotCheckThumbs()
501 {
502     QString pixname = "timeline_vthumbs.png";
503     if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
504         pixname = "timeline_nothumbs.png";
505     } else if (m_extra.audiothumbs->isChecked()) {
506         if (m_extra.videothumbs->isChecked())
507             pixname = "timeline_avthumbs.png";
508         else pixname = "timeline_athumbs.png";
509     }
510
511     m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
512 }
513
514 void Wizard::slotCheckStandard()
515 {
516     m_standard.profiles_list->clear();
517     QStringList profiles;
518     if (!m_standard.button_hdv->isChecked()) {
519         // DV standard
520         QMapIterator<QString, QString> i(m_dvProfiles);
521         while (i.hasNext()) {
522             i.next();
523             QListWidgetItem *item = new QListWidgetItem(i.key(), m_standard.profiles_list);
524             item->setData(Qt::UserRole, i.value());
525         }
526     }
527     if (!m_standard.button_dv->isChecked()) {
528         // HDV standard
529         QMapIterator<QString, QString> i(m_hdvProfiles);
530         while (i.hasNext()) {
531             i.next();
532             QListWidgetItem *item = new QListWidgetItem(i.key(), m_standard.profiles_list);
533             item->setData(Qt::UserRole, i.value());
534         }
535     }
536     if (m_standard.button_all->isChecked()) {
537         QMapIterator<QString, QString> i(m_otherProfiles);
538         while (i.hasNext()) {
539             i.next();
540             QListWidgetItem *item = new QListWidgetItem(i.key(), m_standard.profiles_list);
541             item->setData(Qt::UserRole, i.value());
542         }
543         //m_standard.profiles_list->sortItems();
544     }
545
546     for (int i = 0; i < m_standard.profiles_list->count(); i++) {
547         QListWidgetItem *item = m_standard.profiles_list->item(i);
548
549         QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(item->data(Qt::UserRole).toString());
550         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(values.value("width"), values.value("height"), values.value("frame_rate_num"), values.value("frame_rate_den"), values.value("sample_aspect_num"), values.value("sample_aspect_den"), values.value("display_aspect_num"), values.value("display_aspect_den"));
551         item->setToolTip(infoString);
552     }
553
554     m_standard.profiles_list->setSortingEnabled(true);
555     m_standard.profiles_list->setCurrentRow(0);
556 }
557
558 void Wizard::slotCheckSelectedItem()
559 {
560     // Make sure we always have an item highlighted
561     m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
562 }
563
564
565 void Wizard::adjustSettings()
566 {
567     if (m_extra.installmimes->isChecked()) {
568         QStringList globs;
569         globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts" << "*.m2ts";
570         installExtraMimes("video/mpeg", globs);
571         globs.clear();
572         globs << "*.dv";
573         installExtraMimes("video/dv", globs);
574         runUpdateMimeDatabase();
575     }
576     KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
577     KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
578     KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
579     if (m_standard.profiles_list->currentItem()) {
580         QString selectedProfile = m_standard.profiles_list->currentItem()->data(Qt::UserRole).toString();
581         if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
582         KdenliveSettings::setDefault_profile(selectedProfile);
583     }
584     QString path = m_extra.projectfolder->url().path();
585     if (KStandardDirs::makeDir(path) == false) {
586         kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
587     } else KdenliveSettings::setDefaultprojectfolder(path);
588
589 }
590
591 void Wizard::slotCheckMlt()
592 {
593     QString errorMessage;
594     if (KdenliveSettings::rendererpath().isEmpty()) {
595         errorMessage.append(i18n("Your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
596     }
597     /*QProcess checkProcess;
598     checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
599     if (!checkProcess.waitForStarted())
600         errorMessage.append(i18n("Error starting MLT's command line player (melt)") + ".\n");
601
602     checkProcess.waitForFinished();
603
604     QByteArray result = checkProcess.readAllStandardError();
605     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");*/
606
607     QProcess checkProcess2;
608     checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
609     if (!checkProcess2.waitForStarted())
610         errorMessage.append(i18n("Error starting MLT's command line player (melt).") + '\n');
611
612     checkProcess2.waitForFinished();
613
614     QByteArray result = checkProcess2.readAllStandardError();
615     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');
616
617     if (!errorMessage.isEmpty()) {
618         errorMessage.prepend(QString("<b>%1</b><br />").arg(i18n("Fatal Error")));
619         QLabel *pix = new QLabel();
620         pix->setPixmap(KIcon("dialog-error").pixmap(30));
621         QLabel *label = new QLabel(errorMessage);
622         label->setWordWrap(true);
623         m_startLayout->addSpacing(40);
624         m_startLayout->addWidget(pix);
625         m_startLayout->addWidget(label);
626         m_systemCheckIsOk = false;
627         button(QWizard::NextButton)->setEnabled(false);
628     } else m_systemCheckIsOk = true;
629
630     if (m_systemCheckIsOk) checkMltComponents();
631     slotCheckPrograms();
632 }
633
634 bool Wizard::isOk() const
635 {
636     return m_systemCheckIsOk;
637 }
638
639 void Wizard::slotShowWebInfos()
640 {
641     KRun::runUrl(KUrl("http://kdenlive.org/discover/" + QString(kdenlive_version).section(' ', 0, 0)), "text/html", this);
642 }
643
644 #include "wizard.moc"