Bläddra i källkod

Add away colours plugin.

pull/122/head
Greg Holmes 9 år sedan
förälder
incheckning
9a98255c81

+ 22
- 0
awaycolours/plugin.config Visa fil

@@ -0,0 +1,22 @@
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
+
11
+metadata:
12
+  author=Greboid <greg@dmdirc.com>
13
+  mainclass=com.dmdirc.addons.awaycolours.AwayColours
14
+  description=Provides away colours to theclient
15
+  name=awaycolours
16
+  nicename=Away Colours Plugin
17
+
18
+updates:
19
+  id=75
20
+
21
+version:
22
+  friendly=0.1

+ 104
- 0
awaycolours/src/com/dmdirc/addons/awaycolours/AwayColoursManager.java Visa fil

@@ -0,0 +1,104 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.awaycolours;
24
+
25
+import com.dmdirc.ChannelClientProperty;
26
+import com.dmdirc.ClientModule.GlobalConfig;
27
+import com.dmdirc.DMDircMBassador;
28
+import com.dmdirc.config.ConfigBinder;
29
+import com.dmdirc.config.ConfigBinding;
30
+import com.dmdirc.events.ChannelUserAwayEvent;
31
+import com.dmdirc.events.ChannelUserBackEvent;
32
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
33
+import com.dmdirc.plugins.PluginDomain;
34
+import com.dmdirc.util.colours.Colour;
35
+
36
+import javax.inject.Inject;
37
+
38
+import net.engio.mbassy.listener.Handler;
39
+
40
+/**
41
+ * Adds away colours to DMDirc.
42
+ */
43
+public class AwayColoursManager {
44
+
45
+    private final DMDircMBassador eventBus;
46
+    private final ConfigBinder binder;
47
+    private Colour colour;
48
+    private boolean nicklist = true;
49
+    private boolean text = true;
50
+
51
+    @Inject
52
+    public AwayColoursManager(final DMDircMBassador eventBus,
53
+            @GlobalConfig final AggregateConfigProvider config,
54
+            @PluginDomain(AwayColoursPlugin.class) final String domain) {
55
+        this.eventBus = eventBus;
56
+        binder = new ConfigBinder(config, domain);
57
+
58
+    }
59
+
60
+    public void load() {
61
+        eventBus.subscribe(this);
62
+        binder.bind(this, AwayColoursManager.class);
63
+    }
64
+
65
+    public void unload() {
66
+        eventBus.unsubscribe(this);
67
+        binder.unbind(this);
68
+    }
69
+
70
+    @ConfigBinding(key = "colour")
71
+    public void handleColourChange(final Colour colour) {
72
+        this.colour = colour;
73
+    }
74
+
75
+    @ConfigBinding(key = "nicklist")
76
+    public void handleNicklistChange(final boolean nicklist) {
77
+        this.nicklist = nicklist;
78
+    }
79
+
80
+    @ConfigBinding(key = "text")
81
+    public void handleTextChange(final boolean text) {
82
+        this.text = text;
83
+    }
84
+
85
+    @Handler
86
+    public void handleAwayEvent(final ChannelUserAwayEvent event) {
87
+        if (nicklist) {
88
+            event.getUser().getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, colour);
89
+        }
90
+        if (text) {
91
+            event.getUser().getMap().put(ChannelClientProperty.TEXT_FOREGROUND, colour);
92
+        }
93
+    }
94
+
95
+    @Handler
96
+    public void handleBackEvent(final ChannelUserBackEvent event) {
97
+        if (nicklist) {
98
+            event.getUser().getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
99
+        }
100
+        if (text) {
101
+            event.getUser().getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
102
+        }
103
+    }
104
+}

+ 34
- 0
awaycolours/src/com/dmdirc/addons/awaycolours/AwayColoursModule.java Visa fil

@@ -0,0 +1,34 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.awaycolours;
24
+
25
+import com.dmdirc.ClientModule;
26
+
27
+import dagger.Module;
28
+
29
+/**
30
+ * Dagger injection module for the Away Colours plugin.
31
+ */
32
+@Module(injects = AwayColoursManager.class, addsTo = ClientModule.class)
33
+public class AwayColoursModule {
34
+}

+ 54
- 0
awaycolours/src/com/dmdirc/addons/awaycolours/AwayColoursPlugin.java Visa fil

@@ -0,0 +1,54 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.awaycolours;
24
+
25
+import com.dmdirc.plugins.PluginInfo;
26
+import com.dmdirc.plugins.implementations.BaseCommandPlugin;
27
+
28
+import dagger.ObjectGraph;
29
+
30
+/**
31
+ * Away Colours Plugin.
32
+ */
33
+public final class AwayColoursPlugin extends BaseCommandPlugin {
34
+
35
+    private AwayColoursManager manager;
36
+
37
+    @Override
38
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
39
+        super.load(pluginInfo, graph);
40
+
41
+        setObjectGraph(graph.plus(new AwayColoursModule()));
42
+        manager = getObjectGraph().get(AwayColoursManager.class);
43
+    }
44
+
45
+    @Override
46
+    public void onLoad() {
47
+        manager.load();
48
+    }
49
+
50
+    @Override
51
+    public void onUnload() {
52
+        manager.unload();
53
+    }
54
+}

+ 146
- 0
awaycolours/test/com/dmdirc/addons/awaycolours/AwayColoursManagerTest.java Visa fil

@@ -0,0 +1,146 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.awaycolours;
24
+
25
+import com.dmdirc.ChannelClientProperty;
26
+import com.dmdirc.DMDircMBassador;
27
+import com.dmdirc.config.ConfigBinder;
28
+import com.dmdirc.events.ChannelUserAwayEvent;
29
+import com.dmdirc.events.ChannelUserBackEvent;
30
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
32
+import com.dmdirc.util.colours.Colour;
33
+
34
+import java.util.Map;
35
+
36
+import org.junit.Before;
37
+import org.junit.Test;
38
+import org.junit.runner.RunWith;
39
+import org.mockito.Mock;
40
+import org.mockito.runners.MockitoJUnitRunner;
41
+
42
+import static org.mockito.Mockito.never;
43
+import static org.mockito.Mockito.verify;
44
+import static org.mockito.Mockito.when;
45
+
46
+@RunWith(MockitoJUnitRunner.class)
47
+public class AwayColoursManagerTest {
48
+
49
+    @Mock private DMDircMBassador eventBus;
50
+    @Mock private AggregateConfigProvider config;
51
+    @Mock private ConfigBinder binder;
52
+    @Mock private ChannelUserAwayEvent awayEvent;
53
+    @Mock private ChannelUserBackEvent backEvent;
54
+    @Mock private ChannelClientInfo user;
55
+    @Mock private Map<Object, Object> map;
56
+    private AwayColoursManager instance;
57
+    private Colour colour;
58
+
59
+    @Before
60
+    public void setUp() throws Exception {
61
+        colour = Colour.RED;
62
+        instance = new AwayColoursManager(eventBus, config, "test");
63
+        when(awayEvent.getUser()).thenReturn(user);
64
+        when(backEvent.getUser()).thenReturn(user);
65
+        when(user.getMap()).thenReturn(map);
66
+    }
67
+
68
+    @Test
69
+    public void testLoad() throws Exception {
70
+        instance.load();
71
+        verify(eventBus).subscribe(instance);
72
+    }
73
+
74
+    @Test
75
+    public void testUnload() throws Exception {
76
+        instance.unload();
77
+        verify(eventBus).unsubscribe(instance);
78
+    }
79
+
80
+    @Test
81
+    public void testHandleColourChange() throws Exception {
82
+        instance.handleColourChange(colour);
83
+        instance.handleNicklistChange(true);
84
+        instance.handleTextChange(true);
85
+        instance.handleAwayEvent(awayEvent);
86
+        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, colour);
87
+        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, colour);
88
+        instance.handleColourChange(Colour.BLACK);
89
+        instance.handleNicklistChange(true);
90
+        instance.handleTextChange(true);
91
+        instance.handleAwayEvent(awayEvent);
92
+        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, Colour.BLACK);
93
+        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, Colour.BLACK);
94
+    }
95
+
96
+    @Test
97
+    public void testHandleNicklistChange() throws Exception {
98
+        instance.handleColourChange(colour);
99
+        instance.handleNicklistChange(true);
100
+        instance.handleTextChange(true);
101
+        instance.handleAwayEvent(awayEvent);
102
+        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, colour);
103
+        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, colour);
104
+        instance.handleColourChange(Colour.BLACK);
105
+        instance.handleNicklistChange(false);
106
+        instance.handleTextChange(true);
107
+        instance.handleAwayEvent(awayEvent);
108
+        verify(map, never()).put(ChannelClientProperty.NICKLIST_FOREGROUND, Colour.BLACK);
109
+        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, Colour.BLACK);
110
+    }
111
+
112
+    @Test
113
+    public void testHandleTextChange() throws Exception {
114
+        instance.handleColourChange(colour);
115
+        instance.handleNicklistChange(true);
116
+        instance.handleTextChange(true);
117
+        instance.handleAwayEvent(awayEvent);
118
+        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, colour);
119
+        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, colour);
120
+        instance.handleColourChange(Colour.BLACK);
121
+        instance.handleNicklistChange(true);
122
+        instance.handleTextChange(false);
123
+        instance.handleAwayEvent(awayEvent);
124
+        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, Colour.BLACK);
125
+        verify(map, never()).put(ChannelClientProperty.TEXT_FOREGROUND, Colour.BLACK);
126
+    }
127
+
128
+    @Test
129
+    public void testHandleAwayEvent() throws Exception {
130
+        instance.handleNicklistChange(true);
131
+        instance.handleTextChange(true);
132
+        instance.handleBackEvent(backEvent);
133
+        verify(map).remove(ChannelClientProperty.NICKLIST_FOREGROUND);
134
+        verify(map).remove(ChannelClientProperty.TEXT_FOREGROUND);
135
+    }
136
+
137
+    @Test
138
+    public void testHandleBackEvent() throws Exception {
139
+        instance.handleColourChange(colour);
140
+        instance.handleNicklistChange(true);
141
+        instance.handleTextChange(true);
142
+        instance.handleAwayEvent(awayEvent);
143
+        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, colour);
144
+        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, colour);
145
+    }
146
+}

Laddar…
Avbryt
Spara