From 40788da124781425c89f8a86b6ffbd056c5af1fa Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 13 May 2011 00:22:10 +0200 Subject: Open source code by loading the page HTML instead of requesting (another time) the site url. This will let also the "set content editable" feature works well on save --- src/mainwindow.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2ed8fef5..e5818677 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -74,6 +74,7 @@ #include #include #include +#include #include #include @@ -668,6 +669,19 @@ void MainWindow::fileSaveAs() if (destUrl.isEmpty()) return; + if (w->page()->isContentEditable()) + { + QString code = w->page()->mainFrame()->toHtml(); + QFile file(destUrl); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + + QTextStream out(&file); + out << code; + + return; + } + KIO::Job *job = KIO::file_copy(srcUrl, KUrl(destUrl), -1, KIO::Overwrite); job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache. job->addMetaData("cache", "cache"); // Use entry from cache if available. @@ -960,11 +974,30 @@ QString MainWindow::selectedText() const void MainWindow::viewPageSource() { - if (!currentTab()) + WebTab * w = currentTab(); + + if (!w) return; - KUrl url = currentTab()->url(); - KRun::runUrl(url, QL1S("text/plain"), this, false); + 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); + + if (temp.open(QFile::WriteOnly | QFile::Truncate)) + { + QTextStream out(&temp); + out << code; + } + + KRun::runUrl(QL1S("file://") + temp.fileName(), QL1S("text/plain"), this, false); + return; } -- cgit v1.2.1