//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
-"use strict";
+/* use strict */
Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("downloads", {
- exports: ["Download", "Downloads", "downloads"],
- use: ["io", "messages", "prefs", "services", "util"]
+ exports: ["Download", "Downloads", "downloads"]
}, this);
Cu.import("resource://gre/modules/DownloadUtils.jsm", this);
var Download = Class("Download", {
init: function init(id, list) {
- let self = XPCSafeJSObjectWrapper(services.downloadManager.getDownload(id));
- self.__proto__ = this;
- this.instance = this;
+ let self = this;
+ this.download = services.downloadManager.getDownload(id);
this.list = list;
this.nodes = {
get alive() this.inState(["downloading", "notstarted", "paused", "queued", "scanning"]),
- allowedCommands: Class.memoize(function () let (self = this) ({
+ allowedCommands: Class.Memoize(function () let (self = this) ({
get cancel() self.cancelable && self.inState(["downloading", "paused", "starting"]),
get delete() !this.cancel && self.targetFile.exists(),
get launch() self.targetFile.exists() && self.inState(["finished"]),
}
}
- let total = this.nodes.progressTotal.textContent = this.size ? util.formatBytes(this.size, 1, true) : _("download.unknown");
+ let total = this.nodes.progressTotal.textContent = this.size || !this.nActive ? util.formatBytes(this.size, 1, true)
+ : _("download.unknown");
let suffix = RegExp(/( [a-z]+)?$/i.exec(total)[0] + "$");
this.nodes.progressHave.textContent = util.formatBytes(this.amountTransferred, 1, true).replace(suffix, "");
this.updateProgress();
}
});
+Object.keys(XPCOMShim([Ci.nsIDownload])).forEach(function (key) {
+ if (!(key in Download.prototype))
+ Object.defineProperty(Download.prototype, key, {
+ get: function get() this.download[key],
+ set: function set(val) this.download[key] = val,
+ configurable: true
+ });
+});
var DownloadList = Class("DownloadList",
XPCOM([Ci.nsIDownloadProgressListener,
services.downloadManager.removeListener(this);
},
- message: Class.memoize(function () {
+ message: Class.Memoize(function () {
util.xmlToDom(<table highlight="Downloads" key="list" xmlns={XHTML}>
<tr highlight="DownloadHead">
this.cleanup();
},
- allowedCommands: Class.memoize(function () let (self = this) ({
+ allowedCommands: Class.Memoize(function () let (self = this) ({
get clear() values(self.downloads).some(function (dl) dl.allowedCommands.remove)
})),
updateProgress: function updateProgress() {
let downloads = values(this.downloads).toArray();
+ let active = downloads.filter(function (d) d.alive);
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);
+ this[prop] = active.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 = _("download.nActive", active);
+ this.nActive = active.length;
+ if (active.length)
+ this.nodes.total.textContent = _("download.nActive", active.length);
else for (let key in values(["total", "percent", "speed", "time"]))
this.nodes[key].textContent = "";