Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored May 13, 2011

Showing 1 changed file with 36 additions and 3 deletions. Show diff stats Hide diff stats

  1. 39  src/mainwindow.cpp
39  src/mainwindow.cpp
@@ -74,6 +74,7 @@
74 74
 #include <KStandardDirs>
75 75
 #include <KToggleFullScreenAction>
76 76
 #include <KProtocolManager>
  77
+#include <KTemporaryFile>
77 78
 
78 79
 #include <KParts/Part>
79 80
 #include <KParts/BrowserExtension>
@@ -668,6 +669,19 @@ void MainWindow::fileSaveAs()
668 669
     if (destUrl.isEmpty())
669 670
         return;
670 671
 
  672
+    if (w->page()->isContentEditable())
  673
+    {
  674
+        QString code = w->page()->mainFrame()->toHtml();
  675
+        QFile file(destUrl);
  676
+        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
  677
+            return;
  678
+
  679
+        QTextStream out(&file);
  680
+        out << code;
  681
+
  682
+        return;
  683
+    }
  684
+    
671 685
     KIO::Job *job = KIO::file_copy(srcUrl, KUrl(destUrl), -1, KIO::Overwrite);
672 686
     job->addMetaData("MaxCacheSize", "0");  // Don't store in http cache.
673 687
     job->addMetaData("cache", "cache");     // Use entry from cache if available.
@@ -960,11 +974,30 @@ QString MainWindow::selectedText() const
960 974
 
961 975
 void MainWindow::viewPageSource()
962 976
 {
963  
-    if (!currentTab())
  977
+    WebTab * w = currentTab();
  978
+    
  979
+    if (!w)
964 980
         return;
965 981
 
966  
-    KUrl url = currentTab()->url();
967  
-    KRun::runUrl(url, QL1S("text/plain"), this, false);
  982
+    KUrl url = w->url();
  983
+
  984
+    QString code = w->page()->mainFrame()->toHtml();
  985
+
  986
+    // find a safe file name...
  987
+    QUrl tempUrl = QUrl(url.url());
  988
+    QByteArray name = tempUrl.toEncoded(QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash);
  989
+    QString filePath = KStandardDirs::locateLocal("tmp", QString("code/") + name.toBase64(), true);
  990
+
  991
+    QFile temp(filePath);
  992
+
  993
+    if (temp.open(QFile::WriteOnly | QFile::Truncate))
  994
+    {
  995
+        QTextStream out(&temp);
  996
+        out << code;
  997
+    }
  998
+
  999
+    KRun::runUrl(QL1S("file://") + temp.fileName(), QL1S("text/plain"), this, false);
  1000
+    return;
968 1001
 }
969 1002
 
970 1003
 

0 notes on commit 40788da

Please sign in to comment.
Something went wrong with that request. Please try again.