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 QString clipFile = prePath + counter + ".mlt";
67 view.path->setPath(clipFile);
68 if (d.exec() == QDialog::Accepted) {
70 QDomElement mlt = doc.createElement("mlt");
71 QDomElement playlist = doc.createElement("playlist");
72 if (generator == i18n("Noise")) {
73 QDomElement prod = doc.createElement("producer");
74 prod.setAttribute("mlt_service", "noise");
75 prod.setAttribute("in", "0");
76 prod.setAttribute("out", QString::number((int) fps * view.duration->value()));
77 playlist.appendChild(prod);
79 for (int i = 0; i < view.duration->value(); i++) {
80 // Create the producers
81 QDomElement prod = doc.createElement("producer");
82 prod.setAttribute("mlt_service", "pango");
83 prod.setAttribute("in", "0");
84 prod.setAttribute("out", QString::number((int) fps));
85 prod.setAttribute("text", QString::number(view.duration->value() - i));
86 //FIXME: the font and pad values are approximate, the pango producer seems unable
87 // to produce a predictable frame size.
88 prod.setAttribute("font", QString::number(view.font->value()) + "px");
89 //prod.setAttribute("pad", 50);
90 playlist.appendChild(prod);
93 mlt.appendChild(playlist);
95 QFile file(view.path->url().path());
96 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
97 kWarning() << "////// ERROR writing to file: " << view.path->url().path();
98 KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
101 QTextStream out(&file);
102 out << doc.toString();
103 if (file.error() != QFile::NoError) {
104 KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
109 return view.path->url();
114 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)