Bladeren bron

Remove plugin (un)loaded events.

Depends-On: I84f07c00e0589ff25ae1b4a01f5671488b847925
Change-Id: I413a3f6f72999262bf4426de082cc8c9946a6f90
Reviewed-on: http://gerrit.dmdirc.com/3449
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/49/3449/3
Greg Holmes 10 jaren geleden
bovenliggende
commit
45b649a9d8

+ 22
- 18
src/com/dmdirc/addons/notifications/NotificationsManager.java Bestand weergeven

@@ -24,22 +24,23 @@ package com.dmdirc.addons.notifications;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.ClientModule.UserConfig;
27
-import com.dmdirc.actions.ActionManager;
28
-import com.dmdirc.actions.CoreActionType;
29
-import com.dmdirc.interfaces.ActionListener;
30
-import com.dmdirc.interfaces.actions.ActionType;
27
+import com.dmdirc.events.PluginLoadedEvent;
28
+import com.dmdirc.events.PluginUnloadedEvent;
31 29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32 30
 import com.dmdirc.interfaces.config.ConfigProvider;
33 31
 import com.dmdirc.plugins.PluginDomain;
34 32
 import com.dmdirc.plugins.PluginInfo;
35 33
 import com.dmdirc.plugins.PluginManager;
36 34
 
35
+import com.google.common.eventbus.EventBus;
36
+import com.google.common.eventbus.Subscribe;
37
+
37 38
 import java.util.ArrayList;
38 39
 import java.util.List;
39 40
 
40 41
 import javax.inject.Inject;
41 42
 
42
-public class NotificationsManager implements ActionListener {
43
+public class NotificationsManager {
43 44
 
44 45
     /** The notification methods that we know of. */
45 46
     private final List<String> methods = new ArrayList<>();
@@ -51,23 +52,26 @@ public class NotificationsManager implements ActionListener {
51 52
     private final AggregateConfigProvider globalConfig;
52 53
     /** Plugin manager. */
53 54
     private final PluginManager pluginManager;
55
+    /** Event bus to listen for events on. */
56
+    private final EventBus eventBus;
54 57
 
55 58
     @Inject
56 59
     public NotificationsManager(
57 60
             @PluginDomain(NotificationsPlugin.class) final String domain,
58 61
             @GlobalConfig final AggregateConfigProvider globalConfig,
59 62
             @UserConfig final ConfigProvider userSettings,
63
+            final EventBus eventBus,
60 64
             final PluginManager pluginManager) {
61 65
         this.domain = domain;
62 66
         this.globalConfig = globalConfig;
63 67
         this.pluginManager = pluginManager;
68
+        this.eventBus = eventBus;
64 69
     }
65 70
 
66 71
     public void onLoad() {
67 72
         methods.clear();
68 73
         loadSettings();
69
-        ActionManager.getActionManager().registerListener(this,
70
-                CoreActionType.PLUGIN_LOADED, CoreActionType.PLUGIN_UNLOADED);
74
+        eventBus.register(this);
71 75
         for (PluginInfo target : pluginManager.getPluginInfos()) {
72 76
             if (target.isLoaded()) {
73 77
                 addPlugin(target);
@@ -77,7 +81,17 @@ public class NotificationsManager implements ActionListener {
77 81
 
78 82
     public void onUnload() {
79 83
         methods.clear();
80
-        ActionManager.getActionManager().unregisterListener(this);
84
+        eventBus.unregister(this);
85
+    }
86
+
87
+    @Subscribe
88
+    public void handlePluginLoaded(final PluginLoadedEvent event) {
89
+        addPlugin(event.getPlugin());
90
+    }
91
+
92
+    @Subscribe
93
+    public void handlePluginUnloaded(final PluginUnloadedEvent event) {
94
+        removePlugin(event.getPlugin());
81 95
     }
82 96
 
83 97
     /** Loads the plugins settings. */
@@ -89,16 +103,6 @@ public class NotificationsManager implements ActionListener {
89 103
         }
90 104
     }
91 105
 
92
-    @Override
93
-    public void processEvent(final ActionType type, final StringBuffer format,
94
-            final Object... arguments) {
95
-        if (type == CoreActionType.PLUGIN_LOADED) {
96
-            addPlugin((PluginInfo) arguments[0]);
97
-        } else if (type == CoreActionType.PLUGIN_UNLOADED) {
98
-            removePlugin((PluginInfo) arguments[0]);
99
-        }
100
-    }
101
-
102 106
     /**
103 107
      * Checks to see if a plugin implements the notification method interface and if it does, adds
104 108
      * the method to our list.

+ 22
- 17
src/com/dmdirc/addons/nowplaying/NowPlayingManager.java Bestand weergeven

@@ -24,10 +24,9 @@ package com.dmdirc.addons.nowplaying;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.ClientModule.UserConfig;
27
-import com.dmdirc.actions.CoreActionType;
27
+import com.dmdirc.events.PluginLoadedEvent;
28
+import com.dmdirc.events.PluginUnloadedEvent;
28 29
 import com.dmdirc.interfaces.ActionController;
29
-import com.dmdirc.interfaces.ActionListener;
30
-import com.dmdirc.interfaces.actions.ActionType;
31 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32 31
 import com.dmdirc.interfaces.config.ConfigProvider;
33 32
 import com.dmdirc.plugins.Plugin;
@@ -35,13 +34,16 @@ import com.dmdirc.plugins.PluginDomain;
35 34
 import com.dmdirc.plugins.PluginInfo;
36 35
 import com.dmdirc.plugins.PluginManager;
37 36
 
37
+import com.google.common.eventbus.EventBus;
38
+import com.google.common.eventbus.Subscribe;
39
+
38 40
 import java.util.ArrayList;
39 41
 import java.util.Collections;
40 42
 import java.util.List;
41 43
 
42 44
 import javax.inject.Inject;
43 45
 
44
-public class NowPlayingManager implements ActionListener {
46
+public class NowPlayingManager {
45 47
 
46 48
     /** Plugin manager to get plugins from. */
47 49
     private final PluginManager pluginManager;
@@ -49,6 +51,8 @@ public class NowPlayingManager implements ActionListener {
49 51
     private final ActionController actionController;
50 52
     /** Global configuration to read settings from. */
51 53
     private final AggregateConfigProvider globalConfig;
54
+    /** Event bus to subscribe to events on. */
55
+    private final EventBus eventBus;
52 56
     /** This plugin's settings domain. */
53 57
     private final String domain;
54 58
     /** The sources that we know of. */
@@ -62,6 +66,7 @@ public class NowPlayingManager implements ActionListener {
62 66
     public NowPlayingManager(
63 67
             final PluginManager pluginManager,
64 68
             final ActionController actionController,
69
+            final EventBus eventBus,
65 70
             @GlobalConfig final AggregateConfigProvider globalConfig,
66 71
             @UserConfig final ConfigProvider userConfig,
67 72
             @PluginDomain(NowPlayingPlugin.class) final String domain) {
@@ -69,6 +74,7 @@ public class NowPlayingManager implements ActionListener {
69 74
         this.actionController = actionController;
70 75
         this.globalConfig = globalConfig;
71 76
         this.domain = domain;
77
+        this.eventBus = eventBus;
72 78
     }
73 79
 
74 80
     /**
@@ -78,8 +84,7 @@ public class NowPlayingManager implements ActionListener {
78 84
         sources.clear();
79 85
         managers.clear();
80 86
         order = getSettings();
81
-        actionController.registerListener(this, CoreActionType.PLUGIN_LOADED,
82
-                CoreActionType.PLUGIN_UNLOADED);
87
+        eventBus.register(this);
83 88
         for (PluginInfo target : pluginManager.getPluginInfos()) {
84 89
             if (target.isLoaded()) {
85 90
                 addPlugin(target);
@@ -93,7 +98,17 @@ public class NowPlayingManager implements ActionListener {
93 98
     public void onUnload() {
94 99
         sources.clear();
95 100
         managers.clear();
96
-        actionController.unregisterListener(this);
101
+        eventBus.unregister(this);
102
+    }
103
+
104
+    @Subscribe
105
+    public void handlePluginLoaded(final PluginLoadedEvent event) {
106
+        addPlugin(event.getPlugin());
107
+    }
108
+
109
+    @Subscribe
110
+    public void handlePluginUnloaded(final PluginUnloadedEvent event) {
111
+        removePlugin(event.getPlugin());
97 112
     }
98 113
 
99 114
     /**
@@ -282,14 +297,4 @@ public class NowPlayingManager implements ActionListener {
282 297
         return res;
283 298
     }
284 299
 
285
-    @Override
286
-    public void processEvent(final ActionType type, final StringBuffer format,
287
-            final Object... arguments) {
288
-        if (type == CoreActionType.PLUGIN_LOADED) {
289
-            addPlugin((PluginInfo) arguments[0]);
290
-        } else if (type == CoreActionType.PLUGIN_UNLOADED) {
291
-            removePlugin((PluginInfo) arguments[0]);
292
-        }
293
-    }
294
-
295 300
 }

Laden…
Annuleren
Opslaan