Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Open source code by loading the page HTML instead of requesting (anot…

…her time) the site url.

This will let also the "set content editable" feature works well on save
  • Loading branch information...
commit 40788da124781425c89f8a86b6ffbd056c5af1fa 1 parent 23ae10d
Andrea Diamantini adjamhub authored
Showing with 36 additions and 3 deletions.
  1. +36 −3 src/mainwindow.cpp
39 src/mainwindow.cpp
View
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.