Browse Source

Remove some singleton methods from some more plugins.

Change-Id: I41199c2ed1abfeb08eb75d688602d31844280319
Reviewed-on: http://gerrit.dmdirc.com/2261
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 12 years ago
parent
commit
5e86f22f83

+ 24
- 15
src/com/dmdirc/addons/freedesktop_notifications/FreeDesktopNotificationsPlugin.java View File

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.addons.freedesktop_notifications;
24 24
 
25
+import com.dmdirc.config.ConfigManager;
26
+import com.dmdirc.config.Identity;
25 27
 import com.dmdirc.config.IdentityManager;
26 28
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
27 29
 import com.dmdirc.config.prefs.PreferencesCategory;
@@ -61,15 +63,27 @@ public final class FreeDesktopNotificationsPlugin
61 63
     private boolean stripcodes;
62 64
     /** This plugin's plugin info. */
63 65
     private final PluginInfo pluginInfo;
66
+    /** Global config. */
67
+    private final ConfigManager config;
68
+    /** Addon identity. */
69
+    private final Identity identity;
70
+    /** Plugin manager instance. */
71
+    private final PluginManager pluginManager;
64 72
 
65 73
     /**
66 74
      * Creates a new instance of this plugin.
67 75
      *
68 76
      * @param pluginInfo This plugin's plugin info
77
+     * @param identityManager Identity Manager instance
69 78
      */
70
-    public FreeDesktopNotificationsPlugin(final PluginInfo pluginInfo) {
79
+    public FreeDesktopNotificationsPlugin(final PluginInfo pluginInfo,
80
+            final IdentityManager identityManager,
81
+            final PluginManager pluginManager) {
71 82
         super(pluginInfo.getMetaData());
72 83
         this.pluginInfo = pluginInfo;
84
+        this.pluginManager = pluginManager;
85
+        config = identityManager.getGlobalConfiguration();
86
+        identity = identityManager.getGlobalAddonIdentity();
73 87
         registerCommand(new FDNotifyCommand(this), FDNotifyCommand.INFO);
74 88
     }
75 89
 
@@ -144,11 +158,11 @@ public final class FreeDesktopNotificationsPlugin
144 158
      */
145 159
     @Override
146 160
     public void onLoad() {
147
-        IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
161
+        config.addChangeListener(getDomain(), this);
148 162
         setCachedSettings();
149 163
 
150 164
         // Extract required Files
151
-        final PluginInfo pi = PluginManager.getPluginManager().getPluginInfoByName("freedesktop_notifications");
165
+        final PluginInfo pi = pluginManager.getPluginInfoByName("freedesktop_notifications");
152 166
 
153 167
         // This shouldn't actually happen, but check to make sure.
154 168
         if (pi != null) {
@@ -175,14 +189,14 @@ public final class FreeDesktopNotificationsPlugin
175 189
      */
176 190
     @Override
177 191
     public synchronized void onUnload() {
178
-        IdentityManager.getGlobalConfig().removeListener(this);
192
+        config.removeListener(this);
179 193
         super.onUnload();
180 194
     }
181 195
 
182 196
     /** {@inheritDoc} */
183 197
     @Override
184 198
     public void domainUpdated() {
185
-        IdentityManager.getAddonIdentity().setOption(getDomain(),
199
+        identity.setOption(getDomain(),
186 200
                 "general.icon", getFilesDirString() + "icon.png");
187 201
     }
188 202
 
@@ -218,16 +232,11 @@ public final class FreeDesktopNotificationsPlugin
218 232
     }
219 233
 
220 234
     private void setCachedSettings() {
221
-        timeout = IdentityManager.getGlobalConfig().getOptionInt(getDomain(),
222
-                "general.timeout");
223
-        icon = IdentityManager.getGlobalConfig().getOption(getDomain(),
224
-                "general.icon");
225
-        escapehtml = IdentityManager.getGlobalConfig().getOptionBool(
226
-                getDomain(), "advanced.escapehtml");
227
-        strictescape = IdentityManager.getGlobalConfig().getOptionBool(
228
-                getDomain(), "advanced.strictescape");
229
-        stripcodes = IdentityManager.getGlobalConfig().getOptionBool(
230
-                getDomain(), "advanced.stripcodes");
235
+        timeout = config.getOptionInt(getDomain(), "general.timeout");
236
+        icon = config.getOption(getDomain(), "general.icon");
237
+        escapehtml = config.getOptionBool( getDomain(), "advanced.escapehtml");
238
+        strictescape = config.getOptionBool(getDomain(), "advanced.strictescape");
239
+        stripcodes = config.getOptionBool(getDomain(), "advanced.stripcodes");
231 240
     }
232 241
 
233 242
     /** {@inheritDoc} */

+ 1
- 2
src/com/dmdirc/addons/identd/IdentClient.java View File

@@ -25,7 +25,6 @@ package com.dmdirc.addons.identd;
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.config.ConfigManager;
28
-import com.dmdirc.config.IdentityManager;
29 28
 import com.dmdirc.logger.ErrorLevel;
30 29
 import com.dmdirc.logger.Logger;
31 30
 
@@ -82,7 +81,7 @@ public final class IdentClient implements Runnable {
82 81
             in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
83 82
             final String inputLine;
84 83
             if ((inputLine = in.readLine()) != null) {
85
-                out.println(getIdentResponse(inputLine, IdentityManager.getGlobalConfig()));
84
+                out.println(getIdentResponse(inputLine, myPlugin.getConfig()));
86 85
             }
87 86
         } catch (IOException e) {
88 87
             if (thisThread == myThread) {

+ 13
- 6
src/com/dmdirc/addons/identd/IdentdPlugin.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.addons.identd;
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.interfaces.actions.ActionType;
28
+import com.dmdirc.config.ConfigManager;
28 29
 import com.dmdirc.config.IdentityManager;
29 30
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
30 31
 import com.dmdirc.config.prefs.PreferencesCategory;
@@ -40,6 +41,8 @@ import com.dmdirc.util.validators.PortValidator;
40 41
 import java.util.ArrayList;
41 42
 import java.util.List;
42 43
 
44
+import lombok.Getter;
45
+
43 46
 /**
44 47
  * The Identd plugin answers ident requests from IRC servers.
45 48
  */
@@ -53,6 +56,9 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
53 56
     private final PluginInfo pluginInfo;
54 57
     /** The action controller to use. */
55 58
     private final ActionController actionController;
59
+    /** Global config. */
60
+    @Getter
61
+    private ConfigManager config;
56 62
 
57 63
     /**
58 64
      * Creates a new instance of this plugin.
@@ -61,11 +67,13 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
61 67
      * @param actionController The action controller to register listeners with
62 68
      */
63 69
     public IdentdPlugin(final PluginInfo pluginInfo,
64
-            final ActionController actionController) {
70
+            final ActionController actionController,
71
+            final IdentityManager identityManager) {
65 72
         super();
66 73
 
67 74
         this.pluginInfo = pluginInfo;
68 75
         this.actionController = actionController;
76
+        config = identityManager.getGlobalConfiguration();
69 77
     }
70 78
 
71 79
     /**
@@ -80,8 +88,7 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
80 88
                 CoreActionType.SERVER_CONNECTERROR);
81 89
 
82 90
         myServer = new IdentdServer(this);
83
-        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
84
-                "advanced.alwaysOn")) {
91
+        if (config.getOptionBool(getDomain(), "advanced.alwaysOn")) {
85 92
             myServer.startServer();
86 93
         }
87 94
     }
@@ -116,10 +123,10 @@ public class IdentdPlugin extends BasePlugin implements ActionListener {
116 123
         } else if (type == CoreActionType.SERVER_CONNECTED
117 124
                 || type == CoreActionType.SERVER_CONNECTERROR) {
118 125
             synchronized (servers) {
119
-                servers.remove((Server) arguments[0]);
126
+                servers.remove(arguments[0]);
120 127
 
121
-                if (servers.isEmpty() && !IdentityManager.getGlobalConfig()
122
-                        .getOptionBool(getDomain(), "advanced.alwaysOn")) {
128
+                if (servers.isEmpty() && !config.getOptionBool(getDomain(),
129
+                        "advanced.alwaysOn")) {
123 130
                     myServer.stopServer();
124 131
                 }
125 132
             }

+ 3
- 12
src/com/dmdirc/addons/identd/IdentdServer.java View File

@@ -22,12 +22,8 @@
22 22
 
23 23
 package com.dmdirc.addons.identd;
24 24
 
25
-import com.dmdirc.config.IdentityManager;
26 25
 import com.dmdirc.logger.ErrorLevel;
27 26
 import com.dmdirc.logger.Logger;
28
-import com.dmdirc.plugins.PluginInfo;
29
-import com.dmdirc.plugins.PluginManager;
30
-
31 27
 import java.io.IOException;
32 28
 import java.net.ServerSocket;
33 29
 import java.net.Socket;
@@ -122,18 +118,13 @@ public final class IdentdServer implements Runnable {
122 118
     public void startServer() {
123 119
         if (myThread == null) {
124 120
             try {
125
-                final int identPort = IdentityManager.getGlobalConfig().getOptionInt(myPlugin.getDomain(), "advanced.port");
121
+                final int identPort = myPlugin.getConfig().getOptionInt(
122
+                        myPlugin.getDomain(), "advanced.port");
126 123
                 serverSocket = new ServerSocket(identPort);
127 124
                 myThread = new Thread(this);
128 125
                 myThread.start();
129 126
             } catch (IOException e) {
130
-                Logger.userError(ErrorLevel.MEDIUM, "Unable to start identd server: " + e.getMessage());
131
-                if (e.getMessage().equals("Permission denied")) {
132
-                    final PluginInfo plugin = PluginManager.getPluginManager().getPluginInfoByName("identd");
133
-                    if (plugin != null && PluginManager.getPluginManager().delPlugin(plugin.getMetaData().getRelativeFilename())) {
134
-                        PluginManager.getPluginManager().updateAutoLoad(plugin);
135
-                    }
136
-                }
127
+                Logger.userError(ErrorLevel.HIGH, "Unable to start identd server: " + e.getMessage());
137 128
             }
138 129
         }
139 130
     }

+ 8
- 2
src/com/dmdirc/addons/lagdisplay/LagDisplayPanel.java View File

@@ -21,6 +21,7 @@
21 21
  */
22 22
 package com.dmdirc.addons.lagdisplay;
23 23
 
24
+import com.dmdirc.addons.ui_swing.SwingController;
24 25
 import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupPanel;
25 26
 import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow;
26 27
 
@@ -40,21 +41,26 @@ public class LagDisplayPanel extends StatusbarPopupPanel<JLabel> {
40 41
     private static final long serialVersionUID = 2;
41 42
     /** Lag display plugin. */
42 43
     private final LagDisplayPlugin plugin;
44
+    /** Swing controller. */
45
+    private final SwingController controller;
43 46
 
44 47
     /**
45 48
      * Creates a new {@link LagDisplayPanel} for the specified plugin.
46 49
      *
47 50
      * @param plugin The plugin that owns this panel
51
+     * @param controller Parent Swing controller
48 52
      */
49
-    public LagDisplayPanel(final LagDisplayPlugin plugin) {
53
+    public LagDisplayPanel(final LagDisplayPlugin plugin,
54
+            final SwingController controller) {
50 55
         super(new JLabel());
51 56
 
52 57
         this.plugin = plugin;
58
+        this.controller = controller;
53 59
     }
54 60
 
55 61
     /** {@inheritDoc} */
56 62
     @Override
57 63
     protected StatusbarPopupWindow getWindow() {
58
-        return new ServerInfoDialog(plugin, this);
64
+        return new ServerInfoDialog(plugin, this, controller);
59 65
     }
60 66
 }

+ 13
- 14
src/com/dmdirc/addons/lagdisplay/LagDisplayPlugin.java View File

@@ -32,7 +32,6 @@ import com.dmdirc.addons.ui_swing.SelectionListener;
32 32
 import com.dmdirc.addons.ui_swing.SwingController;
33 33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34 34
 import com.dmdirc.config.ConfigManager;
35
-import com.dmdirc.config.IdentityManager;
36 35
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
37 36
 import com.dmdirc.config.prefs.PreferencesCategory;
38 37
 import com.dmdirc.config.prefs.PreferencesDialogModel;
@@ -42,7 +41,6 @@ import com.dmdirc.interfaces.ActionListener;
42 41
 import com.dmdirc.interfaces.ConfigChangeListener;
43 42
 import com.dmdirc.plugins.BasePlugin;
44 43
 import com.dmdirc.plugins.PluginInfo;
45
-import com.dmdirc.plugins.PluginManager;
46 44
 import com.dmdirc.util.collections.RollingList;
47 45
 
48 46
 import java.util.Date;
@@ -57,7 +55,7 @@ public final class LagDisplayPlugin extends BasePlugin implements
57 55
         ActionListener, ConfigChangeListener, SelectionListener {
58 56
 
59 57
     /** The panel we use in the status bar. */
60
-    private final LagDisplayPanel panel = new LagDisplayPanel(this);
58
+    private final LagDisplayPanel panel;
61 59
     /** A cache of ping times. */
62 60
     private final Map<Server, String> pings = new WeakHashMap<Server, String>();
63 61
     /** Ping history. */
@@ -73,6 +71,8 @@ public final class LagDisplayPlugin extends BasePlugin implements
73 71
     private int historySize = 100;
74 72
     /** This plugin's plugin info. */
75 73
     private final PluginInfo pluginInfo;
74
+    /** Global config. */
75
+    private ConfigManager config;
76 76
 
77 77
     /**
78 78
      * Creates a new LagDisplayPlugin.
@@ -85,6 +85,8 @@ public final class LagDisplayPlugin extends BasePlugin implements
85 85
         super();
86 86
         this.controller = controller;
87 87
         this.pluginInfo = pluginInfo;
88
+        config = controller.getGlobalConfig();
89
+        panel = new LagDisplayPanel(this, controller);
88 90
     }
89 91
 
90 92
     /** {@inheritDoc} */
@@ -92,7 +94,7 @@ public final class LagDisplayPlugin extends BasePlugin implements
92 94
     public void onLoad() {
93 95
         controller.getSwingStatusBar().addComponent(panel);
94 96
         controller.getMainFrame().addSelectionListener(this);
95
-        IdentityManager.getGlobalConfig().addChangeListener(getDomain(), this);
97
+        config.addChangeListener(getDomain(), this);
96 98
         readConfig();
97 99
         ActionManager.getActionManager().registerListener(this,
98 100
                 CoreActionType.SERVER_GOTPING, CoreActionType.SERVER_NOPING,
@@ -105,16 +107,15 @@ public final class LagDisplayPlugin extends BasePlugin implements
105 107
     public void onUnload() {
106 108
         controller.getMainFrame().removeSelectionListener(this);
107 109
         controller.getSwingStatusBar().removeComponent(panel);
108
-        IdentityManager.getConfigIdentity().removeListener(this);
110
+        config.removeListener(this);
109 111
         ActionManager.getActionManager().unregisterListener(this);
110 112
     }
111 113
 
112 114
     /** Reads the plugin's global configuration settings. */
113 115
     private void readConfig() {
114
-        final ConfigManager manager = IdentityManager.getGlobalConfig();
115
-        showGraph = manager.getOptionBool(getDomain(), "graph");
116
-        showLabels = manager.getOptionBool(getDomain(), "labels");
117
-        historySize = manager.getOptionInt(getDomain(), "history");
116
+        showGraph = config.getOptionBool(getDomain(), "graph");
117
+        showLabels = config.getOptionBool(getDomain(), "labels");
118
+        historySize = config.getOptionInt(getDomain(), "history");
118 119
     }
119 120
 
120 121
     /**
@@ -180,9 +181,7 @@ public final class LagDisplayPlugin extends BasePlugin implements
180 181
             }
181 182
         }
182 183
 
183
-        final TextFrame activeFrame = ((SwingController) PluginManager
184
-                .getPluginManager().getPluginInfoByName("ui_swing").getPlugin())
185
-                .getMainFrame().getActiveFrame();
184
+        final TextFrame activeFrame = controller.getMainFrame().getActiveFrame();
186 185
         final FrameContainer active = activeFrame == null ? null
187 186
                 : activeFrame.getContainer();
188 187
 
@@ -210,7 +209,7 @@ public final class LagDisplayPlugin extends BasePlugin implements
210 209
         } else if (type.equals(CoreActionType.SERVER_DISCONNECTED)) {
211 210
             if (((Server) arguments[0]).isChild(active) || arguments[0] == active) {
212 211
                 panel.getComponent().setText("Not connected");
213
-                pings.remove((Server) arguments[0]);
212
+                pings.remove(arguments[0]);
214 213
             }
215 214
 
216 215
             panel.refreshDialog();
@@ -231,7 +230,7 @@ public final class LagDisplayPlugin extends BasePlugin implements
231 230
                     panel.getComponent().setText(value);
232 231
                 }
233 232
             } catch (NumberFormatException ex) {
234
-                pings.remove((Server) arguments[0]);
233
+                pings.remove(arguments[0]);
235 234
             }
236 235
 
237 236
             if (format != null) {

+ 5
- 6
src/com/dmdirc/addons/lagdisplay/PingHistoryPanel.java View File

@@ -22,8 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.lagdisplay;
24 24
 
25
-import com.dmdirc.addons.ui_swing.SwingController;
26
-import com.dmdirc.plugins.PluginManager;
25
+import com.dmdirc.addons.ui_swing.MainFrame;
27 26
 import com.dmdirc.util.collections.RollingList;
28 27
 
29 28
 import java.awt.Color;
@@ -62,8 +61,10 @@ public class PingHistoryPanel extends JPanel {
62 61
      * Creates a new history panel for the specified plugin.
63 62
      *
64 63
      * @param plugin The plugin that owns this panel
64
+     * @param mainFrame Swing main frame
65 65
      */
66
-    public PingHistoryPanel(final LagDisplayPlugin plugin) {
66
+    public PingHistoryPanel(final LagDisplayPlugin plugin,
67
+            final MainFrame mainFrame) {
67 68
         super();
68 69
 
69 70
         setMinimumSize(new Dimension(50, 100));
@@ -71,9 +72,7 @@ public class PingHistoryPanel extends JPanel {
71 72
         setOpaque(false);
72 73
 
73 74
         this.plugin = plugin;
74
-        this.history = plugin.getHistory(((SwingController) PluginManager
75
-                .getPluginManager().getPluginInfoByName("ui_swing")
76
-                .getPlugin()).getMainFrame().getActiveFrame().getContainer()
75
+        history = plugin.getHistory(mainFrame.getActiveFrame().getContainer()
77 76
                 .getServer());
78 77
 
79 78
         for (Long value : history.getList()) {

+ 10
- 8
src/com/dmdirc/addons/lagdisplay/ServerInfoDialog.java View File

@@ -25,11 +25,10 @@ package com.dmdirc.addons.lagdisplay;
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.ServerState;
28
+import com.dmdirc.addons.ui_swing.MainFrame;
28 29
 import com.dmdirc.addons.ui_swing.SwingController;
29 30
 import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPanel;
30 31
 import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow;
31
-import com.dmdirc.plugins.PluginManager;
32
-
33 32
 import java.util.List;
34 33
 
35 34
 import javax.swing.JLabel;
@@ -53,20 +52,23 @@ public class ServerInfoDialog extends StatusbarPopupWindow {
53 52
 
54 53
     /** The lag display plugin. */
55 54
     protected final LagDisplayPlugin plugin;
55
+    /** Swing main frame. */
56
+    private final MainFrame mainFrame;
56 57
 
57 58
     /**
58 59
      * Creates a new ServerInfoDialog.
59 60
      *
60 61
      * @param ldp The {@link LagDisplayPlugin} we're using for info
61 62
      * @param parent The {@link JPanel} to use for positioning
63
+     * @param controller Parent Swing controller
62 64
      */
63
-    public ServerInfoDialog(final LagDisplayPlugin ldp, final StatusbarPanel parent) {
64
-        super(((SwingController) PluginManager.getPluginManager()
65
-                .getPluginInfoByName("ui_swing").getPlugin()), parent,
66
-                ((SwingController) PluginManager.getPluginManager()
67
-                .getPluginInfoByName("ui_swing").getPlugin()).getMainFrame());
65
+    public ServerInfoDialog(final LagDisplayPlugin ldp,
66
+            final StatusbarPanel parent,
67
+            final SwingController controller) {
68
+        super(controller, parent, controller.getMainFrame());
68 69
 
69 70
         plugin = ldp;
71
+        mainFrame = controller.getMainFrame();
70 72
     }
71 73
 
72 74
     /** {@inheritDoc} */
@@ -78,7 +80,7 @@ public class ServerInfoDialog extends StatusbarPopupWindow {
78 80
             panel.add(new JLabel("No open servers."));
79 81
         } else {
80 82
             if (plugin.shouldShowGraph()) {
81
-                panel.add(new PingHistoryPanel(plugin), "span, grow, wrap");
83
+                panel.add(new PingHistoryPanel(plugin, mainFrame), "span, grow, wrap");
82 84
                 panel.add(new JSeparator(), "span, grow, wrap");
83 85
             }
84 86
 

Loading…
Cancel
Save