src/eric7/WebBrowser/Download/DownloadManager.py

Tue, 18 Oct 2022 16:06:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 18 Oct 2022 16:06:21 +0200
branch
eric7
changeset 9413
80c06d472826
parent 9221
bf71ee032bb4
child 9473
3f23dbf37dbe
permissions
-rw-r--r--

Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.

668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8856
diff changeset
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
4 #
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
5
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the download manager class.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
10 from PyQt6.QtCore import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
11 pyqtSlot,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
12 pyqtSignal,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
13 Qt,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
14 QModelIndex,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
15 QFileInfo,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
16 QUrl,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
17 QBasicTimer,
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
18 )
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
19 from PyQt6.QtGui import QCursor, QKeySequence, QShortcut
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
20 from PyQt6.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, QApplication
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
22 from eric7.EricWidgets import EricMessageBox
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
23 from eric7.EricWidgets.EricApplication import ericApp
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 from .Ui_DownloadManager import Ui_DownloadManager
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 from .DownloadModel import DownloadModel
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
28 from .DownloadUtilities import speedString, timeString
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
30 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
32 from eric7.Utilities.AutoSaver import AutoSaver
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
33 from eric7.EricGui import EricPixmapCache
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
34 from eric7 import Globals, Preferences
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
36
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 class DownloadManager(QDialog, Ui_DownloadManager):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
39 Class implementing the download manager.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40
6149
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
41 @signal downloadsCountChanged() emitted to indicate a change of the
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
42 count of download items
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
45 RemoveNever = 0
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
46 RemoveExit = 1
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 RemoveSuccessFullDownload = 2
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
49 UpdateTimerTimeout = 1000
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
51 downloadsCountChanged = pyqtSignal()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
53 def __init__(self, parent=None):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param parent reference to the parent widget (QWidget)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8217
diff changeset
59 super().__init__(parent)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.setupUi(self)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7955
diff changeset
61 self.setWindowFlags(Qt.WindowType.Window)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
62
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
63 self.__winTaskbarButton = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__saveTimer = AutoSaver(self, self.save)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__model = DownloadModel(self)
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
68 self.__manager = WebBrowserWindow.networkManager()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__iconProvider = None
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__downloads = []
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__downloadDirectory = ""
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__loaded = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
75 self.__rowHeightMultiplier = 1.1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.setDownloadDirectory(Preferences.getUI("DownloadPath"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.downloadsView.setShowGrid(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.downloadsView.verticalHeader().hide()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.downloadsView.horizontalHeader().hide()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.downloadsView.setAlternatingRowColors(True)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.downloadsView.horizontalHeader().setStretchLastSection(True)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.downloadsView.setModel(self.__model)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
85 self.downloadsView.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
86 self.downloadsView.customContextMenuRequested.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87 self.__customContextMenuRequested
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
88 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
90 self.__clearShortcut = QShortcut(QKeySequence("Ctrl+L"), self)
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
91 self.__clearShortcut.activated.connect(self.on_cleanupButton_clicked)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
92
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__load()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
95 self.__updateTimer = QBasicTimer()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
96
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
97 def __customContextMenuRequested(self, pos):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
98 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
99 Private slot to handle the context menu request for the bookmarks tree.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
101 @param pos position the context menu was requested (QPoint)
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
102 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
103 menu = QMenu()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105 selectedRowsCount = len(self.downloadsView.selectionModel().selectedRows())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
107 if selectedRowsCount == 1:
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
108 row = self.downloadsView.selectionModel().selectedRows()[0].row()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
109 itm = self.__downloads[row]
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
110 if itm.downloadedSuccessfully():
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
111 menu.addAction(
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
112 EricPixmapCache.getIcon("open"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113 self.tr("Open"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
114 self.__contextMenuOpen,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115 )
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
116 elif itm.downloading():
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
117 menu.addAction(
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
118 EricPixmapCache.getIcon("stopLoading"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
119 self.tr("Cancel"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120 self.__contextMenuCancel,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
121 )
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
122 menu.addSeparator()
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
123 menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
124 self.tr("Open Containing Folder"), self.__contextMenuOpenFolder
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
125 )
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
126 menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127 menu.addAction(self.tr("Go to Download Page"), self.__contextMenuGotoPage)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
128 menu.addAction(self.tr("Copy Download Link"), self.__contextMenuCopyLink)
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
129 menu.addSeparator()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
130 menu.addAction(self.tr("Select All"), self.__contextMenuSelectAll)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131 if selectedRowsCount > 1 or (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
132 selectedRowsCount == 1
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133 and not self.__downloads[
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
134 self.downloadsView.selectionModel().selectedRows()[0].row()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135 ].downloading()
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
136 ):
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
137 menu.addSeparator()
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
138 menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
139 self.tr("Remove From List"), self.__contextMenuRemoveSelected
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
140 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
142 menu.exec(QCursor.pos())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
143
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 def shutdown(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 Public method to stop the download manager.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
148 self.save()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
151 def activeDownloadsCount(self):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 Public method to get the number of active downloads.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
154
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 @return number of active downloads (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 count = 0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 for download in self.__downloads:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 if download.downloading():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 count += 1
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 return count
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
163
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 def allowQuit(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Public method to check, if it is ok to quit.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
167
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @return flag indicating allowance to quit (boolean)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
170 if self.activeDownloadsCount() > 0:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8322
diff changeset
171 res = EricMessageBox.yesNo(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
172 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
173 self.tr(""),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
175 """There are %n downloads in progress.\n"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
176 """Do you want to quit anyway?""",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
177 "",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
178 self.activeDownloadsCount(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
179 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 icon=EricMessageBox.Warning,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if not res:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.show()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
185
6222
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
186 self.close()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
188
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
189 def __testWebBrowserView(self, view, url):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
190 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
191 Private method to test a web browser view against an URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
193 @param view reference to the web browser view to be tested
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
194 @type WebBrowserView
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
195 @param url URL to test against
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
196 @type QUrl
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
197 @return flag indicating, that the view is the one for the URL
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
198 @rtype bool
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
199 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
200 if view.tabWidget().count() < 2:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
201 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
202
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
203 page = view.page()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
204 if page.history().count() != 0:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
205 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207 if not page.url().isEmpty() and page.url().host() == url.host():
6735
31e263d49c04 Fixed some code style issues detected by the updated style checker (over-indented lines).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
208 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
209
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
210 requestedUrl = page.requestedUrl()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
211 if requestedUrl.isEmpty():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
212 requestedUrl = QUrl(view.tabWidget().urlBarForView(view).text())
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
213 return requestedUrl.isEmpty() or requestedUrl.host() == url.host()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
214
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
215 def __closeDownloadTab(self, url):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
216 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
217 Private method to close an empty tab, that was opened only for loading
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
218 the download URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
219
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
220 @param url download URL
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
221 @type QUrl
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
222 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
223 if self.__testWebBrowserView(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
224 WebBrowserWindow.getWindow().currentBrowser(), url
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
225 ):
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
226 WebBrowserWindow.getWindow().closeCurrentBrowser()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
227 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
228
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
229 for window in WebBrowserWindow.mainWindows():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
230 for browser in window.browsers():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
231 if self.__testWebBrowserView(browser, url):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
232 window.closeBrowser(browser)
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
233 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
234
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
235 def download(self, downloadRequest):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 Public method to download a file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
239 @param downloadRequest reference to the download object containing the
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
240 download data.
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
241 @type QWebEngineDownloadRequest
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
243 url = downloadRequest.url()
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
244 if url.isEmpty():
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
246
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
247 self.__closeDownloadTab(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
248
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
249 # Safe Browsing
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
250 from eric7.WebBrowser.SafeBrowsing.SafeBrowsingManager import (
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
251 SafeBrowsingManager,
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
252 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
253
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
254 if SafeBrowsingManager.isEnabled():
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
255 threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0]
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
256 if threatLists:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
257 threatMessages = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
258 WebBrowserWindow.safeBrowsingManager().getThreatMessages(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
259 threatLists
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
260 )
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
261 )
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8322
diff changeset
262 res = EricMessageBox.warning(
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
263 WebBrowserWindow.getWindow(),
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
264 self.tr("Suspicuous URL detected"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
265 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
266 "<p>The URL <b>{0}</b> was found in the Safe"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
267 " Browsing database.</p>{1}"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
268 ).format(url.toString(), "".join(threatMessages)),
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8322
diff changeset
269 EricMessageBox.Abort | EricMessageBox.Ignore,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
270 EricMessageBox.Abort,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271 )
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8322
diff changeset
272 if res == EricMessageBox.Abort:
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
273 downloadRequest.cancel()
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6091
diff changeset
274 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275
6286
2c8a751d6137 DownloadManager: fixed an issue getting the main window
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6234
diff changeset
276 window = WebBrowserWindow.getWindow()
8235
78e6d29eb773 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 3).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
277 pageUrl = window.currentBrowser().url() if window else QUrl()
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2058
diff changeset
278 from .DownloadItem import DownloadItem
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
280 itm = DownloadItem(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
281 downloadRequest=downloadRequest, pageUrl=pageUrl, parent=self
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
282 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 self.__addItem(itm)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
285 if Preferences.getWebBrowser("DownloadManagerAutoOpen"):
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
286 self.show()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
287 else:
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
288 self.__startUpdateTimer()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
289
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
290 def show(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
291 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
292 Public slot to show the download manager dialog.
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
293 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
294 self.__startUpdateTimer()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
295
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8217
diff changeset
296 super().show()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 self.activateWindow()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 self.raise_()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
299
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
300 def __addItem(self, itm, append=False):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 Private method to add a download to the list of downloads.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
303
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
304 @param itm reference to the download item
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
305 @type DownloadItem
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
306 @param append flag indicating to append the item
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
307 @type bool
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
309 itm.statusChanged.connect(lambda: self.__updateRow(itm))
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
310 itm.downloadFinished.connect(self.__finished)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
311
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
312 # insert at top of window
8235
78e6d29eb773 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 3).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
313 row = self.downloadsCount() if append else 0
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 self.__model.beginInsertRows(QModelIndex(), row, row)
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
315 if append:
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
316 self.__downloads.append(itm)
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
317 else:
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
318 self.__downloads.insert(0, itm)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 self.__model.endInsertRows()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
320
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.downloadsView.setIndexWidget(self.__model.index(row, 0), itm)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7955
diff changeset
322 icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 itm.setIcon(icon)
5928
a3809f75ca07 Changed the logic of the two web browsers in order to put new downloads at the top of the list of downloads and add the download date and time to the shown info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
324 self.downloadsView.setRowHeight(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325 row, int(itm.sizeHint().height() * self.__rowHeightMultiplier)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
326 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 # just in case the download finished before the constructor returned
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 self.__updateRow(itm)
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
329 self.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
330
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
331 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
332
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
333 def __updateRow(self, itm):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 Private slot to update a download item.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
336
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
337 @param itm reference to the download item
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
338 @type DownloadItem
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 if itm not in self.__downloads:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
342
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 row = self.__downloads.index(itm)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
344
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 if self.__iconProvider is None:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 self.__iconProvider = QFileIconProvider()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
347
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 icon = self.__iconProvider.icon(QFileInfo(itm.fileName()))
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 if icon.isNull():
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7955
diff changeset
350 icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 itm.setIcon(icon)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
352
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
353 self.downloadsView.setRowHeight(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
354 row, int(itm.minimumSizeHint().height() * self.__rowHeightMultiplier)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
355 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
356
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 remove = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
358
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
359 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
360 itm.downloadedSuccessfully()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
361 and self.removePolicy() == DownloadManager.RemoveSuccessFullDownload
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
362 ):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 remove = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
364
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 if remove:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 self.__model.removeRow(row)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
367
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 self.cleanupButton.setEnabled(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
369 (self.downloadsCount() - self.activeDownloadsCount()) > 0
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
370 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
371
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
372 # record the change
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
373 self.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
374
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 def removePolicy(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 Public method to get the remove policy.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
378
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 @return remove policy (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 """
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
381 return Preferences.getWebBrowser("DownloadManagerRemovePolicy")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
382
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 def setRemovePolicy(self, policy):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 Public method to set the remove policy.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
386
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
387 @param policy policy to be set
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
388 (DownloadManager.RemoveExit, DownloadManager.RemoveNever,
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 DownloadManager.RemoveSuccessFullDownload)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
391 if policy in (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
392 DownloadManager.RemoveExit,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
393 DownloadManager.RemoveNever,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
394 DownloadManager.RemoveSuccessFullDownload,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
395 ):
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
396
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
397 if policy == self.removePolicy():
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
398 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
399
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
400 Preferences.setWebBrowser("DownloadManagerRemovePolicy", self.policy)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
401
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 def save(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 Public method to save the download settings.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 if not self.__loaded:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
408
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
409 Preferences.setWebBrowser("DownloadManagerSize", self.size())
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
410 Preferences.setWebBrowser("DownloadManagerPosition", self.pos())
673
1c1f3a125e68 Fixed a few issues with the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 669
diff changeset
411 if self.removePolicy() == DownloadManager.RemoveExit:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
413
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
414 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
415
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4772
diff changeset
416 if WebBrowserWindow.isPrivate():
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
417 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
418
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
419 downloads = []
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
420 for download in self.__downloads:
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
421 downloads.append(download.getData())
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
422 Preferences.setWebBrowser("DownloadManagerDownloads", downloads)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
423
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 def __load(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 """
748
eb7e73107d27 Improved the SSL certificate handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 679
diff changeset
426 Private method to load the download settings.
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 if self.__loaded:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
430
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
431 size = Preferences.getWebBrowser("DownloadManagerSize")
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 if size.isValid():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 self.resize(size)
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
434 pos = Preferences.getWebBrowser("DownloadManagerPosition")
669
d405dc3e2ed6 Added code to save the position of the download manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
435 self.move(pos)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
436
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
437 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
438
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
439 if not WebBrowserWindow.isPrivate():
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
440 downloads = Preferences.getWebBrowser("DownloadManagerDownloads")
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
441 for download in downloads:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
442 if not download["URL"].isEmpty() and bool(download["Location"]):
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
443 from .DownloadItem import DownloadItem
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
444
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
445 itm = DownloadItem(parent=self)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
446 itm.setData(download)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
447 self.__addItem(itm, append=True)
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
448 self.cleanupButton.setEnabled(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
449 (self.downloadsCount() - self.activeDownloadsCount()) > 0
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
450 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
451
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 self.__loaded = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
453
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
454 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
455
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
456 def closeEvent(self, evt):
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
457 """
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
458 Protected event handler for the close event.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
459
6085
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
460 @param evt reference to the close event
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
461 @type QCloseEvent
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
462 """
7e48a0d98cce Added the capability to pause/resume download (Qt 5.10.0/PyQt 5.10.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
463 self.save()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
464
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 def cleanup(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 Public slot to cleanup the downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 self.on_cleanupButton_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
470
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 @pyqtSlot()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 def on_cleanupButton_clicked(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 """
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
474 Private slot to cleanup the downloads.
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 """
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
476 if self.downloadsCount() == 0:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
478
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
479 self.__model.removeRows(0, self.downloadsCount())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
480 if self.downloadsCount() == 0 and self.__iconProvider is not None:
826
2e3e2055e715 Fixed a few PEP 8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 757
diff changeset
481 self.__iconProvider = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
482
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
483 self.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
484
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
485 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
486
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
487 def __finished(self, success):
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
488 """
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
489 Private slot to handle a finished download.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
490
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
491 @param success flag indicating a successful download
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
492 @type bool
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
493 """
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
494 if self.isVisible():
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
495 QApplication.alert(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
496
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
497 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
498
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
499 if self.activeDownloadsCount() == 0:
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
500 # all active downloads are done
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8322
diff changeset
501 if success and ericApp().activeWindow() is not self:
7955
567f2ec958c3 Changed code to always use the reworked notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
502 WebBrowserWindow.showNotification(
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
503 EricPixmapCache.getPixmap("downloads48"),
7955
567f2ec958c3 Changed code to always use the reworked notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
504 self.tr("Downloads finished"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
505 self.tr("All files have been downloaded."),
7955
567f2ec958c3 Changed code to always use the reworked notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
506 )
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
507 if not Preferences.getWebBrowser("DownloadManagerAutoClose"):
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
508 self.raise_()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
509 self.activateWindow()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
510
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
511 self.__stopUpdateTimer()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
512 self.infoLabel.clear()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
513 self.setWindowTitle(self.tr("Download Manager"))
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
514 if Globals.isWindowsPlatform():
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
515 self.__taskbarButton().progress().hide()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
516
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
517 if Preferences.getWebBrowser("DownloadManagerAutoClose"):
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
518 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
519
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 def setDownloadDirectory(self, directory):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 Public method to set the current download directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
523
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 @param directory current download directory (string)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 self.__downloadDirectory = directory
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 if self.__downloadDirectory != "":
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 self.__downloadDirectory += "/"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
529
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 def downloadDirectory(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532 Public method to get the current download directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
533
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 @return current download directory (string)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
536 return self.__downloadDirectory
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
537
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
538 def downloadsCount(self):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 Public method to get the number of downloads.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
541
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
542 @return number of downloads
6153
0b18c86c03a1 Updated source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
543 @rtype int
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 return len(self.__downloads)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
546
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 def downloads(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
548 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 Public method to get a reference to the downloads.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
550
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 @return reference to the downloads (list of DownloadItem)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 return self.__downloads
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
554
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 def changeOccurred(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 Public method to signal a change.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 self.__saveTimer.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
560
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
561 def __taskbarButton(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
562 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
563 Private method to get a reference to the task bar button (Windows
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
564 only).
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
565
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
566 @return reference to the task bar button
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
567 @rtype QWinTaskbarButton or None
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
568 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
569 if Globals.isWindowsPlatform():
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
570 from PyQt6.QtWinExtras import QWinTaskbarButton
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
571
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
572 if self.__winTaskbarButton is None:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
573 window = WebBrowserWindow.mainWindow()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
574 self.__winTaskbarButton = QWinTaskbarButton(window.windowHandle())
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
575 self.__winTaskbarButton.progress().setRange(0, 100)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
576
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
577 return self.__winTaskbarButton
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
578
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
579 def timerEvent(self, evt):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
580 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
581 Protected event handler for timer events.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
582
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
583 @param evt reference to the timer event
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
584 @type QTimerEvent
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
585 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
586 if evt.timerId() == self.__updateTimer.timerId():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
587 if self.activeDownloadsCount() == 0:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
588 self.__stopUpdateTimer()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
589 self.infoLabel.clear()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
590 self.setWindowTitle(self.tr("Download Manager"))
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
591 if Globals.isWindowsPlatform():
6222
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
592 self.__taskbarButton().progress().hide()
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
593 else:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
594 progresses = []
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
595 for itm in self.__downloads:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
596 if itm is None or itm.downloadCanceled() or not itm.downloading():
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
597 continue
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
598
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
599 progresses.append(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
600 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
601 itm.downloadProgress(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
602 itm.remainingTime(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
603 itm.currentSpeed(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
604 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
605 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
606
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
607 if not progresses:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
608 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
609
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
610 remaining = 0
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
611 progress = 0
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
612 speed = 0.0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
613
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
614 for progressData in progresses:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
615 if progressData[1] > remaining:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
616 remaining = progressData[1]
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
617 progress += progressData[0]
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
618 speed += progressData[2]
8217
385f60c94548 Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
619 progress /= len(progresses)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
620
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
621 if self.isVisible():
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
622 self.infoLabel.setText(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
623 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
624 "{0}% of %n file(s) ({1}) {2}", "", len(progresses)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
625 ).format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
626 progress,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
627 speedString(speed),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
628 timeString(remaining),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
629 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
630 )
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
631 self.setWindowTitle(self.tr("{0}% - Download Manager"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
632
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
633 if Globals.isWindowsPlatform():
6222
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
634 self.__taskbarButton().progress().show()
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
635 self.__taskbarButton().progress().setValue(progress)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
636
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8217
diff changeset
637 super().timerEvent(evt)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
638
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
639 def __startUpdateTimer(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
640 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
641 Private slot to start the update timer.
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
642 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
643 if self.activeDownloadsCount() and not self.__updateTimer.isActive():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
644 self.__updateTimer.start(DownloadManager.UpdateTimerTimeout, self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
645
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
646 def __stopUpdateTimer(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
647 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
648 Private slot to stop the update timer.
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
649 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
650 self.__updateTimer.stop()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
651
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
652 ###########################################################################
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
653 ## Context menu related methods below
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
654 ###########################################################################
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
655
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
656 def __currentItem(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
657 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
658 Private method to get a reference to the current item.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
659
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
660 @return reference to the current item (DownloadItem)
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
661 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
662 index = self.downloadsView.currentIndex()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
663 if index and index.isValid():
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
664 row = index.row()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
665 return self.__downloads[row]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
666
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
667 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
668
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
669 def __contextMenuOpen(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
670 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
671 Private method to open the downloaded file.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
672 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
673 itm = self.__currentItem()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
674 if itm is not None:
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
675 itm.openFile()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
676
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
677 def __contextMenuOpenFolder(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
678 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
679 Private method to open the folder containing the downloaded file.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
680 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
681 itm = self.__currentItem()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
682 if itm is not None:
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
683 itm.openFolder()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
684
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
685 def __contextMenuCancel(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
686 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
687 Private method to cancel the current download.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
688 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
689 itm = self.__currentItem()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
690 if itm is not None:
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
691 itm.cancelDownload()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
692
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
693 def __contextMenuGotoPage(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
694 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
695 Private method to open the download page.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
696 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
697 itm = self.__currentItem()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
698 if itm is not None:
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
699 url = itm.getPageUrl()
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
700 WebBrowserWindow.mainWindow().openUrl(url, "")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
701
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
702 def __contextMenuCopyLink(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
703 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
704 Private method to copy the download link to the clipboard.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
705 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
706 itm = self.__currentItem()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
707 if itm is not None:
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7955
diff changeset
708 url = itm.getPageUrl().toDisplayString(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
709 QUrl.ComponentFormattingOption.FullyDecoded
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
710 )
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
711 QApplication.clipboard().setText(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
712
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
713 def __contextMenuSelectAll(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
714 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
715 Private method to select all downloads.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
716 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
717 self.downloadsView.selectAll()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
718
679
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
719 def __contextMenuRemoveSelected(self):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
720 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
721 Private method to remove the selected downloads from the list.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
722 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
723 self.downloadsView.removeSelected()

eric ide

mercurial