X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fdownloads.jsm;fp=common%2Fmodules%2Fdownloads.jsm;h=fdf5925b846d5d01853db1de0debec0aad957919;hb=8b6fcae7eaa413bc62d645d2d0c99835c47265e6;hp=e4d2f11f7981dfd9eb87406718cde8875ca61669;hpb=5ebd29f56d17f62011cdd596b1d351947ee534ff;p=dactyl.git diff --git a/common/modules/downloads.jsm b/common/modules/downloads.jsm index e4d2f11..fdf5925 100644 --- a/common/modules/downloads.jsm +++ b/common/modules/downloads.jsm @@ -1,18 +1,20 @@ -// Copyright (c) 2011 by Kris Maglione +// Copyright (c) 2011-2012 Kris Maglione // // 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"] -}, this); + exports: ["Download", "Downloads", "downloads"], + require: ["util"] +}); -this.lazyRequire("overlay", ["overlay"]); +lazyRequire("overlay", ["overlay"]); Cu.import("resource://gre/modules/DownloadUtils.jsm", this); +var MAX_LOAD_TIME = 10 * 1000; + let prefix = "DOWNLOAD_"; var states = iter([v, k.slice(prefix.length).toLowerCase()] for ([k, v] in Iterator(Ci.nsIDownloadManager)) @@ -28,35 +30,32 @@ var Download = Class("Download", { this.nodes = { commandTarget: self }; - XML.ignoreWhitespace = true; - XML.prettyPrinting = false; - util.xmlToDom( - - - - {self.displayName} - {self.targetFile.path} - - - - - {_("download.action.Pause")} - {_("download.action.Remove")} - {_("download.action.Resume")} - {_("download.action.Retry")} - {_("download.action.Cancel")} - {_("download.action.Delete")} - - - / - - - - - {self.source.spec} - , + DOM.fromJSON( + ["tr", { highlight: "Download", key: "row" }, + ["td", { highlight: "DownloadTitle" }, + ["span", { highlight: "Link" }, + ["a", { key: "launch", href: self.target.spec, path: self.targetFile.path }, + self.displayName], + ["span", { highlight: "LinkInfo" }, + self.targetFile.path]]], + ["td", { highlight: "DownloadState", key: "state" }], + ["td", { highlight: "DownloadButtons Buttons" }, + ["a", { highlight: "Button", href: "javascript:0", key: "pause" }, _("download.action.Pause")], + ["a", { highlight: "Button", href: "javascript:0", key: "remove" }, _("download.action.Remove")], + ["a", { highlight: "Button", href: "javascript:0", key: "resume" }, _("download.action.Resume")], + ["a", { highlight: "Button", href: "javascript:0", key: "retry" }, _("download.action.Retry")], + ["a", { highlight: "Button", href: "javascript:0", key: "cancel" }, _("download.action.Cancel")], + ["a", { highlight: "Button", href: "javascript:0", key: "delete" }, _("download.action.Delete")]], + ["td", { highlight: "DownloadProgress", key: "progress" }, + ["span", { highlight: "DownloadProgressHave", key: "progressHave" }], + "/", + ["span", { highlight: "DownloadProgressTotal", key: "progressTotal" }]],, + ["td", { highlight: "DownloadPercent", key: "percent" }], + ["td", { highlight: "DownloadSpeed", key: "speed" }], + ["td", { highlight: "DownloadTime", key: "time" }], + ["td", {}, + ["a", { highlight: "DownloadSource", key: "source", href: self.source.spec }, + self.source.spec]]], this.list.document, this.nodes); this.nodes.launch.addEventListener("click", function (event) { @@ -108,7 +107,7 @@ var Download = Class("Download", { function action() { try { if (this.MIMEInfo && this.MIMEInfo.preferredAction == this.MIMEInfo.useHelperApp) - this.MIMEInfo.launchWithFile(file); + this.MIMEInfo.launchWithFile(file.file); else file.launch(); } @@ -226,43 +225,50 @@ var DownloadList = Class("DownloadList", message: Class.Memoize(function () { - XML.ignoreWhitespace = true; - XML.prettyPrinting = false; - util.xmlToDom( - - {_("title.Title")} - {_("title.Status")} - - {_("title.Progress")} - - {_("title.Speed")} - {_("title.Time remaining")} - {_("title.Source")} - -
- - - - - -
{_("title.Totals")}:  - - {_("download.action.Clear")} - - / - - - - -
, this.document, this.nodes); + DOM.fromJSON(["table", { highlight: "Downloads", key: "list" }, + ["tr", { highlight: "DownloadHead", key: "head" }, + ["span", {}, _("title.Title")], + ["span", {}, _("title.Status")], + ["span"], + ["span", {}, _("title.Progress")], + ["span"], + ["span", {}, _("title.Speed")], + ["span", {}, _("title.Time remaining")], + ["span", {}, _("title.Source")]], + ["tr", { highlight: "Download" }, + ["span", {}, + ["div", { style: "min-height: 1ex; /* FIXME */" }]]], + ["tr", { highlight: "Download", key: "totals", active: "true" }, + ["td", {}, + ["span", { highlight: "Title" }, + _("title.Totals") + ":"], + " ", + ["span", { key: "total" }]], + ["td"], + ["td", { highlight: "DownloadButtons" }, + ["a", { highlight: "Button", href: "javascript:0", key: "clear" }, _("download.action.Clear")]], + ["td", { highlight: "DownloadProgress", key: "progress" }, + ["span", { highlight: "DownloadProgressHave", key: "progressHave" }], + "/", + ["span", { highlight: "DownloadProgressTotal", key: "progressTotal" }]], + ["td", { highlight: "DownloadPercent", key: "percent" }], + ["td", { highlight: "DownloadSpeed", key: "speed" }], + ["td", { highlight: "DownloadTime", key: "time" }], + ["td"]]], + this.document, this.nodes); this.index = Array.indexOf(this.nodes.list.childNodes, this.nodes.head); + let start = Date.now(); for (let row in iter(services.downloadManager.DBConnection - .createStatement("SELECT id FROM moz_downloads"))) + .createStatement("SELECT id FROM moz_downloads"))) { + if (Date.now() - start > MAX_LOAD_TIME) { + util.dactyl.warn(_("download.givingUpAfter", (Date.now() - start) / 1000)); + break; + } this.addDownload(row.id); + } this.update(); util.addObserver(this); @@ -402,7 +408,7 @@ var Downloads = Module("downloads", XPCOM(Ci.nsIDownloadProgressListener), { services.downloadManager.addListener(this); }, - destroy: function destroy() { + cleanup: function destroy() { services.downloadManager.removeListener(this); },