home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-mac-0.9.sea.hqx / mozilla-mac-0.9 / Chrome / chatzilla.jar / content / chatzilla / readprefs.js < prev    next >
Text File  |  2001-05-05  |  7KB  |  222 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.  *   +- defaultNet (String) default network to use for irc:// urls
  34.  *   +- initialURLs (String) irc:// urls to connect to on startup, semicolon
  35.  *   |                       seperated
  36.  *   +- munger   (Boolean) send output through text->html munger
  37.  *   |  +- smileyText (Boolean) true => display text (and graphic) when
  38.  *   |                                  matching smileys
  39.  *   |                          false => show only the smiley graphic
  40.  *   +- nickCompleteStr (String) String to use when tab-completing nicknames
  41.  *   |                           at the beginning of sentences
  42.  *   +- stalkWords (String) List of words to add to the stalk victims list
  43.  *   |                      semicolon seperated (see the /stalk command)
  44.  *   +- deleteOnPart (Boolean) Delete channel window automatically after a /part
  45.  *   |
  46.  *   +- notify
  47.  *   |  +- aggressive (Boolean) flash trayicon/ bring window to top when
  48.  *   |                          your nickname is mentioned.
  49.  *   +- settings
  50.  *   |  +- autoSave (Boolean) Save settings on exit
  51.  *   +- style   
  52.  *   |  +- default (String) default style (relative to chrome://chatzilla/skin)
  53.  *   |  +- user
  54.  *   |     +- pre  (String) full path to user css, loaded before system style
  55.  *   |     +- post (String) full path to user css, loaded after system style
  56.  *   +- views
  57.  *   |  +- client
  58.  *   |  |  +- maxlines (Number) max lines to keep in *client* view
  59.  *   |  +- channel
  60.  *   |  |  +- maxlines (Number) max lines to keep in channel views
  61.  *   |  +- chanuser
  62.  *   |     +- maxlines (Number) max lines to keep in /msg views
  63.  *   +- debug
  64.  *      +- tracer (Boolean) enable/disable debug message tracing
  65.  */
  66.  
  67. function readIRCPrefs (rootNode)
  68. {
  69.     var pref =
  70.         Components.classes["@mozilla.org/preferences;1"].createInstance();
  71.     if(!pref)
  72.         throw ("Can't find pref component.");
  73.  
  74.     if (!rootNode)
  75.         rootNode = "extensions.irc.";
  76.  
  77.     if (!rootNode.match(/\.$/))
  78.         rootNode += ".";
  79.     
  80.     pref = pref.QueryInterface(Components.interfaces.nsIPref);
  81.  
  82.     CIRCNetwork.prototype.INITIAL_NICK =
  83.         getCharPref (pref, rootNode + "nickname",
  84.                      CIRCNetwork.prototype.INITIAL_NICK);
  85.     CIRCNetwork.prototype.INITIAL_NAME =
  86.         getCharPref (pref, rootNode + "username",
  87.                      CIRCNetwork.prototype.INITIAL_NAME);
  88.     CIRCNetwork.prototype.INITIAL_DESC =
  89.         getCharPref (pref, rootNode + "desc",
  90.                      CIRCNetwork.prototype.INITIAL_DESC);
  91.     client.DEFAULT_NETWORK =
  92.         getCharPref (pref, rootNode + "defaultNet", "moznet");    
  93.     client.INITIAL_URLS =
  94.         getCharPref (pref, rootNode + "initialURLs", "");
  95.     client.ADDRESSED_NICK_SEP =
  96.         getCharPref (pref, rootNode + "nickCompleteStr",
  97.                      client.ADDRESSED_NICK_SEP);
  98.     client.INITIAL_VICTIMS =
  99.         getCharPref (pref, rootNode + "stalkWords", "");
  100.     
  101.     client.DELETE_ON_PART =
  102.         getCharPref (pref, rootNode + "deleteOnPart", true);
  103.     
  104.     client.munger.enabled =
  105.         getBoolPref (pref, rootNode + "munger", client.munger.enabled);
  106.  
  107.     client.smileyText =
  108.         getBoolPref (pref, rootNode + "munger.smileyText", false);
  109.  
  110.     client.FLASH_WINDOW =
  111.         getBoolPref (pref, rootNode + "notify.aggressive", true);
  112.  
  113.     client.SAVE_SETTINGS =
  114.         getBoolPref (pref, rootNode + "settings.autoSave", true);
  115.  
  116.     client.DEFAULT_STYLE =
  117.         getCharPref (pref, rootNode + "style.default", "output-default.css");
  118.     
  119.     client.USER_CSS_PRE =
  120.         getCharPref (pref, rootNode + "style.user.pre", "");
  121.  
  122.     client.USER_CSS_POST =
  123.         getCharPref (pref, rootNode + "style.user.post", "");
  124.  
  125.     client.MAX_MESSAGES = 
  126.         getIntPref (pref, rootNode + "views.client.maxlines",
  127.                     client.MAX_MESSAGES);
  128.  
  129.     CIRCChannel.prototype.MAX_MESSAGES =
  130.         getIntPref (pref, rootNode + "views.channel.maxlines",
  131.                     CIRCChannel.prototype.MAX_MESSAGES);
  132.  
  133.     CIRCChanUser.prototype.MAX_MESSAGES =
  134.         getIntPref (pref, rootNode + "views.chanuser.maxlines",
  135.                     CIRCChanUser.prototype.MAX_MESSAGES);
  136.     
  137.     var h = client.eventPump.getHook ("event-tracer");
  138.     h.enabled = client.debugMode =
  139.         getBoolPref (pref, rootNode + "debug.tracer", h.enabled);
  140.     
  141. }
  142.  
  143. function writeIRCPrefs (rootNode)
  144. {
  145.     var pref =
  146.         Components.classes["@mozilla.org/preferences;1"].createInstance();
  147.     if(!pref)
  148.         throw ("Can't find pref component.");
  149.  
  150.     if (!rootNode)
  151.         rootNode = "extensions.irc.";
  152.  
  153.     if (!rootNode.match(/\.$/))
  154.         rootNode += ".";
  155.     
  156.     pref = pref.QueryInterface(Components.interfaces.nsIPref);
  157.  
  158.     pref.SetCharPref (rootNode + "nickname",
  159.                       CIRCNetwork.prototype.INITIAL_NICK);
  160.     pref.SetCharPref (rootNode + "username",
  161.                       CIRCNetwork.prototype.INITIAL_NAME);
  162.     pref.SetCharPref (rootNode + "desc", CIRCNetwork.prototype.INITIAL_DESC);
  163.     pref.SetCharPref (rootNode + "nickCompleteStr", client.ADDRESSED_NICK_SEP);
  164.     pref.SetCharPref (rootNode + "stalkWords",
  165.                       client.stalkingVictims.join ("; "));
  166.     pref.SetBoolPref (rootNode + "munger", client.munger.enabled);
  167.     pref.SetBoolPref (rootNode + "munger.smileyText", client.smileyText);
  168.     pref.SetBoolPref (rootNode + "notify.aggressive", client.FLASH_WINDOW);
  169.     
  170.     var h = client.eventPump.getHook ("event-tracer");
  171.     pref.SetBoolPref (rootNode + "debug.tracer", h.enabled);
  172.     
  173. }
  174.  
  175. function getCharPref (prefObj, prefName, defaultValue)
  176. {
  177.     var e, rv;
  178.     
  179.     try
  180.     {
  181.         rv = prefObj.CopyCharPref (prefName);
  182.     }
  183.     catch (e)
  184.     {
  185.         rv = defaultValue;
  186.     }
  187.  
  188.     //dd ("getCharPref: returning '" + rv + "' for " + prefName);
  189.     return rv;
  190.     
  191. }
  192.  
  193. function getIntPref (prefObj, prefName, defaultValue)
  194. {
  195.     var e;
  196.  
  197.     try
  198.     {
  199.         return prefObj.GetIntPref (prefName);
  200.     }
  201.     catch (e)
  202.     {
  203.         return defaultValue;
  204.     }
  205.     
  206. }
  207.  
  208. function getBoolPref (prefObj, prefName, defaultValue)
  209. {
  210.     var e;
  211.  
  212.     try
  213.     {
  214.         return prefObj.GetBoolPref (prefName);
  215.     }
  216.     catch (e)
  217.     {
  218.         return defaultValue;
  219.     }
  220.     
  221. }
  222.