]> git.sesse.net Git - kdenlive/blob - plugins/sampleplugin/sampleplugin.cpp
bdec16e54396653f29f46c51f357cb01a13328c8
[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
34 {
35     return QStringList() << i18n("Countdown") << i18n("Noise");
36 }
37
38
39 KUrl SamplePlugin::generatedClip(const QString &generator, const KUrl &projectFolder, const QStringList &/*lumaNames*/, const QStringList &/*lumaFiles*/, const double fps, const int /*width*/, const int /*height*/)
40 {
41     QString prePath;
42     if (generator == i18n("Noise")) {
43         prePath = projectFolder.path() + "/noise";
44     } else prePath = projectFolder.path() + "/counter";
45     int ct = 0;
46     QString counter = QString::number(ct).rightJustified(5, '0', false);
47     while (QFile::exists(prePath + counter + ".westley")) {
48         ct++;
49         counter = QString::number(ct).rightJustified(5, '0', false);
50     }
51     QDialog d;
52     if (generator == i18n("Noise")) d.setWindowTitle(tr("Create Noise Clip"));
53     else d.setWindowTitle(tr("Create Countdown Clip"));
54     Ui::CountDown_UI view;
55     view.setupUi(&d);
56     QString clipFile = prePath + counter + ".westley";
57     view.path->setPath(clipFile);
58     if (d.exec() == QDialog::Accepted) {
59         QDomDocument doc;
60         QDomElement westley = doc.createElement("westley");
61         QDomElement playlist = doc.createElement("playlist");
62         if (generator == i18n("Noise")) {
63             QDomElement prod = doc.createElement("producer");
64             prod.setAttribute("mlt_service", "noise");
65             prod.setAttribute("in", "0");
66             prod.setAttribute("out", QString::number((int) fps * view.duration->value()));
67             playlist.appendChild(prod);
68         } else {
69             for (int i = 0; i < view.duration->value(); i++) {
70                 // Create the producers
71                 QDomElement prod = doc.createElement("producer");
72                 prod.setAttribute("mlt_service", "pango");
73                 prod.setAttribute("in", "0");
74                 prod.setAttribute("out", QString::number((int) fps));
75                 prod.setAttribute("markup", QString::number(view.duration->value() - i));
76                 playlist.appendChild(prod);
77             }
78         }
79         westley.appendChild(playlist);
80         doc.appendChild(westley);
81         QFile file(view.path->url().path());
82         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
83             kWarning() << "//////  ERROR writing to file: " << view.path->url().path();
84             KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
85             return KUrl();
86         }
87         QTextStream out(&file);
88         out << doc.toString();
89         if (file.error() != QFile::NoError) {
90             KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
91             file.close();
92             return KUrl();
93         }
94         file.close();
95         return view.path->url();
96     }
97     return KUrl();
98 }
99
100 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)