1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-05 08:15:48 +01:00

Add totals columns to the download manager.

--HG--
branch : key-processing
This commit is contained in:
Kris Maglione
2011-01-24 10:14:01 -05:00
parent 304d4fffd7
commit 56777f59c3
2 changed files with 30 additions and 6 deletions

View File

@@ -190,15 +190,18 @@ var DownloadList = Class("DownloadList",
<span>Source</span>
</li>
<li highlight="Download"><span><div style="min-height: 1ex; /* FIXME */"/></span></li>
<li highlight="Download" key="totals">
<span highlight="Title">Totals:</span>
<li highlight="Download" key="totals" active="true">
<span><span highlight="Title">Totals:</span>&#xa0;<span key="total"/></span>
<span/>
<span highlight="DownloadButtons">
<a highlight="Button" key="clear">Clear</a>
</span>
<span/>
<span/>
<span/>
<span highlight="DownloadProgress" key="progress">
<span highlight="DownloadProgressHave" key="progressHave"
/>/<span highlight="DownloadProgressTotal" key="progressTotal"/>
</span>
<span highlight="DownloadPercent" key="percent"/>
<span highlight="DownloadTime" key="time"/>
<span/>
</li>
</ul>, this.document, this.nodes);
@@ -253,6 +256,25 @@ var DownloadList = Class("DownloadList",
for (let node in values(this.nodes))
if (node.update && node.update != update)
node.update();
this.updateProgress();
},
timeRemaining: Infinity,
updateProgress: function updateProgress() {
let downloads = values(this.downloads).toArray();
let self = Object.create(this);
for (let prop in values(["amountTransferred", "size", "speed", "timeRemaining"]))
this[prop] = downloads.reduce(function (acc, dl) dl[prop] + acc, 0);
Download.prototype.updateProgress.call(self);
let active = downloads.filter(function (dl) dl.alive).length;
if (active)
this.nodes.total.textContent = active + " active";
else for (let key in values(["total", "percent", "time"]))
this.nodes[key].textContent = "";
},
observers: {
@@ -290,6 +312,7 @@ var DownloadList = Class("DownloadList",
try {
if (download.id in this.downloads)
this.downloads[download.id].updateProgress();
this.updateProgress();
}
catch (e) {
util.reportError(e);

View File

@@ -672,6 +672,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @returns {string}
*/
formatSeconds: function formatSeconds(seconds) {
function pad(n, val) ("0000000" + val).substr(-Math.max(n, String(val).length));
function div(num, denom) [Math.round(num / denom), Math.round(num % denom)];
let days, hours, minutes;
@@ -683,7 +684,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
if (hours)
return hours + "h " + minutes + "m";
if (minutes)
return minutes + ":" + seconds;
return minutes + ":" + pad(2, seconds);
return seconds + "s";
},