6 """ |
6 """ |
7 Module implementing the download manager class. |
7 Module implementing the download manager class. |
8 """ |
8 """ |
9 |
9 |
10 |
10 |
11 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QModelIndex, QFileInfo, \ |
11 from PyQt5.QtCore import ( |
12 QUrl, QBasicTimer |
12 pyqtSlot, pyqtSignal, Qt, QModelIndex, QFileInfo, QUrl, QBasicTimer |
|
13 ) |
13 from PyQt5.QtGui import QCursor, QKeySequence |
14 from PyQt5.QtGui import QCursor, QKeySequence |
14 from PyQt5.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, \ |
15 from PyQt5.QtWidgets import ( |
15 QApplication, QShortcut |
16 QDialog, QStyle, QFileIconProvider, QMenu, QApplication, QShortcut |
|
17 ) |
16 |
18 |
17 from E5Gui import E5MessageBox |
19 from E5Gui import E5MessageBox |
18 from E5Gui.E5Application import e5App |
20 from E5Gui.E5Application import e5App |
19 |
21 |
20 from .Ui_DownloadManager import Ui_DownloadManager |
22 from .Ui_DownloadManager import Ui_DownloadManager |
121 menu.addAction( |
123 menu.addAction( |
122 self.tr("Copy Download Link"), |
124 self.tr("Copy Download Link"), |
123 self.__contextMenuCopyLink) |
125 self.__contextMenuCopyLink) |
124 menu.addSeparator() |
126 menu.addSeparator() |
125 menu.addAction(self.tr("Select All"), self.__contextMenuSelectAll) |
127 menu.addAction(self.tr("Select All"), self.__contextMenuSelectAll) |
126 if selectedRowsCount > 1 or \ |
128 if ( |
127 (selectedRowsCount == 1 and |
129 selectedRowsCount > 1 or |
128 not self.__downloads[ |
130 (selectedRowsCount == 1 and |
|
131 not self.__downloads[ |
129 self.downloadsView.selectionModel().selectedRows()[0].row()] |
132 self.downloadsView.selectionModel().selectedRows()[0].row()] |
130 .downloading()): |
133 .downloading()) |
|
134 ): |
131 menu.addSeparator() |
135 menu.addSeparator() |
132 menu.addAction( |
136 menu.addAction( |
133 self.tr("Remove From List"), |
137 self.tr("Remove From List"), |
134 self.__contextMenuRemoveSelected) |
138 self.__contextMenuRemoveSelected) |
135 |
139 |
192 |
196 |
193 page = view.page() |
197 page = view.page() |
194 if page.history().count() != 0: |
198 if page.history().count() != 0: |
195 return False |
199 return False |
196 |
200 |
197 if not page.url().isEmpty() and \ |
201 if ( |
198 page.url().host() == url.host(): |
202 not page.url().isEmpty() and |
|
203 page.url().host() == url.host() |
|
204 ): |
199 return True |
205 return True |
200 |
206 |
201 requestedUrl = page.requestedUrl() |
207 requestedUrl = page.requestedUrl() |
202 if requestedUrl.isEmpty(): |
208 if requestedUrl.isEmpty(): |
203 requestedUrl = QUrl(view.tabWidget().urlBarForView(view).text()) |
209 requestedUrl = QUrl(view.tabWidget().urlBarForView(view).text()) |
235 return |
241 return |
236 |
242 |
237 self.__closeDownloadTab(url) |
243 self.__closeDownloadTab(url) |
238 |
244 |
239 # Safe Browsing |
245 # Safe Browsing |
240 from WebBrowser.SafeBrowsing.SafeBrowsingManager import \ |
246 from WebBrowser.SafeBrowsing.SafeBrowsingManager import ( |
241 SafeBrowsingManager |
247 SafeBrowsingManager |
|
248 ) |
242 if SafeBrowsingManager.isEnabled(): |
249 if SafeBrowsingManager.isEnabled(): |
243 threatLists = \ |
250 threatLists = ( |
244 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0] |
251 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0] |
|
252 ) |
245 if threatLists: |
253 if threatLists: |
246 threatMessages = WebBrowserWindow.safeBrowsingManager()\ |
254 threatMessages = ( |
|
255 WebBrowserWindow.safeBrowsingManager() |
247 .getThreatMessages(threatLists) |
256 .getThreatMessages(threatLists) |
|
257 ) |
248 res = E5MessageBox.warning( |
258 res = E5MessageBox.warning( |
249 WebBrowserWindow.getWindow(), |
259 WebBrowserWindow.getWindow(), |
250 self.tr("Suspicuous URL detected"), |
260 self.tr("Suspicuous URL detected"), |
251 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
261 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
252 " Browsing database.</p>{1}").format( |
262 " Browsing database.</p>{1}").format( |
419 |
431 |
420 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
432 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
421 if not WebBrowserWindow.isPrivate(): |
433 if not WebBrowserWindow.isPrivate(): |
422 downloads = Preferences.getWebBrowser("DownloadManagerDownloads") |
434 downloads = Preferences.getWebBrowser("DownloadManagerDownloads") |
423 for download in downloads: |
435 for download in downloads: |
424 if not download["URL"].isEmpty() and \ |
436 if ( |
425 bool(download["Location"]): |
437 not download["URL"].isEmpty() and |
|
438 bool(download["Location"]) |
|
439 ): |
426 from .DownloadItem import DownloadItem |
440 from .DownloadItem import DownloadItem |
427 itm = DownloadItem(parent=self) |
441 itm = DownloadItem(parent=self) |
428 itm.setData(download) |
442 itm.setData(download) |
429 self.__addItem(itm, append=True) |
443 self.__addItem(itm, append=True) |
430 self.cleanupButton.setEnabled( |
444 self.cleanupButton.setEnabled( |
456 """ |
470 """ |
457 if self.downloadsCount() == 0: |
471 if self.downloadsCount() == 0: |
458 return |
472 return |
459 |
473 |
460 self.__model.removeRows(0, self.downloadsCount()) |
474 self.__model.removeRows(0, self.downloadsCount()) |
461 if self.downloadsCount() == 0 and \ |
475 if ( |
462 self.__iconProvider is not None: |
476 self.downloadsCount() == 0 and |
|
477 self.__iconProvider is not None |
|
478 ): |
463 self.__iconProvider = None |
479 self.__iconProvider = None |
464 |
480 |
465 self.changeOccurred() |
481 self.changeOccurred() |
466 |
482 |
467 self.downloadsCountChanged.emit() |
483 self.downloadsCountChanged.emit() |
574 if Globals.isWindowsPlatform(): |
590 if Globals.isWindowsPlatform(): |
575 self.__taskbarButton().progress().hide() |
591 self.__taskbarButton().progress().hide() |
576 else: |
592 else: |
577 progresses = [] |
593 progresses = [] |
578 for itm in self.__downloads: |
594 for itm in self.__downloads: |
579 if itm is None or \ |
595 if ( |
580 itm.downloadCanceled() or \ |
596 itm is None or |
581 not itm.downloading(): |
597 itm.downloadCanceled() or |
|
598 not itm.downloading() |
|
599 ): |
582 continue |
600 continue |
583 |
601 |
584 progresses.append(( |
602 progresses.append(( |
585 itm.downloadProgress(), |
603 itm.downloadProgress(), |
586 itm.remainingTime(), |
604 itm.remainingTime(), |