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