Bug 594744 - Ported cache preferences from bug 559942. r=IanN sr=Neil
authorEdmund Wong <ewong@pw-wspx.org>
Fri, 19 Nov 2010 16:33:00 +0100
changeset 6732 e5d2d6c17145758939eace7a741d377ee26ec1c7
parent 6731 09778c4043bc4e72c6d85e593a67f8a89a63fbca
child 6733 e8aea1be2e425dd70aecb7564019c2b0403de7c6
push idunknown
push userunknown
push dateunknown
reviewersIanN, Neil
bugs594744, 559942
Bug 594744 - Ported cache preferences from bug 559942. r=IanN sr=Neil
suite/common/pref/pref-cache.js
suite/common/pref/pref-cache.xul
suite/locales/en-US/chrome/common/pref/pref-cache.dtd
suite/locales/en-US/chrome/common/pref/prefutilities.properties
--- a/suite/common/pref/pref-cache.js
+++ b/suite/common/pref/pref-cache.js
@@ -34,16 +34,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
+
+function Startup()
+{
+  updateActualCacheSize();
+}
+
 // because the cache is in kilobytes, and the UI is in megabytes.
 function ReadCacheDiskCapacity()
 {
   var pref = document.getElementById("browser.cache.disk.capacity");
   return pref.value >> 10;
 }
 
 function WriteCacheDiskCapacity(aField)
@@ -95,8 +102,51 @@ function CacheSelectFolder()
 }
 
 function ClearDiskAndMemCache()
 {
   Components.classes["@mozilla.org/network/cache-service;1"]
             .getService(Components.interfaces.nsICacheService)
             .evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
 }
+
+function updateCacheSizeUI(cacheSizeEnabled)
+{
+  document.getElementById("browserCacheDiskCacheBefore").disabled = cacheSizeEnabled;
+  document.getElementById("browserCacheDiskCache").disabled = cacheSizeEnabled;
+  document.getElementById("browserCacheDiskCacheAfter").disabled = cacheSizeEnabled;
+}
+
+function ReadSmartSizeEnabled()
+{
+  var enabled = document.getElementById("browser.cache.disk.smart_size.enabled").value;
+  updateCacheSizeUI(enabled);
+  return enabled;
+}
+
+function updateActualCacheSize()
+{
+  var visitor = {
+    visitDevice: function (deviceID, deviceInfo)
+    {
+      if (deviceID == "disk") {
+        var actualSizeLabel = document.getElementById("cacheSizeInfo");
+        var sizeStrings = DownloadUtils.convertByteUnits(deviceInfo.totalSize);
+        var prefStrBundle = document.getElementById("bundle_prefutilities");
+        var sizeStr = prefStrBundle.getFormattedString("cacheSizeInfo",
+                                                        sizeStrings);
+        actualSizeLabel.textContent = sizeStr;
+      }
+      // Do not enumerate entries
+      return false;
+    },
+
+    visitEntry: function (deviceID, entryInfo)
+    {
+      // Do not enumerate entries.
+      return false;
+    }
+  };
+
+  Components.classes["@mozilla.org/network/cache-service;1"]
+            .getService(Components.interfaces.nsICacheService)
+            .visitEntries(visitor);
+}
--- a/suite/common/pref/pref-cache.xul
+++ b/suite/common/pref/pref-cache.xul
@@ -50,16 +50,19 @@
   <prefpane id="cache_pane"
             label="&pref.cache.title;"
             script="chrome://communicator/content/pref/pref-cache.js">
 
     <preferences>
       <preference id="browser.cache.disk.capacity"
                   name="browser.cache.disk.capacity"
                   type="int"/>
+      <preference id="browser.cache.disk.smart_size.enabled"
+                  name="browser.cache.disk.smart_size.enabled"
+                  type="bool"/>
       <preference id="pref.advanced.cache.disable_button.clear_disk"
                   name="pref.advanced.cache.disable_button.clear_disk"
                   type="bool"/>
       <preference id="browser.cache.check_doc_frequency"
                   name="browser.cache.check_doc_frequency"
                   type="int"/>
       <preference id="network.prefetch-next"
                   name="network.prefetch-next"
@@ -69,30 +72,38 @@
                   type="file"/>
     </preferences>
 
     <groupbox>
       <caption label="&pref.cache.caption;"/>
 
       <description>&cachePara;</description>
 
+      <vbox align="start">
+        <label id="cacheSizeInfo"/>
+        <checkbox id="allowSmartSize"
+                  label="&cacheCheck.label;"
+                  accesskey="&cacheCheck.accesskey;"
+                  onsyncfrompreference="return document.getElementById('cache_pane').ReadSmartSizeEnabled();"
+                  preference="browser.cache.disk.smart_size.enabled"/>
+      </vbox>
       <hbox align="center">
         <label id="browserCacheDiskCacheBefore"
-               value="&diskCache.label;"
-               accesskey="&diskCache.accesskey;"
+               value="&diskCacheUpTo.label;"
+               accesskey="&diskCacheUpTo.accesskey;"
                control="browserCacheDiskCache"/>
         <textbox id="browserCacheDiskCache"
                  size="5"
                  type="number"
                  aria-labelledby="browserCacheDiskCacheBefore browserCacheDiskCache browserCacheDiskCacheAfter"
                  preference="browser.cache.disk.capacity"
                  onsyncfrompreference="return document.getElementById('cache_pane').ReadCacheDiskCapacity();"
                  onsynctopreference="return document.getElementById('cache_pane').WriteCacheDiskCapacity(this);"/>
         <label id="browserCacheDiskCacheAfter"
-               value="&mbytes;"/>
+               value="&spaceMbytes;"/>
         <button label="&clearDiskCache.label;"
                 accesskey="&clearDiskCache.accesskey;"
                 oncommand="ClearDiskAndMemCache();"
                 id="clearDiskCache"
                 preference="pref.advanced.cache.disable_button.clear_disk"/>
       </hbox>
 
       <vbox>
@@ -111,38 +122,30 @@
                       attribute="disabled"/>
           </button>
         </hbox>
       </vbox>
       <description>&diskCacheFolderExplanation;</description>
 
       <separator class="thin"/>
 
-      <description>&docCache;</description>
+      <label control="browserCacheCheckDocFrequency"
+             value="&docCache.label;"
+             accesskey="&docCache.accesskey;"/>
       <hbox align="start">
-        <radiogroup id="browserCacheCheckDocFrequency"
-                    orient="horizontal"
-                    preference="browser.cache.check_doc_frequency">
-          <vbox flex="1">
-            <radio value="1"
-                   label="&everyTimeRadio.label;"
-                   accesskey="&everyTimeRadio.accesskey;"/>
-            <radio value="3"
-                   label="&autoRadio.label;"
-                   accesskey="&autoRadio.accesskey;"/>
-          </vbox>
-          <vbox flex="1">
-            <radio value="0"
-                   label="&oncePsessionRadio.label;"
-                   accesskey="&oncePsessionRadio.accesskey;"/>
-            <radio value="2"
-                   label="&neverRadio.label;"
-                   accesskey="&neverRadio.accesskey;"/>
-          </vbox>
-        </radiogroup>
+        <menulist id="browserCacheCheckDocFrequency"
+                  class="indent"
+                  preference="browser.cache.check_doc_frequency">
+          <menupopup>
+            <menuitem value="1" label="&checkEveryTime.label;"/>
+            <menuitem value="3" label="&checkAutomatically.label;"/>
+            <menuitem value="0" label="&checkOncePerSession.label;"/>
+            <menuitem value="2" label="&checkNever.label;"/>
+          </menupopup>
+        </menulist>
       </hbox>
 
     </groupbox>
 
     <groupbox id="prefetch">
       <caption id="prefetchLabel" label="&prefetchTitle.label;"/>
       <vbox id="prefetchBox" align="start">
         <checkbox id="enablePrefetch"
--- a/suite/locales/en-US/chrome/common/pref/pref-cache.dtd
+++ b/suite/locales/en-US/chrome/common/pref/pref-cache.dtd
@@ -1,28 +1,27 @@
 <!-- extracted from content/pref-cache.xul -->
 
 <!--LOCALIZATION NOTE : FILE Cache prefs dialog -->
 <!ENTITY pref.cache.title                "Cache">
 <!ENTITY pref.cache.caption              "Set Cache Options">
 <!ENTITY cachePara                       "The cache keeps copies of frequently visited web pages on your hard disk. (Clicking Reload always shows you the latest version of a page.)">
-<!ENTITY diskCache.label                 "Size:">
-<!ENTITY diskCache.accesskey             "S">
-<!ENTITY mbytes                          "MB">
+<!ENTITY cacheCheck.label                "Let &brandShortName; manage the size of my cache.">
+<!ENTITY cacheCheck.accesskey            "L">
+<!ENTITY diskCacheUpTo.label             "Use up to">
+<!ENTITY diskCacheUpTo.accesskey         "U">
+<!ENTITY spaceMbytes                     "MB of disk space for the cache.">
 <!ENTITY diskCacheFolder.label           "Cache Folder Location:">
 <!ENTITY clearDiskCache.label            "Clear Cache">
 <!ENTITY clearDiskCache.accesskey        "C">
 <!ENTITY chooseDiskCacheFolder.label     "Choose Folder…">
 <!ENTITY chooseDiskCacheFolder.accesskey "F">
 <!ENTITY diskCacheFolderExplanation      "Cache files will be stored in a subfolder named &quot;Cache&quot; of the directory you specify. Restart &brandShortName; for changes to take effect.">
-<!ENTITY docCache                        "Compare the page in the cache to the page on the network:">
-<!ENTITY oncePsessionRadio.label         "Once per session">
-<!ENTITY oncePsessionRadio.accesskey     "O">
-<!ENTITY everyTimeRadio.label            "Every time I view the page">
-<!ENTITY everyTimeRadio.accesskey        "E">
-<!ENTITY neverRadio.label                "Never">
-<!ENTITY neverRadio.accesskey            "N">
-<!ENTITY autoRadio.label                 "When the page is out of date">
-<!ENTITY autoRadio.accesskey             "W">
+<!ENTITY docCache.label                  "Compare the page in the cache to the page on the network:">
+<!ENTITY docCache.accesskey              "m">
+<!ENTITY checkOncePerSession.label       "Once per session">
+<!ENTITY checkEveryTime.label            "Every time I view the page">
+<!ENTITY checkNever.label                "Never">
+<!ENTITY checkAutomatically.label        "When the page is out of date">
 
 <!ENTITY prefetchTitle.label             "Link Prefetching">
 <!ENTITY enablePrefetch.label            "Prefetch web pages when idle, so that links in web pages designed for prefetching can load more quickly">
 <!ENTITY enablePrefetch.accesskey        "P">
--- a/suite/locales/en-US/chrome/common/pref/prefutilities.properties
+++ b/suite/locales/en-US/chrome/common/pref/prefutilities.properties
@@ -1,9 +1,11 @@
 cachefolder=Choose Cache Folder
+#LOCALIZATION NOTE (%1$S) is the size and (%2$S) is the unit of disk space.
+cacheSizeInfo=Your cache is currently using %1$S %2$S of disk space.
 choosehomepage=Choose Home Page
 downloadfolder=Choose a Download Folder
 desktopFolderName=Desktop
 downloadsFolderName=Downloads
 choosesound=Choose a sound
 
 SoundFiles=Sounds