Bug 180623 - Add Date & Time for started (or added) download, r/sr=Neil
authorJens Hatlak <jh@junetz.de>
Tue, 18 Aug 2009 22:55:30 +0200
changeset 3326 2870eb8a8bebbe917a628fb9989650cc4d0be44a
parent 3325 f59c45dbd7c99addaa7adaf07965626d5004a69b
child 3327 8c234c13c206c298db745b29e50c27932d5f1372
push idunknown
push userunknown
push dateunknown
bugs180623
Bug 180623 - Add Date & Time for started (or added) download, r/sr=Neil
suite/common/downloads/downloadmanager.xul
suite/common/downloads/treeView.js
suite/locales/en-US/chrome/common/downloads/downloadmanager.dtd
--- a/suite/common/downloads/downloadmanager.xul
+++ b/suite/common/downloads/downloadmanager.xul
@@ -285,16 +285,22 @@
                         label="&col.transferred.label;"
                         accesskey="&col.transferred.accesskey;"/>
               <menuitem id="menu_ToggleTransferRate" type="checkbox"
                         label="&col.transferrate.label;"
                         accesskey="&col.transferrate.accesskey;"/>
               <menuitem id="menu_ToggleTimeElapsed" type="checkbox"
                         label="&col.timeelapsed.label;"
                         accesskey="&col.timeelapsed.accesskey;"/>
+              <menuitem id="menu_ToggleStartTime" type="checkbox"
+                        label="&col.starttime.label;"
+                        accesskey="&col.starttime.accesskey;"/>
+              <menuitem id="menu_ToggleEndTime" type="checkbox"
+                        label="&col.endtime.label;"
+                        accesskey="&col.endtime.accesskey;"/>
               <menuitem id="menu_ToggleProgressPercent" type="checkbox"
                         label="&col.progresstext.label;"
                         accesskey="&col.progresstext.accesskey;"/>
               <menuitem id="menu_ToggleSource" type="checkbox"
                         label="&col.source.label;"
                         accesskey="&col.source.accesskey;"/>
             </menupopup>
           </menu>
@@ -322,16 +328,22 @@
                         label="&col.transferred.label;"
                         accesskey="&col.transferred.accesskey;"/>
               <menuitem id="menu_SortByTransferRate" type="radio" name="columns"
                         label="&col.transferrate.label;"
                         accesskey="&col.transferrate.accesskey;"/>
               <menuitem id="menu_SortByTimeElapsed" type="radio" name="columns"
                         label="&col.timeelapsed.label;"
                         accesskey="&col.timeelapsed.accesskey;"/>
+              <menuitem id="menu_SortByStartTime" type="radio" name="columns"
+                        label="&col.starttime.label;"
+                        accesskey="&col.starttime.accesskey;"/>
+              <menuitem id="menu_SortByEndTime" type="radio" name="columns"
+                        label="&col.endtime.label;"
+                        accesskey="&col.endtime.accesskey;"/>
               <menuitem id="menu_SortByProgressPercent" type="radio" name="columns"
                         label="&col.progresstext.label;"
                         accesskey="&col.progresstext.accesskey;"/>
               <menuitem id="menu_SortBySource" type="radio" name="columns"
                         label="&col.source.label;"
                         accesskey="&col.source.accesskey;"/>
               <menuseparator/>
               <menuitem id="menu_SortAscending" type="radio" name="direction"
@@ -438,16 +450,28 @@
                persist="width hidden ordinal sortActive sortDirection"/>
       <splitter class="tree-splitter"/>
       <treecol id="TimeElapsed" hidden="true"
                label="&col.timeelapsed.label;"
                tooltiptext="&col.timeelapsed.tooltip;"
                class="sortDirectionIndicator" flex="1"
                persist="width hidden ordinal sortActive sortDirection"/>
       <splitter class="tree-splitter"/>
+      <treecol id="StartTime" hidden="true"
+               label="&col.starttime.label;"
+               tooltiptext="&col.starttime.tooltip;"
+               class="sortDirectionIndicator" flex="1"
+               persist="width hidden ordinal sortActive sortDirection"/>
+      <splitter class="tree-splitter"/>
+      <treecol id="EndTime" hidden="true"
+               label="&col.endtime.label;"
+               tooltiptext="&col.endtime.tooltip;"
+               class="sortDirectionIndicator" flex="1"
+               persist="width hidden ordinal sortActive sortDirection"/>
+      <splitter class="tree-splitter"/>
       <treecol id="Source" hidden="true"
                label="&col.source.label;"
                tooltiptext="&col.source.tooltip;"
                class="sortDirectionIndicator" flex="1"
                persist="width hidden ordinal sortActive sortDirection"/>
     </treecols>
     <treechildren/>
   </tree>
--- a/suite/common/downloads/treeView.js
+++ b/suite/common/downloads/treeView.js
@@ -204,16 +204,24 @@ DownloadTreeView.prototype = {
           var seconds = (dl.endTime - dl.startTime) / 1000;
           var [time1, unit1, time2, unit2] =
             DownloadUtils.convertTimeUnits(seconds);
           if (seconds < 3600 || time2 == 0)
             return this._dlbundle.getFormattedString("timeSingle", [time1, unit1]);
           return this._dlbundle.getFormattedString("timeDouble", [time1, unit1, time2, unit2]);
         }
         return "";
+      case "StartTime":
+        if (dl.startTime)
+          return this._convertTimeToString(dl.startTime);
+        return "";
+      case "EndTime":
+        if (dl.endTime)
+          return this._convertTimeToString(dl.endTime);
+        return "";
       case "Source":
         return dl.uri;
     }
     return "";
   },
 
   setTree: function(aTree) {
     this._tree = aTree;
@@ -544,16 +552,24 @@ DownloadTreeView.prototype = {
         case "TimeElapsed":
           comp_a = (a.endTime && a.startTime && (a.endTime > a.startTime))
                    ? a.endTime - a.startTime
                    : 0;
           comp_b = (b.endTime && b.startTime && (b.endTime > b.startTime))
                    ? b.endTime - b.startTime
                    : 0;
           break;
+        case "StartTime":
+          comp_a = a.startTime;
+          comp_b = b.startTime;
+          break;
+        case "EndTime":
+          comp_a = a.endTime;
+          comp_b = b.endTime;
+          break;
         case "Source":
           comp_a = a.uri;
           comp_b = b.uri;
           break;
         case "unsorted": // Special case for reverting to original order
         default:
           comp_a = a.listIndex;
           comp_b = b.listIndex;
@@ -584,19 +600,28 @@ DownloadTreeView.prototype = {
 
   // ***** local member vars *****
 
   _tree: null,
   _dlBundle: null,
   _statement: null,
   _lastListIndex: 0,
   _selectionCache: null,
+  __dateService: null,
 
   // ***** local helper functions *****
 
+  get _dateService() {
+    if (!this.__dateService) {
+      this.__dateService = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
+                                     .getService(Components.interfaces.nsIScriptableDateFormat);
+    }
+    return this.__dateService;
+  },
+
   // Get array index in _dlList for a given download ID
   _getIdxForID: function(aDlID) {
     var len = this._dlList.length;
     for (let idx = 0; idx < len; idx++) {
       if (this._dlList[idx].dlid == aDlID)
         return idx;
     }
     return -1;
@@ -636,9 +661,36 @@ DownloadTreeView.prototype = {
       var row = this._getIdxForID(dlid);
       if (row != -1)
         this.selection.rangedSelect(row, row, true);
     }
     // Work done, clear the cache
     this._selectionCache = null;
   },
 
+  _convertTimeToString: function(aTime) {
+    var timeObj = new Date(aTime);
+
+    // Check if it is today and only display the time.  Only bother
+    // checking for today if it's within the last 24 hours, since
+    // computing midnight is not really cheap. Sometimes we may get dates
+    // in the future, so always show those.
+    var ago = Date.now() - aTime;
+    var dateFormat = Components.interfaces.nsIScriptableDateFormat.dateFormatShort;
+    if (ago > -10000 && ago < (1000 * 24 * 60 * 60)) {
+      var midnight = new Date();
+      midnight.setHours(0);
+      midnight.setMinutes(0);
+      midnight.setSeconds(0);
+      midnight.setMilliseconds(0);
+
+      if (aTime > midnight.getTime())
+        dateFormat = Components.interfaces.nsIScriptableDateFormat.dateFormatNone;
+    }
+
+    return (this._dateService.FormatDateTime("", dateFormat,
+      Components.interfaces.nsIScriptableDateFormat.timeFormatNoSeconds,
+      timeObj.getFullYear(), timeObj.getMonth() + 1,
+      timeObj.getDate(), timeObj.getHours(),
+      timeObj.getMinutes(), timeObj.getSeconds()));
+  },
+
 };
--- a/suite/locales/en-US/chrome/common/downloads/downloadmanager.dtd
+++ b/suite/locales/en-US/chrome/common/downloads/downloadmanager.dtd
@@ -34,16 +34,22 @@
 <!ENTITY col.transferred.accesskey       "T">
 <!ENTITY col.transferred.tooltip         "Transferred">
 <!ENTITY col.transferrate.label          "Speed">
 <!ENTITY col.transferrate.accesskey      "d">
 <!ENTITY col.transferrate.tooltip        "Speed">
 <!ENTITY col.timeelapsed.label           "Time Elapsed">
 <!ENTITY col.timeelapsed.accesskey       "E">
 <!ENTITY col.timeelapsed.tooltip         "Time Elapsed">
+<!ENTITY col.starttime.label             "Start Time">
+<!ENTITY col.starttime.accesskey         "a">
+<!ENTITY col.starttime.tooltip           "Start Time">
+<!ENTITY col.endtime.label               "End Time">
+<!ENTITY col.endtime.accesskey           "i">
+<!ENTITY col.endtime.tooltip             "End Time">
 <!ENTITY col.progresstext.label          "&#37;">
 <!ENTITY col.progresstext.accesskey      "&#37;">
 <!ENTITY col.progresstext.tooltip        "Progress (&#37;)">
 <!ENTITY col.source.label                "Source">
 <!ENTITY col.source.accesskey            "o">
 <!ENTITY col.source.tooltip              "Source">
 
 <!ENTITY view.columns.label              "Show Columns">