src/eric7/WebBrowser/Download/DownloadManager.py

Wed, 13 Jul 2022 14:55:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 13 Jul 2022 14:55:47 +0200
branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
permissions
-rw-r--r--

Reformatted the source code using the 'Black' utility.

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
8358
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
22 from EricWidgets import EricMessageBox
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
23 from 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
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
30 from WebBrowser.WebBrowserWindow import WebBrowserWindow
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 from Utilities.AutoSaver import AutoSaver
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
33 import UI.PixmapCache
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 import Preferences
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
35 import Globals
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
37
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 class DownloadManager(QDialog, Ui_DownloadManager):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
40 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
41
6149
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6134
diff changeset
42 @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
43 count of download items
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
46 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
47 RemoveExit = 1
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 RemoveSuccessFullDownload = 2
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
50 UpdateTimerTimeout = 1000
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
52 downloadsCountChanged = pyqtSignal()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
54 def __init__(self, parent=None):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @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
59 """
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
60 super().__init__(parent)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 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
62 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
63
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
64 self.__winTaskbarButton = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 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
67
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.__model = DownloadModel(self)
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
69 self.__manager = WebBrowserWindow.networkManager()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__iconProvider = None
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__downloads = []
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__downloadDirectory = ""
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.__loaded = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
75
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
76 self.__rowHeightMultiplier = 1.1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 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
79
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.downloadsView.setShowGrid(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.downloadsView.verticalHeader().hide()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.downloadsView.horizontalHeader().hide()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.downloadsView.setAlternatingRowColors(True)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.downloadsView.horizontalHeader().setStretchLastSection(True)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 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
86 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
87 self.downloadsView.customContextMenuRequested.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
88 self.__customContextMenuRequested
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
90
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
91 self.__clearShortcut = QShortcut(QKeySequence("Ctrl+L"), self)
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
92 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
93
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.__load()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
95
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
96 self.__updateTimer = QBasicTimer()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97
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
98 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
99 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
100 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
101
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
102 @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
103 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
104 menu = QMenu()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106 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
107
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
108 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
109 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
110 itm = self.__downloads[row]
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
111 if itm.downloadedSuccessfully():
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
112 menu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
113 UI.PixmapCache.getIcon("open"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
114 self.tr("Open"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115 self.__contextMenuOpen,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116 )
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
117 elif itm.downloading():
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
118 menu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
119 UI.PixmapCache.getIcon("stopLoading"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120 self.tr("Cancel"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
121 self.__contextMenuCancel,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
122 )
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
123 menu.addSeparator()
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
124 menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
125 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
126 )
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
127 menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
128 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
129 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
130 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
131 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
132 if selectedRowsCount > 1 or (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133 selectedRowsCount == 1
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
134 and not self.__downloads[
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135 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
136 ].downloading()
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
137 ):
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
138 menu.addSeparator()
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
139 menu.addAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
140 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
141 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
142
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
143 menu.exec(QCursor.pos())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 def shutdown(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 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
148 """
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
149 self.save()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
151
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
152 def activeDownloadsCount(self):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @return number of active downloads (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 count = 0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
159
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 for download in self.__downloads:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 if download.downloading():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 count += 1
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 return count
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 def allowQuit(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 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
168
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 @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
170 """
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
171 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
172 res = EricMessageBox.yesNo(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
173 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
174 self.tr(""),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
175 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
176 """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
177 """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
178 "",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
179 self.activeDownloadsCount(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181 icon=EricMessageBox.Warning,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
182 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 if not res:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 self.show()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
186
6222
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
187 self.close()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
189
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
190 def __testWebBrowserView(self, view, url):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
191 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
192 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
193
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
194 @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
195 @type WebBrowserView
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
196 @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
197 @type QUrl
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
198 @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
199 @rtype bool
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
200 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
201 if view.tabWidget().count() < 2:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
202 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
203
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
204 page = view.page()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
205 if page.history().count() != 0:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
206 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
208 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
209 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
210
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
211 requestedUrl = page.requestedUrl()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
212 if requestedUrl.isEmpty():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
213 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
214 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
215
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
216 def __closeDownloadTab(self, url):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
217 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
218 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
219 the download URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
221 @param url download URL
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
222 @type QUrl
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
223 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
224 if self.__testWebBrowserView(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
225 WebBrowserWindow.getWindow().currentBrowser(), url
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226 ):
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
227 WebBrowserWindow.getWindow().closeCurrentBrowser()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
228 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
229
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
230 for window in WebBrowserWindow.mainWindows():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
231 for browser in window.browsers():
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
232 if self.__testWebBrowserView(browser, url):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
233 window.closeBrowser(browser)
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
234 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
235
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
236 def download(self, downloadRequest):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 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
239
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
240 @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
241 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
242 @type QWebEngineDownloadRequest
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
8556
766e1566cb74 Next batch of changes for QtWebEngine as of Qt 6.2.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
244 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
245 if url.isEmpty():
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
247
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
248 self.__closeDownloadTab(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
249
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
250 # Safe Browsing
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
251 from WebBrowser.SafeBrowsing.SafeBrowsingManager import SafeBrowsingManager
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252
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
253 if SafeBrowsingManager.isEnabled():
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
254 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
255 if threatLists:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
256 threatMessages = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
257 WebBrowserWindow.safeBrowsingManager().getThreatMessages(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
258 threatLists
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
259 )
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
260 )
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
261 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
262 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
263 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
264 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
265 "<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
266 " Browsing database.</p>{1}"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
267 ).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
268 EricMessageBox.Abort | EricMessageBox.Ignore,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
269 EricMessageBox.Abort,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
270 )
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
271 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
272 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
273 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274
6286
2c8a751d6137 DownloadManager: fixed an issue getting the main window
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6234
diff changeset
275 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
276 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
277 from .DownloadItem import DownloadItem
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
278
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279 itm = DownloadItem(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
280 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
281 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 self.__addItem(itm)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
283
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
284 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
285 self.show()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
286 else:
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
287 self.__startUpdateTimer()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
288
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
289 def show(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
290 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
291 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
292 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
293 self.__startUpdateTimer()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294
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
295 super().show()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 self.activateWindow()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 self.raise_()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
298
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
299 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
300 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 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
302
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
303 @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
304 @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
305 @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
306 @type bool
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 """
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
308 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
309 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
310
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
311 # 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
312 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
313 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
314 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
315 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
316 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
317 self.__downloads.insert(0, itm)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 self.__model.endInsertRows()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
319
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 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
321 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
322 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
323 self.downloadsView.setRowHeight(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
324 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
325 )
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 # 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
327 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
328 self.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
329
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
330 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
331
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
332 def __updateRow(self, itm):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 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
335
6118
da9e08920e7c Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
336 @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
337 @type DownloadItem
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 if itm not in self.__downloads:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
341
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 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
343
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 if self.__iconProvider is None:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 self.__iconProvider = QFileIconProvider()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
346
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 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
348 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
349 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
350 itm.setIcon(icon)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
351
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
352 self.downloadsView.setRowHeight(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
353 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
354 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
355
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 remove = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
357
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
358 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
359 itm.downloadedSuccessfully()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
360 and self.removePolicy() == DownloadManager.RemoveSuccessFullDownload
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
361 ):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 remove = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
363
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 if remove:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 self.__model.removeRow(row)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
366
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 self.cleanupButton.setEnabled(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
368 (self.downloadsCount() - self.activeDownloadsCount()) > 0
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
369 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
370
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
371 # 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
372 self.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
373
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 def removePolicy(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 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
377
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 @return remove policy (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
380 return Preferences.getWebBrowser("DownloadManagerRemovePolicy")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
381
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 def setRemovePolicy(self, policy):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 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
385
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
386 @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
387 (DownloadManager.RemoveExit, DownloadManager.RemoveNever,
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 DownloadManager.RemoveSuccessFullDownload)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
390 if policy in (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
391 DownloadManager.RemoveExit,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
392 DownloadManager.RemoveNever,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
393 DownloadManager.RemoveSuccessFullDownload,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
394 ):
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
395
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
396 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
397 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
398
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
399 Preferences.setWebBrowser("DownloadManagerRemovePolicy", self.policy)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
400
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 def save(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 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
404 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 if not self.__loaded:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
407
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
408 Preferences.setWebBrowser("DownloadManagerSize", self.size())
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
409 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
410 if self.removePolicy() == DownloadManager.RemoveExit:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
412
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
413 from WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
414
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4772
diff changeset
415 if WebBrowserWindow.isPrivate():
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
416 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
417
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
418 downloads = []
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
419 for download in self.__downloads:
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
420 downloads.append(download.getData())
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
421 Preferences.setWebBrowser("DownloadManagerDownloads", downloads)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
422
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 def __load(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 """
748
eb7e73107d27 Improved the SSL certificate handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 679
diff changeset
425 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
426 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 if self.__loaded:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
429
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
430 size = Preferences.getWebBrowser("DownloadManagerSize")
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 if size.isValid():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 self.resize(size)
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
433 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
434 self.move(pos)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
435
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
436 from WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
437
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
438 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
439 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
440 for download in downloads:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
441 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
442 from .DownloadItem import DownloadItem
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
443
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
444 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
445 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
446 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
447 self.cleanupButton.setEnabled(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
448 (self.downloadsCount() - self.activeDownloadsCount()) > 0
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
449 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
450
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 self.__loaded = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
452
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
453 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
454
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
455 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
456 """
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 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
458
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
459 @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
460 @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
461 """
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 self.save()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
463
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 def cleanup(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 Public slot to cleanup the downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 self.on_cleanupButton_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
469
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 @pyqtSlot()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 def on_cleanupButton_clicked(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 """
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
473 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
474 """
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
475 if self.downloadsCount() == 0:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
477
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
478 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
479 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
480 self.__iconProvider = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
481
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
482 self.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
483
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
484 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
485
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
486 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
487 """
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 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
489
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
490 @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
491 @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
492 """
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 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
494 QApplication.alert(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
495
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
496 self.downloadsCountChanged.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
497
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
498 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
499 # 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
500 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
501 WebBrowserWindow.showNotification(
567f2ec958c3 Changed code to always use the reworked notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
502 UI.PixmapCache.getPixmap("downloads48"),
567f2ec958c3 Changed code to always use the reworked notification system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
503 self.tr("Downloads finished"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
504 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
505 )
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
506 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
507 self.raise_()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
508 self.activateWindow()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
509
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
510 self.__stopUpdateTimer()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
511 self.infoLabel.clear()
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
512 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
513 if Globals.isWindowsPlatform():
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
514 self.__taskbarButton().progress().hide()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
515
6224
08875555771a Web Browser (NG): some more improvements of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6222
diff changeset
516 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
517 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
518
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519 def setDownloadDirectory(self, directory):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 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
522
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 @param directory current download directory (string)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525 self.__downloadDirectory = directory
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 if self.__downloadDirectory != "":
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 self.__downloadDirectory += "/"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
528
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 def downloadDirectory(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 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
532
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
533 @return current download directory (string)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 return self.__downloadDirectory
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
536
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
537 def downloadsCount(self):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 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
540
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6118
diff changeset
541 @return number of downloads
6153
0b18c86c03a1 Updated source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
542 @rtype int
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 return len(self.__downloads)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
545
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 def downloads(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
548 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
549
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550 @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
551 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 return self.__downloads
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
553
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 def changeOccurred(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 Public method to signal a change.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 self.__saveTimer.changeOccurred()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
559
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
560 def __taskbarButton(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
561 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
562 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
563 only).
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
564
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
565 @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
566 @rtype QWinTaskbarButton or None
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
567 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
568 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
569 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
570
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
571 if self.__winTaskbarButton is None:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
572 window = WebBrowserWindow.mainWindow()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
573 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
574 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
575
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
576 return self.__winTaskbarButton
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
577
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
578 def timerEvent(self, evt):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
579 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
580 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
581
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
582 @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
583 @type QTimerEvent
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
584 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
585 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
586 if self.activeDownloadsCount() == 0:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
587 self.__stopUpdateTimer()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
588 self.infoLabel.clear()
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
589 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
590 if Globals.isWindowsPlatform():
6222
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
591 self.__taskbarButton().progress().hide()
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
592 else:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
593 progresses = []
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
594 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
595 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
596 continue
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
597
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
598 progresses.append(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
599 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
600 itm.downloadProgress(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
601 itm.remainingTime(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
602 itm.currentSpeed(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
603 )
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
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
606 if not progresses:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
607 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
608
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
609 remaining = 0
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
610 progress = 0
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
611 speed = 0.0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
612
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
613 for progressData in progresses:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
614 if progressData[1] > remaining:
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
615 remaining = progressData[1]
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
616 progress += progressData[0]
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
617 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
618 progress /= len(progresses)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
619
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
620 if self.isVisible():
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
621 self.infoLabel.setText(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
622 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
623 "{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
624 ).format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
625 progress,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
626 speedString(speed),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
627 timeString(remaining),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
628 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
629 )
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
630 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
631
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
632 if Globals.isWindowsPlatform():
6222
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
633 self.__taskbarButton().progress().show()
baffb22b4467 DownloadManager: Fixed issues in the Windows related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6221
diff changeset
634 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
635
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
636 super().timerEvent(evt)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
637
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
638 def __startUpdateTimer(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
639 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
640 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
641 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
642 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
643 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
644
6221
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
645 def __stopUpdateTimer(self):
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
646 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
647 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
648 """
35ec993034e1 Web Browser (NG): improvement of the download manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6153
diff changeset
649 self.__updateTimer.stop()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
650
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
651 ###########################################################################
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
652 ## 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
653 ###########################################################################
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
654
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
655 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
656 """
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 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
658
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
659 @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
660 """
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 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
662 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
663 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
664 return self.__downloads[row]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
665
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
666 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
667
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
668 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
669 """
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 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
671 """
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 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
673 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
674 itm.openFile()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
675
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
676 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
677 """
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 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
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
680 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
681 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
682 itm.openFolder()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
683
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
684 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
685 """
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 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
687 """
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 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
689 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
690 itm.cancelDownload()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
691
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
692 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
693 """
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 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
695 """
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 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
697 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
698 url = itm.getPageUrl()
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
699 WebBrowserWindow.mainWindow().openUrl(url, "")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
700
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
701 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
702 """
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 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
704 """
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 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
706 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
707 url = itm.getPageUrl().toDisplayString(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
708 QUrl.ComponentFormattingOption.FullyDecoded
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
709 )
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
710 QApplication.clipboard().setText(url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
711
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
712 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
713 """
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 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
715 """
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 self.downloadsView.selectAll()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
717
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
718 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
719 """
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 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
721 """
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 self.downloadsView.removeSelected()

eric ide

mercurial