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