From 83fa761de592db992eb99094256fd4615330e27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Tr=C3=B6scher?= Date: Tue, 26 Jul 2011 12:07:10 +0200 Subject: use KTemporaryFile for tempfile in viewPageSource action. REVIEW:102087 --- src/mainwindow.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c0ca149e..833e69d3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -979,25 +979,19 @@ void MainWindow::viewPageSource() if (!w) return; - KUrl url = w->url(); - QString code = w->page()->mainFrame()->toHtml(); - // find a safe file name... - QUrl tempUrl = QUrl(url.url()); - QByteArray name = tempUrl.toEncoded(QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); - QString filePath = KStandardDirs::locateLocal("tmp", QString("code/") + name.toBase64(), true); - - QFile temp(filePath); + KTemporaryFile tmpFile; + tmpFile.setAutoRemove(false); + if (!tmpFile.open()) + return; - if (temp.open(QFile::WriteOnly | QFile::Truncate)) - { - QTextStream out(&temp); - out << code; - } + QTextStream out(&tmpFile); + out << code; + tmpFile.close(); + KUrl tmpUrl(tmpFile.fileName()); - KRun::runUrl(QString(QL1S("file://") + temp.fileName()), QL1S("text/plain"), this, false); - return; + KRun::runUrl(tmpUrl, QL1S("text/plain"), this, false); } -- cgit v1.2.1