-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.cpp
122 lines (108 loc) · 3.84 KB
/
options.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <QByteArray>
#include <QCommandLineParser>
#include "options.h"
bool parseOptions(const QStringList &strings, Options &options)
{
bool result = true;
QCommandLineParser parser;
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser.addOptions({
{
"url",
"Website URL address.",
"url"
},
{
"b64-url",
"Website URL address (Base64 encoded).",
"b64-url"
},
{
"out",
"Output filename.",
"out"
},
{
"width",
"Screnshot width.",
"width"
},
{
"height",
"Screnshot height.",
"height"
},
{
"delay",
"Wait for n seconds for website after its fully loaded.",
"delay"
},
{
"timeout",
"Max wait time for a page to be loaded.",
"timeout"
},
{
"user-agent",
"Custom browser user agent.",
"user-agent"
},
{
"referer",
"Custom referer header.",
"referer"
},
{
"pdf-orientation",
"PDF orientation (landscape, portrait).",
"pdf-orientation"
},
{
"pdf-paper-size",
"PDF orientation (a3, a4, letter, tabloid).",
"pdf-paper-size"
}
});
parser.parse(strings);
if (parser.isSet("url")) {
options.url = QUrl::fromUserInput(parser.value("url"));
} else if (parser.isSet("b64-url")) {
options.url = QUrl::fromUserInput(QByteArray::fromBase64(parser.value("b64-url").toUtf8()).data());
} else {
result = false;
}
if (parser.isSet("out")) {
options.out = parser.value("out");
} else {
result = false;
}
if (parser.isSet("width")) {
options.width = parser.value("width").toInt();
} else {
options.width = 1024;
}
if (parser.isSet("height")) {
options.height = parser.value("height").toInt();
} else {
options.height = 1024;
}
if (parser.isSet("delay")) {
options.delay = parser.value("delay").toInt();
}
if (parser.isSet("timeout")) {
options.timeout = parser.value("timeout").toInt();
}
if (parser.isSet("user-agent")) {
options.userAgent = parser.value("user-agent");
}
if (parser.isSet("referer")) {
options.referer = parser.value("referer");
}
if (parser.isSet("pdf-orientation")) {
options.pdfOrientation = parser.value("pdf-orientation").toLower();
}
if (parser.isSet("pdf-paper-size")) {
options.pdfPaperSize = parser.value("pdf-paper-size").toLower();
}
return result;
}