[b2caea]: / plugins / sampleplugin / sampleplugin.cpp  Maximize  Restore  History

Download this file

118 lines (107 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
* Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "sampleplugin.h"
#include "ui_countdown_ui.h"
#include <KUrlRequester>
#include <KIntSpinBox>
#include <KDebug>
#include <KMessageBox>
#include <QDialog>
#include <QDomDocument>
#include <QInputDialog>
QStringList SamplePlugin::generators(const QStringList producers) const
{
QStringList result;
if (producers.contains("pango")) result << i18n("Countdown");
if (producers.contains("noise")) result << i18n("Noise");
return result;
}
KUrl SamplePlugin::generatedClip(const QString &generator, const KUrl &projectFolder, const QStringList &/*lumaNames*/, const QStringList &/*lumaFiles*/, const double fps, const int /*width*/, const int height)
{
QString prePath;
if (generator == i18n("Noise")) {
prePath = projectFolder.path() + "/noise";
} else prePath = projectFolder.path() + "/counter";
int ct = 0;
QString counter = QString::number(ct).rightJustified(5, '0', false);
while (QFile::exists(prePath + counter + ".mlt")) {
ct++;
counter = QString::number(ct).rightJustified(5, '0', false);
}
QDialog d;
Ui::CountDown_UI view;
view.setupUi(&d);
if (generator == i18n("Noise")) {
d.setWindowTitle(tr("Create Noise Clip"));
view.font_label->setHidden(true);
view.font->setHidden(true);
} else {
d.setWindowTitle(tr("Create Countdown Clip"));
view.font->setValue(height);
}
// Set single file mode. Default seems to be File::ExistingOnly.
view.path->setMode(KFile::File);
QString clipFile = prePath + counter + ".mlt";
view.path->setUrl(KUrl(clipFile));
if (d.exec() == QDialog::Accepted) {
QDomDocument doc;
QDomElement mlt = doc.createElement("mlt");
QDomElement playlist = doc.createElement("playlist");
if (generator == i18n("Noise")) {
QDomElement prod = doc.createElement("producer");
prod.setAttribute("mlt_service", "noise");
prod.setAttribute("in", "0");
prod.setAttribute("out", QString::number((int) fps * view.duration->value()));
playlist.appendChild(prod);
} else {
for (int i = 0; i < view.duration->value(); i++) {
// Create the producers
QDomElement prod = doc.createElement("producer");
prod.setAttribute("mlt_service", "pango");
prod.setAttribute("in", "0");
prod.setAttribute("out", QString::number((int) fps));
prod.setAttribute("text", QString::number(view.duration->value() - i));
//FIXME: the font and pad values are approximate, the pango producer seems unable
// to produce a predictable frame size.
prod.setAttribute("font", QString::number(view.font->value()) + "px");
//prod.setAttribute("pad", 50);
playlist.appendChild(prod);
}
}
mlt.appendChild(playlist);
doc.appendChild(mlt);
QFile file(view.path->url().path());
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
kWarning() << "////// ERROR writing to file: " << view.path->url().path();
KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
return KUrl();
}
QTextStream out(&file);
out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(0, i18n("Cannot write to file %1", view.path->url().path()));
file.close();
return KUrl();
}
file.close();
return view.path->url();
}
return KUrl();
}
Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)