!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
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
40 /* functions for disabling front end elements when the appropriate
41 back-end preference is locked. */
42
43
44 var nsPrefBranch = null;
45
46 // Prefs in mailnews require dynamic portions to indicate
47 // which of multiple servers or identies. This function
48 // takes a string and a xul element.
49 // The string is a prefstring with a token %tokenname%.
50 // The xul element has an attribute of name |tokenname|
51 // whose value is substituted into the string and returned
52 // by the function.
53 // Any tokens which do not have associated attribute value
54 // are not substituted, and left in the string as-is.
substPrefTokens
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
55 function substPrefTokens(aStr, element)
56 {
57 var tokenpat = /%(\w+)%/;
58 var token;
59 var newprefstr = "";
60
61 var prefPartsArray = aStr.split(".");
62 /* here's a little loop that goes through
63 each part of the string separated by a dot, and
64 if any parts are of the form %string%, it will replace
65 them with the value of the attribute of that name from
66 the xul object */
67 for (var i=0; i< prefPartsArray.length; i++) {
68 token = prefPartsArray[i].match(tokenpat);
69 if (token) { /* we've got a %% match */
70 if (token[1]) {
71 if (element[token[1]]) {
72 newprefstr += element[token[1]] + "."; // here's where we get the info
73 } else { /* all we got was this stinkin % */
74 newprefstr += prefPartsArray[i] + ".";
75 }
76 }
77 } else /* if (token) */ {
78 newprefstr += prefPartsArray[i] + ".";
79 }
80 }
81 newprefstr = newprefstr.slice(0,-1); // remove the last char, a dot
82 if (newprefstr.length <=0 )
83 newprefstr = null;
84
85 return newprefstr;
86 }
87
88 // A simple function which given a xul element with
89 // the pref related attributes (pref, preftype, prefstring)
90 // return if the prefstring specified in that element is
91 // locked (true/false).
92 // If it does not have a valid prefstring, a false is returned.
getAccountValueIsLocked
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
93 function getAccountValueIsLocked(element)
94 {
95 var prefstr = "";
96 var preftype;
97 var prefval;
98 var prefstring;
99
100 if (!nsPrefBranch) {
101 var prefService = Components.classes["@mozilla.org/preferences-service;1"];
102 prefService = prefService.getService();
103 prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
104
105 nsPrefBranch = prefService.getBranch(null);
106 }
107
108 prefstring = element.getAttribute("prefstring");
109 if (prefstring) {
110 preftype = element.getAttribute("preftype");
111 prefstr = substPrefTokens(prefstring, element);
112 // see if the prefstring is locked
113 if (prefstr) {
114 var bLocked=nsPrefBranch.prefIsLocked(prefstr);
115 return bLocked;
116 }
117 }
118 return false;
119 }