1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
22 #include <QXmlStreamWriter>
23 #include <QApplication>
26 #include <KStandardDirs>
29 #include <kmimetype.h>
31 #include "kdenlivesettings.h"
32 #include "profilesdialog.h"
35 Wizard::Wizard(QWidget *parent): QWizard(parent) {
36 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
38 QWizardPage *page1 = new QWizardPage;
39 page1->setTitle(i18n("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);
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()));
54 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
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()));
67 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
70 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
71 QString mimefile = baseName;
72 mimefile.replace('/', '-');
73 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
75 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
77 QStringList extensions = mime->patterns();
78 QString comment = mime->comment();
79 foreach(const QString &glob, globs) {
80 if (!extensions.contains(glob)) extensions << glob;
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";
90 QXmlStreamWriter writer(&packageFile);
91 writer.setAutoFormatting(true);
92 writer.writeStartDocument();
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);
100 if (!comment.isEmpty()) {
101 writer.writeStartElement(nsUri, "comment");
102 writer.writeCharacters(comment);
103 writer.writeEndElement(); // comment
106 foreach(const QString& pattern, extensions) {
107 writer.writeStartElement(nsUri, "glob");
108 writer.writeAttribute("pattern", pattern);
109 writer.writeEndElement(); // glob
112 writer.writeEndElement(); // mime-info
113 writer.writeEndElement(); // mime-type
114 writer.writeEndDocument();
118 void Wizard::runUpdateMimeDatabase() {
119 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
120 //Q_ASSERT(!localPackageDir.isEmpty());
122 proc << "update-mime-database";
123 proc << localPackageDir;
124 const int exitCode = proc.execute();
126 kWarning() << proc.program() << "exited with error code" << exitCode;
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";
140 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
143 void Wizard::slotCheckStandard() {
144 QStringList profiles;
145 if (m_standard.button_pal->isChecked()) {
147 if (m_standard.button_dv->isChecked()) {
148 profiles << "dv_pal" << "dv_pal_wide";
150 profiles << "hdv_720_25p" << "hdv_720_50p" << "hdv_1080_50i" << "hdv_1080_25p" << "atsc_1080p_24" << "atsc_1080p_25";
154 if (m_standard.button_dv->isChecked()) {
155 profiles << "dv_ntsc" << "dv_ntsc_wide";
157 profiles << "hdv_720_30p" << "hdv_720_60p" << "hdv_1080_30p" << "hdv_1080_60i" << "atsc_720p_30" << "atsc_1080i_60";
160 m_standard.profiles_list->clear();
161 QStringList profilesDescription;
162 foreach(const QString &prof, profiles) {
163 QString desc = ProfilesDialog::getProfileDescription(prof);
164 if (!desc.isEmpty()) {
165 QListWidgetItem *item = new QListWidgetItem(desc, m_standard.profiles_list);
166 item->setData(Qt::UserRole, prof);
169 m_standard.profiles_list->setSortingEnabled(true);
170 m_standard.profiles_list->setCurrentRow(0);
173 void Wizard::slotCheckSelectedItem() {
174 // Make sure we always have an item highlighted
175 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
179 void Wizard::adjustSettings() {
180 if (m_extra.installmimes->isChecked()) {
182 globs << "*.mts" << "*.m2t" << "*.mod";
183 installExtraMimes("video/mpeg", globs);
186 installExtraMimes("video/dv", globs);
187 runUpdateMimeDatabase();
189 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
190 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
191 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
192 if (m_standard.profiles_list->currentItem()) {
193 KdenliveSettings::setDefault_profile(m_standard.profiles_list->currentItem()->data(Qt::UserRole).toString());
197 void Wizard::slotCheckMlt() {
198 QString errorMessage;
199 if (KdenliveSettings::rendererpath().isEmpty()) {
200 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
202 QProcess checkProcess;
203 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
204 if (!checkProcess.waitForStarted())
205 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
207 checkProcess.waitForFinished();
209 QByteArray result = checkProcess.readAllStandardError();
210 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");
212 QProcess checkProcess2;
213 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
214 if (!checkProcess2.waitForStarted())
215 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + "\n");
217 checkProcess2.waitForFinished();
219 result = checkProcess2.readAllStandardError();
220 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");
222 if (!errorMessage.isEmpty()) {
223 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
224 QLabel *pix = new QLabel();
225 pix->setPixmap(KIcon("dialog-error").pixmap(30));
226 QLabel *label = new QLabel(errorMessage);
227 label->setWordWrap(true);
228 m_startLayout->addSpacing(40);
229 m_startLayout->addWidget(pix);
230 m_startLayout->addWidget(label);
231 m_systemCheckIsOk = false;
232 button(QWizard::NextButton)->setEnabled(false);
233 } else m_systemCheckIsOk = true;
236 bool Wizard::isOk() const {
237 return m_systemCheckIsOk;
240 #include "wizard.moc"