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 ***************************************************************************/
21 #include <QVBoxLayout>
23 #include <QXmlStreamWriter>
25 #include <KStandardDirs>
28 #include <kmimetype.h>
30 #include "kdenlivesettings.h"
31 #include "profilesdialog.h"
34 Wizard::Wizard(QWidget *parent): QWizard(parent) {
35 setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
37 QWizardPage *page1 = new QWizardPage;
38 page1->setTitle("Welcome");
39 QLabel *label = new QLabel("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...");
40 label->setWordWrap(true);
41 QVBoxLayout *layout = new QVBoxLayout;
42 layout->addWidget(label);
43 page1->setLayout(layout);
46 QWizardPage *page2 = new QWizardPage;
47 page2->setTitle("Video Standard");
48 m_standard.setupUi(page2);
49 m_standard.profiles_list->setMaximumHeight(100);
50 connect(m_standard.button_pal, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
51 connect(m_standard.button_dv, SIGNAL(toggled(bool)), this, SLOT(slotCheckStandard()));
53 connect(m_standard.profiles_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckSelectedItem()));
56 QWizardPage *page3 = new QWizardPage;
57 page3->setTitle("Additional Settings");
58 m_extra.setupUi(page3);
59 m_extra.videothumbs->setChecked(KdenliveSettings::videothumbnails());
60 m_extra.audiothumbs->setChecked(KdenliveSettings::audiothumbnails());
61 m_extra.autosave->setChecked(KdenliveSettings::crashrecovery());
62 connect(m_extra.videothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
63 connect(m_extra.audiothumbs, SIGNAL(stateChanged(int)), this, SLOT(slotCheckThumbs()));
68 void Wizard::installExtraMimes(QString baseName, QStringList globs) {
69 QString mimefile = baseName;
70 mimefile.replace('/', '-');
71 KMimeType::Ptr mime = KMimeType::mimeType(baseName);
73 kDebug() << "KMimeTypeTrader: mimeType " << baseName << " not found";
75 QStringList extensions = mime->patterns();
76 QString comment = mime->comment();
77 foreach(const QString &glob, globs) {
78 if (!extensions.contains(glob)) extensions << glob;
80 kDebug() << "EXTS: " << extensions;
81 QString packageFileName = KStandardDirs::locateLocal("xdgdata-mime", "packages/" + mimefile + ".xml");
82 kDebug() << "INSTALLING NEW MIME TO: " << packageFileName;
83 QFile packageFile(packageFileName);
84 if (!packageFile.open(QIODevice::WriteOnly)) {
85 kError() << "Couldn't open" << packageFileName << "for writing";
88 QXmlStreamWriter writer(&packageFile);
89 writer.setAutoFormatting(true);
90 writer.writeStartDocument();
92 const QString nsUri = "http://www.freedesktop.org/standards/shared-mime-info";
93 writer.writeDefaultNamespace(nsUri);
94 writer.writeStartElement("mime-info");
95 writer.writeStartElement(nsUri, "mime-type");
96 writer.writeAttribute("type", baseName);
98 if (!comment.isEmpty()) {
99 writer.writeStartElement(nsUri, "comment");
100 writer.writeCharacters(comment);
101 writer.writeEndElement(); // comment
104 foreach(const QString& pattern, extensions) {
105 writer.writeStartElement(nsUri, "glob");
106 writer.writeAttribute("pattern", pattern);
107 writer.writeEndElement(); // glob
110 writer.writeEndElement(); // mime-info
111 writer.writeEndElement(); // mime-type
112 writer.writeEndDocument();
116 void Wizard::runUpdateMimeDatabase() {
117 const QString localPackageDir = KStandardDirs::locateLocal("xdgdata-mime", QString());
118 Q_ASSERT(!localPackageDir.isEmpty());
120 proc << "update-mime-database";
121 proc << localPackageDir;
122 const int exitCode = proc.execute();
124 kWarning() << proc.program() << "exited with error code" << exitCode;
128 void Wizard::slotCheckThumbs() {
129 QString pixname = "timeline_vthumbs.png";
130 if (!m_extra.audiothumbs->isChecked() && !m_extra.videothumbs->isChecked()) {
131 pixname = "timeline_nothumbs.png";
132 } else if (m_extra.audiothumbs->isChecked()) {
133 if (m_extra.videothumbs->isChecked())
134 pixname = "timeline_avthumbs.png";
135 else pixname = "timeline_athumbs.png";
138 m_extra.timeline_preview->setPixmap(QPixmap(KStandardDirs::locate("appdata", pixname)));
141 void Wizard::slotCheckStandard() {
142 QStringList profiles;
143 if (m_standard.button_pal->isChecked()) {
145 if (m_standard.button_dv->isChecked()) {
146 profiles << "dv_pal" << "dv_pal_wide";
148 profiles << "hdv_720_25p" << "hdv_1080_50i";
152 if (m_standard.button_dv->isChecked()) {
153 profiles << "dv_ntsc" << "dv_ntsc_wide";
155 profiles << "hdv_720_30p" << "hdv_1080_60i" << "atsc_720p_30" << "atsc_1080i_60";
158 m_standard.profiles_list->clear();
159 QStringList profilesDescription;
160 foreach(const QString &prof, profiles) {
161 QListWidgetItem *item = new QListWidgetItem(ProfilesDialog::getProfileDescription(prof), m_standard.profiles_list);
162 item->setData(Qt::UserRole, prof);
164 m_standard.profiles_list->setCurrentRow(0);
167 void Wizard::slotCheckSelectedItem() {
168 // Make sure we always have an item highlighted
169 m_standard.profiles_list->setCurrentRow(m_standard.profiles_list->currentRow());
173 void Wizard::adjustSettings() {
174 if (m_extra.installmimes->isChecked()) {
176 globs << "*.mts" << "*.m2t";
177 installExtraMimes("video/mpeg", globs);
180 installExtraMimes("video/dv", globs);
181 runUpdateMimeDatabase();
183 KdenliveSettings::setAudiothumbnails(m_extra.audiothumbs->isChecked());
184 KdenliveSettings::setVideothumbnails(m_extra.videothumbs->isChecked());
185 KdenliveSettings::setCrashrecovery(m_extra.autosave->isChecked());
186 if (m_standard.profiles_list->currentItem()) {
187 KdenliveSettings::setDefault_profile(m_standard.profiles_list->currentItem()->data(Qt::UserRole).toString());
191 #include "wizard.moc"