Bug 389569 - "Less than a minute" in Download Manager is silly. Patch by Edward Lee <edilee@mozilla.com>. r=sdwilsh, r=mano, ui-r=beltzner

git-svn-id: svn://10.0.0.236/trunk@231924 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sdwilsh%shawnwilsher.com
2007-08-12 10:19:12 +00:00
parent bc3a9d993c
commit 9fa642faaf
2 changed files with 34 additions and 12 deletions

View File

@@ -37,10 +37,13 @@ transferSameUnits=#1 of #3 #4
transferDiffUnits=#1 #2 of #3 #4
transferNoTotal=#1 #2
# LOCALIZATION NOTE (timeLeft): number of minutes left (greater than 1)
# 3 min -> 2 min -> less than a minute; example: 11 minutes left
timeLeft=#1 minutes left
timeLessMinute=Less than a minute
# LOCALIZATION NOTE (timeMinutesLeft): number of minutes left (greater than 1)
# LOCALIZATION NOTE (timeSecondsLeft): number of seconds left (greater than 3)
# 3 min -> 2 min -> 60 secs -> 59 secs -> ... -> 5 secs -> 4 secs -> few secs
# examples: 11 minutes left; 11 seconds left;
timeMinutesLeft=#1 minutes left
timeSecondsLeft=#1 seconds left
timeFewSeconds=A few seconds left
timeUnknown=Unknown time left
fileDoesNotExistOpenTitle=Cannot Open %S

View File

@@ -46,13 +46,16 @@ function DownloadProgressListener()
this._transferSameUnits = sb.getString("transferSameUnits");
this._transferDiffUnits = sb.getString("transferDiffUnits");
this._transferNoTotal = sb.getString("transferNoTotal");
this._timeLeft = sb.getString("timeLeft");
this._timeLessMinute = sb.getString("timeLessMinute");
this._timeMinutesLeft = sb.getString("timeMinutesLeft");
this._timeSecondsLeft = sb.getString("timeSecondsLeft");
this._timeFewSeconds = sb.getString("timeFewSeconds");
this._timeUnknown = sb.getString("timeUnknown");
this._units = [sb.getString("bytes"),
sb.getString("kilobyte"),
sb.getString("megabyte"),
sb.getString("gigabyte")];
this.lastSeconds = Infinity;
}
DownloadProgressListener.prototype =
@@ -180,12 +183,28 @@ DownloadProgressListener.prototype =
// Update time remaining.
let (remain) {
if ((aDownload.speed > 0) && (aMaxTotalProgress > 0)) {
let minutes = Math.ceil((aMaxTotalProgress - aCurTotalProgress) /
aDownload.speed / 60);
if (minutes > 1)
remain = this._replaceInsert(this._timeLeft, 1, minutes);
else
remain = this._timeLessMinute;
let seconds = Math.ceil((aMaxTotalProgress - aCurTotalProgress) /
aDownload.speed);
// Reuse the last seconds if the new one is longer by some small amount
// This avoids jittering seconds, e.g., 41 40 38 40 -> 41 40 38 38
// However, large changes are shown, e.g., 41 38 49 -> 41 38 49
let (diff = seconds - this.lastSeconds) {
if (diff > 0 && diff <= 10)
seconds = this.lastSeconds;
else
this.lastSeconds = seconds;
}
// Be friendly in the last few seconds
if (seconds <= 3)
remain = this._timeFewSeconds;
// Show 2 digit seconds starting at 60; otherwise use minutes
else if (seconds <= 60)
remain = this._replaceInsert(this._timeSecondsLeft, 1, seconds);
else
remain = this._replaceInsert(this._timeMinutesLeft, 1,
Math.ceil(seconds / 60));
} else {
remain = this._timeUnknown;
}