Browse Source

fix handling of temporary files during PDF conversion via API

The TempFile class was able to handle only one file, but was used
in scenarios where multiple temp files were required. Change the
implementation and API to support this usage scenario, which also
fixes #1790.

Ideally, one should do away with this and use an in-memory QtWebKit
protocol [1] e.g. mem://uuid.html but that is something to be taken
up after refactoring of the current codebase.

[1] http://doc.qt.digia.com/qq/32/qq32-webkit-protocols.html
Ashish Kulkarni 10 years ago
parent
commit
71657b9e41
6 changed files with 15 additions and 16 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      src/lib/multipageloader.cc
  3. 1 1
      src/lib/pdfconverter.cc
  4. 1 3
      src/lib/pdfconverter_p.hh
  5. 8 8
      src/lib/tempfile.cc
  6. 3 3
      src/lib/tempfile.hh

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@ v0.12.2 (unreleased)
 * **#1722**: **[qt]** fix broken hyphenation with soft-hyphens
 * **#1769**: fixed unicode URLs in links
 * **#1772**: added variable 'isodate' for substitution in headers/footers
+* **#1790**: fix handling of temporary files during PDF conversion via API
 * **#1808**: fix [sitepage] and [sitepages] not working without HTML headers/footers
 * **#1825**: fix handling of non-ASCII characters in command-line arguments
 * **#1863**: **[qt]** blank page or crash with low DPI on Windows

+ 1 - 1
src/lib/multipageloader.cc

@@ -550,7 +550,7 @@ void MultiPageLoaderPrivate::clearResources() {
 		ResourceObject *tmp = resources.takeFirst();
 		tmp->deleteLater();
 	}
-	tempIn.remove();
+	tempIn.removeAll();
 }
 
 void MultiPageLoaderPrivate::cancel() {

+ 1 - 1
src/lib/pdfconverter.cc

@@ -487,7 +487,7 @@ void PdfConverterPrivate::loadTocs() {
 
 		QString style = ps.tocXsl;
 		if (style.isEmpty()) {
-			style = obj.tocStyleFile.create(".xsl");
+			style = obj.tocFile.create(".xsl");
 			StreamDumper styleDump(style);
 			dumpDefaultTOCStyleSheet(styleDump.stream, ps.toc);
 		}

+ 1 - 3
src/lib/pdfconverter_p.hh

@@ -71,7 +71,6 @@ public:
 	QList<QWebPage *> headers;
 	QList<QWebPage *> footers;
 	int pageCount;
-	TempFile tocStyleFile;
 	TempFile tocFile;
 
 	void clear() {
@@ -84,8 +83,7 @@ public:
 		footers.clear();
 		webPageToObject.remove(page);
  		page=0;
-		tocStyleFile.remove();
-		tocFile.remove();
+		tocFile.removeAll();
 	}
 
 	PageObject(const settings::PdfObject & set, const QString * d=NULL):

+ 8 - 8
src/lib/tempfile.cc

@@ -39,25 +39,25 @@ TempFile::TempFile() {
 }
 
 TempFile::~TempFile() {
-	remove();
+	removeAll();
 }
 
 /*!
-  \brief Create a new temporary file, deleting the old if one exists
+  \brief Create a new temporary file
   \param ext The extention of the temporary file
   \returns Path of the new temporary file
 */
 QString TempFile::create(const QString & ext) {
-	remove();
-	path = QDir::tempPath()+"/wktemp-"+QUuid::createUuid().toString().mid(1,36)+ext;
+	QString path = QDir::tempPath()+"/wktemp-"+QUuid::createUuid().toString().mid(1,36)+ext;
+	paths.append(path);
 	return path;
 }
 
 /*!
-  \brief Remove the temporary file hold by this object it it exists
+  \brief Remove all the temporary files held by this object
 */
-void TempFile::remove() {
-	if (!path.isEmpty())
+void TempFile::removeAll() {
+	foreach (const QString &path, paths)
 		QFile::remove(path);
-	path="";
+	paths.clear();
 }

+ 3 - 3
src/lib/tempfile.hh

@@ -21,18 +21,18 @@
 #ifndef __TEMPFILE_HH__
 #define __TEMPFILE_HH__
 
-#include <QString>
+#include <QStringList>
 
 #include "dllbegin.inc"
 
 class DLL_LOCAL TempFile {
 private:
-	QString path;
+	QStringList paths;
 public:
 	TempFile();
 	~TempFile();
 	QString create(const QString & ext);
-	void remove();
+	void removeAll();
 };
 
 #include "dllend.inc"