!import
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org Code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2001
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * dianesun@netscape.com
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 var gIncomingServer;
40 var gServerType;
41 var gImapIncomingServer;
42 var gPref = null;
43 var gLockedPref = null;
44
onInit
45 function onInit(aPageId, aServerId)
46 {
47 onLockPreference();
48
49 // init values here
50 initServerSettings();
51 initRetentionSettings();
52 initDownloadSettings();
53
54 onCheckItem("offline.notDownloadMin", "offline.notDownload");
55 onCheckItem("nntp.downloadMsgMin", "nntp.downloadMsg");
56 onCheckItem("nntp.removeBodyMin", "nntp.removeBody");
57 onCheckKeepMsg();
58 }
59
initServerSettings
60 function initServerSettings()
61 {
62
63 document.getElementById("offline.notDownload").checked = gIncomingServer.limitOfflineMessageSize;
64 if(gIncomingServer.maxMessageSize > 0)
65 document.getElementById("offline.notDownloadMin").setAttribute("value", gIncomingServer.maxMessageSize);
66 else
67 document.getElementById("offline.notDownloadMin").setAttribute("value", "50");
68
69 if(gServerType == "imap") {
70 gImapIncomingServer = gIncomingServer.QueryInterface(Components.interfaces.nsIImapIncomingServer);
71 document.getElementById("offline.downloadBodiesOnGetNewMail").checked = gImapIncomingServer.downloadBodiesOnGetNewMail;
72 document.getElementById("offline.newFolder").checked = gImapIncomingServer.offlineDownload;
73 }
74 }
75
initRetentionSettings
76 function initRetentionSettings()
77 {
78 var retentionSettings = gIncomingServer.retentionSettings;
79 initCommonRetentionSettings(retentionSettings);
80
81 document.getElementById("nntp.removeBody").checked = retentionSettings.cleanupBodiesByDays;
82 if(retentionSettings.daysToKeepBodies > 0)
83 document.getElementById("nntp.removeBodyMin").setAttribute("value", retentionSettings.daysToKeepBodies);
84 else
85 document.getElementById("nntp.removeBodyMin").setAttribute("value", "30");
86 }
87
88
initDownloadSettings
89 function initDownloadSettings()
90 {
91
92 var downloadSettings = gIncomingServer.downloadSettings;
93 document.getElementById("nntp.downloadMsg").checked = downloadSettings.downloadByDate;
94 document.getElementById("nntp.notDownloadRead").checked = downloadSettings.downloadUnreadOnly;
95 if(downloadSettings.ageLimitOfMsgsToDownload > 0)
96 document.getElementById("nntp.downloadMsgMin").setAttribute("value", downloadSettings.ageLimitOfMsgsToDownload);
97 else
98 document.getElementById("nntp.downloadMsgMin").setAttribute("value", "30");
99
100 }
101
102
onPreInit
103 function onPreInit(account, accountValues)
104 {
105
106 gServerType = getAccountValue(account, accountValues, "server", "type", null, false);
107 hideShowControls(gServerType);
108 gIncomingServer= account.incomingServer;
109 gIncomingServer.type = gServerType;
110
111 // 10 is OFFLINE_SUPPORT_LEVEL_REGULAR, see nsIMsgIncomingServer.idl
112 // currently, there is no offline without diskspace
113 var titleStringID = (gIncomingServer.offlineSupportLevel >= 10) ?
114 "prefPanel-offline-and-diskspace" : "prefPanel-diskspace";
115
116 var prefBundle = document.getElementById("bundle_prefs");
117 var headertitle = document.getElementById("headertitle");
118 headertitle.setAttribute('title',prefBundle.getString(titleStringID));
119
120 if (gServerType == "pop3")
121 {
122 var pop3Server = gIncomingServer.QueryInterface(Components.interfaces.nsIPop3IncomingServer);
123 // hide retention settings for deferred accounts
124 if (pop3Server.deferredToAccount.length)
125 {
126 var retentionRadio = document.getElementById("retention.keepMsg");
127 retentionRadio.setAttribute("hidden", "true");
128 var retentionCheckbox = document.getElementById("retention.keepUnread");
129 retentionCheckbox.setAttribute("hidden", "true");
130 var retentionLabel = document.getElementById("retentionDescription");
131 retentionLabel.setAttribute("hidden", "true");
132 }
133 }
134 }
135
onClickSelect
136 function onClickSelect()
137 {
138
139 top.window.openDialog("chrome://messenger/content/msgSelectOffline.xul", "", "centerscreen,chrome,modal,titlebar,resizable=yes");
140 return true;
141
142 }
143
onSave
144 function onSave()
145 {
146
147 var downloadSettings = new Array;
148
149 gIncomingServer.limitOfflineMessageSize = document.getElementById("offline.notDownload").checked;
150 gIncomingServer.maxMessageSize = document.getElementById("offline.notDownloadMin").value;
151
152 var retentionSettings = saveCommonRetentionSettings();
153
154 retentionSettings.daysToKeepBodies = document.getElementById("nntp.removeBodyMin").value;
155 retentionSettings.cleanupBodiesByDays = document.getElementById("nntp.removeBody").checked;
156
157 downloadSettings.downloadByDate = document.getElementById("nntp.downloadMsg").checked;
158 downloadSettings.downloadUnreadOnly = document.getElementById("nntp.notDownloadRead").checked;
159 downloadSettings.ageLimitOfMsgsToDownload = document.getElementById("nntp.downloadMsgMin").value;
160
161 gIncomingServer.retentionSettings = retentionSettings;
162 gIncomingServer.downloadSettings = downloadSettings;
163
164 if (gImapIncomingServer) {
165 gImapIncomingServer.downloadBodiesOnGetNewMail = document.getElementById("offline.downloadBodiesOnGetNewMail").checked;
166 gImapIncomingServer.offlineDownload = document.getElementById("offline.newFolder").checked;
167 }
168 }
169
170 // Does the work of disabling an element given the array which contains xul id/prefstring pairs.
171 // Also saves the id/locked state in an array so that other areas of the code can avoid
172 // stomping on the disabled state indiscriminately.
disableIfLocked
173 function disableIfLocked( prefstrArray )
174 {
175 if (!gLockedPref)
176 gLockedPref = new Array;
177
178 for (var i=0; i<prefstrArray.length; i++) {
179 var id = prefstrArray[i].id;
180 var element = document.getElementById(id);
181 if (gPref.prefIsLocked(prefstrArray[i].prefstring)) {
182 element.disabled = true;
183 gLockedPref[id] = true;
184 } else {
185 element.removeAttribute("disabled");
186 gLockedPref[id] = false;
187 }
188 }
189 }
190
191 // Disables xul elements that have associated preferences locked.
onLockPreference
192 function onLockPreference()
193 {
194 var isDownloadLocked = false;
195 var isGetNewLocked = false;
196 var initPrefString = "mail.server";
197 var finalPrefString;
198
199 var prefService = Components.classes["@mozilla.org/preferences-service;1"];
200 prefService = prefService.getService();
201 prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
202
203 // This panel does not use the code in AccountManager.js to handle
204 // the load/unload/disable. keep in mind new prefstrings and changes
205 // to code in AccountManager, and update these as well.
206 var allPrefElements = [
207 { prefstring:"offline_download", id:"offline.newFolder"},
208 { prefstring:"download_bodies_on_get_new_mail",
209 id:"offline.downloadBodiesOnGetNewMail"},
210 { prefstring:"limit_offline_message_size", id:"offline.notDownload"},
211 { prefstring:"max_size", id:"offline.notDownloadMin"},
212 { prefstring:"downloadUnreadOnly", id:"nntp.notDownloadRead"},
213 { prefstring:"downloadByDate", id:"nntp.downloadMsg"},
214 { prefstring:"ageLimit", id:"nntp.downloadMsgMin"},
215 { prefstring:"retainBy", id:"retention.keepMsg"},
216 { prefstring:"daysToKeepHdrs", id:"retention.keepOldMsgMin"},
217 { prefstring:"numHdrsToKeep", id:"retention.keepNewMsgMin"},
218 { prefstring:"keepUnreadOnly", id:"retention.keepUnread"},
219 { prefstring:"daysToKeepBodies", id:"nntp.removeBodyMin"},
220 { prefstring:"cleanupBodies", id:"nntp.removeBody" },
221 { prefstring:"disable_button.selectFolder", id:"selectNewsgroupsButton"},
222 { prefstring:"disable_button.selectFolder", id:"selectImapFoldersButton"}
223 ];
224
225 finalPrefString = initPrefString + "." + gIncomingServer.key + ".";
226 gPref = prefService.getBranch(finalPrefString);
227
228 disableIfLocked( allPrefElements );
229 }
230
onCheckItem
231 function onCheckItem(changeElementId, checkElementId)
232 {
233 var element = document.getElementById(changeElementId);
234 var checked = document.getElementById(checkElementId).checked;
235 if(checked && !gLockedPref[checkElementId] ) {
236 element.removeAttribute("disabled");
237 }
238 else {
239 element.setAttribute("disabled", "true");
240 }
241 }