]> git.sesse.net Git - kdenlive/blob - src/wizard.cpp
Fix proxy and various other things when using libav instead of ffmpeg
[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 "renderer.h"
24 #ifdef USE_V4L
25 #include "v4l/v4lcapture.h"
26 #endif
27 #include "config-kdenlive.h"
28
29 #include <mlt++/Mlt.h>
30 #include <framework/mlt_version.h>
31
32 #include <KStandardDirs>
33 #include <KLocale>
34 #include <KProcess>
35 #include <kmimetype.h>
36 #include <KRun>
37 #include <KService>
38 #include <KMimeTypeTrader>
39
40 #include <QLabel>
41 #include <QFile>
42 #include <QXmlStreamWriter>
43 #include <QTimer>
44
45 // Recommended MLT version
46 const int mltVersionMajor = 0;
47 const int mltVersionMinor = 8;
48 const int mltVersionRevision = 0;
49
50 static const char kdenlive_version[] = VERSION;
51
52 Wizard::Wizard(bool upgrade, QWidget *parent) :
53     QWizard(parent),
54     m_systemCheckIsOk(false)
55 {
56     setWindowTitle(i18n("Config Wizard"));
57     setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
58
59     QWizardPage *page1 = new QWizardPage;
60     page1->setTitle(i18n("Welcome"));
61     QLabel *label;
62     if (upgrade)
63         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)));
64     else
65         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..."));
66     label->setWordWrap(true);
67     m_startLayout = new QVBoxLayout;
68     m_startLayout->addWidget(label);
69     QPushButton *but = new QPushButton(KIcon("help-about"), i18n("Discover the features of this Kdenlive release"), this);
70     connect(but, SIGNAL(clicked()), this, SLOT(slotShowWebInfos()));
71     m_startLayout->addStretch();
72     m_startLayout->addWidget(but);
73
74
75     page1->setLayout(m_startLayout);
76     addPage(page1);
77
78     QWizardPage *page4 = new QWizardPage;
79     page4->setTitle(i18n("Checking MLT engine"));
80     m_mltCheck.setupUi(page4);
81     addPage(page4);
82
83     WizardDelegate *listViewDelegate = new WizardDelegate(m_mltCheck.programList);
84     m_mltCheck.programList->setItemDelegate(listViewDelegate);
85
86     QWizardPage *page2 = new QWizardPage;
87     page2->setTitle(i18n("Video Standard"));
88     m_standard.setupUi(page2);
89
90     m_okIcon = KIcon("dialog-ok");
91     m_badIcon = KIcon("dialog-close");
92
93     // build profiles lists
94     QMap<QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
95     QMap<QString, QString>::const_iterator i = profilesInfo.constBegin();
96     while (i != profilesInfo.constEnd()) {
97         QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
98         if (profileData.value("width") == "720") m_dvProfiles.insert(i.key(), i.value());
99         else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.insert(i.key(), i.value());
100         else m_otherProfiles.insert(i.key(), i.value());
101         ++i;
102     }
103
104     m_standard.button_all->setChecked(true);
105     connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
106     connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
107     connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
108     slotCheckStandard();
109     connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
110
111     // select default profile
112     if (!KdenliveSettings::default_profile().isEmpty()) {
113         for (int i = 0; i < m_standard.profiles_list->count(); i++) {
114             if (m_standard.profiles_list->item(i)->data(Qt::UserRole).toString() == KdenliveSettings::default_profile()) {
115                 m_standard.profiles_list->setCurrentRow(i);
116                 m_standard.profiles_list->scrollToItem(m_standard.profiles_list->currentItem());
117                 break;
118             }
119         }
120     }
121
122     addPage(page2);
123
124     QWizardPage *page3 = new QWizardPage;
125     page3->setTitle(i18n("Additional Settings"));
126     m_extra.setupUi(page3);
127     m_extra.projectfolder->setMode(KFile::Directory);
128     m_extra.projectfolder->setUrl(KUrl(KdenliveSettings::defaultprojectfolder()));
129     m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
130     m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
131     m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
132     connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
133     connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
134     slotCheckThumbs();
135     addPage(page3);
136
137 #ifndef Q_WS_MAC
138     QWizardPage *page6 = new QWizardPage;
139     page6->setTitle(i18n("Capture device"));
140     m_capture.setupUi(page6);
141     bool found_decklink = Render::getBlackMagicDeviceList(m_capture.decklink_devices);
142     KdenliveSettings::setDecklink_device_found(found_decklink);
143     if (found_decklink) m_capture.decklink_status->setText(i18n("Default Blackmagic Decklink card:"));
144     else m_capture.decklink_status->setText(i18n("No Blackmagic Decklink device found"));
145     connect(m_capture.decklink_devices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDecklinkDevice(int)));
146     connect(m_capture.button_reload, SIGNAL(clicked()), this, SLOT(slotDetectWebcam()));
147     connect(m_capture.v4l_devices, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateCaptureParameters()));
148     connect(m_capture.v4l_formats, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSaveCaptureFormat()));
149     m_capture.button_reload->setIcon(KIcon("view-refresh"));
150
151     addPage(page6);
152 #endif
153
154     QWizardPage *page5 = new QWizardPage;
155     page5->setTitle(i18n("Checking system"));
156     m_check.setupUi(page5);
157     addPage(page5);
158
159     listViewDelegate = new WizardDelegate(m_check.programList);
160     m_check.programList->setItemDelegate(listViewDelegate);
161     slotDetectWebcam();
162     QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
163 }
164
165 void Wizard::slotDetectWebcam()
166 {
167 #ifdef USE_V4L
168     m_capture.v4l_devices->blockSignals(true);
169     m_capture.v4l_devices->clear();
170
171     // Video 4 Linux device detection
172     for (int i = 0; i < 10; i++) {
173         QString path = "/dev/video" + QString::number(i);
174         if (QFile::exists(path)) {
175             QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path.toUtf8().constData());
176             if (!deviceInfo.isEmpty()) {
177                 m_capture.v4l_devices->addItem(deviceInfo.at(0), path);
178                 m_capture.v4l_devices->setItemData(m_capture.v4l_devices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
179             }
180         }
181     }
182     if (m_capture.v4l_devices->count() > 0) {
183         m_capture.v4l_status->setText(i18n("Default video4linux device:"));
184         // select default device
185         bool found = false;
186         for (int i = 0; i < m_capture.v4l_devices->count(); i++) {
187             QString device = m_capture.v4l_devices->itemData(i).toString();
188             if (device == KdenliveSettings::video4vdevice()) {
189                 m_capture.v4l_devices->setCurrentIndex(i);
190                 found = true;
191                 break;
192             }
193         }
194         slotUpdateCaptureParameters();
195         if (!found) m_capture.v4l_devices->setCurrentIndex(0);
196     } else m_capture.v4l_status->setText(i18n("No device found, plug your webcam and refresh."));
197     m_capture.v4l_devices->blockSignals(false);
198 #endif /* USE_V4L */
199 }
200
201 void Wizard::slotUpdateCaptureParameters()
202 {
203     QString device = m_capture.v4l_devices->itemData(m_capture.v4l_devices->currentIndex()).toString();
204     if (!device.isEmpty()) KdenliveSettings::setVideo4vdevice(device);
205
206     QString formats = m_capture.v4l_devices->itemData(m_capture.v4l_devices->currentIndex(), Qt::UserRole + 1).toString();
207
208     m_capture.v4l_formats->blockSignals(true);
209     m_capture.v4l_formats->clear();
210
211     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
212     if (QFile::exists(vl4ProfilePath)) {
213         MltVideoProfile profileInfo = ProfilesDialog::getVideoProfile(vl4ProfilePath);
214         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));
215     }
216     QStringList pixelformats = formats.split('>', QString::SkipEmptyParts);
217     QString itemSize;
218     QString pixelFormat;
219     QStringList itemRates;
220     for (int i = 0; i < pixelformats.count(); i++) {
221         QString format = pixelformats.at(i).section(':', 0, 0);
222         QStringList sizes = pixelformats.at(i).split(':', QString::SkipEmptyParts);
223         pixelFormat = sizes.takeFirst();
224         for (int j = 0; j < sizes.count(); j++) {
225             itemSize = sizes.at(j).section('=', 0, 0);
226             itemRates = sizes.at(j).section('=', 1, 1).split(',', QString::SkipEmptyParts);
227             for (int k = 0; k < itemRates.count(); k++) {
228                 QString formatDescription = '[' + format + "] " + itemSize + " (" + itemRates.at(k) + ')';
229                 if (m_capture.v4l_formats->findText(formatDescription) == -1)
230                     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));
231             }
232         }
233     }
234     if (!QFile::exists(vl4ProfilePath)) {
235         if (m_capture.v4l_formats->count() > 9) slotSaveCaptureFormat();
236         else {
237             // No existing profile and no autodetected profiles
238             MltVideoProfile profileInfo;
239             profileInfo.width = 320;
240             profileInfo.height = 200;
241             profileInfo.frame_rate_num = 15;
242             profileInfo.frame_rate_den = 1;
243             profileInfo.display_aspect_num = 4;
244             profileInfo.display_aspect_den = 3;
245             profileInfo.sample_aspect_num = 1;
246             profileInfo.sample_aspect_den = 1;
247             profileInfo.progressive = 1;
248             profileInfo.colorspace = 601;
249             ProfilesDialog::saveProfile(profileInfo, vl4ProfilePath);
250             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));
251         }
252     }
253     m_capture.v4l_formats->blockSignals(false);
254 }
255
256 void Wizard::checkMltComponents()
257 {
258     QSize itemSize(20, fontMetrics().height() * 2.5);
259     m_mltCheck.programList->setColumnWidth(0, 30);
260     m_mltCheck.programList->setIconSize(QSize(24, 24));
261
262
263     QTreeWidgetItem *mltitem = new QTreeWidgetItem(m_mltCheck.programList);
264
265     QTreeWidgetItem *meltitem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Melt") + " (" + KdenliveSettings::rendererpath() + ')');
266     meltitem->setData(1, Qt::UserRole, i18n("Required for rendering (part of MLT package)"));
267     meltitem->setSizeHint(0, itemSize);
268     meltitem->setIcon(0, m_okIcon);
269
270
271     Mlt::Repository *repository = Mlt::Factory::init();
272     if (!repository) {
273         mltitem->setData(1, Qt::UserRole, i18n("Cannot start the MLT video backend!"));
274         mltitem->setIcon(0, m_badIcon);
275         m_systemCheckIsOk = false;
276         button(QWizard::NextButton)->setEnabled(false);
277     }
278     else {
279         int mltVersion = (mltVersionMajor << 16) + (mltVersionMinor << 8) + mltVersionRevision;
280         mltitem->setText(1, i18n("MLT version: %1", mlt_version_get_string()));
281         mltitem->setSizeHint(0, itemSize);
282         if (mlt_version_get_int() < 1792) {
283             mltitem->setData(1, Qt::UserRole, i18n("Your MLT version is unsupported!!!"));
284             mltitem->setIcon(0, m_badIcon);
285             m_systemCheckIsOk = false;
286             button(QWizard::NextButton)->setEnabled(false);
287         }
288         else if (mlt_version_get_int() < mltVersion) {
289             mltitem->setData(1, Qt::UserRole, i18n("Please upgrade to MLT %1.%2.%3", mltVersionMajor, mltVersionMinor, mltVersionRevision));
290             mltitem->setIcon(0, m_badIcon);
291         }
292         else {
293             mltitem->setData(1, Qt::UserRole, i18n("MLT video backend!"));
294             mltitem->setIcon(0, m_okIcon);
295         }
296
297         // Retrieve the list of available transitions.
298         Mlt::Properties *producers = repository->producers();
299         QStringList producersItemList;
300         for (int i = 0; i < producers->count(); ++i)
301             producersItemList << producers->get_name(i);
302         delete producers;
303
304         Mlt::Properties *consumers = repository->consumers();
305         QStringList consumersItemList;
306         for (int i = 0; i < consumers->count(); ++i)
307             consumersItemList << consumers->get_name(i);
308         delete consumers;
309
310         // SDL module
311         QTreeWidgetItem *sdlItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("SDL module"));
312         sdlItem->setData(1, Qt::UserRole, i18n("Required for Kdenlive"));
313         sdlItem->setSizeHint(0, itemSize);
314         
315         if (!consumersItemList.contains("sdl")) {
316             sdlItem->setIcon(0, m_badIcon);
317             m_systemCheckIsOk = false;
318             button(QWizard::NextButton)->setEnabled(false);
319         }
320         else {
321             sdlItem->setIcon(0, m_okIcon);
322         }
323
324         // AVformat module
325         QTreeWidgetItem *avformatItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Avformat module (FFmpeg)"));
326         avformatItem->setData(1, Qt::UserRole, i18n("Required to work with various video formats (hdv, mpeg, flash, ...)"));
327         avformatItem->setSizeHint(0, itemSize);
328         Mlt::Consumer *consumer = NULL;
329         Mlt::Profile p;
330         if (consumersItemList.contains("avformat"))
331             consumer = new Mlt::Consumer(p, "avformat");
332         if (consumer == NULL || !consumer->is_valid()) {
333             avformatItem->setIcon(0, m_badIcon);
334             m_mltCheck.tabWidget->setTabEnabled(1, false);
335         }
336         else {
337             avformatItem->setIcon(0, m_okIcon);
338             consumer->set("vcodec", "list");
339             consumer->set("acodec", "list");
340             consumer->set("f", "list");
341             consumer->start();
342             QStringList result;
343             Mlt::Properties vcodecs((mlt_properties) consumer->get_data("vcodec"));
344             for (int i = 0; i < vcodecs.count(); i++)
345                 result << QString(vcodecs.get(i));
346             m_mltCheck.vcodecs_list->addItems(result);
347             KdenliveSettings::setVideocodecs(result);
348             result.clear();
349             Mlt::Properties acodecs((mlt_properties) consumer->get_data("acodec"));
350             for (int i = 0; i < acodecs.count(); i++)
351                 result << QString(acodecs.get(i));
352             m_mltCheck.acodecs_list->addItems(result);
353             KdenliveSettings::setAudiocodecs(result);
354             result.clear();
355             Mlt::Properties formats((mlt_properties) consumer->get_data("f"));
356             for (int i = 0; i < formats.count(); i++)
357                 result << QString(formats.get(i));
358             m_mltCheck.formats_list->addItems(result);
359             KdenliveSettings::setSupportedformats(result);
360             delete consumer;
361         }
362
363         // DV module
364         QTreeWidgetItem *dvItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("DV module (libdv)"));
365         dvItem->setData(1, Qt::UserRole, i18n("Required to work with dv files if avformat module is not installed"));
366         dvItem->setSizeHint(0, itemSize);
367         if (!producersItemList.contains("libdv")) {
368             dvItem->setIcon(0, m_badIcon);
369         }
370         else {
371             dvItem->setIcon(0, m_okIcon);
372         }
373
374         // Image module
375         QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("QImage module"));
376         imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
377         imageItem->setSizeHint(0, itemSize);
378         if (!producersItemList.contains("qimage")) {
379             imageItem->setIcon(0, m_badIcon);
380             imageItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Pixbuf module"));
381             imageItem->setData(1, Qt::UserRole, i18n("Required to work with images"));
382             imageItem->setSizeHint(0, itemSize);
383             if (producersItemList.contains("pixbuf")) {
384                 imageItem->setIcon(0, m_badIcon);
385             }
386             else {
387                 imageItem->setIcon(0, m_okIcon);
388             }
389         }
390         else {
391             imageItem->setIcon(0, m_okIcon);
392         }
393
394         // Titler module
395         QTreeWidgetItem *titleItem = new QTreeWidgetItem(m_mltCheck.programList, QStringList() << QString() << i18n("Title module"));
396         titleItem->setData(1, Qt::UserRole, i18n("Required to work with titles"));
397         titleItem->setSizeHint(0, itemSize);
398         if (!producersItemList.contains("kdenlivetitle")) {
399             KdenliveSettings::setHastitleproducer(false);
400             titleItem->setIcon(0, m_badIcon);
401         } else {
402             titleItem->setIcon(0, m_okIcon);
403             KdenliveSettings::setHastitleproducer(true);
404         }
405     }
406 }
407
408 void Wizard::slotCheckPrograms()
409 {
410     QSize itemSize(20, fontMetrics().height() * 2.5);
411     m_check.programList->setColumnWidth(0, 30);
412     m_check.programList->setIconSize(QSize(24, 24));
413
414     QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
415     item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
416     item->setSizeHint(0, itemSize);
417     QString exepath = KStandardDirs::findExe("ffmpeg");
418     QString playpath = KStandardDirs::findExe("ffplay");
419     item->setIcon(0, m_okIcon);
420     if (exepath.isEmpty()) {
421         // Check for libav version
422         exepath = KStandardDirs::findExe("avconv");
423         if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
424     }
425     if (playpath.isEmpty()) {
426         // Check for libav version
427         playpath = KStandardDirs::findExe("avplay");
428         if (playpath.isEmpty()) item->setIcon(0, m_badIcon);
429     }
430     if (!exepath.isEmpty()) KdenliveSettings::setFfmpegpath(exepath);
431     if (!playpath.isEmpty()) KdenliveSettings::setFfplaypath(playpath);
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" << "*.m2v";
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
649     if (!errorMessage.isEmpty()) {
650         errorMessage.prepend(QString("<b>%1</b><br />").arg(i18n("Fatal Error")));
651         QLabel *pix = new QLabel();
652         pix->setPixmap(KIcon("dialog-error").pixmap(30));
653         QLabel *label = new QLabel(errorMessage);
654         label->setWordWrap(true);
655         m_startLayout->addSpacing(40);
656         m_startLayout->addWidget(pix);
657         m_startLayout->addWidget(label);
658         m_systemCheckIsOk = false;
659         button(QWizard::NextButton)->setEnabled(false);
660     } else m_systemCheckIsOk = true;
661
662     if (m_systemCheckIsOk) checkMltComponents();
663     slotCheckPrograms();
664 }
665
666 bool Wizard::isOk() const
667 {
668     return m_systemCheckIsOk;
669 }
670
671 void Wizard::slotShowWebInfos()
672 {
673     KRun::runUrl(KUrl("http://kdenlive.org/discover/" + QString(kdenlive_version).section(' ', 0, 0)), "text/html", this);
674 }
675
676 void Wizard::slotSaveCaptureFormat()
677 {
678     QStringList format = m_capture.v4l_formats->itemData(m_capture.v4l_formats->currentIndex()).toStringList();
679     if (format.isEmpty()) return;
680     MltVideoProfile profile;
681     profile.description = "Video4Linux capture";
682     profile.colorspace = 601;
683     profile.width = format.at(1).toInt();
684     profile.height = format.at(2).toInt();
685     profile.sample_aspect_num = 1;
686     profile.sample_aspect_den = 1;
687     profile.display_aspect_num = format.at(1).toInt();
688     profile.display_aspect_den = format.at(2).toInt();
689     profile.frame_rate_num = format.at(3).toInt();
690     profile.frame_rate_den = format.at(4).toInt();
691     profile.progressive = 1;
692     QString vl4ProfilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
693     ProfilesDialog::saveProfile(profile, vl4ProfilePath);
694 }
695
696 void Wizard::slotUpdateDecklinkDevice(int captureCard)
697 {
698     KdenliveSettings::setDecklink_capturedevice(captureCard);
699 }
700
701 #include "wizard.moc"