]> git.sesse.net Git - kdenlive/blob - src/wizard.cpp
Check that MLT's avformat is ok at first start, it should help detect startup crashes...
[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 <QLabel>
21 #include <QFile>
22 #include <QXmlStreamWriter>
23 #include <QApplication>
24 #include <QTimer>
25
26 #include <KStandardDirs>
27 #include <KLocale>
28 #include <KProcess>
29 #include <kmimetype.h>
30
31 #include "kdenlivesettings.h"
32 #include "profilesdialog.h"
33 #include "wizard.h"
34
35 Wizard::Wizard(QWidget *parent): QWizard(parent) {
36     setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
37
38     QWizardPage *page1 = new QWizardPage;
39     page1->setTitle("Welcome");
40     QLabel *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..."));
41     label->setWordWrap(true);
42     m_startLayout = new QVBoxLayout;
43     m_startLayout->addWidget(label);
44     page1->setLayout(m_startLayout);
45     addPage(page1);
46
47     QWizardPage *page2 = new QWizardPage;
48     page2->setTitle(i18n("Video Standard"));
49     m_standard.setupUi(page2);
50     m_standard.profiles_list->setMaximumHeight(100);
51     connect(m_standard.button_pal, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
52     connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
53     slotCheckStandard();
54     connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
55     addPage(page2);
56
57     QWizardPage *page3 = new QWizardPage;
58     page3->setTitle(i18n("Additional Settings"));
59     m_extra.setupUi(page3);
60     m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
61     m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
62     m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
63     connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
64     connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
65     slotCheckThumbs();
66     addPage(page3);
67     QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
68 }
69
70 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
71     QString mimefile = baseName;
72     mimefile.replace('/', '-');
73     KMimeType::Ptr mime = KMimeType::mimeType(baseName);
74     if (!mime) {
75         kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
76     } else {
77         QStringList extensions = mime->patterns();
78         QString comment = mime->comment();
79         foreach(const QString &glob, globs) {
80             if (!extensions.contains(glob)) extensions << glob;
81         }
82         kDebug() << "EXTS: " << extensions;
83         QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
84         kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
85         QFile packageFile(packageFileName);
86         if (!packageFile.open(QIODevice::WriteOnly)) {
87             kError() << "Couldn't open" << packageFileName << "for writing";
88             return;
89         }
90         QXmlStreamWriter writer(&packageFile);
91         writer.setAutoFormatting(true);
92         writer.writeStartDocument();
93
94         const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
95         writer.writeDefaultNamespace(nsUri);
96         writer.writeStartElement("mime-info");
97         writer.writeStartElement(nsUri, "mime-type");
98         writer.writeAttribute("type", baseName);
99
100         if (!comment.isEmpty()) {
101             writer.writeStartElement(nsUri, "comment");
102             writer.writeCharacters(comment);
103             writer.writeEndElement(); // comment
104         }
105
106         foreach(const QString& pattern, extensions) {
107             writer.writeStartElement(nsUri, "glob");
108             writer.writeAttribute("pattern", pattern);
109             writer.writeEndElement(); // glob
110         }
111
112         writer.writeEndElement(); // mime-info
113         writer.writeEndElement(); // mime-type
114         writer.writeEndDocument();
115     }
116 }
117
118 void Wizard::runUpdateMimeDatabase() {
119     const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
120     //Q_ASSERT(!localPackageDir.isEmpty());
121     KProcess proc;
122     proc << "update-mime-database";
123     proc << localPackageDir;
124     const int exitCode = proc.execute();
125     if (exitCode) {
126         kWarning() << proc.program() << "exited with error code" << exitCode;
127     }
128 }
129
130 void Wizard::slotCheckThumbs() {
131     QString pixname = "timeline_vthumbs.png";
132     if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
133         pixname = "timeline_nothumbs.png";
134     } else if (m_extra.audiothumbs->isChecked()) {
135         if (m_extra.videothumbs->isChecked())
136             pixname = "timeline_avthumbs.png";
137         else pixname = "timeline_athumbs.png";
138     }
139
140     m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
141 }
142
143 void Wizard::slotCheckStandard() {
144     QStringList profiles;
145     if (m_standard.button_pal->isChecked()) {
146         // PAL standard
147         if (m_standard.button_dv->isChecked()) {
148             profiles << "dv_pal" << "dv_pal_wide";
149         } else {
150             profiles << "hdv_720_25p" << "hdv_1080_50i";
151         }
152     } else {
153         // NTSC standard
154         if (m_standard.button_dv->isChecked()) {
155             profiles << "dv_ntsc" << "dv_ntsc_wide";
156         } else {
157             profiles << "hdv_720_30p" << "hdv_1080_60i" << "atsc_720p_30" << "atsc_1080i_60";
158         }
159     }
160     m_standard.profiles_list->clear();
161     QStringList profilesDescription;
162     foreach(const QString &prof, profiles) {
163         QListWidgetItem *item = new QListWidgetItem(ProfilesDialog::getProfileDescription(prof), m_standard.profiles_list);
164         item->setData(Qt::UserRole, prof);
165     }
166     m_standard.profiles_list->setCurrentRow(0);
167 }
168
169 void Wizard::slotCheckSelectedItem() {
170     // Make sure we always have an item highlighted
171     m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
172 }
173
174
175 void Wizard::adjustSettings() {
176     if (m_extra.installmimes->isChecked()) {
177         QStringList globs;
178         globs << "*.mts" << "*.m2t";
179         installExtraMimes("video/mpeg", globs);
180         globs.clear();
181         globs << "*.dv";
182         installExtraMimes("video/dv", globs);
183         runUpdateMimeDatabase();
184     }
185     KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
186     KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
187     KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
188     if (m_standard.profiles_list->currentItem()) {
189         KdenliveSettings::setDefault_profile(m_standard.profiles_list->currentItem()->data(Qt::UserRole).toString());
190     }
191 }
192
193 void Wizard::slotCheckMlt() {
194     QString errorMessage;
195     if (KdenliveSettings::rendererpath().isEmpty()) {
196         errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
197     }
198     QProcess checkProcess;
199     checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
200     if (!checkProcess.waitForStarted())
201         errorMessage.append("Error starting MLT's command line player (inigo).\n");
202
203     checkProcess.waitForFinished();
204
205     QByteArray result = checkProcess.readAllStandardError();
206     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"));
207
208     if (!errorMessage.isEmpty()) {
209         QLabel *pix = new QLabel();
210         pix->setPixmap(KIcon("process-stop").pixmap(30));
211         QLabel *label = new QLabel(errorMessage);
212         label->setWordWrap(true);
213         m_startLayout->addSpacing(40);
214         m_startLayout->addWidget(pix);
215         m_startLayout->addWidget(label);
216         m_systemCheckIsOk = false;
217         button(QWizard::NextButton)->setEnabled(false);
218     } else m_systemCheckIsOk = true;
219 }
220
221 bool Wizard::isOk() const {
222     return m_systemCheckIsOk;
223 }
224
225 #include "wizard.moc"