Browse Source

implement a --license command line option

This shows the complete list of authors and the full license text,
which are included in the compiled binary via QT resources.
Ashish Kulkarni 11 years ago
parent
commit
cd6331b1ae

+ 2 - 1
.gitignore

@@ -13,7 +13,8 @@ static-build/
 doc/
 man1/
 Makefile
+qrc_wkhtmltopdf.cpp
 Makefile.*
 *_resource.rc
 gitcontrol.bat
-gitcmd.lnk
+gitcmd.lnk

+ 1 - 0
common.pri

@@ -39,6 +39,7 @@ MOC_DIR      = ../../build
 OBJECTS_DIR  = ../../build
 UI_DIR       = ../../build
 INCLUDEPATH += ../../include
+RESOURCES    = $$PWD/wkhtmltopdf.qrc
 
 win32:      CONFIG += console
 win32-g++*: QMAKE_LFLAGS += -static-libgcc -static-libstdc++

+ 20 - 8
src/shared/commandlineparserbase.cc

@@ -72,22 +72,34 @@ void CommandLineParserBase::outputSwitches(Outputter * o, bool extended, bool do
  	}
 }
 
+#define STRINGIZE_(x) #x
+#define STRINGIZE(x) STRINGIZE_(x)
+
+const char *CommandLineParserBase::appVersion() const {
+#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
+	return STRINGIZE(FULL_VERSION) " (patched qt)";
+#else
+	return STRINGIZE(FULL_VERSION);
+#endif
+}
+
 /*!
   Output version information aka. --version
   \param fd The file to output to
 */
 void CommandLineParserBase::version(FILE * fd) const {
+	fprintf(fd, "%s %s\n", appName().toLocal8Bit().constData(), appVersion());
+}
+
+/*!
+  Output license information aka. --license
+  \param fd The file to output to
+*/
+void CommandLineParserBase::license(FILE * fd) const {
  	Outputter * o = Outputter::text(fd,false);
   	outputName(o);
-  	outputLicense(o);
   	outputAuthors(o);
-	o->beginParagraph();
-#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
-	o->text("Compiled against wkhtmltopdf patched qt.");
-#else
-	o->bold("Not");
-	o->text(" compiled against wkhtmltopdf patched qt.");
-#endif
+  	outputLicense(o);
 	delete o;
 }
 

+ 2 - 0
src/shared/commandlineparserbase.hh

@@ -75,10 +75,12 @@ public:
 	//commandlineparserbase.cc
 	void outputSwitches(Outputter * o, bool extended, bool doc) const;
 	virtual char * mapAddress(char * d, char *) const {return d;}
+	virtual void license(FILE * fd) const;
 	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;
+	const char *appVersion() const;
 	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;

+ 12 - 1
src/shared/commonarguments.cc

@@ -89,6 +89,16 @@ struct VersionFunc {
 	}
 };
 
+/*!
+  Lambda: show the license
+*/
+struct LicenseFunc {
+    bool operator()(const char **, CommandLineParserBase & p, char *) {
+		p.license(stdout);
+		exit(0);
+	}
+};
+
 /*!
   The next arguments we add will belong to this section
   /param s The name of the section
@@ -147,7 +157,8 @@ 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("version", 'V' ,"Output version information and exit", new Caller<VersionFunc>());
+	addarg("license", 0 ,"Output license information and exit", new Caller<LicenseFunc>());
 	addarg("extended-help", 'H',"Display more extensive help, detailing less common command switches", new Caller<HelpFunc<true> >());
 
 	extended(true);

+ 12 - 17
src/shared/commondocparts.cc

@@ -20,9 +20,7 @@
 
 #include "commandlineparserbase.hh"
 #include "outputter.hh"
-
-#define STRINGIZE_(x) #x
-#define STRINGIZE(x) STRINGIZE_(x)
+#include <QFile>
 
 /*!
   Output the name and version of the program, and also whether we are using a patched qt
@@ -30,9 +28,8 @@
 */
 void CommandLineParserBase::outputName(Outputter * o) const {
 	o->beginSection("Name");
-	o->paragraph(appName()+" " STRINGIZE(FULL_VERSION));
+	o->paragraph(appName()+" "+appVersion());
 	o->endSection();
-
 }
 
 /*!
@@ -41,14 +38,12 @@ void CommandLineParserBase::outputName(Outputter * o) const {
 */
 void CommandLineParserBase::outputLicense(Outputter * o) const {
 	o->beginSection("License");
-	o->paragraph("Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.");
-	o->endParagraph();
-	o->beginParagraph();
-	o->text("License LGPLv3+: GNU Lesser General Public License version 3 or later ");
-	o->link("http://gnu.org/licenses/lgpl.html");
-	o->text(". This is free software: you are free to change and redistribute it. "
-			"There is NO WARRANTY, to the extent permitted by law.");
-	o->endParagraph();
+	o->paragraph("Copyright (c) 2010-2014 wkhtmltopdf authors");
+	QFile file(":/COPYING");
+	file.open(QIODevice::ReadOnly | QIODevice::Text);
+	QTextStream stream(&file);
+	o->verbatim(stream.readAll());
+	o->endSection();
 }
 
 /*!
@@ -57,10 +52,10 @@ void CommandLineParserBase::outputLicense(Outputter * o) const {
 */
 void CommandLineParserBase::outputAuthors(Outputter * o) const {
 	o->beginSection("Authors");
-	o->paragraph(
-		QString::fromUtf8(
-			"Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. "
-			"Patches by Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and Mário Silva."));
+	QFile file(":/AUTHORS");
+	file.open(QIODevice::ReadOnly | QIODevice::Text);
+	QTextStream stream(&file);
+	o->verbatim(stream.readAll());
 	o->endSection();
 }
 

+ 6 - 0
wkhtmltopdf.qrc

@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+  <qresource>
+    <file>AUTHORS</file>
+    <file>COPYING</file>
+  </qresource>
+</RCC>