[Conkeror] [PATCH 1/2] download manager: show display name, allow target file name to change

David Kettler kettler at internode.on.net
Wed Feb 18 04:01:51 PST 2009


The download manager will now update the display of the target file
name each time there is a change in download state.  If the display
name differs from the (basename of) the target name, it is shown
parenthetically.  Changes to the names in hooks are thus reflected in
the display.

The download manager handling of the target file is changed.  It is
now maintained explicitly and can be specified in register_download.
This is necessary because the targetFile property is immutable.

These changes allow, for instance, downloads to a file with a
temporary name that is changed to the final name when the download is
finished.
---
 modules/download-manager.js |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/modules/download-manager.js b/modules/download-manager.js
index 888ef6a..3fd146a 100644
--- a/modules/download-manager.js
+++ b/modules/download-manager.js
@@ -169,18 +169,25 @@ const DOWNLOAD_NOT_TEMPORARY = 0;
 const DOWNLOAD_TEMPORARY_FOR_ACTION = 1;
 const DOWNLOAD_TEMPORARY_FOR_COMMAND = 2;
 
-function download_info(source_buffer, mozilla_info) {
+function download_info(source_buffer, mozilla_info, target_file) {
     this.source_buffer = source_buffer;
+    this.target_file = target_file;
     if (mozilla_info != null)
         this.attach(mozilla_info);
 }
 download_info.prototype = {
     attach : function (mozilla_info) {
+        if (!this.target_file)
+            target_file = this.mozilla_info.targetFile;
+        else if (this.target_file.path != mozilla_info.targetFile.path)
+            throw interactive_error("Download target file unexpected.");
         this.mozilla_info = mozilla_info;
         id_to_download_info[mozilla_info.id] = this;
         download_added_hook.run(this);
     },
 
+    target_file : null,
+
     shell_command : null,
 
     shell_command_cwd : null,
@@ -202,7 +209,7 @@ download_info.prototype = {
 
     // Reflectors to properties of nsIDownload
     get state () { return this.mozilla_info.state; },
-    get target_file () { return this.mozilla_info.targetFile; },
+    get display_name () { return this.mozilla_info.displayName; },
     get amount_transferred () { return this.mozilla_info.amountTransferred; },
     get percent_complete () { return this.mozilla_info.percentComplete; },
     get size () {
@@ -227,6 +234,14 @@ download_info.prototype = {
     get id () { return this.mozilla_info.id; },
     get referrer () { return this.mozilla_info.referrer; },
 
+    target_file_text : function() {
+        let target = this.target_file.path;
+        let display = this.display_name;
+        if (target.indexOf(display, target.length - display.length) == -1)
+            target += " (" + display + ")";
+        return target;
+    },
+
     throw_if_removed : function () {
         if (this.removed)
             throw interactive_error("Download has already been removed from the download manager.");
@@ -357,8 +372,8 @@ download_info.prototype = {
 var define_download_local_hook = simple_local_hook_definer();
 
 // FIXME: add more parameters
-function register_download(buffer, source_uri) {
-    var info = new download_info(buffer);
+function register_download(buffer, source_uri, target_file) {
+    var info = new download_info(buffer, null, target_file);
     info.registered_time_stamp = Date.now();
     info.registered_source_uri = source_uri;
     unmanaged_download_info_list.push(info);
@@ -599,6 +614,7 @@ download_buffer.prototype = {
 
         // Remove all node references
         delete this.status_textnode;
+        delete this.target_file_node;
         delete this.transferred_div_node;
         delete this.transferred_textnode;
         delete this.progress_container_node;
@@ -719,7 +735,7 @@ download_buffer.prototype = {
             target_label = "Target:";
         g.text(target_label, label);
         value = g.element("div", div, "class", "download-value");
-        g.text(info.target_file.path, value);
+        this.target_file_node = g.text("", value);
 
         div = g.element("div", d.body, "class", "download-info", "id", "download-mime-type");
         label = g.element("div", div, "class", "download-label");
@@ -791,6 +807,7 @@ download_buffer.prototype = {
             break;
         }
         this.status_textnode.nodeValue = label + ":";
+        this.target_file_node.nodeValue = info.target_file_text();
         this.update_time_field();
 
         var tran_text = "";
-- 
1.5.6.5



More information about the Conkeror mailing list