From fac30831e9235bb3373a0a96c40c9b653f87e34c Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 14 Jan 2010 10:52:25 +0100 Subject: Use QTemporaryFile for opening documents in external applications. Reviewed-by: kh1 --- tools/assistant/tools/assistant/helpviewer.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index 4ba896c..f20cbc1 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include #include @@ -243,19 +245,17 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *, if (isLocalUrl(url)) { const QString& path = url.path(); if (path.endsWith(QLatin1String(".pdf"))) { - const int lastDash = path.lastIndexOf(QChar('/')); - QString fileName = QDir::tempPath() + QDir::separator(); - if (lastDash < 0) - fileName += path; - else - fileName += path.mid(lastDash + 1, path.length()); - - QFile tmpFile(QDir::cleanPath(fileName)); - if (tmpFile.open(QIODevice::ReadWrite)) { - tmpFile.write(HelpEngineWrapper::instance().fileData(url)); - tmpFile.close(); + QTemporaryFile tmpTmpFile; + if (!tmpTmpFile.open()) + return false; + const QString extension = QFileInfo(path).completeSuffix(); + QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".") + % extension); + if (actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) { + actualTmpFile.write(HelpEngineWrapper::instance().fileData(url)); + actualTmpFile.close(); + QDesktopServices::openUrl(QUrl(actualTmpFile.fileName())); } - QDesktopServices::openUrl(QUrl(tmpFile.fileName())); if (closeNewTab) QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab"); -- cgit v0.12