source: wkhtmltox/trunk/fuentes/src/shared/commonarguments.cc @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

File size: 9.8 KB
Line 
1// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2// vi:set ts=4 sts=4 sw=4 noet :
3//
4// Copyright 2010, 2011 wkhtmltopdf authors
5//
6// This file is part of wkhtmltopdf.
7//
8// wkhtmltopdf is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// wkhtmltopdf is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20
21#include "arghandler.inl"
22#include "commandlineparserbase.hh"
23#include <wkhtmltox/loadsettings.hh>
24using namespace wkhtmltopdf::settings;
25
26struct LoadErrorHandlingTM: public SomeSetterTM<LoadPage::LoadErrorHandling> {
27        static LoadPage::LoadErrorHandling strToT(const char * val, bool &ok) {
28                return strToLoadErrorHandling(val, &ok);
29        }
30        static QString TToStr(const LoadPage::LoadErrorHandling & o, bool & ok) {
31                ok=true;
32                return loadErrorHandlingToStr(o);
33        }
34};
35typedef SomeSetter<LoadErrorHandlingTM> LoadErrorHandlingSetting;
36
37struct ProxyTM: public SomeSetterTM<Proxy> {
38        static Proxy strToT(const char * val, bool &ok) {
39                return strToProxy(val, &ok);
40        }
41};
42/*!
43  Argument handler setting a proxy variable
44 */
45typedef SomeSetter<ProxyTM> ProxySetter;
46
47
48//All these function would have been lambda function, had C++ supported them, now we are forced to write them here
49
50/*!
51  Lambda: Call the usage method
52*/
53template <bool v>
54struct HelpFunc {
55        bool operator()(const char **, CommandLineParserBase & p, char *) {
56                p.usage(stdout,v);
57                exit(0);
58        }
59};
60
61/*!
62  Lambda: Call the man method
63*/
64struct ManPageFunc {
65        bool operator()(const char **, CommandLineParserBase & p, char *) {
66                p.manpage(stdout);
67                exit(0);
68        }
69};
70
71/*!
72  Lambda: Call the man method
73*/
74template <bool T>
75struct ReadmeFunc {
76        bool operator()(const char **, CommandLineParserBase & p, char *) {
77                p.readme(stdout, T);
78                exit(0);
79        }
80};
81
82/*!
83  Lambda: Call the version method
84*/
85struct VersionFunc {
86        bool operator()(const char **, CommandLineParserBase & p, char *) {
87                p.version(stdout);
88                exit(0);
89        }
90};
91
92/*!
93  Lambda: show the license
94*/
95struct LicenseFunc {
96    bool operator()(const char **, CommandLineParserBase & p, char *) {
97                p.license(stdout);
98                exit(0);
99        }
100};
101
102/*!
103  The next arguments we add will belong to this section
104  /param s The name of the section
105  /param desc A description of the section
106*/
107void CommandLineParserBase::section(QString s, QString desc) {
108        currentSection = s;
109        sectionDesc[s] = desc;
110        sections.push_back(s);
111}
112
113/*!
114  Indicate whether the next arguments we add require a patched qt to work
115  /param h Do we require a patch
116*/
117void CommandLineParserBase::qthack(bool h) {
118        currentHack = h;
119}
120
121void CommandLineParserBase::mode(int m) {
122        currentMode = m;
123}
124
125/*!
126  Indicate whether the next arguments we add are "extended" and should not
127  be shown in a simple --help
128  \param e Are the arguments extended
129*/
130void CommandLineParserBase::extended(bool e) {
131        currentExtended = e;
132}
133
134
135/*!
136  Add an argument to the list of arguments
137  \param l The long "--" name of the argument
138  \param s The short '-' name of the argument or 0 if unspecified
139  \param d Description of the argument
140  \param h The handler for the argument
141  \param display Is the argument hidden
142*/
143void CommandLineParserBase::addarg(QString l, char s, QString d, ArgHandler * h, bool display) {
144        h->desc = d;
145        h->longName = l;
146        h->shortSwitch = s;
147        h->display = display;
148        h->qthack = currentHack;
149        h->section = currentMode;
150        h->extended = currentExtended;
151        longToHandler[l] = h;
152        if (s) shortToHandler[s] = h;
153        sectionArgumentHandles[currentSection].push_back(h);
154}
155
156void CommandLineParserBase::addDocArgs() {
157        extended(false);
158        qthack(false);
159        addarg("help", 'h', "Display help", new Caller<HelpFunc<false> >());
160        addarg("version", 'V' ,"Output version information and exit", new Caller<VersionFunc>());
161        addarg("license", 0 ,"Output license information and exit", new Caller<LicenseFunc>());
162        addarg("extended-help", 'H',"Display more extensive help, detailing less common command switches", new Caller<HelpFunc<true> >());
163
164        extended(true);
165        qthack(false);
166        addarg("manpage", 0, "Output program man page", new Caller<ManPageFunc>());
167        addarg("htmldoc", 0, "Output program html help", new Caller<ReadmeFunc<true> >());
168        addarg("readme", 0, "Output program readme", new Caller<ReadmeFunc<false> >());
169}
170
171
172void CommandLineParserBase::addGlobalLoadArgs(LoadGlobal & s) {
173        extended(true);
174        qthack(false);
175
176    addarg("cookie-jar", 0, "Read and write cookies from and to the supplied cookie jar file", new QStrSetter(s.cookieJar, "path") );
177}
178
179void CommandLineParserBase::addWebArgs(Web & s) {
180        extended(true);
181        qthack(false);
182
183        addarg("enable-plugins",0,"Enable installed plugins (plugins will likely not work)", new ConstSetter<bool>(s.enablePlugins,true));
184        addarg("disable-plugins",0,"Disable installed plugins", new ConstSetter<bool>(s.enablePlugins,false));
185
186        addarg("minimum-font-size",0,"Minimum font size", new IntSetter(s.minimumFontSize,"int"));
187        addarg("user-style-sheet",0,"Specify a user style sheet, to load with every page", new QStrSetter(s.userStyleSheet,"url"));
188        addarg("no-images",0,"Do not load or print images", new ConstSetter<bool>(s.loadImages, false));
189        addarg("images",0,"Do load or print images", new ConstSetter<bool>(s.loadImages, true));
190
191        addarg("disable-javascript",'n',"Do not allow web pages to run javascript", new ConstSetter<bool>(s.enableJavascript,false));
192        addarg("enable-javascript",0,"Do allow web pages to run javascript", new ConstSetter<bool>(s.enableJavascript,true));
193
194        extended(true);
195        qthack(true);
196        qthack(false);
197        addarg("encoding", 0, "Set the default text encoding, for input", new QStrSetter(s.defaultEncoding,"encoding"));
198
199
200}
201
202void CommandLineParserBase::addPageLoadArgs(LoadPage & s) {
203        extended(true);
204        qthack(false);
205        addarg("proxy",'p',"Use a proxy", new ProxySetter(s.proxy, "proxy"));
206        addarg("bypass-proxy-for", 0, "Bypass proxy for host (repeatable)", new StringListSetter(s.bypassProxyForHosts, "value"));
207        addarg("username",0,"HTTP Authentication username", new QStrSetter(s.username, "username"));
208        addarg("password",0,"HTTP Authentication password", new QStrSetter(s.password, "password"));
209        addarg("load-error-handling", 0, "Specify how to handle pages that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.loadErrorHandling, "handler"));
210        addarg("load-media-error-handling", 0, "Specify how to handle media files that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.mediaLoadErrorHandling, "handler"));
211        addarg("custom-header",0,"Set an additional HTTP header (repeatable)", new MapSetter<>(s.customHeaders, "name", "value"));
212        addarg("custom-header-propagation",0,"Add HTTP headers specified by --custom-header for each resource request.", new ConstSetter<bool>(s.repeatCustomHeaders, true));
213        addarg("no-custom-header-propagation",0,"Do not add HTTP headers specified by --custom-header for each resource request.", new ConstSetter<bool>(s.repeatCustomHeaders, true));
214
215        addarg("javascript-delay",0,"Wait some milliseconds for javascript finish", new IntSetter(s.jsdelay,"msec"));
216        addarg("window-status",0,"Wait until window.status is equal to this string before rendering page", new QStrSetter(s.windowStatus, "windowStatus"));
217
218        addarg("zoom",0,"Use this zoom factor", new FloatSetter(s.zoomFactor,"float",1.0));
219        addarg("cookie",0,"Set an additional cookie (repeatable), value should be url encoded.", new MapSetter<>(s.cookies, "name", "value"));
220        addarg("post", 0, "Add an additional post field (repeatable)", new MapSetter<PostItemCreator<false> >(s.post, "name", "value"));
221        addarg("post-file", 0, "Post an additional file (repeatable)", new MapSetter<PostItemCreator<true> >(s.post, "name", "path"));
222
223        addarg("disable-local-file-access", 0, "Do not allowed conversion of a local file to read in other local files, unless explicitly allowed with --allow", new ConstSetter<bool>(s.blockLocalFileAccess, true));
224        addarg("enable-local-file-access", 0, "Allowed conversion of a local file to read in other local files.", new ConstSetter<bool>(s.blockLocalFileAccess, false));
225        addarg("allow", 0, "Allow the file or files from the specified folder to be loaded (repeatable)", new StringListSetter(s.allowed,"path"));
226
227        addarg("cache-dir", 0, "Web cache directory", new QStrSetter(s.cacheDir,"path"));
228
229        addarg("debug-javascript", 0,"Show javascript debugging output", new ConstSetter<bool>(s.debugJavascript, true));
230        addarg("no-debug-javascript", 0,"Do not show javascript debugging output", new ConstSetter<bool>(s.debugJavascript, false));
231        addarg("stop-slow-scripts", 0, "Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, true));
232        addarg("no-stop-slow-scripts", 0, "Do not Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, false));
233        addarg("run-script", 0, "Run this additional javascript after the page is done loading (repeatable)", new StringListSetter(s.runScript, "js"));
234
235        addarg("checkbox-svg", 0, "Use this SVG file when rendering unchecked checkboxes", new QStrSetter(s.checkboxSvg, "path", ""));
236        addarg("checkbox-checked-svg", 0, "Use this SVG file when rendering checked checkboxes", new QStrSetter(s.checkboxCheckedSvg, "path" ,""));
237        addarg("radiobutton-svg", 0, "Use this SVG file when rendering unchecked radiobuttons", new QStrSetter(s.radiobuttonSvg, "path", ""));
238        addarg("radiobutton-checked-svg", 0, "Use this SVG file when rendering checked radiobuttons", new QStrSetter(s.radiobuttonCheckedSvg, "path", ""));
239}
Note: See TracBrowser for help on using the repository browser.