Continued porting the web browser. QtWebEngine

Thu, 25 Feb 2016 19:29:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 25 Feb 2016 19:29:09 +0100
branch
QtWebEngine
changeset 4772
db71b47b663e
parent 4769
2b6f7e026cdc
child 4773
cad470dfd807

Continued porting the web browser.

- finished adding the Downloads stuff

WebBrowser/Download/DownloadItem.py file | annotate | diff | comparison | revisions
WebBrowser/Download/DownloadManager.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
--- a/WebBrowser/Download/DownloadItem.py	Wed Feb 24 20:27:40 2016 +0100
+++ b/WebBrowser/Download/DownloadItem.py	Thu Feb 25 19:29:09 2016 +0100
@@ -42,7 +42,7 @@
     DownloadSuccessful = 1
     DownloadCancelled = 2
     
-    def __init__(self, downloadItem, parent=None):
+    def __init__(self, downloadItem=None, parent=None):
         """
         Constructor
         
@@ -72,8 +72,7 @@
         
         self.__downloadItem = downloadItem
         self.__pageUrl = \
-            WebBrowserWindow.mainWindow().getWindow().currentBrowser().url() \
-            or QUrl()
+            WebBrowserWindow.mainWindow().getWindow().currentBrowser().url()
         self.__bytesReceived = 0
         self.__bytesTotal = -1
         self.__downloadTime = QTime()
--- a/WebBrowser/Download/DownloadManager.py	Wed Feb 24 20:27:40 2016 +0100
+++ b/WebBrowser/Download/DownloadManager.py	Thu Feb 25 19:29:09 2016 +0100
@@ -9,7 +9,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot, Qt, QModelIndex, QFileInfo
+from PyQt5.QtCore import pyqtSlot, Qt, QModelIndex, QFileInfo, QUrl
 from PyQt5.QtGui import QCursor, QKeySequence
 from PyQt5.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, \
     QApplication, QShortcut
@@ -86,22 +86,17 @@
         if selectedRowsCount == 1:
             row = self.downloadsView.selectionModel().selectedRows()[0].row()
             itm = self.__downloads[row]
-            if itm.downloadCanceled():
+            if itm.downloadedSuccessfully():
+                menu.addAction(
+                    UI.PixmapCache.getIcon("open.png"),
+                    self.tr("Open"), self.__contextMenuOpen)
+            elif itm.downloading():
                 menu.addAction(
-                    UI.PixmapCache.getIcon("restart.png"),
-                    self.tr("Retry"), self.__contextMenuRetry)
-            else:
-                if itm.downloadedSuccessfully():
-                    menu.addAction(
-                        UI.PixmapCache.getIcon("open.png"),
-                        self.tr("Open"), self.__contextMenuOpen)
-                elif itm.downloading():
-                    menu.addAction(
-                        UI.PixmapCache.getIcon("stopLoading.png"),
-                        self.tr("Cancel"), self.__contextMenuCancel)
-                    menu.addSeparator()
-                menu.addAction(
-                    self.tr("Open Containing Folder"),
+                    UI.PixmapCache.getIcon("stopLoading.png"),
+                    self.tr("Cancel"), self.__contextMenuCancel)
+                menu.addSeparator()
+            menu.addAction(
+                self.tr("Open Containing Folder"),
                     self.__contextMenuOpenFolder)
             menu.addSeparator()
             menu.addAction(
@@ -239,11 +234,6 @@
             max(oldHeight, itm.minimumSizeHint().height() * 1.5))
         
         remove = False
-        # TODO: Private Browsing
-##        globalSettings = QWebSettings.globalSettings()
-##        if not itm.downloading() and \
-##           globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled):
-##            remove = True
         
         if itm.downloadedSuccessfully() and \
            self.removePolicy() == DownloadManager.RemoveSuccessFullDownload:
@@ -295,11 +285,14 @@
         if self.removePolicy() == DownloadManager.RemoveExit:
             return
         
-        # TODO: Downloads: check saving downloads
-##        downloads = []
-##        for download in self.__downloads:
-##            downloads.append(download.getData())
-##        Preferences.setWebBrowser("DownloadManagerDownloads", downloads)
+        from WebBrowser.WebBrowserWindow import WebBrowserWindow
+        if WebBrowserWindow.mainWindow().isPrivate():
+            return
+        
+        downloads = []
+        for download in self.__downloads:
+            downloads.append(download.getData())
+        Preferences.setWebBrowser("DownloadManagerDownloads", downloads)
     
     def __load(self):
         """
@@ -314,15 +307,14 @@
         pos = Preferences.getWebBrowser("DownloadManagerPosition")
         self.move(pos)
         
-        # TODO: Downloads: check laoding downloads
-##        downloads = Preferences.getWebBrowser("DownloadManagerDownloads")
-##        for download in downloads:
-##            if not download[0].isEmpty() and \
-##               download[1] != "":
-##                from .DownloadItem import DownloadItem
-##                itm = DownloadItem(parent=self)
-##                itm.setData(download)
-##                self.__addItem(itm)
+        downloads = Preferences.getWebBrowser("DownloadManagerDownloads")
+        for download in downloads:
+            if not download[0].isEmpty() and \
+               download[1] != "":
+                from .DownloadItem import DownloadItem
+                itm = DownloadItem(parent=self)
+                itm.setData(download)
+                self.__addItem(itm)
         self.cleanupButton.setEnabled(
             (len(self.__downloads) - self.activeDownloads()) > 0)
         
@@ -422,7 +414,6 @@
     ## Context menu related methods below
     ###########################################################################
     
-    # TODO: Downloads: check the context menu actions
     def __currentItem(self):
         """
         Private method to get a reference to the current item.
@@ -436,14 +427,6 @@
         
         return None
     
-    def __contextMenuRetry(self):
-        """
-        Private method to retry of the download.
-        """
-        itm = self.__currentItem()
-        if itm is not None:
-            itm.retry()
-    
     def __contextMenuOpen(self):
         """
         Private method to open the downloaded file.
@@ -483,7 +466,7 @@
         """
         itm = self.__currentItem()
         if itm is not None:
-            url = itm.getPageUrl().toString()
+            url = itm.getPageUrl().toDisplayString(QUrl.FullyDecoded)
             QApplication.clipboard().setText(url)
     
     def __contextMenuSelectAll(self):
--- a/WebBrowser/WebBrowserView.py	Wed Feb 24 20:27:40 2016 +0100
+++ b/WebBrowser/WebBrowserView.py	Thu Feb 25 19:29:09 2016 +0100
@@ -659,7 +659,7 @@
         # TODO: context menu: Open Link in New Window
         # TODO: context menu: Open Link in Private Window
         menu.addSeparator()
-        # TODO: Download Link
+        # TODO: Qt 5.6
 ##        menu.addAction(
 ##            UI.PixmapCache.getIcon("download.png"),
 ##            self.tr("Save Lin&k"), self.__downloadLink)
@@ -767,11 +767,10 @@
             UI.PixmapCache.getIcon("mailSend.png"),
             self.tr("Send Media Address"), self.__sendLink)\
             .setData(hitTest.mediaUrl())
-        # TODO: DownloadManager
+        # TODO: Qt 5.6
 ##        menu.addAction(
 ##            UI.PixmapCache.getIcon("download.png"),
-##            self.tr("Save Media"), self.__downloadMedia)\
-##            .setData(hitTest.mediaUrl())
+##            self.tr("Save Media"), self.__downloadMedia)
     
     def __createSelectedTextContextMenu(self, menu, hitTest):
         """
@@ -1011,23 +1010,24 @@
             data = data.toString()
         QApplication.clipboard().setText(data)
     
+    # TODO: Qt 5.6
 ##    def __downloadLink(self):
 ##        """
 ##        Private slot to download a link and save it to disk.
 ##        """
-##        self.pageAction(QWebPage.DownloadLinkToDisk).trigger()
+##        self.triggerPageAction(QWebEnginePage.DownloadLinkToDisk)
 ##    
 ##    def __downloadImage(self):
 ##        """
 ##        Private slot to download an image and save it to disk.
 ##        """
-##        self.pageAction(QWebPage.DownloadImageToDisk).trigger()
+##        self.triggerPageAction(QWebEnginePage.DownloadImageToDisk)
 ##    
 ##    def __copyImage(self):
 ##        """
 ##        Private slot to copy an image to the clipboard.
 ##        """
-##        self.pageAction(QWebPage.CopyImageToClipboard).trigger()
+##        self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
     
     # TODO: AdBlock
 ##    def __blockImage(self):
@@ -1040,15 +1040,14 @@
 ##        dlg = WebBrowser.WebBrowserWindow.WebBrowserWindow.adBlockManager().showDialog()
 ##        dlg.addCustomRule(url)
     
-    # TODO: DownloadManager
+    # TODO: Qt 5.6
 ##    def __downloadMedia(self):
 ##        """
 ##        Private slot to download a media and save it to disk.
 ##        """
-##        act = self.sender()
-##        url = act.data()
-##        self.__mw.downloadManager().download(url, True, mainWindow=self.__mw)
+##        self.triggerPageAction(QWebEnginePage.DownloadMediaToDisk)
     
+    # TODO: Qt 5.6: do this with triggerPageAction()
     def __pauseMedia(self):
         """
         Private slot to pause or play the selected media.
@@ -1057,6 +1056,7 @@
         script = Scripts.toggleMediaPause(self.__clickedPos)
         self.page().runJavaScript(script)
     
+    # TODO: Qt 5.6: do this with triggerPageAction()
     def __muteMedia(self):
         """
         Private slot to (un)mute the selected media.

eric ide

mercurial