Browse Source

Share load argumenst, argument handlers, and most of commandlineparser

Jakob Truelsen 15 years ago
parent
commit
d430385e43

+ 41 - 419
src/image/arguments.cc

@@ -1,434 +1,56 @@
-/*
- * File:   arguments.cc
- * Author: Christian Sciberras
- * Created: 20 May 2010
- *   This file is part of wkhtmltoimage.
- *   wkhtmltoimage is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   wkhtmltoimage is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with wkhtmltoimage.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "commandlineparser_p.hh"
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "commandlineparser.hh"
+#include "arghandler.inl"
 #include <qglobal.h>
 
-/*!
-  \class ArgHandler
-  \brief Class responsible for handling an argument
-*/
-
-/*!
-  \var ArgHandler::longName
-  \brief The long name of the argument, e.g. "help" for "--help"
-*/
-
-/*!
-  \var ArgHandler::desc
-  \brief A descriptive text of the argument
-*/
-
-/*!
-  \var ArgHandler::shortSwitch
-  \brief Sort name, e.g. 'h' for '-h', if 0 there is no short name
-*/
-
-/*!
-  \var ArgHandler::argn
-  \brief The names of the arguments to the switch
-*/
-
-/*!											  
-  \var ArgHandler::display
-  \brief Indicate that the argument is not hidden
-*/
-
-/*!
-  \var ArgHandler::extended
-  \brief Indicate if the argument is an extended argument
-*/
-
-/*!											  
-  \var ArgHandler::qthack
-  \brief Indicate that the argument is only available with hacked qt
-*/
-
-/*!
-  \fn ArgHandler::operator()(const char ** args, CommandLineParserPrivate & parser)
-  Callend when the switch was specified
-  \param args The arguments to the switch, guarantied to have size of argn
-  \param settings The settings to store the information in
-*/
-
-/*!
-  \fn ArgHandler::useDefault(CommandLineParserPrivate & parser)
-  Set give settings its default value
-
-  This is a NOOP for ArgHandler
-  \param parser The parser giving the request
-*/
-void ArgHandler::useDefault(CommandLineParserPrivate & parser) {
-	Q_UNUSED(parser);
-} 
-
-
-/*!
-  \class CommandLineParserPrivate
-  Implementation details for CommandLineParser
-*/
-
-/*!
-  Sets a variable to some constant
-*/
-template <typename T> class ConstSetter: public ArgHandler {
-public:
-	T & dst;
-	const T src;
-	const T def;
-	ConstSetter(T & arg, const T s, const T d): dst(arg), src(s), def(d) {};
-	bool operator() (const char **, CommandLineParserPrivate &) {
-		dst=src;
-		return true;
-	}
-	virtual void useDefault(CommandLineParserPrivate &) {
-		dst=def;
-	}
-};
-
-struct StringPairCreator {
-	typedef QPair<QString, QString> T;
-	inline T operator()(const QString & key, const QString & value) const {
-		return T(key, value);
-	}
-};
-
-template <bool file> 
-struct PostItemCreator {
-	typedef typename Settings::PostItem T;
-	inline T operator()(const QString & key, const QString & value) const {
-		T p;
-		p.name = key;
-		p.value = value;
-		p.file = file;
-		return p;
-	}
-};
-
-
-struct StringListSetter: public ArgHandler {
-	QList<QString> & dst;
-	StringListSetter(QList<QString> & a, QString valueName) : dst(a) {
-		argn.push_back(valueName);
-	}
-	virtual bool operator() (const char ** args, CommandLineParserPrivate &) {
-		dst.append( args[0] );
-		return true;
-	}
-	virtual void useDefault() {
-		dst.clear();
-	}
-};
-
-
-/*!
-  Putting values into a map
-*/
-template <typename T=StringPairCreator>
-struct MapSetter: public ArgHandler {
-	QList< typename T::T > & dst;
-	MapSetter(QList<typename T::T > & a, QString keyName, QString valueName) : dst(a) {
-		argn.push_back(keyName);
-		argn.push_back(valueName);
-	}
-	virtual bool operator() (const char ** args, CommandLineParserPrivate &) {
-		dst.append( T()(args[0], args[1]) );
-		return true;
-	}
-	virtual void useDefault() {
-		dst.clear();
-	}
-};
-
-
-/*!
-  SomeSetter template method base
-*/
-template <typename TT> 
-struct SomeSetterTM {
-	typedef TT T;
-	//T strToT(const char * val, bool & ok);
-	static QString TToStr(const T &, bool & ok) {ok=false; return "";}
-};
-
-/*!
-  TemplateMethod class used to set a single variable of some type TT::T
-*/
-template <typename TT>
-struct SomeSetter: public ArgHandler {
-	typedef typename TT::T T;
-	T & val;
-	T def;
-	bool hasDef;
-
-	SomeSetter(T & a, QString an, T d): val(a), def(d), hasDef(true) {
-		argn.push_back(an);
-	}
-
-	SomeSetter(T & a, QString an): val(a), hasDef(false) {
-		argn.push_back(an);
-	}
-
-	virtual void useDefault(CommandLineParserPrivate &) {
-		if (hasDef)
-			val=def;
-	}
-
-	bool operator() (const char ** vals, CommandLineParserPrivate &) {
-		bool ok;
-		val = TT::strToT(vals[0], ok);
-		return ok;
-	}
-
-	virtual QString getDesc() const {
-		if (!hasDef) return desc;
-		bool ok;
-		QString x = TT::TToStr(def,ok);
-		if (!ok) return desc;
-		return desc + " (default " + x + ")";
-	}
-};
-
-struct IntTM: public SomeSetterTM<int> {
-	static int strToT(const char * val, bool & ok) {
-		return QString(val).toInt(&ok);
-	}
-	static QString TToStr(const int & t, bool & ok) {
-		ok=(t!=-1);
-		return QString::number(t);
-	}
-};
-/*!
-  Argument handler setting an int variable
-*/
-typedef SomeSetter<IntTM> IntSetter;
-
-struct FloatTM: public SomeSetterTM<float> {
-	static float strToT(const char * val, bool & ok) {
-		return QString(val).toFloat(&ok);
-	}
-	static QString TToStr(const float & t, bool & ok) {
-		ok=(t!=-1);
-		return QString::number(t);
-	}
-};
-/*!
-  Argument handler setting an float variable
-*/
-typedef SomeSetter<FloatTM> FloatSetter;
-
-struct StrTM: public SomeSetterTM<const char *> {
-	static const char * strToT(const char * val, bool & ok) {
-		ok=true;
-		return val;
-	}
-	static QString TToStr(const char * t, bool & ok) {
-		ok = (t[0] != '\0');
-		return QString(t);
-	}
-};
-/*!
-  Argument handler setting a string variable
-*/
-typedef SomeSetter<StrTM> StrSetter;
-
-struct QStrTM: public SomeSetterTM<QString> {
-	static QString strToT(const char * val, bool & ok) {
-		ok=true;
-		return QString::fromLocal8Bit(val);
-	}
-	static QString TToStr(QString t, bool & ok) {
-		ok=!t.isEmpty();
-		return t;
-	}
-};
-/*!
-  Argument handler setting a string variable
-*/
-typedef SomeSetter<QStrTM> QStrSetter;
-
-struct ProxyTM: public SomeSetterTM<Settings::ProxySettings> {
-	static Settings::ProxySettings strToT(const char * val, bool &ok) {
-		return Settings::strToProxy(val, &ok);
-	}
-};
-/*!
-  Argument handler setting a proxy variable  
- */
-typedef SomeSetter<ProxyTM> ProxySetter;
-
-/*!
-  Argument handler responsible for calling a function
-*/
-template <typename T> struct Caller: public ArgHandler {
-	Caller() {}
-	Caller(QString a1) {
-		argn.push_back(a1);
-	}
-	bool operator() (const char **vals, CommandLineParserPrivate & s) {
-		return T()(vals,s);
-	}
-};
-
-//All these function would have been lambda function, had C++ supported them, now we are forced to write them here
-
-/*!
-  Lambda: Call the usage method
-*/
-template <bool v>
-struct HelpFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p) {
-		p.usage(stdout,v);
-		exit(0);
-	}
-};
-
-/*!
-  Lambda: Call the man method
-*/
-struct ManPageFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p) {
-		p.manpage(stdout);
-		exit(0);
-	}
-};
-
-/*!
-  Lambda: Call the man method
-*/
-template <bool T>
-struct ReadmeFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p) {
-		p.readme(stdout, T);
-		exit(0);
-	}
-};
-
-/*!
-  Lambda: Call the version method
-*/
-struct VersionFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p) {
-		p.version(stdout);
-		exit(0);
-	}
-};
-
-/*!
-  The next arguments we add will belong to this section
-  /param s The name of the section
-  /param desc A description of the section
-*/
-void CommandLineParserPrivate::section(QString s, QString desc) {
-	currentSection = s;
-	sectionDesc[s] = desc;
-	sections.push_back(s);
-}
-
-/*!
-  Indicate whether the next arguments we add are "extended" and should not 
-  be shown in a simple --help
-  \param e Are the arguments extended
-*/
-void CommandLineParserPrivate::extended(bool e) {
-	currentExtended = e;
-}
-
-/*!
-  Add an argument to the list of arguments
-  \param l The long "--" name of the argument
-  \param s The short '-' name of the argument or 0 if unspecified
-  \param d Description of the argument
-  \param h The handler for the argument
-  \param display Is the argument hidden
-*/
-void CommandLineParserPrivate::addarg(QString l, char s, QString d, ArgHandler * h, bool display) {
-	h->desc = d;
-	h->longName = l;
-	h->shortSwitch = s;
-	h->display = display;
-	h->qthack = currentHack;
-	h->extended = currentExtended;
-	longToHandler[l] = h;
-	if(s) shortToHandler[s] = h;
-	sectionArgumentHandles[currentSection].push_back(h);
-}
-
-/*!
-  Construct the commandline parser adding all the arguments
-  \param s The settings to store values in
-*/
-CommandLineParserPrivate::CommandLineParserPrivate(Settings & s):
+CommandLineParser::CommandLineParser(wkhtmltopdf::settings::Global & s):
 	settings(s)
 {
+	mode(global);
 	section("General Options");
 	extended(false);
-	addarg("help",'h',"Display help",new Caller<HelpFunc<false> >());
-	addarg("quiet",'q',"Be less verbose",new ConstSetter<bool>(s.quiet,true,false));
-	addarg("version",'V',"Output version information an exit", new Caller<VersionFunc>());
-	addarg("extended-help",0,"Display more extensive help, detailing less common command switches", new Caller<HelpFunc<true> >());
-	addarg("proxy",'p',"Use a proxy", new ProxySetter(s.proxy, "proxy"));
-	addarg("username",0,"HTTP Authentication username", new QStrSetter(s.username, "username",""));
-	addarg("password",0,"HTTP Authentication password", new QStrSetter(s.password, "password",""));
-	extended(true);
-	addarg("custom-header",0,"Set an additional HTTP header (repeatable)", new MapSetter<>(s.customHeaders, "name", "value"));
-	addarg("manpage", 0, "Output program man page", new Caller<ManPageFunc>());
-	addarg("htmldoc", 0, "Output program html help", new Caller<ReadmeFunc<true> >());
-	addarg("readme", 0, "Output program readme", new Caller<ReadmeFunc<false> >());
-	addarg("disable-javascript",'n',"Do not allow web pages to run javascript", new ConstSetter<bool>(s.enableJavascript,false,true));
-	addarg("grayscale",'g',"Image will be generated in grayscale", new ConstSetter<QPrinter::ColorMode>(s.colorMode,QPrinter::GrayScale,QPrinter::Color));
-	addarg("redirect-delay",0,"Wait some milliseconds for js-redirects", new IntSetter(s.jsredirectwait,"msec",200));
-	addarg("enable-plugins",0,"Enable installed plugins (such as flash)", new ConstSetter<bool>(s.enablePlugins,true,false));
+	addDocArgs();
+	
+	extended(false);
+	qthack(false);
+	addarg("disable-javascript",'n',"Do not allow web pages to run javascript", new ConstSetter<bool>(s.enableJavascript,false));
+	addarg("grayscale",'g',"Image will be generated in grayscale", new ConstSetter<QPrinter::ColorMode>(s.colorMode,QPrinter::GrayScale));
+	addarg("enable-plugins",0,"Enable installed plugins (such as flash)", new ConstSetter<bool>(s.enablePlugins,true));
 
-	addarg("scale-w",0,"Set width for resizing", new IntSetter(s.scale.width,"int",-1));
-	addarg("scale-h",0,"Set height for resizing", new IntSetter(s.scale.height,"int",-1));
+	addarg("scale-w",0,"Set width for resizing", new IntSetter(s.scale.width,"int"));
+	addarg("scale-h",0,"Set height for resizing", new IntSetter(s.scale.height,"int"));
 
-	addarg("crop-x",0,"Set x coordinate for croping", new IntSetter(s.crop.left,"int",0));
-	addarg("crop-y",0,"Set y coordinate for croping", new IntSetter(s.crop.top,"int",0));
-	addarg("crop-w",0,"Set width for croping", new IntSetter(s.crop.width,"int",-1));
-	addarg("crop-h",0,"Set height for croping", new IntSetter(s.crop.height,"int",-1));
+	addarg("crop-x",0,"Set x coordinate for croping", new IntSetter(s.crop.left,"int"));
+	addarg("crop-y",0,"Set y coordinate for croping", new IntSetter(s.crop.top,"int"));
+	addarg("crop-w",0,"Set width for croping", new IntSetter(s.crop.width,"int"));
+	addarg("crop-h",0,"Set height for croping", new IntSetter(s.crop.height,"int"));
 
-	addarg("minimum-font-size",0,"Minimum font size", new IntSetter(s.minimumFontSize,"int",5));
-	addarg("cookie-jar", 0, "Read and write cookies from and to the supplied cookie jar file", new QStrSetter(s.cookieJar, "path", "") );
-	addarg("cookie",0,"Set an additional cookie (repeatable)", new MapSetter<>(s.cookies, "name", "value"));
-	addarg("post", 0, "Add an additional post field (repeatable)", new MapSetter<PostItemCreator<false> >(s.post, "name", "value"));
-	addarg("post-file", 0, "Post an aditional file (repeatable)", new MapSetter<PostItemCreator<true> >(s.post, "name", "path"));
-	addarg("disallow-local-file-access", 0, "Do not allowed conversion of a local file to read in other local files, unless explecitily allowed with --allow", new ConstSetter<bool>(s.blockLocalFileAccess, true, false));
-	addarg("allow", 0, "Allow the file or files from the specified folder to be loaded (repeatable)", new StringListSetter(s.allowed,"path"));
-	addarg("format",0,"Sets the image output format (eg: PNG), if not set, it tries to determine it from output file ame", new QStrSetter(s.fmt, "ext"));
+	addarg("minimum-font-size",0,"Minimum font size", new IntSetter(s.minimumFontSize,"int"));
 	
-	addarg("disable-smart-shrinking", 0, "Disable the intelligent shrinking strategy used by WebKit that makes the pixel/dpi ratio none constant",new ConstSetter<bool>(s.enableIntelligentShrinking, false, true));
-	addarg("replace",0, "Replace [name] with value in header and footer (repeatable)", new MapSetter<>(s.replacements, "name", "value"));
+	addarg("disable-smart-shrinking", 0, "Disable the intelligent shrinking strategy used by WebKit that makes the pixel/dpi ratio none constant",new ConstSetter<bool>(s.enableIntelligentShrinking, false));
 #ifdef Q_WS_X11
-	addarg("use-xserver",0,"Use the X server (some plugins and other stuff might not work without X11)", new ConstSetter<bool>(s.useGraphics,true,false));
+	addarg("use-xserver",0,"Use the X server (some plugins and other stuff might not work without X11)", new ConstSetter<bool>(s.useGraphics,true));
 #endif
 
-#if QT_VERSION >= 0x040600
-	//qthack(false);
-#endif
-	addarg("encoding",0,"Set the default text encoding, for input", new QStrSetter(s.defaultEncoding,"encoding",""));
+	//addarg("encoding",0,"Set the default text encoding, for input", new QStrSetter(s.defaultEncoding,"encoding",""));
 	
-#if QT_VERSION >= 0x040500 //Not printing the background was added in QT4.5
-	addarg("no-background",0,"Do not print background", new ConstSetter<bool>(s.background,false,true));
-	addarg("user-style-sheet",0,"Specify a user style sheet, to load with every page", new QStrSetter(s.userStyleSheet,"url",""));
-#endif
-	addarg("debug-javascript", 0,"Show javascript debugging output", new ConstSetter<bool>(s.debugJavascript, true, false));
-#if QT_VERSION >= 0x040600
-	addarg("stop-slow-scripts", 0, "Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, true, false));
-#endif	
-	extended(false);
+	addarg("no-background",0,"Do not print background", new ConstSetter<bool>(s.background,false));
+	addarg("user-style-sheet",0,"Specify a user style sheet, to load with every page", new QStrSetter(s.userStyleSheet,"url"));
+
+	addGlobalLoadArgs(s.loadGlobal);
+	addPageLoadArgs(s.loadPage);
 }

+ 53 - 197
src/image/commandlineparser.cc

@@ -1,79 +1,39 @@
-/*
- * File:   commandlinesparser.cc
- * Author: Christian Sciberras
- * Created: 20 May 2010
- *   This file is part of wkhtmltoimage.
- *   wkhtmltoimage is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   wkhtmltoimage is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with wkhtmltoimage.  If not, see <http://www.gnu.org/licenses/>.
- */
-#include "commondocparts.hh"
-#include "commandlineparser_p.hh"
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "commandlineparser.hh"
 #include <qwebframe.h>
+#include "outputter.hh"
 
 /*!
   \file commandlineparser.hh
   \brief Defines the CommandLineParser class
 */
 
-/*!
-  \file commandlineparser_p.hh
-  \brief Defines the CommandLineParserPrivate, ArgHandler and Outputter class
-*/
-
-bool ahsort(const ArgHandler * a, const ArgHandler * b) {
-	return a->longName < b->longName;
-}
-
-/*!
-  Output description of switches to an outputter
-  \param o The outputter to output to
-  \param extended Should we also output extended arguments
-  \param doc Indicate to the outputter that it is writing documentation
-*/
-void CommandLineParserPrivate::outputSwitches(Outputter * o, bool extended, bool doc) const {
-	foreach(const QString & section, sections) {
-		QList<const ArgHandler *> display;
-		foreach(const ArgHandler * handler, sectionArgumentHandles[section]) {
-			if(!doc && handler->qthack) continue;
-			if(!extended && handler->extended) continue;
-			display.push_back(handler);
-		}
-		qSort(display.begin(), display.end(), ahsort);
-		if(display.size() == 0) continue;
-		o->beginSection(section);
-		if(!sectionDesc[section].isEmpty()) {
-			o->beginParagraph();
-			o->text(sectionDesc[section]);
-			o->endParagraph();
-		}
-		o->beginSwitch();
-		foreach(const ArgHandler * handler, display)
-			o->cswitch(handler);
-		o->endSwitch();
-		o->endSection();
- 	}
-}
-
 /*!
   Output the man page to a given file
   \param fd The file to store the man page
 */
-void CommandLineParserPrivate::manpage(FILE * fd) const {
+void CommandLineParser::manpage(FILE * fd) const {
 	Outputter * o = Outputter::man(fd);
  	outputManName(o);
  	outputSynopsis(o);
  	outputDescripton(o);
 	outputSwitches(o, true, false);
  	outputContact(o);
-	commonDocParts::outputAuthors(o);
+	outputAuthors(o);
 	delete o;
 }
 
@@ -82,120 +42,62 @@ void CommandLineParserPrivate::manpage(FILE * fd) const {
   \param fd The file to output the information to
   \param extended Should we show extended arguments
 */
-void CommandLineParserPrivate::usage(FILE * fd, bool extended) const {
+void CommandLineParser::usage(FILE * fd, bool extended) const {
 	Outputter * o = Outputter::text(fd,false);
-	commonDocParts::outputName(o, "wkhtmltoimage");
+	outputName(o);
 	outputSynopsis(o);
  	outputDescripton(o);
 	outputSwitches(o, extended, false);
 	if (extended) {
-	  commonDocParts::outputProxyDoc(o);
+		outputProxyDoc(o);
 	}
  	outputContact(o);
 	delete o;
 }
 
-/*!
-  Output version information aka. --version
-  \param fd The file to output to
-*/
-void CommandLineParserPrivate::version(FILE * fd) const {
- 	Outputter * o = Outputter::text(fd,false);
-  	commonDocParts::outputName(o, "wkhtmltoimage");
-  	commonDocParts::outputLicense(o);
-  	commonDocParts::outputAuthors(o);
-	delete o;
-}
-
 /*!
   Output the readme/manual
   \param fd The file to output to
   \param html Do we want the html manaul, or the README
 */
-void CommandLineParserPrivate::readme(FILE * fd, bool html) const {
+void CommandLineParser::readme(FILE * fd, bool html) const {
 	Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
 	outputDocStart(o);
 	outputContact(o);
-	commonDocParts::outputLicense(o);
-	commonDocParts::outputAuthors(o);
+	outputLicense(o);
+	outputAuthors(o);
 	outputSynopsis(o);
 	outputSwitches(o, true, true);
- 	commonDocParts::outputProxyDoc(o);
-	commonDocParts::outputStaticProblems(o);
+ 	outputProxyDoc(o);
+	outputStaticProblems(o);
 	outputCompilation(o);
 	outputInstallation(o);
 	outputExamples(o);
 	delete o;
 }
 
-/*!
-  Output usage information aka. --help
-  \param fd The file to output the information to
-  \param extended Should we show extended arguments
-*/
-void CommandLineParser::usage(FILE * fd, bool extended) const {
-	d->usage(fd, extended);
-}
-
-/*!
-  Output version information aka. --version
-  \param fd The file to output to
-*/
-void CommandLineParser::version(FILE * fd) const {
-	d->version(fd);
-}
-
-/*!
-  Output the man page to a given file
-  \param fd The file to store the man page
-*/
-void CommandLineParser::manpage(FILE * fd) const {
-	d->manpage(fd);
-}
-
-/*!
-  Output the readme/manual
-  \param fd The file to output to
-  \param html Do we want the html manaul, or the README
-*/
-void CommandLineParser::readme(FILE * fd, bool html) const {
-	d->readme(fd,html);
-}
-
-/*!
-  Construct a commandline parser, storing its values in some settings
-  \param s The settings to store the values in.
-*/
-CommandLineParser::CommandLineParser(Settings & s):
-	d(new CommandLineParserPrivate(s))
-{
-}
-	
-CommandLineParser::~CommandLineParser() {
-	delete d;
-}
 
 /*!
  * Load default arguments and put them in the settings structure
  */
-void CommandLineParser::loadDefaults() {
-	d->settings.in = "-";
-	d->settings.proxy.host = "";
-	foreach(ArgHandler * h, d->longToHandler) 
-		h->useDefault(*d);
-
-	//Load configuration from enviornment
-	char * val;
-	const char * vars[] = {"proxy","all_proxy","http_proxy", NULL};
-	for(int i=0; vars[i]; ++i) {
-		if ((val = getenv("proxy"))) {
-			bool ok=false;
-			Settings::ProxySettings p = Settings::strToProxy(val, &ok);
-			if(ok) 
-				d->settings.proxy = p;
-		}
-	}
-}
+// void CommandLineParser::loadDefaults() {
+// 	d->settings.in = "-";
+// 	d->settings.proxy.host = "";
+// 	foreach(ArgHandler * h, d->longToHandler) 
+// 		h->useDefault(*d);
+
+// 	//Load configuration from enviornment
+// 	char * val;
+// 	const char * vars[] = {"proxy","all_proxy","http_proxy", NULL};
+// 	for(int i=0; vars[i]; ++i) {
+// 		if ((val = getenv("proxy"))) {
+// 			bool ok=false;
+// 			Settings::ProxySettings p = Settings::strToProxy(val, &ok);
+// 			if(ok) 
+// 				d->settings.proxy = p;
+// 		}
+// 	}
+// }
 
 /*!
  * Parse command line arguments, and set settings accordingly.
@@ -203,68 +105,22 @@ void CommandLineParser::loadDefaults() {
  * \param argv a NULL terminated list with the arguments
  */
 void CommandLineParser::parseArguments(int argc, const char ** argv, bool final) {
-    d->settings.in="";
-    d->settings.out="";
+	settings.in="";
+    settings.out="";
+	bool defaultMode=false;
 	for (int i=1; i < argc; ++i) {
         if(i==argc-2 && argv[i][1]!='-'){ // the arg before last (in)
-            d->settings.in = argv[i];
+            settings.in = argv[i];
         } else if (i==argc-1 && argv[i][1]!='-'){ // the last arg (out)
-            d->settings.out = argv[i];
-		} else if (argv[i][1] == '-') { //We have a long style argument
-			//Try to find a handler for this long switch
-			QHash<QString, ArgHandler*>::iterator j = d->longToHandler.find(argv[i]+2);
-			if (j == d->longToHandler.end()) { //Ups that argument did not exist
-				fprintf(stderr, "Unknown long argument %s\n\n", argv[i]);
-				d->usage(stderr, false);
-				exit(1);
-			}
-			//Check to see if there is enough arguments to the switch
-			if (argc-i < j.value()->argn.size()+1) {
-				fprintf(stderr, "Not enough arguments parsed to %s\n\n", argv[i]);
-				d->usage(stderr, false);
-				exit(1);
-			}
-			if (!(*(j.value()))(argv+i+1, *d)) {
-				fprintf(stderr, "Invalid argument(s) parsed to %s\n\n", argv[i]);
-				d->usage(stderr, false);
-				exit(1);
-			}
-			if (j.value()->qthack)
-				fprintf(stderr, "The switch %s, is not support using unpatched qt, and will be ignored.", argv[i]);
-			//Skip allredy handled switch arguments
-			i += j.value()->argn.size();
+            settings.out = argv[i];
 		} else {
-			int c=i;//Remember the current argument we are parsing
-			for (int j=1; argv[c][j] != '\0'; ++j) {
-				QHash<char, ArgHandler*>::iterator k = d->shortToHandler.find(argv[c][j]);
-				//If the short argument is invalid print usage information and exit
-				if (k == d->shortToHandler.end()) {
-					fprintf(stderr, "Unknown switch -%c\n\n", argv[c][j]);
-					d->usage(stderr, false);
-					exit(1);
-				}
-				//Check to see if there is enough arguments to the switch
-				if (argc-i < k.value()->argn.size()+1) {
-					fprintf(stderr, "Not enough arguments parsed to -%c\n\n", argv[c][j]);
-					d->usage(stderr, false);
-					exit(1);
-				}
-				if (!(*(k.value()))(argv+i+1, *d)) {
-					fprintf(stderr, "Invalid argument(s) parsed to -%c\n\n", argv[c][j]);
-					d->usage(stderr, false);
-					exit(1);
-				}
-			if (k.value()->qthack)
-				fprintf(stderr, "The switch -%c, is not support using unpatched qt, and will be ignored.", argv[c][j]);
-				//Skip allredy handled switch arguments
-				i += k.value()->argn.size();
-			}
+			parseArg(global, argc, argv, defaultMode, i, 0);
 		}
 	}
 
-	if(final || d->settings.in=="" || d->settings.out=="") {
+	if(final || settings.in=="" || settings.out=="") {
         fprintf(stderr, "You need to specify at least one input file, and exactly one output file\nUse - for stdin or stdout\n\n");
-        d->usage(stderr, false);
+        usage(stderr, false);
         exit(1);
     }
 }

+ 44 - 29
src/image/commandlineparser.hh

@@ -1,40 +1,55 @@
-/*
- * File:   commandlineparser.hh
- * Author: Christian Sciberras
- * Created: 20 May 2010
- *   This file is part of wkhtmltoimage.
- *   wkhtmltoimage is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   wkhtmltoimage is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with wkhtmltoimage.  If not, see <http://www.gnu.org/licenses/>.
- */
-
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef __COMMMAND_LINE_PARSER_HH__
 #define __COMMMAND_LINE_PARSER_HH__
 #include "settings.hh"
+#include "commandlineparserbase.hh"
 #include <cstdio>
 
-class CommandLineParserPrivate;
-
 /*! \brief The class is responcible for parsing command line information
 */
-class CommandLineParser {
+class CommandLineParser: public CommandLineParserBase {
 public:
-	CommandLineParser(Settings & settings);
-	~CommandLineParser();
-	void version(FILE * fd) const;
-	void usage(FILE * fd, bool extended) const;
-	void manpage(FILE * fd) const;
-	void readme(FILE * fd, bool html) const;
-	void loadDefaults();
+	const static int global = 1;
+	wkhtmltopdf::settings::Global & settings;
+
+	//arguments.cc
+	CommandLineParser(wkhtmltopdf::settings::Global & settings);
+	~CommandLineParser() {};
+	//docparts.cc
+	void outputManName(Outputter * o) const;
+	void outputSynopsis(Outputter * o) const;
+	void outputDescripton(Outputter * o) const;
+	void outputArgsFromStdin(Outputter * o) const;
+	void outputNotPatched(Outputter * o, bool sure) const;
+	void outputPageBreakDoc(Outputter * o) const;
+	void outputContact(Outputter * o) const;
+	void outputDocStart(Outputter * o) const;
+	void outputCompilation(Outputter * o) const;
+	void outputInstallation(Outputter * o) const;
+	void outputExamples(Outputter * o) const;
+
+	//commandlineparser.cc
+	virtual void usage(FILE * fd, bool extended) const;
+	virtual void manpage(FILE * fd) const;
+	virtual void readme(FILE * fd, bool html) const;
+	virtual QString appName() const {return "wkhtmltoimage";}
+
+	//void loadDefaults();
 	void parseArguments(int argc, const char ** argv, bool final=false);
-private:
-	CommandLineParserPrivate * d;
+
 };
 #endif //__COMMMAND_LINE_PARSER_HH__

+ 0 - 74
src/image/commandlineparser_p.hh

@@ -1,74 +0,0 @@
-/*
- * File:   commandlineparser_p.hh
- * Author: Christian Sciberras
- * Created: 20 May 2010
- *   This file is part of wkhtmltoimage.
- *   wkhtmltoimage is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   wkhtmltoimage is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with wkhtmltoimage.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __COMMMAND_LINE_PARSER_P_HH__
-#define __COMMMAND_LINE_PARSER_P_HH__
-
-#include <cstdio>
-#include <QString>
-#include "commandlineparser.hh"
-#include "settings.hh"
-#include "outputter.hh"
-
-class CommandLineParserPrivate;
-
-class ArgHandler: public ArgHandlerBase {
-public:
-	virtual bool operator() (const char ** args, CommandLineParserPrivate & parser) = 0;
-	virtual void useDefault(CommandLineParserPrivate & parser);
-};
-
-class CommandLineParserPrivate {
-public:
-	QString currentSection;
-	Settings & settings;
-	bool currentExtended;
-	bool currentHack;
-
-	QList<QString> sections;
-	QHash<QString, ArgHandler *> longToHandler;
-	QHash<char, ArgHandler *> shortToHandler;
-	QHash<QString, QList<ArgHandler *> > sectionArgumentHandles;
-	QHash<QString, QString> sectionDesc;
-
-	//arguments.cc
-	CommandLineParserPrivate(Settings & s);
-	void section(QString s, QString desc="");
-	void extended(bool);
-	void addarg(QString, char, QString, ArgHandler * h, bool display=true);
-
-	//docparts.cc
-	void outputManName(Outputter * o) const;
-	void outputSynopsis(Outputter * o) const;
-	void outputDescripton(Outputter * o) const;
-	void outputArgsFromStdin(Outputter * o) const;
-	void outputNotPatched(Outputter * o, bool sure) const;
-	void outputPageBreakDoc(Outputter * o) const;
-	void outputContact(Outputter * o) const;
-	void outputDocStart(Outputter * o) const;
-	void outputCompilation(Outputter * o) const;
-	void outputInstallation(Outputter * o) const;
-	void outputExamples(Outputter * o) const;
-	//commandlineparser.cc
-	void outputSwitches(Outputter * o, bool extended, bool doc) const;
-	void version(FILE * fd) const;
-	void usage(FILE * fd, bool extended) const;
-	void manpage(FILE * fd) const;
-	void readme(FILE * fd, bool html) const;
-};
-
-#endif //__COMMMAND_LINE_PARSER_P_HH__

+ 21 - 13
src/image/pageloader.cc → src/image/converter.cc

@@ -1,11 +1,19 @@
-/* 
- * File:   pageloader.cpp
- * Author: Christian Sciberras
- * 
- * Created on 20 ta’ Mejju 2010, 00:21
- */
-
-#include "pageloader.hh"
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "converter.hh"
 
 #include <QObject>
 #include <QWebPage>
@@ -18,19 +26,19 @@
 #include <QFileInfo>
 #include <QDebug>
 
-void PageLoader::loaded(bool ok) {
+void Converter::loaded(bool ok) {
 
 }
 
-PageLoader::PageLoader(Settings & s){
-	httpErrorCode=0;
+Converter::Converter(wkhtmltopdf::settings::Global & s){
+  httpErrorCode=0;
 	settings=s;
 }
 
-PageLoader::~PageLoader() {
+Converter::~Converter() {
 }
 
-bool PageLoader::convert() {
+bool Converter::convert() {
 	// init error code
 	httpErrorCode=0;
 	// quickfix; if out is "-", set quiet to ON

+ 14 - 12
src/shared/commondocparts.hh → src/image/converter.hh

@@ -1,5 +1,4 @@
-// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
-// vi:set ts=4 sts=4 sw=4 noet :
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
 // This file is part of wkhtmltopdf.
 //
 // wkhtmltopdf is free software: you can redistribute it and/or modify
@@ -14,16 +13,19 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-#ifndef __COMMONDOCPARTS_HH__
-#define __COMMONDOCPARTS_HH__
-#include "outputter.hh"
+#include <QObject>
+#include <QWebPage>
+#include "settings.hh"
 
-namespace commonDocParts {
-void outputName(Outputter * o, QString app);
-void outputLicense(Outputter * o);
-void outputAuthors(Outputter * o);
-void outputStaticProblems(Outputter * o);
-void outputProxyDoc(Outputter * o);
+class Converter: public QObject {
+	Q_OBJECT
+public:
+	Converter(wkhtmltopdf::settings::Global & s);
+	~Converter();
+	int httpErrorCode;
+	wkhtmltopdf::settings::Global settings;
+	bool convert();
+public slots:
+	void loaded(bool ok);
 };
 
-#endif //__COMMONDOCPARTS_HH__

+ 10 - 9
src/image/docparts.cc

@@ -13,7 +13,8 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-#include "commandlineparser_p.hh"
+#include "commandlineparser.hh"
+#include "outputter.hh"
 #include <QWebFrame>
 
 #define STRINGIZE_(x) #x
@@ -23,7 +24,7 @@
   Output name and a short description
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputManName(Outputter * o) const {
+void CommandLineParser::outputManName(Outputter * o) const {
 	o->beginSection("Name");
 	o->paragraph("wkhtmltoimage - html to image converter");
 	o->endSection();
@@ -33,7 +34,7 @@ void CommandLineParserPrivate::outputManName(Outputter * o) const {
   Output a short synopsis on how to call the command line program
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputSynopsis(Outputter * o) const {
+void CommandLineParser::outputSynopsis(Outputter * o) const {
 	o->beginSection("Synopsis");
 	o->verbatim("wkhtmltoimage [OPTIONS]... <input file> <output file>\n");
 	o->endSection();
@@ -43,7 +44,7 @@ void CommandLineParserPrivate::outputSynopsis(Outputter * o) const {
   Explain what the program does
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputDescripton(Outputter * o) const {
+void CommandLineParser::outputDescripton(Outputter * o) const {
 	o->beginSection("Description");
 	o->beginParagraph();
 	o->text("Converts an HTML page into an image, ");
@@ -56,7 +57,7 @@ void CommandLineParserPrivate::outputDescripton(Outputter * o) const {
   Output contact information
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputContact(Outputter * o) const {
+void CommandLineParser::outputContact(Outputter * o) const {
 	o->beginSection("Contact");
 	o->beginParagraph();
 	o->text("If you experience bugs or want to request new features please visit ");
@@ -71,7 +72,7 @@ void CommandLineParserPrivate::outputContact(Outputter * o) const {
   Output beginning of the readme
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputDocStart(Outputter * o) const {
+void CommandLineParser::outputDocStart(Outputter * o) const {
 	o->beginSection(QString("wkhtmltoimage ")+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD) + " Manual");
 	o->paragraph("This file documents wkhtmltoimage, a program capable of converting HTML "
 				 "documents into images.");
@@ -82,7 +83,7 @@ void CommandLineParserPrivate::outputDocStart(Outputter * o) const {
   Output information on how to compile
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputCompilation(Outputter * o) const {
+void CommandLineParser::outputCompilation(Outputter * o) const {
 	o->beginSection("Compilation");
 	o->paragraph("It can happen that the static binary does not work for your system "
 		     "for one reason or the other, in that case you might need to compile "
@@ -95,7 +96,7 @@ void CommandLineParserPrivate::outputCompilation(Outputter * o) const {
   Output information on how to install
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputInstallation(Outputter * o) const {
+void CommandLineParser::outputInstallation(Outputter * o) const {
 	o->beginSection("Installation");
 	o->paragraph(
 		"There are several ways to install wkhtmltoimage.  You can download a "
@@ -107,7 +108,7 @@ void CommandLineParserPrivate::outputInstallation(Outputter * o) const {
   Output examples on how to use wkhtmltoimage
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputExamples(Outputter * o) const {
+void CommandLineParser::outputExamples(Outputter * o) const {
 	o->beginSection("Examples");
 	o->paragraph("This section presents a number of examples of how to invoke wkhtmltoimage.");
 	o->paragraph("To convert a remote HTML file to PNG:");

+ 2 - 2
src/image/image.pro

@@ -34,8 +34,8 @@ INSTALLS += target
 target.path=$$INSTALLBASE/bin
 
 # Input
-HEADERS += pageloader.hh settings.hh
+HEADERS += pageloader.hh settings.hh converter.hh
 SOURCES += wkhtmltoimage.cc arguments.cc commandlineparser.cc docparts.cc \
-           pageloader.cc settings.cc utilities.cc \
+           converter.cc utilities.cc \
 
 include(../shared/shared.pri)

+ 0 - 23
src/image/pageloader.hh

@@ -1,23 +0,0 @@
-/* 
- * File:   pageloader.h
- * Author: Christian Sciberras
- *
- * Created on 20 ta’ Mejju 2010, 00:21
- */
-
-#include <QObject>
-#include <QWebPage>
-#include "settings.hh"
-
-class PageLoader: public QObject {
-	Q_OBJECT
-public:
-	PageLoader(Settings & s);
-	~PageLoader();
-	int httpErrorCode;
-	Settings settings;
-	bool convert();
-public slots:
-	void loaded(bool ok);
-};
-

+ 49 - 86
src/image/settings.hh

@@ -1,85 +1,65 @@
-/*
- * File:   convert.cc
- * Author: Christian Sciberras
- * Created: 20 May 2010
- *   This file is part of wkhtmltoimage.
- *   wkhtmltoimage is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   wkhtmltoimage is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with wkhtmltoimage.  If not, see <http://www.gnu.org/licenses/>.
- */
-
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef __SETTINGS_HH__
 #define __SETTINGS_HH__
+#include "loadsettings.hh"
 #include <QString>
 #include <qnetworkproxy.h>
 #include <QPrinter>
 
+namespace wkhtmltopdf {
+namespace settings {
+
+
+/*! \brief Settings for cropping image */
+struct CropSettings {
+	//! Cropping left/x coord
+	int left;
+	//! Cropping top/y coord
+	int top;
+	//! Cropping width/w dime
+	int width;
+	//! Cropping height/h dime
+	int height;
+};
+
+/*! \brief Settings for scaling image */
+struct ScaleSettings {
+	//! Scale width/w dime
+	int width;
+	//! Scale height/h dime
+	int height;
+};
+
 /*! \brief Class holding all user settings.
 
     This class holds all the user settings, settings can be filled in by hand,
     or with other methods. 
     \sa CommandLineParser::parse()
 */
-struct Settings {
-	/*! \brief Settings for proxy */
-	struct ProxySettings {
-		//! Type of proxy to use
-		QNetworkProxy::ProxyType type; 
-		//! The port of the proxy to use
-		int port; 
-		//! The host name of the proxy to use or NULL
-		QString host; 
-		//! Username for the said proxy or NULL
-		QString user; 
-		//! Password for the said proxy or NULL
-		QString password; 
-	};
-
-	// @dep: what is this for?
-	struct PostItem {
-		QString name;
-		QString value;
-		bool file;
-	};
-
-	/*! \brief Settings for cropping image */
-	struct CropSettings {
-		//! Cropping left/x coord
-		int left;
-		//! Cropping top/y coord
-		int top;
-		//! Cropping width/w dime
-		int width;
-		//! Cropping height/h dime
-		int height;
-	};
-
-	/*! \brief Settings for scaling image */
-	struct ScaleSettings {
-		//! Scale width/w dime
-		int width;
-		//! Scale height/h dime
-		int height;
-	};
-	
-	//! Proxy related settings
-	ProxySettings proxy;
+struct Global {
 	//! Crop related settings
 	CropSettings crop;
 	//! Scale related settings
 	ScaleSettings scale;
+	
+	LoadGlobal loadGlobal;
+	LoadPage loadPage;
 
-	//! Username used for http auth login
-	QString username;
-	//! Password used for http auth login
-	QString password;
 	//! Be less verbose
 	bool quiet; 
 	//! Should we print background images
@@ -93,14 +73,12 @@ struct Settings {
 	//! Should the horrible intelligent shrking feature be enabled?
 	bool enableIntelligentShrinking;
 	//! How many milliseconds should we wait for a javascrit redirect
-	int jsredirectwait;
-	//! Color or grayscale
+
 	QPrinter::ColorMode colorMode;
 	//! Minimum font size
 	int minimumFontSize;
 	//! Encoding used to enterpit a document which doesn't supply encoding
-	QString defaultEncoding;
-	//! Stylesheet supplied by the user
+	
 	QString userStyleSheet;
 	//! The file/url for input
 	QString in;
@@ -108,23 +86,8 @@ struct Settings {
 	QString out;
 	//! The output format
 	QString fmt;
-	//! Map of custum header valiabels
-	QList< QPair<QString, QString> > customHeaders;
-	//! Map of cookies
-	QList< QPair<QString, QString> > cookies;
-	//! Replacements
-	QList< QPair<QString, QString> > replacements;
-	//! Path of the cookie jar file
-	QString cookieJar;
-	
-	QList< PostItem > post;
-	bool stopSlowScripts;
-	bool debugJavascript;
-	bool blockLocalFileAccess;
-	QList< QString > allowed;
-	bool produceForms;
-
-	static ProxySettings strToProxy(const char * s, bool * ok=0);
 };
 
+}
+}
 #endif //__SETTINGS_HH__

+ 14 - 14
src/image/utilities.cc

@@ -19,11 +19,11 @@
  */
 class MyLooksStyle: public QCleanlooksStyle {
 public:
-	Settings & settings;
+  //	Settings & settings;
 
 	typedef QCleanlooksStyle parent_t;
 
-	MyLooksStyle(Settings & s): settings(s) {}
+  //MyLooksStyle(Settings & s): settings(s) {}
 
 	void drawPrimitive( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0 ) const {
 		painter->setBrush(Qt::white);
@@ -33,20 +33,20 @@ public:
 			painter->drawRect(r);
 		} else if(element == QStyle::PE_IndicatorCheckBox) {
 			painter->drawRect(r);
-			if (!settings.produceForms && (option->state & QStyle::State_On)) {
-				r.translate(int(r.width()*0.075), int(r.width()*0.075));
-				painter->drawLine(r.topLeft(), r.bottomRight());
-				painter->drawLine(r.topRight(), r.bottomLeft());
-			}
+			//if (!settings.produceForms && (option->state & QStyle::State_On)) {
+			r.translate(int(r.width()*0.075), int(r.width()*0.075));
+			painter->drawLine(r.topLeft(), r.bottomRight());
+			painter->drawLine(r.topRight(), r.bottomLeft());
+			//}
 		} else if(element == QStyle::PE_IndicatorRadioButton) {
 			painter->drawEllipse(r);
-			if (!settings.produceForms && (option->state & QStyle::State_On)) {
-				r.translate(int(r.width()*0.20), int(r.width()*0.20));
-				r.setWidth(int(r.width()*0.70));
-				r.setHeight(int(r.height()*0.70));
-				painter->setBrush(Qt::black);
-				painter->drawEllipse(r);
-			}
+			//if (!settings.produceForms && (option->state & QStyle::State_On)) {
+			r.translate(int(r.width()*0.20), int(r.width()*0.20));
+			r.setWidth(int(r.width()*0.70));
+			r.setHeight(int(r.height()*0.70));
+			painter->setBrush(Qt::black);
+			painter->drawEllipse(r);
+			//}
 		} else {
 			parent_t::drawPrimitive(element, option, painter, widget);
 		}

+ 20 - 22
src/image/wkhtmltoimage.cc

@@ -1,42 +1,40 @@
-																													/*
- * File:   wkhtmltoimage.cc
- * Author: Christian Sciberras
- * Created: 18 May 2010
- *   This file is part of wkhtmltoimage.
- *   wkhtmltoimage is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   wkhtmltoimage is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with wkhtmltoimage.  If not, see <http://www.gnu.org/licenses/>.
- */
-
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 #include "commandlineparser.hh"
 #include "settings.hh"
 #include "utilities.cc"
-#include "pageloader.hh"
+#include "converter.hh"
 #include <QApplication>
 
 int main(int argc, char** argv) {
 	//This will store all our settings
-	Settings settings;
+	wkhtmltopdf::settings::Global settings;
 	//Create a command line parser to parse commandline arguments
 	CommandLineParser parser(settings);
 	//Setup default values in settings
-	parser.loadDefaults();
+	//parser.loadDefaults();
 	//Parse the arguments
 	parser.parseArguments(argc, (const char**)argv);
 
 	//Construct QApplication required for printing
 	QApplication a( argc, argv );
-	a.setStyle(new MyLooksStyle(settings));
+	a.setStyle(new MyLooksStyle());
 
 	//Create the actual page converter to convert the pages
-	PageLoader converter(settings);
+	Converter converter(settings);
 
 	if (!converter.convert()) return EXIT_FAILURE;
 

+ 25 - 362
src/pdf/arguments.cc

@@ -14,7 +14,8 @@
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "commandlineparser_p.hh"
+#include "commandlineparser.hh"
+#include "arghandler.inl"
 #include <QFile>
 #include "pageconverter.hh"
 #include <qglobal.h>
@@ -72,190 +73,7 @@
   Implementation details for CommandLineParser
 */
 
-
-template <typename T> class DstArgHandler: public ArgHandler {
-public:
-	T & dst;
-	DstArgHandler(T & d): dst(d) {};
-
-	T & realDst(CommandLineParserPrivate & cp, Page & ps) {
-		//Very very ugly hack, when the setting is within the page settisgs offset
-		//Dummy struct return its location within the supplied page settings
-		//The dest is within the fake page offset struct 
-		
-		char * d = reinterpret_cast<char *>(&dst);
-		char * od = reinterpret_cast<char *>(&cp.od);
-		if(od > d || d >= od + sizeof(Page)) return dst;
-		return * reinterpret_cast<T*>(d - od + reinterpret_cast<char *>(&ps));
-	}
-};
-
-
-/*!
-  Sets a variable to some constant
-*/
-template <typename T> class ConstSetter: public DstArgHandler<T> {
-public:
-	typedef DstArgHandler<T> p_t;
-	const T src;
-	ConstSetter(T & arg, const T s): p_t(arg), src(s) {};
-	bool operator() (const char **, CommandLineParserPrivate & cp, Page & ps) {
-		p_t::realDst(cp,ps)=src;
-		return true;
-	}
-
-	virtual QString getDesc() const {
-		if (src != p_t::dst) return p_t::desc;
-		return p_t::desc + " (default)";
-	}
-
-};
-
-struct StringPairCreator {
-	typedef QPair<QString, QString> T;
-	inline T operator()(const QString & key, const QString & value) const {
-		return T(key, value);
-	}
-};
-
-template <bool file> 
-struct PostItemCreator {
-	typedef PostItem T;
-	inline T operator()(const QString & key, const QString & value) const {
-		T p;
-		p.name = key;
-		p.value = value;
-		p.file = file;
-		return p;
-	}
-};
-
-
-struct StringListSetter: public DstArgHandler<QList<QString> > {
-	typedef DstArgHandler<QList<QString> > p_t;
-	StringListSetter(QList<QString> & a, QString valueName) : p_t (a) {
-		p_t::argn.push_back(valueName);
-	}
-	virtual bool operator() (const char ** args, CommandLineParserPrivate & cp, Page & ps) {
-		p_t::realDst(cp, ps).append( args[0] );
-		return true;
-	}
-};
-
-
-/*!
-  Putting values into a map
-*/
-template <typename T=StringPairCreator>
-struct MapSetter: public DstArgHandler< QList< typename T::T > > {
-	typedef DstArgHandler< QList< typename T::T > > p_t;
-	MapSetter(QList<typename T::T > & a, QString keyName, QString valueName) : p_t(a) {
-		p_t::argn.push_back(keyName);
-		p_t::argn.push_back(valueName);
-	}
-	virtual bool operator() (const char ** args, CommandLineParserPrivate & cp, Page & ps) {
-		p_t::realDst(cp, ps).append( T()(args[0], args[1]) );
-		return true;
-	}
-};
-
-
-/*!
-  SomeSetter template method base
-*/
-template <typename TT> 
-struct SomeSetterTM {
-	typedef TT T;
-	//T strToT(const char * val, bool & ok);
-	static QString TToStr(const T &, bool & ok) {ok=false; return "";}
-};
-
-/*!
-  TemplateMethod class used to set a single variable of some type TT::T
-*/
-template <typename TT>
-struct SomeSetter: public DstArgHandler< typename TT::T > {
-	typedef DstArgHandler< typename TT::T > p_t;
-	typedef typename TT::T T;
-	bool hasDef;
-
-	SomeSetter(T & a, QString an, bool def=true): p_t(a), hasDef(def) {
-		p_t::argn.push_back(an);
-	}
-
-	bool operator() (const char ** vals, CommandLineParserPrivate & cp, Page & ps) {
-		bool ok;
-		p_t::realDst(cp, ps) = TT::strToT(vals[0], ok);
-		return ok;
-	}
-
-	virtual QString getDesc() const {
-		if (!hasDef) return p_t::desc;
-		bool ok;
-		QString x = TT::TToStr(p_t::dst, ok);
-		if (!ok) return p_t::desc;
-		return p_t::desc + " (default " + x + ")";
-	}
-};
-
-struct IntTM: public SomeSetterTM<int> {
-	static int strToT(const char * val, bool & ok) {
-		return QString(val).toInt(&ok);
-	}
-	static QString TToStr(const int & t, bool & ok) {
-		ok=(t!=-1);
-		return QString::number(t);
-	}
-};
-
-/*!
-  Argument handler setting an int variable
-*/
-typedef SomeSetter<IntTM> IntSetter;
-
-struct FloatTM: public SomeSetterTM<float> {
-	static float strToT(const char * val, bool & ok) {
-		return QString(val).toFloat(&ok);
-	}
-	static QString TToStr(const float & t, bool & ok) {
-		ok=(t!=-1);
-		return QString::number(t);
-	}
-};
-/*!
-  Argument handler setting an float variable
-*/
-typedef SomeSetter<FloatTM> FloatSetter;
-
-struct StrTM: public SomeSetterTM<const char *> {
-	static const char * strToT(const char * val, bool & ok) {
-		ok=true;
-		return val;
-	}
-	static QString TToStr(const char * t, bool & ok) {
-		ok = (t[0] != '\0');
-		return QString(t);
-	}
-};
-/*!
-  Argument handler setting a string variable
-*/
-typedef SomeSetter<StrTM> StrSetter;
-
-struct QStrTM: public SomeSetterTM<QString> {
-	static QString strToT(const char * val, bool & ok) {
-		ok=true;
-		return QString::fromLocal8Bit(val);
-	}
-	static QString TToStr(const QString & t, bool & ok) {
-		ok=!t.isEmpty();
-		return t;
-	}
-};
-/*!
-  Argument handler setting a string variable
-*/
-typedef SomeSetter<QStrTM> QStrSetter;
+using namespace wkhtmltopdf::settings;
 
 struct UnitRealTM: public SomeSetterTM<UnitReal> {
 	static UnitReal strToT(const char * val, bool &ok) {
@@ -284,16 +102,6 @@ struct PageSizeTM: public SomeSetterTM<QPrinter::PageSize> {
  */
 typedef SomeSetter<PageSizeTM> PageSizeSetter;
 
-struct ProxyTM: public SomeSetterTM<Proxy> {
-	static Proxy strToT(const char * val, bool &ok) {
-		return strToProxy(val, &ok);
-	}
-};
-/*!
-  Argument handler setting a proxy variable  
- */
-typedef SomeSetter<ProxyTM> ProxySetter;
-
 struct OrientationTM: public SomeSetterTM<QPrinter::Orientation> {
 	static QPrinter::Orientation strToT(const char * val, bool &ok) {
 		return strToOrientation(val, &ok);
@@ -308,48 +116,8 @@ struct OrientationTM: public SomeSetterTM<QPrinter::Orientation> {
  */
 typedef SomeSetter<OrientationTM> OrientationSetter;
 
-
-struct LoadErrorHandlingTM: public SomeSetterTM<Page::LoadErrorHandling> {
-	static Page::LoadErrorHandling strToT(const char * val, bool &ok) {
-		return strToLoadErrorHandling(val, &ok);
-	}
-	static QString TToStr(const Page::LoadErrorHandling & o, bool & ok) {
-		ok=true;
-		return loadErrorHandlingToStr(o);
-	}
-};
-typedef SomeSetter<LoadErrorHandlingTM> LoadErrorHandlingSetting;
-
-
-/*!
-  Argument handler responsible for calling a function
-*/
-template <typename T> struct Caller: public ArgHandler {
-	Caller() {}
-	Caller(QString a1) {
-		argn.push_back(a1);
-	}
-	bool operator() (const char **vals, CommandLineParserPrivate & s, Page & page) {
-		return T()(vals, s, page);
-	}
-};
-
-//All these function would have been lambda function, had C++ supported them, now we are forced to write them here
-
-/*!
-  Lambda: Call the usage method
-*/
-template <bool v>
-struct HelpFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p, Page &) {
-		p.usage(stdout,v);
-		exit(0);
-	}
-};
-
-
 struct DefaultTocFunc {
-	bool operator()(const char **, CommandLineParserPrivate &, Page &) {
+	bool operator()(const char **, CommandLineParserBase &, char *) {
 		QFile file;
 		file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
 		QTextStream stream(&file);
@@ -359,46 +127,16 @@ struct DefaultTocFunc {
 	}
 };
 
-/*!
-  Lambda: Call the man method
-*/
-struct ManPageFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p, Page &) {
-		p.manpage(stdout);
-		exit(0);
-	}
-};
-
-/*!
-  Lambda: Call the man method
-*/
-template <bool T>
-struct ReadmeFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p, Page &) {
-		p.readme(stdout, T);
-		exit(0);
-	}
-};
-
-/*!
-  Lambda: Call the version method
-*/
-struct VersionFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p, Page &) {
-		p.version(stdout);
-		exit(0);
-	}
-};
 
 /*!
   Set the default header
 */
 struct DefaultHeaderFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p, Page & page) {
-		page.header.left="[webpage]";
-		page.header.right="[page]/[toPage]";
-		page.header.line=true;
-		p.globalSettings.margin.top = strToUnitReal("2cm");
+	bool operator()(const char **, CommandLineParserBase & p, char * page) {
+		reinterpret_cast<Page*>(page)->header.left="[webpage]";
+		reinterpret_cast<Page*>(page)->header.right="[page]/[toPage]";
+		reinterpret_cast<Page*>(page)->header.line=true;
+		static_cast<CommandLineParser&>(p).globalSettings.margin.top = strToUnitReal("2cm");
 		return true;
 	}
 };
@@ -407,7 +145,7 @@ struct DefaultHeaderFunc {
   Setup default book mode
 */
 struct BookFunc {
-	bool operator()(const char **, CommandLineParserPrivate &) {
+	bool operator()(const char **, CommandLineParserBase &) {
 		//p.settings.header.left="[section]";
 		//p.settings.header.right="[page]/[toPage]";
 		//p.settings.header.line=true;
@@ -418,78 +156,25 @@ struct BookFunc {
 	}
 };
 
-/*!
-  The next arguments we add will belong to this section
-  /param s The name of the section
-  /param desc A description of the section
-*/
-void CommandLineParserPrivate::section(QString s, QString desc) {
-	currentSection = s;
-	sectionDesc[s] = desc;
-	sections.push_back(s);
-}
-
-/*!
-  Indicate whether the next arguments we add require a patched qt to work
-  /param h Do we require a patch
-*/
-void CommandLineParserPrivate::qthack(bool h) {
-	currentHack = h;
-}
-
-void CommandLineParserPrivate::mode(int m) {
-	currentMode = m;
-}
-
-/*!
-  Indicate whether the next arguments we add are "extended" and should not 
-  be shown in a simple --help
-  \param e Are the arguments extended
-*/
-void CommandLineParserPrivate::extended(bool e) {
-	currentExtended = e;
-}
-
-/*!
-  Add an argument to the list of arguments
-  \param l The long "--" name of the argument
-  \param s The short '-' name of the argument or 0 if unspecified
-  \param d Description of the argument
-  \param h The handler for the argument
-  \param display Is the argument hidden
-*/
-void CommandLineParserPrivate::addarg(QString l, char s, QString d, ArgHandler * h, bool display) {
-	h->desc = d;
-	h->longName = l;
-	h->shortSwitch = s;
-	h->display = display;
-	h->qthack = currentHack;
-	h->extended = currentExtended;
-	h->section = currentMode;
-	longToHandler[l] = h;
-	if(s) shortToHandler[s] = h;
-	sectionArgumentHandles[currentSection].push_back(h);
-}
-
 /*!
   Construct the commandline parser adding all the arguments
   \param s The settings to store values in
 */
-CommandLineParserPrivate::CommandLineParserPrivate(Global & s, QList<Page> & ps):
+CommandLineParser::CommandLineParser(Global & s, QList<Page> & ps):
 	readArgsFromStdin(false),
 	globalSettings(s),
 	pageSettings(ps)
 {
 	section("Global Options");
 	mode(global);
-	
+
+	addDocArgs();
+
 	extended(false);
 	qthack(false);
-	addarg("help", 'h', "Display help", new Caller<HelpFunc<false> >());
+
 	addarg("quiet", 'q', "Be less verbose", new ConstSetter<bool>(s.quiet,true));
-	addarg("version", 'V' ,"Output version information an exit", new Caller<VersionFunc>());
 	
-	addarg("extended-help", 'H',"Display more extensive help, detailing less common command switches", new Caller<HelpFunc<true> >());
 	addarg("no-collate", 0, "Do not collate when printing multiple copies", new ConstSetter<bool>(s.collate, false));
 	addarg("collate", 0, "Collate when printing multiple copies", new ConstSetter<bool>(s.collate, true));
 
@@ -513,15 +198,12 @@ CommandLineParserPrivate::CommandLineParserPrivate(Global & s, QList<Page> & ps)
  	addarg("margin-right",'R',"Set the page right margin", new UnitRealSetter(s.margin.right,"unitreal"));
  	addarg("margin-top",'T',"Set the page top margin", new UnitRealSetter(s.margin.top,"unitreal"));
 
- 	addarg("manpage", 0, "Output program man page", new Caller<ManPageFunc>());
- 	addarg("htmldoc", 0, "Output program html help", new Caller<ReadmeFunc<true> >());
- 	addarg("readme", 0, "Output program readme", new Caller<ReadmeFunc<false> >());
  	addarg("dpi",'d',"Change the dpi explicitly (this has no effect on X11 based systems)", new IntSetter(s.dpi,"dpi"));
  	addarg("page-height", 0, "Page height", new UnitRealSetter(s.size.height,"unitreal"));
  	addarg("page-width", 0, "Page width", new UnitRealSetter(s.size.width,"unitreal"));
 
 // 	addarg("book",'b',"Set the options one would usually set when printing a book", new Caller<BookFunc>());
-	addarg("cookie-jar", 0, "Read and write cookies from and to the supplied cookie jar file", new QStrSetter(s.cookieJar, "path") );
+	addGlobalLoadArgs(s.load);
 
 
 	extended(true);
@@ -546,30 +228,11 @@ CommandLineParserPrivate::CommandLineParserPrivate(Global & s, QList<Page> & ps)
  	extended(true);
  	qthack(false);
  	addarg("default-header",0,"Add a default header, with the name of the page to the left, and the page number to the right, this is short for: --header-left='[webpage]' --header-right='[page]/[toPage]' --top 2cm --header-line", new Caller<DefaultHeaderFunc>());
-	addarg("proxy",'p',"Use a proxy", new ProxySetter(od.proxy, "proxy"));
- 	addarg("username",0,"HTTP Authentication username", new QStrSetter(od.username, "username"));
- 	addarg("password",0,"HTTP Authentication password", new QStrSetter(od.password, "password"));
-	addarg("load-error-handling", 0, "Specify how to handle pages that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(od.loadErrorHandling, "handler"));
-	addarg("custom-header",0,"Set an additional HTTP header (repeatable)", new MapSetter<>(od.customHeaders, "name", "value"));
-	addarg("custom-header-propagation",0,"Add HTTP headers specified by --custom-header for each resource request.", new ConstSetter<bool>(od.repeatCustomHeaders, true));
-	addarg("no-custom-header-propagation",0,"Do not add HTTP headers specified by --custom-header for each resource request.", new ConstSetter<bool>(od.repeatCustomHeaders, true));
 
-	addarg("disable-javascript",'n',"Do not allow web pages to run javascript", new ConstSetter<bool>(od.enableJavascript,false));
-	addarg("enable-javascript",'n',"Do allow web pages to run javascript", new ConstSetter<bool>(od.enableJavascript,true));
-	
-	addarg("javascript-delay",0,"Wait some milliseconds for javascript finish", new IntSetter(od.jsdelay,"msec"));
  	addarg("enable-plugins",0,"Enable installed plugins (plugins will likely not work)", new ConstSetter<bool>(od.enablePlugins,true));
  	addarg("disable-plugins",0,"Disable installed plugins", new ConstSetter<bool>(od.enablePlugins,false));
 
 	addarg("minimum-font-size",0,"Minimum font size", new IntSetter(od.minimumFontSize,"int"));
- 	addarg("zoom",0,"Use this zoom factor", new FloatSetter(od.zoomFactor,"float",1.0));
- 	addarg("cookie",0,"Set an additional cookie (repeatable)", new MapSetter<>(od.cookies, "name", "value"));
- 	addarg("post", 0, "Add an additional post field (repeatable)", new MapSetter<PostItemCreator<false> >(od.post, "name", "value"));
- 	addarg("post-file", 0, "Post an additional file (repeatable)", new MapSetter<PostItemCreator<true> >(od.post, "name", "path"));
-	
-	addarg("disable-local-file-access", 0, "Do not allowed conversion of a local file to read in other local files, unless explecitily allowed with --allow", new ConstSetter<bool>(od.blockLocalFileAccess, true));
-	addarg("enable-local-file-access", 0, "Allowed conversion of a local file to read in other local files.", new ConstSetter<bool>(od.blockLocalFileAccess, false));
- 	addarg("allow", 0, "Allow the file or files from the specified folder to be loaded (repeatable)", new StringListSetter(od.allowed,"path"));
 
 #if QT_VERSION >= 0x040500 //Not printing the background was added in QT4.5
  	addarg("no-background",0,"Do not print background", new ConstSetter<bool>(od.background, false));
@@ -577,15 +240,6 @@ CommandLineParserPrivate::CommandLineParserPrivate(Global & s, QList<Page> & ps)
  	addarg("user-style-sheet",0,"Specify a user style sheet, to load with every page", new QStrSetter(od.userStyleSheet,"url"));
 #endif
    	
- 	addarg("debug-javascript", 0,"Show javascript debugging output", new ConstSetter<bool>(od.debugJavascript, true));
-	addarg("no-debug-javascript", 0,"Do not show javascript debugging output", new ConstSetter<bool>(od.debugJavascript, false));
-#if QT_VERSION >= 0x040600
- 	addarg("stop-slow-scripts", 0, "Stop slow running javascripts", new ConstSetter<bool>(od.stopSlowScripts, true));
- 	addarg("no-stop-slow-scripts", 0, "Do not Stop slow running javascripts", new ConstSetter<bool>(od.stopSlowScripts, true));
- 	addarg("no-images",0,"Do not load or print images", new ConstSetter<bool>(od.loadImages, false));
- 	addarg("images",0,"Do load or print images", new ConstSetter<bool>(od.loadImages, true));
-#endif	
-
  	extended(true);
  	qthack(true);
 	addarg("enable-forms", 0, "Turn HTML form fields into pdf form fields", new ConstSetter<bool>(od.produceForms, true));
@@ -601,6 +255,15 @@ CommandLineParserPrivate::CommandLineParserPrivate(Global & s, QList<Page> & ps)
 	addarg("enable-toc-back-links",0,"Do not link from section header to toc", new ConstSetter<bool>(od.toc.backLinks,true));
 	addarg("disable-toc-back-links",0,"Do not link from section header to toc", new ConstSetter<bool>(od.toc.backLinks,true));
 
+	addarg("disable-javascript",'n',"Do not allow web pages to run javascript", new ConstSetter<bool>(od.enableJavascript,false));
+	addarg("enable-javascript",'n',"Do allow web pages to run javascript", new ConstSetter<bool>(od.enableJavascript,true));
+
+	addPageLoadArgs(od.load);
+#if QT_VERSION >= 0x040600
+	addarg("no-images",0,"Do not load or print images", new ConstSetter<bool>(od.loadImages, false));
+	addarg("images",0,"Do load or print images", new ConstSetter<bool>(od.loadImages, true));
+#endif	
+
 
 // 	addarg("page-offset",0,"Set the starting page number", new IntSetter(s.pageOffset,"offset",1));
 

+ 30 - 215
src/pdf/commandlineparser.cc

@@ -13,10 +13,11 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-#include "commandlineparser_p.hh"
-#include "commondocparts.hh"
+#include "commandlineparser.hh"
+#include "outputter.hh"
 #include <qwebframe.h>
 
+using namespace wkhtmltopdf::settings;
 /*!
   \file commandlineparser.hh
   \brief Defines the CommandLineParser class
@@ -27,67 +28,17 @@
   \brief Defines the CommandLineParserPrivate, ArgHandler and Outputter class
 */
 
-bool ahsort(const ArgHandler * a, const ArgHandler * b) {
-	QRegExp e("^(no|enable|disable)-");
-	QString x=a->longName;
-	QString y=b->longName;
-	x.remove(e);
-	y.remove(e);
-	if (x == y) {
-		QRegExp e("^no-");
-		x=a->longName;
-		y=b->longName;
-		x.replace(e,"zzzz");
-		y.replace(e,"zzzz");
-	}
-	return x < y;
-}
-
-/*!
-  Output description of switches to an outputter
-  \param o The outputter to output to
-  \param extended Should we also output extended arguments
-  \param doc Indicate to the outputter that it is writing documentation
-*/
-void CommandLineParserPrivate::outputSwitches(Outputter * o, bool extended, bool doc) const {
-	foreach(const QString & section, sections) {
-		QList<const ArgHandler *> display;
-		foreach(const ArgHandler * handler, sectionArgumentHandles[section]) {
-#ifndef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-			if(!doc && handler->qthack) continue;
-#else 
-			Q_UNUSED(doc);
-#endif
-			if(!extended && handler->extended) continue;
-			display.push_back(handler);
-		}
-		qSort(display.begin(), display.end(), ahsort);
-		if(display.size() == 0) continue;
-		o->beginSection(section);
-		if(!sectionDesc[section].isEmpty()) {
-			o->beginParagraph();
-			o->text(sectionDesc[section]);
-			o->endParagraph();
-		}
-		o->beginSwitch();
-		foreach(const ArgHandler * handler, display)
-			o->cswitch(handler);
-		o->endSwitch();
-		o->endSection();
- 	}
-}
-
 /*!
   Output the man page to a given file
   \param fd The file to store the man page
 */
-void CommandLineParserPrivate::manpage(FILE * fd) const {
+void CommandLineParser::manpage(FILE * fd) const {
 	Outputter * o = Outputter::man(fd);
  	outputManName(o);
  	outputSynopsis(o);
  	outputDescripton(o);
 	outputSwitches(o, true, false);
-	commonDocParts::outputProxyDoc(o);
+	outputProxyDoc(o);
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
  	outputHeaderFooterDoc(o);
  	outputOutlineDoc(o);
@@ -98,7 +49,7 @@ void CommandLineParserPrivate::manpage(FILE * fd) const {
 	outputArgsFromStdin(o);
  	outputPageBreakDoc(o);
  	outputContact(o);
- 	commonDocParts::outputAuthors(o);
+ 	outputAuthors(o);
 	delete o;
 }
 
@@ -107,9 +58,9 @@ void CommandLineParserPrivate::manpage(FILE * fd) const {
   \param fd The file to output the information to
   \param extended Should we show extended arguments
 */
-void CommandLineParserPrivate::usage(FILE * fd, bool extended) const {
+void CommandLineParser::usage(FILE * fd, bool extended) const {
 	Outputter * o = Outputter::text(fd,false);
-	commonDocParts::outputName(o, "wkhtmltopdf");
+	outputName(o);
 	outputSynopsis(o);
  	outputDescripton(o);
 	outputSwitches(o, extended, false);
@@ -119,7 +70,7 @@ void CommandLineParserPrivate::usage(FILE * fd, bool extended) const {
 	if (extended) {
 		outputPageSizes(o);
 		outputArgsFromStdin(o);
-		commonDocParts::outputProxyDoc(o);
+		outputProxyDoc(o);
 		outputHeaderFooterDoc(o);
 		outputOutlineDoc(o);
 	}
@@ -127,99 +78,40 @@ void CommandLineParserPrivate::usage(FILE * fd, bool extended) const {
 	delete o;
 }
 
-/*!
-  Output version information aka. --version
-  \param fd The file to output to
-*/
-void CommandLineParserPrivate::version(FILE * fd) const {
- 	Outputter * o = Outputter::text(fd,false);
-  	commonDocParts::outputName(o, "wkhtmltopdf");
-  	commonDocParts::outputLicense(o);
-  	commonDocParts::outputAuthors(o);
-	delete o;
-}
-
 /*!
   Output the readme/manual
   \param fd The file to output to
   \param html Do we want the html manaul, or the README
 */
-void CommandLineParserPrivate::readme(FILE * fd, bool html) const {
+void CommandLineParser::readme(FILE * fd, bool html) const {
 	Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
 	outputDocStart(o);
 	outputContact(o);
 	outputNotPatched(o, false);
-	commonDocParts::outputLicense(o);
-	commonDocParts::outputAuthors(o);
+	outputLicense(o);
+	outputAuthors(o);
 	outputSynopsis(o);
 	outputSwitches(o, true, true);
- 	commonDocParts::outputProxyDoc(o);
+ 	outputProxyDoc(o);
  	outputHeaderFooterDoc(o);
  	outputOutlineDoc(o);
  	outputPageBreakDoc(o);
 	outputPageSizes(o);
 	outputArgsFromStdin(o);
-	commonDocParts::outputStaticProblems(o);
+	outputStaticProblems(o);
 	outputCompilation(o);
 	outputInstallation(o);
 	outputExampels(o);
 	delete o;
 }
 
-/*!
-  Output usage information aka. --help
-  \param fd The file to output the information to
-  \param extended Should we show extended arguments
-*/
-void CommandLineParser::usage(FILE * fd, bool extended) const {
-	d->usage(fd, extended);
-}
-
-/*!
-  Output version information aka. --version
-  \param fd The file to output to
-*/
-void CommandLineParser::version(FILE * fd) const {
-	d->version(fd);
-}
-
-/*!
-  Output the man page to a given file
-  \param fd The file to store the man page
-*/
-void CommandLineParser::manpage(FILE * fd) const {
-	d->manpage(fd);
-}
-
-/*!
-  Output the readme/manual
-  \param fd The file to output to
-  \param html Do we want the html manaul, or the README
-*/
-void CommandLineParser::readme(FILE * fd, bool html) const {
-	d->readme(fd,html);
-}
-
-/*!
-  Construct a commandline parser, storing its values in some settings
-  \param s The settings to store the values in.
-*/
-CommandLineParser::CommandLineParser(Global & s, QList<Page> & ps):
-	d(new CommandLineParserPrivate(s, ps))
-{
-}
-	
-CommandLineParser::~CommandLineParser() {
-	delete d;
-}
-
 /*!
  * Load default arguments and put them in the settings structure
  */
-void CommandLineParser::loadDefaults() {
-	//d->settings.in.clear();
-	//d->settings.proxy.host = "";
-	//foreach(ArgHandler * h, d->longToHandler) 
+//void CommandLineParser::loadDefaults() {
+	//settings.in.clear();
+	//settings.proxy.host = "";
+	//foreach(ArgHandler * h, longToHandler) 
 	//	h->useDefault(*d);
 
 	//Load configuration from enviornment
@@ -230,89 +122,12 @@ void CommandLineParser::loadDefaults() {
 	//		bool ok=false;
 	//		Settings::ProxySettings p = Settings::strToProxy(val, &ok);
 	//		if(ok) 
-	//			d->settings.proxy = p;
+	//			settings.proxy = p;
 	//	}
 	//}
-}
-
-
-void CommandLineParserPrivate::parseArg(int sections, const int argc, const char ** argv, bool & defaultMode, int & arg, Page & page) {
-	if (argv[arg][1] == '-') { //We have a long style argument
-		//After an -- apperas in the argument list all that follows is interpited as default arguments
-		if (argv[arg][2] == '0') {
-			defaultMode=true;
-			return;
-		}
-		//Try to find a handler for this long switch
-		QHash<QString, ArgHandler*>::iterator j = longToHandler.find(argv[arg]+2);
-		if (j == longToHandler.end()) { //Ups that argument did not exist
-			fprintf(stderr, "Unknown long argument %s\n\n", argv[arg]);
-			usage(stderr, false);
-			exit(1);
-		}
-		if (!(j.value()->section & sections)) {
-			fprintf(stderr, "%s specified in incorrect location\n\n", argv[arg]);
-			usage(stderr, false);
-			exit(1);
-		}
-		//Check to see if there is enough arguments to the switch
-		if (argc-arg < j.value()->argn.size()+1) {
-			fprintf(stderr, "Not enough arguments parsed to %s\n\n", argv[arg]);
-			usage(stderr, false);
-			exit(1);
-		}
-		if (!(*(j.value()))(argv+arg+1, *this, page)) {
-			fprintf(stderr, "Invalid argument(s) parsed to %s\n\n", argv[arg]);
-			usage(stderr, false);
-			exit(1);
-		}
-#ifndef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-		if (j.value()->qthack)
-			fprintf(stderr, "The switch %s, is not support using unpatched qt, and will be ignored.", argv[arg]);
-#endif
-		//Skip allredy handled switch arguments
-		arg += j.value()->argn.size();
-	} else {
-		int c=arg;//Remember the current argument we are parsing
-		for (int j=1; argv[c][j] != '\0'; ++j) {
-			QHash<char, ArgHandler*>::iterator k = shortToHandler.find(argv[c][j]);
-			//If the short argument is invalid print usage information and exit
-			if (k == shortToHandler.end()) {
-				fprintf(stderr, "Unknown switch -%c\n\n", argv[c][j]);
-				usage(stderr, false);
-				exit(1);
-			}
-			if (!(k.value()->section & sections)) {
-				fprintf(stderr, "-%c specified in incorrect location\n\n", argv[c][j]);
-				usage(stderr, false);
-				exit(1);
-			}
-			//Check to see if there is enough arguments to the switch
-			if (argc-arg < k.value()->argn.size()+1) {
-				fprintf(stderr, "Not enough arguments parsed to -%c\n\n", argv[c][j]);
-				usage(stderr, false);
-				exit(1);
-			}
-			if (!(*(k.value()))(argv+arg+1, *this, page)) {
-				fprintf(stderr, "Invalid argument(s) parsed to -%c\n\n", argv[c][j]);
-				usage(stderr, false);
-				exit(1);
-			}
-#ifndef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
- 			if (k.value()->qthack)
- 				fprintf(stderr, "The switch -%c, is not support using unpatched qt, and will be ignored.", argv[c][j]);
-#endif
-			//Skip allredy handled switch arguments
-			arg += k.value()->argn.size();
-		}
-	}
-}
+//}
 
 
-bool CommandLineParser::readArgsFromStdin() const {
-	return d->readArgsFromStdin;
-}
-
 /*!
  * Parse command line arguments, and set settings accordingly.
  * \param argc the number of command line arguments
@@ -327,16 +142,16 @@ void CommandLineParser::parseArguments(int argc, const char ** argv, bool fromSt
 	//Parse global options
 	for(;arg < argc;++arg) {
 		if (argv[arg][0] != '-' || argv[arg][1] == '\0' || defaultMode) break;
-		d->parseArg(d->global | d->page, argc, argv, defaultMode, arg, def);
+		parseArg(global | page, argc, argv, defaultMode, arg, (char *)&def);
 	}
 	
-	if (d->readArgsFromStdin && !fromStdin) return;
+	if (readArgsFromStdin && !fromStdin) return;
 
 	//Parse page options
 	while(arg < argc-1) {
-		d->pageSettings.push_back(def);
-		Page & ps = d->pageSettings.back();
-		int sections = d->page;
+		pageSettings.push_back(def);
+		Page & ps = pageSettings.back();
+		int sections = page;
 		if (!strcmp(argv[arg],"cover")) {
 			++arg;
 			if(arg >= argc-1) {
@@ -356,7 +171,7 @@ void CommandLineParser::parseArguments(int argc, const char ** argv, bool fromSt
 			++arg;
 		} else if (!strcmp(argv[arg],"toc")) {
 			++arg;
-			sections = d->page | d->toc;
+			sections = page | toc;
 			ps.isTableOfContent = true;
 		} else {
 			if (!strcmp(argv[arg],"page")) {
@@ -372,16 +187,16 @@ void CommandLineParser::parseArguments(int argc, const char ** argv, bool fromSt
 		}
 		for(;arg < argc;++arg) {
 			if (argv[arg][0] != '-' || argv[arg][1] == '\0' || defaultMode) break;
-			d->parseArg(sections, argc, argv, defaultMode, arg, ps);
+			parseArg(sections, argc, argv, defaultMode, arg, (char*)&ps);
 		}
 	}
 	
-	if (d->pageSettings.size() == 0 || argc < 2) {
+	if (pageSettings.size() == 0 || argc < 2) {
 		fprintf(stderr, "You need to specify atleast one input file, and exactly one output file\nUse - for stdin or stdout\n\n");
-		d->usage(stderr, false);
+		usage(stderr, false);
 		exit(1);
 	}
-	d->globalSettings.out = argv[argc-1];
+	globalSettings.out = argv[argc-1];
 }
 
 

+ 43 - 14
src/pdf/commandlineparser.hh

@@ -16,25 +16,54 @@
 #ifndef __COMMMAND_LINE_PARSER_HH__
 #define __COMMMAND_LINE_PARSER_HH__
 #include "settings.hh"
+#include "commandlineparserbase.hh"
 #include <cstdio>
 
-class CommandLineParserPrivate;
-
-/*! \brief The class is responcible for parsing command line information
-*/
-class CommandLineParser {
+class CommandLineParser: public CommandLineParserBase {
 public:
+	const static int global = 1;
+	const static int page = 2;
+	const static int toc = 4;
+	bool readArgsFromStdin;
+	wkhtmltopdf::settings::Global & globalSettings;
+	QList<wkhtmltopdf::settings::Page> & pageSettings;
+
+	wkhtmltopdf::settings::Page od;
+	
+	//Arguments.cc
 	CommandLineParser(wkhtmltopdf::settings::Global & globalSettings, 
 					  QList<wkhtmltopdf::settings::Page> & pageSettings);
-	~CommandLineParser();
-	void version(FILE * fd) const;
-	void usage(FILE * fd, bool extended) const;
-	void manpage(FILE * fd) const;
-	void readme(FILE * fd, bool html) const;
-	void loadDefaults();
+
+	//docparts.cc
+	void outputManName(Outputter * o) const;
+	void outputSynopsis(Outputter * o) const;
+	void outputDescripton(Outputter * o) const;
+	void outputPageSizes(Outputter * o) const;
+	void outputArgsFromStdin(Outputter * o) const;
+	void outputHeaderFooterDoc(Outputter * o) const;
+	void outputOutlineDoc(Outputter * o) const;
+	void outputNotPatched(Outputter * o, bool sure) const;
+	void outputPageBreakDoc(Outputter * o) const;
+	void outputContact(Outputter * o) const;
+	void outputDocStart(Outputter * o) const;
+	void outputCompilation(Outputter * o) const;
+	void outputInstallation(Outputter * o) const;
+	void outputExampels(Outputter * o) const;
+	
+	//commandlineparser.cc
+	virtual QString appName() const {return "wkhtmltopdf";}
+	virtual void usage(FILE * fd, bool extended) const;
+	virtual void manpage(FILE * fd) const;
+	virtual void readme(FILE * fd, bool html) const;
+
 	void parseArguments(int argc, const char ** argv, bool fromStdin=false);
-	bool readArgsFromStdin() const;
-private:
-	CommandLineParserPrivate * d;
+
+	virtual char * mapAddress(char * d, char * ns) const {
+		char * od = reinterpret_cast<char *>(&od);
+		if(od > d || d >= od + sizeof(wkhtmltopdf::settings::Page)) return d;;
+		return d - od + ns;
+	}
+ 
 };
+
 #endif //__COMMMAND_LINE_PARSER_HH__

+ 0 - 88
src/pdf/commandlineparser_p.hh

@@ -1,88 +0,0 @@
-//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
-// This file is part of wkhtmltopdf.
-//
-// wkhtmltopdf is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// wkhtmltopdf is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-#ifndef __COMMMAND_LINE_PARSER_P_HH__
-#define __COMMMAND_LINE_PARSER_P_HH__
-
-#include <cstdio>
-#include <QString>
-#include "commandlineparser.hh"
-#include "settings.hh"
-#include "outputter.hh"
-
-using namespace wkhtmltopdf::settings;
-
-class CommandLineParserPrivate;
-
-class ArgHandler: public ArgHandlerBase {
-public:
-	int section;
-	virtual bool operator() (const char ** args, CommandLineParserPrivate & parser, Page & page) = 0;
-};
-
-class CommandLineParserPrivate {
-public:
-	const static int global = 1;
-	const static int page = 2;
-	const static int toc = 4;
-
-	bool readArgsFromStdin;
-	Page od;
-	int currentMode;
-	QString currentSection;
-	Global & globalSettings;
-	QList<Page> & pageSettings;
-	bool currentExtended;
-	bool currentHack;
-
-	QList<QString> sections;
-	QHash<QString, ArgHandler *> longToHandler;
-	QHash<char, ArgHandler *> shortToHandler;
-	QHash<QString, QList<ArgHandler *> > sectionArgumentHandles;
-	QHash<QString, QString> sectionDesc;
-
-	//arguments.cc
-	CommandLineParserPrivate(Global & gs, QList<Page> & ps);
-	void section(QString s, QString desc="");
-	void mode(int m);
-	void qthack(bool);
-	void extended(bool);
-	void addarg(QString, char, QString, ArgHandler * h, bool display=true);
-	void parseArg(int sections, const int argc, const char ** argv, bool & defaultMode, int & arg, Page & page);
-
-	//docparts.cc
-	void outputManName(Outputter * o) const;
-	void outputSynopsis(Outputter * o) const;
-	void outputDescripton(Outputter * o) const;
-	void outputPageSizes(Outputter * o) const;
-	void outputArgsFromStdin(Outputter * o) const;
-	void outputHeaderFooterDoc(Outputter * o) const;
-	void outputOutlineDoc(Outputter * o) const;
-	void outputNotPatched(Outputter * o, bool sure) const;
-	void outputPageBreakDoc(Outputter * o) const;
-	void outputContact(Outputter * o) const;
-	void outputDocStart(Outputter * o) const;
-	void outputCompilation(Outputter * o) const;
-	void outputInstallation(Outputter * o) const;
-	void outputExampels(Outputter * o) const;
-	//commandlineparser.cc
-	void outputSwitches(Outputter * o, bool extended, bool doc) const;
-	void version(FILE * fd) const;
-	void usage(FILE * fd, bool extended) const;
-	void manpage(FILE * fd) const;
-	void readme(FILE * fd, bool html) const;
-};
-
-#endif //__COMMMAND_LINE_PARSER_P_HH__

+ 16 - 15
src/pdf/docparts.cc

@@ -13,7 +13,8 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-#include "commandlineparser_p.hh"
+#include "commandlineparser.hh"
+#include "outputter.hh"
 #include <QWebFrame>
 
 #define STRINGIZE_(x) #x
@@ -23,7 +24,7 @@
   Output name and a short description
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputManName(Outputter * o) const {
+void CommandLineParser::outputManName(Outputter * o) const {
 	o->beginSection("Name");
 	o->paragraph("wkhtmltopdf - html to pdf converter");
 	o->endSection();
@@ -33,7 +34,7 @@ void CommandLineParserPrivate::outputManName(Outputter * o) const {
   Output a short synopsis on how to call the command line program
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputSynopsis(Outputter * o) const {
+void CommandLineParser::outputSynopsis(Outputter * o) const {
 	o->beginSection("Synopsis");
 	o->verbatim("wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>\n");
 	o->endSection();
@@ -85,7 +86,7 @@ void CommandLineParserPrivate::outputSynopsis(Outputter * o) const {
   Explain what the program does
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputDescripton(Outputter * o) const {
+void CommandLineParser::outputDescripton(Outputter * o) const {
 	o->beginSection("Description");
 	o->beginParagraph();
 	o->text("Converts one or more HTML pages into a PDF document, ");
@@ -104,7 +105,7 @@ void CommandLineParserPrivate::outputDescripton(Outputter * o) const {
   \param o The outputter to output to
   \param sure Is the functionality restricted in this wkhtmltopdf
 */
-void CommandLineParserPrivate::outputNotPatched(Outputter * o, bool sure) const {
+void CommandLineParser::outputNotPatched(Outputter * o, bool sure) const {
 	o->beginSection("Reduced Functionality");
 	if (sure) 
 		o->paragraph("This version of wkhtmltopdf has been compiled against a version of "
@@ -134,7 +135,7 @@ void CommandLineParserPrivate::outputNotPatched(Outputter * o, bool sure) const
   Explain the page breaking is somewhat broken
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputPageBreakDoc(Outputter * o) const {
+void CommandLineParser::outputPageBreakDoc(Outputter * o) const {
 	o->beginSection("Page Breaking");
 	o->paragraph(
 		"The current page breaking algorithm of WebKit leaves much to be desired. "
@@ -163,7 +164,7 @@ void CommandLineParserPrivate::outputPageBreakDoc(Outputter * o) const {
   Output documentation about headers and footers
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputHeaderFooterDoc(Outputter * o) const {
+void CommandLineParser::outputHeaderFooterDoc(Outputter * o) const {
 	o->beginSection("Footers And Headers");
 	o->paragraph("Headers and footers can be added to the document by the --header-* and --footer* "
 				 "arguments respectfully.  In header and footer text string supplied to e.g. --header-left, "
@@ -217,7 +218,7 @@ void CommandLineParserPrivate::outputHeaderFooterDoc(Outputter * o) const {
   Output documentation about outlines
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputOutlineDoc(Outputter * o) const {
+void CommandLineParser::outputOutlineDoc(Outputter * o) const {
 	o->beginSection("Outlines");
 	o->beginParagraph();
 	o->text(
@@ -239,7 +240,7 @@ void CommandLineParserPrivate::outputOutlineDoc(Outputter * o) const {
   Output contact information
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputContact(Outputter * o) const {
+void CommandLineParser::outputContact(Outputter * o) const {
 	o->beginSection("Contact");
 	o->beginParagraph();
 	o->text("If you experience bugs or want to request new features please visit ");
@@ -254,7 +255,7 @@ void CommandLineParserPrivate::outputContact(Outputter * o) const {
   Output beginning of the readme
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputDocStart(Outputter * o) const {
+void CommandLineParser::outputDocStart(Outputter * o) const {
 	o->beginSection(QString("wkhtmltopdf ")+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD) + " Manual");
 	o->paragraph("This file documents wkhtmltopdf, a program capable of converting html "
 				 "documents into PDF documents.");
@@ -265,7 +266,7 @@ void CommandLineParserPrivate::outputDocStart(Outputter * o) const {
   Output information on how to use read-args-from-stdin
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputArgsFromStdin(Outputter * o) const {
+void CommandLineParser::outputArgsFromStdin(Outputter * o) const {
 	o->beginSection("Reading arguments from stdin");
 	o->paragraph("If you need to convert a lot of pages in a batch, and you feel that wkhtmltopdf "
 				 "is a bit to slow to start up, then you should try --read-args-from-stdin,");
@@ -283,7 +284,7 @@ void CommandLineParserPrivate::outputArgsFromStdin(Outputter * o) const {
   Output information on how to compile
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputCompilation(Outputter * o) const {
+void CommandLineParser::outputCompilation(Outputter * o) const {
 	o->beginSection("Compilation");
 	o->paragraph("It can happen that the static binary does not work for your system "
 				 "for one reason or the other, in that case you might need to compile "
@@ -332,7 +333,7 @@ void CommandLineParserPrivate::outputCompilation(Outputter * o) const {
   Output information on how to install
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputInstallation(Outputter * o) const {
+void CommandLineParser::outputInstallation(Outputter * o) const {
 	o->beginSection("Installation");
 	o->paragraph(
 		"There are several ways to install wkhtmltopdf.  You can download a "
@@ -350,7 +351,7 @@ void CommandLineParserPrivate::outputInstallation(Outputter * o) const {
   \param o The outputter to output to
 
 */
-void CommandLineParserPrivate::outputPageSizes(Outputter * o) const {
+void CommandLineParser::outputPageSizes(Outputter * o) const {
 	o->beginSection("Page sizes");
 	o->beginParagraph();
 	o->text("The default page size of the rendered document is A4, but using this --page-size option"
@@ -368,7 +369,7 @@ void CommandLineParserPrivate::outputPageSizes(Outputter * o) const {
   Output examples on how to use wkhtmltopdf
   \param o The outputter to output to
 */
-void CommandLineParserPrivate::outputExampels(Outputter * o) const {
+void CommandLineParser::outputExampels(Outputter * o) const {
 	o->beginSection("Examples");
 	o->paragraph("This section presents a number of examples of how to invoke wkhtmltopdf.");
 	o->paragraph("To convert a remote HTML file to PDF:");

+ 5 - 5
src/pdf/pageconverter.cc

@@ -65,10 +65,10 @@ bool looksLikeHtmlAndNotAUrl(QString str) {
 }
 
 PageConverterPrivate::PageConverterPrivate(Global & s, PageConverter & o) :
-	settings(s), pageLoader(s),
+	settings(s), pageLoader(s.load),
 	outer(o), printer(0), painter(0)
 #ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-	, hfLoader(s), tocLoader1(s), tocLoader2(s)
+	, hfLoader(s.load), tocLoader1(s.load), tocLoader2(s.load)
 	, tocLoader(&tocLoader1), tocLoaderOld(&tocLoader2)
 	, outline(0), tocPrinter(0)
 #endif
@@ -187,7 +187,7 @@ void PageConverterPrivate::beginConvert() {
 		}
 
 		if (!s.isTableOfContent) {
-			o.loaderObject = pageLoader.addResource(s.page, s);
+			o.loaderObject = pageLoader.addResource(s.page, s.load);
 			o.page = &o.loaderObject->page;
 			PageObject::webPageToObject[o.page] = &o;
 			updateWebSettings(o.page->settings(), s);
@@ -386,7 +386,7 @@ void PageConverterPrivate::loadTocs() {
 		StreamDumper sd(path);
 		outline->dump(sd.stream, style);
 		
-		obj.loaderObject = pageLoader.addResource(path, ps);
+		obj.loaderObject = pageLoader.addResource(path, ps.load);
 		obj.page = &obj.loaderObject->page;
 		PageObject::webPageToObject[obj.page] = &obj;
 		updateWebSettings(obj.page->settings(), ps);
@@ -777,7 +777,7 @@ QWebPage * PageConverterPrivate::loadHeaderFooter(QString url, const QHash<QStri
 	QUrl u = MultiPageLoader::guessUrlFromString(url);
 	for(QHash<QString, QString>::const_iterator i=parms.begin(); i != parms.end(); ++i)
 		u.addQueryItem(i.key(), i.value());
-	return &hfLoader.addResource(u, ps)->page;
+	return &hfLoader.addResource(u, ps.load)->page;
 
 }
 

BIN
src/pdf/pdf


+ 3 - 4
src/pdf/pdf.pro

@@ -30,11 +30,10 @@ INSTALLS += target
 target.path=$$INSTALLBASE/bin
 
 #Libaray part
-HEADERS += pageconverter.hh pageconverter_p.hh \
-           multipageloader_p.hh multipageloader.hh
+HEADERS += pageconverter.hh pageconverter_p.hh
 
-SOURCES += tempfile.cc settings.cc pageconverter.cc \
-           multipageloader.cc outline.cc tocstylesheet.cc
+SOURCES += settings.cc pageconverter.cc \
+           outline.cc tocstylesheet.cc
 
 #Application part
 

+ 0 - 87
src/pdf/settings.cc

@@ -86,25 +86,6 @@ QString pageSizeToStr(QPrinter::PageSize ps) {
 }
 
 
-Page::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok) {
-	if (ok) *ok = true;
-	if (!strcasecmp(s, "abort")) return Page::abort;
-	if (!strcasecmp(s, "skip")) return Page::skip;
-	if (!strcasecmp(s, "ignore")) return Page::ignore;
-	*ok = false;
-	return Page::abort;
-}
-
-QString loadErrorHandlingToStr(Page::LoadErrorHandling leh) {
-	switch(leh) {
-	case Page::abort: return "abort";
-	case Page::skip: return "skip";
-	case Page::ignore: return "ignore";
-	}
-	throw std::logic_error("Internal error in loadErrorHandlingToStr");
-}
-
-
 /*!
   Read orientation from a string, possible values are landscape and portrait (case insensitive)
   \param s The string containing the orientation
@@ -186,66 +167,6 @@ QString unitRealToStr(const UnitReal & ur, bool * ok) {
 }
 
 
-/*!
-  Read proxy settings from a string, the grammar is described in the manual
-  \param proxy the proxy string to parse
-  \param ok If supplied indicates whether the proxy was valid
-*/
-Proxy strToProxy(const char * proxy, bool * ok) {
-	Proxy p;
-	if(ok) *ok=true;
-	//Allow users to use no proxy, even if one is specified in the env
-	if (!strcmp(proxy,"none")) {
-		p.host = "";
-		return p;
-	}
-	
-	p.type = QNetworkProxy::HttpProxy;
-	//Read proxy type bit "http://" or "socks5://"
-	if (!strncmp(proxy,"http://",7)) {
-		proxy += 7;
-	} else if (!strncmp(proxy,"socks5://",9)) {
-		p.type = QNetworkProxy::Socks5Proxy;
-		proxy += 9;
-	}
-
-	//Read username and password
-	char * val = (char *) strchr(proxy,'@');
-	p.user = p.password = "";
-	if (val != NULL) {
-		p.user = QString(proxy).left(val-proxy);
-		proxy = val+1;
-		
-		int idx = p.user.indexOf(':');
-		if(idx != -1) {
-			p.password = p.user.mid(idx+1);
-			p.user = p.user.left(idx);
-		}
-	}
-
- 	//Read hostname and port
- 	val = (char *) strchr(proxy,':');
- 	p.port = 1080; //Default proxy port
- 	if (val == NULL) p.host = proxy;
- 	else {
-		p.port = QString(val+1).toInt(ok);
-		if(p.port < 0 || p.port > 65535) {
-			p.port = 1080;
-			*ok = false;
-		}
-		p.host = QString(proxy).left(val-proxy);
- 	}
-	if(ok && p.host.size() == 0) *ok = false;
-	return p;
-}
-
-Proxy::Proxy():
-    type(QNetworkProxy::NoProxy),
-	port(-1),
-	host(),
-	user(),
-	password() {}
-
 Size::Size():
 	pageSize(QPrinter::A4), 
 	height(UnitReal(-1,QPrinter::Millimeter)),
@@ -280,7 +201,6 @@ Global::Global():
 	outlineDepth(4),
 	dumpOutline(""),
 	out("-"),
-	cookieJar(""),
 	documentTitle(""),
 	useCompression(true) {};
 
@@ -300,16 +220,9 @@ Page::Page():
 	useLocalLinks(true),
 	enableJavascript(true),
 	enableIntelligentShrinking(true),
-	jsdelay(200),
-	zoomFactor(1.0),
 	minimumFontSize(-1),
 	printMediaType(false),
-	repeatCustomHeaders(false),
-	blockLocalFileAccess(false),
-	stopSlowScripts(true),
-	debugJavascript(false),
 	produceForms(false),
-	loadErrorHandling(abort),
 	enablePlugins(false),
 	includeInOutline(true),
 	pagesCount(true),

+ 9 - 79
src/pdf/settings.hh

@@ -19,32 +19,13 @@
 #include <QString>
 #include <QNetworkProxy>
 #include <QPrinter>
+#include "loadsettings.hh"
+
 namespace wkhtmltopdf {
 namespace settings {
 
 typedef QPair<qreal, QPrinter::Unit> UnitReal;
 
-/*! \brief Settings consdering proxy */
-struct Proxy {
-	Proxy();
-	//! Type of proxy to use
-	QNetworkProxy::ProxyType type; 
-	//! The port of the proxy to use
-	int port; 
-	//! The host name of the proxy to use or NULL
-	QString host; 
-	//! Username for the said proxy or NULL
-	QString user; 
-	//! Password for the said proxy or NULL
-	QString password; 
-};
-
-struct PostItem {
-	QString name;
-	QString value;
-	bool file;
-};
-	
 /*! \brief Settings consdering margins */
 struct Margin {
 	Margin();
@@ -86,8 +67,8 @@ struct TableOfContent {
 	float fontScale;
 };
 
-/*! \brief Class holding all user setting.
 
+/*! \brief Class holding all user setting.
     This class holds all the user settings, settings can be filled in by hand,
     or with other methods. 
     \sa CommandLineParser::parse()
@@ -136,9 +117,6 @@ struct Global {
 
 	//! The file where in to store the output
 	QString out;
-
-	//! Path of the cookie jar file
-	QString cookieJar;
 	
 	QString documentTitle;
 
@@ -149,6 +127,8 @@ struct Global {
 
 	//! Specify the output format we should use
 	QString outputFormat;
+
+	LoadGlobal load;
 };
 
 /*! \brief Settings considering headers and footers */
@@ -172,13 +152,7 @@ struct HeaderFooter {
 	float spacing;
 };
 
-
 struct Page {
-	enum LoadErrorHandling {
-		abort,
-		skip,
-		ignore
-	};
 
 	Page();
 	//! Settings regarding the TOC
@@ -192,12 +166,6 @@ struct Page {
 	//! Header related settings
 	HeaderFooter footer;
 	
-	//! Username used for http auth login
-	QString username;
-	
-	//! Password used for http auth login
-	QString password;
-	
 	//! Should we print background images
 	bool background;
 	
@@ -215,13 +183,7 @@ struct Page {
 	
 	//! Should the horrible intelligent shrinking feature be enabled?
 	bool enableIntelligentShrinking;
-	
-	//! How many milliseconds should we wait for a Javascript redirect
-	int jsdelay;
-	
-	//! What zoom factor should we apply when printing
-	float zoomFactor;
-	
+		
 	//! Minimum font size
 	int minimumFontSize;
 	
@@ -230,48 +192,21 @@ struct Page {
 	
 	//! Encoding used to enterpit a document with do supplied encoding
 	QString defaultEncoding;
-	
-	//! Map of custum header variables
-	QList< QPair<QString, QString> > customHeaders;
-	
-	//! Set if the custom header should be repeated for each resource request
-	bool repeatCustomHeaders;
-	
-	//! Map of cookies
-	QList< QPair<QString, QString> > cookies;
-	
+			
 	//! Replacements
 	QList< QPair<QString, QString> > replacements;
 	
-	QList< PostItem > post;
-	
-	//! Block access to local files for the given page
-	bool blockLocalFileAccess;
-	
-	//! If access to local files is not allowed in general, allow it for these files
-	QList< QString > allowed;
-	
-	//! Stop Javascript from running too long
-	bool stopSlowScripts;		
-	
-	//! Output Javascript debug messages
-	bool debugJavascript;
-	
 	//! Convert forms on the pages into PDF forms
 	bool produceForms;
 	
-	//! What should we do about load errors
-	LoadErrorHandling loadErrorHandling;
-	
 	//! Stylesheet supplied by the user
 	QString userStyleSheet;
+
+	LoadPage load;
 	
 	//! Should plugins be allowed
 	bool enablePlugins;
 
-	//! Proxy related settings
-	Proxy proxy;
-
 	bool includeInOutline;
 
 	bool pagesCount;
@@ -281,16 +216,11 @@ struct Page {
 	QString tocXsl;
 };
 
-Page::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);
-QString loadErrorHandlingToStr(Page::LoadErrorHandling leh);
-
 QPrinter::PageSize strToPageSize(const char * s, bool * ok=0);
 QString pageSizeToStr(QPrinter::PageSize ps);
 
 UnitReal strToUnitReal(const char * s, bool * ok=0);
 QString unitRealToStr(const UnitReal & ur, bool * ok);
-	
-Proxy strToProxy(const char * s, bool * ok=0);
 
 QPrinter::Orientation strToOrientation(const char * s, bool * ok=0);
 QString orientationToStr(QPrinter::Orientation o);

+ 5 - 3
src/pdf/wkhtmltopdf.cc

@@ -183,8 +183,10 @@ int main(int argc, char * argv[]) {
 	QList<Page> pageSettings;
 	//Create a command line parser to parse commandline arguments
 	CommandLineParser parser(globalSettings, pageSettings);
+
 	//Setup default values in settings
-	parser.loadDefaults();
+	//parser.loadDefaults();
+
 	//Parse the arguments
 	parser.parseArguments(argc, (const char**)argv);
 
@@ -199,7 +201,7 @@ int main(int argc, char * argv[]) {
 	QApplication a(argc, argv, use_graphics);
 	a.setStyle(new MyLooksStyle());
 
-	if (parser.readArgsFromStdin()) {
+	if (parser.readArgsFromStdin) {
 		char buff[20400];
 		char *nargv[1000];
 		nargv[0] = argv[0];
@@ -213,7 +215,7 @@ int main(int argc, char * argv[]) {
 			//Create a command line parser to parse commandline arguments
 			CommandLineParser parser(globalSettings, pageSettings);
 			//Setup default values in settings
-			parser.loadDefaults();
+			//parser.loadDefaults();
 			//Parse the arguments
 			parser.parseArguments(nargc, (const char**)nargv, true);
 			

+ 3 - 3
src/shared/arghandler.cc

@@ -17,10 +17,10 @@
 #include "outputter.hh"
 
 /*!
-  \fn ArgHandlerBase::getDesc() const
+  \fn ArgHandler::getDesc() const
   Get the description of this switch
 */  
-QString ArgHandlerBase::getDesc() const {
+QString ArgHandler::getDesc() const {
 	return desc;
 }
 
@@ -28,4 +28,4 @@ QString ArgHandlerBase::getDesc() const {
   \fn ArgHandlerBase::~ArgHandlerBase()
   Dummy virtual destructor
 */  
-ArgHandlerBase::~ArgHandlerBase() {}
+ArgHandler::~ArgHandler() {}

+ 202 - 0
src/shared/arghandler.inl

@@ -0,0 +1,202 @@
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "loadsettings.hh"
+
+template <typename T> class DstArgHandler: public ArgHandler {
+public:
+ 	T & dst;
+ 	DstArgHandler(T & d): dst(d) {};
+	
+ 	T & realDst(const CommandLineParserBase & cp, char * page) {
+		return * reinterpret_cast<T*>(cp.mapAddress(reinterpret_cast<char *>(&dst), page));
+ 	}
+};
+
+/*!
+  Sets a variable to some constant
+*/
+template <typename T> class ConstSetter: public DstArgHandler<T> {
+public:
+	typedef DstArgHandler<T> p_t;
+	const T src;
+	ConstSetter(T & arg, const T s): p_t(arg), src(s) {};
+	bool operator() (const char **, CommandLineParserBase & cp, char * ps) {
+		p_t::realDst(cp, ps)=src;
+		return true;
+	}
+	
+	virtual QString getDesc() const {
+		if (src != p_t::dst) return p_t::desc;
+		return p_t::desc + " (default)";
+	}
+};
+
+struct StringPairCreator {
+	typedef QPair<QString, QString> T;
+	inline T operator()(const QString & key, const QString & value) const {
+		return T(key, value);
+	}
+};
+
+template <bool file> 
+struct PostItemCreator {
+	typedef wkhtmltopdf::settings::PostItem T;
+	inline T operator()(const QString & key, const QString & value) const {
+		T p;
+		p.name = key;
+		p.value = value;
+		p.file = file;
+		return p;
+	}
+};
+
+/*!
+  Putting values into a map
+*/
+template <typename T=StringPairCreator>
+struct MapSetter: public DstArgHandler< QList< typename T::T > > {
+	typedef DstArgHandler<QList< typename T::T > > p_t;
+	MapSetter(QList<typename T::T > & a, QString keyName, QString valueName) : p_t(a) {
+		p_t::argn.push_back(keyName);
+		p_t::argn.push_back(valueName);
+	}
+	virtual bool operator() (const char ** args, CommandLineParserBase & cp, char * ps) {
+		p_t::realDst(cp, ps).append( T()(args[0], args[1]) );
+		return true;
+	}
+};
+
+struct StringListSetter: public DstArgHandler<QList<QString> > {
+	typedef DstArgHandler<QList<QString> > p_t;
+	StringListSetter(QList<QString> & a, QString valueName) : p_t (a) {
+		p_t::argn.push_back(valueName);
+	}
+	virtual bool operator() (const char ** args, CommandLineParserBase & cp, char * ps) {
+		p_t::realDst(cp, ps).append( args[0] );
+		return true;
+	}
+};
+
+/*!
+  SomeSetter template method base
+*/
+template <typename TT> 
+struct SomeSetterTM {
+	typedef TT T;
+	//T strToT(const char * val, bool & ok);
+	static QString TToStr(const T &, bool & ok) {ok=false; return "";}
+};
+
+/*!
+  TemplateMethod class used to set a single variable of some type TT::T
+*/
+template <typename TT>
+struct SomeSetter: public DstArgHandler<typename TT::T > {
+	typedef DstArgHandler<typename TT::T > p_t;
+	typedef typename TT::T T;
+	bool hasDef;
+
+	SomeSetter(T & a, QString an, bool def=true): p_t(a), hasDef(def) {
+		p_t::argn.push_back(an);
+	}
+
+	bool operator() (const char ** vals, CommandLineParserBase & cp, char * ps) {
+		bool ok;
+		p_t::realDst(cp, ps) = TT::strToT(vals[0], ok);
+		return ok;
+	}
+
+	virtual QString getDesc() const {
+		if (!hasDef) return p_t::desc;
+		bool ok;
+		QString x = TT::TToStr(p_t::dst, ok);
+		if (!ok) return p_t::desc;
+		return p_t::desc + " (default " + x + ")";
+	}
+};
+
+struct IntTM: public SomeSetterTM<int> {
+	static int strToT(const char * val, bool & ok) {
+		return QString(val).toInt(&ok);
+	}
+	static QString TToStr(const int & t, bool & ok) {
+		ok=(t!=-1);
+		return QString::number(t);
+	}
+};
+
+/*!
+  Argument handler setting an int variable
+*/
+typedef SomeSetter<IntTM> IntSetter;
+
+struct FloatTM: public SomeSetterTM<float> {
+	static float strToT(const char * val, bool & ok) {
+		return QString(val).toFloat(&ok);
+	}
+	static QString TToStr(const float & t, bool & ok) {
+		ok=(t!=-1);
+		return QString::number(t);
+	}
+};
+/*!
+  Argument handler setting an float variable
+*/
+typedef SomeSetter<FloatTM> FloatSetter;
+
+struct StrTM: public SomeSetterTM<const char *> {
+	static const char * strToT(const char * val, bool & ok) {
+		ok=true;
+		return val;
+	}
+	static QString TToStr(const char * t, bool & ok) {
+		ok = (t[0] != '\0');
+		return QString(t);
+	}
+};
+/*!
+  Argument handler setting a string variable
+*/
+typedef SomeSetter<StrTM> StrSetter;
+
+struct QStrTM: public SomeSetterTM<QString> {
+	static QString strToT(const char * val, bool & ok) {
+		ok=true;
+		return QString::fromLocal8Bit(val);
+	}
+	static QString TToStr(const QString & t, bool & ok) {
+		ok=!t.isEmpty();
+		return t;
+	}
+};
+/*!
+  Argument handler setting a string variable
+*/
+typedef SomeSetter<QStrTM> QStrSetter;
+
+
+/*!
+  Argument handler responsible for calling a function
+*/
+template <typename T> struct Caller: public ArgHandler {
+	Caller() {}
+	Caller(QString a1) {
+		argn.push_back(a1);
+	}
+	bool operator() (const char **vals, CommandLineParserBase & s, char * page) {
+		return T()(vals, s, page);
+	}
+};

+ 79 - 0
src/shared/commandlineparserbase.hh

@@ -0,0 +1,79 @@
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifndef __COMMANDLINEPARSER_BASE_HH__
+#define __COMMANDLINEPARSER_BASE_HH__
+#include "loadsettings.hh"
+class Outputter;
+class CommandLineParserBase;
+
+class ArgHandler {
+public:
+	QString longName;
+	QString desc;
+	char shortSwitch;
+	QVector<QString> argn;
+	bool display;
+	bool extended;
+	bool qthack;
+	virtual QString getDesc() const;
+	virtual ~ArgHandler();
+	int section;
+	virtual bool operator() (const char ** args, CommandLineParserBase & parser, char * page) = 0;
+};
+
+class CommandLineParserBase {
+public:
+	int currentMode;
+	QString currentSection;
+	bool currentExtended;
+	bool currentHack;
+	
+	QList<QString> sections;
+	QHash<QString, ArgHandler *> longToHandler;
+	QHash<char, ArgHandler *> shortToHandler;
+	QHash<QString, QList<ArgHandler *> > sectionArgumentHandles;
+	QHash<QString, QString> sectionDesc;
+	
+	//basearguments.cc
+	void section(QString s, QString desc="");
+	void mode(int m);
+	void qthack(bool);
+	void extended(bool);
+	
+	void addarg(QString, char, QString, ArgHandler * h, bool display=true);
+	void addDocArgs();
+	void addGlobalLoadArgs(wkhtmltopdf::settings::LoadGlobal & s);
+	void addPageLoadArgs(wkhtmltopdf::settings::LoadPage & s);
+	
+	//commondocparts.cc
+	void outputName(Outputter * o) const;
+	void outputLicense(Outputter * o) const;
+	void outputAuthors(Outputter * o) const;
+	void outputStaticProblems(Outputter * o) const;
+	void outputProxyDoc(Outputter * o) const;
+	
+	//commandlineparserbase.cc
+	void outputSwitches(Outputter * o, bool extended, bool doc) const;
+	virtual char * mapAddress(char * d, char *) const {return d;}
+	virtual void version(FILE * fd) const;
+	void parseArg(int sections, const int argc, const char ** argv, bool & defaultMode, int & arg, char * page);
+
+	virtual QString appName() const = 0;
+	virtual void usage(FILE * fd, bool extended) const = 0;
+	virtual void manpage(FILE * fd) const = 0;
+	virtual void readme(FILE * fd, bool html) const = 0;
+};
+#endif //__COMMANDLINEPARSER_BASE_HH__

+ 191 - 0
src/shared/commonarguments.cc

@@ -0,0 +1,191 @@
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "commandlineparserbase.hh"
+#include "arghandler.inl"
+#include "loadsettings.hh"
+using namespace wkhtmltopdf::settings;
+
+struct LoadErrorHandlingTM: public SomeSetterTM<LoadPage::LoadErrorHandling> {
+	static LoadPage::LoadErrorHandling strToT(const char * val, bool &ok) {
+		return strToLoadErrorHandling(val, &ok);
+	}
+	static QString TToStr(const LoadPage::LoadErrorHandling & o, bool & ok) {
+		ok=true;
+		return loadErrorHandlingToStr(o);
+	}
+};
+typedef SomeSetter<LoadErrorHandlingTM> LoadErrorHandlingSetting;
+
+struct ProxyTM: public SomeSetterTM<Proxy> {
+	static Proxy strToT(const char * val, bool &ok) {
+		return strToProxy(val, &ok);
+	}
+};
+/*!
+  Argument handler setting a proxy variable  
+ */
+typedef SomeSetter<ProxyTM> ProxySetter;
+
+
+//All these function would have been lambda function, had C++ supported them, now we are forced to write them here
+
+/*!
+  Lambda: Call the usage method
+*/
+template <bool v>
+struct HelpFunc {
+	bool operator()(const char **, CommandLineParserBase & p, char *) {
+		p.usage(stdout,v);
+		exit(0);
+	}
+};
+
+/*!
+  Lambda: Call the man method
+*/
+struct ManPageFunc {
+	bool operator()(const char **, CommandLineParserBase & p, char *) {
+		p.manpage(stdout);
+		exit(0);
+	}
+};
+
+/*!
+  Lambda: Call the man method
+*/
+template <bool T>
+struct ReadmeFunc {
+	bool operator()(const char **, CommandLineParserBase & p, char *) {
+		p.readme(stdout, T);
+		exit(0);
+	}
+};
+
+/*!
+  Lambda: Call the version method
+*/
+struct VersionFunc {
+	bool operator()(const char **, CommandLineParserBase & p, char *) {
+		p.version(stdout);
+		exit(0);
+	}
+};
+
+/*!
+  The next arguments we add will belong to this section
+  /param s The name of the section
+  /param desc A description of the section
+*/
+void CommandLineParserBase::section(QString s, QString desc) {
+	currentSection = s;
+	sectionDesc[s] = desc;
+	sections.push_back(s);
+}
+
+/*!
+  Indicate whether the next arguments we add require a patched qt to work
+  /param h Do we require a patch
+*/
+void CommandLineParserBase::qthack(bool h) {
+	currentHack = h;
+}
+
+void CommandLineParserBase::mode(int m) {
+	currentMode = m;
+}
+
+/*!
+  Indicate whether the next arguments we add are "extended" and should not 
+  be shown in a simple --help
+  \param e Are the arguments extended
+*/
+void CommandLineParserBase::extended(bool e) {
+	currentExtended = e;
+}
+
+
+/*!
+  Add an argument to the list of arguments
+  \param l The long "--" name of the argument
+  \param s The short '-' name of the argument or 0 if unspecified
+  \param d Description of the argument
+  \param h The handler for the argument
+  \param display Is the argument hidden
+*/
+void CommandLineParserBase::addarg(QString l, char s, QString d, ArgHandler * h, bool display) {
+	h->desc = d;
+	h->longName = l;
+	h->shortSwitch = s;
+	h->display = display;
+	h->qthack = currentHack;
+	h->section = currentMode;
+	h->extended = currentExtended;
+	longToHandler[l] = h;
+	if(s) shortToHandler[s] = h;
+	sectionArgumentHandles[currentSection].push_back(h);
+}
+
+void CommandLineParserBase::addDocArgs() {
+	extended(false);
+	qthack(false);
+	addarg("help", 'h', "Display help", new Caller<HelpFunc<false> >());
+	addarg("version", 'V' ,"Output version information an exit", new Caller<VersionFunc>());
+	addarg("extended-help", 'H',"Display more extensive help, detailing less common command switches", new Caller<HelpFunc<true> >());
+
+	extended(true);
+ 	qthack(false);
+	addarg("manpage", 0, "Output program man page", new Caller<ManPageFunc>());
+ 	addarg("htmldoc", 0, "Output program html help", new Caller<ReadmeFunc<true> >());
+ 	addarg("readme", 0, "Output program readme", new Caller<ReadmeFunc<false> >());
+}
+
+
+void CommandLineParserBase::addGlobalLoadArgs(LoadGlobal & s) {
+	extended(true);
+	qthack(false);
+	
+    addarg("cookie-jar", 0, "Read and write cookies from and to the supplied cookie jar file", new QStrSetter(s.cookieJar, "path") );
+}
+
+void CommandLineParserBase::addPageLoadArgs(LoadPage & s) {
+	extended(true);
+	qthack(false);
+	addarg("proxy",'p',"Use a proxy", new ProxySetter(s.proxy, "proxy"));
+	addarg("username",0,"HTTP Authentication username", new QStrSetter(s.username, "username"));
+	addarg("password",0,"HTTP Authentication password", new QStrSetter(s.password, "password"));
+	addarg("load-error-handling", 0, "Specify how to handle pages that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.loadErrorHandling, "handler"));
+	addarg("custom-header",0,"Set an additional HTTP header (repeatable)", new MapSetter<>(s.customHeaders, "name", "value"));
+	addarg("custom-header-propagation",0,"Add HTTP headers specified by --custom-header for each resource request.", new ConstSetter<bool>(s.repeatCustomHeaders, true));
+	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));
+	
+	addarg("javascript-delay",0,"Wait some milliseconds for javascript finish", new IntSetter(s.jsdelay,"msec"));
+	
+	addarg("zoom",0,"Use this zoom factor", new FloatSetter(s.zoomFactor,"float",1.0));
+	addarg("cookie",0,"Set an additional cookie (repeatable)", new MapSetter<>(s.cookies, "name", "value"));
+	addarg("post", 0, "Add an additional post field (repeatable)", new MapSetter<PostItemCreator<false> >(s.post, "name", "value"));
+	addarg("post-file", 0, "Post an additional file (repeatable)", new MapSetter<PostItemCreator<true> >(s.post, "name", "path"));
+		
+	addarg("disable-local-file-access", 0, "Do not allowed conversion of a local file to read in other local files, unless explecitily allowed with --allow", new ConstSetter<bool>(s.blockLocalFileAccess, true));
+	addarg("enable-local-file-access", 0, "Allowed conversion of a local file to read in other local files.", new ConstSetter<bool>(s.blockLocalFileAccess, false));
+	addarg("allow", 0, "Allow the file or files from the specified folder to be loaded (repeatable)", new StringListSetter(s.allowed,"path"));
+	
+	addarg("debug-javascript", 0,"Show javascript debugging output", new ConstSetter<bool>(s.debugJavascript, true));
+	addarg("no-debug-javascript", 0,"Do not show javascript debugging output", new ConstSetter<bool>(s.debugJavascript, false));
+#if QT_VERSION >= 0x040600
+	addarg("stop-slow-scripts", 0, "Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, true));
+	addarg("no-stop-slow-scripts", 0, "Do not Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, true));
+#endif	
+}

+ 8 - 10
src/shared/commondocparts.cc

@@ -14,8 +14,8 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
-#include "commondocparts.hh"
-namespace commonDocParts {
+#include "commandlineparserbase.hh"
+#include "outputter.hh"
 
 #define STRINGIZE_(x) #x
 #define STRINGIZE(x) STRINGIZE_(x)
@@ -24,9 +24,9 @@ namespace commonDocParts {
   Output the name and version of the program, and also whether we are using a patched qt
   \param o The outputter to output to
 */
-void outputName(Outputter * o, QString app) {
+void CommandLineParserBase::outputName(Outputter * o) const {
 	o->beginSection("Name");
-	o->paragraph(app+" "+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD));
+	o->paragraph(appName()+" "+QString::number(MAJOR_VERSION)+"."+QString::number(MINOR_VERSION)+"."+QString::number(PATCH_VERSION)+(QString(STRINGIZE(BUILD)).isEmpty()?"":" ")+STRINGIZE(BUILD));
 	o->endSection();
 
 }
@@ -35,7 +35,7 @@ void outputName(Outputter * o, QString app) {
   Output copyright stuff
   \param o The outputter to output to
 */
-void outputLicense(Outputter * o) {
+void CommandLineParserBase::outputLicense(Outputter * o) const {
 	o->beginSection("License");
 	o->paragraph("Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.");
 	o->endParagraph();
@@ -51,7 +51,7 @@ void outputLicense(Outputter * o) {
   Output list of authors
   \param o The outputter to output to
 */
-void outputAuthors(Outputter * o) {
+void CommandLineParserBase::outputAuthors(Outputter * o) const {
 	o->beginSection("Authors");
 	o->paragraph(
 		QString::fromUtf8(
@@ -64,7 +64,7 @@ void outputAuthors(Outputter * o) {
   Output information on the problems with the static version
   \param o The outputter to output to
 */
-void outputStaticProblems(Outputter * o) {
+void CommandLineParserBase::outputStaticProblems(Outputter * o) const {
 	o->beginSection("Static version");
 	o->beginParagraph();
 	o->text("On the wkhtmltopdf website you can download a static version of wkhtmltopdf ");
@@ -87,7 +87,7 @@ void outputStaticProblems(Outputter * o) {
   Output documentation about the proxy settings
   \param o The outputter to output to
 */
-void outputProxyDoc(Outputter * o) {
+void CommandLineParserBase::outputProxyDoc(Outputter * o) const {
 	o->beginSection("Specifying A Proxy");
 	o->paragraph(
 		"By default proxy information will be read from the environment"
@@ -103,5 +103,3 @@ void outputProxyDoc(Outputter * o) {
 				"None\n");
 	o->endSection();
 }
-
-};

+ 1 - 1
src/shared/htmloutputter.cc

@@ -101,7 +101,7 @@ public:
 		fprintf(fd, "<table>\n");
 	}
 
-	void cswitch(const ArgHandlerBase * h) {
+	void cswitch(const ArgHandler * h) {
 		fprintf(fd, "<tr><td class=\"short\">");
 		if(h->shortSwitch)
 			fprintf(fd, "-%c,",h->shortSwitch);

+ 114 - 0
src/shared/loadsettings.cc

@@ -0,0 +1,114 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "loadsettings.hh"
+#include <QMap>
+#include <stdexcept>
+namespace wkhtmltopdf {
+namespace settings {
+
+LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok) {
+	if (ok) *ok = true;
+	if (!strcasecmp(s, "abort")) return LoadPage::abort;
+	if (!strcasecmp(s, "skip")) return LoadPage::skip;
+	if (!strcasecmp(s, "ignore")) return LoadPage::ignore;
+	*ok = false;
+	return LoadPage::abort;
+}
+
+QString loadErrorHandlingToStr(LoadPage::LoadErrorHandling leh) {
+	switch(leh) {
+	case LoadPage::abort: return "abort";
+	case LoadPage::skip: return "skip";
+	case LoadPage::ignore: return "ignore";
+	}
+	throw std::logic_error("Internal error in loadErrorHandlingToStr");
+}
+
+/*!
+  Read proxy settings from a string, the grammar is described in the manual
+  \param proxy the proxy string to parse
+  \param ok If supplied indicates whether the proxy was valid
+*/
+Proxy strToProxy(const char * proxy, bool * ok) {
+	Proxy p;
+	if(ok) *ok=true;
+	//Allow users to use no proxy, even if one is specified in the env
+	if (!strcmp(proxy,"none")) {
+		p.host = "";
+		return p;
+	}
+	
+	p.type = QNetworkProxy::HttpProxy;
+	//Read proxy type bit "http://" or "socks5://"
+	if (!strncmp(proxy,"http://",7)) {
+		proxy += 7;
+	} else if (!strncmp(proxy,"socks5://",9)) {
+		p.type = QNetworkProxy::Socks5Proxy;
+		proxy += 9;
+	}
+
+	//Read username and password
+	char * val = (char *) strchr(proxy,'@');
+	p.user = p.password = "";
+	if (val != NULL) {
+		p.user = QString(proxy).left(val-proxy);
+		proxy = val+1;
+		
+		int idx = p.user.indexOf(':');
+		if(idx != -1) {
+			p.password = p.user.mid(idx+1);
+			p.user = p.user.left(idx);
+		}
+	}
+
+ 	//Read hostname and port
+ 	val = (char *) strchr(proxy,':');
+ 	p.port = 1080; //Default proxy port
+ 	if (val == NULL) p.host = proxy;
+ 	else {
+		p.port = QString(val+1).toInt(ok);
+		if(p.port < 0 || p.port > 65535) {
+			p.port = 1080;
+			*ok = false;
+		}
+		p.host = QString(proxy).left(val-proxy);
+ 	}
+	if(ok && p.host.size() == 0) *ok = false;
+	return p;
+}
+
+Proxy::Proxy():
+    type(QNetworkProxy::NoProxy),
+	port(-1),
+	host(),
+	user(),
+	password() {}
+
+LoadGlobal::LoadGlobal():
+	cookieJar("") {};
+
+LoadPage::LoadPage():
+	jsdelay(200),
+	zoomFactor(1.0),
+	repeatCustomHeaders(false),
+	blockLocalFileAccess(false),
+	stopSlowScripts(true),
+	debugJavascript(false),
+	loadErrorHandling(abort) {};
+
+}
+}

+ 111 - 0
src/shared/loadsettings.hh

@@ -0,0 +1,111 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifndef __LOADSETTINGS_HH__
+#define __LOADSETTINGS_HH__
+#include <QString>
+#include <QNetworkProxy>
+namespace wkhtmltopdf {
+namespace settings {
+
+/*! \brief Settings consdering proxy */
+struct Proxy {
+	Proxy();
+	//! Type of proxy to use
+	QNetworkProxy::ProxyType type; 
+	//! The port of the proxy to use
+	int port; 
+	//! The host name of the proxy to use or NULL
+	QString host; 
+	//! Username for the said proxy or NULL
+	QString user; 
+	//! Password for the said proxy or NULL
+	QString password; 
+};
+
+struct PostItem {
+	QString name;
+	QString value;
+	bool file;
+};
+
+struct LoadGlobal {
+	LoadGlobal();
+	//! Path of the cookie jar file
+	QString cookieJar;
+};
+
+struct LoadPage {
+	LoadPage();
+
+	enum LoadErrorHandling {
+		abort,
+		skip,
+		ignore
+	};
+
+	//! Username used for http auth login
+	QString username;
+	
+	//! Password used for http auth login
+	QString password;
+	
+	//! How many milliseconds should we wait for a Javascript redirect
+	int jsdelay;
+	
+	//! What zoom factor should we apply when printing
+	// TODO MOVE
+	float zoomFactor;
+
+	//! Map of custum header variables
+	QList< QPair<QString, QString> > customHeaders;
+	
+	//! Set if the custom header should be repeated for each resource request
+	bool repeatCustomHeaders;
+
+	//! Map of cookies
+	QList< QPair<QString, QString> > cookies;
+
+	QList< PostItem > post;
+	
+	//! Block access to local files for the given page
+	bool blockLocalFileAccess;
+	
+	//! If access to local files is not allowed in general, allow it for these files
+	QList< QString > allowed;
+	
+	//! Stop Javascript from running too long
+	bool stopSlowScripts;		
+	
+	//! Output Javascript debug messages
+	bool debugJavascript;
+
+	//! What should we do about load errors
+	LoadErrorHandling loadErrorHandling;
+
+	//! Proxy related settings
+	Proxy proxy;
+};
+
+LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);
+QString loadErrorHandlingToStr(LoadPage::LoadErrorHandling leh);
+
+Proxy strToProxy(const char * s, bool * ok=0);
+
+
+}
+}
+#endif //__LOADSETTINGS_HH__

+ 1 - 1
src/shared/manoutputter.cc

@@ -90,7 +90,7 @@ public:
 		fprintf(fd,"%s\n",S(s));
 	}
 	
-	void cswitch(const ArgHandlerBase * h) {
+	void cswitch(const ArgHandler * h) {
 		fprintf(fd, ".TP\n");
 		fprintf(fd, "\\fB");
 		if(h->shortSwitch != 0)

+ 10 - 11
src/pdf/multipageloader.cc → src/shared/multipageloader.cc

@@ -35,7 +35,7 @@ namespace wkhtmltopdf {
 
 LoaderObject::LoaderObject(QWebPage & p): page(p), skip(false) {};
 
-MyNetworkAccessManager::MyNetworkAccessManager(const settings::Page & s): settings(s) {}
+MyNetworkAccessManager::MyNetworkAccessManager(const settings::LoadPage & s): settings(s) {}
 
 void MyNetworkAccessManager::allow(QString path) {
 	QString x = QFileInfo(path).canonicalFilePath();
@@ -103,8 +103,7 @@ bool MyQWebPage::shouldInterruptJavaScript() {
 	return false;
 }
 
-
-ResourceObject::ResourceObject(MultiPageLoaderPrivate & mpl, const QUrl & u, const settings::Page & s): 
+ResourceObject::ResourceObject(MultiPageLoaderPrivate & mpl, const QUrl & u, const settings::LoadPage & s): 
 	networkAccessManager(s),
 	url(u),
 	loginTry(0), 
@@ -192,11 +191,11 @@ void ResourceObject::loadProgress(int p) {
 
 
 void ResourceObject::loadFinished(bool ok) {
-	multiPageLoader.hasError = multiPageLoader.hasError || (!ok && settings.loadErrorHandling == settings::Page::abort);
+	multiPageLoader.hasError = multiPageLoader.hasError || (!ok && settings.loadErrorHandling == settings::LoadPage::abort);
 	if (!ok) {
-		if (settings.loadErrorHandling == settings::Page::abort)
+		if (settings.loadErrorHandling == settings::LoadPage::abort)
 			error(QString("Failed loading page ") + url.toString() + " (sometimes it will work just to ignore this error with --load-error-handling ignore)");
-		else if (settings.loadErrorHandling == settings::Page::skip) {
+		else if (settings.loadErrorHandling == settings::LoadPage::skip) {
 			warning(QString("Failed loading page ") + url.toString() + " (skipped)");
 			lo.skip = true;
 		} else
@@ -382,7 +381,7 @@ bool MultiPageLoader::copyFile(QFile & src, QFile & dst) {
 	return true;
 }
 
-MultiPageLoaderPrivate::MultiPageLoaderPrivate(settings::Global & s, MultiPageLoader & o): 
+MultiPageLoaderPrivate::MultiPageLoaderPrivate(const settings::LoadGlobal & s, MultiPageLoader & o): 
 	outer(o), settings(s) {
 
 	cookieJar = new MyCookieJar();
@@ -395,7 +394,7 @@ MultiPageLoaderPrivate::~MultiPageLoaderPrivate() {
 	clearResources();
 }
 
-LoaderObject * MultiPageLoaderPrivate::addResource(const QUrl & url, const settings::Page & page) {
+LoaderObject * MultiPageLoaderPrivate::addResource(const QUrl & url, const settings::LoadPage & page) {
 	ResourceObject * ro = new ResourceObject(*this, url, page);
 	resources.push_back(ro);
 	return &ro->lo;
@@ -433,7 +432,7 @@ void MultiPageLoaderPrivate::fail() {
   \brief Construct a multipage loader object, load settings read from the supplied settings
   \param s The settings to be used while loading pages
 */
-MultiPageLoader::MultiPageLoader(settings::Global & s):
+MultiPageLoader::MultiPageLoader(settings::LoadGlobal & s):
 	d(new MultiPageLoaderPrivate(s, *this)) {
 }
 
@@ -445,7 +444,7 @@ MultiPageLoader::~MultiPageLoader() {
   \brief Add a resource, to be loaded described by a string
   @param string Url describing the resource to load
 */
-LoaderObject * MultiPageLoader::addResource(const QString & string, const settings::Page & s) {
+LoaderObject * MultiPageLoader::addResource(const QString & string, const settings::LoadPage & s) {
 	QString url=string;
 	if (url == "-") {
 		QFile in;
@@ -464,7 +463,7 @@ LoaderObject * MultiPageLoader::addResource(const QString & string, const settin
   \brief Add a page to be loaded
   @param url Url of the page to load
 */
-LoaderObject * MultiPageLoader::addResource(const QUrl & url, const settings::Page & s) {
+LoaderObject * MultiPageLoader::addResource(const QUrl & url, const settings::LoadPage & s) {
 	return d->addResource(url, s);
 }
 

+ 4 - 4
src/pdf/multipageloader.hh → src/shared/multipageloader.hh

@@ -16,7 +16,7 @@
 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef __MULTIPAGELOADER_HH__
 #define __MULTIPAGELOADER_HH__
-#include "settings.hh"
+#include "loadsettings.hh"
 #include <QFile>
 #include <QObject>
 #include <QUrl>
@@ -38,10 +38,10 @@ class MultiPageLoaderPrivate;
 class MultiPageLoader: public QObject {
 	Q_OBJECT
 public:
-	MultiPageLoader(settings::Global & s);
+	MultiPageLoader(settings::LoadGlobal & s);
 	~MultiPageLoader();
-	LoaderObject * addResource(const QString & url, const settings::Page & pageSettings);
-	LoaderObject * addResource(const QUrl & url, const settings::Page & pageSettingns);
+	LoaderObject * addResource(const QString & url, const settings::LoadPage & settings);
+	LoaderObject * addResource(const QUrl & url, const settings::LoadPage & settings);
 	static QUrl guessUrlFromString(const QString &string);
 	int httpErrorCode();
 	static bool copyFile(QFile & src, QFile & dst);

+ 8 - 8
src/pdf/multipageloader_p.hh → src/shared/multipageloader_p.hh

@@ -30,17 +30,17 @@ class MyNetworkAccessManager: public QNetworkAccessManager {
 	Q_OBJECT
 private:
 	QSet<QString> allowed;
-	const settings::Page & settings;
+	const settings::LoadPage & settings;
 public:
 	void allow(QString path);
-	MyNetworkAccessManager(const settings::Page & s);
+	MyNetworkAccessManager(const settings::LoadPage & s);
 	QNetworkReply * createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
 signals:
 	void warning(const QString & text);
 };
 
-class ResourceObject;
 class MultiPageLoaderPrivate;
+class ResourceObject;
 
 class MyQWebPage: public QWebPage {
 	Q_OBJECT ;
@@ -67,11 +67,11 @@ private:
 	bool signalPrint;
 	MultiPageLoaderPrivate & multiPageLoader;
 public:
-	ResourceObject(MultiPageLoaderPrivate & mpl, const QUrl & u, const settings::Page & s);
+	ResourceObject(MultiPageLoaderPrivate & mpl, const QUrl & u, const settings::LoadPage & s);
 	MyQWebPage webPage;
 	LoaderObject lo;
 	int httpErrorCode;
-	const settings::Page settings;	
+	const settings::LoadPage settings;	
 public slots:
 	void load();
 	void loadStarted();
@@ -104,7 +104,7 @@ public:
 	MyCookieJar * cookieJar;
 
 	MultiPageLoader & outer;
-	settings::Global & settings;
+	const settings::LoadGlobal settings;
 
 	QList<ResourceObject *> resources;
 
@@ -115,9 +115,9 @@ public:
 	bool finishedEmitted;
 	TempFile tempIn;
 
-	MultiPageLoaderPrivate(settings::Global & s, MultiPageLoader & o);
+	MultiPageLoaderPrivate(const settings::LoadGlobal & settings, MultiPageLoader & o);
 	~MultiPageLoaderPrivate(); 
-	LoaderObject * addResource(const QUrl & url, const settings::Page & settings);
+	LoaderObject * addResource(const QUrl & url, const settings::LoadPage & settings);
 	void load();
 	void clearResources();
 	void cancel();

+ 2 - 14
src/shared/outputter.hh

@@ -19,19 +19,7 @@
 #include <QString>
 #include <QVector>
 #include <stdio.h>
-
-class ArgHandlerBase {
-public:
-	QString longName;
-	QString desc;
-	char shortSwitch;
-	QVector<QString> argn;
-	bool display;
-	bool extended;
-	bool qthack;
-	virtual QString getDesc() const;
-	virtual ~ArgHandlerBase();
-};
+#include "commandlineparserbase.hh"
 
 class Outputter {
 public:
@@ -50,7 +38,7 @@ public:
  	virtual void endList() = 0;
  	virtual void listItem(const QString & t) = 0;
 	virtual void beginSwitch() = 0;
-	virtual void cswitch(const ArgHandlerBase * h) = 0;
+	virtual void cswitch(const ArgHandler * h) = 0;
 	virtual void endSwitch() = 0;
 	void paragraph(const QString & t);
 	static Outputter * text(FILE * fd, bool doc=false, bool extended=false);

+ 8 - 1
src/shared/shared.pri

@@ -1,3 +1,10 @@
+#Lbaray Part
+HEADERS += ../shared/multipageloader_p.hh ../shared/multipageloader.hh
+SOURCES += ../shared/loadsettings.cc ../shared/multipageloader.cc ../shared/tempfile.cc 
+
+#Application part
 
 SOURCES += ../shared/outputter.cc ../shared/manoutputter.cc ../shared/htmloutputter.cc \
-           ../shared/textoutputter.cc ../shared/arghandler.cc commondocparts.cc
+           ../shared/textoutputter.cc ../shared/arghandler.cc ../shared/commondocparts.cc \
+ 	   ../shared/commandlineparserbase.cc ../shared/commonarguments.cc
+           

+ 0 - 0
src/pdf/tempfile.cc → src/shared/tempfile.cc


+ 0 - 0
src/pdf/tempfile.hh → src/shared/tempfile.hh


+ 1 - 1
src/shared/textoutputter.cc

@@ -124,7 +124,7 @@ public:
 	
 	void beginSwitch() {}
 
-	void cswitch(const ArgHandlerBase * h) {
+	void cswitch(const ArgHandler * h) {
 		w=0;
 		if(!doc) {fprintf(fd,"  "); w=2;}
 		if(h->shortSwitch != 0)