]> git.sesse.net Git - kdenlive/blob - plugins/sampleplugin/sampleplugin.cpp
Adjust plugin to show only when used producer is present, hack around resulting count...
[kdenlive] / plugins / sampleplugin / sampleplugin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include "sampleplugin.h"
22 #include "ui_countdown_ui.h"
23
24 #include <KUrlRequester>
25 #include <KIntSpinBox>
26 #include <KDebug>
27 #include <KMessageBox>
28
29 #include <QDialog>
30 #include <QDomDocument>
31 #include <QInputDialog>
32
33 QStringList SamplePlugin::generators(const QStringList producers) const
34 {
35     QStringList result;
36     if (producers.contains("pango")) result << i18n("Countdown");
37     if (producers.contains("noise")) result << i18n("Noise");
38     return result;
39 }
40
41
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)
43 {
44     QString prePath;
45     if (generator == i18n("Noise")) {
46         prePath = projectFolder.path() + "/noise";
47     } else prePath = projectFolder.path() + "/counter";
48     int ct = 0;
49     QString counter = QString::number(ct).rightJustified(5, '0', false);
50     while (QFile::exists(prePath + counter + ".westley")) {
51         ct++;
52         counter = QString::number(ct).rightJustified(5, '0', false);
53     }
54     QDialog d;
55     Ui::CountDown_UI view;
56     view.setupUi(&d);
57     if (generator == i18n("Noise")) {
58         d.setWindowTitle(tr("Create Noise Clip"));
59         view.font_label->setHidden(true);
60         view.font->setHidden(true);
61     } else {
62         d.setWindowTitle(tr("Create Countdown Clip"));
63         view.font->setValue(height);
64     }
65
66     QString clipFile = prePath + counter + ".westley";
67     view.path->setPath(clipFile);
68     if (d.exec() == QDialog::Accepted) {
69         QDomDocument doc;
70         QDomElement westley = doc.createElement("westley");
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);
78         } else {
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);
91             }
92         }
93         westley.appendChild(playlist);
94         doc.appendChild(westley);
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()));
99             return KUrl();
100         }
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()));
105             file.close();
106             return KUrl();
107         }
108         file.close();
109         return view.path->url();
110     }
111     return KUrl();
112 }
113
114 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)