WebBrowser/Download/DownloadManager.py

changeset 6134
cb0985e8da91
parent 6118
da9e08920e7c
child 6149
e611e45a17d6
diff -r eba07240fac1 -r cb0985e8da91 WebBrowser/Download/DownloadManager.py
--- a/WebBrowser/Download/DownloadManager.py	Sun Feb 11 16:04:16 2018 +0100
+++ b/WebBrowser/Download/DownloadManager.py	Sun Feb 11 16:04:47 2018 +0100
@@ -9,7 +9,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot, Qt, QModelIndex, QFileInfo, QUrl
+from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QModelIndex, QFileInfo, QUrl
 from PyQt5.QtGui import QCursor, QKeySequence
 from PyQt5.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, \
     QApplication, QShortcut
@@ -35,6 +35,8 @@
     RemoveExit = 1
     RemoveSuccessFullDownload = 2
     
+    downloadsCountChanged = pyqtSignal()
+    
     def __init__(self, parent=None):
         """
         Constructor
@@ -128,7 +130,7 @@
         self.save()
         self.close()
     
-    def activeDownloads(self):
+    def activeDownloadsCount(self):
         """
         Public method to get the number of active downloads.
         
@@ -147,13 +149,13 @@
         
         @return flag indicating allowance to quit (boolean)
         """
-        if self.activeDownloads() > 0:
+        if self.activeDownloadsCount() > 0:
             res = E5MessageBox.yesNo(
                 self,
                 self.tr(""),
                 self.tr("""There are %n downloads in progress.\n"""
                         """Do you want to quit anyway?""", "",
-                        self.activeDownloads()),
+                        self.activeDownloadsCount()),
                 icon=E5MessageBox.Warning)
             if not res:
                 self.show()
@@ -194,8 +196,11 @@
                     downloadItem.cancel()
                     return
         
+        pageUrl = \
+            WebBrowserWindow.mainWindow().getWindow().currentBrowser().url()
         from .DownloadItem import DownloadItem
-        itm = DownloadItem(downloadItem, parent=self)
+        itm = DownloadItem(downloadItem=downloadItem, pageUrl=pageUrl,
+                           parent=self)
         self.__addItem(itm)
         
         if itm.canceledFileSelect():
@@ -221,7 +226,7 @@
         
         # insert at top of window
         if append:
-            row = len(self.__downloads)
+            row = self.downloadsCount()
         else:
             row = 0
         self.__model.beginInsertRows(QModelIndex(), row, row)
@@ -240,6 +245,8 @@
         self.__updateRow(itm)
         self.changeOccurred()
         self.__updateActiveItemCount()
+        
+        self.downloadsCountChanged.emit()
     
     def __updateRow(self, itm):
         """
@@ -275,7 +282,7 @@
             self.__model.removeRow(row)
         
         self.cleanupButton.setEnabled(
-            (len(self.__downloads) - self.activeDownloads()) > 0)
+            (self.downloadsCount() - self.activeDownloadsCount()) > 0)
         
         # record the change
         self.changeOccurred()
@@ -350,10 +357,12 @@
                     itm.setData(download)
                     self.__addItem(itm, append=True)
             self.cleanupButton.setEnabled(
-                (len(self.__downloads) - self.activeDownloads()) > 0)
+                (self.downloadsCount() - self.activeDownloadsCount()) > 0)
         
         self.__loaded = True
         self.__updateActiveItemCount()
+        
+        self.downloadsCountChanged.emit()
     
     def closeEvent(self, evt):
         """
@@ -375,29 +384,31 @@
         """
         Private slot cleanup the downloads.
         """
-        if len(self.__downloads) == 0:
+        if self.downloadsCount() == 0:
             return
         
-        self.__model.removeRows(0, len(self.__downloads))
-        if len(self.__downloads) == 0 and \
+        self.__model.removeRows(0, self.downloadsCount())
+        if self.downloadsCount() == 0 and \
            self.__iconProvider is not None:
             self.__iconProvider = None
         
         self.changeOccurred()
         self.__updateActiveItemCount()
+        
+        self.downloadsCountChanged.emit()
     
     def __updateItemCount(self):
         """
         Private method to update the count label.
         """
-        count = len(self.__downloads)
+        count = self.downloadsCount()
         self.countLabel.setText(self.tr("%n Download(s)", "", count))
     
     def __updateActiveItemCount(self):
         """
         Private method to update the window title.
         """
-        count = self.activeDownloads()
+        count = self.activeDownloadsCount()
         if count > 0:
             self.setWindowTitle(
                 self.tr("Downloading %n file(s)", "", count))
@@ -411,6 +422,8 @@
         self.__updateActiveItemCount()
         if self.isVisible():
             QApplication.alert(self)
+        
+        self.downloadsCountChanged.emit()
     
     def setDownloadDirectory(self, directory):
         """
@@ -430,11 +443,12 @@
         """
         return self.__downloadDirectory
     
-    def count(self):
+    def downloadsCount(self):
         """
         Public method to get the number of downloads.
         
-        @return number of downloads (integer)
+        @return number of downloads
+        @type int
         """
         return len(self.__downloads)
     

eric ide

mercurial