home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / chatzilla.jar / content / chatzilla / readprefs.js < prev    next >
Text File  |  2000-09-13  |  5KB  |  172 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is JSIRC Test Client #3
  14.  *
  15.  * The Initial Developer of the Original Code is New Dimensions Consulting,
  16.  * Inc. Portions created by New Dimensions Consulting, Inc. are
  17.  * Copyright (C) 1999 New Dimenstions Consulting, Inc. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  *
  22.  *
  23.  * Contributor(s):
  24.  *  Robert Ginda, rginda@ndcico.com, original author
  25.  */
  26.  
  27. /*
  28.  * currently recognized prefs:
  29.  * + extensions.irc.
  30.  *   +- nickname (String)  initial nickname
  31.  *   +- username (String)  initial username (ie: username@host.tld)
  32.  *   +- desc     (String)  initial description (used in whois info)
  33.  *   +- network  (String)  network to connect to on startup
  34.  *   +- channel  (String)  channel to join after connecting
  35.  *   +- munger   (Boolean) send output through text->html munger
  36.  *   +- toolbar
  37.  *   |  +- icons (Boolean) display icons in toolbar buttons
  38.  *   +- notify
  39.  *      +- aggressive (Boolean) flash trayicon/ bring window to top when
  40.  *                              your nickname is mentioned.
  41.  *   +- style   
  42.  *   |  +- default (String) default style (relative to chrome://chatzilla/skin)
  43.  *   |  +- user
  44.  *   |     +- pre  (String) full path to user css, loaded before system style
  45.  *   |     +- post (String) full path to user css, loaded after system style
  46.  *   +- views
  47.  *   |  +- client
  48.  *   |  |  +- maxlines (Number) max lines to keep in *client* view
  49.  *   |  +- channel
  50.  *   |  |  +- maxlines (Number) max lines to keep in channel views
  51.  *   |  +- chanuser
  52.  *   |     +- maxlines (Number) max lines to keep in /msg views
  53.  *   +- debug
  54.  *      +- tracer (Boolean) enable/disable debug message tracing
  55.  */
  56.  
  57. function readIRCPrefs (rootNode)
  58. {
  59.     var pref =
  60.         Components.classes["@mozilla.org/preferences;1"].createInstance();
  61.     if(!pref)
  62.         throw ("Can't find pref component.");
  63.  
  64.     if (!rootNode)
  65.         rootNode = "extensions.irc.";
  66.  
  67.     if (!rootNode.match(/\.$/))
  68.         rootNode += ".";
  69.     
  70.     pref = pref.QueryInterface(Components.interfaces.nsIPref);
  71.  
  72.     CIRCNetwork.prototype.INITIAL_NICK =
  73.         getCharPref (pref, rootNode + "nickname",
  74.                      CIRCNetwork.prototype.INITIAL_NICK);
  75.     CIRCNetwork.prototype.INITIAL_NAME =
  76.         getCharPref (pref, rootNode + "username",
  77.                      CIRCNetwork.prototype.INITIAL_NAME);
  78.     CIRCNetwork.prototype.INITIAL_DESC =
  79.         getCharPref (pref, rootNode + "desc",
  80.                      CIRCNetwork.prototype.INITIAL_DESC);
  81.     CIRCNetwork.prototype.INITIAL_CHANNEL =
  82.         getCharPref (pref, rootNode + "channel",
  83.                      CIRCNetwork.prototype.INITIAL_CHANNEL);
  84.  
  85.     client.STARTUP_NETWORK =
  86.         getCharPref (pref, rootNode + "network", "");
  87.  
  88.     client.munger.enabled =
  89.         getBoolPref (pref, rootNode + "munger", client.munger.enabled);
  90.  
  91.     client.ICONS_IN_TOOLBAR = 
  92.         getBoolPref (pref, rootNode + "toolbar.icons", true);
  93.  
  94.     client.FLASH_WINDOW =
  95.         getBoolPref (pref, rootNode + "notify.aggressive", true);
  96.  
  97.     client.DEFAULT_STYLE =
  98.         getCharPref (pref, rootNode + "style.default", "output-default.css");
  99.  
  100.     client.USER_CSS_PRE =
  101.         getCharPref (pref, rootNode + "style.user.pre", "");
  102.  
  103.     client.USER_CSS_POST =
  104.  
  105.         getCharPref (pref, rootNode + "style.user.post", "");
  106.  
  107.     client.MAX_MESSAGES = 
  108.         getIntPref (pref, rootNode + "views.client.maxlines",
  109.                     client.MAX_MESSAGES);
  110.  
  111.     CIRCChannel.prototype.MAX_MESSAGES =
  112.         getIntPref (pref, rootNode + "views.channel.maxlines",
  113.                     CIRCChannel.prototype.MAX_MESSAGES);
  114.  
  115.     CIRCChanUser.prototype.MAX_MESSAGES =
  116.         getIntPref (pref, rootNode + "views.chanuser.maxlines",
  117.                     CIRCChanUser.prototype.MAX_MESSAGES);
  118.     
  119.     var h = client.eventPump.getHook ("event-tracer");
  120.     h.enabled =
  121.         getBoolPref (pref, rootNode + "debug.tracer", h.enabled);
  122.     
  123. }
  124.  
  125. function getCharPref (prefObj, prefName, defaultValue)
  126. {
  127.     var e, rv;
  128.     
  129.     try
  130.     {
  131.         rv = prefObj.CopyCharPref (prefName);
  132.     }
  133.     catch (e)
  134.     {
  135.         rv = defaultValue;
  136.     }
  137.  
  138.     //dd ("getCharPref: returning '" + rv + "' for " + prefName);
  139.     return rv;
  140.     
  141. }
  142.  
  143. function getIntPref (prefObj, prefName, defaultValue)
  144. {
  145.     var e;
  146.  
  147.     try
  148.     {
  149.         return prefObj.GetIntPref (prefName);
  150.     }
  151.     catch (e)
  152.     {
  153.         return defaultValue;
  154.     }
  155.     
  156. }
  157.  
  158. function getBoolPref (prefObj, prefName, defaultValue)
  159. {
  160.     var e;
  161.  
  162.     try
  163.     {
  164.         return prefObj.GetBoolPref (prefName);
  165.     }
  166.     catch (e)
  167.     {
  168.         return defaultValue;
  169.     }
  170.     
  171. }
  172.