Web Browser (NG): some more improvements of the download manager

Sun, 08 Apr 2018 17:34:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 08 Apr 2018 17:34:59 +0200
changeset 6224
08875555771a
parent 6223
53eda93de07c
child 6225
56b6f18abc21

Web Browser (NG): some more improvements of the download manager

Preferences/ConfigurationPages/NetworkPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/NetworkPage.ui file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
WebBrowser/Download/DownloadItem.py file | annotate | diff | comparison | revisions
WebBrowser/Download/DownloadManager.py file | annotate | diff | comparison | revisions
icons/default/downloads48.png file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationPages/NetworkPage.py	Sun Apr 08 16:37:21 2018 +0200
+++ b/Preferences/ConfigurationPages/NetworkPage.py	Sun Apr 08 17:34:59 2018 +0200
@@ -141,6 +141,7 @@
                 self.__webKit = True
             except ImportError:
                 self.cleanupGroup.hide()
+            self.displayGroup.hide()
         else:
             policy = Preferences.getWebBrowser("DownloadManagerRemovePolicy")
             from WebBrowser.Download.DownloadManager import DownloadManager
@@ -150,6 +151,10 @@
                 self.cleanupExitButton.setChecked(True)
             else:
                 self.cleanupSuccessfulButton.setChecked(True)
+            self.openOnStartCheckBox.setChecked(
+                Preferences.getWebBrowser("DownloadManagerAutoOpen"))
+            self.closeOnFinishedCheckBox.setChecked(
+                Preferences.getWebBrowser("DownloadManagerAutoClose"))
             self.__webEngine = True
     
     def save(self):
@@ -183,6 +188,12 @@
             else:
                 policy = DownloadManager.RemoveSuccessFullDownload
             Preferences.setWebBrowser("DownloadManagerRemovePolicy", policy)
+            Preferences.setWebBrowser(
+                "DownloadManagerAutoOpen",
+                self.openOnStartCheckBox.isChecked())
+            Preferences.setWebBrowser(
+                "DownloadManagerAutoClose",
+                self.closeOnFinishedCheckBox.isChecked())
         
         Preferences.setUI(
             "UseProxy",
--- a/Preferences/ConfigurationPages/NetworkPage.ui	Sun Apr 08 16:37:21 2018 +0200
+++ b/Preferences/ConfigurationPages/NetworkPage.ui	Sun Apr 08 17:34:59 2018 +0200
@@ -7,10 +7,10 @@
     <x>0</x>
     <y>0</y>
     <width>591</width>
-    <height>1127</height>
+    <height>1261</height>
    </rect>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_6">
+  <layout class="QVBoxLayout" name="verticalLayout_7">
    <item>
     <widget class="QLabel" name="headerLabel">
      <property name="text">
@@ -55,7 +55,7 @@
      <property name="title">
       <string>Downloads</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout_3">
+     <layout class="QVBoxLayout" name="verticalLayout_6">
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
@@ -132,6 +132,35 @@
         </layout>
        </widget>
       </item>
+      <item>
+       <widget class="QGroupBox" name="displayGroup">
+        <property name="title">
+         <string>Download Manager Display Policy</string>
+        </property>
+        <layout class="QVBoxLayout" name="verticalLayout_3">
+         <item>
+          <widget class="QCheckBox" name="openOnStartCheckBox">
+           <property name="toolTip">
+            <string>Select to open the download manager dialog when starting a download</string>
+           </property>
+           <property name="text">
+            <string>Open when starting download</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QCheckBox" name="closeOnFinishedCheckBox">
+           <property name="toolTip">
+            <string>Select to close the download manager dialog when the last download is finished</string>
+           </property>
+           <property name="text">
+            <string>Close when downloads finished</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
@@ -478,6 +507,8 @@
   <tabstop>cleanupNeverButton</tabstop>
   <tabstop>cleanupExitButton</tabstop>
   <tabstop>cleanupSuccessfulButton</tabstop>
+  <tabstop>openOnStartCheckBox</tabstop>
+  <tabstop>closeOnFinishedCheckBox</tabstop>
   <tabstop>noProxyButton</tabstop>
   <tabstop>systemProxyButton</tabstop>
   <tabstop>manualProxyButton</tabstop>
--- a/Preferences/__init__.py	Sun Apr 08 16:37:21 2018 +0200
+++ b/Preferences/__init__.py	Sun Apr 08 17:34:59 2018 +0200
@@ -1106,9 +1106,11 @@
         "GreaseMonkeyDisabledScripts": [],
         # Downloads
         "DownloadManagerRemovePolicy": 0,      # never delete downloads
-        "DownloadManagerSize": QSize(400, 300),
+        "DownloadManagerSize": QSize(450, 600),
         "DownloadManagerPosition": QPoint(),
         "DownloadManagerDownloads": [],
+        "DownloadManagerAutoOpen": False,
+        "DownloadManagerAutoClose": False,
         # Spell Checking
         "SpellCheckEnabled": False,
         "SpellCheckLanguages": [],
@@ -3016,6 +3018,7 @@
                  "SafeBrowsingEnabled", "SafeBrowsingFilterPlatform",
                  "SafeBrowsingAutoUpdate", "AllowGeolocationOnInsecureOrigins",
                  "AllowWindowActivationFromJavaScript", "ShowScrollBars",
+                 "DownloadManagerAutoOpen", "DownloadManagerAutoClose",
                  ]:
         return toBool(prefClass.settings.value(
             "WebBrowser/" + key, prefClass.webBrowserDefaults[key]))
--- a/WebBrowser/Download/DownloadItem.py	Sun Apr 08 16:37:21 2018 +0200
+++ b/WebBrowser/Download/DownloadItem.py	Sun Apr 08 17:34:59 2018 +0200
@@ -35,11 +35,11 @@
     Class implementing a widget controlling a download.
     
     @signal statusChanged() emitted upon a status change of a download
-    @signal downloadFinished() emitted when a download finished
+    @signal downloadFinished(success) emitted when a download finished
     @signal progress(int, int) emitted to signal the download progress
     """
     statusChanged = pyqtSignal()
-    downloadFinished = pyqtSignal()
+    downloadFinished = pyqtSignal(bool)
     progress = pyqtSignal(int, int)
     
     Downloading = 0
@@ -356,7 +356,7 @@
         self.__state = DownloadItem.DownloadCancelled
         self.__downloadItem.cancel()
         self.__setDateTime()
-        self.downloadFinished.emit()
+        self.downloadFinished.emit(False)
     
     @pyqtSlot()
     def on_openButton_clicked(self):
@@ -544,7 +544,7 @@
         self.__adjustSize()
         
         self.statusChanged.emit()
-        self.downloadFinished.emit()
+        self.downloadFinished.emit(True)
         
         if self.__autoOpen:
             self.openFile()
--- a/WebBrowser/Download/DownloadManager.py	Sun Apr 08 16:37:21 2018 +0200
+++ b/WebBrowser/Download/DownloadManager.py	Sun Apr 08 17:34:59 2018 +0200
@@ -16,6 +16,7 @@
     QApplication, QShortcut
 
 from E5Gui import E5MessageBox
+from E5Gui.E5Application import e5App
 
 from .Ui_DownloadManager import Ui_DownloadManager
 
@@ -265,7 +266,10 @@
                            parent=self)
         self.__addItem(itm)
         
-        self.__startUpdateTimer()
+        if Preferences.getWebBrowser("DownloadManagerAutoOpen"):
+            self.show()
+        else:
+            self.__startUpdateTimer()
     
     def show(self):
         """
@@ -459,14 +463,39 @@
         
         self.downloadsCountChanged.emit()
     
-    def __finished(self):
+    def __finished(self, success):
         """
         Private slot to handle a finished download.
+        
+        @param success flag indicating a successful download
+        @type bool
         """
         if self.isVisible():
             QApplication.alert(self)
         
         self.downloadsCountChanged.emit()
+        
+        if self.activeDownloadsCount() == 0:
+            # all active downloads are done
+            if success and e5App().activeWindow() is not self:
+                if WebBrowserWindow.notificationsEnabled():
+                    WebBrowserWindow.showNotification(
+                        UI.PixmapCache.getPixmap("downloads48.png"),
+                        self.tr("Downloads finished"),
+                        self.tr("All files have been downloaded.")
+                    )
+                if not Preferences.getWebBrowser("DownloadManagerAutoClose"):
+                    self.raise_()
+                    self.activateWindow()
+            
+            self.__stopUpdateTimer()
+            self.infoLabel.clear()
+            self.setWindowTitle(self.tr("Download Manager"))
+            if Globals.isWindowsPlatform():
+                self.__taskbarButton().progress().hide()
+            
+            if Preferences.getWebBrowser("DownloadManagerAutoClose"):
+                self.close()
     
     def setDownloadDirectory(self, directory):
         """
Binary file icons/default/downloads48.png has changed

eric ide

mercurial