From 1510e5115bf27218f8bf775e22927e213018ee86 Mon Sep 17 00:00:00 2001
From: Andrea Diamantini <adjam7@gmail.com>
Date: Sun, 19 Apr 2009 12:13:19 +0200
Subject: Porting "view page source" code to KDE from Pawel's clone

---
 src/mainwindow.cpp | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 077a057b..37e1f760 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -661,12 +661,29 @@ void MainWindow::slotViewPageSource()
     if (!currentTab())
         return;
 
-    QString markup = currentTab()->page()->mainFrame()->toHtml();
-    QPlainTextEdit *view = new QPlainTextEdit(markup);
-    view->setWindowTitle(i18n("Page Source of ") + currentTab()->title());
-    view->setMinimumWidth(640);
-    view->setAttribute(Qt::WA_DeleteOnClose);
-    view->show();
+    KUrl url(currentTab()->url());
+    bool isTempFile = false;
+    if (!url.isLocalFile())
+    {
+        KTemporaryFile sourceFile;
+
+        /// TODO: autochoose tempfile suffix
+        sourceFile.setSuffix(QString(".html"));
+        sourceFile.setAutoRemove(false);
+        
+        if (sourceFile.open())
+        {
+            QDataStream stream(&sourceFile);
+            stream << currentTab()->page()->mainFrame()->toHtml().toUtf8();
+            
+            url = KUrl();
+            url.setPath(sourceFile.fileName());
+            isTempFile = true;
+        }
+    }
+    KRun::runUrl(url, QLatin1String("text/plain"), this, isTempFile);
+}
+
 }
 
 
-- 
cgit v1.2.1