-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscriptparser.cpp
94 lines (78 loc) · 2.33 KB
/
scriptparser.cpp
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
#include <string>
#include <sstream>
#include <QFile>
#include <QMap>
#include <QRect>
#include <QSettings>
#include <QSize>
#include <QString>
#include <QTextStream>
#include <QVariant>
#include "scriptparser.h"
#include "templet.hpp"
namespace {
QString readTemplate(const QString& path) {
QFile tpl(path);
if(!tpl.open(QIODevice::ReadOnly | QIODevice::Text)) {
throw vfg::ScriptParserError(QString("Unable to open %1").arg(path).toStdString());
}
QTextStream stream(&tpl);
return stream.readAll();
}
} // namespace
namespace vfg {
ScriptParser::ScriptParser(const QString &filePath) :
path(filePath)
{
}
void ScriptParser::setTemplate(const QString &path)
{
tplPath = path;
}
QString ScriptParser::parse(const QMap<QString, QVariant>& settings) const try
{
using templet::make_data;
templet::DataMap data;
data["source_path"] = make_data(path.toStdString());
data["avs_plugins"] = make_data(settings.value("avisynthpluginspath")
.toString().toStdString());
if(settings.value("ivtc", 0).toInt()) {
data["ivtc"] = make_data("true");
}
if(settings.value("deinterlace", 0).toInt()) {
data["deinterlace"] = make_data("true");
}
const QSize resized = settings.value("resize").toSize();
if(resized.width() || resized.height()) {
templet::DataMap resize;
resize["width"] = make_data(resized.width());
resize["height"] = make_data(resized.height());
data["resize"] = make_data(resize);
}
const QRect crop = settings.value("crop").toRect();
const auto cropTop = crop.y();
const auto cropRight = crop.width();
const auto cropBottom = crop.height();
const auto cropLeft = crop.x();
if(cropTop || cropRight || cropBottom || cropLeft) {
templet::DataMap crop;
crop["top"] = make_data(cropTop);
crop["right"] = make_data(cropRight);
crop["bottom"] = make_data(cropBottom);
crop["left"] = make_data(cropLeft);
data["crop"] = make_data(crop);
}
const std::string tpl = readTemplate(tplPath).toStdString();
std::ostringstream oss;
templet::parse(tpl, data, oss);
return QString::fromStdString(oss.str());
}
catch(const vfg::ScriptParserError& ex)
{
throw;
}
catch(const std::exception &ex)
{
throw;
}
} // namespace vfg