Helpviewer/Download/DownloadItem.py

changeset 673
1c1f3a125e68
parent 670
bb833c4bcf28
child 679
b427350a9d97
equal deleted inserted replaced
671:cc0471f53e74 673:1c1f3a125e68
314 self.infoLabel.setText(self.trUtf8("Error saving: {0}")\ 314 self.infoLabel.setText(self.trUtf8("Error saving: {0}")\
315 .format(self.__output.errorString())) 315 .format(self.__output.errorString()))
316 self.on_stopButton_clicked() 316 self.on_stopButton_clicked()
317 else: 317 else:
318 self.__startedSaving = True 318 self.__startedSaving = True
319 if self.__finishedDownloading: 319 if (self.bytesTotal() == 0 and self.__reply.atEnd()) or \
320 self.__finishedDownloading:
320 self.__finished() 321 self.__finished()
321 322
322 def __networkError(self): 323 def __networkError(self):
323 """ 324 """
324 Private slot to handle a network error. 325 Private slot to handle a network error.
362 """ 363 """
363 Public method to get the total number of bytes of the download. 364 Public method to get the total number of bytes of the download.
364 365
365 @return total number of bytes (integer) 366 @return total number of bytes (integer)
366 """ 367 """
367 return self.__reply.header(QNetworkRequest.ContentLengthHeader) 368 total = self.__reply.header(QNetworkRequest.ContentLengthHeader)
369 if total is None:
370 total = 0
371 return total
368 372
369 def bytesReceived(self): 373 def bytesReceived(self):
370 """ 374 """
371 Public method to get the number of bytes received. 375 Public method to get the number of bytes received.
372 376
379 Public method to get an estimation for the remaining time. 383 Public method to get an estimation for the remaining time.
380 384
381 @return estimation for the remaining time (float) 385 @return estimation for the remaining time (float)
382 """ 386 """
383 if not self.downloading(): 387 if not self.downloading():
388 return -1.0
389
390 if self.bytesTotal() == 0:
384 return -1.0 391 return -1.0
385 392
386 timeRemaining = (self.bytesTotal() - self.bytesReceived()) / self.currentSpeed() 393 timeRemaining = (self.bytesTotal() - self.bytesReceived()) / self.currentSpeed()
387 394
388 # ETA should never be 0 395 # ETA should never be 0
407 Private method to update the info label. 414 Private method to update the info label.
408 """ 415 """
409 if self.__reply.error() != QNetworkReply.NoError: 416 if self.__reply.error() != QNetworkReply.NoError:
410 return 417 return
411 418
412 bytesTotal = self.__reply.header(QNetworkRequest.ContentLengthHeader) 419 bytesTotal = self.bytesTotal()
413 running = not self.downloadedSuccessfully() 420 running = not self.downloadedSuccessfully()
414 421
415 speed = self.currentSpeed() 422 speed = self.currentSpeed()
416 timeRemaining = self.remainingTime() 423 timeRemaining = self.remainingTime()
417 424
428 bytesTotal == 0 and self.trUtf8("?") \ 435 bytesTotal == 0 and self.trUtf8("?") \
429 or dataString(bytesTotal), 436 or dataString(bytesTotal),
430 dataString(int(speed)), 437 dataString(int(speed)),
431 remaining) 438 remaining)
432 else: 439 else:
433 if self.__bytesReceived == bytesTotal: 440 if self.__bytesReceived == bytesTotal or bytesTotal == 0:
434 info = self.trUtf8("{0} downloaded")\ 441 info = self.trUtf8("{0} downloaded")\
435 .format(dataString(self.__output.size())) 442 .format(dataString(self.__output.size()))
436 else: 443 else:
437 info = self.trUtf8("{0} of {1} - Stopped")\ 444 info = self.trUtf8("{0} of {1} - Stopped")\
438 .format(dataString(self.__bytesReceived), 445 .format(dataString(self.__bytesReceived),

eric ide

mercurial