Bug 510707 - "Add prefs ui for imap autosync date constraints" [r=bugzilla sr=bienvenu ui-r=clarkbw]
authorBlake Winton <bwinton@latte.ca>
Tue, 08 Sep 2009 12:33:32 +0100
changeset 3581 52d3e8783d64e0b2bc2585b9bcf80ac769173057
parent 3580 eaed6a7430a2bcb02ceec52ac07adce3ee288145
child 3582 94b69751ee35b1aa477dd71287b0c5f6c0a6c00d
push id2901
push userbugzilla@standard8.plus.com
push dateTue, 08 Sep 2009 11:35:15 +0000
treeherdercomm-central@52d3e8783d64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbugzilla, bienvenu, clarkbw
bugs510707
Bug 510707 - "Add prefs ui for imap autosync date constraints" [r=bugzilla sr=bienvenu ui-r=clarkbw]
mail/locales/en-US/chrome/messenger/am-offline.dtd
mailnews/base/prefs/content/am-offline.js
mailnews/base/prefs/content/am-offline.xul
suite/locales/en-US/chrome/mailnews/pref/am-offline.dtd
--- a/mail/locales/en-US/chrome/messenger/am-offline.dtd
+++ b/mail/locales/en-US/chrome/messenger/am-offline.dtd
@@ -27,8 +27,23 @@
 <!ENTITY nntpRemoveMsgBody.label "Remove bodies from messages more than">
 <!ENTITY nntpRemoveMsgBody.accesskey "o">
 <!ENTITY offlineSelectNntp.label "Select newsgroups for offline use…">
 <!ENTITY offlineSelectNntp.accesskey "S">
 <!ENTITY offlineImapAdvancedOffline.label "Advanced…">
 <!ENTITY offlineImapAdvancedOffline.accesskey "v">
 <!ENTITY syncGroupTitle.label "Message Synchronizing">
 <!ENTITY diskspaceGroupTitle.label "Disk Space">
+
+<!-- LOCALIZATION NOTE: (useAutosyncBefore.label, useAutosyncMiddle.label, useAutosyncAfter.label):
+  The entities useAutosyncBefore.label, useAutosyncMiddle.label, and
+  useAutosyncAfter.label appear on a single line in preferences as follows:
+
+  &useAutosyncBefore.label [textbox for autosync value] &useAutosyncMiddle.label; [dropdown for autosync interval] &useAutosyncAfter.label;
+-->
+<!ENTITY useAutosyncBefore.label         "">
+<!ENTITY useAutosyncMiddle.label         "">
+<!ENTITY allInterval.label               "All">
+<!ENTITY dayInterval.label               "Days of">
+<!ENTITY weekInterval.label              "Weeks of">
+<!ENTITY monthInterval.label             "Months of">
+<!ENTITY yearInterval.label              "Years of">
+<!ENTITY useAutosyncAfter.label          "email will be stored on disk">
--- a/mailnews/base/prefs/content/am-offline.js
+++ b/mailnews/base/prefs/content/am-offline.js
@@ -90,70 +90,133 @@ function initRetentionSettings()
         document.getElementById("nntp.removeBodyMin").setAttribute("value", retentionSettings.daysToKeepBodies);
     else
         document.getElementById("nntp.removeBodyMin").setAttribute("value", "30");
 }
 
 
 function initDownloadSettings()
 {
-
     var downloadSettings =  gIncomingServer.downloadSettings;
     document.getElementById("nntp.downloadMsg").checked = downloadSettings.downloadByDate;
     document.getElementById("nntp.notDownloadRead").checked = downloadSettings.downloadUnreadOnly;
     if(downloadSettings.ageLimitOfMsgsToDownload > 0)
         document.getElementById("nntp.downloadMsgMin").setAttribute("value", downloadSettings.ageLimitOfMsgsToDownload);
     else
         document.getElementById("nntp.downloadMsgMin").setAttribute("value", "30");
  
+  // Figure out what the most natural division of the autosync pref into
+  // a value and an interval is.
+  let autosyncInterval = document.getElementById("autosyncInterval");
+  let autosyncValue = document.getElementById("autosyncValue");
+  let autosyncPref = document.getElementById("imap.autoSyncMaxAgeDays");
+  let autosyncPrefValue = (autosyncPref.value == "") ? -1 :
+                                               parseInt(autosyncPref.value, 10);
+
+  // Clear the preference until we're done initializing.
+  autosyncPref.value = "";
+
+  if (autosyncPrefValue <= 0) {
+    // Special-case values <= 0 to have an interval of "All" and a disabled
+    // value of the positive version of the preference, so we don't lose
+    // the last value the user typed.
+    autosyncInterval.value = 0;
+    autosyncValue.value = 31;
+    autosyncValue.disabled = true;
+  }
+  else {
+    // Otherwise, get the list of possible intervals, in order from
+    // largest to smallest.
+    let valuesToTest = [];
+    for (let i = autosyncInterval.itemCount - 1; i >= 0; i--)
+      valuesToTest.push(autosyncInterval.getItemAtIndex(i).value);
+
+    // and find the first one that divides the preference evenly.
+    for (let i in valuesToTest) {
+      if (!(autosyncPrefValue % valuesToTest[i])) {
+        autosyncInterval.value = valuesToTest[i];
+        autosyncValue.value = autosyncPrefValue / autosyncInterval.value;
+        break;
+      }
+    }
+  }
+  autosyncPref.value = autosyncPrefValue;
 }
 
 
 function onPreInit(account, accountValues)
 {
+  gServerType = getAccountValue(account, accountValues, "server", "type", null, false);
+  hideShowControls(gServerType);
+  gIncomingServer = account.incomingServer;
+  gIncomingServer.type = gServerType;
 
-    gServerType = getAccountValue(account, accountValues, "server", "type", null, false);
-    hideShowControls(gServerType);
-    gIncomingServer= account.incomingServer;
-    gIncomingServer.type = gServerType;
-
-    // 10 is OFFLINE_SUPPORT_LEVEL_REGULAR, see nsIMsgIncomingServer.idl
-    // currently, there is no offline without diskspace
-    var titleStringID = (gIncomingServer.offlineSupportLevel >= 10) ?
-     "prefPanel-synchronization" : "prefPanel-diskspace";
+  // 10 is OFFLINE_SUPPORT_LEVEL_REGULAR, see nsIMsgIncomingServer.idl
+  // currently, there is no offline without diskspace
+  var titleStringID = (gIncomingServer.offlineSupportLevel >= 10) ?
+   "prefPanel-synchronization" : "prefPanel-diskspace";
 
-    var prefBundle = document.getElementById("bundle_prefs");
-    var headertitle = document.getElementById("headertitle");
-    headertitle.setAttribute('title',prefBundle.getString(titleStringID));
-    document.title = prefBundle.getString(titleStringID);
+  var prefBundle = document.getElementById("bundle_prefs");
+  var headertitle = document.getElementById("headertitle");
+  headertitle.setAttribute('title',prefBundle.getString(titleStringID));
+  document.title = prefBundle.getString(titleStringID);
 
-    if (gServerType == "pop3")
-    {
-      var pop3Server = gIncomingServer.QueryInterface(Components.interfaces.nsIPop3IncomingServer);
-      // hide retention settings for deferred accounts
-      if (pop3Server.deferredToAccount.length)
-      {
-        var retentionRadio = document.getElementById("retention.keepMsg");
-        retentionRadio.setAttribute("hidden", "true");
-        var retentionLabel = document.getElementById("retentionDescriptionPop");
-        retentionLabel.setAttribute("hidden", "true");
-        var applyToFlaggedCheckbox = document.getElementById("retention.applyToFlagged");
-        applyToFlaggedCheckbox.setAttribute("hidden", "true");
-      }
+  if (gServerType == "pop3") {
+    var pop3Server = gIncomingServer.QueryInterface(Components.interfaces.nsIPop3IncomingServer);
+    // hide retention settings for deferred accounts
+    if (pop3Server.deferredToAccount.length) {
+      var retentionRadio = document.getElementById("retention.keepMsg");
+      retentionRadio.setAttribute("hidden", "true");
+      var retentionLabel = document.getElementById("retentionDescriptionPop");
+      retentionLabel.setAttribute("hidden", "true");
+      var applyToFlaggedCheckbox = document.getElementById("retention.applyToFlagged");
+      applyToFlaggedCheckbox.setAttribute("hidden", "true");
     }
+  }
 }
 
 function onClickSelect()
 {
    
     top.window.openDialog("chrome://messenger/content/msgSelectOffline.xul", "", "centerscreen,chrome,modal,titlebar,resizable=yes");
     return true;
 
 }
 
+/**
+ * Handle updates to the Autosync
+ */
+function onAutosyncChange()
+{
+  let autosyncInterval = document.getElementById("autosyncInterval");
+  let autosyncValue = document.getElementById("autosyncValue");
+  let autosyncPref = document.getElementById("imap.autoSyncMaxAgeDays");
+
+  // If we're not done initializing, don't do anything.
+  // (See initDownloadSettings() for more details.)
+  if (autosyncPref.value == "")
+    return;
+
+  // If the user selected the All option, disable the autosync and the
+  // textbox.
+  if (autosyncInterval.value == 0) {
+    autosyncPref.value = 0;
+    autosyncValue.disabled = true;
+    return;
+  }
+
+  let max = 0x7FFFFFFF / (60 * 60 * 24 * autosyncInterval.value);
+  autosyncValue.setAttribute("max", max);
+  if (autosyncValue.value > max)
+    autosyncValue.value = Math.floor(max);
+
+  autosyncValue.disabled = false;
+  autosyncPref.value = autosyncValue.value * autosyncInterval.value;
+}
+
 function onCancel()
 {
     // restore the offline flags for all folders
     restoreOfflineFolders(gOfflineMap);
     return true;
 }
 
 function onSave()
--- a/mailnews/base/prefs/content/am-offline.xul
+++ b/mailnews/base/prefs/content/am-offline.xul
@@ -49,16 +49,19 @@
 
     <stringbundle id="bundle_prefs" src="chrome://messenger/locale/prefs.properties"/> 
 
     <script type="application/x-javascript" src="chrome://messenger/content/AccountManager.js"/>
     <script type="application/x-javascript" src="chrome://messenger/content/retention.js"/>
     <script type="application/x-javascript" src="chrome://messenger/content/am-offline.js"/>
 
     <label hidden="true" wsm_persist="true" id="server.type"/>  
+    <label id="imap.autoSyncMaxAgeDays" hidden="true"
+           wsm_persist="true" preftype="int"
+           prefstring="mail.server.%serverkey%.autosync_max_age_days"/>
 
     <dialogheader id="headertitle"/>
 
     <groupbox id="offline.titlebox" hidefor="movemail,pop3,none,rss">
       <caption label="&syncGroupTitle.label;"/>
 
     <checkbox hidefor="movemail,pop3,nntp,none" 
               id="offline.folders" label="&allFoldersOffline.label;"
@@ -77,43 +80,67 @@
                 oncommand="onClickSelect()" id="selectNewsgroupsButton" class="selectForOfflineUseButton"/>
     </hbox>
 
     </groupbox>
 
     <groupbox id="diskspace.titlebox">
       <caption label="&diskspaceGroupTitle.label;" hidefor="movemail,pop3,none,rss"/>
 
+    <!-- IMAP Autosync Preference -->
+    <hbox align="center" hidefor="movemail,pop3,nntp,none,rss">
+      <label id="useAutosyncBefore">&useAutosyncBefore.label;</label>
+      <textbox id="autosyncValue" type="number" size="5" min="1"
+               class="autosync" onchange="onAutosyncChange();"
+               aria-labelledby="useAutosyncBefore autosyncValue useAutosyncMiddle autosyncInterval useAutosyncAfter"/>
+      <label id="useAutosyncMiddle">&useAutosyncMiddle.label;</label>
+      <menulist id="autosyncInterval" onselect="onAutosyncChange();">
+        <menupopup>
+          <menuitem label="&allInterval.label;" value="0"/>
+          <menuitem label="&dayInterval.label;" value="1"/>
+          <menuitem label="&weekInterval.label;" value="7"/>
+          <menuitem label="&monthInterval.label;" value="31"/>
+          <menuitem label="&yearInterval.label;" value="365"/>
+        </menupopup>
+      </menulist>
+      <label id="useAutosyncAfter" control="autosyncValue"
+             flex="1">&useAutosyncAfter.label;</label>
+    </hbox>
+
     <description hidefor="pop3,movemail,none,rss">&doNotDownload.label;</description>
     <description hidefor="imap,nntp,none,rss">&doNotDownloadPop3Movemail.label;</description>
 
     <hbox align="center" class="indent" hidefor="rss">
         <checkbox hidefor="movemail,pop3,imap,none"
                   id="nntp.notDownloadRead" wsm_persist="true"
-                  label="&nntpNotDownloadRead.label;" accesskey="&nntpNotDownloadRead.accesskey;"/>
+                  label="&nntpNotDownloadRead.label;"
+                  accesskey="&nntpNotDownloadRead.accesskey;"/>
     </hbox>
 
     <hbox align="center" class="indent" hidefor="none,rss">
         <checkbox wsm_persist="true" id="offline.notDownload"
-                  label="&offlineNotDownload.label;" accesskey="&offlineNotDownload.accesskey;"
+                  label="&offlineNotDownload.label;"
+                  accesskey="&offlineNotDownload.accesskey;"
                   oncommand="onCheckItem('offline.notDownloadMin', 'offline.notDownload');"/>
         <textbox wsm_persist="true" id="offline.notDownloadMin"
                  type="number" min="1" increment="10" size="4" value="50"
                  aria-labelledby="offline.notDownload offline.notDownloadMin kbLabel"/>
         <label value="&kb.label;" control="offline.notDownloadMin" id="kbLabel"/>
     </hbox>
 
     <hbox align="center" class="indent" hidefor="movemail,pop3,imap,none,rss">
         <checkbox wsm_persist="true" id="nntp.downloadMsg"
-                  label="&nntpDownloadMsg.label;" accesskey="&nntpDownloadMsg.accesskey;"
+                  label="&nntpDownloadMsg.label;"
+                  accesskey="&nntpDownloadMsg.accesskey;"
                   oncommand="onCheckItem('nntp.downloadMsgMin', 'nntp.downloadMsg');"/>
         <textbox wsm_persist="true" id="nntp.downloadMsgMin"
                  type="number" min="1" size="2" value="30"
                  aria-labelledby="nntp.downloadMsg nntp.downloadMsgMin daysOldLabel"/>
-        <label value="&daysOld.label;" control="nntp.downloadMsgMin" id="daysOldLabel"/>
+        <label value="&daysOld.label;" control="nntp.downloadMsgMin"
+               id="daysOldLabel"/>
     </hbox>
 
     <vbox align="start">
     <separator hidefor="none,rss"/>
     <label id="retentionDescription" hidefor="imap,pop3" class="desc" control="retention.keepMsg">&retentionCleanup.label;</label>
     <label id="retentionDescriptionImap" hidefor="movemail,pop3,nntp,none,rss" class="desc" control="retention.keepMsg">&retentionCleanupImap.label;</label>
     <label id="retentionDescriptionPop" hidefor="movemail,imap,nntp,none,rss" class="desc" control="retention.keepMsg">&retentionCleanupPop.label;</label>
 
--- a/suite/locales/en-US/chrome/mailnews/pref/am-offline.dtd
+++ b/suite/locales/en-US/chrome/mailnews/pref/am-offline.dtd
@@ -27,8 +27,23 @@
 <!ENTITY nntpRemoveMsgBody.label "Remove bodies from messages more than">
 <!ENTITY nntpRemoveMsgBody.accesskey "o">
 <!ENTITY offlineSelectNntp.label "Select newsgroups for offline use…">
 <!ENTITY offlineSelectNntp.accesskey "S">
 <!ENTITY offlineImapAdvancedOffline.label "Advanced…">
 <!ENTITY offlineImapAdvancedOffline.accesskey "v">
 <!ENTITY syncGroupTitle.label "Message Synchronizing">
 <!ENTITY diskspaceGroupTitle.label "Disk Space">
+
+<!-- LOCALIZATION NOTE: (useAutosyncBefore.label, useAutosyncMiddle.label, useAutosyncAfter.label):
+  The entities useAutosyncBefore.label, useAutosyncMiddle.label, and
+  useAutosyncAfter.label appear on a single line in preferences as follows:
+
+  &useAutosyncBefore.label [textbox for autosync value] &useAutosyncMiddle.label; [dropdown for autosync interval] &useAutosyncAfter.label;
+-->
+<!ENTITY useAutosyncBefore.label         "">
+<!ENTITY useAutosyncMiddle.label         "">
+<!ENTITY allInterval.label               "All">
+<!ENTITY dayInterval.label               "Days of">
+<!ENTITY weekInterval.label              "Weeks of">
+<!ENTITY monthInterval.label             "Months of">
+<!ENTITY yearInterval.label              "Years of">
+<!ENTITY useAutosyncAfter.label          "email will be stored on disk">