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