Browse Source

Remove singleton calls from DCC plugin.

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

+ 7
- 3
src/com/dmdirc/addons/dcc/ChatContainer.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.addons.dcc;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.addons.dcc.actions.DCCActions;
27 27
 import com.dmdirc.addons.dcc.io.DCCChat;
28
+import com.dmdirc.config.ConfigManager;
28 29
 import com.dmdirc.ui.WindowManager;
29 30
 import com.dmdirc.ui.core.components.WindowComponent;
30 31
 
@@ -47,16 +48,19 @@ public class ChatContainer extends DCCFrameContainer implements DCCChatHandler {
47 48
      *
48 49
      * @param plugin the DCC Plugin responsible for this window
49 50
      * @param dcc The DCCChat object this window wraps around
51
+     * @param configManager Config manager
50 52
      * @param title The title of this window
51 53
      * @param nick My Current Nickname
52 54
      * @param targetNick Nickname of target
53 55
      */
54 56
     public ChatContainer(final DCCPlugin plugin, final DCCChat dcc,
55
-            final String title, final String nick, final String targetNick) {
56
-        super(title, "dcc-chat-inactive",DCCCommandParser.getDCCCommandParser(),
57
+            final ConfigManager configManager, final String title,
58
+            final String nick, final String targetNick) {
59
+        super(title, "dcc-chat-inactive", configManager,
60
+                DCCCommandParser.getDCCCommandParser(),
57 61
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
58 62
                 WindowComponent.INPUTFIELD.getIdentifier()));
59
-        this.dccChat = dcc;
63
+        dccChat = dcc;
60 64
         dcc.setHandler(this);
61 65
         nickname = nick;
62 66
         otherNickname = targetNick;

+ 20
- 15
src/com/dmdirc/addons/dcc/DCCCommand.java View File

@@ -30,7 +30,7 @@ import com.dmdirc.addons.dcc.io.DCC;
30 30
 import com.dmdirc.addons.dcc.io.DCCChat;
31 31
 import com.dmdirc.addons.dcc.io.DCCTransfer;
32 32
 import com.dmdirc.addons.dcc.kde.KFileChooser;
33
-import com.dmdirc.addons.ui_swing.SwingController;
33
+import com.dmdirc.addons.ui_swing.MainFrame;
34 34
 import com.dmdirc.commandparser.BaseCommandInfo;
35 35
 import com.dmdirc.commandparser.CommandArguments;
36 36
 import com.dmdirc.commandparser.CommandInfo;
@@ -39,9 +39,7 @@ import com.dmdirc.commandparser.commands.Command;
39 39
 import com.dmdirc.commandparser.commands.IntelligentCommand;
40 40
 import com.dmdirc.commandparser.commands.context.CommandContext;
41 41
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
42
-import com.dmdirc.config.IdentityManager;
43 42
 import com.dmdirc.parser.interfaces.Parser;
44
-import com.dmdirc.plugins.PluginManager;
45 43
 import com.dmdirc.ui.input.AdditionalTabTargets;
46 44
 import com.dmdirc.ui.input.TabCompletionType;
47 45
 
@@ -62,14 +60,18 @@ public class DCCCommand extends Command implements IntelligentCommand {
62 60
 
63 61
     /** My Plugin. */
64 62
     private final DCCPlugin myPlugin;
63
+    /** Main frame instance used as the parent for dialogs. */
64
+    private final MainFrame mainFrame;
65 65
 
66 66
     /**
67 67
      * Creates a new instance of DCCCommand.
68 68
      *
69
+     * @param mainFrame mainFrame instance to use
69 70
      * @param plugin The DCC Plugin that this command belongs to
70 71
      */
71
-    public DCCCommand(final DCCPlugin plugin) {
72
+    public DCCCommand(final MainFrame mainFrame, final DCCPlugin plugin) {
72 73
         super();
74
+        this.mainFrame = mainFrame;
73 75
         myPlugin = plugin;
74 76
     }
75 77
 
@@ -137,6 +139,7 @@ public class DCCCommand extends Command implements IntelligentCommand {
137 139
         final DCCChat chat = new DCCChat();
138 140
         if (myPlugin.listen(chat)) {
139 141
             final ChatContainer window = new ChatContainer(myPlugin, chat,
142
+                    origin.getConfigManager(),
140 143
                     "*Chat: " + target, myNickname, target);
141 144
             parser.sendCTCP(target, "DCC", "CHAT chat " + DCC.ipToLong(
142 145
                     myPlugin.getListenIP(parser)) + " " + chat.getPort());
@@ -173,17 +176,19 @@ public class DCCCommand extends Command implements IntelligentCommand {
173 176
             @Override
174 177
             public void run() {
175 178
                 final JFileChooser jc = givenFile.exists()
176
-                        ? KFileChooser.getFileChooser(myPlugin, givenFile)
177
-                        : KFileChooser.getFileChooser(myPlugin);
179
+                        ? KFileChooser.getFileChooser(origin.getConfigManager(),
180
+                                myPlugin, givenFile)
181
+                        : KFileChooser.getFileChooser(origin.getConfigManager(),
182
+                                myPlugin);
178 183
                 final int result = showFileChooser(givenFile, target, jc);
179 184
                 if (result != JFileChooser.APPROVE_OPTION
180 185
                         || !handleInvalidItems(jc)) {
181 186
                     return;
182 187
                 }
183
-                final DCCTransfer send = new DCCTransfer(IdentityManager
184
-                        .getGlobalConfig().getOptionInt(myPlugin.getDomain(),
188
+                final DCCTransfer send = new DCCTransfer(origin
189
+                        .getConfigManager().getOptionInt(myPlugin.getDomain(),
185 190
                         "send.blocksize"));
186
-                send.setTurbo(IdentityManager.getGlobalConfig().getOptionBool(
191
+                send.setTurbo(origin.getConfigManager().getOptionBool(
187 192
                         myPlugin.getDomain(), "send.forceturbo"));
188 193
                 send.setType(DCCTransfer.TransferType.SEND);
189 194
 
@@ -197,10 +202,11 @@ public class DCCCommand extends Command implements IntelligentCommand {
197 202
                 send.setFileName(jc.getSelectedFile().getAbsolutePath());
198 203
                 send.setFileSize(jc.getSelectedFile().length());
199 204
 
200
-                if (IdentityManager.getGlobalConfig().getOptionBool(
205
+                if (origin.getConfigManager().getOptionBool(
201 206
                         myPlugin.getDomain(), "send.reverse")) {
202 207
                     final Parser parser = server.getParser();
203
-                    new TransferContainer(myPlugin, send, "Send: " + target,
208
+                    new TransferContainer(myPlugin, send,
209
+                            origin.getConfigManager(), "Send: " + target,
204 210
                             target, server);
205 211
                     parser.sendCTCP(target, "DCC", "SEND \""
206 212
                             + jc.getSelectedFile().getName() + "\" "
@@ -211,7 +217,8 @@ public class DCCCommand extends Command implements IntelligentCommand {
211 217
                 } else {
212 218
                     final Parser parser = server.getParser();
213 219
                     if (myPlugin.listen(send)) {
214
-                        new TransferContainer(myPlugin, send, "*Send: "
220
+                        new TransferContainer(myPlugin, send,
221
+                                origin.getConfigManager(), "*Send: "
215 222
                                 + target, target, server);
216 223
                         parser.sendCTCP(target, "DCC", "SEND \""
217 224
                                 + jc.getSelectedFile().getName() + "\" "
@@ -274,9 +281,7 @@ public class DCCCommand extends Command implements IntelligentCommand {
274 281
         jc.setDialogTitle("Send file to " + target + " - DMDirc ");
275 282
         jc.setFileSelectionMode(JFileChooser.FILES_ONLY);
276 283
         jc.setMultiSelectionEnabled(false);
277
-        return jc.showOpenDialog(((SwingController) PluginManager
278
-                .getPluginManager().getPluginInfoByName("ui_swing")
279
-                .getPlugin()).getMainFrame());
284
+        return jc.showOpenDialog(mainFrame);
280 285
         }
281 286
     }
282 287
 

+ 5
- 4
src/com/dmdirc/addons/dcc/DCCFrameContainer.java View File

@@ -25,7 +25,7 @@ package com.dmdirc.addons.dcc;
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.WritableFrameContainer;
27 27
 import com.dmdirc.commandparser.parsers.CommandParser;
28
-import com.dmdirc.config.IdentityManager;
28
+import com.dmdirc.config.ConfigManager;
29 29
 import com.dmdirc.ui.input.TabCompleter;
30 30
 
31 31
 import java.util.Collection;
@@ -43,13 +43,14 @@ public abstract class DCCFrameContainer extends WritableFrameContainer {
43 43
      *
44 44
      * @param title The title of this window
45 45
      * @param icon The icon to use
46
+     * @param configManager Config manager
46 47
      * @param parser Command parser to use for this window
47 48
      * @param components The UI components that this frame requires
48 49
      */
49 50
     public DCCFrameContainer(final String title, final String icon,
50
-            final CommandParser parser, final Collection<String> components) {
51
-        super(icon, title, title, IdentityManager.getGlobalConfig(), parser,
52
-                components);
51
+            final ConfigManager configManager, final CommandParser parser,
52
+            final Collection<String> components) {
53
+        super(icon, title, title, configManager, parser, components);
53 54
     }
54 55
 
55 56
     /** {@inheritDoc} */

+ 44
- 47
src/com/dmdirc/addons/dcc/DCCPlugin.java View File

@@ -26,7 +26,6 @@ import com.dmdirc.Main;
26 26
 import com.dmdirc.Server;
27 27
 import com.dmdirc.actions.ActionManager;
28 28
 import com.dmdirc.actions.CoreActionType;
29
-import com.dmdirc.interfaces.actions.ActionType;
30 29
 import com.dmdirc.addons.dcc.actions.DCCActions;
31 30
 import com.dmdirc.addons.dcc.io.DCC;
32 31
 import com.dmdirc.addons.dcc.io.DCCChat;
@@ -35,6 +34,7 @@ import com.dmdirc.addons.dcc.kde.KFileChooser;
35 34
 import com.dmdirc.addons.ui_swing.SwingController;
36 35
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
37 36
 import com.dmdirc.addons.ui_swing.components.frames.ComponentFrame;
37
+import com.dmdirc.config.ConfigManager;
38 38
 import com.dmdirc.config.Identity;
39 39
 import com.dmdirc.config.IdentityManager;
40 40
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
@@ -43,13 +43,13 @@ import com.dmdirc.config.prefs.PreferencesDialogModel;
43 43
 import com.dmdirc.config.prefs.PreferencesSetting;
44 44
 import com.dmdirc.config.prefs.PreferencesType;
45 45
 import com.dmdirc.interfaces.ActionListener;
46
+import com.dmdirc.interfaces.actions.ActionType;
46 47
 import com.dmdirc.logger.ErrorLevel;
47 48
 import com.dmdirc.logger.Logger;
48 49
 import com.dmdirc.parser.interfaces.ClientInfo;
49 50
 import com.dmdirc.parser.interfaces.Parser;
50 51
 import com.dmdirc.plugins.BasePlugin;
51 52
 import com.dmdirc.plugins.PluginInfo;
52
-import com.dmdirc.plugins.PluginManager;
53 53
 import com.dmdirc.ui.WindowManager;
54 54
 
55 55
 import java.io.File;
@@ -71,6 +71,10 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
71 71
     private PlaceholderContainer container;
72 72
     /** This plugin's plugin info. */
73 73
     private final PluginInfo pluginInfo;
74
+    /** Config manager to read settings from. */
75
+    private final ConfigManager config;
76
+    /** Parent swing controller. */
77
+    private final SwingController controller;
74 78
 
75 79
     /**
76 80
      * Creates a new instance of this plugin.
@@ -81,8 +85,11 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
81 85
     public DCCPlugin(final SwingController controller,
82 86
             final PluginInfo pluginInfo) {
83 87
         super();
88
+        this.controller = controller;
89
+        config = controller.getGlobalConfig();
84 90
         this.pluginInfo = pluginInfo;
85
-        registerCommand(new DCCCommand(this), DCCCommand.INFO);
91
+        registerCommand(new DCCCommand(controller.getMainFrame(), this),
92
+                DCCCommand.INFO);
86 93
         final SwingWindowFactory factory = controller.getWindowFactory();
87 94
         factory.registerImplementation(new HashSet<String>(Arrays.asList(
88 95
                 "com.dmdirc.addons.dcc.ui.PlaceholderPanel")),
@@ -139,12 +146,11 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
139 146
             /** {@inheritDoc} */
140 147
             @Override
141 148
             public void run() {
142
-                final JFileChooser jc = KFileChooser.getFileChooser(
143
-                        DCCPlugin.this, IdentityManager.getGlobalConfig()
144
-                        .getOption(getDomain(), "receive.savelocation"));
149
+                final JFileChooser jc = KFileChooser.getFileChooser(config,
150
+                        DCCPlugin.this,
151
+                        config.getOption(getDomain(), "receive.savelocation"));
145 152
                 int result;
146
-                if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
147
-                        "receive.autoaccept")) {
153
+                if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
148 154
                     result = JFileChooser.APPROVE_OPTION;
149 155
                 } else {
150 156
                     result = showFileChooser(send, jc);
@@ -158,12 +164,12 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
158 164
                 }
159 165
                 final boolean resume = handleResume(jc);
160 166
                 if (reverse && !token.isEmpty()) {
161
-                    new TransferContainer(DCCPlugin.this, send,
167
+                    new TransferContainer(DCCPlugin.this, send, config,
162 168
                             "*Receive: " + nickname, nickname, null);
163 169
                     send.setToken(token);
164 170
                     if (resume) {
165
-                        if (IdentityManager.getGlobalConfig().getOptionBool(
166
-                                getDomain(), "receive.reverse.sendtoken")) {
171
+                        if (config.getOptionBool(getDomain(),
172
+                                "receive.reverse.sendtoken")) {
167 173
                             parser.sendCTCP(nickname, "DCC", "RESUME "
168 174
                                     + send.getShortFileName() + " 0 "
169 175
                                     + jc.getSelectedFile().length() + " "
@@ -183,8 +189,8 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
183 189
                         }
184 190
                     }
185 191
                 } else {
186
-                    new TransferContainer(DCCPlugin.this, send, "Receive: "
187
-                            + nickname, nickname, null);
192
+                    new TransferContainer(DCCPlugin.this, send, config,
193
+                            "Receive: " + nickname, nickname, null);
188 194
                     if (resume) {
189 195
                         parser.sendCTCP(nickname, "DCC", "RESUME "
190 196
                                 + send.getShortFileName() + " "
@@ -216,13 +222,11 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
216 222
             final String token) {
217 223
         if (jc.getSelectedFile().exists() && send.getFileSize() > -1
218 224
                 && send.getFileSize() <= jc.getSelectedFile().length()) {
219
-            if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
220
-                    "receive.autoaccept")) {
225
+            if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
221 226
                 return false;
222 227
             } else {
223
-                JOptionPane.showMessageDialog(((SwingController) PluginManager
224
-                        .getPluginManager().getPluginInfoByName("ui_swing")
225
-                        .getPlugin()).getMainFrame(), "This file has already "
228
+                JOptionPane.showMessageDialog(controller.getMainFrame(),
229
+                        "This file has already "
226 230
                         + "been completed, or is longer than the file you are "
227 231
                         + "receiving.\nPlease choose a different file.",
228 232
                         "Problem with selected file",
@@ -243,14 +247,11 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
243 247
      */
244 248
     private boolean handleResume(final JFileChooser jc) {
245 249
         if (jc.getSelectedFile().exists()) {
246
-            if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
247
-                    "receive.autoaccept")) {
250
+            if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
248 251
                 return true;
249 252
             } else {
250 253
                 final int result = JOptionPane.showConfirmDialog(
251
-                        ((SwingController) PluginManager
252
-                        .getPluginManager().getPluginInfoByName("ui_swing")
253
-                        .getPlugin()).getMainFrame(), "This file exists already"
254
+                        controller.getMainFrame(), "This file exists already"
254 255
                         + ", do you want to resume an exisiting download?",
255 256
                         "Resume Download?", JOptionPane.YES_NO_OPTION);
256 257
                 return (result == JOptionPane.YES_OPTION);
@@ -278,9 +279,7 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
278 279
                 jc.setFileSelectionMode(JFileChooser.FILES_ONLY);
279 280
                 jc.setMultiSelectionEnabled(false);
280 281
                 jc.setSelectedFile(new File(send.getFileName()));
281
-        return jc.showSaveDialog(((SwingController) PluginManager
282
-                .getPluginManager().getPluginInfoByName("ui_swing")
283
-                .getPlugin()).getMainFrame());
282
+        return jc.showSaveDialog(controller.getMainFrame());
284 283
     }
285 284
 
286 285
     /** {@inheritDoc} */
@@ -299,14 +298,14 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
299 298
      * @return True if Socket was opened.
300 299
      */
301 300
     protected boolean listen(final DCC dcc) {
302
-        final boolean usePortRange = IdentityManager.getGlobalConfig()
303
-                .getOptionBool(getDomain(), "firewall.ports.usePortRange");
301
+        final boolean usePortRange = config.getOptionBool(getDomain(),
302
+                "firewall.ports.usePortRange");
304 303
         try {
305 304
             if (usePortRange) {
306
-                final int startPort = IdentityManager.getGlobalConfig()
307
-                        .getOptionInt(getDomain(), "firewall.ports.startPort");
308
-                final int endPort = IdentityManager.getGlobalConfig()
309
-                        .getOptionInt(getDomain(), "firewall.ports.endPort");
305
+                final int startPort = config.getOptionInt(getDomain(),
306
+                        "firewall.ports.startPort");
307
+                final int endPort = config.getOptionInt(getDomain(),
308
+                        "firewall.ports.endPort");
310 309
                 dcc.listen(startPort, endPort);
311 310
             } else {
312 311
                 dcc.listen();
@@ -328,8 +327,7 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
328 327
     public void handleProcessEvent(final ActionType type,
329 328
             final StringBuffer format, final boolean dontAsk,
330 329
             final Object... arguments) {
331
-        if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(),
332
-                "receive.autoaccept") && !dontAsk) {
330
+        if (config.getOptionBool(getDomain(), "receive.autoaccept") && !dontAsk) {
333 331
             handleProcessEvent(type, format, true, arguments);
334 332
             return;
335 333
         }
@@ -375,14 +373,14 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
375 373
             }
376 374
             final String myNickname = ((Server) arguments[0]).getParser()
377 375
                     .getLocalClient().getNickname();
378
-            final DCCFrameContainer f = new ChatContainer(this, chat,
376
+            final DCCFrameContainer f = new ChatContainer(this, chat, config,
379 377
                     "Chat: " + nickname, myNickname, nickname);
380 378
             f.addLine("DCCChatStarting", nickname, chat.getHost(),
381 379
                     chat.getPort());
382 380
             chat.connect();
383 381
         } else {
384 382
             ActionManager.getActionManager().triggerEvent(
385
-                    DCCActions.DCC_CHAT_REQUEST, null, ((Server) arguments[0]),
383
+                    DCCActions.DCC_CHAT_REQUEST, null, arguments[0],
386 384
                     nickname);
387 385
             askQuestion("User " + nickname + " on "
388 386
                     + ((Server) arguments[0]).getName()
@@ -478,7 +476,7 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
478 476
             } else {
479 477
                 ActionManager.getActionManager().triggerEvent(
480 478
                         DCCActions.DCC_SEND_REQUEST, null,
481
-                        ((Server) arguments[0]), nickname, filename);
479
+                        arguments[0], nickname, filename);
482 480
                 askQuestion("User " + nickname + " on "
483 481
                         + ((Server) arguments[0]).getName()
484 482
                         + " would like to send you a file over DCC.\n\nFile: "
@@ -490,10 +488,9 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
490 488
         } else {
491 489
             final boolean newSend = send == null;
492 490
             if (newSend) {
493
-                send = new DCCTransfer(IdentityManager.getGlobalConfig()
494
-                        .getOptionInt(getDomain(), "send.blocksize"));
495
-                send.setTurbo(IdentityManager.getGlobalConfig().getOptionBool(
496
-                        getDomain(), "send.forceturbo"));
491
+                send = new DCCTransfer(config.getOptionInt(getDomain(),
492
+                        "send.blocksize"));
493
+                send.setTurbo(config.getOptionBool(getDomain(), "send.forceturbo"));
497 494
             }
498 495
             try {
499 496
                 send.setAddress(Long.parseLong(ip), Integer.parseInt(port));
@@ -628,14 +625,15 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
628 625
      * Create the container window.
629 626
      */
630 627
     protected void createContainer() {
631
-        container = new PlaceholderContainer(this);
628
+        container = new PlaceholderContainer(this, config, controller);
632 629
         WindowManager.getWindowManager().addWindow(container);
633 630
     }
634 631
 
635 632
     /** {@inheritDoc} */
636 633
     @Override
637 634
     public void domainUpdated() {
638
-        final Identity defaults = IdentityManager.getAddonIdentity();
635
+        final Identity defaults = IdentityManager.getIdentityManager()
636
+                .getGlobalAddonIdentity();
639 637
 
640 638
         defaults.setOption(getDomain(), "receive.savelocation",
641 639
                 Main.getConfigDir() + "downloads"
@@ -647,8 +645,8 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
647 645
      */
648 646
     @Override
649 647
     public void onLoad() {
650
-        final File dir = new File(IdentityManager.getGlobalConfig()
651
-                .getOption(getDomain(), "receive.savelocation"));
648
+        final File dir = new File(config.getOption(getDomain(),
649
+                "receive.savelocation"));
652 650
         if (dir.exists()) {
653 651
             if (!dir.isDirectory()) {
654 652
                 Logger.userError(ErrorLevel.LOW,
@@ -698,8 +696,7 @@ public final class DCCPlugin extends BasePlugin implements ActionListener {
698 696
      * @return The IP Address we should send as our listening IP.
699 697
      */
700 698
     public String getListenIP(final Parser parser) {
701
-        final String configIP = IdentityManager.getGlobalConfig().getOption(
702
-                getDomain(), "firewall.ip");
699
+        final String configIP = config.getOption(getDomain(), "firewall.ip");
703 700
         if (!configIP.isEmpty()) {
704 701
             try {
705 702
                 return InetAddress.getByName(configIP).getHostAddress();

+ 11
- 9
src/com/dmdirc/addons/dcc/PlaceholderContainer.java View File

@@ -26,8 +26,7 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Server;
27 27
 import com.dmdirc.addons.ui_swing.SwingController;
28 28
 import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
29
-import com.dmdirc.config.IdentityManager;
30
-import com.dmdirc.plugins.PluginManager;
29
+import com.dmdirc.config.ConfigManager;
31 30
 
32 31
 import java.awt.Dialog.ModalityType;
33 32
 import java.util.Arrays;
@@ -39,17 +38,22 @@ public class PlaceholderContainer extends FrameContainer {
39 38
 
40 39
     /** The plugin which owns this placeholder. */
41 40
     private final DCCPlugin plugin;
41
+    /** Parent swing controller. */
42
+    private final SwingController controller;
42 43
 
43 44
     /**
44 45
      * Creates a placeholder DCC frame.
45 46
      *
46 47
      * @param plugin The plugin which owns this placeholder
48
+     * @param config Config manager
49
+     * @param controller Swing controller
47 50
      */
48
-    public PlaceholderContainer(final DCCPlugin plugin) {
49
-        super("dcc", "DCCs", "DCCs", IdentityManager.getGlobalConfig(),
50
-                Arrays.asList("com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
51
-
51
+    public PlaceholderContainer(final DCCPlugin plugin,
52
+            final ConfigManager config, final SwingController controller) {
53
+        super("dcc", "DCCs", "DCCs", config, Arrays.asList(
54
+                "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
52 55
         this.plugin = plugin;
56
+        this.controller = controller;
53 57
     }
54 58
 
55 59
     /** {@inheritDoc} */
@@ -66,9 +70,7 @@ public class PlaceholderContainer extends FrameContainer {
66 70
         }
67 71
 
68 72
         if (dccs > 0) {
69
-            new StandardQuestionDialog(((SwingController) PluginManager
70
-                    .getPluginManager().getPluginInfoByName("ui_swing")
71
-                    .getPlugin()), ModalityType.MODELESS,
73
+            new StandardQuestionDialog(controller, ModalityType.MODELESS,
72 74
                     "Close confirmation",
73 75
                     "Closing this window will cause all existing DCCs "
74 76
                     + "to terminate, are you sure you want to do this?") {

+ 14
- 9
src/com/dmdirc/addons/dcc/TransferContainer.java View File

@@ -29,7 +29,7 @@ import com.dmdirc.actions.ActionManager;
29 29
 import com.dmdirc.addons.dcc.actions.DCCActions;
30 30
 import com.dmdirc.addons.dcc.io.DCC;
31 31
 import com.dmdirc.addons.dcc.io.DCCTransfer;
32
-import com.dmdirc.config.IdentityManager;
32
+import com.dmdirc.config.ConfigManager;
33 33
 import com.dmdirc.parser.interfaces.Parser;
34 34
 import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
35 35
 import com.dmdirc.ui.WindowManager;
@@ -50,6 +50,9 @@ public class TransferContainer extends FrameContainer implements
50 50
     /** The dcc plugin that owns this frame */
51 51
     protected final DCCPlugin plugin;
52 52
 
53
+    /** Config manager. */
54
+    private final ConfigManager config;
55
+
53 56
     /** The Window we're using. */
54 57
     private boolean windowClosing = false;
55 58
 
@@ -84,21 +87,24 @@ public class TransferContainer extends FrameContainer implements
84 87
      *
85 88
      * @param plugin the DCC Plugin responsible for this window
86 89
      * @param dcc The DCCTransfer object this window wraps around
90
+     * @param configManager Config manager
87 91
      * @param title The title of this window
88 92
      * @param targetNick Nickname of target
89 93
      * @param server The server that initiated this send
90 94
      */
91 95
     public TransferContainer(final DCCPlugin plugin, final DCCTransfer dcc,
92
-            final String title, final String targetNick, final Server server) {
96
+            final ConfigManager config, final String title,
97
+            final String targetNick, final Server server) {
93 98
         super(dcc.getType() == DCCTransfer.TransferType.SEND
94 99
                 ? "dcc-send-inactive" : "dcc-receive-inactive",
95
-                title, title, IdentityManager.getGlobalConfig(),
100
+                title, title, config,
96 101
                 Arrays.asList("com.dmdirc.addons.dcc.ui.TransferPanel"));
97 102
         this.plugin = plugin;
98 103
         this.dcc = dcc;
99 104
         this.server = server;
100
-        this.parser = server == null ? null : server.getParser();
101
-        this.myPlugin = plugin;
105
+        this.config = config;
106
+        parser = server == null ? null : server.getParser();
107
+        myPlugin = plugin;
102 108
 
103 109
         if (parser != null) {
104 110
             parser.getCallbackManager().addNonCriticalCallback(
@@ -152,8 +158,8 @@ public class TransferContainer extends FrameContainer implements
152 158
             percent = getPercent();
153 159
         }
154 160
 
155
-        final boolean percentageInTitle = IdentityManager.getGlobalConfig()
156
-                .getOptionBool(plugin.getDomain(), "general.percentageInTitle");
161
+        final boolean percentageInTitle = config.getOptionBool(
162
+                plugin.getDomain(), "general.percentageInTitle");
157 163
 
158 164
         if (percentageInTitle) {
159 165
             final StringBuilder title = new StringBuilder();
@@ -325,8 +331,7 @@ public class TransferContainer extends FrameContainer implements
325 331
                 }, "DCC-Error-Message");
326 332
                 errorThread.start();
327 333
             } else {
328
-                if (IdentityManager.getGlobalConfig().getOptionBool(
329
-                        plugin.getDomain(), "send.reverse")) {
334
+                if (config.getOptionBool(plugin.getDomain(), "send.reverse")) {
330 335
                     parser.sendCTCP(otherNickname, "DCC", "SEND \"" +
331 336
                             new File(dcc.getFileName()).getName() + "\" "
332 337
                             + DCC.ipToLong(myPlugin.getListenIP(parser))

+ 32
- 24
src/com/dmdirc/addons/dcc/kde/KFileChooser.java View File

@@ -23,8 +23,7 @@
23 23
 package com.dmdirc.addons.dcc.kde;
24 24
 
25 25
 import com.dmdirc.addons.dcc.DCCPlugin;
26
-import com.dmdirc.config.IdentityManager;
27
-
26
+import com.dmdirc.config.ConfigManager;
28 27
 import java.awt.Component;
29 28
 import java.awt.HeadlessException;
30 29
 import java.io.File;
@@ -68,16 +67,19 @@ public final class KFileChooser extends JFileChooser {
68 67
 
69 68
     /** The plugin that this file chooser is for. */
70 69
     private final DCCPlugin plugin;
70
+    /** Used to read settings from. */
71
+    private final ConfigManager config;
71 72
 
72 73
     /**
73 74
      * Constructs a FileChooser pointing to the user's default directory.
74 75
      *
75 76
      * @param plugin The plugin that owns this KFileChooser
76 77
      */
77
-    private KFileChooser(final DCCPlugin plugin) {
78
+    private KFileChooser(final ConfigManager config, final DCCPlugin plugin) {
78 79
         super();
79 80
 
80 81
         this.plugin = plugin;
82
+        this.config = config;
81 83
     }
82 84
 
83 85
     /**
@@ -86,10 +88,11 @@ public final class KFileChooser extends JFileChooser {
86 88
      * @param plugin The plugin that owns this KFileChooser
87 89
      * @param currentDirectory Directory to use as the base directory
88 90
      */
89
-    private KFileChooser(final DCCPlugin plugin, final File currentDirectory) {
91
+    private KFileChooser(final ConfigManager config, final DCCPlugin plugin, final File currentDirectory) {
90 92
         super(currentDirectory);
91 93
 
92 94
         this.plugin = plugin;
95
+        this.config = config;
93 96
     }
94 97
 
95 98
     /**
@@ -99,10 +102,11 @@ public final class KFileChooser extends JFileChooser {
99 102
      * @param currentDirectory Directory to use as the base directory
100 103
      * @param fsv The FileSystemView to use
101 104
      */
102
-    private KFileChooser(final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
105
+    private KFileChooser(final ConfigManager config, final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
103 106
         super(currentDirectory, fsv);
104 107
 
105 108
         this.plugin = plugin;
109
+        this.config = config;
106 110
     }
107 111
 
108 112
     /**
@@ -111,10 +115,11 @@ public final class KFileChooser extends JFileChooser {
111 115
      * @param plugin The plugin that owns this KFileChooser
112 116
      * @param fsv The FileSystemView to use
113 117
      */
114
-    private KFileChooser(final DCCPlugin plugin, final FileSystemView fsv) {
118
+    private KFileChooser(final ConfigManager config, final DCCPlugin plugin, final FileSystemView fsv) {
115 119
         super(fsv);
116 120
 
117 121
         this.plugin = plugin;
122
+        this.config = config;
118 123
     }
119 124
 
120 125
     /**
@@ -123,10 +128,11 @@ public final class KFileChooser extends JFileChooser {
123 128
      * @param plugin The plugin that owns this KFileChooser
124 129
      * @param currentDirectoryPath Directory to use as the base directory
125 130
      */
126
-    private KFileChooser(final DCCPlugin plugin, final String currentDirectoryPath) {
131
+    private KFileChooser(final ConfigManager config, final DCCPlugin plugin, final String currentDirectoryPath) {
127 132
         super(currentDirectoryPath);
128 133
 
129 134
         this.plugin = plugin;
135
+        this.config = config;
130 136
     }
131 137
 
132 138
     /**
@@ -136,21 +142,23 @@ public final class KFileChooser extends JFileChooser {
136 142
      * @param currentDirectoryPath Directory to use as the base directory
137 143
      * @param fsv The FileSystemView to use
138 144
      */
139
-    private KFileChooser(final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
145
+    private KFileChooser(final ConfigManager config, final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
140 146
         super(currentDirectoryPath, fsv);
141 147
 
142 148
         this.plugin = plugin;
149
+        this.config = config;
143 150
     }
144 151
 
145 152
     /**
146 153
      * Should a KFileChooser be used rather than a JFileChooser?
147 154
      *
155
+     * @param config Config manager
148 156
      * @param plugin The DCC Plugin that is requesting a chooser
149 157
      * @return return true if getFileChooser() will return a KFileChooser not a
150 158
      *         JFileChooser
151 159
      */
152
-    public static boolean useKFileChooser(final DCCPlugin plugin) {
153
-        return KDialogProcess.hasKDialog() && IdentityManager.getGlobalConfig().getOptionBool(plugin.getDomain(), "general.useKFileChooser");
160
+    public static boolean useKFileChooser(final ConfigManager config, final DCCPlugin plugin) {
161
+        return KDialogProcess.hasKDialog() && config.getOptionBool(plugin.getDomain(), "general.useKFileChooser");
154 162
     }
155 163
 
156 164
     /**
@@ -159,8 +167,8 @@ public final class KFileChooser extends JFileChooser {
159 167
      * @param plugin The DCC Plugin that is requesting a chooser
160 168
      * @return The relevant FileChooser
161 169
      */
162
-    public static JFileChooser getFileChooser(final DCCPlugin plugin) {
163
-        return useKFileChooser(plugin) ? new KFileChooser(plugin) : new JFileChooser();
170
+    public static JFileChooser getFileChooser(final ConfigManager config, final DCCPlugin plugin) {
171
+        return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin) : new JFileChooser();
164 172
     }
165 173
 
166 174
     /**
@@ -170,8 +178,8 @@ public final class KFileChooser extends JFileChooser {
170 178
      * @param currentDirectory Directory to use as the base directory
171 179
      * @return The relevant FileChooser
172 180
      */
173
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final File currentDirectory) {
174
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectory) : new JFileChooser(currentDirectory);
181
+    public static JFileChooser getFileChooser(final ConfigManager config, final DCCPlugin plugin, final File currentDirectory) {
182
+        return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectory) : new JFileChooser(currentDirectory);
175 183
     }
176 184
 
177 185
     /**
@@ -182,8 +190,8 @@ public final class KFileChooser extends JFileChooser {
182 190
      * @param fsv The FileSystemView to use
183 191
      * @return The relevant FileChooser
184 192
      */
185
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
186
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectory, fsv) : new JFileChooser(currentDirectory, fsv);
193
+    public static JFileChooser getFileChooser(final ConfigManager config, final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
194
+        return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectory, fsv) : new JFileChooser(currentDirectory, fsv);
187 195
     }
188 196
 
189 197
     /**
@@ -193,8 +201,8 @@ public final class KFileChooser extends JFileChooser {
193 201
      * @param fsv The FileSystemView to use
194 202
      * @return The relevant FileChooser
195 203
      */
196
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final FileSystemView fsv) {
197
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, fsv) : new JFileChooser(fsv);
204
+    public static JFileChooser getFileChooser(final ConfigManager config, final DCCPlugin plugin, final FileSystemView fsv) {
205
+        return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, fsv) : new JFileChooser(fsv);
198 206
     }
199 207
 
200 208
     /**
@@ -204,8 +212,8 @@ public final class KFileChooser extends JFileChooser {
204 212
      * @param currentDirectoryPath Directory to use as the base directory
205 213
      * @return The relevant FileChooser
206 214
      */
207
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final String currentDirectoryPath) {
208
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectoryPath) : new JFileChooser(currentDirectoryPath);
215
+    public static JFileChooser getFileChooser(final ConfigManager config, final DCCPlugin plugin, final String currentDirectoryPath) {
216
+        return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectoryPath) : new JFileChooser(currentDirectoryPath);
209 217
     }
210 218
 
211 219
     /**
@@ -216,8 +224,8 @@ public final class KFileChooser extends JFileChooser {
216 224
      * @param fsv The FileSystemView to use
217 225
      * @return The relevant FileChooser
218 226
      */
219
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
220
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectoryPath, fsv) : new JFileChooser(currentDirectoryPath, fsv);
227
+    public static JFileChooser getFileChooser(final ConfigManager config, final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
228
+        return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectoryPath, fsv) : new JFileChooser(currentDirectoryPath, fsv);
221 229
     }
222 230
 
223 231
     /**
@@ -241,7 +249,7 @@ public final class KFileChooser extends JFileChooser {
241 249
     /** {@inheritDoc} */
242 250
     @Override
243 251
     public int showOpenDialog(final Component parent) throws HeadlessException {
244
-        if (!useKFileChooser(plugin)) {
252
+        if (!useKFileChooser(config, plugin)) {
245 253
             return super.showOpenDialog(parent);
246 254
         }
247 255
 
@@ -304,7 +312,7 @@ public final class KFileChooser extends JFileChooser {
304 312
     /** {@inheritDoc} */
305 313
     @Override
306 314
     public int showSaveDialog(final Component parent) throws HeadlessException {
307
-        if (!useKFileChooser(plugin)) {
315
+        if (!useKFileChooser(config, plugin)) {
308 316
             return super.showSaveDialog(parent);
309 317
         }
310 318
 

Loading…
Cancel
Save