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