diff -r 9986ec0e559a -r 10516539f238 Helpviewer/Download/DownloadItem.py --- a/Helpviewer/Download/DownloadItem.py Tue Oct 15 22:03:54 2013 +0200 +++ b/Helpviewer/Download/DownloadItem.py Fri Oct 18 23:00:41 2013 +0200 @@ -13,8 +13,8 @@ except (NameError): pass -from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QTime, QFile, QFileInfo, QUrl, \ - QIODevice, QCryptographicHash +from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QTime, QFile, QFileInfo, \ + QUrl, QIODevice, QCryptographicHash from PyQt4.QtGui import QWidget, QPalette, QStyle, QDesktopServices, QDialog from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply @@ -50,9 +50,10 @@ Constructor @keyparam reply reference to the network reply object (QNetworkReply) - @keyparam requestFilename flag indicating to ask the user for a filename (boolean) - @keyparam webPage reference to the web page object the download originated - from (QWebPage) + @keyparam requestFilename flag indicating to ask the user for a + filename (boolean) + @keyparam webPage reference to the web page object the download + originated from (QWebPage) @keyparam download flag indicating a download operation (boolean) @keyparam parent reference to the parent widget (QWidget) @keyparam mainWindow reference to the main window (HelpWindow) @@ -66,7 +67,8 @@ self.progressBar.setMaximum(0) - self.__isFtpDownload = reply is not None and reply.url().scheme() == "ftp" + self.__isFtpDownload = reply is not None and \ + reply.url().scheme() == "ftp" self.tryAgainButton.setIcon(UI.PixmapCache.getIcon("restart.png")) self.tryAgainButton.setEnabled(False) @@ -109,7 +111,8 @@ self.__md5Hash = QCryptographicHash(QCryptographicHash.Md5) if not requestFilename: - self.__requestFilename = Preferences.getUI("RequestDownloadFilename") + self.__requestFilename = \ + Preferences.getUI("RequestDownloadFilename") self.__initialize() @@ -154,9 +157,7 @@ def __getFileName(self): """ - Private method to get the filename to save to from the user. - - @return flag indicating success (boolean) + Private method to get the file name to save to from the user. """ if self.__gettingFileName: return @@ -171,7 +172,8 @@ self.__toDownload = True ask = False else: - defaultFileName, originalFileName = self.__saveFileName(downloadDirectory) + defaultFileName, originalFileName = \ + self.__saveFileName(downloadDirectory) fileName = defaultFileName self.__originalFileName = originalFileName ask = True @@ -188,8 +190,9 @@ self.progressBar.setVisible(False) self.__reply.close() self.on_stopButton_clicked() - self.filenameLabel.setText(self.trUtf8("Download canceled: {0}").format( - QFileInfo(defaultFileName).fileName())) + self.filenameLabel.setText( + self.trUtf8("Download canceled: {0}").format( + QFileInfo(defaultFileName).fileName())) self.__canceledFileSelect = True return @@ -206,8 +209,9 @@ return self.__autoOpen = dlg.getAction() == "open" - fileName = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + \ - '/' + QFileInfo(fileName).completeBaseName() + fileName = QDesktopServices.storageLocation( + QDesktopServices.TempLocation) + \ + '/' + QFileInfo(fileName).completeBaseName() if ask and not self.__autoOpen and self.__requestFilename: self.__gettingFileName = True @@ -221,14 +225,15 @@ self.progressBar.setVisible(False) self.__reply.close() self.on_stopButton_clicked() - self.filenameLabel.setText(self.trUtf8("Download canceled: {0}")\ - .format(QFileInfo(defaultFileName).fileName())) + self.filenameLabel.setText( + self.trUtf8("Download canceled: {0}")\ + .format(QFileInfo(defaultFileName).fileName())) self.__canceledFileSelect = True return fileInfo = QFileInfo(fileName) - Helpviewer.HelpWindow.HelpWindow.downloadManager().setDownloadDirectory( - fileInfo.absoluteDir().absolutePath()) + Helpviewer.HelpWindow.HelpWindow.downloadManager()\ + .setDownloadDirectory(fileInfo.absoluteDir().absolutePath()) self.filenameLabel.setText(fileInfo.fileName()) self.__output.setFileName(fileName + ".part") @@ -240,8 +245,8 @@ if not saveDirPath.mkpath(saveDirPath.absolutePath()): self.progressBar.setVisible(False) self.on_stopButton_clicked() - self.infoLabel.setText( - self.trUtf8("Download directory ({0}) couldn't be created.")\ + self.infoLabel.setText(self.trUtf8( + "Download directory ({0}) couldn't be created.")\ .format(saveDirPath.absolutePath())) return @@ -258,7 +263,8 @@ """ path = "" if self.__reply.hasRawHeader("Content-Disposition"): - header = bytes(self.__reply.rawHeader("Content-Disposition")).decode() + header = bytes(self.__reply.rawHeader("Content-Disposition"))\ + .decode() if header: pos = header.find("filename=") if pos != -1: @@ -415,7 +421,8 @@ if not self.__requestFilename: self.__getFileName() if not self.__output.open(QIODevice.WriteOnly): - self.infoLabel.setText(self.trUtf8("Error opening save file: {0}")\ + self.infoLabel.setText( + self.trUtf8("Error opening save file: {0}")\ .format(self.__output.errorString())) self.on_stopButton_clicked() self.statusChanged.emit() @@ -453,8 +460,8 @@ if locationHeader and locationHeader.isValid(): self.__url = QUrl(locationHeader) import Helpviewer.HelpWindow - self.__reply = Helpviewer.HelpWindow.HelpWindow.networkAccessManager().get( - QNetworkRequest(self.__url)) + self.__reply = Helpviewer.HelpWindow.HelpWindow\ + .networkAccessManager().get(QNetworkRequest(self.__url)) self.__initialize() def __downloadProgress(self, bytesReceived, bytesTotal): @@ -484,7 +491,8 @@ @return total number of bytes (integer) """ if self.__bytesTotal == -1: - self.__bytesTotal = self.__reply.header(QNetworkRequest.ContentLengthHeader) + self.__bytesTotal = self.__reply.header( + QNetworkRequest.ContentLengthHeader) if self.__bytesTotal is None: self.__bytesTotal = -1 return self.__bytesTotal @@ -509,7 +517,8 @@ if self.bytesTotal() == -1: return -1.0 - timeRemaining = (self.bytesTotal() - self.bytesReceived()) / self.currentSpeed() + timeRemaining = (self.bytesTotal() - + self.bytesReceived()) / self.currentSpeed() # ETA should never be 0 if timeRemaining == 0: @@ -559,8 +568,11 @@ if self.__bytesReceived == bytesTotal or bytesTotal == -1: info = self.trUtf8("{0} downloaded\nSHA1: {1}\nMD5: {2}")\ .format(dataString(self.__output.size()), - str(self.__sha1Hash.result().toHex(), encoding="ascii"), - str(self.__md5Hash.result().toHex(), encoding="ascii")) + str(self.__sha1Hash.result().toHex(), + encoding="ascii"), + str(self.__md5Hash.result().toHex(), + encoding="ascii") + ) else: info = self.trUtf8("{0} of {1} - Stopped")\ .format(dataString(self.__bytesReceived),