Explorar el Código

Contactlist plugin

Fixes CLIENT-254

Change-Id: Idb5a3172b615b2b00fd2dfe1b089183303a8bd18
Reviewed-on: http://gerrit.dmdirc.com/1984
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith hace 13 años
padre
commit
7d1d256d19

+ 84
- 0
src/com/dmdirc/addons/contactlist/ContactListCommand.java Ver fichero

@@ -0,0 +1,84 @@
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.FrameContainer;
26
+import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
28
+import com.dmdirc.commandparser.CommandType;
29
+import com.dmdirc.commandparser.commands.Command;
30
+import com.dmdirc.commandparser.commands.IntelligentCommand;
31
+import com.dmdirc.commandparser.commands.IntelligentCommand.IntelligentCommandContext;
32
+import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
33
+import com.dmdirc.commandparser.commands.context.CommandContext;
34
+import com.dmdirc.ui.input.AdditionalTabTargets;
35
+
36
+/**
37
+ * Generates a contact list for the channel the command is used in.
38
+ */
39
+public class ContactListCommand extends Command implements CommandInfo,
40
+        IntelligentCommand {
41
+
42
+    /** {@inheritDoc} */
43
+    @Override
44
+    public void execute(final FrameContainer origin,
45
+            final CommandArguments args, final CommandContext context) {
46
+        final ChannelCommandContext chanContext = (ChannelCommandContext) context;
47
+
48
+        final ContactListListener listener = new ContactListListener(chanContext.getChannel());
49
+        listener.addListeners();
50
+        listener.clientListUpdated(chanContext.getChannel().getChannelInfo().getChannelClients());
51
+    }
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public String getName() {
56
+        return "contactlist";
57
+    }
58
+
59
+    /** {@inheritDoc} */
60
+    @Override
61
+    public boolean showInHelp() {
62
+        return true;
63
+    }
64
+
65
+    /** {@inheritDoc} */
66
+    @Override
67
+    public CommandType getType() {
68
+        return CommandType.TYPE_CHANNEL;
69
+    }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public String getHelp() {
74
+        return "contactlist - Show a contact list for the current channel";
75
+    }
76
+
77
+    /** {@inheritDoc} */
78
+    @Override
79
+    public AdditionalTabTargets getSuggestions(final int arg,
80
+            final IntelligentCommandContext context) {
81
+        return new AdditionalTabTargets().excludeAll();
82
+    }
83
+
84
+}

+ 115
- 0
src/com/dmdirc/addons/contactlist/ContactListListener.java Ver fichero

@@ -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
+}

+ 48
- 0
src/com/dmdirc/addons/contactlist/ContactListPlugin.java Ver fichero

@@ -0,0 +1,48 @@
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.commandparser.CommandManager;
26
+import com.dmdirc.plugins.BasePlugin;
27
+
28
+/**
29
+ * Plugin to provide a POC contact list.
30
+ */
31
+public final class ContactListPlugin extends BasePlugin {
32
+
33
+    /** The command we've registered. */
34
+    private ContactListCommand command;
35
+
36
+    /** {@inheritDoc} */
37
+    @Override
38
+    public void onLoad() {
39
+        command = new ContactListCommand();
40
+        CommandManager.registerCommand(command);
41
+    }
42
+
43
+    /** {@inheritDoc} */
44
+    @Override
45
+    public void onUnload() {
46
+        CommandManager.unregisterCommand(command);
47
+    }
48
+}

+ 26
- 0
src/com/dmdirc/addons/contactlist/package-info.java Ver fichero

@@ -0,0 +1,26 @@
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
+/**
24
+ * Provides a proof of concept contact list.
25
+ */
26
+package com.dmdirc.addons.contactlist;

+ 31
- 0
src/com/dmdirc/addons/contactlist/plugin.config Ver fichero

@@ -0,0 +1,31 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+  version
10
+  requires
11
+  icons
12
+
13
+metadata:
14
+  author=Chris <chris@dmdirc.com>
15
+  mainclass=com.dmdirc.addons.contactlist.ContactListPlugin
16
+  description=Proof of concept contact list support
17
+  name=contactlist
18
+  nicename=Contact List
19
+
20
+updates:
21
+  id=67
22
+
23
+version:
24
+  friendly=0.1
25
+
26
+provides:
27
+  contactlist command
28
+
29
+icons:
30
+  query-away=plugin://contactlist:com/dmdirc/addons/contactlist/res/offline.png
31
+  query-here=plugin://contactlist:com/dmdirc/addons/contactlist/res/online.png

BIN
src/com/dmdirc/addons/contactlist/res/offline.png Ver fichero


BIN
src/com/dmdirc/addons/contactlist/res/online.png Ver fichero


Loading…
Cancelar
Guardar