]> git.sesse.net Git - kdenlive/blob - plugins/sampleplugin/sampleplugin.cpp
Start to add QLatin1String
[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 <KDebug>
25 #include <KMessageBox>
26 #include <KApplication>
27
28 #include <QDialog>
29 #include <QProcess>
30
31 QStringList SamplePlugin::generators(const QStringList &producers) const
32 {
33     QStringList result;
34     if (producers.contains(QLatin1String("pango"))) result << i18n("Countdown");
35     if (producers.contains(QLatin1String("noise"))) result << i18n("Noise");
36     return result;
37 }
38
39
40 KUrl SamplePlugin::generatedClip(const QString &renderer, const QString &generator, const KUrl &projectFolder, const QStringList &/*lumaNames*/, const QStringList &/*lumaFiles*/, const double fps, const int /*width*/, const int height)
41 {
42     QString prePath;
43     if (generator == i18n("Noise")) {
44         prePath = projectFolder.path() + QLatin1String("/noise");
45     } else prePath = projectFolder.path() + QLatin1String("/counter");
46     int ct = 0;
47     QString counter = QString::number(ct).rightJustified(5, QLatin1Char('0'), false);
48     while (QFile::exists(prePath + counter + QLatin1String(".mlt"))) {
49         ct++;
50         counter = QString::number(ct).rightJustified(5, QLatin1Char('0'), false);
51     }
52     QPointer<QDialog> d = new QDialog;
53     Ui::CountDown_UI view;
54     view.setupUi(d);
55     if (generator == i18n("Noise")) {
56         d->setWindowTitle(i18n("Create Noise Clip"));
57         view.font_label->setHidden(true);
58         view.font->setHidden(true);
59     } else {
60         d->setWindowTitle(i18n("Create Countdown Clip"));
61         view.font->setValue(height);
62     }
63
64     // Set single file mode. Default seems to be File::ExistingOnly.
65     view.path->setMode(KFile::File);
66
67     QString clipFile = prePath + counter + QLatin1String(".mlt");
68     view.path->setUrl(KUrl(clipFile));
69     KUrl result;
70     
71     if (d->exec() == QDialog::Accepted) {
72         QProcess generatorProcess;
73
74         // Disable VDPAU so that rendering will work even if there is a Kdenlive instance using VDPAU
75 #if QT_VERSION >= 0x040600
76         QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
77         env.insert(QLatin1String("MLT_NO_VDPAU"), QLatin1String("1"));
78         generatorProcess.setProcessEnvironment(env);
79 #else
80         QStringList env = QProcess::systemEnvironment();
81         env << QLatin1String("MLT_NO_VDPAU=1");
82         generatorProcess.setEnvironment(env);
83 #endif
84         QStringList args;
85         if (generator == i18n("Noise")) {
86             args << QLatin1String("noise:") << QLatin1String("in=0") << QLatin1String("out=") + QString::number((int) fps * view.duration->value());
87         }
88         else {
89             // Countdown producer
90             for (int i = 0; i < view.duration->value(); i++) {
91                 // Create the producers
92                 args << QLatin1String("pango:") << QLatin1String("in=0") << QLatin1String("out=") + QString::number((int) fps * view.duration->value());
93                 args << QLatin1String("text=") + QString::number(view.duration->value() - i);
94                 args << QLatin1String("font=") + QString::number(view.font->value()) + QLatin1String("px");
95             }
96         }
97
98         args << QLatin1String("-consumer")<<QString::fromLatin1("xml:%1").arg(view.path->url().path());
99         generatorProcess.start(renderer, args);
100         if (generatorProcess.waitForFinished()) {
101             if (generatorProcess.exitStatus() == QProcess::CrashExit) {
102                 kDebug() << "/// Generator failed: ";
103                 QString error = QString::fromLocal8Bit(generatorProcess.readAllStandardError());
104                 KMessageBox::sorry(kapp->activeWindow(), i18n("Failed to generate clip:\n%1", error, i18n("Generator Failed")));
105             }
106             else {
107                 result = view.path->url();
108             }
109         } else {
110             kDebug() << "/// Generator failed: ";
111             QString error = QString::fromLocal8Bit(generatorProcess.readAllStandardError());
112             KMessageBox::sorry(kapp->activeWindow(), i18n("Failed to generate clip:\n%1", error, i18n("Generator Failed")));
113         }
114     }
115     delete d;
116     return result;
117 }
118
119 Q_EXPORT_PLUGIN2(kdenlive_sampleplugin, SamplePlugin)
120
121 #include "sampleplugin.moc"