!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 38 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/mail/components/preferences/compose.js"
2
3 const kLDAPPrefContractID="@mozilla.org/ldapprefs-service;1";
4
5 var gRefresh = false; // leftover hack from the old preferences dialog
6
7 var gComposePane = {
8 mInitialized: false,
9 mDirectories: null,
10 mLDAPPrefsService: null,
11 mSpellChecker: null,
12 mDictCount : 0,
13
init
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
14 init: function ()
15 {
16 if (kLDAPPrefContractID in Components.classes)
17 this.mLDAPPrefsService = Components.classes[kLDAPPrefContractID].getService(Components.interfaces.nsILDAPPrefsService);
18
19 this.createDirectoriesList();
20
21 // build the local address book menu list. We do this by hand instead of using the xul template
22 // builder because of Bug #285076,
23 this.createLocalDirectoriesList();
24
25 this.enableAutocomplete();
26
27 this.initLanguageMenu();
28
29 this.populateFonts();
30
31 document.getElementById('downloadDictionaries').setAttribute('href', this.getDictionaryURL());
32
33 var preference = document.getElementById("mail.preferences.compose.selectedTabIndex");
34 if (preference.value)
35 document.getElementById("composePrefs").selectedIndex = preference.value;
36 this.mInitialized = true;
37 },
38
getDictionaryURL
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
39 getDictionaryURL: function()
40 {
41 var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
42 .getService(Components.interfaces.nsIURLFormatter);
43
44 return formatter.formatURLPref("spellchecker.dictionaries.download.url");
45 },
46
tabSelectionChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
47 tabSelectionChanged: function ()
48 {
49 if (this.mInitialized)
50 {
51 var preference = document.getElementById("mail.preferences.compose.selectedTabIndex");
52 preference.valueFromPreferences = document.getElementById("composePrefs").selectedIndex;
53 }
54 },
55
sendOptionsDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
56 sendOptionsDialog: function()
57 {
58 document.documentElement.openSubDialog("chrome://messenger/content/preferences/sendoptions.xul","", null);
59 },
60
htmlComposeDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
61 htmlComposeDialog: function()
62 {
63 document.documentElement.openSubDialog("chrome://messenger/content/preferences/htmlcompose.xul","", null);
64 },
65
enableAutocomplete
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
66 enableAutocomplete: function()
67 {
68 var directoriesList = document.getElementById("directoriesList");
69 var directoriesListPopup = document.getElementById("directoriesListPopup");
70 var editButton = document.getElementById("editButton");
71
72 if (document.getElementById("autocompleteLDAP").checked)
73 {
74 editButton.removeAttribute("disabled");
75 directoriesList.removeAttribute("disabled");
76 directoriesListPopup.removeAttribute("disabled");
77 }
78 else
79 {
80 directoriesList.setAttribute("disabled", true);
81 directoriesListPopup.setAttribute("disabled", true);
82 editButton.setAttribute("disabled", true);
83 }
84
85 // if we do not have any directories disable the dropdown list box
86 if (!this.mDirectories || (this.mDirectories < 1))
87 directoriesList.setAttribute("disabled", true);
88 },
89
createLocalDirectoriesList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
90 createLocalDirectoriesList: function ()
91 {
92 var abPopup = document.getElementById("abPopup-menupopup");
93
94 if (abPopup)
95 this.loadLocalDirectories(abPopup);
96 },
97
loadLocalDirectories
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
98 loadLocalDirectories: function (aPopup)
99 {
100 var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
101 .getService(Components.interfaces.nsIRDFService);
102
103 var parentDir = rdfService.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory);
104 var enumerator = parentDir.childNodes;
105 var preference = document.getElementById("mail.collect_addressbook");
106
107 if (enumerator)
108 {
109 while (enumerator.hasMoreElements())
110 {
111 var addrbook = enumerator.getNext();
112 if (addrbook instanceof Components.interfaces.nsIAbDirectory &&
113 !addrbook.isRemote && !addrbook.isMailList &&
114 (addrbook.operations & addrbook.opWrite))
115 {
116 var abURI = addrbook.URI;
117 item = document.createElement("menuitem");
118 item.setAttribute("label", addrbook.dirName);
119 item.setAttribute("value", abURI);
120 aPopup.appendChild(item);
121 if (preference.value == abURI)
122 {
123 aPopup.parentNode.value = abURI;
124 aPopup.selectedItem = item;
125 }
126 }
127 }
128 }
129 },
130
createDirectoriesList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
131 createDirectoriesList: function()
132 {
133 var directoriesListPopup = document.getElementById("directoriesListPopup");
134
135 if (directoriesListPopup)
136 this.loadDirectories(directoriesListPopup);
137 },
138
loadDirectories
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
139 loadDirectories: function(aPopup)
140 {
141 var prefCount = {value:0};
142 var description = "";
143 var item;
144 var j=0;
145 var arrayOfDirectories;
146 var position;
147 var dirType;
148 var prefService;
149
150 prefService = Components.classes["@mozilla.org/preferences-service;1"]
151 .getService(Components.interfaces.nsIPrefBranch);
152
153 if (!this.mDirectories)
154 {
155 try
156 {
157 if (this.mLDAPPrefsService)
158 arrayOfDirectories = this.mLDAPPrefsService.getServerList(prefService, prefCount);
159 }
160 catch (ex) {}
161
162 if (arrayOfDirectories)
163 {
164 this.mDirectories = new Array();
165 for (var i = 0; i < prefCount.value; i++)
166 {
167 if ((arrayOfDirectories[i] != "ldap_2.servers.pab") &&
168 (arrayOfDirectories[i] != "ldap_2.servers.history"))
169 {
170 try
171 {
172 position = prefService.getIntPref(arrayOfDirectories[i]+".position");
173 }
174 catch(ex)
175 {
176 position = 1;
177 }
178
179 try
180 {
181 dirType = prefService.getIntPref(arrayOfDirectories[i]+".dirType");
182 }
183 catch(ex)
184 {
185 dirType = 1;
186 }
187
188 if ((position != 0) && (dirType == 1))
189 {
190 try
191 {
192 description = prefService.getComplexValue(arrayOfDirectories[i]+".description",
193 Components.interfaces.nsISupportsString).data;
194 }
195 catch(ex)
196 {
197 description="";
198 }
199
200 if (description != "")
201 {
202 if (aPopup)
203 {
204 item = document.createElement("menuitem");
205 item.setAttribute("label", description);
206 item.setAttribute("value", arrayOfDirectories[i]);
207 aPopup.appendChild(item);
208 }
209
210 this.mDirectories[j++] = {value:arrayOfDirectories[i], label:description};
211 }
212 }
213 }
214 }
215
216 if (aPopup)
217 {
218 // we are in mail/news Account settings
219 item = document.createElement("menuitem");
220 var addressBookBundle = document.getElementById("bundle_addressBook");
221 var directoryName = addressBookBundle.getString("directoriesListItemNone");
222 item.setAttribute("label", directoryName);
223 item.setAttribute("value", "");
224 aPopup.appendChild(item);
225
226 // Now check what we are displaying is valid.
227 var directoriesList = document.getElementById("directoriesList");
228 var value = directoriesList.value;
229 directoriesList.selectedItem = null;
230 directoriesList.value = value;
231 if (!directoriesList.selectedItem)
232 {
233 directoriesList.value = "";
234 // If we have no other directories, also disable the popup.
235 if (gAvailDirectories.length == 0)
236 directoriesList.disabled = true;
237 }
238 else if (!prefService.prefIsLocked("ldap_2.autoComplete.directoryServer"))
239 directoriesList.disabled = false;
240 }
241 }
242 }
243 },
244
editDirectories
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
245 editDirectories: function()
246 {
247 var args = {fromGlobalPref: true};
248 window.openDialog("chrome://messenger/content/addressbook/pref-editdirectories.xul",
249 "editDirectories", "chrome,modal=yes,resizable=no", args);
250 if (gRefresh)
251 {
252 var popup = document.getElementById("directoriesListPopup");
253 if (popup)
254 while (popup.hasChildNodes())
255 popup.removeChild(popup.lastChild);
256
257 }
258
259 this.mDirectories = null;
260 this.loadDirectories(popup);
261 gRefresh = false;
262 },
263
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
264 initLanguageMenu: function ()
265 {
266 var languageMenuList = document.getElementById("languageMenuList");
267 this.mSpellChecker = Components.classes['@mozilla.org/spellchecker/engine;1'].getService(Components.interfaces.mozISpellCheckingEngine);
268 var o1 = {};
269 var o2 = {};
270
271 // Get the list of dictionaries from
272 // the spellchecker.
273
274 this.mSpellChecker.getDictionaryList(o1, o2);
275
276 var dictList = o1.value;
277 var count = o2.value;
278
279 // if we don't have any dictionaries installed, disable the menu list
280 languageMenuList.disabled = !count;
281
282 // If dictionary count hasn't changed then no need to update the menu.
283 if (this.mDictCount == count)
284 return;
285
286 // Store current dictionary count.
287 this.mDictCount = count;
288
289 // Load the string bundles that will help us map
290 // RFC 1766 strings to UI strings.
291
292 // Load the language string bundle.
293 var languageBundle = document.getElementById("languageBundle");
294 var regionBundle = null;
295 // If we have a language string bundle, load the region string bundle.
296 if (languageBundle)
297 regionBundle = document.getElementById("regionBundle");
298
299 var menuStr2;
300 var isoStrArray;
301 var langId;
302 var langLabel;
303 var i;
304
305 for (i = 0; i < count; i++)
306 {
307 try {
308 langId = dictList[i];
309 isoStrArray = dictList[i].split("-");
310
311 if (languageBundle && isoStrArray[0])
312 langLabel = languageBundle.getString(isoStrArray[0].toLowerCase());
313
314 if (regionBundle && langLabel && isoStrArray.length > 1 && isoStrArray[1])
315 {
316 menuStr2 = regionBundle.getString(isoStrArray[1].toLowerCase());
317 if (menuStr2)
318 langLabel += "/" + menuStr2;
319 }
320
321 if (langLabel && isoStrArray.length > 2 && isoStrArray[2])
322 langLabel += " (" + isoStrArray[2] + ")";
323
324 if (!langLabel)
325 langLabel = langId;
326 } catch (ex) {
327 // getString throws an exception when a key is not found in the
328 // bundle. In that case, just use the original dictList string.
329 langLabel = langId;
330 }
331 dictList[i] = [langLabel, langId];
332 }
333
334 // sort by locale-aware collation
335 dictList.sort(
compareFn
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
336 function compareFn(a, b)
337 {
338 return a[0].localeCompare(b[0]);
339 }
340 );
341
342 // Remove any languages from the list.
343 var languageMenuPopup = languageMenuList.firstChild;
344 while (languageMenuPopup.hasChildNodes())
345 languageMenuPopup.removeChild(languageMenuPopup.firstChild);
346
347 // append the dictionaries to the menu list...
348 for (i = 0; i < count; i++)
349 languageMenuList.appendItem(dictList[i][0], dictList[i][1]);
350
351 languageMenuList.setInitialSelection();
352 },
353
populateFonts
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
354 populateFonts: function()
355 {
356 var fontsList = document.getElementById("FontSelect");
357 try
358 {
359 var enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
360 .getService(Components.interfaces.nsIFontEnumerator);
361 var localFontCount = { value: 0 }
362 var localFonts = enumerator.EnumerateAllFonts(localFontCount);
363 for (var i = 0; i < localFonts.length; ++i)
364 {
365 if (localFonts[i] != "")
366 fontsList.appendItem(localFonts[i], localFonts[i]);
367 }
368 }
369 catch(e) { }
370 },
371
restoreHTMLDefaults
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
372 restoreHTMLDefaults: function()
373 {
374 // reset throws an exception if the pref value is already the default so
375 // work around that with some try/catch exception handling
376 try {
377 document.getElementById('msgcompose.font_face').reset();
378 } catch (ex) {}
379
380 try {
381 document.getElementById('msgcompose.font_size').reset();
382 } catch (ex) {}
383
384 try {
385 document.getElementById('msgcompose.text_color').reset();
386 } catch (ex) {}
387
388 try {
389 document.getElementById('msgcompose.background_color').reset();
390 } catch (ex) {}
391 }
392 };