WebBrowser/Download/DownloadItem.py

branch
maintenance
changeset 6273
0daf79d65080
parent 6166
bace7fb85a01
parent 6224
08875555771a
child 6319
df201b9fbad4
equal deleted inserted replaced
6207:0a74c1efab70 6273:0daf79d65080
19 19
20 from E5Gui import E5FileDialog 20 from E5Gui import E5FileDialog
21 21
22 from .Ui_DownloadItem import Ui_DownloadItem 22 from .Ui_DownloadItem import Ui_DownloadItem
23 23
24 from .DownloadUtilities import timeString, dataString 24 from .DownloadUtilities import timeString, dataString, speedString
25 from WebBrowser.WebBrowserWindow import WebBrowserWindow 25 from WebBrowser.WebBrowserWindow import WebBrowserWindow
26 26
27 import UI.PixmapCache 27 import UI.PixmapCache
28 import Utilities.MimeTypes 28 import Utilities.MimeTypes
29 import Globals 29 import Globals
33 class DownloadItem(QWidget, Ui_DownloadItem): 33 class DownloadItem(QWidget, Ui_DownloadItem):
34 """ 34 """
35 Class implementing a widget controlling a download. 35 Class implementing a widget controlling a download.
36 36
37 @signal statusChanged() emitted upon a status change of a download 37 @signal statusChanged() emitted upon a status change of a download
38 @signal downloadFinished() emitted when a download finished 38 @signal downloadFinished(success) emitted when a download finished
39 @signal progress(int, int) emitted to signal the download progress 39 @signal progress(int, int) emitted to signal the download progress
40 """ 40 """
41 statusChanged = pyqtSignal() 41 statusChanged = pyqtSignal()
42 downloadFinished = pyqtSignal() 42 downloadFinished = pyqtSignal(bool)
43 progress = pyqtSignal(int, int) 43 progress = pyqtSignal(int, int)
44 44
45 Downloading = 0 45 Downloading = 0
46 DownloadSuccessful = 1 46 DownloadSuccessful = 1
47 DownloadCancelled = 2 47 DownloadCancelled = 2
354 self.pauseButton.setVisible(False) 354 self.pauseButton.setVisible(False)
355 self.setUpdatesEnabled(True) 355 self.setUpdatesEnabled(True)
356 self.__state = DownloadItem.DownloadCancelled 356 self.__state = DownloadItem.DownloadCancelled
357 self.__downloadItem.cancel() 357 self.__downloadItem.cancel()
358 self.__setDateTime() 358 self.__setDateTime()
359 self.downloadFinished.emit() 359 self.downloadFinished.emit(False)
360 360
361 @pyqtSlot() 361 @pyqtSlot()
362 def on_openButton_clicked(self): 362 def on_openButton_clicked(self):
363 """ 363 """
364 Private slot to open the downloaded file. 364 Private slot to open the downloaded file.
399 self.progressBar.setMaximum(totalValue) 399 self.progressBar.setMaximum(totalValue)
400 400
401 self.progress.emit(currentValue, totalValue) 401 self.progress.emit(currentValue, totalValue)
402 self.__updateInfoLabel() 402 self.__updateInfoLabel()
403 403
404 def downloadProgress(self):
405 """
406 Public method to get the download progress.
407
408 @return current download progress
409 @rtype int
410 """
411 return self.progressBar.value()
412
404 def bytesTotal(self): 413 def bytesTotal(self):
405 """ 414 """
406 Public method to get the total number of bytes of the download. 415 Public method to get the total number of bytes of the download.
407 416
408 @return total number of bytes (integer) 417 @return total number of bytes (integer)
469 remaining = "" 478 remaining = ""
470 479
471 if bytesTotal > 0: 480 if bytesTotal > 0:
472 remaining = timeString(timeRemaining) 481 remaining = timeString(timeRemaining)
473 482
474 info = self.tr("{0} of {1} ({2}/sec)\n{3}")\ 483 info = self.tr("{0} of {1} ({2}/sec) {3}")\
475 .format( 484 .format(
476 dataString(self.__bytesReceived), 485 dataString(self.__bytesReceived),
477 bytesTotal == -1 and self.tr("?") or 486 bytesTotal == -1 and self.tr("?") or
478 dataString(bytesTotal), 487 dataString(bytesTotal),
479 dataString(int(speed)), 488 speedString(speed),
480 remaining) 489 remaining)
481 else: 490 else:
482 if self.__bytesReceived == bytesTotal or bytesTotal == -1: 491 if self.__bytesReceived == bytesTotal or bytesTotal == -1:
483 info = self.tr("{0} downloaded")\ 492 info = self.tr("{0} downloaded")\
484 .format(dataString(self.__bytesReceived)) 493 .format(dataString(self.__bytesReceived))
533 self.__setDateTime() 542 self.__setDateTime()
534 543
535 self.__adjustSize() 544 self.__adjustSize()
536 545
537 self.statusChanged.emit() 546 self.statusChanged.emit()
538 self.downloadFinished.emit() 547 self.downloadFinished.emit(True)
539 548
540 if self.__autoOpen: 549 if self.__autoOpen:
541 self.openFile() 550 self.openFile()
542 551
543 def canceledFileSelect(self): 552 def canceledFileSelect(self):

eric ide

mercurial