1 /***************************************************************************
2 * Copyright (C) 2009 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 "sampleplugin.h"
22 #include "ui_countdown_ui.h"
24 #include <KUrlRequester>
25 #include <KIntSpinBox>
27 #include <KMessageBox>
30 #include <QDomDocument>
31 #include <QInputDialog>
33 QStringList SamplePlugin::generators(const QStringList producers) const
36 if (producers.contains("pango")) result << i18n("Countdown");
37 if (producers.contains("noise")) result << i18n("Noise");
42 KUrl SamplePlugin::generatedClip(const QString &generator, const KUrl &projectFolder, const QStringList &/*lumaNames*/, const QStringList &/*lumaFiles*/, const double fps, const int /*width*/, const int height)
45 if (generator == i18n("Noise")) {
46 prePath = projectFolder.path() + "/noise";
47 } else prePath = projectFolder.path() + "/counter";
49 QString counter = QString::number(ct).rightJustified(5, '0', false);
50 while (QFile::exists(prePath + counter + ".mlt")) {
52 counter = QString::number(ct).rightJustified(5, '0', false);
55 Ui::CountDown_UI view;
57 if (generator == i18n("Noise")) {
58 d.setWindowTitle(tr("Create Noise Clip"));
59 view.font_label->setHidden(true);
60 view.font->setHidden(true);
62 d.setWindowTitle(tr("Create Countdown Clip"));
63 view.font->setValue(height);
66 // Set single file mode. Default seems to be File::ExistingOnly.
67 view.path->setMode(KFile::File);
69 QString clipFile = prePath + counter + ".mlt";
70 view.path->setUrl(KUrl(clipFile));
71 if (d.exec() == QDialog::Accepted) {
73 QDomElement mlt = doc.createElement("mlt");
74 QDomElement playlist = doc.createElement("playlist");
75 if (generator == i18n("Noise")) {
76 QDomElement prod = doc.createElement("producer");
77 prod.setAttribute("mlt_service", "noise");
78 prod.setAttribute("in", "0");
79 prod.setAttribute("out", QString::number((int) fps * view.duration->value()));
80 prod.setAttribute("resource", "<producer>");
81 playlist.appendChild(prod);
83 for (int i = 0; i < view.duration->value(); i++) {
84 // Create the producers
85 QDomElement prod = doc.createElement("producer");
86 prod.setAttribute("mlt_service", "pango");
87 prod.setAttribute("in", "0");
88 prod.setAttribute("out", QString::number((int) fps));
89 prod.setAttribute("text", QString::number(view.duration->value() - i));
90 prod.setAttribute("resource", "<producer>");
91 //FIXME: the font and pad values are approximate, the pango producer seems unable
92 // to produce a predictable frame size.
93 prod.setAttribute("font", QString::number(view.font->value()) + "px");
94 //prod.setAttribute("pad", 50);
95 playlist.appendChild(prod);
98 mlt.appendChild(playlist);
100 QFile file(view.path->url().path());
101 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
102 kWarning() << "////// ERROR writing to file: " << view.path->url().path();
103 KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
106 QTextStream out(&file);
107 out << doc.toString();
108 if (file.error() != QFile::NoError) {
109 KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
114 return view.path->url();
119 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)