Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.

Sun, 26 Sep 2010 15:18:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 26 Sep 2010 15:18:07 +0200
changeset 641
b06d4df23797
parent 640
ae2e2a0cde5b
child 643
719db11dd4df

Fixed an issue in the web browser related to webkit and Qt help and fixed an issue introduced by the latest refactoring.

APIs/Python3/eric5.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric5.Helpviewer.Network.QtHelpAccessHandler.html file | annotate | diff | comparison | revisions
Helpviewer/HelpBrowserWV.py file | annotate | diff | comparison | revisions
Helpviewer/HelpTabWidget.py file | annotate | diff | comparison | revisions
Helpviewer/Network/NetworkReply.py file | annotate | diff | comparison | revisions
Helpviewer/Network/QtHelpAccessHandler.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric5.api	Sun Sep 26 11:18:21 2010 +0200
+++ b/APIs/Python3/eric5.api	Sun Sep 26 15:18:07 2010 +0200
@@ -2132,6 +2132,8 @@
 eric5.Helpviewer.Network.NetworkReply.NetworkReply.readData?4(maxlen)
 eric5.Helpviewer.Network.NetworkReply.NetworkReply?1(request, fileData, mimeType, parent = None)
 eric5.Helpviewer.Network.PyrcAccessHandler.PyrcAccessHandler.createRequest?4(op, request, outgoingData = None)
+eric5.Helpviewer.Network.QtHelpAccessHandler.ExtensionMap?7
+eric5.Helpviewer.Network.QtHelpAccessHandler.QtDocPath?7
 eric5.Helpviewer.Network.QtHelpAccessHandler.QtHelpAccessHandler.createRequest?4(op, request, outgoingData = None)
 eric5.Helpviewer.Network.QtHelpAccessHandler.QtHelpAccessHandler?1(engine, parent = None)
 eric5.Helpviewer.Network.SchemeAccessHandler.SchemeAccessHandler.createRequest?4(op, request, outgoingData = None)
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Sep 26 11:18:21 2010 +0200
+++ b/Documentation/Help/source.qhp	Sun Sep 26 15:18:07 2010 +0200
@@ -6961,6 +6961,7 @@
       <keyword name="QtHelpAccessHandler (Module)" id="QtHelpAccessHandler (Module)" ref="eric5.Helpviewer.Network.QtHelpAccessHandler.html" />
       <keyword name="QtHelpAccessHandler" id="QtHelpAccessHandler" ref="eric5.Helpviewer.Network.QtHelpAccessHandler.html#QtHelpAccessHandler" />
       <keyword name="QtHelpAccessHandler (Constructor)" id="QtHelpAccessHandler (Constructor)" ref="eric5.Helpviewer.Network.QtHelpAccessHandler.html#QtHelpAccessHandler.__init__" />
+      <keyword name="QtHelpAccessHandler.__mimeFromUrl" id="QtHelpAccessHandler.__mimeFromUrl" ref="eric5.Helpviewer.Network.QtHelpAccessHandler.html#QtHelpAccessHandler.__mimeFromUrl" />
       <keyword name="QtHelpAccessHandler.createRequest" id="QtHelpAccessHandler.createRequest" ref="eric5.Helpviewer.Network.QtHelpAccessHandler.html#QtHelpAccessHandler.createRequest" />
       <keyword name="FtpReply (Module)" id="FtpReply (Module)" ref="eric5.Helpviewer.Network.FtpReply.html" />
       <keyword name="FtpReply" id="FtpReply" ref="eric5.Helpviewer.Network.FtpReply.html#FtpReply" />
--- a/Documentation/Source/eric5.Helpviewer.Network.QtHelpAccessHandler.html	Sun Sep 26 11:18:21 2010 +0200
+++ b/Documentation/Source/eric5.Helpviewer.Network.QtHelpAccessHandler.html	Sun Sep 26 15:18:07 2010 +0200
@@ -26,7 +26,7 @@
 </p>
 <h3>Global Attributes</h3>
 <table>
-<tr><td>None</td></tr>
+<tr><td>ExtensionMap</td></tr><tr><td>QtDocPath</td></tr>
 </table>
 <h3>Classes</h3>
 <table>
@@ -57,6 +57,9 @@
 <td><a href="#QtHelpAccessHandler.__init__">QtHelpAccessHandler</a></td>
 <td>Constructor</td>
 </tr><tr>
+<td><a href="#QtHelpAccessHandler.__mimeFromUrl">__mimeFromUrl</a></td>
+<td>Private method to guess the mime type given an URL.</td>
+</tr><tr>
 <td><a href="#QtHelpAccessHandler.createRequest">createRequest</a></td>
 <td>Protected method to create a request.</td>
 </tr>
@@ -74,6 +77,16 @@
 <dd>
 reference to the parent object (QObject)
 </dd>
+</dl><a NAME="QtHelpAccessHandler.__mimeFromUrl" ID="QtHelpAccessHandler.__mimeFromUrl"></a>
+<h4>QtHelpAccessHandler.__mimeFromUrl</h4>
+<b>__mimeFromUrl</b>(<i>url</i>)
+<p>
+        Private method to guess the mime type given an URL.
+</p><dl>
+<dt><i>url</i></dt>
+<dd>
+URL to guess the mime type from (QUrl)
+</dd>
 </dl><a NAME="QtHelpAccessHandler.createRequest" ID="QtHelpAccessHandler.createRequest"></a>
 <h4>QtHelpAccessHandler.createRequest</h4>
 <b>createRequest</b>(<i>op, request, outgoingData = None</i>)
--- a/Helpviewer/HelpBrowserWV.py	Sun Sep 26 11:18:21 2010 +0200
+++ b/Helpviewer/HelpBrowserWV.py	Sun Sep 26 15:18:07 2010 +0200
@@ -1066,8 +1066,6 @@
         self.__progress = 0
         self.mw.progressBar().hide()
         
-##        self.__iconChanged()
-        
         if ok:
             self.mw.adblockManager().page().applyRulesToPage(self.page())
             self.mw.passwordManager().fill(self.page())
--- a/Helpviewer/HelpTabWidget.py	Sun Sep 26 11:18:21 2010 +0200
+++ b/Helpviewer/HelpTabWidget.py	Sun Sep 26 15:18:07 2010 +0200
@@ -82,7 +82,7 @@
         self.setCornerWidget(self.__rightCornerWidget, Qt.TopRightCorner)
         
         self.__newTabButton = QToolButton(self)
-        self.__newTabButton.setIcon(UI.PixmapCache.getIcon("new.png"))
+        self.__newTabButton.setIcon(UI.PixmapCache.getIcon("tabNew.png"))
         self.__newTabButton.setToolTip(self.trUtf8("Open a new help window tab"))
         self.setCornerWidget(self.__newTabButton, Qt.TopLeftCorner)
         self.__newTabButton.clicked[bool].connect(self.newBrowser)
@@ -221,10 +221,24 @@
         
         browser.sourceChanged.connect(self.__sourceChanged)
         browser.titleChanged.connect(self.__titleChanged)
+        browser.highlighted.connect(self.showMessage)
+        browser.backwardAvailable.connect(self.__mainWindow.setBackwardAvailable)
+        browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable)
+        browser.loadStarted.connect(self.__loadStarted)
+        browser.loadFinished.connect(self.__loadFinished)
+        browser.iconChanged.connect(self.__iconChanged)
+        browser.search.connect(self.newBrowser)
+        browser.page().windowCloseRequested.connect(self.__windowCloseRequested)
+        browser.page().printRequested.connect(self.__printRequested)
         
         index = self.addTab(browser, self.trUtf8("..."))
         self.setCurrentIndex(index)
         
+        self.__mainWindow.closeAct.setEnabled(True)
+        self.__mainWindow.closeAllAct.setEnabled(True)
+        self.__closeButton and self.__closeButton.setEnabled(True)
+        self.__navigationButton.setEnabled(True)
+        
         if not linkName and Preferences.getHelp("StartupBehavior") == 0:
             linkName = Preferences.getHelp("HomePage")
         
@@ -237,21 +251,6 @@
                 self.setTabText(index, 
                     self.__elide(browser.documentTitle().replace("&", "&&")))
                 self.setTabToolTip(index, browser.documentTitle())
-        
-        browser.highlighted.connect(self.showMessage)
-        browser.backwardAvailable.connect(self.__mainWindow.setBackwardAvailable)
-        browser.forwardAvailable.connect(self.__mainWindow.setForwardAvailable)
-        browser.loadStarted.connect(self.__loadStarted)
-        browser.loadFinished.connect(self.__loadFinished)
-        browser.iconChanged.connect(self.__iconChanged)
-        browser.page().windowCloseRequested.connect(self.__windowCloseRequested)
-        browser.page().printRequested.connect(self.__printRequested)
-        browser.search.connect(self.newBrowser)
-        
-        self.__mainWindow.closeAct.setEnabled(True)
-        self.__mainWindow.closeAllAct.setEnabled(True)
-        self.__closeButton and self.__closeButton.setEnabled(True)
-        self.__navigationButton.setEnabled(True)
     
     def __showNavigationMenu(self):
         """
--- a/Helpviewer/Network/NetworkReply.py	Sun Sep 26 11:18:21 2010 +0200
+++ b/Helpviewer/Network/NetworkReply.py	Sun Sep 26 15:18:07 2010 +0200
@@ -51,6 +51,8 @@
         
         @return bytes available (integer)
         """
+        if self.__data.length() == 0:
+            QTimer.singleShot(0, lambda: self.finished.emit())
         return self.__data.length() + QNetworkReply.bytesAvailable(self)
     
     def readData(self, maxlen):
--- a/Helpviewer/Network/QtHelpAccessHandler.py	Sun Sep 26 11:18:21 2010 +0200
+++ b/Helpviewer/Network/QtHelpAccessHandler.py	Sun Sep 26 15:18:07 2010 +0200
@@ -7,10 +7,49 @@
 Module implementing a scheme access handler for QtHelp.
 """
 
+import mimetypes
+import os
+
+from PyQt4.QtCore import QByteArray
+
 from .SchemeAccessHandler import SchemeAccessHandler
 
 from .NetworkReply import NetworkReply
 
+QtDocPath = "qthelp://com.trolltech."
+
+ExtensionMap = {
+    ".bmp"   : "image/bmp",
+    ".css"   : "text/css",
+    ".gif"   : "image/gif",
+    ".html"  : "text/html",
+    ".htm"   : "text/html",
+    ".ico"   : "image/x-icon",
+    ".jpeg"  : "image/jpeg",
+    ".jpg"   : "image/jpeg",
+    ".js"    : "application/x-javascript",
+    ".mng"   : "video/x-mng",
+    ".pbm"   : "image/x-portable-bitmap",
+    ".pgm"   : "image/x-portable-graymap",
+    ".pdf"   : "application/pdf",
+    ".png"   : "image/png",
+    ".ppm"   : "image/x-portable-pixmap",
+    ".rss"   : "application/rss+xml",
+    ".svg"   : "image/svg+xml",
+    ".svgz"  : "image/svg+xml",
+    ".text"  : "text/plain",
+    ".tif"   : "image/tiff",
+    ".tiff"  : "image/tiff",
+    ".txt"   : "text/plain",
+    ".xbm"   : "image/x-xbitmap",
+    ".xml"   : "text/xml",
+    ".xpm"   : "image/x-xpm",
+    ".xsl"   : "text/xsl",
+    ".xhtml" : "application/xhtml+xml",
+    ".wml"   : "text/vnd.wap.wml",
+    ".wmlc"  : "application/vnd.wap.wmlc",
+}
+
 class QtHelpAccessHandler(SchemeAccessHandler):
     """
     Class implementing a scheme access handler for QtHelp.
@@ -26,6 +65,19 @@
         
         self.__engine = engine
     
+    def __mimeFromUrl(self, url):
+        """
+        Private method to guess the mime type given an URL.
+        
+        @param url URL to guess the mime type from (QUrl)
+        """
+        path = url.path()
+        ext = os.path.splitext(path)[1].lower()
+        if ext in ExtensionMap:
+            return ExtensionMap[ext]
+        else:
+            return "application/octet-stream"
+    
     def createRequest(self, op, request, outgoingData = None):
         """
         Protected method to create a request.
@@ -39,12 +91,30 @@
         url = request.url()
         strUrl = url.toString()
         
-        if strUrl.endswith(".svg") or strUrl.endswith(".svgz"):
-            mimeType = "image/svg+xml"
-        elif strUrl.endswith(".css"):
-            mimeType = "text/css"
-        elif strUrl.endswith(".js"):
-            mimeType = "text/javascript"
+        # For some reason the url to load is already wrong (passed from webkit)
+        # though the css file and the references inside should work that way. One 
+        # possible problem might be that the css is loaded at the same level as the
+        # html, thus a path inside the css like (../images/foo.png) might cd out of
+        # the virtual folder
+        if not self.__engine.findFile(url).isValid():
+            if strUrl.startswith(QtDocPath):
+                newUrl = request.url()
+                if not newUrl.path().startswith("/qdoc/"):
+                    newUrl.setPath("qdoc" + newUrl.path())
+                    url = newUrl
+                    strUrl = url.toString()
+        
+        mimeType = mimetypes.guess_type(strUrl)[0]
+        if mimeType is None:
+            # do our own (limited) guessing
+            mimeType = self.__mimeFromUrl(url)
+        
+        if self.__engine.findFile(url).isValid():
+            data = self.__engine.fileData(url)
         else:
-            mimeType = "text/html"
-        return NetworkReply(request, self.__engine.fileData(url), mimeType, self.parent())
+            data = QByteArray(self.trUtf8("""<title>Error 404...</title>"""
+                """<div align="center"><br><br>"""
+                """<h1>The page could not be found</h1><br>"""
+                """<h3>'{0}'</h3></div>""").format(strUrl).encode("utf-8"))
+        return NetworkReply(request, data, mimeType, self.parent())
+

eric ide

mercurial