|
@@ -0,0 +1,115 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
|
3
|
+ *
|
|
4
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+ * in the Software without restriction, including without limitation the rights
|
|
7
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+ * furnished to do so, subject to the following conditions:
|
|
10
|
+ *
|
|
11
|
+ * The above copyright notice and this permission notice shall be included in
|
|
12
|
+ * all copies or substantial portions of the Software.
|
|
13
|
+ *
|
|
14
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+ * SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+package com.dmdirc.addons.contactlist;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.Channel;
|
|
26
|
+import com.dmdirc.FrameContainer;
|
|
27
|
+import com.dmdirc.Query;
|
|
28
|
+import com.dmdirc.actions.ActionManager;
|
|
29
|
+import com.dmdirc.actions.CoreActionType;
|
|
30
|
+import com.dmdirc.actions.interfaces.ActionType;
|
|
31
|
+import com.dmdirc.interfaces.ActionListener;
|
|
32
|
+import com.dmdirc.interfaces.FrameCloseListener;
|
|
33
|
+import com.dmdirc.interfaces.NicklistListener;
|
|
34
|
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
|
|
35
|
+
|
|
36
|
+import java.util.Collection;
|
|
37
|
+
|
|
38
|
+/**
|
|
39
|
+ * Listens for contact list related events.
|
|
40
|
+ */
|
|
41
|
+public class ContactListListener implements NicklistListener,
|
|
42
|
+ ActionListener, FrameCloseListener {
|
|
43
|
+
|
|
44
|
+ /** The channel this listener is for. */
|
|
45
|
+ private final Channel channel;
|
|
46
|
+
|
|
47
|
+ /**
|
|
48
|
+ * Creates a new ContactListListener for the specified channel.
|
|
49
|
+ *
|
|
50
|
+ * @param channel The channel to show a contact list for
|
|
51
|
+ */
|
|
52
|
+ public ContactListListener(final Channel channel) {
|
|
53
|
+ this.channel = channel;
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ /**
|
|
57
|
+ * Adds all necessary listeners for this contact list listener to function.
|
|
58
|
+ */
|
|
59
|
+ public void addListeners() {
|
|
60
|
+ channel.addNicklistListener(this);
|
|
61
|
+ channel.addCloseListener(this);
|
|
62
|
+ ActionManager.getActionManager().registerListener(this, CoreActionType.CHANNEL_USERAWAY, CoreActionType.CHANNEL_USERBACK);
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ /**
|
|
66
|
+ * Removes the listeners added by {@link #addListeners()}.
|
|
67
|
+ */
|
|
68
|
+ public void removeListeners() {
|
|
69
|
+ channel.removeNicklistListener(this);
|
|
70
|
+ channel.removeCloseListener(this);
|
|
71
|
+ ActionManager.getActionManager().unregisterListener(this);
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ /** {@inheritDoc} */
|
|
75
|
+ @Override
|
|
76
|
+ public void clientListUpdated(final Collection<ChannelClientInfo> clients) {
|
|
77
|
+ for (ChannelClientInfo client : clients) {
|
|
78
|
+ clientAdded(client);
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ /** {@inheritDoc} */
|
|
83
|
+ @Override
|
|
84
|
+ public void clientListUpdated() {
|
|
85
|
+ // Do nothing
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ /** {@inheritDoc} */
|
|
89
|
+ @Override
|
|
90
|
+ public void clientAdded(final ChannelClientInfo client) {
|
|
91
|
+ final Query query = channel.getServer().getQuery(client.getClient().getNickname(), false);
|
|
92
|
+
|
|
93
|
+ query.setIcon("query-" + client.getClient().getAwayState().name().toLowerCase());
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ /** {@inheritDoc} */
|
|
97
|
+ @Override
|
|
98
|
+ public void clientRemoved(final ChannelClientInfo client) {
|
|
99
|
+ // Do nothing
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ /** {@inheritDoc} */
|
|
103
|
+ @Override
|
|
104
|
+ public void processEvent(final ActionType type, final StringBuffer format, final Object... arguments) {
|
|
105
|
+ if (arguments[0] == channel) {
|
|
106
|
+ clientAdded((ChannelClientInfo) arguments[1]);
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ /** {@inheritDoc} */
|
|
111
|
+ @Override
|
|
112
|
+ public void windowClosing(final FrameContainer window) {
|
|
113
|
+ removeListeners();
|
|
114
|
+ }
|
|
115
|
+}
|