WebBrowser/Download/DownloadManager.py

Tue, 24 Oct 2017 19:09:09 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 24 Oct 2017 19:09:09 +0200
changeset 5928
a3809f75ca07
parent 5829
d3448873ced3
child 6048
82ad8ec9548c
permissions
-rw-r--r--

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.

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
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
3 # Copyright (c) 2010 - 2017 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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
12 from PyQt5.QtCore import pyqtSlot, Qt, QModelIndex, QFileInfo, QUrl
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
13 from PyQt5.QtGui import QCursor, QKeySequence
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 from PyQt5.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, \
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
15 QApplication, QShortcut
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .Ui_DownloadManager import Ui_DownloadManager
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from .DownloadModel import DownloadModel
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
23 from WebBrowser.WebBrowserWindow import WebBrowserWindow
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 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
26 import UI.PixmapCache
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import Preferences
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
29
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 class DownloadManager(QDialog, Ui_DownloadManager):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
32 Class implementing the download manager.
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
34 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
35 RemoveExit = 1
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 RemoveSuccessFullDownload = 2
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
38 def __init__(self, parent=None):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Constructor
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @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
43 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
44 super(DownloadManager, self).__init__(parent)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setupUi(self)
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
46 self.setWindowFlags(Qt.Window)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__saveTimer = AutoSaver(self, self.save)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.__model = DownloadModel(self)
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
51 self.__manager = WebBrowserWindow.networkManager()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__iconProvider = None
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__downloads = []
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__downloadDirectory = ""
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__loaded = False
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
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
58 self.__rowHeightMultiplier = 1.1
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
59
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.setDownloadDirectory(Preferences.getUI("DownloadPath"))
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.downloadsView.setShowGrid(False)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.downloadsView.verticalHeader().hide()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.downloadsView.horizontalHeader().hide()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.downloadsView.setAlternatingRowColors(True)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.downloadsView.horizontalHeader().setStretchLastSection(True)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.downloadsView.setModel(self.__model)
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
68 self.downloadsView.setContextMenuPolicy(Qt.CustomContextMenu)
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
69 self.downloadsView.customContextMenuRequested.connect(
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
70 self.__customContextMenuRequested)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
72 self.__clearShortcut = QShortcut(QKeySequence("Ctrl+L"), self)
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
73 self.__clearShortcut.activated.connect(self.on_cleanupButton_clicked)
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
74
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__load()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
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
77 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
78 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
79 Private slot to handle the context menu request for the bookmarks tree.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
80
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
81 @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
82 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
83 menu = QMenu()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
84
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
85 selectedRowsCount = len(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
86 self.downloadsView.selectionModel().selectedRows())
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
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
88 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
89 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
90 itm = self.__downloads[row]
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
91 if itm.downloadedSuccessfully():
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
92 menu.addAction(
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
93 UI.PixmapCache.getIcon("open.png"),
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
94 self.tr("Open"), self.__contextMenuOpen)
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
95 elif itm.downloading():
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
96 menu.addAction(
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
97 UI.PixmapCache.getIcon("stopLoading.png"),
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
98 self.tr("Cancel"), self.__contextMenuCancel)
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
99 menu.addSeparator()
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
100 menu.addAction(
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
101 self.tr("Open Containing Folder"),
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4788
diff changeset
102 self.__contextMenuOpenFolder)
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
103 menu.addSeparator()
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
104 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
105 self.tr("Go to Download Page"),
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
106 self.__contextMenuGotoPage)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
107 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
108 self.tr("Copy Download Link"),
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
109 self.__contextMenuCopyLink)
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 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
111 menu.addAction(self.tr("Select All"), self.__contextMenuSelectAll)
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
112 if selectedRowsCount > 1 or \
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
113 (selectedRowsCount == 1 and
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
114 not self.__downloads[
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
115 self.downloadsView.selectionModel().selectedRows()[0].row()]
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
116 .downloading()):
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
117 menu.addSeparator()
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
118 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
119 self.tr("Remove From List"),
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
120 self.__contextMenuRemoveSelected)
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
121
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
122 menu.exec_(QCursor.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
123
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 def shutdown(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 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
127 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.__saveTimer.changeOccurred()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.__saveTimer.saveIfNeccessary()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.close()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 def activeDownloads(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 Public method to get the number of active downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @return number of active downloads (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 count = 0
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 for download in self.__downloads:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 if download.downloading():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 count += 1
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 return count
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 def allowQuit(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 check, if it is ok to quit.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 @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
150 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if self.activeDownloads() > 0:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
152 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
153 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
154 self.tr(""),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
155 self.tr("""There are %n downloads in progress.\n"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
156 """Do you want to quit anyway?""", "",
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
157 self.activeDownloads()),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
158 icon=E5MessageBox.Warning)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 if not res:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.show()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 return False
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 return True
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
164 def download(self, downloadItem):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Public method to download a file.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
168 @param downloadItem reference to the download object containing the
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
169 download data.
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
170 @type QWebEngineDownloadItem
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
172 url = downloadItem.url()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
173 if url.isEmpty():
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
176 # Safe Browsing
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
177 threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
178 if threatLists:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
179 threatMessages = WebBrowserWindow.safeBrowsingManager()\
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
180 .getThreatMessages(threatLists)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
181 res = E5MessageBox.warning(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
182 WebBrowserWindow.getWindow(),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
183 self.tr("Suspicuous URL detected"),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
184 self.tr("<p>The URL <b>{0}</b> was found in the Safe Browsing"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
185 " database.</p>{1}").format(url.toString(),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
186 "".join(threatMessages)),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
187 E5MessageBox.StandardButtons(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
188 E5MessageBox.Abort |
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
189 E5MessageBox.Ignore),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
190 E5MessageBox.Abort)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
191 if res == E5MessageBox.Abort:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
192 downloadItem.cancel()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
193 return
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
194
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2058
diff changeset
195 from .DownloadItem import DownloadItem
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
196 itm = DownloadItem(downloadItem, parent=self)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.__addItem(itm)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 if itm.canceledFileSelect():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 if not self.isVisible():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 self.show()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 self.activateWindow()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.raise_()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207
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
208 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
209 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 Private method to add a download to the list of downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211
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
212 @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
213 @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
214 @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
215 @type bool
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 itm.statusChanged.connect(self.__updateRow)
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
218 itm.downloadFinished.connect(self.__finished)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
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
220 # insert at top of window
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
221 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
222 row = len(self.__downloads)
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
223 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
224 row = 0
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 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
226 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
227 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
228 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
229 self.__downloads.insert(0, itm)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 self.__model.endInsertRows()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 self.downloadsView.setIndexWidget(self.__model.index(row, 0), itm)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 icon = self.style().standardIcon(QStyle.SP_FileIcon)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 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
235 self.downloadsView.setRowHeight(
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
236 row, itm.sizeHint().height() * self.__rowHeightMultiplier)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 # 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
238 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
239 self.changeOccurred()
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
240 self.__updateActiveItemCount()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
242 def __updateRow(self, itm=None):
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 Private slot to update a download item.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 @param itm reference to the download item (DownloadItem)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 if itm is None:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 itm = self.sender()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 if itm not in self.__downloads:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 row = self.__downloads.index(itm)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 if self.__iconProvider is None:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 self.__iconProvider = QFileIconProvider()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 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
260 if icon.isNull():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 icon = self.style().standardIcon(QStyle.SP_FileIcon)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 itm.setIcon(icon)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
264 self.downloadsView.setRowHeight(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
265 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
266 itm.minimumSizeHint().height() * self.__rowHeightMultiplier)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 remove = False
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 if itm.downloadedSuccessfully() and \
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 self.removePolicy() == DownloadManager.RemoveSuccessFullDownload:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 remove = True
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 if remove:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 self.__model.removeRow(row)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 self.cleanupButton.setEnabled(
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 (len(self.__downloads) - self.activeDownloads()) > 0)
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
279
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
280 # 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
281 self.changeOccurred()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 def removePolicy(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 Public method to get the remove policy.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 @return remove policy (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 """
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
289 return Preferences.getWebBrowser("DownloadManagerRemovePolicy")
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 def setRemovePolicy(self, policy):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 Public method to set the remove policy.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
295 @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
296 (DownloadManager.RemoveExit, DownloadManager.RemoveNever,
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 DownloadManager.RemoveSuccessFullDownload)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
299 assert policy in (DownloadManager.RemoveExit,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
300 DownloadManager.RemoveNever,
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 DownloadManager.RemoveSuccessFullDownload)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
673
1c1f3a125e68 Fixed a few issues with the download manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 669
diff changeset
303 if policy == self.removePolicy():
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305
4769
2b6f7e026cdc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
306 Preferences.setWebBrowser("DownloadManagerRemovePolicy", self.policy)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 def save(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 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
311 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 if not self.__loaded:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
315 Preferences.setWebBrowser("DownloadManagerSize", self.size())
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
316 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
317 if self.removePolicy() == DownloadManager.RemoveExit:
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
320 from WebBrowser.WebBrowserWindow import WebBrowserWindow
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4772
diff changeset
321 if WebBrowserWindow.isPrivate():
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
322 return
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
323
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
324 downloads = []
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
325 for download in self.__downloads:
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
326 downloads.append(download.getData())
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
327 Preferences.setWebBrowser("DownloadManagerDownloads", downloads)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 def __load(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 """
748
eb7e73107d27 Improved the SSL certificate handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 679
diff changeset
331 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
332 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 if self.__loaded:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
336 size = Preferences.getWebBrowser("DownloadManagerSize")
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 if size.isValid():
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 self.resize(size)
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
339 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
340 self.move(pos)
d405dc3e2ed6 Added code to save the position of the download manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
341
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
342 downloads = Preferences.getWebBrowser("DownloadManagerDownloads")
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
343 for download in downloads:
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
344 if not download[0].isEmpty() and \
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
345 download[1] != "":
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
346 from .DownloadItem import DownloadItem
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
347 itm = DownloadItem(parent=self)
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
348 itm.setData(download)
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
349 self.__addItem(itm, append=True)
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 self.cleanupButton.setEnabled(
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 (len(self.__downloads) - self.activeDownloads()) > 0)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 self.__loaded = True
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
354 self.__updateActiveItemCount()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 def cleanup(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 Public slot to cleanup the downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 self.on_cleanupButton_clicked()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 @pyqtSlot()
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 def on_cleanupButton_clicked(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 Private slot cleanup the downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 if len(self.__downloads) == 0:
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 return
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 self.__model.removeRows(0, len(self.__downloads))
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 if len(self.__downloads) == 0 and \
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 self.__iconProvider is not None:
826
2e3e2055e715 Fixed a few PEP 8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 757
diff changeset
373 self.__iconProvider = None
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
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
375 self.changeOccurred()
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
376 self.__updateActiveItemCount()
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 def __updateItemCount(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 Private method to update the count label.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 count = len(self.__downloads)
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
383 self.countLabel.setText(self.tr("%n Download(s)", "", count))
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384
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
385 def __updateActiveItemCount(self):
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
386 """
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
387 Private method to update the window title.
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
388 """
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
389 count = self.activeDownloads()
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
390 if count > 0:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
391 self.setWindowTitle(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
392 self.tr("Downloading %n file(s)", "", count))
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
393 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
394 self.setWindowTitle(self.tr("Downloads"))
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
395
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
396 def __finished(self):
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
397 """
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
398 Private slot to handle a finished download.
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
399 """
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
400 self.__updateActiveItemCount()
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
401 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
402 QApplication.alert(self)
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
403
668
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 def setDownloadDirectory(self, directory):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 Public method to set the current download directory.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 @param directory current download directory (string)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 self.__downloadDirectory = directory
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 if self.__downloadDirectory != "":
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 self.__downloadDirectory += "/"
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 def downloadDirectory(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 Public method to get the current download directory.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 @return current download directory (string)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 return self.__downloadDirectory
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 def count(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 Public method to get the number of downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 @return number of downloads (integer)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 return len(self.__downloads)
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 def downloads(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 Public method to get a reference to the downloads.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 @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
435 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 return self.__downloads
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 def changeOccurred(self):
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 Public method to signal a change.
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 """
b0061a6f7484 Added a download manager to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 self.__saveTimer.changeOccurred()
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
443 self.__updateItemCount()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
444
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
445 ###########################################################################
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
446 ## 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
447 ###########################################################################
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
448
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
449 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
450 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
451 Private method to get a reference to the current item.
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
452
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
453 @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
454 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
455 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
456 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
457 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
458 return self.__downloads[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
459
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
460 return 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
461
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
462 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
463 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
464 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
465 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
466 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
467 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
468 itm.openFile()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
469
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
470 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
471 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
472 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
473 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
474 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
475 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
476 itm.openFolder()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
477
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
478 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
479 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
480 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
481 """
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 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
483 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
484 itm.cancelDownload()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
485
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
486 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
487 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
488 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
489 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
490 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
491 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
492 url = itm.getPageUrl()
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
493 WebBrowserWindow.mainWindow().openUrl(url, "")
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
494
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
495 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
496 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
497 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
498 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
499 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
500 if itm is not None:
4772
db71b47b663e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4769
diff changeset
501 url = itm.getPageUrl().toDisplayString(QUrl.FullyDecoded)
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
502 QApplication.clipboard().setText(url)
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
503
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
504 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
505 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
506 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
507 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
508 self.downloadsView.selectAll()
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
509
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
510 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
511 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
512 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
513 """
b427350a9d97 Added a context menu to the download manager of the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 673
diff changeset
514 self.downloadsView.removeSelected()

eric ide

mercurial