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("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_1080_50i";
154 if (m_standard.button_dv->isChecked()) {
155 profiles << "dv_ntsc" << "dv_ntsc_wide";
157 profiles << "hdv_720_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 QListWidgetItem *item = new QListWidgetItem(ProfilesDialog::getProfileDescription(prof), m_standard.profiles_list);
164 item->setData(Qt::UserRole, prof);
166 m_standard.profiles_list->setCurrentRow(0);
169 void Wizard::slotCheckSelectedItem() {
170 // Make sure we always have an item highlighted
171 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
175 void Wizard::adjustSettings() {
176 if (m_extra.installmimes->isChecked()) {
178 globs << "*.mts" << "*.m2t";
179 installExtraMimes("video/mpeg", globs);
182 installExtraMimes("video/dv", globs);
183 runUpdateMimeDatabase();
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());
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"));
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");
203 checkProcess.waitForFinished();
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"));
208 QProcess checkProcess2;
209 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
210 if (!checkProcess2.waitForStarted())
211 errorMessage.append("Error starting MLT's command line player (inigo).\n");
213 checkProcess2.waitForFinished();
215 result = checkProcess2.readAllStandardError();
216 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"));
218 if (!errorMessage.isEmpty()) {
219 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
220 QLabel *pix = new QLabel();
221 pix->setPixmap(KIcon("dialog-error").pixmap(30));
222 QLabel *label = new QLabel(errorMessage);
223 label->setWordWrap(true);
224 m_startLayout->addSpacing(40);
225 m_startLayout->addWidget(pix);
226 m_startLayout->addWidget(label);
227 m_systemCheckIsOk = false;
228 button(QWizard::NextButton)->setEnabled(false);
229 } else m_systemCheckIsOk = true;
232 bool Wizard::isOk() const {
233 return m_systemCheckIsOk;
236 #include "wizard.moc"