land davida's patch for new imap offline account settings, sr=bienvenu 436615
authorDavid Bienvenu <bienvenu@nventure.com>
Tue, 16 Sep 2008 18:51:32 -0700
changeset 349 5ad568b3a57beb8e190f0dbc9b0ab31a1fe1cb69
parent 348 428ab4153a1ffc3a71946c8126811e0ca984fbc3
child 350 bc29303430f462870e6f28087e8a75290e6e85ce
push idunknown
push userunknown
push dateunknown
reviewersbienvenu
bugs436615
land davida's patch for new imap offline account settings, sr=bienvenu 436615
mail/locales/en-US/chrome/messenger/am-offline.dtd
mail/locales/en-US/chrome/messenger/prefs.properties
mailnews/base/prefs/resources/content/am-offline.js
mailnews/base/prefs/resources/content/am-offline.xul
mailnews/base/src/nsMsgAccountManagerDS.cpp
suite/locales/en-US/chrome/mailnews/pref/am-offline.dtd
suite/locales/en-US/chrome/mailnews/pref/prefs.properties
--- a/mail/locales/en-US/chrome/messenger/am-offline.dtd
+++ b/mail/locales/en-US/chrome/messenger/am-offline.dtd
@@ -1,12 +1,12 @@
 <!ENTITY doNotDownloadPop3Movemail.label "To save disk space, do not download:">
 <!ENTITY doNotDownload.label "To save disk space, do not download for offline use:">
-<!ENTITY offlineNewFolder.label "When I create new folders, select them for offline use">
-<!ENTITY offlineNewFolder.accesskey "c">
+<!ENTITY allFoldersOffline.label "Keep messages for this account on this computer">
+<!ENTITY allFoldersOffline.accesskey "o">
 <!ENTITY offlineNotDownload.label "Messages larger than">
 <!ENTITY offlineNotDownload.accesskey "M">
 <!ENTITY kb.label "KB">
 <!ENTITY days.label "days">
 <!ENTITY daysOld.label "days old">
 <!ENTITY message.label "messages">
 <!ENTITY nntpNotDownloadRead.label "Read messages">
 <!ENTITY nntpNotDownloadRead.accesskey "d">
@@ -20,15 +20,12 @@
 <!ENTITY retentionKeepNew.label "Delete all but the last">
 <!ENTITY retentionKeepNew.accesskey "b">
 <!ENTITY retentionKeepUnread.label "Always delete read messages">
 <!ENTITY retentionKeepUnread.accesskey "w">
 <!ENTITY nntpRemoveBody.label "Only message bodies less than">
 <!ENTITY nntpRemoveBody.accesskey "O">
 <!ENTITY offlineSelectNntp.label "Select newsgroups for offline use…">
 <!ENTITY offlineSelectNntp.accesskey "S">
-<!ENTITY offlineSelectImap.label "Select folders for offline use…">
-<!ENTITY offlineSelectImap.accesskey "S">
-<!ENTITY offlineDesc.label "You can download your messages locally so that they are available when you are working offline.">
-<!ENTITY makeInboxMsgsAvailable.label "Make the messages in my Inbox available when I am working offline">
-<!ENTITY makeInboxMsgsAvailable.accesskey "k">
-<!ENTITY offlineGroupTitle.label "Offline">
+<!ENTITY offlineImapAdvancedOffline.label "Advanced…">
+<!ENTITY offlineImapAdvancedOffline.accesskey "A">
+<!ENTITY syncGroupTitle.label "Message Synchronizing">
 <!ENTITY diskspaceGroupTitle.label "Disk Space">
--- a/mail/locales/en-US/chrome/messenger/prefs.properties
+++ b/mail/locales/en-US/chrome/messenger/prefs.properties
@@ -38,17 +38,17 @@ emailFieldText=Email Address:
 #LOCALIZATION NOTE: defaultEmailText: %1$S is user name, %2$S is domain
 defaultEmailText=Enter your email address. This is the address others will use to send email to you (for example, "%1$S@%2$S"). 
 #LOCALIZATION NOTE: customizedEmailText: %1$S is provider, %2$S is email username, %3$S is sample email, %4$S is sample username
 customizedEmailText=Enter your %1$S %2$S (for example, if your %1$S email address is "%3$S", your %2$S is "%4$S"). 
 
 # account manager stuff
 prefPanel-server=Server Settings
 prefPanel-copies=Copies & Folders
-prefPanel-offline-and-diskspace=Offline & Disk Space
+prefPanel-syncing-and-diskspace=Syncing & Disk Space
 prefPanel-diskspace=Disk Space
 prefPanel-addressing=Composition & Addressing
 prefPanel-advanced=Advanced
 prefPanel-junk=Junk Settings
 ## LOCALIZATION NOTE (prefPanel-smtp): Don't translate "SMTP"
 prefPanel-smtp=Outgoing Server (SMTP)
 
 # account manager multiple identity support
--- a/mailnews/base/prefs/resources/content/am-offline.js
+++ b/mailnews/base/prefs/resources/content/am-offline.js
@@ -16,16 +16,17 @@
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998-2001
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   dianesun@netscape.com
+ *   dascher@mozillamessaging.com
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -36,45 +37,53 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 var gIncomingServer;
 var gServerType;
 var gImapIncomingServer;
 var gPref = null;
 var gLockedPref = null;
+var gOfflineMap = null; // map of folder URLs to offline flags
+var Cc = Components.classes;
+var Ci = Components.interfaces;
 
 function onInit(aPageId, aServerId) 
 {
     onLockPreference();	
 
     // init values here
     initServerSettings();
     initRetentionSettings();
     initDownloadSettings();
+    initOfflineSettings();
 
     onCheckItem("offline.notDownloadMin", "offline.notDownload");
     onCheckItem("nntp.downloadMsgMin", "nntp.downloadMsg");
     onCheckItem("nntp.removeBodyMin", "nntp.removeBody");
     onCheckKeepMsg();
 }
 
+function initOfflineSettings()
+{
+    checkOffline();
+    gOfflineMap = collectOfflineFolders();
+}
+
 function initServerSettings()
-{	 
- 
+{
     document.getElementById("offline.notDownload").checked =  gIncomingServer.limitOfflineMessageSize;
     if(gIncomingServer.maxMessageSize > 0)
         document.getElementById("offline.notDownloadMin").setAttribute("value", gIncomingServer.maxMessageSize);
     else
         document.getElementById("offline.notDownloadMin").setAttribute("value", "50");
 
     if(gServerType == "imap") {
         gImapIncomingServer = gIncomingServer.QueryInterface(Components.interfaces.nsIImapIncomingServer);
-        document.getElementById("offline.downloadBodiesOnGetNewMail").checked =  gImapIncomingServer.downloadBodiesOnGetNewMail;
-        document.getElementById("offline.newFolder").checked =  gImapIncomingServer.offlineDownload;
+        document.getElementById("offline.folders").checked =  gImapIncomingServer.offlineDownload;
     }
 }
   
 function initRetentionSettings()
 {
     var retentionSettings =  gIncomingServer.retentionSettings; 
     initCommonRetentionSettings(retentionSettings);
 
@@ -106,17 +115,17 @@ function onPreInit(account, accountValue
     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-offline-and-diskspace" : "prefPanel-diskspace";
+     "prefPanel-syncing-and-diskspace" : "prefPanel-diskspace";
 
     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")
     {
@@ -137,40 +146,47 @@ function onPreInit(account, accountValue
 function onClickSelect()
 {
    
     top.window.openDialog("chrome://messenger/content/msgSelectOffline.xul", "", "centerscreen,chrome,modal,titlebar,resizable=yes");
     return true;
 
 }
 
+function onCancel()
+{
+    // restore the offline flags for all folders
+    restoreOfflineFolders(gOfflineMap);
+    return true;
+}
+
 function onSave()
 {
     var downloadSettings =
       Components.classes["@mozilla.org/msgDatabase/downloadSettings;1"]
                 .createInstance(Components.interfaces.nsIMsgDownloadSettings);
 
     gIncomingServer.limitOfflineMessageSize = document.getElementById("offline.notDownload").checked;
     gIncomingServer.maxMessageSize = document.getElementById("offline.notDownloadMin").value;
 
-	var retentionSettings = saveCommonRetentionSettings();
+    var retentionSettings = saveCommonRetentionSettings();
 
     retentionSettings.daysToKeepBodies = document.getElementById("nntp.removeBodyMin").value;
     retentionSettings.cleanupBodiesByDays = document.getElementById("nntp.removeBody").checked;
 
     downloadSettings.downloadByDate = document.getElementById("nntp.downloadMsg").checked;
     downloadSettings.downloadUnreadOnly = document.getElementById("nntp.notDownloadRead").checked;
     downloadSettings.ageLimitOfMsgsToDownload = document.getElementById("nntp.downloadMsgMin").value;
 
     gIncomingServer.retentionSettings = retentionSettings;
     gIncomingServer.downloadSettings = downloadSettings;
 
     if (gImapIncomingServer) {
-        gImapIncomingServer.downloadBodiesOnGetNewMail = document.getElementById("offline.downloadBodiesOnGetNewMail").checked;
-        gImapIncomingServer.offlineDownload = document.getElementById("offline.newFolder").checked;
+        // Set the pref on the incomingserver, and set the flag on all folders.
+        gImapIncomingServer.offlineDownload = document.getElementById("offline.folders").checked;
     }
 }
 
 // Does the work of disabling an element given the array which contains xul id/prefstring pairs.
 // Also saves the id/locked state in an array so that other areas of the code can avoid
 // stomping on the disabled state indiscriminately.
 function disableIfLocked( prefstrArray )
 {
@@ -201,19 +217,16 @@ function onLockPreference()
     var prefService = Components.classes["@mozilla.org/preferences-service;1"];
     prefService = prefService.getService();
     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
 
     // This panel does not use the code in AccountManager.js to handle
     // the load/unload/disable.  keep in mind new prefstrings and changes
     // to code in AccountManager, and update these as well.
     var allPrefElements = [
-      { prefstring:"offline_download", id:"offline.newFolder"},
-      { prefstring:"download_bodies_on_get_new_mail",
-                           id:"offline.downloadBodiesOnGetNewMail"},
       { prefstring:"limit_offline_message_size", id:"offline.notDownload"},
       { prefstring:"max_size", id:"offline.notDownloadMin"},
       { prefstring:"downloadUnreadOnly", id:"nntp.notDownloadRead"},
       { prefstring:"downloadByDate", id:"nntp.downloadMsg"},
       { prefstring:"ageLimit", id:"nntp.downloadMsgMin"},
       { prefstring:"retainBy", id:"retention.keepMsg"},
       { prefstring:"daysToKeepHdrs", id:"retention.keepOldMsgMin"},
       { prefstring:"numHdrsToKeep", id:"retention.keepNewMsgMin"},
@@ -236,8 +249,68 @@ function onCheckItem(changeElementId, ch
     var checked = document.getElementById(checkElementId).checked;
     if(checked && !gLockedPref[checkElementId] ) {
         element.removeAttribute("disabled");
     }
     else {
         element.setAttribute("disabled", "true");
     }
 }
+
+function checkOffline()
+{
+    var offline = document.getElementById("offline.folders").checked;
+    var folderPickerButton = document.getElementById('selectImapFoldersButton');
+    folderPickerButton.disabled = !offline;
+}
+
+function toggleOffline()
+{
+    checkOffline()
+    var offline = document.getElementById("offline.folders").checked;
+    var rootFolder = gIncomingServer.rootFolder;
+    var allFolders = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
+    rootFolder.ListDescendents(allFolders);
+    var numFolders = allFolders.Count();
+    var folder;
+    for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
+    {
+      folder = allFolders.GetElementAt(folderIndex).QueryInterface(Ci.nsIMsgFolder);
+      if (offline)
+        folder.setFlag(Components.interfaces.nsMsgFolderFlags.Offline);
+      else
+        folder.clearFlag(Components.interfaces.nsMsgFolderFlags.Offline);
+    }
+    
+}
+
+function collectOfflineFolders()
+{
+    var offlineFolderMap = {};
+    var rootFolder = gIncomingServer.rootFolder;
+    var allFolders = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
+    rootFolder.ListDescendents(allFolders);
+    var numFolders = allFolders.Count();
+    var folder;
+    for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
+    {
+      folder = allFolders.GetElementAt(folderIndex).QueryInterface(Ci.nsIMsgFolder);
+      offlineFolderMap[folder.folderURL] = folder.getFlag(Components.interfaces.nsMsgFolderFlags.Offline);
+    }
+    return offlineFolderMap;
+}
+
+function restoreOfflineFolders(offlineFolderMap)
+{
+    var rootFolder = gIncomingServer.rootFolder;
+    var allFolders = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
+    rootFolder.ListDescendents(allFolders);
+    var numFolders = allFolders.Count();
+    var folder;
+    for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
+    {
+      folder = allFolders.GetElementAt(folderIndex).QueryInterface(Ci.nsIMsgFolder);
+      if (offlineFolderMap[folder.folderURL])
+        folder.setFlag(Components.interfaces.nsMsgFolderFlags.Offline);
+      else
+        folder.clearFlag(Components.interfaces.nsMsgFolderFlags.Offline);
+    }
+}
--- a/mailnews/base/prefs/resources/content/am-offline.xul
+++ b/mailnews/base/prefs/resources/content/am-offline.xul
@@ -53,33 +53,27 @@
     <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"/>  
 
     <dialogheader id="headertitle"/>
 
     <groupbox id="offline.titlebox" hidefor="movemail,pop3,none,rss">
-      <caption label="&offlineGroupTitle.label;"/>
-
-    <description hidefor="movemail,pop3">&offlineDesc.label;</description>
+      <caption label="&syncGroupTitle.label;"/>
 
     <checkbox hidefor="movemail,pop3,nntp,none" 
-              id="offline.downloadBodiesOnGetNewMail" wsm_persist="true" 
-              label="&makeInboxMsgsAvailable.label;" 
-              accesskey="&makeInboxMsgsAvailable.accesskey;"/>
-
-    <checkbox hidefor="movemail,pop3,nntp,none" 
-              id="offline.newFolder" label="&offlineNewFolder.label;" 
-              accesskey="&offlineNewFolder.accesskey;"/>
+              id="offline.folders" label="&allFoldersOffline.label;"
+              oncommand="toggleOffline()"
+              accesskey="&allFoldersOffline.accesskey;"/>
 
     <separator class="thin" hidefor="movemail,pop3,nntp,none"/>
 
     <hbox hidefor="movemail,pop3,nntp,none" align="right">
-        <button label="&offlineSelectImap.label;" accesskey="&offlineSelectImap.accesskey;"
+        <button label="&offlineImapAdvancedOffline.label;" accesskey="&offlineImapAdvancedOffline.accesskey;"
                 oncommand="onClickSelect()" id="selectImapFoldersButton" class="selectForOfflineUseButton"/>
     </hbox>
 
     <hbox hidefor="movemail,pop3,imap,none" align="right">
         <button label="&offlineSelectNntp.label;" accesskey="&offlineSelectNntp.accesskey;"
                 oncommand="onClickSelect()" id="selectNewsgroupsButton" class="selectForOfflineUseButton"/>
     </hbox>
 
--- a/mailnews/base/src/nsMsgAccountManagerDS.cpp
+++ b/mailnews/base/src/nsMsgAccountManagerDS.cpp
@@ -335,17 +335,17 @@ nsMsgAccountManagerDataSource::GetTarget
     if (source == kNC_PageTitleServer)
       mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-server").get(),
                                        getter_Copies(pageTitle));
 
     else if (source == kNC_PageTitleCopies)
       mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-copies").get(),
                                        getter_Copies(pageTitle));
     else if (source == kNC_PageTitleOfflineAndDiskSpace)
-      mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-offline-and-diskspace").get(),
+      mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-syncing-and-diskspace").get(),
                                        getter_Copies(pageTitle));
     else if (source == kNC_PageTitleDiskSpace)
       mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-diskspace").get(),
                                        getter_Copies(pageTitle));
     else if (source == kNC_PageTitleAddressing)
       mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-addressing").get(),
                                        getter_Copies(pageTitle));
     else if (source == kNC_PageTitleSMTP)
--- a/suite/locales/en-US/chrome/mailnews/pref/am-offline.dtd
+++ b/suite/locales/en-US/chrome/mailnews/pref/am-offline.dtd
@@ -1,12 +1,12 @@
 <!ENTITY doNotDownloadPop3Movemail.label "To save disk space, do not download:">
 <!ENTITY doNotDownload.label "To save disk space, do not download for offline use:">
-<!ENTITY offlineNewFolder.label "When I create new folders, select them for offline use">
-<!ENTITY offlineNewFolder.accesskey "c">
+<!ENTITY allFoldersOffline.label "Keep messages for this account on this computer">
+<!ENTITY allFoldersOffline.accesskey "o">
 <!ENTITY offlineNotDownload.label "Messages larger than">
 <!ENTITY offlineNotDownload.accesskey "M">
 <!ENTITY kb.label "KB">
 <!ENTITY days.label "days">
 <!ENTITY daysOld.label "days old">
 <!ENTITY message.label "messages">
 <!ENTITY nntpNotDownloadRead.label "Read messages">
 <!ENTITY nntpNotDownloadRead.accesskey "d">
@@ -20,15 +20,12 @@
 <!ENTITY retentionKeepNew.label "Delete all but the last">
 <!ENTITY retentionKeepNew.accesskey "b">
 <!ENTITY retentionKeepUnread.label "Always delete read messages">
 <!ENTITY retentionKeepUnread.accesskey "w">
 <!ENTITY nntpRemoveBody.label "Only message bodies less than">
 <!ENTITY nntpRemoveBody.accesskey "O">
 <!ENTITY offlineSelectNntp.label "Select newsgroups for offline use…">
 <!ENTITY offlineSelectNntp.accesskey "S">
-<!ENTITY offlineSelectImap.label "Select folders for offline use…">
-<!ENTITY offlineSelectImap.accesskey "S">
-<!ENTITY offlineDesc.label "You can download your messages locally so that they are available when you are working offline.">
-<!ENTITY makeInboxMsgsAvailable.label "Make the messages in my Inbox available when I am working offline">
-<!ENTITY makeInboxMsgsAvailable.accesskey "k">
-<!ENTITY offlineGroupTitle.label "Offline">
+<!ENTITY offlineImapAdvancedOffline.label "Advanced…">
+<!ENTITY offlineImapAdvancedOffline.accesskey "A">
+<!ENTITY syncGroupTitle.label "Message Synchronizing">
 <!ENTITY diskspaceGroupTitle.label "Disk Space">
--- a/suite/locales/en-US/chrome/mailnews/pref/prefs.properties
+++ b/suite/locales/en-US/chrome/mailnews/pref/prefs.properties
@@ -76,17 +76,17 @@ emailFieldText=Email Address:
 #LOCALIZATION NOTE: defaultEmailText: %1$S is user name, %2$S is domain
 defaultEmailText=Enter your email address. This is the address others will use to send email to you (for example, "%1$S@%2$S"). 
 #LOCALIZATION NOTE: customizedEmailText: %1$S is provider, %2$S is email username, %3$S is sample email, %4$S is sample username
 customizedEmailText=Enter your %1$S %2$S (for example, if your %1$S email address is "%3$S", your %2$S is "%4$S"). 
 
 # account manager stuff
 prefPanel-server=Server Settings
 prefPanel-copies=Copies & Folders
-prefPanel-offline-and-diskspace=Offline & Disk Space
+prefPanel-syncing-and-diskspace=Syncing & Disk Space
 prefPanel-diskspace=Disk Space
 prefPanel-addressing=Composition & Addressing
 prefPanel-junk=Junk Settings
 ## LOCALIZATION NOTE (prefPanel-smtp): Don't translate "SMTP"
 prefPanel-smtp=Outgoing Server (SMTP)
 
 # account manager multiple identity support
 #LOCALIZATION NOTE: accountName: %1$S