Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
fix handling of temporary files during PDF conversion via API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ashkulz committed Jan 3, 2015
1 parent cd80b56 commit 71657b9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/multipageloader.cc
Expand Up @@ -550,7 +550,7 @@ void MultiPageLoaderPrivate::clearResources() {
ResourceObject *tmp = resources.takeFirst();
tmp->deleteLater();
}
tempIn.remove();
tempIn.removeAll();
}

void MultiPageLoaderPrivate::cancel() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pdfconverter.cc
Expand Up @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/pdfconverter_p.hh
Expand Up @@ -71,7 +71,6 @@ public:
QList<QWebPage *> headers;
QList<QWebPage *> footers;
int pageCount;
TempFile tocStyleFile;
TempFile tocFile;

void clear() {
Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions src/lib/tempfile.cc
Expand Up @@ -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();
}
6 changes: 3 additions & 3 deletions src/lib/tempfile.hh
Expand Up @@ -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"
Expand Down

0 comments on commit 71657b9

Please sign in to comment.