7 Module implementing the download manager class. |
7 Module implementing the download manager class. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, Qt, QModelIndex, QFileInfo |
12 from PyQt5.QtCore import pyqtSlot, Qt, QModelIndex, QFileInfo, QUrl |
13 from PyQt5.QtGui import QCursor, QKeySequence |
13 from PyQt5.QtGui import QCursor, QKeySequence |
14 from PyQt5.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, \ |
14 from PyQt5.QtWidgets import QDialog, QStyle, QFileIconProvider, QMenu, \ |
15 QApplication, QShortcut |
15 QApplication, QShortcut |
16 |
16 |
17 from E5Gui import E5MessageBox |
17 from E5Gui import E5MessageBox |
84 self.downloadsView.selectionModel().selectedRows()) |
84 self.downloadsView.selectionModel().selectedRows()) |
85 |
85 |
86 if selectedRowsCount == 1: |
86 if selectedRowsCount == 1: |
87 row = self.downloadsView.selectionModel().selectedRows()[0].row() |
87 row = self.downloadsView.selectionModel().selectedRows()[0].row() |
88 itm = self.__downloads[row] |
88 itm = self.__downloads[row] |
89 if itm.downloadCanceled(): |
89 if itm.downloadedSuccessfully(): |
90 menu.addAction( |
90 menu.addAction( |
91 UI.PixmapCache.getIcon("restart.png"), |
91 UI.PixmapCache.getIcon("open.png"), |
92 self.tr("Retry"), self.__contextMenuRetry) |
92 self.tr("Open"), self.__contextMenuOpen) |
93 else: |
93 elif itm.downloading(): |
94 if itm.downloadedSuccessfully(): |
|
95 menu.addAction( |
|
96 UI.PixmapCache.getIcon("open.png"), |
|
97 self.tr("Open"), self.__contextMenuOpen) |
|
98 elif itm.downloading(): |
|
99 menu.addAction( |
|
100 UI.PixmapCache.getIcon("stopLoading.png"), |
|
101 self.tr("Cancel"), self.__contextMenuCancel) |
|
102 menu.addSeparator() |
|
103 menu.addAction( |
94 menu.addAction( |
104 self.tr("Open Containing Folder"), |
95 UI.PixmapCache.getIcon("stopLoading.png"), |
|
96 self.tr("Cancel"), self.__contextMenuCancel) |
|
97 menu.addSeparator() |
|
98 menu.addAction( |
|
99 self.tr("Open Containing Folder"), |
105 self.__contextMenuOpenFolder) |
100 self.__contextMenuOpenFolder) |
106 menu.addSeparator() |
101 menu.addSeparator() |
107 menu.addAction( |
102 menu.addAction( |
108 self.tr("Go to Download Page"), |
103 self.tr("Go to Download Page"), |
109 self.__contextMenuGotoPage) |
104 self.__contextMenuGotoPage) |
237 self.downloadsView.setRowHeight( |
232 self.downloadsView.setRowHeight( |
238 row, |
233 row, |
239 max(oldHeight, itm.minimumSizeHint().height() * 1.5)) |
234 max(oldHeight, itm.minimumSizeHint().height() * 1.5)) |
240 |
235 |
241 remove = False |
236 remove = False |
242 # TODO: Private Browsing |
|
243 ## globalSettings = QWebSettings.globalSettings() |
|
244 ## if not itm.downloading() and \ |
|
245 ## globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled): |
|
246 ## remove = True |
|
247 |
237 |
248 if itm.downloadedSuccessfully() and \ |
238 if itm.downloadedSuccessfully() and \ |
249 self.removePolicy() == DownloadManager.RemoveSuccessFullDownload: |
239 self.removePolicy() == DownloadManager.RemoveSuccessFullDownload: |
250 remove = True |
240 remove = True |
251 |
241 |
293 Preferences.setWebBrowser("DownloadManagerSize", self.size()) |
283 Preferences.setWebBrowser("DownloadManagerSize", self.size()) |
294 Preferences.setWebBrowser("DownloadManagerPosition", self.pos()) |
284 Preferences.setWebBrowser("DownloadManagerPosition", self.pos()) |
295 if self.removePolicy() == DownloadManager.RemoveExit: |
285 if self.removePolicy() == DownloadManager.RemoveExit: |
296 return |
286 return |
297 |
287 |
298 # TODO: Downloads: check saving downloads |
288 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
299 ## downloads = [] |
289 if WebBrowserWindow.mainWindow().isPrivate(): |
300 ## for download in self.__downloads: |
290 return |
301 ## downloads.append(download.getData()) |
291 |
302 ## Preferences.setWebBrowser("DownloadManagerDownloads", downloads) |
292 downloads = [] |
|
293 for download in self.__downloads: |
|
294 downloads.append(download.getData()) |
|
295 Preferences.setWebBrowser("DownloadManagerDownloads", downloads) |
303 |
296 |
304 def __load(self): |
297 def __load(self): |
305 """ |
298 """ |
306 Private method to load the download settings. |
299 Private method to load the download settings. |
307 """ |
300 """ |
312 if size.isValid(): |
305 if size.isValid(): |
313 self.resize(size) |
306 self.resize(size) |
314 pos = Preferences.getWebBrowser("DownloadManagerPosition") |
307 pos = Preferences.getWebBrowser("DownloadManagerPosition") |
315 self.move(pos) |
308 self.move(pos) |
316 |
309 |
317 # TODO: Downloads: check laoding downloads |
310 downloads = Preferences.getWebBrowser("DownloadManagerDownloads") |
318 ## downloads = Preferences.getWebBrowser("DownloadManagerDownloads") |
311 for download in downloads: |
319 ## for download in downloads: |
312 if not download[0].isEmpty() and \ |
320 ## if not download[0].isEmpty() and \ |
313 download[1] != "": |
321 ## download[1] != "": |
314 from .DownloadItem import DownloadItem |
322 ## from .DownloadItem import DownloadItem |
315 itm = DownloadItem(parent=self) |
323 ## itm = DownloadItem(parent=self) |
316 itm.setData(download) |
324 ## itm.setData(download) |
317 self.__addItem(itm) |
325 ## self.__addItem(itm) |
|
326 self.cleanupButton.setEnabled( |
318 self.cleanupButton.setEnabled( |
327 (len(self.__downloads) - self.activeDownloads()) > 0) |
319 (len(self.__downloads) - self.activeDownloads()) > 0) |
328 |
320 |
329 self.__loaded = True |
321 self.__loaded = True |
330 self.__updateActiveItemCount() |
322 self.__updateActiveItemCount() |
420 |
412 |
421 ########################################################################### |
413 ########################################################################### |
422 ## Context menu related methods below |
414 ## Context menu related methods below |
423 ########################################################################### |
415 ########################################################################### |
424 |
416 |
425 # TODO: Downloads: check the context menu actions |
|
426 def __currentItem(self): |
417 def __currentItem(self): |
427 """ |
418 """ |
428 Private method to get a reference to the current item. |
419 Private method to get a reference to the current item. |
429 |
420 |
430 @return reference to the current item (DownloadItem) |
421 @return reference to the current item (DownloadItem) |
434 row = index.row() |
425 row = index.row() |
435 return self.__downloads[row] |
426 return self.__downloads[row] |
436 |
427 |
437 return None |
428 return None |
438 |
429 |
439 def __contextMenuRetry(self): |
|
440 """ |
|
441 Private method to retry of the download. |
|
442 """ |
|
443 itm = self.__currentItem() |
|
444 if itm is not None: |
|
445 itm.retry() |
|
446 |
|
447 def __contextMenuOpen(self): |
430 def __contextMenuOpen(self): |
448 """ |
431 """ |
449 Private method to open the downloaded file. |
432 Private method to open the downloaded file. |
450 """ |
433 """ |
451 itm = self.__currentItem() |
434 itm = self.__currentItem() |
481 """ |
464 """ |
482 Private method to copy the download link to the clipboard. |
465 Private method to copy the download link to the clipboard. |
483 """ |
466 """ |
484 itm = self.__currentItem() |
467 itm = self.__currentItem() |
485 if itm is not None: |
468 if itm is not None: |
486 url = itm.getPageUrl().toString() |
469 url = itm.getPageUrl().toDisplayString(QUrl.FullyDecoded) |
487 QApplication.clipboard().setText(url) |
470 QApplication.clipboard().setText(url) |
488 |
471 |
489 def __contextMenuSelectAll(self): |
472 def __contextMenuSelectAll(self): |
490 """ |
473 """ |
491 Private method to select all downloads. |
474 Private method to select all downloads. |