1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
10 /* PJIRC is free software; you can redistribute */
11 /* it and/or modify it under the terms of the GNU */
12 /* General Public License as published by the */
13 /* Free Software Foundation; version 2 or later of */
16 /* PJIRC is distributed in the hope that it will */
17 /* be useful, but WITHOUT ANY WARRANTY; without */
18 /* even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
20 /* General Public License for more details. */
22 /* You should have received a copy of the GNU */
23 /* General Public License along with PJIRC; if */
24 /* not, write to the Free Software Foundation, */
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
26 /* MA 02111-1307 USA */
28 /*****************************************************/
32 import irc.FileTextProvider;
33 import irc.IRCConfiguration;
34 import irc.ParameterProvider;
35 import irc.StringParser;
36 import irc.TextProvider;
38 import java.awt.Color;
39 import java.util.Vector;
42 * Toolkit for Configuration creation.
44 public class PixxConfigurationLoader {
45 private IRCConfiguration _config;
46 private ParameterProvider _provider;
49 * Create a new PixxConfigurationLoader.
52 * the irc configuration.
54 public PixxConfigurationLoader(IRCConfiguration config) {
56 _provider = _config.getInterfaceParameterProvider();
61 * Create a new PixxConfiguration object, using the given IRCConfiguration.
63 * @return a new PixxConfiguration instance.
67 public PixxConfiguration loadPixxConfiguration() throws Exception {
68 return getPixxConfiguration();
71 private String getParameter(String key) {
72 return _provider.getParameter(key);
75 private boolean getBoolean(String key, boolean def) {
76 String v = getParameter(key);
79 v = v.toLowerCase(java.util.Locale.ENGLISH).trim();
80 if (v.equals("true") || v.equals("on") || v.equals("1"))
85 private String getString(String key, String def) {
86 String v = getParameter(key);
92 private int getInt(String key, int def) {
93 String v = getParameter(key);
97 return Integer.parseInt(v);
98 } catch (Exception e) {
104 private TextProvider getTextProvider() {
105 String lang = getString("language", "pixx-english");
106 String encoding = getString("languageencoding", "");
107 String extension = getString("lngextension", "lng");
108 String backlang = getString("backuplanguage", "pixx-english");
109 String backencoding = getString("backuplanguageencoding", "");
110 return new FileTextProvider(lang + "." + extension, encoding, backlang + "." + extension, backencoding,
111 _config.getFileHandler());
114 private String[] getArray(String name) {
115 Vector v = new Vector();
119 cmd = getParameter(name + i);
121 v.insertElementAt(cmd, v.size());
123 } while (cmd != null);
124 String[] ans = new String[v.size()];
125 for (i = 0; i < v.size(); i++)
126 ans[i] = (String) v.elementAt(i);
130 private void readDocking(PixxConfiguration config) {
131 StringParser parser = new StringParser();
132 String[] arr = getArray("dockingconfig");
133 for (int i = 0; i < arr.length; i++) {
135 String back[] = parser.parseString(cmd);
136 if (back.length >= 3) {
137 String type = back[0].toLowerCase(java.util.Locale.ENGLISH);
138 String name = back[1].toLowerCase(java.util.Locale.ENGLISH);
139 String action = back[2].toLowerCase(java.util.Locale.ENGLISH);
140 boolean undock = false;
141 if (action.equals("undock"))
143 config.setDockingPolicy(type, name, undock);
148 private void readMouse(PixxConfiguration config, String name, int button, int click) throws Exception {
149 String s = getString("mouse" + name.toLowerCase(java.util.Locale.ENGLISH), button + " " + click);
150 int pos = s.indexOf(' ');
152 throw new Exception("mouse" + name.toLowerCase(java.util.Locale.ENGLISH) + " parameter syntax error");
153 String before = s.substring(0, pos).trim();
154 String after = s.substring(pos + 1).trim();
155 config.setMouseConfiguration(name, new Integer(before).intValue(), new Integer(after).intValue());
158 private String[] getHighLightWords() {
159 String words = getParameter("highlightwords");
161 return new String[0];
162 return new StringParser().parseString(words);
165 private void add(Vector v, Object o) {
166 v.insertElementAt(o, v.size());
169 private void str2(Vector v, PixxConfiguration c, int id, String str) {
170 add(v, new String[] { c.getText(id), str });
174 * Load default popup menu configuration, based on the global
178 * global IRCConfiguration.
180 public void loadDefaultPopup(PixxConfiguration config) {
181 Vector v = config.getNickMenuVector();
184 boolean b = config.getB("showstatus") && !config.getIRCConfiguration().getB("useinfo");
186 str2(v, config, PixxTextProvider.GUI_WHOIS, "/whois %1");
187 str2(v, config, PixxTextProvider.GUI_QUERY, "/query %1");
188 str2(v, config, PixxTextProvider.GUI_KICK, "/kick %2 %1");
189 str2(v, config, PixxTextProvider.GUI_BAN, "/mode %2 +b %1");
191 str[0] = config.getText(PixxTextProvider.GUI_KICKBAN);
192 str[1] = "/mode %2 -o %1";
193 str[2] = "/mode %2 +b %1";
194 str[3] = "/kick %2 %1";
197 add(v, new String[] { "--" });
198 str2(v, config, PixxTextProvider.GUI_OP, "/mode %2 +o %1");
199 str2(v, config, PixxTextProvider.GUI_DEOP, "/mode %2 -o %1");
200 str2(v, config, PixxTextProvider.GUI_VOICE, "/mode %2 +v %1");
201 str2(v, config, PixxTextProvider.GUI_DEVOICE, "/mode %2 -v %1");
203 add(v, new String[] { "--" });
204 str2(v, config, PixxTextProvider.GUI_PING, "/ctcp ping %1");
205 str2(v, config, PixxTextProvider.GUI_VERSION, "/ctcp version %1");
206 str2(v, config, PixxTextProvider.GUI_TIME, "/ctcp time %1");
207 str2(v, config, PixxTextProvider.GUI_FINGER, "/ctcp finger %1");
211 private void readPopup(PixxConfiguration config) {
212 if (!getBoolean("configurepopup", false)) {
213 loadDefaultPopup(config);
216 Vector v = config.getNickMenuVector();
217 String[] str = getArray("popupmenustring");
218 for (int i = 0; i < str.length; i++) {
220 String cmd[] = getArray("popupmenucommand" + (i + 1) + "_");
221 String[] fin = new String[1 + cmd.length];
223 for (int j = 0; j < cmd.length; j++)
229 private PixxColorModel getColorModel() {
230 PixxColorModel model = new PixxColorModel();
232 for (int i = 0; i < model.getColorCount(); i++) {
233 String color = getParameter("color" + i);
236 model.setColor(i, new Color(Integer.parseInt(color, 16)));
238 } catch (Exception e) {
244 private PixxConfiguration getPixxConfiguration() throws Exception {
245 PixxConfiguration config = new PixxConfiguration(_config);
246 config.setTextProvider(getTextProvider());
248 Vector v = new Vector();
249 String[] words = getHighLightWords();
250 for (int i = 0; i < words.length; i++)
251 v.insertElementAt(words[i], v.size());
252 config.setHighLightConfig(getInt("highlightcolor", 5), getBoolean("highlightnick", false), v);
253 config.set("highlight", getBoolean("highlight", false));
255 config.set("timestamp", getBoolean("timestamp", false));
256 config.set("showclose", getBoolean("showclose", true));
257 config.set("showconnect", getBoolean("showconnect", true));
258 config.set("showchanlist", getBoolean("showchanlist", true));
259 config.set("showabout", getBoolean("showabout", true));
260 config.set("showhelp", getBoolean("showhelp", true));
261 config.set("nicklistwidth", getInt("nicklistwidth", 130));
262 config.set("nickfield", getBoolean("nickfield", false));
263 config.set("showstatus", getBoolean("showstatus", true));
264 config.set("styleselector", getBoolean("styleselector", false));
265 config.set("setfontonstyle", getBoolean("setfontonstyle", false));
266 config.set("helppage", getString("helppage", "http://www.pjirc.com/help.php"));
267 config.set("showchannelnickchanged", getBoolean("showchannelnickchanged", true));
268 config.set("showchannelnickmodeapply", getBoolean("showchannelnickmodeapply", true));
269 config.set("showchannelmodeapply", getBoolean("showchannelmodeapply", true));
270 config.set("showchanneltopicchanged", getBoolean("showchanneltopicchanged", true));
271 config.set("showchannelnickquit", getBoolean("showchannelnickquit", true));
272 config.set("showchannelnickkick", getBoolean("showchannelnickkick", true));
273 config.set("showchannelnickpart", getBoolean("showchannelnickpart", true));
274 config.set("showchannelnickjoin", getBoolean("showchannelnickjoin", true));
275 config.set("showdock", getBoolean("showdock", true));
276 config.set("automaticqueries", getBoolean("automaticqueries", true));
277 config.set("leftnickalign", getBoolean("leftnickalign", false));
278 config.set("taskbaritemwidth", getInt("taskbaritemwidth", 100));
279 config.set("scrollspeed", getInt("scrollspeed", 0));
280 config.set("leaveonundockedwindowclose", getBoolean("leaveonundockedwindowclose", false));
281 config.set("nickprefix", getString("nickprefix", "<"));
282 config.set("nickpostfix", getString("nickpostfix", "> "));
283 config.set("showchannelyoujoin", getBoolean("showchannelyoujoin", false));
285 config.set("displayentertexthere", getBoolean("displayentertexthere", false));
286 config.set("ignoreallmouseevents", getBoolean("ignoreallmouseevents", false));
287 config.set("hideundockedsources", getBoolean("hideundockedsources", false));
289 config.set("displaychannelname", getBoolean("displaychannelname", true));
290 config.set("displaychannelmode", getBoolean("displaychannelmode", true));
291 config.set("displaychannelcount", getBoolean("displaychannelcount", true));
292 config.set("displaychanneltopic", getBoolean("displaychanneltopic", true));
294 config.setColorModel(getColorModel());
296 readMouse(config, "nickquery", 1, 2);
297 readMouse(config, "urlopen", 1, 2);
298 readMouse(config, "channeljoin", 1, 2);
299 readMouse(config, "nickpopup", 3, 1);
300 readMouse(config, "taskbarpopup", 3, 1);