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