Bug 781762 - Add the ability to delete all downloaded files at one time, r=margaret
authorMark Capella <markcapella@twcny.rr.com>
Fri, 28 Sep 2012 01:52:43 -0400
changeset 108385 85a1897826b5c25684aab983b4dca5fd83a6b4e9
parent 108384 52be204da1cfa0c3188d744ba21a5563affc8e34
child 108386 005ccc9a2f2f536ca16f1d8d0d9c63ba2a9359ba
push id15503
push usermarkcapella@twcny.rr.com
push dateFri, 28 Sep 2012 05:57:51 +0000
treeherdermozilla-inbound@85a1897826b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs781762
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 781762 - Add the ability to delete all downloaded files at one time, r=margaret
mobile/android/chrome/content/aboutDownloads.js
mobile/android/locales/en-US/chrome/aboutDownloads.properties
--- a/mobile/android/chrome/content/aboutDownloads.js
+++ b/mobile/android/chrome/content/aboutDownloads.js
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 let Ci = Components.interfaces, Cc = Components.classes, Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DownloadUtils.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/PluralForm.jsm");
 
 let gStrings = Services.strings.createBundle("chrome://browser/locale/aboutDownloads.properties");
 
 let downloadTemplate =
 "<li downloadID='{id}' role='button' state='{state}'>" +
   "<img class='icon' src='{icon}'/>" +
   "<div class='details'>" +
      "<div class='row'>" +
@@ -106,26 +107,35 @@ let Downloads = {
                                                 contextmenus.SelectorContext("li[state='" + this._dlmgr.DOWNLOAD_DOWNLOADING + "']," +
                                                                              "li[state='" + this._dlmgr.DOWNLOAD_NOTSTARTED + "']," +
                                                                              "li[state='" + this._dlmgr.DOWNLOAD_QUEUED + "']," +
                                                                              "li[state='" + this._dlmgr.DOWNLOAD_PAUSED + "']"),
       function (aTarget) {
         Downloads.cancelDownload(aTarget);
       }
     );
+
+    // Delete All shown when item is finished, canceled, or failed
+    Downloads.deleteAllMenuItem = contextmenus.add(gStrings.GetStringFromName("downloadAction.deleteAll"),
+                                                   contextmenus.SelectorContext("li[state='" + this._dlmgr.DOWNLOAD_FINISHED + "']," +
+                                                                                "li[state='" + this._dlmgr.DOWNLOAD_CANCELED + "']," +
+                                                                                "li[state='" + this._dlmgr.DOWNLOAD_FAILED + "']"),
+                                                   this.deleteAll.bind(this)
+    );
   },
 
   uninit: function dl_uninit() {
     let contextmenus = gChromeWin.NativeWindow.contextmenus;
     contextmenus.remove(this.openMenuItem);
     contextmenus.remove(this.removeMenuItem);
     contextmenus.remove(this.pauseMenuItem);
     contextmenus.remove(this.resumeMenuItem);
     contextmenus.remove(this.retryMenuItem);
     contextmenus.remove(this.cancelMenuItem);
+    contextmenus.remove(this.deleteAllMenuItem);
 
     Services.obs.removeObserver(this, "dl-start");
     Services.obs.removeObserver(this, "dl-failed");
     Services.obs.removeObserver(this, "dl-scanning");
     Services.obs.removeObserver(this, "dl-done");
     Services.obs.removeObserver(this, "dl-blocked");
     Services.obs.removeObserver(this, "dl-dirty");
     Services.obs.removeObserver(this, "dl-cancel");
@@ -405,16 +415,35 @@ let Downloads = {
 
     this._list.removeChild(aItem);
 
     try {
       if (f) f.remove(false);
     } catch(ex) { }
   },
 
+  deleteAll: function dl_deleteAll() {
+    let title = gStrings.GetStringFromName("downloadAction.deleteAll");
+    let messageForm = gStrings.GetStringFromName("downloadMessage.deleteAll");
+    let elements = this._list.querySelectorAll("li[state='" + this._dlmgr.DOWNLOAD_FINISHED + "']," +
+                                               "li[state='" + this._dlmgr.DOWNLOAD_CANCELED + "']," +
+                                               "li[state='" + this._dlmgr.DOWNLOAD_FAILED + "']");
+    let message = PluralForm.get(elements.length, messageForm)
+                            .replace("#1", elements.length);
+    let flags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_OK +
+                Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL;
+    let choice = Services.prompt.confirmEx(null, title, message, flags,
+                                           null, null, null, null, {});
+    if (choice == 0) {
+      for (let i = 0; i < elements.length; i++) {
+        this.removeDownload(elements[i]);
+      }
+    }
+  },
+
   pauseDownload: function dl_pauseDownload(aItem) {
     try {
       let download = this._getDownloadForElement(aItem);
       this._dlmgr.pauseDownload(aItem.getAttribute("downloadID"));
       this._updateDownloadRow(aItem);
     } catch (ex) {
       console.log("Error: pauseDownload() " + ex);  
     }
--- a/mobile/android/locales/en-US/chrome/aboutDownloads.properties
+++ b/mobile/android/locales/en-US/chrome/aboutDownloads.properties
@@ -1,14 +1,21 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 downloadAction.open=Open
 downloadAction.remove=Delete
+downloadAction.deleteAll=Delete All
+
+# LOCALIZATION NOTE (downloadMessage.deleteAll):
+# Semi-colon list of plural forms. See:
+# http://developer.mozilla.org/en/docs/Localization_and_Plurals
+downloadMessage.deleteAll=Delete this download?;Delete #1 downloads?
+
 downloadAction.pause=Pause
 downloadAction.resume=Resume
 downloadAction.cancel=Cancel
 downloadAction.retry=Retry
 downloadState.downloading=Downloading…
 downloadState.canceled=Canceled
 downloadState.failed=Failed
 downloadState.paused=Paused