WebBrowser/Download/DownloadItem.py

changeset 6091
7b989321d74c
parent 6090
5cdb7ea57551
child 6097
bf18415da0c7
child 6134
cb0985e8da91
equal deleted inserted replaced
6090:5cdb7ea57551 6091:7b989321d74c
317 name = os.path.join(directory, baseName) 317 name = os.path.join(directory, baseName)
318 if endName: 318 if endName:
319 name += '.' + endName 319 name += '.' + endName
320 return name, origName 320 return name, origName
321 321
322 # TODO: duplicate code to openFile()
323 def __open(self):
324 """
325 Private slot to open the downloaded file.
326 """
327 info = QFileInfo(self.__fileName)
328 url = QUrl.fromLocalFile(info.absoluteFilePath())
329 QDesktopServices.openUrl(url)
330
331 @pyqtSlot(bool) 322 @pyqtSlot(bool)
332 def on_pauseButton_clicked(self, checked): 323 def on_pauseButton_clicked(self, checked):
333 """ 324 """
334 Private slot to pause the download. 325 Private slot to pause the download.
335 326
543 534
544 self.statusChanged.emit() 535 self.statusChanged.emit()
545 self.downloadFinished.emit() 536 self.downloadFinished.emit()
546 537
547 if self.__autoOpen: 538 if self.__autoOpen:
548 self.__open() 539 self.openFile()
549 540
550 def canceledFileSelect(self): 541 def canceledFileSelect(self):
551 """ 542 """
552 Public method to check, if the user canceled the file selection. 543 Public method to check, if the user canceled the file selection.
553 544
577 568
578 @return absolute path of the output file (string) 569 @return absolute path of the output file (string)
579 """ 570 """
580 return QFileInfo(self.__fileName).absoluteFilePath() 571 return QFileInfo(self.__fileName).absoluteFilePath()
581 572
582 # TODO: change from tuple to dict
583 def getData(self): 573 def getData(self):
584 """ 574 """
585 Public method to get the relevant download data. 575 Public method to get the relevant download data.
586 576
587 @return tuple of URL, save location, flag, the 577 @return dictionary containing the URL, save location, done flag,
588 URL of the related web page and the date and time 578 the URL of the related web page and the date and time of the
589 of the download 579 download
590 @rtype tuple of (QUrl, str, bool, QUrl, QDateTime) 580 @rtype dict of {"URL": QUrl, "Location": str, "Done": bool,
591 """ 581 "PageURL": QUrl, "Downloaded": QDateTime}
592 return (self.__url, QFileInfo(self.__fileName).filePath(), 582 """
593 self.downloadedSuccessfully(), self.__pageUrl, 583 return {
594 self.__downloadedDateTime) 584 "URL": self.__url,
595 585 "Location": QFileInfo(self.__fileName).filePath(),
596 # TODO: change from tuple to dict 586 "Done": self.downloadedSuccessfully(),
587 "PageURL": self.__pageUrl,
588 "Downloaded": self.__downloadedDateTime
589 }
590
597 def setData(self, data): 591 def setData(self, data):
598 """ 592 """
599 Public method to set the relevant download data. 593 Public method to set the relevant download data.
600 594
601 @param data tuple of URL, save location, flag, the 595 @param data dictionary containing the URL, save location, done flag,
602 URL of the related web page and the date and time 596 the URL of the related web page and the date and time of the
603 of the download 597 download
604 @type QUrl, str, bool, QUrl, QDateTime 598 @type dict of {"URL": QUrl, "Location": str, "Done": bool,
605 """ 599 "PageURL": QUrl, "Downloaded": QDateTime}
606 self.__url = data[0] 600 """
607 self.__fileName = data[1] 601 self.__url = data["URL"]
608 self.__pageUrl = data[3] 602 self.__fileName = data["Location"]
603 self.__pageUrl = data["PageURL"]
609 604
610 self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) 605 self.filenameLabel.setText(QFileInfo(self.__fileName).fileName())
611 self.infoLabel.setText(self.__fileName) 606 self.infoLabel.setText(self.__fileName)
612 607
613 if len(data) == 5: 608 try:
614 self.__setDateTime(data[4]) 609 self.__setDateTime(data["Downloaded"])
615 else: 610 except KeyError:
616 self.__setDateTime(QDateTime()) 611 self.__setDateTime(QDateTime())
617 612
618 self.pauseButton.setEnabled(False) 613 self.pauseButton.setEnabled(False)
619 self.pauseButton.setVisible(False) 614 self.pauseButton.setVisible(False)
620 self.stopButton.setEnabled(False) 615 self.stopButton.setEnabled(False)
621 self.stopButton.setVisible(False) 616 self.stopButton.setVisible(False)
622 self.openButton.setEnabled(data[2]) 617 self.openButton.setEnabled(data["Done"])
623 self.openButton.setVisible(data[2]) 618 self.openButton.setVisible(data["Done"])
624 if data[2]: 619 if data["Done"]:
625 self.__state = DownloadItem.DownloadSuccessful 620 self.__state = DownloadItem.DownloadSuccessful
626 else: 621 else:
627 self.__state = DownloadItem.DownloadCancelled 622 self.__state = DownloadItem.DownloadCancelled
628 self.progressBar.setVisible(False) 623 self.progressBar.setVisible(False)
629 624

eric ide

mercurial