Bug 402278 - Download activity summary in the status bar. p=dev@schonfeld.org (Michael Schonfeld), r=mano, ui-r=madhava, ui-r=beltzner, a1.9=beltzner

This commit is contained in:
edward.lee@engineering.uiuc.edu 2008-01-26 21:08:46 -08:00
parent 7c4173f004
commit cdaf19cd61
5 changed files with 152 additions and 2 deletions

View File

@ -58,6 +58,12 @@
#
# ***** END LICENSE BLOCK *****
let Ci = Components.interfaces;
let Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/PluralForm.jsm");
const kXULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
@ -99,6 +105,7 @@ var gBrowser = null;
var gNavToolbox = null;
var gSidebarCommand = "";
var gInPrintPreviewMode = false;
let gDownloadManager = null;
// Global variable that holds the nsContextMenu instance.
var gContextMenu = null;
@ -1066,8 +1073,14 @@ function delayedStartup()
// active downloads) and speeds up the first-load of the download manager UI.
// If the user manually opens the download manager before the timeout, the
// downloads will start right away, and getting the service again won't hurt.
setTimeout(function() Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager), 10000);
setTimeout(function() {
gDownloadManager = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager);
// Initialize the downloads monitor panel listener
gDownloadManager.addListener(DownloadMonitorPanel);
DownloadMonitorPanel.init();
}, 10000);
#ifndef XP_MACOSX
updateEditUIVisibility();
@ -6011,3 +6024,110 @@ function getIdentityHandler() {
gIdentityHandler = new IdentityHandler();
return gIdentityHandler;
}
let DownloadMonitorPanel = {
//////////////////////////////////////////////////////////////////////////////
//// DownloadMonitorPanel Member Variables
_panel: null,
_activeStr: null,
_pausedStr: null,
_lastTime: Infinity,
//////////////////////////////////////////////////////////////////////////////
//// DownloadMonitorPanel Public Methods
/**
* Initialize the status panel and member variables
*/
init: function DMP_init() {
// Initialize "private" member variables
this._panel = document.getElementById("download-monitor");
// Cache the status strings
let (bundle = document.getElementById("bundle_browser")) {
this._activeStr = bundle.getString("activeDownloads");
this._pausedStr = bundle.getString("pausedDownloads");
}
this.updateStatus();
},
/**
* Update status based on the number of active and paused downloads
*/
updateStatus: function DMP_updateStatus() {
let numActive = gDownloadManager.activeDownloadCount;
// Hide the panel and reset the "last time" if there's no downloads
if (numActive == 0) {
this._panel.hidden = true;
this._lastTime = Infinity;
return;
}
// Find the download with the longest remaining time
let numPaused = 0;
let maxTime = -Infinity;
let dls = gDownloadManager.activeDownloads;
while (dls.hasMoreElements()) {
let dl = dls.getNext().QueryInterface(Ci.nsIDownload);
if (dl.state == gDownloadManager.DOWNLOAD_DOWNLOADING) {
// Figure out if this download takes longer
if (dl.speed > 0 && dl.size > 0)
maxTime = Math.max(maxTime, (dl.size - dl.amountTransferred) / dl.speed);
else
maxTime = -1;
}
else if (dl.state == gDownloadManager.DOWNLOAD_PAUSED)
numPaused++;
}
// Get the remaining time string and last sec for time estimation
let timeLeft;
[timeLeft, this._lastSec] = DownloadUtils.getTimeLeft(maxTime, this._lastSec);
// Figure out how many downloads are currently downloading
let numDls = numActive - numPaused;
let status = this._activeStr;
// If all downloads are paused, show the paused message instead
if (numDls == 0) {
numDls = numPaused;
status = this._pausedStr;
}
// Get the correct plural form and insert the number of downloads and time
// left message if necessary
status = PluralForm.get(numDls, status);
status = status.replace("#1", numDls);
status = status.replace("#2", timeLeft);
// Update the panel and show it
this._panel.label = status;
this._panel.hidden = false;
},
//////////////////////////////////////////////////////////////////////////////
//// nsIDownloadProgressListener
/**
* Update status for download progress changes
*/
onProgressChange: function() {
this.updateStatus();
},
/**
* Update status for download state changes
*/
onDownloadStateChange: function() {
this.updateStatus();
},
//////////////////////////////////////////////////////////////////////////////
//// nsISupports
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadProgressListener]),
};

View File

@ -470,6 +470,9 @@
<statusbar class="chromeclass-status" id="status-bar"
ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
<statusbarpanel id="statusbar-display" label="" flex="1"/>
<statusbarpanel id="download-monitor" class="statusbarpanel-iconic-text"
tooltiptext="&downloadMonitor.tooltip;" hidden="true"
ondblclick="doCommand();" command="Tools:Downloads"/>
<statusbarpanel class="statusbarpanel-progress" collapsed="true" id="statusbar-progresspanel">
<progressmeter class="progressmeter-statusbar" id="statusbar-icon" mode="normal" value="0"/>
</statusbarpanel>

View File

@ -1283,3 +1283,12 @@ toolbar[mode="text"] > #window-controls > toolbarbutton > .toolbarbutton-text {
#checkForUpdates[loading="true"] {
list-style-image: url("chrome://global/skin/throbber/Throbber-small.gif");
}
#download-monitor {
list-style-image: url("chrome://mozapps/skin/downloads/downloadIcon.png");
}
#download-monitor image {
height: 16px;
width: 16px;
}

View File

@ -1754,3 +1754,12 @@ toolbarbutton.bookmark-item[dragover="true"][open="true"] {
min-width: 280px;
padding: 10px;
}
#download-monitor {
list-style-image: url("chrome://mozapps/skin/downloads/downloadIcon.png");
}
#download-monitor image {
height: 16px;
width: 16px;
}

View File

@ -1702,3 +1702,12 @@ toolbarbutton.bookmark-item[dragover="true"][open="true"] {
min-width: 280px;
padding: 10px;
}
#download-monitor {
list-style-image: url("chrome://mozapps/skin/downloads/downloadIcon.png");
}
#download-monitor image {
height: 16px;
width: 16px;
}