summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index c0ca149e..d0d4d401 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -79,6 +79,7 @@
#include <KParts/Part>
#include <KParts/BrowserExtension>
+#include <KMimeTypeTrader>
// Qt Includes
#include <QtCore/QTimer>
@@ -980,24 +981,30 @@ void MainWindow::viewPageSource()
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);
+ KTemporaryFile tmpFile;
+ tmpFile.setAutoRemove(false);
+ if (!tmpFile.open())
+ return;
- QFile temp(filePath);
+ QTextStream out(&tmpFile);
+ out << code;
+ tmpFile.close();
+ KUrl tmpUrl(tmpFile.fileName());
- if (temp.open(QFile::WriteOnly | QFile::Truncate))
+ KParts::ReadOnlyPart *pa = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(QL1S("text/plain"), w, this, QString());
+ if (pa)
{
- QTextStream out(&temp);
- out << code;
+ WebTab *srcTab = m_view->newWebTab(true);
+ srcTab->page()->setIsOnRekonqPage(true);
+ srcTab->setPart(pa, tmpUrl);
+ srcTab->urlBar()->setQUrl(url.pathOrUrl());
+ m_view->setTabText(m_view->currentIndex(), i18n("Source of: ") + url.prettyUrl());
+ updateActions();
}
-
- KRun::runUrl(QString(QL1S("file://") + temp.fileName()), QL1S("text/plain"), this, false);
- return;
+ else
+ KRun::runUrl(tmpUrl, QL1S("text/plain"), this, false);
}