--- a/WebBrowser/Download/DownloadItem.py Thu Jan 25 16:39:06 2018 +0100 +++ b/WebBrowser/Download/DownloadItem.py Thu Jan 25 17:21:00 2018 +0100 @@ -319,15 +319,6 @@ name += '.' + endName return name, origName - # TODO: duplicate code to openFile() - def __open(self): - """ - Private slot to open the downloaded file. - """ - info = QFileInfo(self.__fileName) - url = QUrl.fromLocalFile(info.absoluteFilePath()) - QDesktopServices.openUrl(url) - @pyqtSlot(bool) def on_pauseButton_clicked(self, checked): """ @@ -545,7 +536,7 @@ self.downloadFinished.emit() if self.__autoOpen: - self.__open() + self.openFile() def canceledFileSelect(self): """ @@ -579,49 +570,53 @@ """ return QFileInfo(self.__fileName).absoluteFilePath() - # TODO: change from tuple to dict def getData(self): """ Public method to get the relevant download data. - @return tuple of URL, save location, flag, the - URL of the related web page and the date and time - of the download - @rtype tuple of (QUrl, str, bool, QUrl, QDateTime) + @return dictionary containing the URL, save location, done flag, + the URL of the related web page and the date and time of the + download + @rtype dict of {"URL": QUrl, "Location": str, "Done": bool, + "PageURL": QUrl, "Downloaded": QDateTime} """ - return (self.__url, QFileInfo(self.__fileName).filePath(), - self.downloadedSuccessfully(), self.__pageUrl, - self.__downloadedDateTime) + return { + "URL": self.__url, + "Location": QFileInfo(self.__fileName).filePath(), + "Done": self.downloadedSuccessfully(), + "PageURL": self.__pageUrl, + "Downloaded": self.__downloadedDateTime + } - # TODO: change from tuple to dict def setData(self, data): """ Public method to set the relevant download data. - @param data tuple of URL, save location, flag, the - URL of the related web page and the date and time - of the download - @type QUrl, str, bool, QUrl, QDateTime + @param data dictionary containing the URL, save location, done flag, + the URL of the related web page and the date and time of the + download + @type dict of {"URL": QUrl, "Location": str, "Done": bool, + "PageURL": QUrl, "Downloaded": QDateTime} """ - self.__url = data[0] - self.__fileName = data[1] - self.__pageUrl = data[3] + self.__url = data["URL"] + self.__fileName = data["Location"] + self.__pageUrl = data["PageURL"] self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) self.infoLabel.setText(self.__fileName) - if len(data) == 5: - self.__setDateTime(data[4]) - else: + try: + self.__setDateTime(data["Downloaded"]) + except KeyError: self.__setDateTime(QDateTime()) self.pauseButton.setEnabled(False) self.pauseButton.setVisible(False) self.stopButton.setEnabled(False) self.stopButton.setVisible(False) - self.openButton.setEnabled(data[2]) - self.openButton.setVisible(data[2]) - if data[2]: + self.openButton.setEnabled(data["Done"]) + self.openButton.setVisible(data["Done"]) + if data["Done"]: self.__state = DownloadItem.DownloadSuccessful else: self.__state = DownloadItem.DownloadCancelled