-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (59 loc) · 1.94 KB
/
main.cpp
File metadata and controls
68 lines (59 loc) · 1.94 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
#include <QCoreApplication>
#include <QFile>
#include <QDir>
#include <QByteArray>
#include <QTextStream>
#include <QStringList>
#include "queryhelper.h"
QByteArray aggregate(const QString& query, const QString& registrant)
{
QueryHelper helper(query);
helper.bindVariable("registrant", QVariant(registrant));
return helper.evaluate();
}
QByteArray toArticles(const QString& query, QByteArray aggregated)
{
QueryHelper helper(query);
helper.bindVariable("aggregated", aggregated);
return helper.evaluate();
}
QString toHtml(const QString& query, QByteArray aggregated, QByteArray articles)
{
QueryHelper helper(query);
helper.bindVariable("subscriptions", aggregated);
helper.bindVariable("articles", articles);
QString ret = helper.evaluateToStr();
ret.replace(">",">")
.replace("<","<")
.replace(""","\"")
.replace("&","&");
return ret;
}
// Sorry Linux only yet.
QString findConfig(const QString& fileName)
{
QStringList list = QStringList() << "./etc/"
<< "/usr/local/etc/qplanet"
<< "/usr/etc/qplanet"
<< "/etc/qplanet";
foreach(QString dir, list) {
QDir d(dir);
if (d.exists(fileName)) {
return d.filePath(fileName);
}
}
return QDir(list.first()).filePath(fileName);
}
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QString aggregateQuery = ":/query/aggregate.xq";
QString articlesQuery = ":/query/articles.xq";
QString templateQuery = findConfig("template.xq");
QString registrant = findConfig("regist.xml");
QByteArray aggregated = aggregate(aggregateQuery, registrant);
QByteArray articles = toArticles(articlesQuery,aggregated);
QString html = toHtml(templateQuery, aggregated, articles);
QTextStream(stdout) << html << endl;
return 0;
}