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 // build profiles lists
52 m_profilesInfo = ProfilesDialog::getProfilesInfo();
53 QMap<QString, QString>::const_iterator i = m_profilesInfo.constBegin();
54 while (i != m_profilesInfo.constEnd()) {
55 QMap< QString, QString > profileData = ProfilesDialog::getSettingsFromFile(i.value());
56 if (profileData.value("width") == "720") m_dvProfiles.append(i.key());
57 else if (profileData.value("width").toInt() >= 1080) m_hdvProfiles.append(i.key());
58 else m_otherProfiles.append(i.key());
62 connect(m_standard.button_all, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
63 connect(m_standard.button_hdv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
64 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
66 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
69 QWizardPage *page3 = new QWizardPage;
70 page3->setTitle(i18n("Additional Settings"));
71 m_extra.setupUi(page3);
72 m_extra.projectfolder->setMode(KFile::Directory);
73 m_extra.projectfolder->setPath(QDir::homePath() + "/kdenlive");
74 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
75 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
76 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
77 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
78 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
81 QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
84 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
85 QString mimefile = baseName;
86 mimefile.replace('/', '-');
87 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
89 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
91 QStringList extensions = mime->patterns();
92 QString comment = mime->comment();
93 foreach(const QString &glob, globs) {
94 if (!extensions.contains(glob)) extensions << glob;
96 kDebug() << "EXTS: " << extensions;
97 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
98 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
99 QFile packageFile(packageFileName);
100 if (!packageFile.open(QIODevice::WriteOnly)) {
101 kError() << "Couldn't open" << packageFileName << "for writing";
104 QXmlStreamWriter writer(&packageFile);
105 writer.setAutoFormatting(true);
106 writer.writeStartDocument();
108 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
109 writer.writeDefaultNamespace(nsUri);
110 writer.writeStartElement("mime-info");
111 writer.writeStartElement(nsUri, "mime-type");
112 writer.writeAttribute("type", baseName);
114 if (!comment.isEmpty()) {
115 writer.writeStartElement(nsUri, "comment");
116 writer.writeCharacters(comment);
117 writer.writeEndElement(); // comment
120 foreach(const QString& pattern, extensions) {
121 writer.writeStartElement(nsUri, "glob");
122 writer.writeAttribute("pattern", pattern);
123 writer.writeEndElement(); // glob
126 writer.writeEndElement(); // mime-info
127 writer.writeEndElement(); // mime-type
128 writer.writeEndDocument();
132 void Wizard::runUpdateMimeDatabase() {
133 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
134 //Q_ASSERT(!localPackageDir.isEmpty());
136 proc << "update-mime-database";
137 proc << localPackageDir;
138 const int exitCode = proc.execute();
140 kWarning() << proc.program() << "exited with error code" << exitCode;
144 void Wizard::slotCheckThumbs() {
145 QString pixname = "timeline_vthumbs.png";
146 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
147 pixname = "timeline_nothumbs.png";
148 } else if (m_extra.audiothumbs->isChecked()) {
149 if (m_extra.videothumbs->isChecked())
150 pixname = "timeline_avthumbs.png";
151 else pixname = "timeline_athumbs.png";
154 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
157 void Wizard::slotCheckStandard() {
158 m_standard.profiles_list->clear();
159 QStringList profiles;
160 if (m_standard.button_dv->isChecked()) {
162 m_standard.profiles_list->addItems(m_dvProfiles);
163 } else if (m_standard.button_hdv->isChecked()) {
165 m_standard.profiles_list->addItems(m_hdvProfiles);
167 m_standard.profiles_list->addItems(m_dvProfiles);
168 m_standard.profiles_list->addItems(m_hdvProfiles);
169 m_standard.profiles_list->addItems(m_otherProfiles);
170 //m_standard.profiles_list->sortItems();
173 for (int i = 0; i < m_standard.profiles_list->count(); i++) {
174 QListWidgetItem *item = m_standard.profiles_list->item(i);
175 MltVideoProfile prof = ProfilesDialog::getVideoProfile(m_profilesInfo.value(item->text()));
176 const QString infoString = i18n("<b>Frame size:</b>%1x%2<br><b>Frame rate:</b>%3/%4<br><b>Aspect ratio:</b>%5/%6<br><b>Display ratio:</b>%7/%8").arg(QString::number(prof.width), QString::number(prof.height), QString::number(prof.frame_rate_num), QString::number(prof.frame_rate_den), QString::number(prof.sample_aspect_num), QString::number(prof.sample_aspect_den), QString::number(prof.display_aspect_num), QString::number(prof.display_aspect_den));
177 item->setToolTip(infoString);
180 m_standard.profiles_list->setSortingEnabled(true);
181 m_standard.profiles_list->setCurrentRow(0);
184 void Wizard::slotCheckSelectedItem() {
185 // Make sure we always have an item highlighted
186 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
190 void Wizard::adjustSettings() {
191 if (m_extra.installmimes->isChecked()) {
193 globs << "*.mts" << "*.m2t" << "*.mod" << "*.ts";
194 installExtraMimes("video/mpeg", globs);
197 installExtraMimes("video/dv", globs);
198 runUpdateMimeDatabase();
200 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
201 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
202 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
203 if (m_standard.profiles_list->currentItem()) {
204 QString selectedProfile = m_profilesInfo.value(m_standard.profiles_list->currentItem()->text());
205 if (selectedProfile.isEmpty()) selectedProfile = "dv_pal";
206 KdenliveSettings::setDefault_profile(selectedProfile);
208 QString path = m_extra.projectfolder->url().path();
209 if (KStandardDirs::makeDir(path) == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
210 KdenliveSettings::setDefaultprojectfolder(path);
214 void Wizard::slotCheckMlt() {
215 QString errorMessage;
216 if (KdenliveSettings::rendererpath().isEmpty()) {
217 errorMessage.append(i18n("your MLT installation cannot be found. Install MLT and restart Kdenlive.\n"));
219 QProcess checkProcess;
220 checkProcess.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "producer");
221 if (!checkProcess.waitForStarted())
222 errorMessage.append(i18n("Error starting MLT's command line player (inigo)") + ".\n");
224 checkProcess.waitForFinished();
226 QByteArray result = checkProcess.readAllStandardError();
227 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");
229 QProcess checkProcess2;
230 checkProcess2.start(KdenliveSettings::rendererpath(), QStringList() << "-query" << "consumer");
231 if (!checkProcess2.waitForStarted())
232 errorMessage.append(i18n("Error starting MLT's command line player (inigo).") + "\n");
234 checkProcess2.waitForFinished();
236 result = checkProcess2.readAllStandardError();
237 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");
239 if (!errorMessage.isEmpty()) {
240 errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
241 QLabel *pix = new QLabel();
242 pix->setPixmap(KIcon("dialog-error").pixmap(30));
243 QLabel *label = new QLabel(errorMessage);
244 label->setWordWrap(true);
245 m_startLayout->addSpacing(40);
246 m_startLayout->addWidget(pix);
247 m_startLayout->addWidget(label);
248 m_systemCheckIsOk = false;
249 button(QWizard::NextButton)->setEnabled(false);
250 } else m_systemCheckIsOk = true;
253 bool Wizard::isOk() const {
254 return m_systemCheckIsOk;
257 #include "wizard.moc"