浏览代码

Add support of redirect time out

Jakob Truelsen 16 年之前
父节点
当前提交
97f33cbcd5
共有 3 个文件被更改,包括 16 次插入345 次删除
  1. 0 337
      src/arghandlers.inc
  2. 14 6
      src/multipageloader.cc
  3. 2 2
      src/multipageloader_p.hh

+ 0 - 337
src/arghandlers.inc

@@ -1,337 +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 __ARGHANDLERS_INC__
-#define __ARGHANDLERS_INC__
-#include "commandlineparser_p.hh"
-
-
-/*!
-  \class ArgHandler
-  \brief Class responcible 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
-*/
-
-/*!
-  \fn ArgHandler::operator()(const char ** args, Settings & settings)
-  Callend when the switch was specified
-  \param args The arguments to the switch, garantied to have size of argn
-  \param settings The settings to store the information in
-*/
- 
-/*!
-  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);
-} 
-  
-/*!
-  Get the description of this switch
-*/  
-QString ArgHandler::getDesc() const {
-	return desc;
-}
-
-/*!
-  Dummy virtual destructor
-*/  
-ArgHandler::~ArgHandler() {}
-
-
-/*!
-  \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;
-	}
-};
-
-/*!
-  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(val);
-	}
-	static QString TToStr(QString t, bool & ok) {
-		ok=!t.isEmpty();
-		return t;
-	}
-};
-/*!
-  Argument handler setting a string variable
-*/
-typedef SomeSetter<QStrTM> QStrSetter;
-
-struct UnitRealTM: public SomeSetterTM<QPair<qreal, QPrinter::Unit> > {
-	static QPair<qreal, QPrinter::Unit> strToT(const char * val, bool &ok) {
-		return Settings::strToUnitReal(val, &ok);
-	}
-};
-/*!
-  Argument handler setting a real-number/unit combo variable  
- */
-typedef SomeSetter<UnitRealTM> UnitRealSetter;
-
-struct PageSizeTM: public SomeSetterTM<QPrinter::PageSize> {
-	static QPrinter::PageSize strToT(const char * val, bool &ok) {
-		return Settings::strToPageSize(val, &ok);
-	}
-};
-/*!
-  Argument handler setting a page size variable  
- */
-typedef SomeSetter<PageSizeTM> PageSizeSetter;
-
-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;
-
-struct OrientationTM: public SomeSetterTM<QPrinter::Orientation> {
-	static QPrinter::Orientation strToT(const char * val, bool &ok) {
-		return Settings::strToOrientation(val, &ok);
-	}
-};
-/*!
-  Argument handler setting a orientation variable  
- */
-typedef SomeSetter<OrientationTM> OrientationSetter;
-
-
-/*!
-  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
-
-/*!
-  Lamba: 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);
-	}
-};
-
-/*!
-  Set the default header
-*/
-struct DefaultHeaderFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p) {
-		p.settings.header.left="[webpage]";
-		p.settings.header.right="[page]/[toPage]";
-		p.settings.header.line=true;
-		p.settings.margin.top = Settings::strToUnitReal("2cm");
-		return true;
-	}
-};
-
-/*!
-  Setup default book mode
-*/
-struct BookFunc {
-	bool operator()(const char **, CommandLineParserPrivate & p) {
-		p.settings.header.left="[section]";
-		p.settings.header.right="[page]/[toPage]";
-		p.settings.header.line=true;
-		p.settings.outline = true;
-		p.settings.printToc = true;
-		p.settings.margin.top = Settings::strToUnitReal("2cm");
-		return true;
-	}
-};
-
-#endif //__ARGHANDLERS_INC__

+ 14 - 6
src/multipageloader.cc

@@ -16,6 +16,7 @@
 #include "multipageloader_p.hh"
 #include <QFile>
 #include <QFileInfo>
+#include <QTimer>
 
 /*!
   \file multipageloader.hh
@@ -25,6 +26,7 @@
 /*!
   \file multipageloader_p.hh
   \brief Defines the MultiPageLoaderPrivate class
+*/
 
 /*!
  * Track and handle network errors
@@ -141,7 +143,7 @@ void MultiPageLoaderPrivate::load() {
 	finishedSum=0;
 	loadStartedEmitted=false;
 	error=false;
-
+	loadingPages=0;
 	for(int i=0; i < pages.size(); ++i) 
 		pages[i]->mainFrame()->load(urls[i]);
 
@@ -179,6 +181,7 @@ void MultiPageLoaderPrivate::cancel() {
  * Once loading starting, this is called
  */
 void MultiPageLoaderPrivate::loadStarted() {
+	loadingPages++;
 	if (loadStartedEmitted) return;
 	loadStartedEmitted=true;
 	emit outer.loadStarted();
@@ -201,19 +204,24 @@ void MultiPageLoaderPrivate::loadProgress(int progress) {
 }
 
 void MultiPageLoaderPrivate::loadFinished(bool ok) {
+	loadingPages--;
 	error = error && ok;
 	if (!pageToIndex.count(QObject::sender())) return;
 	
 	int idx=pageToIndex[QObject::sender()];
-	if (finishedList[idx]) return;
-	finishedList[idx] = true;
+	if (!finishedList[idx]) {
+		finishedList[idx] = true;
+		finishedSum += 1;
+	}
 
-	finishedSum += 1;
-	
 	if (finishedSum == finishedList.size())
-		emit outer.loadFinished(error);
+		QTimer::singleShot(settings.jsredirectwait, this, SLOT(timedFinished()));
 }
 
+void MultiPageLoaderPrivate::timedFinished() {
+	if(loadingPages == 0) 
+		emit outer.loadFinished(error);
+}
 
 /*!
   \brief Construct a multipage loader object, load settings read from the supplied settings

+ 2 - 2
src/multipageloader_p.hh

@@ -35,7 +35,6 @@ public:
 
 	QNetworkAccessManager networkAccessManager;
 	QHash<QObject *, int> pageToIndex;
-	
 
 	QList<int> progressList;
 	QList<bool> finishedList;
@@ -43,7 +42,7 @@ public:
 	int finishedSum;
 	bool loadStartedEmitted;
 	bool error;
-
+	int loadingPages;
 
 	MultiPageLoaderPrivate(Settings & s, MultiPageLoader & o);
 	~MultiPageLoaderPrivate(); 
@@ -57,6 +56,7 @@ public slots:
 	void loadStarted();
 	void loadProgress(int progress);
 	void loadFinished(bool ok);
+	void timedFinished();
 	void sslErrors(QNetworkReply *reply, const QList<QSslError> &);
 	void amfinished(QNetworkReply * reply);
 	void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);