summaryrefslogtreecommitdiffstats
path: root/tools/assistant
diff options
context:
space:
mode:
authorck <qt-info@nokia.com>2010-01-14 09:52:25 (GMT)
committerck <qt-info@nokia.com>2010-01-14 09:52:25 (GMT)
commitfac30831e9235bb3373a0a96c40c9b653f87e34c (patch)
tree90759531097a1da71c418a41280334fe24db8301 /tools/assistant
parent7d1e48639d6d3897e66779f22fe02d17d6c38707 (diff)
downloadQt-fac30831e9235bb3373a0a96c40c9b653f87e34c.zip
Qt-fac30831e9235bb3373a0a96c40c9b653f87e34c.tar.gz
Qt-fac30831e9235bb3373a0a96c40c9b653f87e34c.tar.bz2
Use QTemporaryFile for opening documents in external applications.
Reviewed-by: kh1
Diffstat (limited to 'tools/assistant')
-rw-r--r--tools/assistant/tools/assistant/helpviewer.cpp24
1 files 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 <QtCore/QEvent>
#include <QtCore/QVariant>
#include <QtCore/QByteArray>
+#include <QtCore/QStringBuilder>
+#include <QtCore/QTemporaryFile>
#include <QtCore/QTimer>
#include <QtGui/QMenu>
@@ -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");