]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/ChanList.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / ChanList.java
1 /*****************************************************/\r
2 /*          This java file is a part of the          */\r
3 /*                                                   */\r
4 /*           -  Plouf's Java IRC Client  -           */\r
5 /*                                                   */\r
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */\r
7 /*                                                   */\r
8 /*         All contacts : theplouf@yahoo.com         */\r
9 /*                                                   */\r
10 /*  PJIRC is free software; you can redistribute     */\r
11 /*  it and/or modify it under the terms of the GNU   */\r
12 /*  General Public License as published by the       */\r
13 /*  Free Software Foundation; version 2 or later of  */\r
14 /*  the License.                                     */\r
15 /*                                                   */\r
16 /*  PJIRC is distributed in the hope that it will    */\r
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */\r
18 /*  even the implied warranty of MERCHANTABILITY or  */\r
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */\r
20 /*  General Public License for more details.         */\r
21 /*                                                   */\r
22 /*  You should have received a copy of the GNU       */\r
23 /*  General Public License along with PJIRC; if      */\r
24 /*  not, write to the Free Software Foundation,      */\r
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */\r
26 /*  MA  02111-1307  USA                              */\r
27 /*                                                   */\r
28 /*****************************************************/\r
29 \r
30 package irc;\r
31 \r
32 import java.util.Vector;\r
33 \r
34 /**\r
35  * A channel list handler.\r
36  */\r
37 public class ChanList extends IRCSource {\r
38         private ListenerGroup _listeners;\r
39         private Vector _channels;\r
40         private String _name;\r
41         private boolean _running;\r
42         private int _ignored;\r
43 \r
44         /**\r
45          * Create a new ChanList.\r
46          * \r
47          * @param config\r
48          *          the global configuration.\r
49          * @param server\r
50          *          the IRCServer from where to retreive channel list.\r
51          * @param name\r
52          *          the chanlist name.\r
53          */\r
54         public ChanList(IRCConfiguration config, IRCServer server, String name) {\r
55                 super(config, server);\r
56                 _name = name;\r
57                 _server = server;\r
58                 _listeners = new ListenerGroup();\r
59                 _channels = new Vector();\r
60                 _running = false;\r
61         }\r
62 \r
63         @Override\r
64         public String getType() {\r
65                 return "ChanList";\r
66         }\r
67 \r
68         /**\r
69          * Get the chanlist name.\r
70          * \r
71          * @return the chanlist name.\r
72          */\r
73         @Override\r
74         public String getName() {\r
75                 return _name;\r
76         }\r
77 \r
78         /**\r
79          * Get the channels.\r
80          * \r
81          * @return array of all channels.\r
82          */\r
83         public ChannelInfo[] getChannels() {\r
84                 ChannelInfo[] ans = new ChannelInfo[_channels.size()];\r
85                 for (int i = 0; i < _channels.size(); i++)\r
86                         ans[i] = (ChannelInfo) _channels.elementAt(i);\r
87                 return ans;\r
88         }\r
89 \r
90         /**\r
91          * Get the channel count.\r
92          * \r
93          * @return the number of channels.\r
94          */\r
95         public int getChannelCount() {\r
96                 return _channels.size();\r
97         }\r
98 \r
99         /**\r
100          * Get the ignored channel count.\r
101          * \r
102          * @return the number of channels that have been ignored.\r
103          */\r
104         public int getIgnoredChannelCount() {\r
105                 return _ignored;\r
106         }\r
107 \r
108         /**\r
109          * Add a channel in the channel list.\r
110          * \r
111          * @param nfo\r
112          *          new channel to add.\r
113          */\r
114         public void addChannel(ChannelInfo nfo) {\r
115                 if (_channels.size() > 1024 && nfo.userCount < 5) {\r
116                         _ignored++;\r
117                         return;\r
118                 }\r
119                 _channels.insertElementAt(nfo, _channels.size());\r
120                 _listeners.sendEvent("channelAdded", nfo, this);\r
121         }\r
122 \r
123         /**\r
124          * Begin a new channel listing. The channel list is cleared.\r
125          */\r
126         public void begin() {\r
127                 _ignored = 0;\r
128                 _running = true;\r
129                 _channels = new Vector();\r
130                 _listeners.sendEvent("channelBegin", this);\r
131         }\r
132 \r
133         /**\r
134          * End the channel listing.\r
135          */\r
136         public void end() {\r
137                 _running = false;\r
138                 _listeners.sendEvent("channelEnd", this);\r
139         }\r
140 \r
141         /**\r
142          * Add a ChanListListener.\r
143          * \r
144          * @param lis\r
145          *          listener to add.\r
146          */\r
147         public void addChanListListener(ChanListListener lis) {\r
148                 _listeners.addListener(lis);\r
149         }\r
150 \r
151         /**\r
152          * Remove a chanListListener.\r
153          * \r
154          * @param lis\r
155          *          listener to remove.\r
156          */\r
157         public void removeChanListListeners(ChanListListener lis) {\r
158                 _listeners.removeListener(lis);\r
159         }\r
160 \r
161         /**\r
162          * Request the destruction of this chanlist.\r
163          */\r
164         @Override\r
165         public void leave() {\r
166                 if (_running)\r
167                         return;\r
168                 getIRCServer().leaveChanList(_name);\r
169         }\r
170 \r
171         @Override\r
172         public boolean talkable() {\r
173                 return false;\r
174         }\r
175 \r
176         @Override\r
177         public boolean mayDefault() {\r
178                 return false;\r
179         }\r
180 \r
181 }\r