ソースを参照

Tidy up some plugins

Change-Id: I613acb4e089072dfea68f682aa2c81366c66e1c6
Reviewed-on: http://gerrit.dmdirc.com/2730
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8
Chris Smith 10年前
コミット
23276790c4

+ 20
- 10
src/com/dmdirc/addons/urlcatcher/UrlCatcherPlugin.java ファイルの表示

@@ -24,13 +24,13 @@ package com.dmdirc.addons.urlcatcher;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Raw;
27
-import com.dmdirc.actions.ActionManager;
28 27
 import com.dmdirc.actions.CoreActionType;
29 28
 import com.dmdirc.interfaces.actions.ActionType;
30
-import com.dmdirc.config.IdentityManager;
29
+import com.dmdirc.interfaces.ActionController;
31 30
 import com.dmdirc.interfaces.ActionListener;
32 31
 import com.dmdirc.interfaces.CommandController;
33 32
 import com.dmdirc.interfaces.ConfigChangeListener;
33
+import com.dmdirc.interfaces.IdentityController;
34 34
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
35 35
 import com.dmdirc.ui.messages.Styliser;
36 36
 
@@ -45,7 +45,11 @@ public class UrlCatcherPlugin extends BaseCommandPlugin implements
45 45
         ActionListener, ConfigChangeListener {
46 46
 
47 47
     /* URLs and the number of times they were mentioned. */
48
-    private final Map<String, Integer> urls = new HashMap<String, Integer>();
48
+    private final Map<String, Integer> urls = new HashMap<>();
49
+    /** Controller to read settings from. */
50
+    private final IdentityController identityController;
51
+    /** Controller to listen to action events from. */
52
+    private final ActionController actionController;
49 53
     /** Whether to capture URLs from the raw window. */
50 54
     private boolean captureRaw = false;
51 55
 
@@ -53,18 +57,24 @@ public class UrlCatcherPlugin extends BaseCommandPlugin implements
53 57
      * Creates a new instance of this plugin.
54 58
      *
55 59
      * @param commandController Command controller to register commands
60
+     * @param identityController Controller to load settings from.
61
+     * @param actionController Controller to listen to action events from.
56 62
      */
57
-    public UrlCatcherPlugin(final CommandController commandController) {
63
+    public UrlCatcherPlugin(
64
+            final CommandController commandController,
65
+            final IdentityController identityController,
66
+            final ActionController actionController) {
58 67
         super(commandController);
68
+        this.identityController = identityController;
69
+        this.actionController = actionController;
59 70
         registerCommand(new UrlListCommand(this), UrlListCommand.INFO);
60 71
     }
61 72
 
62 73
     /** {@inheritDoc} */
63 74
     @Override
64 75
     public void onLoad() {
65
-        ActionManager.getActionManager().registerListener(this,
66
-                CoreActionType.CLIENT_LINE_ADDED);
67
-        IdentityManager.getIdentityManager().getGlobalConfiguration().addChangeListener(getDomain(), this);
76
+        actionController.registerListener(this, CoreActionType.CLIENT_LINE_ADDED);
77
+        identityController.getGlobalConfiguration().addChangeListener(getDomain(), this);
68 78
         updateConfig();
69 79
         super.onLoad();
70 80
     }
@@ -72,8 +82,8 @@ public class UrlCatcherPlugin extends BaseCommandPlugin implements
72 82
     /** {@inheritDoc} */
73 83
     @Override
74 84
     public void onUnload() {
75
-        ActionManager.getActionManager().unregisterListener(this);
76
-        IdentityManager.getIdentityManager().getGlobalConfiguration().removeListener(this);
85
+        actionController.unregisterListener(this);
86
+        identityController.getGlobalConfiguration().removeListener(this);
77 87
         super.onUnload();
78 88
     }
79 89
 
@@ -81,7 +91,7 @@ public class UrlCatcherPlugin extends BaseCommandPlugin implements
81 91
      * Re-reads the configuration of the URL catcher plugin.
82 92
      */
83 93
     private void updateConfig() {
84
-        captureRaw = IdentityManager.getIdentityManager().getGlobalConfiguration().getOptionBool(getDomain(), "captureraw");
94
+        captureRaw = identityController.getGlobalConfiguration().getOptionBool(getDomain(), "captureraw");
85 95
     }
86 96
 
87 97
     /** {@inheritDoc} */

+ 17
- 11
src/com/dmdirc/addons/userlevel/UserLevelPlugin.java ファイルの表示

@@ -22,13 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.userlevel;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
26 25
 import com.dmdirc.actions.CoreActionType;
27 26
 import com.dmdirc.interfaces.actions.ActionComponent;
28 27
 import com.dmdirc.interfaces.actions.ActionType;
29
-import com.dmdirc.config.IdentityManager;
28
+import com.dmdirc.interfaces.ActionController;
30 29
 import com.dmdirc.interfaces.ActionListener;
31 30
 import com.dmdirc.interfaces.ConfigChangeListener;
31
+import com.dmdirc.interfaces.IdentityController;
32 32
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
33 33
 import com.dmdirc.parser.interfaces.ClientInfo;
34 34
 import com.dmdirc.plugins.implementations.BasePlugin;
@@ -36,38 +36,44 @@ import com.dmdirc.plugins.implementations.BasePlugin;
36 36
 import java.util.HashMap;
37 37
 import java.util.Map;
38 38
 
39
+import lombok.RequiredArgsConstructor;
40
+
39 41
 /**
40 42
  * Allows the client to assign user levels to users (based on hostname matches),
41 43
  * and for actions/plugins to check those levels.
42 44
  */
45
+@RequiredArgsConstructor
43 46
 public class UserLevelPlugin extends BasePlugin implements ActionListener,
44 47
         ConfigChangeListener {
45 48
 
46 49
     /** The domain used for userlevels. */
47 50
     private static final String DOMAIN = "userlevels";
48 51
     /** A map of hostmasks to associated level numbers. */
49
-    private static final Map<String, Integer> LEVELS = new HashMap<String, Integer>();
52
+    private static final Map<String, Integer> LEVELS = new HashMap<>();
53
+
54
+    /** The identity controller to use to read settings. */
55
+    private final IdentityController identityController;
56
+    /** The action controller to add components to. */
57
+    private final ActionController actionController;
50 58
 
51 59
     /** {@inheritDoc} */
52 60
     @Override
53 61
     public void onLoad() {
54
-        ActionManager.getActionManager().registerListener(this,
55
-                CoreActionType.CHANNEL_JOIN);
56
-        ActionManager.getActionManager().registerComponents(
62
+        actionController.registerListener(this, CoreActionType.CHANNEL_JOIN);
63
+        actionController.registerComponents(
57 64
                 new ActionComponent[]{
58 65
                     new AccessLevelComponent(),
59 66
                     new ChannelAccessLevelComponent()
60 67
                 });
61
-        IdentityManager.getIdentityManager().getGlobalConfiguration()
62
-                .addChangeListener(DOMAIN, this);
68
+        identityController.getGlobalConfiguration().addChangeListener(DOMAIN, this);
63 69
         loadLevels();
64 70
     }
65 71
 
66 72
     /** {@inheritDoc} */
67 73
     @Override
68 74
     public void onUnload() {
69
-        ActionManager.getActionManager().unregisterListener(this);
70
-        IdentityManager.getIdentityManager().getGlobalConfiguration().removeListener(this);
75
+        actionController.unregisterListener(this);
76
+        identityController.getGlobalConfiguration().removeListener(this);
71 77
     }
72 78
 
73 79
     /** {@inheritDoc} */
@@ -127,7 +133,7 @@ public class UserLevelPlugin extends BasePlugin implements ActionListener,
127 133
     private void loadLevels() {
128 134
         LEVELS.clear();
129 135
 
130
-        for (Map.Entry<String, String> item : IdentityManager.getIdentityManager()
136
+        for (Map.Entry<String, String> item : identityController
131 137
                 .getGlobalConfiguration().getOptions(DOMAIN).entrySet()) {
132 138
             try {
133 139
                 LEVELS.put(item.getKey(), Integer.parseInt(item.getValue()));

+ 20
- 15
src/com/dmdirc/addons/windowstatus/WindowStatusPlugin.java ファイルの表示

@@ -30,13 +30,13 @@ import com.dmdirc.addons.ui_swing.SelectionListener;
30 30
 import com.dmdirc.addons.ui_swing.SwingController;
31 31
 import com.dmdirc.addons.ui_swing.UIUtilities;
32 32
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
33
-import com.dmdirc.config.IdentityManager;
34 33
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
35 34
 import com.dmdirc.config.prefs.PreferencesCategory;
36 35
 import com.dmdirc.config.prefs.PreferencesDialogModel;
37 36
 import com.dmdirc.config.prefs.PreferencesSetting;
38 37
 import com.dmdirc.config.prefs.PreferencesType;
39 38
 import com.dmdirc.interfaces.ConfigChangeListener;
39
+import com.dmdirc.interfaces.IdentityController;
40 40
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
41 41
 import com.dmdirc.parser.interfaces.ChannelInfo;
42 42
 import com.dmdirc.parser.interfaces.ClientInfo;
@@ -57,7 +57,9 @@ public final class WindowStatusPlugin extends BasePlugin
57 57
     /** The panel we use in the status bar. */
58 58
     private final WindowStatusPanel panel;
59 59
     /** Parent Swing UI. */
60
-    private SwingController controller;
60
+    private final SwingController controller;
61
+    /** Identity controller to read settings from. */
62
+    private final IdentityController identityController;
61 63
     /** Should we show the real name in queries? */
62 64
     private boolean showname;
63 65
     /** Should we show users without modes? */
@@ -70,11 +72,18 @@ public final class WindowStatusPlugin extends BasePlugin
70 72
     /**
71 73
      * Creates a new instance of WindowStatusPlugin.
72 74
      *
73
-     * @param pluginInfo This plugin's plugin info
75
+     * @param pluginInfo This plugin's plugin info.
76
+     * @param controller The parent {@link SwingController}.
77
+     * @param identityController The controller to read settings from.
74 78
      */
75
-    public WindowStatusPlugin(final PluginInfo pluginInfo) {
79
+    public WindowStatusPlugin(
80
+            final PluginInfo pluginInfo,
81
+            final SwingController controller,
82
+            final IdentityController identityController) {
76 83
         super();
77 84
         this.pluginInfo = pluginInfo;
85
+        this.controller = controller;
86
+        this.identityController = identityController;
78 87
 
79 88
         panel = UIUtilities.invokeAndWait(
80 89
                 new Callable<WindowStatusPanel>() {
@@ -90,12 +99,9 @@ public final class WindowStatusPlugin extends BasePlugin
90 99
     /** {@inheritDoc} */
91 100
     @Override
92 101
     public void onLoad() {
93
-        controller = (SwingController) pluginInfo.getMetaData().getManager()
94
-                .getPluginInfoByName("ui_swing").getPlugin();
95 102
         controller.getSwingStatusBar().addComponent(panel);
96 103
         controller.getMainFrame().addSelectionListener(this);
97
-        IdentityManager.getIdentityManager().getGlobalConfiguration()
98
-                .addChangeListener(getDomain(), this);
104
+        identityController.getGlobalConfiguration().addChangeListener(getDomain(), this);
99 105
         updateCache();
100 106
     }
101 107
 
@@ -104,7 +110,6 @@ public final class WindowStatusPlugin extends BasePlugin
104 110
     public void onUnload() {
105 111
         controller.getMainFrame().removeSelectionListener(this);
106 112
         controller.getSwingStatusBar().removeComponent(panel);
107
-        controller = null;
108 113
     }
109 114
 
110 115
     /** {@inheritDoc} */
@@ -115,11 +120,11 @@ public final class WindowStatusPlugin extends BasePlugin
115 120
 
116 121
     /** Updates the cached config settings. */
117 122
     private void updateCache() {
118
-        showname = IdentityManager.getIdentityManager().getGlobalConfiguration()
123
+        showname = identityController.getGlobalConfiguration()
119 124
                 .getOptionBool(getDomain(), "client.showname");
120
-        shownone = IdentityManager.getIdentityManager().getGlobalConfiguration()
125
+        shownone = identityController.getGlobalConfiguration()
121 126
                 .getOptionBool(getDomain(), "channel.shownone");
122
-        nonePrefix = IdentityManager.getIdentityManager().getGlobalConfiguration()
127
+        nonePrefix = identityController.getGlobalConfiguration()
123 128
                 .getOption(getDomain(), "channel.noneprefix");
124 129
         updateStatus();
125 130
     }
@@ -129,7 +134,7 @@ public final class WindowStatusPlugin extends BasePlugin
129 134
         final TextFrame active = controller.getMainFrame().getActiveFrame();
130 135
 
131 136
         if (active != null) {
132
-            updateStatus(active == null ? null : active.getContainer());
137
+            updateStatus(active.getContainer());
133 138
         }
134 139
     }
135 140
 
@@ -149,8 +154,8 @@ public final class WindowStatusPlugin extends BasePlugin
149 154
             textString.append(((Server) current).getName());
150 155
         } else if (current instanceof Channel) {
151 156
             final ChannelInfo chan = ((Channel) current).getChannelInfo();
152
-            final Map<Integer, String> names = new HashMap<Integer, String>();
153
-            final Map<Integer, Integer> types = new HashMap<Integer, Integer>();
157
+            final Map<Integer, String> names = new HashMap<>();
158
+            final Map<Integer, Integer> types = new HashMap<>();
154 159
 
155 160
             textString.append(chan.getName());
156 161
             textString.append(" - Nicks: ");

+ 6
- 4
test/com/dmdirc/addons/urlcatcher/UrlCatcherPluginTest.java ファイルの表示

@@ -26,7 +26,9 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.config.ConfigManager;
28 28
 import com.dmdirc.config.InvalidIdentityFileException;
29
+import com.dmdirc.interfaces.ActionController;
29 30
 import com.dmdirc.interfaces.CommandController;
31
+import com.dmdirc.interfaces.IdentityController;
30 32
 import com.dmdirc.ui.messages.Styliser;
31 33
 
32 34
 import org.junit.Before;
@@ -43,18 +45,20 @@ public class UrlCatcherPluginTest {
43 45
     @Mock private FrameContainer container;
44 46
     @Mock private ConfigManager manager;
45 47
     @Mock private CommandController controller;
48
+    @Mock private IdentityController identityController;
49
+    @Mock private ActionController actionController;
50
+    private UrlCatcherPlugin plugin;
46 51
 
47 52
     @Before
48 53
     public void setupClass() {
49 54
         when(container.getConfigManager()).thenReturn(manager);
50 55
         final Styliser styliser = new Styliser(container);
51 56
         when(container.getStyliser()).thenReturn(styliser);
57
+        plugin = new UrlCatcherPlugin(controller, identityController, actionController);
52 58
     }
53 59
 
54 60
     @Test
55 61
     public void testURLCounting() throws InvalidIdentityFileException {
56
-        final UrlCatcherPlugin plugin = new UrlCatcherPlugin(controller);
57
-
58 62
         plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
59 63
                 container, "This is a message - http://www.google.com/ foo");
60 64
         plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
@@ -68,8 +72,6 @@ public class UrlCatcherPluginTest {
68 72
 
69 73
     @Test
70 74
     public void testURLCatching() throws InvalidIdentityFileException {
71
-        final UrlCatcherPlugin plugin = new UrlCatcherPlugin(controller);
72
-
73 75
         plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
74 76
                 container, "http://www.google.com/ www.example.com foo://bar.baz");
75 77
         plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,

読み込み中…
キャンセル
保存