home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / 01_03.iso / software / ghostzilla_hit / files / ghostzilla-1.0-plus-install.exe / chrome / chatzilla.jar / content / chatzilla / readprefs.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  11.1 KB  |  301 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.  *   +- initialScripts (String) urls for scripts to run at startup,
  37.  *   |                          semicolon seperated
  38.  *   +- newTabThreshold (Number) max number of tabs to have open before disabling
  39.  *   |                           automatic tab creation for private messages.
  40.  *   |                           use 0 for unlimited new tabs, or 1 to disable
  41.  *   |                           automatic tab creation.
  42.  *   +- focusNewTab (Boolean) bring new tabs created in response to a private
  43.  *   |                        message to the front.
  44.  *   +- munger   (Boolean) send output through text->html munger
  45.  *   |  +- colorCodes (Boolean) enable color code handling
  46.  *   |  +- <various>  (Boolean) enable specific munger entry
  47.  *   |  +- smileyText (Boolean) true => display text (and graphic) when
  48.  *   |                                  matching smileys
  49.  *   |                          false => show only the smiley graphic
  50.  *   +- nickCompleteStr (String) String to use when tab-completing nicknames
  51.  *   |                           at the beginning of sentences
  52.  *   +- stalkWords (String) List of words to add to the stalk victims list
  53.  *   |                      semicolon seperated (see the /stalk command)
  54.  *   +- deleteOnPart (Boolean) Delete channel window automatically after a /part
  55.  *   |
  56.  *   |  The following beep prefs can be set to the text "beep" to use the
  57.  *   |  system beep, or "" to disable the beep.
  58.  *   +- msgBeep   (String) url to sound to play when a /msg is recieved
  59.  *   +- stalkBeep (String) url to sound to play when a /stalk matches
  60.  *   +- queryBeep (String) url to sound to play for new msgs in a /query
  61.  *   |
  62.  *   +- notify
  63.  *   |  +- aggressive (Boolean) flash trayicon/ bring window to top when
  64.  *   |                          your nickname is mentioned.
  65.  *   +- settings
  66.  *   |  +- autoSave (Boolean) Save settings on exit
  67.  *   +- style   
  68.  *   |  +- default (String) url to default style sheet
  69.  *   +- views
  70.  *   |  +- collapseMsgs (Boolean) Collapse consecutive messages from same
  71.  *   |  |                         user
  72.  *   |  +- copyMessages (Boolean) Copy important messages to the network
  73.  *   |  |                         window
  74.  *   |  +- client
  75.  *   |  |  +- maxlines  (Number) max lines to keep in *client* view
  76.  *   |  +- network
  77.  *   |  |  +- maxlines  (Number) max lines to keep in network views
  78.  *   |  +- channel
  79.  *   |  |  +- maxlines  (Number) max lines to keep in channel views
  80.  *   |  +- chanuser
  81.  *   |     +- maxlines  (Number) max lines to keep in /msg views
  82.  *   +- debug
  83.  *      +- tracer (Boolean) enable/disable debug message tracing
  84.  */
  85.  
  86. function readIRCPrefs (rootNode)
  87. {
  88.     const PREF_CTRID = "@mozilla.org/preferences-service;1";
  89.     const nsIPrefBranch = Components.interfaces.nsIPrefBranch
  90.     var pref = Components.classes[PREF_CTRID].getService(nsIPrefBranch);
  91.     if(!pref)
  92.         throw ("Can't find pref component.");
  93.  
  94.     if (!rootNode)
  95.         rootNode = "extensions.irc.";
  96.  
  97.     if (!rootNode.match(/\.$/))
  98.         rootNode += ".";
  99.     
  100.     CIRCNetwork.prototype.INITIAL_NICK =
  101.         getCharPref (pref, rootNode + "nickname",
  102.                      CIRCNetwork.prototype.INITIAL_NICK);
  103.     CIRCNetwork.prototype.INITIAL_NAME =
  104.         getCharPref (pref, rootNode + "username",
  105.                      CIRCNetwork.prototype.INITIAL_NAME);
  106.     CIRCNetwork.prototype.INITIAL_DESC =
  107.         getCharPref (pref, rootNode + "desc",
  108.                      CIRCNetwork.prototype.INITIAL_DESC);
  109.     client.DEFAULT_NETWORK =
  110.         getCharPref (pref, rootNode + "defaultNet", "moznet");
  111.     client.CHARSET = getCharPref (pref, rootNode + "charset", "");
  112.     client.INITIAL_URLS =
  113.         getCharPref (pref, rootNode + "initialURLs", "irc://");
  114.     if (!client.INITIAL_URLS)
  115.         client.INITIAL_URLS = "irc://";
  116.     client.INITIAL_SCRIPTS =
  117.         getCharPref (pref, rootNode + "initialScripts", "");
  118.     client.NEW_TAB_THRESHOLD =
  119.         getIntPref (pref, rootNode + "newTabThreshold", 15);
  120.     client.FOCUS_NEW_TAB =
  121.         getIntPref (pref, rootNode + "focusNewTab", false);
  122.     client.ADDRESSED_NICK_SEP =
  123.         getCharPref (pref, rootNode + "nickCompleteStr",
  124.                      client.ADDRESSED_NICK_SEP).replace(/\s*$/, "");
  125.     client.INITIAL_VICTIMS =
  126.         getCharPref (pref, rootNode + "stalkWords", "");
  127.     
  128.     client.DELETE_ON_PART =
  129.         getCharPref (pref, rootNode + "deleteOnPart", true);
  130.  
  131.     client.STALK_BEEP =
  132.         getCharPref (pref, rootNode + "stalkBeep", "beep");
  133.     client.MSG_BEEP =
  134.         getCharPref (pref, rootNode + "msgBeep", "beep beep");
  135.     client.QUERY_BEEP =
  136.         getCharPref (pref, rootNode + "queryBeep", "beep");
  137.     
  138.     client.munger.enabled =
  139.         getBoolPref (pref, rootNode + "munger", client.munger.enabled);
  140.  
  141.     client.enableColors =
  142.         getBoolPref (pref, rootNode + "munger.colorCodes", true);
  143.  
  144.     client.smileyText =
  145.         getBoolPref (pref, rootNode + "munger.smileyText", false);
  146.  
  147.     for (var entry in client.munger.entries)
  148.     {
  149.         if (entry[0] != ".")
  150.         {
  151.             client.munger.entries[entry].enabled =
  152.                 getBoolPref (pref, rootNode + "munger." + entry,
  153.                              client.munger.entries[entry].enabled);
  154.         }
  155.     }
  156.  
  157.     client.FLASH_WINDOW =
  158.         getBoolPref (pref, rootNode + "notify.aggressive", true);
  159.  
  160.     client.SAVE_SETTINGS =
  161.         getBoolPref (pref, rootNode + "settings.autoSave", true);
  162.  
  163.     client.DEFAULT_STYLE =
  164.         getCharPref (pref, rootNode + "style.default",
  165.                      "chrome://chatzilla/skin/output-default.css");
  166.     
  167.     client.COLLAPSE_MSGS = 
  168.         getBoolPref (pref, rootNode + "views.collapseMsgs", false);
  169.  
  170.     client.COPY_MESSAGES = 
  171.         getBoolPref (pref, rootNode + "views.copyMessages", true);
  172.  
  173.     client.MAX_MESSAGES = 
  174.         getIntPref (pref, rootNode + "views.client.maxlines",
  175.                     client.MAX_MESSAGES);
  176.  
  177.     CIRCNetwork.prototype.MAX_MESSAGES =
  178.         getIntPref (pref, rootNode + "views.network.maxlines",
  179.                     CIRCChanUser.prototype.MAX_MESSAGES);
  180.  
  181.     CIRCChannel.prototype.MAX_MESSAGES =
  182.         getIntPref (pref, rootNode + "views.channel.maxlines",
  183.                     CIRCChannel.prototype.MAX_MESSAGES);
  184.  
  185.     CIRCUser.prototype.MAX_MESSAGES =
  186.         getIntPref (pref, rootNode + "views.chanuser.maxlines",
  187.                     CIRCChanUser.prototype.MAX_MESSAGES);
  188.     
  189.     var h = client.eventPump.getHook ("event-tracer");
  190.     h.enabled = client.debugMode =
  191.         getBoolPref (pref, rootNode + "debug.tracer", h.enabled);
  192.     
  193. }
  194.  
  195. function writeIRCPrefs (rootNode)
  196. {
  197.     const PREF_CTRID = "@mozilla.org/preferences-service;1";
  198.     const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
  199.     var pref = Components.classes[PREF_CTRID].getService(nsIPrefBranch);
  200.     if(!pref)
  201.         throw ("Can't find pref component.");
  202.  
  203.     if (!rootNode)
  204.         rootNode = "extensions.irc.";
  205.  
  206.     if (!rootNode.match(/\.$/))
  207.         rootNode += ".";
  208.     
  209.     pref.setCharPref (rootNode + "nickname",
  210.                       CIRCNetwork.prototype.INITIAL_NICK);
  211.     pref.setCharPref (rootNode + "username",
  212.                       CIRCNetwork.prototype.INITIAL_NAME);
  213.     pref.setCharPref (rootNode + "desc", CIRCNetwork.prototype.INITIAL_DESC);
  214.     pref.setCharPref (rootNode + "charset", client.CHARSET);
  215.     pref.setCharPref (rootNode + "nickCompleteStr", client.ADDRESSED_NICK_SEP);
  216.     pref.setCharPref (rootNode + "initialURLs", client.INITIAL_URLS);
  217.     pref.setCharPref (rootNode + "initialScripts", client.INITIAL_SCRIPTS);
  218.     pref.setCharPref (rootNode + "newTabThreshold", client.NEW_TAB_THRESHOLD);
  219.     pref.setCharPref (rootNode + "focusNewTab", client.FOCUS_NEW_TAB);
  220.     pref.setCharPref (rootNode + "style.default", client.DEFAULT_STYLE);
  221.     pref.setCharPref (rootNode + "stalkWords",
  222.                       client.stalkingVictims.join ("; "));
  223.     pref.setCharPref (rootNode + "stalkBeep", client.STALK_BEEP);
  224.     pref.setCharPref (rootNode + "msgBeep", client.MSG_BEEP);
  225.     pref.setCharPref (rootNode + "queryBeep", client.QUERY_BEEP);    
  226.     pref.setBoolPref (rootNode + "munger", client.munger.enabled);
  227.     pref.setBoolPref (rootNode + "munger.colorCodes", client.enableColors);
  228.     pref.setBoolPref (rootNode + "munger.smileyText", client.smileyText);
  229.  
  230.     for (var entry in client.munger.entries)
  231.     {
  232.         if (entry[0] != ".")
  233.         {
  234.             pref.setBoolPref (rootNode + "munger." + entry,
  235.                               client.munger.entries[entry].enabled);
  236.         }
  237.     }
  238.     pref.setBoolPref (rootNode + "notify.aggressive", client.FLASH_WINDOW);
  239.     pref.setBoolPref (rootNode + "views.collapseMsgs", client.COLLAPSE_MSGS);
  240.     pref.setBoolPref (rootNode + "views.copyMessages", client.COPY_MESSAGES);
  241.     pref.setIntPref (rootNode + "views.client.maxlines", client.MAX_MESSAGES);
  242.     pref.setIntPref (rootNode + "views.network.maxlines",
  243.                      CIRCChanUser.prototype.MAX_MESSAGES);
  244.     pref.setIntPref (rootNode + "views.channel.maxlines",
  245.                      CIRCChannel.prototype.MAX_MESSAGES);
  246.     pref.setIntPref (rootNode + "views.chanuser.maxlines",
  247.                      CIRCChanUser.prototype.MAX_MESSAGES);
  248.     
  249.     var h = client.eventPump.getHook ("event-tracer");
  250.     pref.setBoolPref (rootNode + "debug.tracer", h.enabled);
  251.     
  252. }
  253.  
  254. function getCharPref (prefObj, prefName, defaultValue)
  255. {
  256.     var e, rv;
  257.     
  258.     try
  259.     {
  260.         rv = prefObj.getCharPref (prefName);
  261.     }
  262.     catch (e)
  263.     {
  264.         rv = defaultValue;
  265.     }
  266.  
  267.     //dd ("getCharPref: returning '" + rv + "' for " + prefName);
  268.     return rv;
  269.     
  270. }
  271.  
  272. function getIntPref (prefObj, prefName, defaultValue)
  273. {
  274.     var e;
  275.  
  276.     try
  277.     {
  278.         return prefObj.getIntPref (prefName);
  279.     }
  280.     catch (e)
  281.     {
  282.         return defaultValue;
  283.     }
  284.     
  285. }
  286.  
  287. function getBoolPref (prefObj, prefName, defaultValue)
  288. {
  289.     var e;
  290.  
  291.     try
  292.     {
  293.         return prefObj.getBoolPref (prefName);
  294.     }
  295.     catch (e)
  296.     {
  297.         return defaultValue;
  298.     }
  299.     
  300. }
  301.