Browse Source

Merge pull request #361 from greboid/dev4

Some more work on the channel who plugin.
pull/363/head
Chris Smith 9 years ago
parent
commit
0559ef744b

+ 13
- 4
channelwho/src/com/dmdirc/addons/channelwho/ChannelWhoManager.java View File

@@ -27,7 +27,9 @@ import com.dmdirc.events.ServerConnectingEvent;
27 27
 import com.dmdirc.events.ServerDisconnectedEvent;
28 28
 import com.dmdirc.interfaces.Connection;
29 29
 import com.dmdirc.interfaces.ConnectionManager;
30
-import com.dmdirc.plugins.PluginDomain;
30
+
31
+import java.util.HashMap;
32
+import java.util.Map;
31 33
 
32 34
 import javax.inject.Inject;
33 35
 
@@ -38,16 +40,20 @@ import net.engio.mbassy.listener.Handler;
38 40
  */
39 41
 public class ChannelWhoManager {
40 42
 
43
+    private final ConnectionHandlerFactory connectionHandlerFactory;
41 44
     private final ConnectionManager connectionManager;
42 45
     private final DMDircMBassador eventBus;
46
+    private final Map<Connection, ConnectionHandler> connectionHandlers;
43 47
 
44 48
     @Inject
45 49
     public ChannelWhoManager(
46
-            @PluginDomain(ChannelWhoPlugin.class) final String domain,
50
+            final ConnectionHandlerFactory connectionHandlerFactory,
47 51
             final ConnectionManager connectionManager,
48 52
             final DMDircMBassador eventBus) {
53
+        this.connectionHandlerFactory = connectionHandlerFactory;
49 54
         this.connectionManager = connectionManager;
50 55
         this.eventBus = eventBus;
56
+        connectionHandlers = new HashMap<>();
51 57
     }
52 58
 
53 59
     public void load() {
@@ -61,11 +67,14 @@ public class ChannelWhoManager {
61 67
     }
62 68
 
63 69
     private void addConnectionHandler(final Connection connection) {
64
-        // TODO: Create a handler class which will monitor settings + handle timers.
70
+        connectionHandlers.computeIfAbsent(connection, connectionHandlerFactory::get);
65 71
     }
66 72
 
67 73
     private void removeConnectionHandler(final Connection connection) {
68
-        // TODO: Remove handlers
74
+        final ConnectionHandler connectionHandler = connectionHandlers.remove(connection);
75
+        if (connectionHandler != null) {
76
+            connectionHandler.unload();
77
+        }
69 78
     }
70 79
 
71 80
     @Handler

+ 49
- 0
channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandler.java View File

@@ -0,0 +1,49 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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.channelwho;
24
+
25
+import com.dmdirc.interfaces.Connection;
26
+import com.dmdirc.interfaces.GroupChat;
27
+
28
+/**
29
+ * Responsible for managing timers and settings required to who any {@link GroupChat}s on a
30
+ * {@link Connection} as specified by the user.
31
+ */
32
+public class ConnectionHandler {
33
+
34
+    private final Connection connection;
35
+    private final String domain;
36
+
37
+    public ConnectionHandler(final Connection connection, final String domain) {
38
+        this.connection = connection;
39
+        this.domain = domain;
40
+    }
41
+
42
+    public void load() {
43
+        connection.getWindowModel().getEventBus().subscribe(this);
44
+    }
45
+
46
+    public void unload() {
47
+        connection.getWindowModel().getEventBus().unsubscribe(this);
48
+    }
49
+}

+ 47
- 0
channelwho/src/com/dmdirc/addons/channelwho/ConnectionHandlerFactory.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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.channelwho;
24
+
25
+import com.dmdirc.interfaces.Connection;
26
+import com.dmdirc.plugins.PluginDomain;
27
+
28
+import javax.inject.Inject;
29
+
30
+/**
31
+ * Factory for creating {@link ConnectionHandler}s.
32
+ */
33
+public class ConnectionHandlerFactory {
34
+
35
+    private final String domain;
36
+
37
+    @Inject
38
+    public ConnectionHandlerFactory(@PluginDomain(ChannelWhoPlugin.class) final String domain) {
39
+        this.domain = domain;
40
+    }
41
+
42
+    public ConnectionHandler get(final Connection connection) {
43
+        final ConnectionHandler handler = new ConnectionHandler(connection, domain);
44
+        handler.load();
45
+        return handler;
46
+    }
47
+}

+ 2
- 1
channelwho/test/com/dmdirc/addons/channelwho/ChannelWhoManagerTest.java View File

@@ -34,6 +34,7 @@ import org.mockito.runners.MockitoJUnitRunner;
34 34
 @RunWith(MockitoJUnitRunner.class)
35 35
 public class ChannelWhoManagerTest {
36 36
 
37
+    @Mock private ConnectionHandlerFactory connectionHandlerFactory;
37 38
     @Mock private ConnectionManager connectionManager;
38 39
     @Mock private DMDircMBassador eventBus;
39 40
 
@@ -41,7 +42,7 @@ public class ChannelWhoManagerTest {
41 42
 
42 43
     @Before
43 44
     public void setUp() throws Exception {
44
-        instance = new ChannelWhoManager("test", connectionManager, eventBus);
45
+        instance = new ChannelWhoManager(connectionHandlerFactory, connectionManager, eventBus);
45 46
     }
46 47
 
47 48
     @Test

Loading…
Cancel
Save