summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-05-13 00:22:10 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-05-13 00:22:10 +0200
commit40788da124781425c89f8a86b6ffbd056c5af1fa (patch)
tree40051799a4f40ad76928bc9a7ad7b1c450306eef
parentDeveloper tool: set content editable. (diff)
downloadrekonq-40788da124781425c89f8a86b6ffbd056c5af1fa.tar.xz
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
-rw-r--r--src/mainwindow.cpp39
1 files 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 <KStandardDirs>
#include <KToggleFullScreenAction>
#include <KProtocolManager>
+#include <KTemporaryFile>
#include <KParts/Part>
#include <KParts/BrowserExtension>
@@ -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;
}