home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / mail.xpi / bin / chrome / messenger.jar / content / messenger / am-prefs.js < prev    next >
Text File  |  2001-05-17  |  4KB  |  103 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  */
  20.  
  21.  
  22. /* functions for disabling front end elements when the appropriate
  23.    back-end preference is locked. */
  24.  
  25.  
  26. var nsPrefBranch = null;
  27.  
  28. // Prefs in mailnews require dynamic portions to indicate 
  29. // which of multiple servers or identies.  This function
  30. // takes a string and a xul element.
  31. //  The string is a prefstring with a token %tokenname%.
  32. //  The xul element has an attribute of name |tokenname|
  33. //  whose value is substituted into the string and returned
  34. //  by the function.
  35. //  Any tokens which do not have associated attribute value
  36. //  are not substituted, and left in the string as-is.
  37. function substPrefTokens(aStr, element)
  38. {
  39.   var tokenpat = /%(\w+)%/;
  40.   var token;
  41.   var newprefstr = "";
  42.  
  43.   var prefPartsArray = aStr.split(".");
  44.   /* here's a little loop that goes through
  45.      each part of the string separated by a dot, and
  46.      if any parts are of the form %string%, it will replace
  47.      them with the value of the attribute of that name from
  48.      the xul object */
  49.   for (var i=0; i< prefPartsArray.length; i++) {
  50.     token = prefPartsArray[i].match(tokenpat);
  51.     if (token) { /* we've got a %% match */
  52.       if (token[1]) {
  53.         if (element[token[1]]) {
  54.           newprefstr += element[token[1]] + "."; // here's where we get the info
  55.         } else { /* all we got was this stinkin % */
  56.           newprefstr += prefPartsArray[i] + ".";
  57.         }
  58.       }
  59.     } else /* if (token) */ {
  60.       newprefstr += prefPartsArray[i] + ".";
  61.     }
  62.   }
  63.   newprefstr = newprefstr.slice(0,-1); // remove the last char, a dot
  64.   if (newprefstr.length <=0 )
  65.     newprefstr = null;
  66.  
  67.   return newprefstr;
  68. }
  69.  
  70. // A simple function which given a xul element with
  71. // the pref related attributes (pref, preftype, prefstring)
  72. // return if the prefstring specified in that element is
  73. // locked (true/false).
  74. // If it does not have a valid prefstring, a false is returned.
  75. function getAccountValueIsLocked(element)
  76. {
  77.   var prefstr = "";
  78.   var preftype;
  79.   var prefval;
  80.  
  81.   if (!nsPrefBranch) {
  82.     var prefService = Components.classes["@mozilla.org/preferences-service;1"];
  83.     prefService = prefService.getService();
  84.     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  85.  
  86.     nsPrefBranch = prefService.getBranch(null);
  87.   }
  88.  
  89.  
  90.   if (element.getAttribute("pref") == "true" ) {
  91.     preftype    = element.getAttribute("preftype");
  92.     prefstring  = element.getAttribute("prefstring");
  93.     prefstr = substPrefTokens(prefstring, element);
  94.     // see if the prefstring is locked
  95.     if (prefstr) {
  96.       var bLocked=nsPrefBranch.prefIsLocked(prefstr);
  97.       return bLocked;
  98.     }
  99.   }
  100.   return false;
  101. }
  102.  
  103.