]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/downloads.jsm
Import 1.0 supporting Firefox up to 14.*
[dactyl.git] / common / modules / downloads.jsm
index 03ab19909e70014be9dc9d313c329331359d0581..e4d2f11f7981dfd9eb87406718cde8875ca61669 100644 (file)
@@ -9,6 +9,8 @@ defineModule("downloads", {
     exports: ["Download", "Downloads", "downloads"]
 }, this);
 
+this.lazyRequire("overlay", ["overlay"]);
+
 Cu.import("resource://gre/modules/DownloadUtils.jsm", this);
 
 let prefix = "DOWNLOAD_";
@@ -26,6 +28,8 @@ var Download = Class("Download", {
         this.nodes = {
             commandTarget: self
         };
+        XML.ignoreWhitespace = true;
+        XML.prettyPrinting = false;
         util.xmlToDom(
             <tr highlight="Download" key="row" xmlns:dactyl={NS} xmlns={XHTML}>
                 <td highlight="DownloadTitle">
@@ -222,8 +226,10 @@ var DownloadList = Class("DownloadList",
 
     message: Class.Memoize(function () {
 
+        XML.ignoreWhitespace = true;
+        XML.prettyPrinting = false;
         util.xmlToDom(<table highlight="Downloads" key="list" xmlns={XHTML}>
-                        <tr highlight="DownloadHead">
+                        <tr highlight="DownloadHead" key="head">
                             <span>{_("title.Title")}</span>
                             <span>{_("title.Status")}</span>
                             <span/>
@@ -251,6 +257,9 @@ var DownloadList = Class("DownloadList",
                         </tr>
                       </table>, this.document, this.nodes);
 
+        this.index = Array.indexOf(this.nodes.list.childNodes,
+                                   this.nodes.head);
+
         for (let row in iter(services.downloadManager.DBConnection
                                      .createStatement("SELECT id FROM moz_downloads")))
             this.addDownload(row.id);
@@ -272,7 +281,7 @@ var DownloadList = Class("DownloadList",
                                               .indexOf(download);
 
             this.nodes.list.insertBefore(download.nodes.row,
-                                         this.nodes.list.childNodes[index + 1]);
+                                         this.nodes.list.childNodes[index + this.index + 1]);
         }
     },
     removeDownload: function removeDownload(id) {
@@ -388,7 +397,30 @@ var DownloadList = Class("DownloadList",
     }
 });
 
-var Downloads = Module("downloads", {
+var Downloads = Module("downloads", XPCOM(Ci.nsIDownloadProgressListener), {
+    init: function () {
+        services.downloadManager.addListener(this);
+    },
+
+    destroy: function destroy() {
+        services.downloadManager.removeListener(this);
+    },
+
+    onDownloadStateChange: function (state, download) {
+        if (download.state == services.downloadManager.DOWNLOAD_FINISHED) {
+            let url   = download.source.spec;
+            let title = download.displayName;
+            let file  = download.targetFile.path;
+            let size  = download.size;
+
+
+            overlay.modules.forEach(function (modules) {
+                modules.dactyl.echomsg({ domains: [util.getHost(url)], message: _("io.downloadFinished", title, file) },
+                                       1, modules.commandline.ACTIVE_WINDOW);
+                modules.autocommands.trigger("DownloadPost", { url: url, title: title, file: file, size: size });
+            });
+        }
+    }
 }, {
 }, {
     commands: function initCommands(dactyl, modules, window) {