home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 March / PCWorld_2007-03_cd.bin / komunikace / nvu / nvu-1.0-cs-CZ.win32.installer.exe / chrome / toolkit.jar / content / global / nsUserSettings.js < prev    next >
Text File  |  2003-08-16  |  3KB  |  105 lines

  1.  
  2. /**
  3.  * nsPreferences - a wrapper around nsIPrefService. Provides built in
  4.  *                 exception handling to make preferences access simpler.
  5.  **/
  6. var nsPreferences = {
  7.   get mPrefService()
  8.     {
  9.       return Components.classes["@mozilla.org/preferences-service;1"]
  10.                        .getService(Components.interfaces.nsIPrefBranch);
  11.     },
  12.  
  13.   setBoolPref: function (aPrefName, aPrefValue)
  14.     {
  15.       try 
  16.         {
  17.           this.mPrefService.setBoolPref(aPrefName, aPrefValue);
  18.         }
  19.       catch(e)
  20.         {
  21.         }
  22.     },
  23.   
  24.   getBoolPref: function (aPrefName, aDefVal)
  25.     {
  26.       try
  27.         {
  28.           return this.mPrefService.getBoolPref(aPrefName);
  29.         }
  30.       catch(e)
  31.         {
  32.           return aDefVal != undefined ? aDefVal : null;
  33.         }
  34.       return null;        // quiet warnings
  35.     },
  36.   
  37.   setUnicharPref: function (aPrefName, aPrefValue)
  38.     {
  39.       try
  40.         {
  41.           var str = Components.classes["@mozilla.org/supports-string;1"]
  42.                               .createInstance(Components.interfaces.nsISupportsString);
  43.           str.data = aPrefValue;
  44.           this.mPrefService.setComplexValue(aPrefName,
  45.                                             Components.interfaces.nsISupportsString, str);
  46.         }
  47.       catch(e)
  48.         {
  49.         }
  50.     },
  51.   
  52.   copyUnicharPref: function (aPrefName, aDefVal)
  53.     {
  54.       try
  55.         {
  56.           return this.mPrefService.getComplexValue(aPrefName,
  57.                                                    Components.interfaces.nsISupportsString).data;
  58.         }
  59.       catch(e)
  60.         {
  61.           return aDefVal != undefined ? aDefVal : null;
  62.         }
  63.       return null;        // quiet warnings
  64.     },
  65.     
  66.   setIntPref: function (aPrefName, aPrefValue)
  67.     {
  68.       try
  69.         {
  70.           this.mPrefService.setIntPref(aPrefName, aPrefValue);
  71.         }
  72.       catch(e)
  73.         {
  74.         }
  75.     },
  76.   
  77.   getIntPref: function (aPrefName, aDefVal)
  78.     {
  79.       try
  80.         {
  81.           return this.mPrefService.getIntPref(aPrefName);
  82.         }
  83.       catch(e)
  84.         {
  85.           return aDefVal != undefined ? aDefVal : null;
  86.         }
  87.       return null;        // quiet warnings
  88.     },
  89.  
  90.   getLocalizedUnicharPref: function (aPrefName, aDefVal)
  91.     {
  92.       try
  93.         {
  94.           return this.mPrefService.getComplexValue(aPrefName,
  95.                                                    Components.interfaces.nsIPrefLocalizedString).data;
  96.         }
  97.       catch(e)
  98.         {
  99.           return aDefVal != undefined ? aDefVal : null;
  100.         }
  101.       return null;        // quiet warnings
  102.     }
  103. };
  104.  
  105.