]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/IRCApplication.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / IRCApplication.java
1 /*****************************************************/
2 /*          This java file is a part of the          */
3 /*                                                   */
4 /*           -  Plouf's Java IRC Client  -           */
5 /*                                                   */
6 /*   Copyright (C)  2002 - 2005 Philippe Detournay   */
7 /*                                                   */
8 /*         All contacts : theplouf@yahoo.com         */
9 /*                                                   */
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  */
14 /*  the License.                                     */
15 /*                                                   */
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.         */
21 /*                                                   */
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                              */
27 /*                                                   */
28 /*****************************************************/
29
30 package irc;
31
32 import irc.gui.GUISource;
33 import irc.gui.IRCInterface;
34 import irc.gui.IRCInterfaceListener;
35 import irc.ident.IdentListener;
36 import irc.ident.IdentWrapper;
37 import irc.plugin.Plugin;
38
39 import java.awt.Button;
40 import java.awt.Container;
41 import java.awt.FlowLayout;
42 import java.awt.Font;
43 import java.awt.Frame;
44 import java.awt.GridLayout;
45 import java.awt.TextField;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.awt.event.WindowEvent;
49 import java.awt.event.WindowListener;
50 import java.io.File;
51 import java.util.Enumeration;
52 import java.util.Hashtable;
53 import java.util.Vector;
54
55 /**
56  * The IRC Application. This is the main class of PJIRC.
57  */
58 public class IRCApplication extends IRCObject implements ServerListener, ServerManager, IdentListener,
59                 IRCInterfaceListener, WindowListener, ActionListener, PluginManager {
60         private DefaultSource _defaultSource;
61
62         private Interpretor _inter;
63
64         private IdentWrapper _ident;
65
66         private StartupConfiguration _start;
67
68         private IRCInterface _interface;
69         private Vector _plugins;
70         private Hashtable _pluginsTable;
71
72         private Frame _frame;
73         private Container _container;
74
75         private Hashtable _servers;
76
77         private Object _nickLock = new Object();
78
79         /**
80          * Create a new IRCApplication.
81          * 
82          * @param config
83          *          the IRC configuration.
84          * @param startupConfig
85          *          the startup configuration.
86          * @param source
87          *          a container in wich the application will display. Maybe null. If
88          *          null, a new Frame will be opened.
89          */
90         public IRCApplication(IRCConfiguration config, StartupConfiguration startupConfig, Container source) {
91                 super(config);
92                 _container = source;
93                 _start = startupConfig;
94                 _plugins = new Vector();
95                 _pluginsTable = new Hashtable();
96
97                 String gui = config.getS("gui");
98                 try {
99                         Class cl = Class.forName("irc.gui." + gui + ".Interface");
100                         java.lang.reflect.Constructor ctr = cl.getDeclaredConstructor(new Class[] { config.getClass() });
101                         _interface = (IRCInterface) ctr.newInstance(new Object[] { config });
102                 } catch (java.lang.reflect.InvocationTargetException iex) {
103                         iex.getTargetException().printStackTrace();
104                         throw new Error("Unable to load interface " + gui + " : " + iex.getTargetException());
105                 } catch (Throwable ex) {
106                         ex.printStackTrace();
107                         throw new Error("Unable to load interface " + gui + " : " + ex);
108                 }
109
110                 _servers = new Hashtable();
111                 _defaultSource = new DefaultSource(_ircConfiguration);
112                 DefaultInterpretor defaultInter = new DefaultInterpretor(_ircConfiguration, _start, this, this);
113                 _defaultSource.setInterpretor(defaultInter);
114         }
115
116         /**
117          * Init the application.
118          */
119         public synchronized void init() {
120                 loadPlugin(_interface);
121
122                 String[] plugins = _start.getPlugins();
123                 for (int i = 0; i < plugins.length; i++)
124                         loadPlugin(plugins[i]);
125
126                 _interface.addIRCInterfaceListener(this);
127                 if (_container == null) {
128                         _frame = new Frame();
129                         _frame.addWindowListener(this);
130                         if (_interface.getComponent() != null)
131                                 _frame.add(_interface.getComponent());
132                         _frame.setFont(new Font("", Font.PLAIN, 12));
133                         _frame.setSize(640, 400);
134                         _frame.show();
135                 } else {
136                         _frame = null;
137                         _container.removeAll();
138                         _container.setLayout(new GridLayout(1, 1));
139                         if (_interface.getComponent() != null)
140                                 _container.add(_interface.getComponent());
141                 }
142
143                 _inter = new CTCPInterpretor(_ircConfiguration, _defaultSource.getInterpretor(), this);
144                 _inter.addLast(_interface.getInterpretor());
145
146                 if (_ircConfiguration.getB("useidentserver")) {
147                         try {
148                                 _ident = new IdentWrapper(_ircConfiguration);
149                                 Exception e = _ident.start(_start.getName(), this);
150                                 if (e != null) {
151                                         _defaultSource.report("\3" + "6" + "*** " + getText(IRCTextProvider.IDENT_FAILED_LAUNCH, e.getMessage()));
152                                 }
153                         } catch (Throwable ex) {
154                                 _ircConfiguration.internalError("ident error", ex, "plouf@pjirc.com");
155                         }
156                 } else {
157                         _ident = null;
158                 }
159
160                 String[] init = _ircConfiguration.getInitialization();
161                 for (int i = 0; i < init.length; i++)
162                         _defaultSource.sendString(init[i]);
163
164                 IRCServer server = new IRCServer(_ircConfiguration, this, _start.getNick(), _start.getAltNick(), _start.getName(),
165                                 _start.getAlias());
166                 server.setServers(_start.getHost(), _start.getPort(), _start.getPass());
167
168                 newServer(server, _ircConfiguration.getB("autoconnection"));
169
170                 requestSourceFocus();
171         }
172
173         /**
174          * Get the IRC interface.
175          * 
176          * @return the IRC interface.
177          */
178         public IRCInterface getIRCInterface() {
179                 return _interface;
180         }
181
182         @Override
183         public void newServer(Server server, boolean connect) {
184                 server.addServerListener(this);
185                 _servers.put(server, server);
186
187                 Enumeration enum1 = _plugins.elements();
188                 while (enum1.hasMoreElements()) {
189                         Plugin plugin = (Plugin) enum1.nextElement();
190                         plugin.serverCreated(server);
191                 }
192
193                 server.enumerateSourcesAsCreated(this);
194                 if (connect)
195                         server.connect();
196         }
197
198         /**
199          * Uninit the application.
200          */
201         public synchronized void uninit() {
202                 Enumeration en = _servers.keys();
203                 while (en.hasMoreElements()) {
204                         Server s = (Server) en.nextElement();
205                         s.leave();
206                 }
207
208                 if (_ident != null)
209                         _ident.stop();
210                 _interface.removeIRCInterfaceListener(this);
211
212                 if (_frame != null)
213                         _frame.removeWindowListener(this);
214                 _frame = null;
215
216                 while (_plugins.size() > 0) {
217                         unloadPlugin((Plugin) _plugins.elementAt(_plugins.size() - 1));
218                 }
219                 _pluginsTable = new Hashtable();
220
221                 if (_container != null)
222                         _container.removeAll();
223
224                 EventDispatcher.clearCache();
225         }
226
227         @Override
228         public boolean loadPlugin(String str) {
229                 if (_pluginsTable.get(str) != null)
230                         return false;
231                 Plugin plugin;
232                 try {
233                         Class cl = Class.forName("irc.plugin." + str);
234                         java.lang.reflect.Constructor ctr = cl.getDeclaredConstructor(new Class[] { _ircConfiguration.getClass() });
235                         plugin = (Plugin) ctr.newInstance(new Object[] { _ircConfiguration });
236                         loadPlugin(plugin);
237                 } catch (Throwable ex) {
238                         ex.printStackTrace();
239                         return false;
240                 }
241                 _pluginsTable.put(str, plugin);
242                 return true;
243         }
244
245         @Override
246         public boolean unloadPlugin(String str) {
247                 Plugin plugin = (Plugin) _pluginsTable.get(str);
248                 if (plugin == null)
249                         return false;
250                 _pluginsTable.remove(str);
251                 unloadPlugin(plugin);
252                 return true;
253         }
254
255         private void loadPlugin(Plugin plugin) {
256                 class addHandler implements ServerListener {
257                         private Plugin _plugin;
258
259                         /**
260                          * Create a new addHandler
261                          * 
262                          * @param plug
263                          *          plugin.
264                          */
265                         public addHandler(Plugin plug) {
266                                 _plugin = plug;
267                         }
268
269                         @Override
270                         public void serverConnected(Server s) {/* ... */
271                         }
272
273                         @Override
274                         public void serverDisconnected(Server s) {/* ... */
275                         }
276
277                         @Override
278                         public void serverLeft(Server s) {/* ... */
279                         }
280
281                         @Override
282                         public String[] cannotUseRequestedNicknames(Server s) {
283                                 return null;
284                         }
285
286                         @Override
287                         public void sourceCreated(Source source, Server server, Boolean bring) {
288                                 _plugin.sourceCreated(source, bring);
289                         }
290
291                         @Override
292                         public void sourceRemoved(Source source, Server server) {/* ... */
293                         }
294
295                         @Override
296                         public Object specialServerRequest(String request, Server server, Object[] params) {
297                                 return null;
298                         }
299                 }
300
301                 plugin.setIRCApplication(this);
302                 plugin.load();
303                 _plugins.insertElementAt(plugin, _plugins.size());
304                 plugin.sourceCreated(_defaultSource, Boolean.TRUE);
305
306                 Enumeration en = _servers.keys();
307                 while (en.hasMoreElements()) {
308                         Server s = (Server) en.nextElement();
309                         plugin.serverCreated(s);
310
311                         s.enumerateSourcesAsCreated(new addHandler(plugin));
312                 }
313
314         }
315
316         private void unloadPlugin(Plugin plugin) {
317                 class removeHandler implements ServerListener {
318                         private Plugin _plugin;
319
320                         /**
321                          * Create a new removeHandler
322                          * 
323                          * @param plug
324                          *          plugin.
325                          */
326                         public removeHandler(Plugin plug) {
327                                 _plugin = plug;
328                         }
329
330                         @Override
331                         public void serverConnected(Server s) {/* ... */
332                         }
333
334                         @Override
335                         public void serverDisconnected(Server s) {/* ... */
336                         }
337
338                         @Override
339                         public void serverLeft(Server s) {/* ... */
340                         }
341
342                         @Override
343                         public String[] cannotUseRequestedNicknames(Server s) {
344                                 return null;
345                         }
346
347                         @Override
348                         public void sourceCreated(Source source, Server server, Boolean bring) {/* ... */
349                         }
350
351                         @Override
352                         public void sourceRemoved(Source source, Server server) {
353                                 _plugin.sourceRemoved(source);
354                         }
355
356                         @Override
357                         public Object specialServerRequest(String request, Server server, Object[] params) {
358                                 return null;
359                         }
360                 }
361
362                 for (int i = 0; i < _plugins.size(); i++) {
363                         if (_plugins.elementAt(i) == plugin) {
364                                 _plugins.removeElementAt(i);
365                                 Enumeration en = _servers.keys();
366                                 while (en.hasMoreElements()) {
367                                         Server s = (Server) en.nextElement();
368                                         s.enumerateSourcesAsRemoved(new removeHandler(plugin));
369                                         plugin.serverRemoved(s);
370                                 }
371                                 plugin.sourceRemoved(_defaultSource);
372                                 plugin.unload();
373                                 return;
374                         }
375                 }
376         }
377
378         @Override
379         public void sourceCreated(Source source, Server server, Boolean bring) {
380                 source.getInterpretor().addLast(_inter);
381                 Enumeration enum1 = _plugins.elements();
382                 while (enum1.hasMoreElements()) {
383                         Plugin plugin = (Plugin) enum1.nextElement();
384                         plugin.sourceCreated(source, bring);
385                 }
386         }
387
388         @Override
389         public void sourceRemoved(Source source, Server server) {
390                 Enumeration enum1 = _plugins.elements();
391                 while (enum1.hasMoreElements()) {
392                         Plugin plugin = (Plugin) enum1.nextElement();
393                         plugin.sourceRemoved(source);
394                 }
395         }
396
397         @Override
398         public void serverLeft(Server s) {
399                 Enumeration enum1 = _plugins.elements();
400                 while (enum1.hasMoreElements()) {
401                         Plugin plugin = (Plugin) enum1.nextElement();
402                         plugin.serverRemoved(s);
403                 }
404                 _servers.remove(s);
405                 s.removeServerListener(this);
406         }
407
408         private Frame getParentFrame() {
409                 if (_frame != null)
410                         return _frame;
411                 Container ans = _container;
412                 while (ans != null) {
413                         if (ans instanceof Frame)
414                                 return (Frame) ans;
415                         ans = ans.getParent();
416                 }
417                 return null;
418         }
419
420         /**
421          * Get the application's parent container. The GUI instance will be added into
422          * this container or one of its children.
423          * 
424          * @return application's parent container.
425          */
426         public Container getContainer() {
427                 if (_frame != null)
428                         return _frame;
429                 return _container;
430         }
431
432         @Override
433         public Object specialServerRequest(String request, Server s, Object[] params) {
434                 if (request.equals("DCCFileRequest")) {
435                         File f = _ircConfiguration.getSecurityProvider().getSaveFile(params[1].toString(),
436                                         getText(IRCTextProvider.FILE_SAVEAS) + " [" + params[1] + "]");
437                         return f;
438                 } else if (request.equals("DCCChatRequest")) {
439                         boolean accept = _ircConfiguration.getSecurityProvider().confirm(getParentFrame(),
440                                         getText(IRCTextProvider.GUI_DCC_CHAT_WARNING_TITLE),
441                                         getText(IRCTextProvider.GUI_DCC_CHAT_WARNING_TEXT, (String) params[0]));
442                         return new Boolean(accept);
443                 } else {
444                         _ircConfiguration.internalError("Unknown request : " + request, null, "plouf@pjirc.com");
445                         return null;
446                 }
447         }
448
449         @Override
450         public void serverConnected(Server server) {
451                 for (int i = 0; i < _start.getCommands().length; i++) {
452                         String cmd = _start.getCommands()[i];
453                         if ((cmd.startsWith("/")) && (server instanceof IRCServer))
454                                 ((IRCServer) server).getStatus().sendString(_start.getCommands()[i]);
455                         else
456                                 server.execute(_start.getCommands()[i]);
457                 }
458
459                 Enumeration enum1 = _plugins.elements();
460                 while (enum1.hasMoreElements()) {
461                         Plugin plugin = (Plugin) enum1.nextElement();
462                         plugin.serverConnected(server);
463                 }
464
465         }
466
467         @Override
468         public void serverDisconnected(Server s) {
469                 Enumeration enum1 = _plugins.elements();
470                 while (enum1.hasMoreElements()) {
471                         Plugin plugin = (Plugin) enum1.nextElement();
472                         plugin.serverDisconnected(s);
473                 }
474         }
475
476         @Override
477         public void identRequested(String source, Integer result, String reply) {
478                 _defaultSource.report("\3" + "6" + "*** " + getText(IRCTextProvider.IDENT_REQUEST, source));
479                 String s = "";
480                 switch (result.intValue()) {
481                 case IdentListener.IDENT_ERROR:
482                         s = getText(IRCTextProvider.IDENT_ERROR);
483                         break;
484                 case IdentListener.IDENT_OK:
485                         s = getText(IRCTextProvider.IDENT_REPLIED, reply);
486                         break;
487                 case IdentListener.IDENT_DEFAULT:
488                         s = getText(IRCTextProvider.IDENT_REPLIED, getText(IRCTextProvider.IDENT_DEFAULT_USER) + " : " + reply);
489                         break;
490                 case IdentListener.IDENT_NOT_FOUND:
491                         s = getText(IRCTextProvider.IDENT_NO_USER);
492                         break;
493                 default:
494                         s = getText(IRCTextProvider.IDENT_UNDEFINED);
495                         break;
496                 }
497                 _defaultSource.report("\3" + "6" + "*** " + s);
498
499         }
500
501         @Override
502         public void identRunning(Integer port) {
503                 _defaultSource.report("\3" + "6" + "*** " + getText(IRCTextProvider.IDENT_RUNNING_ON_PORT, port + ""));
504         }
505
506         @Override
507         public void identLeaving(String message) {
508                 _defaultSource.report("\3" + "6" + "*** " + getText(IRCTextProvider.IDENT_LEAVING, message));
509         }
510
511         @Override
512         public void activeChanged(GUISource source, IRCInterface inter) {
513                 if (source != null) {
514                         if (source.getSource().mayDefault())
515                                 source.getSource().getServer().setDefaultSource(source.getSource());
516                         if (_frame != null)
517                                 _frame.setTitle(source.getTitle());
518                 }
519         }
520
521         @Override
522         public void windowActivated(WindowEvent e) {
523                 // nothing here
524         }
525
526         @Override
527         public void windowClosed(WindowEvent e) {
528                 if (e.getSource() == _frame) {
529                         EventDispatcher.dispatchEventAsync(this, "uninit", new Object[0]);
530                 }
531         }
532
533         @Override
534         public void windowClosing(WindowEvent e) {
535                 ((Frame) e.getSource()).hide();
536                 ((Frame) e.getSource()).dispose();
537         }
538
539         @Override
540         public void windowDeactivated(WindowEvent e) {
541                 // nothing here
542         }
543
544         @Override
545         public void windowDeiconified(WindowEvent e) {
546                 // nothing here
547         }
548
549         @Override
550         public void windowIconified(WindowEvent e) {
551                 // nothing here
552         }
553
554         @Override
555         public void windowOpened(WindowEvent e) {
556                 // nothing here
557         }
558
559         private GUISource getActiveSource() {
560                 return _interface.getActive();
561         }
562
563         private Source getSource(String serverName, String type, String name) {
564                 Enumeration e = _servers.keys();
565                 while (e.hasMoreElements()) {
566                         Server s = (Server) e.nextElement();
567                         String sname = s.getServerName();
568                         if (sname.equals(serverName) || serverName.length() == 0) {
569                                 Enumeration f = s.getSources();
570                                 while (f.hasMoreElements()) {
571                                         Source src = (Source) f.nextElement();
572                                         if (src.getType().equals(type) && src.getName().equals(name))
573                                                 return src;
574                                 }
575                         }
576                 }
577                 return null;
578         }
579
580         /**
581          * Request the active source to gain focus.
582          */
583         public void requestSourceFocus() {
584                 GUISource current = getActiveSource();
585                 if (current == null)
586                         return;
587                 current.requestFocus();
588         }
589
590         /**
591          * Request the given source to gain focus.
592          * 
593          * @param serverName
594          *          the source's server name, or an empty string if no server
595          *          filtering needs to be done.
596          * @param type
597          *          the source type.
598          * @param name
599          *          the source name.
600          */
601         public void requestSourceFocus(String serverName, String type, String name) {
602                 Source source = getSource(serverName, type, name);
603                 if (source != null) {
604                         GUISource gui = _interface.getGUISource(source);
605                         if (gui != null)
606                                 _interface.setActive(gui);
607                 }
608         }
609
610         /**
611          * Send the given command to the given source interpretor.
612          * 
613          * @param serverName
614          *          the source's server name, or an empty string if no server
615          *          filtering needs to be done.
616          * @param type
617          *          the source type.
618          * @param name
619          *          the source name.
620          * @param cmd
621          *          the command to send.
622          */
623         public void sendString(String serverName, String type, String name, String cmd) {
624                 Source source = getSource(serverName, type, name);
625                 if (source != null)
626                         source.sendString(cmd);
627         }
628
629         /**
630          * Send the given string to the current source interpretor.
631          * 
632          * @param str
633          *          string to send to the interpretor.
634          */
635         public void sendString(String str) {
636                 GUISource current = getActiveSource();
637                 if (current == null)
638                         return;
639                 current.getSource().sendString(str);
640         }
641
642         /**
643          * Set the current textfield text.
644          * 
645          * @param txt
646          *          new textfield text.
647          */
648         public void setFieldText(String txt) {
649                 GUISource current = getActiveSource();
650                 if (current == null)
651                         return;
652                 current.setFieldText(txt);
653         }
654
655         /**
656          * Get the current textfield text.
657          * 
658          * @return the current textfield text.
659          */
660         public String getFieldText() {
661                 GUISource current = getActiveSource();
662                 if (current == null)
663                         return "";
664                 return current.getFieldText();
665         }
666
667         /**
668          * Validate the current textfield text, as if user pressed return key.
669          */
670         public void validateText() {
671                 GUISource current = getActiveSource();
672                 if (current == null)
673                         return;
674                 current.validateText();
675         }
676
677         /**
678          * Send the given event value to the given plugin.
679          * 
680          * @param pluginName
681          *          the plugin name.
682          * @param event
683          *          the event value to be sent.
684          */
685         public void sendPluginEvent(String pluginName, Object event) {
686                 Plugin plugin = (Plugin) _pluginsTable.get(pluginName);
687                 if (plugin == null)
688                         return;
689                 plugin.externalEvent(event);
690         }
691
692         /**
693          * Get the plugin value from the given plugin name.
694          * 
695          * @param pluginName
696          *          the plugin name.
697          * @param valueName
698          *          the value name.
699          * @return the returned plugin value, or null if the plugin is not found.
700          */
701         public Object getPluginValue(String pluginName, Object valueName) {
702                 Plugin plugin = (Plugin) _pluginsTable.get(pluginName);
703                 if (plugin == null)
704                         return null;
705                 return plugin.getValue(valueName);
706         }
707
708         @Override
709         public String[] cannotUseRequestedNicknames(Server s) {
710                 synchronized (_nickLock) {
711                         if (_interface.getComponent() != null)
712                                 _interface.getComponent().setEnabled(false);
713                         if (_frame != null)
714                                 _frame.setEnabled(false);
715                         Frame f = new Frame();
716                         f.setLayout(new FlowLayout());
717                         f.setSize(200, 65);
718                         f.setTitle(getText(IRCTextProvider.GUI_CHANGE_NICK));
719                         TextField field = new TextField(_start.getNick());
720                         Button b = new Button("Ok");
721                         b.addActionListener(this);
722                         f.add(field);
723                         f.add(b);
724                         f.show();
725                         try {
726                                 _nickLock.wait();
727                         } catch (InterruptedException ex) {
728                                 // ignore...
729                         }
730                         f.hide();
731                         f.remove(b);
732                         f.remove(field);
733                         f.dispose();
734                         String[] ans = new String[1];
735                         ans[0] = field.getText();
736                         if (_frame != null)
737                                 _frame.setEnabled(true);
738                         if (_interface.getComponent() != null)
739                                 _interface.getComponent().setEnabled(true);
740                         return ans;
741                 }
742         }
743
744         @Override
745         public void actionPerformed(ActionEvent evt) {
746                 synchronized (_nickLock) {
747                         _nickLock.notifyAll();
748                 }
749         }
750
751         private static void usage() {
752                 System.out.println("Usage :");
753                 System.out.println("   java irc.IRCApplication -f configfile");
754                 System.out.println("or java irc.IRCApplication -p nick fullname host gui");
755                 System.out.println("");
756                 System.out.println("Without any parameter, '-f pjirc.cfg' parameters are assumed.");
757         }
758
759         /**
760          * Actual entry point.
761          * 
762          * @param args
763          *          application parameters.
764          */
765         public static void go(String[] args) {
766                 FileHandler file = new LocalFileHandler();
767                 IRCConfiguration ircConfiguration;
768                 StartupConfiguration startupConfiguration;
769
770                 try {
771
772                         if ((args.length == 0) || ((args.length >= 2) && (args[0].equals("-f")))) {
773                                 String f = "pjirc.cfg";
774                                 if (args.length >= 2)
775                                         f = args[1];
776                                 StreamParameterProvider provider = new StreamParameterProvider(file.getInputStream(f));
777                                 ConfigurationLoader loader = new ConfigurationLoader(provider, new NullURLHandler(), new AWTImageLoader(),
778                                                 new NullSoundHandler(), file);
779                                 ircConfiguration = loader.loadIRCConfiguration();
780                                 startupConfiguration = loader.loadStartupConfiguration();
781                         } else if ((args.length >= 5) && (args[0].equals("-p"))) {
782                                 StreamParameterProvider provider = new StreamParameterProvider(null);
783                                 ConfigurationLoader loader = new ConfigurationLoader(provider, new NullURLHandler(), new AWTImageLoader(),
784                                                 new NullSoundHandler(), file);
785                                 ircConfiguration = loader.loadIRCConfiguration();
786                                 ircConfiguration.set("gui", args[4]);
787                                 startupConfiguration = new StartupConfiguration(args[1], "", args[2], new String[] { "" },
788                                                 new String[] { args[3] }, new int[] { 6667 }, "", new String[] {}, new String[] {});
789                         } else {
790                                 usage();
791                                 return;
792                         }
793
794                         IRCApplication application = new IRCApplication(ircConfiguration, startupConfiguration, null);
795                         EventDispatcher.dispatchEventAsyncAndWaitEx(application, "init", new Object[0]);
796                 } catch (Throwable ex) {
797                         System.out.println("Error : " + ex.getMessage());
798                         ex.printStackTrace();
799                 }
800         }
801
802         /**
803          * Main entry point.
804          * 
805          * @param args
806          *          application parameters.
807          */
808         public static void main(String[] args) {
809                 go(args);
810         }
811
812 }