diff -r d405dc3e2ed6 -r bb833c4bcf28 Helpviewer/Download/DownloadItem.py --- a/Helpviewer/Download/DownloadItem.py Mon Oct 11 09:36:44 2010 +0200 +++ b/Helpviewer/Download/DownloadItem.py Mon Oct 11 11:05:38 2010 +0200 @@ -10,7 +10,7 @@ from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QTime, QFile, QFileInfo, QUrl, \ QIODevice from PyQt4.QtGui import QWidget, QPalette, QStyle, QDesktopServices, QFileDialog -from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply +from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply from E5Gui import E5MessageBox @@ -69,6 +69,7 @@ self.__bytesReceived = 0 self.__downloadTime = QTime() self.__output = QFile() + self.__fileName = "" self.__startedSaving = False self.__finishedDownloading = False self.__gettingFileName = False @@ -95,6 +96,9 @@ self.openButton.setEnabled(False) self.openButton.setVisible(False) + # start timer for the download estimation + self.__downloadTime.start() + # attach to the reply object self.__url = self.__reply.url() self.__reply.setParent(self) @@ -109,9 +113,6 @@ self.progressBar.setValue(0) self.__getFileName() - # start timer for the download estimation - self.__downloadTime.start() - if self.__reply.error() != QNetworkReply.NoError: self.__networkError() self.__finished() @@ -128,8 +129,14 @@ downloadDirectory = Helpviewer.HelpWindow.HelpWindow\ .downloadManager().downloadDirectory() - defaultFileName = self.__saveFileName(downloadDirectory) - fileName = defaultFileName + if self.__fileName: + fileName = self.__fileName + self.__toDownload = True + ask = False + else: + defaultFileName = self.__saveFileName(downloadDirectory) + fileName = defaultFileName + ask = True self.__autoOpen = False if not self.__toDownload: res = E5MessageBox.question(self, @@ -153,7 +160,7 @@ fileName = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + \ '/' + QFileInfo(fileName).completeBaseName() - if not self.__autoOpen and self.__requestFilename: + if ask and not self.__autoOpen and self.__requestFilename: self.__gettingFileName = True fileName = QFileDialog.getSaveFileName( None, @@ -169,15 +176,17 @@ .format(QFileInfo(defaultFileName).fileName())) self.__canceledFileSelect = True return - fileInfo = QFileInfo(fileName) - Helpviewer.HelpWindow.HelpWindow.downloadManager().setDownloadDirectory( - fileInfo.absoluteDir().absolutePath()) - self.filenameLabel.setText(fileInfo.fileName()) + + fileInfo = QFileInfo(fileName) + Helpviewer.HelpWindow.HelpWindow.downloadManager().setDownloadDirectory( + fileInfo.absoluteDir().absolutePath()) + self.filenameLabel.setText(fileInfo.fileName()) self.__output.setFileName(fileName) + self.__fileName = fileName # check file path for saving - saveDirPath = QFileInfo(self.__output.fileName()).dir() + saveDirPath = QFileInfo(self.__fileName).dir() if not saveDirPath.exists(): if not saveDirPath.mkpath(saveDirPath.absolutePath()): self.progressBar.setVisible(False) @@ -187,7 +196,7 @@ .format(saveDirPath.absolutePath())) return - self.filenameLabel.setText(QFileInfo(self.__output.fileName()).fileName()) + self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) if self.__requestFilename: self.__readyRead() @@ -252,6 +261,7 @@ reply = nam.get(QNetworkRequest(self.__url)) if self.__output.exists(): self.__output.remove() + self.__output = QFile() self.__reply = reply self.__initialize(tryAgain = True) self.statusChanged.emit() @@ -449,8 +459,6 @@ """ Private slot to handle the download finished. """ - self.__readyRead() - self.__finishedDownloading = True if not self.__startedSaving: return @@ -483,7 +491,6 @@ @param icon reference to the icon to be set (QIcon) """ - # TODO: adjust the size self.fileIcon.setPixmap(icon.pixmap(48, 48)) def fileName(self): @@ -492,7 +499,7 @@ @return name of the output file (string) """ - return self.__output.fileName() + return self.__fileName def absoluteFilePath(self): """ @@ -500,7 +507,7 @@ @return absolute path of the output file (string) """ - return QFileInfo(self.__output).absoluteFilePath() + return QFileInfo(self.__fileName).absoluteFilePath() def getData(self): """ @@ -509,7 +516,7 @@ @return tuple of URL, save location and done flag (QUrl, string, boolean) """ - return (self.__url, QFileInfo(self.__output).filePath(), + return (self.__url, QFileInfo(self.__fileName).filePath(), self.downloadedSuccessfully()) def setData(self, data): @@ -520,9 +527,10 @@ (QUrl, string, boolean) """ self.__url = data[0] - self.__output.setFileName(data[1]) + self.__fileName = data[1] - self.filenameLabel.setText(QFileInfo(self.__output.fileName()).fileName()) + self.filenameLabel.setText(QFileInfo(self.__fileName).fileName()) + self.infoLabel.setText(self.__fileName) self.stopButton.setEnabled(False) self.stopButton.setVisible(False)