зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1448143 - Factor out a size getter from DownloadsViewUI.jsm so other consumers can access it r=Mardak
MozReview-Commit-ID: EgyfXz1ntys --HG-- extra : rebase_source : 8a2fcdd366764a6cf0d51a14d7df2f70fb1a3af0
This commit is contained in:
Родитель
d3e1a09b4c
Коммит
8189974edc
|
@ -109,6 +109,28 @@ this.DownloadsViewUI.DownloadElementShell.prototype = {
|
|||
return OS.Path.basename(this.download.target.path);
|
||||
},
|
||||
|
||||
/**
|
||||
* The user-facing label for the size (if any) of the download. The return value
|
||||
* is an object 'sizeStrings' with 2 strings:
|
||||
* 1. stateLabel - The size with the units (e.g. "1.5 MB").
|
||||
* 2. status - The status of the download (e.g. "Completed");
|
||||
*/
|
||||
get sizeStrings() {
|
||||
let s = DownloadsCommon.strings;
|
||||
let sizeStrings = {};
|
||||
|
||||
if (this.download.target.size !== undefined) {
|
||||
let [size, unit] = DownloadUtils.convertByteUnits(this.download.target.size);
|
||||
sizeStrings.stateLabel = s.sizeWithUnits(size, unit);
|
||||
sizeStrings.status = s.statusSeparator(s.stateCompleted, sizeStrings.stateLabel);
|
||||
} else {
|
||||
// History downloads may not have a size defined.
|
||||
sizeStrings.stateLabel = s.sizeUnknown;
|
||||
sizeStrings.status = s.stateCompleted;
|
||||
}
|
||||
return sizeStrings;
|
||||
},
|
||||
|
||||
get browserWindow() {
|
||||
return RecentWindow.getMostRecentBrowserWindow();
|
||||
},
|
||||
|
@ -245,17 +267,10 @@ this.DownloadsViewUI.DownloadElementShell.prototype = {
|
|||
stateLabel = s.fileMovedOrMissing;
|
||||
hoverStatus = stateLabel;
|
||||
} else if (this.download.succeeded) {
|
||||
// For completed downloads, show the file size (e.g. "1.5 MB").
|
||||
if (this.download.target.size !== undefined) {
|
||||
let [size, unit] =
|
||||
DownloadUtils.convertByteUnits(this.download.target.size);
|
||||
stateLabel = s.sizeWithUnits(size, unit);
|
||||
status = s.statusSeparator(s.stateCompleted, stateLabel);
|
||||
} else {
|
||||
// History downloads may not have a size defined.
|
||||
stateLabel = s.sizeUnknown;
|
||||
status = s.stateCompleted;
|
||||
}
|
||||
// For completed downloads, show the file size
|
||||
let sizeStrings = this.sizeStrings;
|
||||
stateLabel = sizeStrings.stateLabel;
|
||||
status = sizeStrings.status;
|
||||
hoverStatus = status;
|
||||
} else if (this.download.canceled) {
|
||||
stateLabel = s.stateCanceled;
|
||||
|
|
Загрузка…
Ссылка в новой задаче