]> git.sesse.net Git - kdenlive/blob - plugins/sampleplugin/sampleplugin.cpp
* Small cmake cleanup
[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 <QtGui>
22 #include <QDialog>
23 #include <QDomDocument>
24
25 #include <KUrlRequester>
26 #include <KIntSpinBox>
27 #include <KDebug>
28 #include <KMessageBox>
29
30 #include "sampleplugin.h"
31 #include "ui_countdown_ui.h"
32
33  QStringList SamplePlugin::generators() const
34  {
35      return QStringList() << tr("Countdown");
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     int ct = 0;
41     QString counter = QString::number(ct).rightJustified(5, '0', false);
42     while (QFile::exists(projectFolder.path() + "/counter" + counter + ".westley")) {
43         ct++;
44         counter = QString::number(ct).rightJustified(5, '0', false);
45     }
46     QDialog d;
47     d.setWindowTitle(tr("Create Countdown Clip"));
48     Ui::CountDown_UI view;
49     view.setupUi(&d);
50     QString clipFile = projectFolder.path() + "/counter" + counter + ".westley";
51     view.path->setPath(clipFile);
52     if (d.exec() == QDialog::Accepted) {
53         QDomDocument doc;
54         QDomElement westley = doc.createElement("westley");
55         QDomElement playlist = doc.createElement("playlist");
56         for (int i = 0; i < view.duration->value(); i++) {
57             // Create the producers
58             QDomElement prod = doc.createElement("producer");
59             prod.setAttribute("mlt_service", "pango");
60             prod.setAttribute("in", "0");
61             prod.setAttribute("out", QString::number((int) fps));
62             prod.setAttribute("markup", QString::number(view.duration->value() - i));
63             playlist.appendChild(prod);
64         }
65         westley.appendChild(playlist);
66         doc.appendChild(westley);
67         QFile file(view.path->url().path());
68         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
69             kWarning() << "//////  ERROR writing to file: " << view.path->url().path();
70             KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
71             return KUrl();
72         }
73         QTextStream out(&file);
74         out << doc.toString();
75         file.close();
76         return view.path->url();
77     }
78     return KUrl();
79 }
80
81 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)