Helpviewer/Download/DownloadItem.py

changeset 673
1c1f3a125e68
parent 670
bb833c4bcf28
child 679
b427350a9d97
--- a/Helpviewer/Download/DownloadItem.py	Mon Oct 11 14:57:26 2010 +0200
+++ b/Helpviewer/Download/DownloadItem.py	Wed Oct 13 22:47:44 2010 +0200
@@ -316,7 +316,8 @@
             self.on_stopButton_clicked()
         else:
             self.__startedSaving = True
-            if self.__finishedDownloading:
+            if (self.bytesTotal() == 0 and self.__reply.atEnd()) or \
+               self.__finishedDownloading:
                 self.__finished()
     
     def __networkError(self):
@@ -364,7 +365,10 @@
         
         @return total number of bytes (integer)
         """
-        return self.__reply.header(QNetworkRequest.ContentLengthHeader)
+        total = self.__reply.header(QNetworkRequest.ContentLengthHeader)
+        if total is None:
+            total = 0
+        return total
     
     def bytesReceived(self):
         """
@@ -383,6 +387,9 @@
         if not self.downloading():
             return -1.0
         
+        if self.bytesTotal() == 0:
+            return -1.0
+        
         timeRemaining = (self.bytesTotal() - self.bytesReceived()) / self.currentSpeed()
         
         # ETA should never be 0
@@ -409,7 +416,7 @@
         if self.__reply.error() != QNetworkReply.NoError:
             return
         
-        bytesTotal = self.__reply.header(QNetworkRequest.ContentLengthHeader)
+        bytesTotal = self.bytesTotal()
         running = not self.downloadedSuccessfully()
         
         speed = self.currentSpeed()
@@ -430,7 +437,7 @@
                     dataString(int(speed)), 
                     remaining)
         else:
-            if self.__bytesReceived == bytesTotal:
+            if self.__bytesReceived == bytesTotal or bytesTotal == 0:
                 info = self.trUtf8("{0} downloaded")\
                     .format(dataString(self.__output.size()))
             else:

eric ide

mercurial