Bläddra i källkod

Daggerify the DCC plugin.

Rename old DCCPlugin to DCCManager and inflate it using dagger.

Also remove unused method in OsdPlugin.

Change-Id: Ie8eb84b187ff9bc9379bdae41fcc4ecec85b6964
Depends-On: I99ebc7d10f558008a7889252cc3c96f39747303e
Reviewed-on: http://gerrit.dmdirc.com/2861
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 år sedan
förälder
incheckning
2e0a59b753

+ 4
- 2
src/com/dmdirc/addons/dcc/DCCCommand.java Visa fil

@@ -50,6 +50,7 @@ import com.dmdirc.ui.input.TabCompletionType;
50 50
 import java.io.File;
51 51
 import java.util.concurrent.Callable;
52 52
 
53
+import javax.inject.Inject;
53 54
 import javax.swing.JFileChooser;
54 55
 import javax.swing.JOptionPane;
55 56
 
@@ -64,7 +65,7 @@ public class DCCCommand extends Command implements IntelligentCommand {
64 65
             CommandType.TYPE_SERVER);
65 66
 
66 67
     /** My Plugin. */
67
-    private final DCCPlugin myPlugin;
68
+    private final DCCManager myPlugin;
68 69
     /** Main frame instance used as the parent for dialogs. */
69 70
     private final MainFrame mainFrame;
70 71
     /** Window management. */
@@ -81,10 +82,11 @@ public class DCCCommand extends Command implements IntelligentCommand {
81 82
      * @param messageSinkManager The sink manager to use to despatch messages.
82 83
      * @param windowManager Window management
83 84
      */
85
+    @Inject
84 86
     public DCCCommand(
85 87
             final CommandController controller,
86 88
             final MainFrame mainFrame,
87
-            final DCCPlugin plugin,
89
+            final DCCManager plugin,
88 90
             final MessageSinkManager messageSinkManager,
89 91
             final WindowManager windowManager) {
90 92
         super(controller);

+ 812
- 0
src/com/dmdirc/addons/dcc/DCCManager.java Visa fil

@@ -0,0 +1,812 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.dcc;
24
+
25
+import com.dmdirc.Server;
26
+import com.dmdirc.actions.ActionManager;
27
+import com.dmdirc.actions.CoreActionType;
28
+import com.dmdirc.addons.dcc.actions.DCCActions;
29
+import com.dmdirc.addons.dcc.io.DCC;
30
+import com.dmdirc.addons.dcc.io.DCCChat;
31
+import com.dmdirc.addons.dcc.io.DCCTransfer;
32
+import com.dmdirc.addons.dcc.kde.KFileChooser;
33
+import com.dmdirc.addons.ui_swing.SwingController;
34
+import com.dmdirc.addons.ui_swing.SwingWindowFactory;
35
+import com.dmdirc.addons.ui_swing.components.frames.ComponentFrame;
36
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
37
+import com.dmdirc.config.prefs.PreferencesCategory;
38
+import com.dmdirc.config.prefs.PreferencesDialogModel;
39
+import com.dmdirc.config.prefs.PreferencesSetting;
40
+import com.dmdirc.config.prefs.PreferencesType;
41
+import com.dmdirc.interfaces.ActionListener;
42
+import com.dmdirc.interfaces.CommandController;
43
+import com.dmdirc.interfaces.actions.ActionType;
44
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
45
+import com.dmdirc.interfaces.config.ConfigProvider;
46
+import com.dmdirc.interfaces.config.IdentityController;
47
+import com.dmdirc.logger.ErrorLevel;
48
+import com.dmdirc.logger.Logger;
49
+import com.dmdirc.messages.MessageSinkManager;
50
+import com.dmdirc.parser.interfaces.ClientInfo;
51
+import com.dmdirc.parser.interfaces.Parser;
52
+import com.dmdirc.plugins.PluginInfo;
53
+import com.dmdirc.ui.WindowManager;
54
+
55
+import java.io.File;
56
+import java.io.IOException;
57
+import java.net.InetAddress;
58
+import java.net.UnknownHostException;
59
+import java.util.Arrays;
60
+import java.util.HashSet;
61
+
62
+import javax.inject.Inject;
63
+import javax.inject.Singleton;
64
+import javax.swing.JFileChooser;
65
+import javax.swing.JOptionPane;
66
+
67
+import lombok.Getter;
68
+
69
+/**
70
+ * This plugin adds DCC to DMDirc.
71
+ */
72
+@Singleton
73
+public class DCCManager implements ActionListener {
74
+
75
+    /** Our DCC Container window. */
76
+    private PlaceholderContainer container;
77
+    /** This plugin's plugin info. */
78
+    private final PluginInfo pluginInfo;
79
+    /** Config manager to read settings from. */
80
+    private final AggregateConfigProvider config;
81
+    /** Parent swing controller. */
82
+    private final SwingController controller;
83
+    /** Identity controller to read settings from. */
84
+    private final IdentityController identityController;
85
+    /** The sink manager to use to despatch messages. */
86
+    private final MessageSinkManager messageSinkManager;
87
+    /** Window Management. */
88
+    private final WindowManager windowManager;
89
+    /** The command controller to use. */
90
+    private final CommandController commandController;
91
+    /** The configuration domain to use. */
92
+    @Getter
93
+    private final String domain;
94
+
95
+    /**
96
+     * Creates a new instance of this plugin.
97
+     *
98
+     * @param controller The controller to register UI implementations with
99
+     * @param pluginInfo This plugin's plugin info
100
+     * @param identityController The Identity controller that provides the current config
101
+     * @param commandController Command controller to register commands
102
+     * @param messageSinkManager The sink manager to use to despatch messages.
103
+     * @param windowManager Window Management
104
+     */
105
+    @Inject
106
+    public DCCManager(
107
+            final SwingController controller,
108
+            final PluginInfo pluginInfo,
109
+            final IdentityController identityController,
110
+            final CommandController commandController,
111
+            final MessageSinkManager messageSinkManager,
112
+            final WindowManager windowManager) {
113
+        this.identityController = identityController;
114
+        this.controller = controller;
115
+        this.messageSinkManager = messageSinkManager;
116
+        this.windowManager = windowManager;
117
+        this.commandController = commandController;
118
+        this.domain = pluginInfo.getDomain();
119
+        config = controller.getGlobalConfig();
120
+        this.pluginInfo = pluginInfo;
121
+        final SwingWindowFactory factory = controller.getWindowFactory();
122
+        factory.registerImplementation(new HashSet<>(Arrays.asList(
123
+                "com.dmdirc.addons.dcc.ui.PlaceholderPanel")),
124
+                ComponentFrame.class);
125
+        factory.registerImplementation(new HashSet<>(Arrays.asList(
126
+                "com.dmdirc.addons.dcc.ui.TransferPanel")),
127
+                ComponentFrame.class);
128
+
129
+        final ConfigProvider defaults = identityController.getAddonSettings();
130
+        defaults.setOption(getDomain(), "receive.savelocation",
131
+                identityController.getConfigurationDirectory() + "downloads"
132
+                + System.getProperty("file.separator"));
133
+    }
134
+
135
+    /**
136
+     * Ask a question, if the answer is the answer required, then recall
137
+     * handleProcessEvent.
138
+     *
139
+     * @param question Question to ask
140
+     * @param title Title of question dialog
141
+     * @param desiredAnswer Answer required
142
+     * @param type Actiontype to pass back
143
+     * @param format StringBuffer to pass back
144
+     * @param arguments arguments to pass back
145
+     */
146
+    public void askQuestion(final String question, final String title,
147
+            final int desiredAnswer, final ActionType type,
148
+            final StringBuffer format, final Object... arguments) {
149
+        // New thread to ask the question in to stop us locking the UI
150
+        new Thread(new Runnable() {
151
+
152
+            /** {@inheritDoc} */
153
+            @Override
154
+            public void run() {
155
+                final int result = JOptionPane.showConfirmDialog(null, question,
156
+                        title, JOptionPane.YES_NO_OPTION);
157
+                if (result == desiredAnswer) {
158
+                    handleProcessEvent(type, format, true, arguments);
159
+                }
160
+            }
161
+
162
+        }, "QuestionThread: " + title).start();
163
+    }
164
+
165
+    /**
166
+     * Ask the location to save a file, then start the download.
167
+     *
168
+     * @param nickname Person this dcc is from.
169
+     * @param send The DCCSend to save for.
170
+     * @param parser The parser this send was received on
171
+     * @param reverse Is this a reverse dcc?
172
+     * @param token Token used in reverse dcc.
173
+     */
174
+    public void saveFile(final String nickname, final DCCTransfer send,
175
+            final Parser parser, final boolean reverse, final String token) {
176
+        // New thread to ask the user where to save in to stop us locking the UI
177
+        new Thread(new Runnable() {
178
+
179
+            /** {@inheritDoc} */
180
+            @Override
181
+            public void run() {
182
+                final JFileChooser jc = KFileChooser.getFileChooser(config,
183
+                        DCCManager.this,
184
+                        config.getOption(getDomain(), "receive.savelocation"));
185
+                int result;
186
+                if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
187
+                    result = JFileChooser.APPROVE_OPTION;
188
+                } else {
189
+                    result = showFileChooser(send, jc);
190
+                }
191
+                if (result != JFileChooser.APPROVE_OPTION) {
192
+                    return;
193
+                }
194
+                send.setFileName(jc.getSelectedFile().getPath());
195
+                if (!handleExists(send, jc, nickname, parser,reverse, token)) {
196
+                    return;
197
+                }
198
+                final boolean resume = handleResume(jc);
199
+                if (reverse && !token.isEmpty()) {
200
+                    TransferContainer container = new TransferContainer(DCCManager.this, send,
201
+                            config, "*Receive: " + nickname, nickname, null);
202
+                    windowManager.addWindow(getContainer(), container);
203
+                    send.setToken(token);
204
+                    if (resume) {
205
+                        if (config.getOptionBool(getDomain(),
206
+                                "receive.reverse.sendtoken")) {
207
+                            parser.sendCTCP(nickname, "DCC", "RESUME "
208
+                                    + send.getShortFileName() + " 0 "
209
+                                    + jc.getSelectedFile().length() + " "
210
+                                    + token);
211
+                        } else {
212
+                            parser.sendCTCP(nickname, "DCC", "RESUME "
213
+                                    + send.getShortFileName() + " 0 "
214
+                                    + jc.getSelectedFile().length());
215
+                        }
216
+                    } else {
217
+                        if (listen(send)) {
218
+                            parser.sendCTCP(nickname, "DCC", "SEND "
219
+                                    + send.getShortFileName() + " "
220
+                                    + DCC.ipToLong(getListenIP(parser))
221
+                                    + " " + send.getPort() + " "
222
+                                    + send.getFileSize() + " " + token);
223
+                        }
224
+                    }
225
+                } else {
226
+                    TransferContainer container = new TransferContainer(DCCManager.this, send,
227
+                            config, "Receive: " + nickname, nickname, null);
228
+                    windowManager.addWindow(getContainer(), container);
229
+                    if (resume) {
230
+                        parser.sendCTCP(nickname, "DCC", "RESUME "
231
+                                + send.getShortFileName() + " "
232
+                                + send.getPort() + " "
233
+                                + jc.getSelectedFile().length());
234
+                    } else {
235
+                        send.connect();
236
+                    }
237
+                }
238
+            }
239
+
240
+        }, "saveFileThread: " + send.getShortFileName()).start();
241
+    }
242
+
243
+    /**
244
+     * Checks if the selected file exists and prompts the user as required.
245
+     *
246
+     * @param send DCC Transfer
247
+     * @param jc File chooser
248
+     * @param nickname Remote nickname
249
+     * @param parser Parser
250
+     * @param reverse Reverse DCC?
251
+     * @param token DCC token
252
+     *
253
+     * @return true if the user wants to continue, false if they wish to abort
254
+     */
255
+    private boolean handleExists(final DCCTransfer send, final JFileChooser jc,
256
+            final String nickname, final Parser parser, final boolean reverse,
257
+            final String token) {
258
+        if (jc.getSelectedFile().exists() && send.getFileSize() > -1
259
+                && send.getFileSize() <= jc.getSelectedFile().length()) {
260
+            if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
261
+                return false;
262
+            } else {
263
+                JOptionPane.showMessageDialog(controller.getMainFrame(),
264
+                        "This file has already "
265
+                        + "been completed, or is longer than the file you are "
266
+                        + "receiving.\nPlease choose a different file.",
267
+                        "Problem with selected file",
268
+                        JOptionPane.ERROR_MESSAGE);
269
+                saveFile(nickname, send, parser, reverse, token);
270
+                return false;
271
+            }
272
+        }
273
+        return true;
274
+    }
275
+
276
+    /**
277
+     * Prompts the user to resume a transfer if required.
278
+     *
279
+     * @param jc File chooser
280
+     *
281
+     * @return true if the user wants to continue the transfer false otherwise
282
+     */
283
+    private boolean handleResume(final JFileChooser jc) {
284
+        if (jc.getSelectedFile().exists()) {
285
+            if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
286
+                return true;
287
+            } else {
288
+                final int result = JOptionPane.showConfirmDialog(
289
+                        controller.getMainFrame(), "This file exists already"
290
+                        + ", do you want to resume an exisiting download?",
291
+                        "Resume Download?", JOptionPane.YES_NO_OPTION);
292
+                return (result == JOptionPane.YES_OPTION);
293
+            }
294
+        }
295
+        return false;
296
+    }
297
+
298
+    /**
299
+     * Sets up and display a file chooser.
300
+     *
301
+     * @param send DCCTransfer object sending the file
302
+     * @param jc File chooser
303
+     *
304
+     * @return   the return state of the file chooser on popdown:
305
+     * <ul>
306
+     * <li>JFileChooser.CANCEL_OPTION
307
+     * <li>JFileChooser.APPROVE_OPTION
308
+     * <li>JFileChooser.ERROR_OPTION if an error occurs or the
309
+     *                               dialog is dismissed
310
+     * </ul>
311
+     */
312
+    private int showFileChooser(final DCCTransfer send, final JFileChooser jc) {
313
+        jc.setDialogTitle("Save " + send.getShortFileName() + " As - DMDirc");
314
+                jc.setFileSelectionMode(JFileChooser.FILES_ONLY);
315
+                jc.setMultiSelectionEnabled(false);
316
+                jc.setSelectedFile(new File(send.getFileName()));
317
+        return jc.showSaveDialog(controller.getMainFrame());
318
+    }
319
+
320
+    /** {@inheritDoc} */
321
+    @Override
322
+    public void processEvent(final ActionType type, final StringBuffer format,
323
+            final Object... arguments) {
324
+        handleProcessEvent(type, format, false, arguments);
325
+    }
326
+
327
+    /**
328
+     * Make the given DCC start listening.
329
+     * This will either call dcc.listen() or dcc.listen(startPort, endPort)
330
+     * depending on config.
331
+     *
332
+     * @param dcc DCC to start listening.
333
+     * @return True if Socket was opened.
334
+     */
335
+    protected boolean listen(final DCC dcc) {
336
+        final boolean usePortRange = config.getOptionBool(getDomain(),
337
+                "firewall.ports.usePortRange");
338
+        try {
339
+            if (usePortRange) {
340
+                final int startPort = config.getOptionInt(getDomain(),
341
+                        "firewall.ports.startPort");
342
+                final int endPort = config.getOptionInt(getDomain(),
343
+                        "firewall.ports.endPort");
344
+                dcc.listen(startPort, endPort);
345
+            } else {
346
+                dcc.listen();
347
+            }
348
+            return true;
349
+        } catch (IOException ioe) {
350
+            return false;
351
+        }
352
+    }
353
+
354
+    /**
355
+     * Process an event of the specified type.
356
+     *
357
+     * @param type The type of the event to process
358
+     * @param format Format of messages that are about to be sent. (May be null)
359
+     * @param dontAsk Don't ask any questions, assume yes.
360
+     * @param arguments The arguments for the event
361
+     */
362
+    public void handleProcessEvent(final ActionType type,
363
+            final StringBuffer format, final boolean dontAsk,
364
+            final Object... arguments) {
365
+        if (config.getOptionBool(getDomain(), "receive.autoaccept") && !dontAsk) {
366
+            handleProcessEvent(type, format, true, arguments);
367
+            return;
368
+        }
369
+
370
+        if (type == CoreActionType.SERVER_CTCP) {
371
+            final String[] ctcpData = ((String) arguments[3]).split(" ");
372
+            if ("DCC".equalsIgnoreCase((String) arguments[2])) {
373
+                if ("chat".equalsIgnoreCase(ctcpData[0])
374
+                        && ctcpData.length > 3) {
375
+                    handleChat(type, format, dontAsk, ctcpData, arguments);
376
+                } else if ("send".equalsIgnoreCase(ctcpData[0])
377
+                        && ctcpData.length > 3) {
378
+                    handleSend(type, format, dontAsk, ctcpData, arguments);
379
+                } else if (("resume".equalsIgnoreCase(ctcpData[0])
380
+                        || "accept".equalsIgnoreCase(ctcpData[0]))
381
+                        && ctcpData.length > 2) {
382
+                    handleReceive(ctcpData, arguments);
383
+                }
384
+            }
385
+        }
386
+    }
387
+
388
+    /**
389
+     * Handles a DCC chat request.
390
+     *
391
+     * @param type The type of the event to process
392
+     * @param format Format of messages that are about to be sent. (May be null)
393
+     * @param dontAsk Don't ask any questions, assume yes.
394
+     * @param ctcpData CTCP data bits
395
+     * @param arguments The arguments for the event
396
+     */
397
+    private void handleChat(final ActionType type, final StringBuffer format,
398
+            final boolean dontAsk, final String[] ctcpData,
399
+            final Object... arguments) {
400
+        final String nickname = ((ClientInfo) arguments[1]).getNickname();
401
+        if (dontAsk) {
402
+            final DCCChat chat = new DCCChat();
403
+            try {
404
+                chat.setAddress(Long.parseLong(ctcpData[2]),
405
+                        Integer.parseInt(ctcpData[3]));
406
+            } catch (NumberFormatException nfe) {
407
+                return;
408
+            }
409
+            final String myNickname = ((Server) arguments[0]).getParser()
410
+                    .getLocalClient().getNickname();
411
+            final DCCFrameContainer f = new ChatContainer(chat, config, commandController,
412
+                    "Chat: " + nickname, myNickname, nickname, messageSinkManager);
413
+            windowManager.addWindow(getContainer(), f);
414
+            f.addLine("DCCChatStarting", nickname, chat.getHost(),
415
+                    chat.getPort());
416
+            chat.connect();
417
+        } else {
418
+            ActionManager.getActionManager().triggerEvent(
419
+                    DCCActions.DCC_CHAT_REQUEST, null, arguments[0],
420
+                    nickname);
421
+            askQuestion("User " + nickname + " on "
422
+                    + ((Server) arguments[0]).getName()
423
+                    + " would like to start a DCC Chat with you.\n\n"
424
+                    + "Do you want to continue?",
425
+                    "DCC Chat Request", JOptionPane.YES_OPTION,
426
+                    type, format, arguments);
427
+        }
428
+    }
429
+
430
+    /**
431
+     * Handles a DCC send request.
432
+     *
433
+     * @param type The type of the event to process
434
+     * @param format Format of messages that are about to be sent. (May be null)
435
+     * @param dontAsk Don't ask any questions, assume yes.
436
+     * @param ctcpData CTCP data bits
437
+     * @param arguments The arguments for the event
438
+     */
439
+    private void handleSend(final ActionType type, final StringBuffer format,
440
+            final boolean dontAsk, final String[] ctcpData,
441
+            final Object... arguments) {
442
+        final String nickname = ((ClientInfo) arguments[1]).getNickname();
443
+        final String filename;
444
+        String tmpFilename;
445
+        // Clients tend to put files with spaces in the name in ""
446
+        final StringBuilder filenameBits = new StringBuilder();
447
+        int i;
448
+        final boolean quoted = ctcpData[1].startsWith("\"");
449
+        if (quoted) {
450
+            for (i = 1; i < ctcpData.length; i++) {
451
+                String bit = ctcpData[i];
452
+                if (i == 1) {
453
+                    bit = bit.substring(1);
454
+                }
455
+                if (bit.endsWith("\"")) {
456
+                    filenameBits.append(" ")
457
+                            .append(bit.substring(0, bit.length() - 1));
458
+                    break;
459
+                } else {
460
+                    filenameBits.append(" ").append(bit);
461
+                }
462
+            }
463
+            tmpFilename = filenameBits.toString().trim();
464
+        } else {
465
+            tmpFilename = ctcpData[1];
466
+            i = 1;
467
+        }
468
+
469
+        // Try to remove path names if sent.
470
+        // Change file separatorChar from other OSs first
471
+        if (File.separatorChar == '/') {
472
+            tmpFilename = tmpFilename.replace('\\', File.separatorChar);
473
+        } else {
474
+            tmpFilename = tmpFilename.replace('/', File.separatorChar);
475
+        }
476
+        // Then get just the name of the file.
477
+        filename = new File(tmpFilename).getName();
478
+
479
+        final String ip = ctcpData[++i];
480
+        final String port = ctcpData[++i];
481
+        long size;
482
+        if (ctcpData.length + 1 > i) {
483
+            try {
484
+                size = Integer.parseInt(ctcpData[++i]);
485
+            } catch (NumberFormatException nfe) {
486
+                size = -1;
487
+            }
488
+        } else {
489
+            size = -1;
490
+        }
491
+        final String token = (ctcpData.length - 1 > i
492
+                && !ctcpData[i + 1].equals("T")) ? ctcpData[++i] : "";
493
+
494
+        // Ignore incorrect ports, or non-numeric IP/Port
495
+        try {
496
+            final int portInt = Integer.parseInt(port);
497
+            if (portInt > 65535 || portInt < 0) {
498
+                return;
499
+            }
500
+            Long.parseLong(ip);
501
+        } catch (NumberFormatException nfe) {
502
+            return;
503
+        }
504
+
505
+        DCCTransfer send = DCCTransfer.findByToken(token);
506
+
507
+        if (send == null && !dontAsk) {
508
+            if (!token.isEmpty() && !port.equals("0")) {
509
+                // This is a reverse DCC Send that we no longer care about.
510
+            } else {
511
+                ActionManager.getActionManager().triggerEvent(
512
+                        DCCActions.DCC_SEND_REQUEST, null,
513
+                        arguments[0], nickname, filename);
514
+                askQuestion("User " + nickname + " on "
515
+                        + ((Server) arguments[0]).getName()
516
+                        + " would like to send you a file over DCC.\n\nFile: "
517
+                        + filename + "\n\nDo you want to continue?",
518
+                        "DCC Send Request", JOptionPane.YES_OPTION, type,
519
+                        format, arguments);
520
+            }
521
+        } else {
522
+            final boolean newSend = send == null;
523
+            if (newSend) {
524
+                send = new DCCTransfer(config.getOptionInt(getDomain(),
525
+                        "send.blocksize"));
526
+                send.setTurbo(config.getOptionBool(getDomain(), "send.forceturbo"));
527
+            }
528
+            try {
529
+                send.setAddress(Long.parseLong(ip), Integer.parseInt(port));
530
+            } catch (NumberFormatException nfe) {
531
+                return;
532
+            }
533
+            if (newSend) {
534
+                send.setFileName(filename);
535
+                send.setFileSize(size);
536
+                saveFile(nickname, send, ((Server) arguments[0]).getParser(),
537
+                        "0".equals(port), token);
538
+            } else {
539
+                send.connect();
540
+            }
541
+        }
542
+    }
543
+
544
+    /**
545
+     * Handles a DCC chat request.
546
+     *
547
+     * @param ctcpData CTCP data bits
548
+     * @param arguments The arguments for the event
549
+     */
550
+    private void handleReceive(final String[] ctcpData,
551
+            final Object... arguments) {
552
+        final String filename;
553
+        // Clients tend to put files with spaces in the name in ""
554
+        final StringBuilder filenameBits = new StringBuilder();
555
+        int i;
556
+        final boolean quoted = ctcpData[1].startsWith("\"");
557
+        if (quoted) {
558
+            for (i = 1; i < ctcpData.length; i++) {
559
+                String bit = ctcpData[i];
560
+                if (i == 1) {
561
+                    bit = bit.substring(1);
562
+                }
563
+                if (bit.endsWith("\"")) {
564
+                    filenameBits.append(" ")
565
+                            .append(bit.substring(0, bit.length() - 1));
566
+                    break;
567
+                } else {
568
+                    filenameBits.append(" ").append(bit);
569
+                }
570
+            }
571
+            filename = filenameBits.toString().trim();
572
+        } else {
573
+            filename = ctcpData[1];
574
+            i = 1;
575
+        }
576
+
577
+        final int port;
578
+        final int position;
579
+        try {
580
+            port = Integer.parseInt(ctcpData[++i]);
581
+            position = Integer.parseInt(ctcpData[++i]);
582
+            } catch (NumberFormatException nfe) {
583
+                return;
584
+        }
585
+        final String token = (ctcpData.length - 1 > i) ? " "
586
+                + ctcpData[++i] : "";
587
+
588
+        // Now look for a dcc that matches.
589
+        for (DCCTransfer send : DCCTransfer.getTransfers()) {
590
+            if (send.getPort() == port && (new File(send.getFileName()))
591
+                    .getName().equalsIgnoreCase(filename)) {
592
+                if ((!token.isEmpty() && !send.getToken().isEmpty())
593
+                        && (!token.equals(send.getToken()))) {
594
+                    continue;
595
+                }
596
+                final Parser parser = ((Server) arguments[0]).getParser();
597
+                final String nick = ((ClientInfo) arguments[1]).getNickname();
598
+                if (ctcpData[0].equalsIgnoreCase("resume")) {
599
+                    parser.sendCTCP(nick, "DCC", "ACCEPT "+ ((quoted) ? "\""
600
+                            + filename + "\"" : filename) + " " + port + " "
601
+                            + send.setFileStart(position) + token);
602
+                } else {
603
+                    send.setFileStart(position);
604
+                    if (port == 0) {
605
+                        // Reverse dcc
606
+                        if (listen(send)) {
607
+                            if (send.getToken().isEmpty()) {
608
+                                parser.sendCTCP(nick, "DCC", "SEND "
609
+                                        + ((quoted) ? "\"" + filename
610
+                                        + "\"" : filename) + " "
611
+                                        + DCC.ipToLong(send.getHost())
612
+                                        + " " + send.getPort()
613
+                                        + " " + send.getFileSize());
614
+                            } else {
615
+                                parser.sendCTCP(nick, "DCC", "SEND "
616
+                                        + ((quoted) ? "\"" + filename
617
+                                        + "\"" : filename)
618
+                                        + " " + DCC.ipToLong(send.getHost())
619
+                                        + " " + send.getPort()
620
+                                        + " " + send.getFileSize() + " "
621
+                                        + send.getToken());
622
+                            }
623
+                        }
624
+                    } else {
625
+                        send.connect();
626
+                    }
627
+                }
628
+            }
629
+        }
630
+    }
631
+
632
+
633
+
634
+    /**
635
+     * Retrieves the container for the placeholder.
636
+     *
637
+     * @since 0.6.4
638
+     * @return This plugin's placeholder container
639
+     */
640
+    public synchronized PlaceholderContainer getContainer() {
641
+        if (container == null) {
642
+            createContainer();
643
+        }
644
+
645
+        return container;
646
+    }
647
+
648
+    /**
649
+     * Removes the cached container.
650
+     *
651
+     * @since 0.6.4
652
+     */
653
+    public synchronized void removeContainer() {
654
+        container = null;
655
+    }
656
+
657
+    /**
658
+     * Create the container window.
659
+     */
660
+    protected void createContainer() {
661
+        container = new PlaceholderContainer(this, config, controller);
662
+        windowManager.addWindow(container);
663
+    }
664
+
665
+    /**
666
+     * Called when the plugin is loaded.
667
+     */
668
+    public void onLoad() {
669
+        final File dir = new File(config.getOption(getDomain(),
670
+                "receive.savelocation"));
671
+        if (dir.exists()) {
672
+            if (!dir.isDirectory()) {
673
+                Logger.userError(ErrorLevel.LOW,
674
+                        "Unable to create download dir (file exists instead)");
675
+            }
676
+        } else {
677
+            try {
678
+                dir.mkdirs();
679
+                dir.createNewFile();
680
+            } catch (IOException ex) {
681
+                Logger.userError(ErrorLevel.LOW,
682
+                        "Unable to create download dir");
683
+            }
684
+        }
685
+
686
+        ActionManager.getActionManager().registerTypes(DCCActions.values());
687
+        ActionManager.getActionManager().registerListener(this,
688
+                CoreActionType.SERVER_CTCP);
689
+    }
690
+
691
+    /**
692
+     * Called when this plugin is Unloaded.
693
+     */
694
+    public synchronized void onUnload() {
695
+        ActionManager.getActionManager().unregisterListener(this);
696
+        if (container != null) {
697
+            container.close();
698
+        }
699
+    }
700
+
701
+    /**
702
+     * Get the IP Address we should send as our listening IP.
703
+     *
704
+     * @return The IP Address we should send as our listening IP.
705
+     */
706
+    public String getListenIP() {
707
+        return getListenIP(null);
708
+    }
709
+
710
+    /**
711
+     * Get the IP Address we should send as our listening IP.
712
+     *
713
+     * @param parser Parser the IRC Parser where this dcc is initiated
714
+     * @return The IP Address we should send as our listening IP.
715
+     */
716
+    public String getListenIP(final Parser parser) {
717
+        final String configIP = config.getOption(getDomain(), "firewall.ip");
718
+        if (!configIP.isEmpty()) {
719
+            try {
720
+                return InetAddress.getByName(configIP).getHostAddress();
721
+            } catch (UnknownHostException ex) { //NOPMD - handled below
722
+                //Continue below
723
+            }
724
+        }
725
+        if (parser != null) {
726
+            final String myHost = parser.getLocalClient().getHostname();
727
+            if (!myHost.isEmpty()) {
728
+                try {
729
+                    return InetAddress.getByName(myHost).getHostAddress();
730
+                } catch (UnknownHostException e) { //NOPMD - handled below
731
+                    //Continue below
732
+                }
733
+            }
734
+        }
735
+        try {
736
+            return InetAddress.getLocalHost().getHostAddress();
737
+        } catch (UnknownHostException e) {
738
+            // This is almost certainly not what we want, but we can't work out
739
+            // the right one.
740
+            return "127.0.0.1"; //NOPMD
741
+        }
742
+    }
743
+
744
+    /**
745
+     * Adds configuration options for the DCC plugin.
746
+     *
747
+     * @param manager The model to add options to.
748
+     */
749
+    public void showConfig(final PreferencesDialogModel manager) {
750
+        final PreferencesCategory general = new PluginPreferencesCategory(
751
+                pluginInfo, "DCC", "", "category-dcc");
752
+        final PreferencesCategory firewall = new PluginPreferencesCategory(
753
+                pluginInfo, "Firewall", "");
754
+        final PreferencesCategory sending = new PluginPreferencesCategory(
755
+                pluginInfo, "Sending", "");
756
+        final PreferencesCategory receiving = new PluginPreferencesCategory(
757
+                pluginInfo, "Receiving", "");
758
+
759
+        manager.getCategory("Plugins").addSubCategory(general.setInlineAfter());
760
+        general.addSubCategory(firewall.setInline());
761
+        general.addSubCategory(sending.setInline());
762
+        general.addSubCategory(receiving.setInline());
763
+
764
+        firewall.addSetting(new PreferencesSetting(PreferencesType.TEXT,
765
+                getDomain(), "firewall.ip", "Forced IP",
766
+                "What IP should be sent as our IP (Blank = work it out)",
767
+                manager.getConfigManager(), manager.getIdentity()));
768
+        firewall.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
769
+                getDomain(), "firewall.ports.usePortRange", "Use Port Range",
770
+                "Useful if you have a firewall that only forwards specific "
771
+                + "ports", manager.getConfigManager(), manager.getIdentity()));
772
+        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
773
+                getDomain(), "firewall.ports.startPort", "Start Port",
774
+                "Port to try to listen on first", manager.getConfigManager(),
775
+                manager.getIdentity()));
776
+        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
777
+                getDomain(), "firewall.ports.endPort", "End Port",
778
+                "Port to try to listen on last", manager.getConfigManager(),
779
+                manager.getIdentity()));
780
+        receiving.addSetting(new PreferencesSetting(PreferencesType.DIRECTORY,
781
+                getDomain(), "receive.savelocation", "Default save location",
782
+                "Where the save as window defaults to?",
783
+                manager.getConfigManager(), manager.getIdentity()));
784
+        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
785
+                getDomain(), "send.reverse", "Reverse DCC",
786
+                "With reverse DCC, the sender connects rather than "
787
+                + "listens like normal dcc", manager.getConfigManager(),
788
+                manager.getIdentity()));
789
+        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
790
+                getDomain(), "send.forceturbo", "Use Turbo DCC",
791
+                "Turbo DCC doesn't wait for ack packets. this is "
792
+                + "faster but not always supported.",
793
+                manager.getConfigManager(), manager.getIdentity()));
794
+        receiving.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
795
+                getDomain(), "receive.reverse.sendtoken",
796
+                "Send token in reverse receive",
797
+                "If you have problems with reverse dcc receive resume,"
798
+                + " try toggling this.", manager.getConfigManager(),
799
+                manager.getIdentity()));
800
+        general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
801
+                getDomain(), "send.blocksize", "Blocksize to use for DCC",
802
+                "Change the block size for send/receive, this can "
803
+                + "sometimes speed up transfers.", manager.getConfigManager(),
804
+                manager.getIdentity()));
805
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
806
+                getDomain(), "general.percentageInTitle",
807
+                "Show percentage of transfers in the window title",
808
+                "Show the current percentage of transfers in the DCC window "
809
+                + "title", manager.getConfigManager(), manager.getIdentity()));
810
+    }
811
+
812
+}

+ 14
- 756
src/com/dmdirc/addons/dcc/DCCPlugin.java Visa fil

@@ -22,789 +22,47 @@
22 22
 
23 23
 package com.dmdirc.addons.dcc;
24 24
 
25
-import com.dmdirc.Server;
26
-import com.dmdirc.actions.ActionManager;
27
-import com.dmdirc.actions.CoreActionType;
28
-import com.dmdirc.addons.dcc.actions.DCCActions;
29
-import com.dmdirc.addons.dcc.io.DCC;
30
-import com.dmdirc.addons.dcc.io.DCCChat;
31
-import com.dmdirc.addons.dcc.io.DCCTransfer;
32
-import com.dmdirc.addons.dcc.kde.KFileChooser;
33
-import com.dmdirc.addons.ui_swing.SwingController;
34
-import com.dmdirc.addons.ui_swing.SwingWindowFactory;
35
-import com.dmdirc.addons.ui_swing.components.frames.ComponentFrame;
36
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
37
-import com.dmdirc.config.prefs.PreferencesCategory;
38 25
 import com.dmdirc.config.prefs.PreferencesDialogModel;
39
-import com.dmdirc.config.prefs.PreferencesSetting;
40
-import com.dmdirc.config.prefs.PreferencesType;
41
-import com.dmdirc.interfaces.ActionListener;
42
-import com.dmdirc.interfaces.CommandController;
43
-import com.dmdirc.interfaces.actions.ActionType;
44
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
45
-import com.dmdirc.interfaces.config.ConfigProvider;
46
-import com.dmdirc.interfaces.config.IdentityController;
47
-import com.dmdirc.logger.ErrorLevel;
48
-import com.dmdirc.logger.Logger;
49
-import com.dmdirc.messages.MessageSinkManager;
50
-import com.dmdirc.parser.interfaces.ClientInfo;
51
-import com.dmdirc.parser.interfaces.Parser;
52 26
 import com.dmdirc.plugins.PluginInfo;
53 27
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
54
-import com.dmdirc.ui.WindowManager;
55 28
 
56
-import java.io.File;
57
-import java.io.IOException;
58
-import java.net.InetAddress;
59
-import java.net.UnknownHostException;
60
-import java.util.Arrays;
61
-import java.util.HashSet;
62
-
63
-import javax.swing.JFileChooser;
64
-import javax.swing.JOptionPane;
29
+import dagger.ObjectGraph;
65 30
 
66 31
 /**
67
- * This plugin adds DCC to DMDirc.
32
+ * Adds support for DCC transfers and chats.
68 33
  */
69
-public class DCCPlugin extends BaseCommandPlugin implements ActionListener {
70
-
71
-    /** Our DCC Container window. */
72
-    private PlaceholderContainer container;
73
-    /** This plugin's plugin info. */
74
-    private final PluginInfo pluginInfo;
75
-    /** Config manager to read settings from. */
76
-    private final AggregateConfigProvider config;
77
-    /** Parent swing controller. */
78
-    private final SwingController controller;
79
-    /** Identity controller to read settings from. */
80
-    private final IdentityController identityController;
81
-    /** The sink manager to use to despatch messages. */
82
-    private final MessageSinkManager messageSinkManager;
83
-    /** Window Management. */
84
-    private final WindowManager windowManager;
85
-
86
-    /**
87
-     * Creates a new instance of this plugin.
88
-     *
89
-     * @param controller The controller to register UI implementations with
90
-     * @param pluginInfo This plugin's plugin info
91
-     * @param identityController The Identity controller that provides the current config
92
-     * @param commandController Command controller to register commands
93
-     * @param messageSinkManager The sink manager to use to despatch messages.
94
-     * @param windowManager Window Management
95
-     */
96
-    public DCCPlugin(
97
-            final SwingController controller,
98
-            final PluginInfo pluginInfo,
99
-            final IdentityController identityController,
100
-            final CommandController commandController,
101
-            final MessageSinkManager messageSinkManager,
102
-            final WindowManager windowManager) {
103
-        super(commandController);
104
-        this.identityController = identityController;
105
-        this.controller = controller;
106
-        this.messageSinkManager = messageSinkManager;
107
-        this.windowManager = windowManager;
108
-        config = controller.getGlobalConfig();
109
-        this.pluginInfo = pluginInfo;
110
-        registerCommand(new DCCCommand(
111
-                commandController, controller.getMainFrame(), this,
112
-                messageSinkManager, windowManager), DCCCommand.INFO);
113
-        final SwingWindowFactory factory = controller.getWindowFactory();
114
-        factory.registerImplementation(new HashSet<>(Arrays.asList(
115
-                "com.dmdirc.addons.dcc.ui.PlaceholderPanel")),
116
-                ComponentFrame.class);
117
-        factory.registerImplementation(new HashSet<>(Arrays.asList(
118
-                "com.dmdirc.addons.dcc.ui.TransferPanel")),
119
-                ComponentFrame.class);
120
-    }
121
-
122
-    /**
123
-     * Ask a question, if the answer is the answer required, then recall
124
-     * handleProcessEvent.
125
-     *
126
-     * @param question Question to ask
127
-     * @param title Title of question dialog
128
-     * @param desiredAnswer Answer required
129
-     * @param type Actiontype to pass back
130
-     * @param format StringBuffer to pass back
131
-     * @param arguments arguments to pass back
132
-     */
133
-    public void askQuestion(final String question, final String title,
134
-            final int desiredAnswer, final ActionType type,
135
-            final StringBuffer format, final Object... arguments) {
136
-        // New thread to ask the question in to stop us locking the UI
137
-        new Thread(new Runnable() {
138
-
139
-            /** {@inheritDoc} */
140
-            @Override
141
-            public void run() {
142
-                final int result = JOptionPane.showConfirmDialog(null, question,
143
-                        title, JOptionPane.YES_NO_OPTION);
144
-                if (result == desiredAnswer) {
145
-                    handleProcessEvent(type, format, true, arguments);
146
-                }
147
-            }
148
-
149
-        }, "QuestionThread: " + title).start();
150
-    }
151
-
152
-    /**
153
-     * Ask the location to save a file, then start the download.
154
-     *
155
-     * @param nickname Person this dcc is from.
156
-     * @param send The DCCSend to save for.
157
-     * @param parser The parser this send was received on
158
-     * @param reverse Is this a reverse dcc?
159
-     * @param token Token used in reverse dcc.
160
-     */
161
-    public void saveFile(final String nickname, final DCCTransfer send,
162
-            final Parser parser, final boolean reverse, final String token) {
163
-        // New thread to ask the user where to save in to stop us locking the UI
164
-        new Thread(new Runnable() {
165
-
166
-            /** {@inheritDoc} */
167
-            @Override
168
-            public void run() {
169
-                final JFileChooser jc = KFileChooser.getFileChooser(config,
170
-                        DCCPlugin.this,
171
-                        config.getOption(getDomain(), "receive.savelocation"));
172
-                int result;
173
-                if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
174
-                    result = JFileChooser.APPROVE_OPTION;
175
-                } else {
176
-                    result = showFileChooser(send, jc);
177
-                }
178
-                if (result != JFileChooser.APPROVE_OPTION) {
179
-                    return;
180
-                }
181
-                send.setFileName(jc.getSelectedFile().getPath());
182
-                if (!handleExists(send, jc, nickname, parser,reverse, token)) {
183
-                    return;
184
-                }
185
-                final boolean resume = handleResume(jc);
186
-                if (reverse && !token.isEmpty()) {
187
-                    TransferContainer container = new TransferContainer(DCCPlugin.this, send,
188
-                            config, "*Receive: " + nickname, nickname, null);
189
-                    windowManager.addWindow(getContainer(), container);
190
-                    send.setToken(token);
191
-                    if (resume) {
192
-                        if (config.getOptionBool(getDomain(),
193
-                                "receive.reverse.sendtoken")) {
194
-                            parser.sendCTCP(nickname, "DCC", "RESUME "
195
-                                    + send.getShortFileName() + " 0 "
196
-                                    + jc.getSelectedFile().length() + " "
197
-                                    + token);
198
-                        } else {
199
-                            parser.sendCTCP(nickname, "DCC", "RESUME "
200
-                                    + send.getShortFileName() + " 0 "
201
-                                    + jc.getSelectedFile().length());
202
-                        }
203
-                    } else {
204
-                        if (listen(send)) {
205
-                            parser.sendCTCP(nickname, "DCC", "SEND "
206
-                                    + send.getShortFileName() + " "
207
-                                    + DCC.ipToLong(getListenIP(parser))
208
-                                    + " " + send.getPort() + " "
209
-                                    + send.getFileSize() + " " + token);
210
-                        }
211
-                    }
212
-                } else {
213
-                    TransferContainer container = new TransferContainer(DCCPlugin.this, send,
214
-                            config, "Receive: " + nickname, nickname, null);
215
-                    windowManager.addWindow(getContainer(), container);
216
-                    if (resume) {
217
-                        parser.sendCTCP(nickname, "DCC", "RESUME "
218
-                                + send.getShortFileName() + " "
219
-                                + send.getPort() + " "
220
-                                + jc.getSelectedFile().length());
221
-                    } else {
222
-                        send.connect();
223
-                    }
224
-                }
225
-            }
226
-
227
-        }, "saveFileThread: " + send.getShortFileName()).start();
228
-    }
229
-
230
-    /**
231
-     * Checks if the selected file exists and prompts the user as required.
232
-     *
233
-     * @param send DCC Transfer
234
-     * @param jc File chooser
235
-     * @param nickname Remote nickname
236
-     * @param parser Parser
237
-     * @param reverse Reverse DCC?
238
-     * @param token DCC token
239
-     *
240
-     * @return true if the user wants to continue, false if they wish to abort
241
-     */
242
-    private boolean handleExists(final DCCTransfer send, final JFileChooser jc,
243
-            final String nickname, final Parser parser, final boolean reverse,
244
-            final String token) {
245
-        if (jc.getSelectedFile().exists() && send.getFileSize() > -1
246
-                && send.getFileSize() <= jc.getSelectedFile().length()) {
247
-            if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
248
-                return false;
249
-            } else {
250
-                JOptionPane.showMessageDialog(controller.getMainFrame(),
251
-                        "This file has already "
252
-                        + "been completed, or is longer than the file you are "
253
-                        + "receiving.\nPlease choose a different file.",
254
-                        "Problem with selected file",
255
-                        JOptionPane.ERROR_MESSAGE);
256
-                saveFile(nickname, send, parser, reverse, token);
257
-                return false;
258
-            }
259
-        }
260
-        return true;
261
-    }
34
+public class DCCPlugin extends BaseCommandPlugin {
262 35
 
263
-    /**
264
-     * Prompts the user to resume a transfer if required.
265
-     *
266
-     * @param jc File chooser
267
-     *
268
-     * @return true if the user wants to continue the transfer false otherwise
269
-     */
270
-    private boolean handleResume(final JFileChooser jc) {
271
-        if (jc.getSelectedFile().exists()) {
272
-            if (config.getOptionBool(getDomain(), "receive.autoaccept")) {
273
-                return true;
274
-            } else {
275
-                final int result = JOptionPane.showConfirmDialog(
276
-                        controller.getMainFrame(), "This file exists already"
277
-                        + ", do you want to resume an exisiting download?",
278
-                        "Resume Download?", JOptionPane.YES_NO_OPTION);
279
-                return (result == JOptionPane.YES_OPTION);
280
-            }
281
-        }
282
-        return false;
283
-    }
284
-
285
-    /**
286
-     * Sets up and display a file chooser.
287
-     *
288
-     * @param send DCCTransfer object sending the file
289
-     * @param jc File chooser
290
-     *
291
-     * @return   the return state of the file chooser on popdown:
292
-     * <ul>
293
-     * <li>JFileChooser.CANCEL_OPTION
294
-     * <li>JFileChooser.APPROVE_OPTION
295
-     * <li>JFileChooser.ERROR_OPTION if an error occurs or the
296
-     *                               dialog is dismissed
297
-     * </ul>
298
-     */
299
-    private int showFileChooser(final DCCTransfer send, final JFileChooser jc) {
300
-        jc.setDialogTitle("Save " + send.getShortFileName() + " As - DMDirc");
301
-                jc.setFileSelectionMode(JFileChooser.FILES_ONLY);
302
-                jc.setMultiSelectionEnabled(false);
303
-                jc.setSelectedFile(new File(send.getFileName()));
304
-        return jc.showSaveDialog(controller.getMainFrame());
305
-    }
36
+    private DCCManager dccManager;
306 37
 
307 38
     /** {@inheritDoc} */
308 39
     @Override
309
-    public void processEvent(final ActionType type, final StringBuffer format,
310
-            final Object... arguments) {
311
-        handleProcessEvent(type, format, false, arguments);
312
-    }
313
-
314
-    /**
315
-     * Make the given DCC start listening.
316
-     * This will either call dcc.listen() or dcc.listen(startPort, endPort)
317
-     * depending on config.
318
-     *
319
-     * @param dcc DCC to start listening.
320
-     * @return True if Socket was opened.
321
-     */
322
-    protected boolean listen(final DCC dcc) {
323
-        final boolean usePortRange = config.getOptionBool(getDomain(),
324
-                "firewall.ports.usePortRange");
325
-        try {
326
-            if (usePortRange) {
327
-                final int startPort = config.getOptionInt(getDomain(),
328
-                        "firewall.ports.startPort");
329
-                final int endPort = config.getOptionInt(getDomain(),
330
-                        "firewall.ports.endPort");
331
-                dcc.listen(startPort, endPort);
332
-            } else {
333
-                dcc.listen();
334
-            }
335
-            return true;
336
-        } catch (IOException ioe) {
337
-            return false;
338
-        }
339
-    }
340
-
341
-    /**
342
-     * Process an event of the specified type.
343
-     *
344
-     * @param type The type of the event to process
345
-     * @param format Format of messages that are about to be sent. (May be null)
346
-     * @param dontAsk Don't ask any questions, assume yes.
347
-     * @param arguments The arguments for the event
348
-     */
349
-    public void handleProcessEvent(final ActionType type,
350
-            final StringBuffer format, final boolean dontAsk,
351
-            final Object... arguments) {
352
-        if (config.getOptionBool(getDomain(), "receive.autoaccept") && !dontAsk) {
353
-            handleProcessEvent(type, format, true, arguments);
354
-            return;
355
-        }
40
+    public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
41
+        super.load(pluginInfo, graph);
356 42
 
357
-        if (type == CoreActionType.SERVER_CTCP) {
358
-            final String[] ctcpData = ((String) arguments[3]).split(" ");
359
-            if ("DCC".equalsIgnoreCase((String) arguments[2])) {
360
-                if ("chat".equalsIgnoreCase(ctcpData[0])
361
-                        && ctcpData.length > 3) {
362
-                    handleChat(type, format, dontAsk, ctcpData, arguments);
363
-                } else if ("send".equalsIgnoreCase(ctcpData[0])
364
-                        && ctcpData.length > 3) {
365
-                    handleSend(type, format, dontAsk, ctcpData, arguments);
366
-                } else if (("resume".equalsIgnoreCase(ctcpData[0])
367
-                        || "accept".equalsIgnoreCase(ctcpData[0]))
368
-                        && ctcpData.length > 2) {
369
-                    handleReceive(ctcpData, arguments);
370
-                }
371
-            }
372
-        }
373
-    }
374
-
375
-    /**
376
-     * Handles a DCC chat request.
377
-     *
378
-     * @param type The type of the event to process
379
-     * @param format Format of messages that are about to be sent. (May be null)
380
-     * @param dontAsk Don't ask any questions, assume yes.
381
-     * @param ctcpData CTCP data bits
382
-     * @param arguments The arguments for the event
383
-     */
384
-    private void handleChat(final ActionType type, final StringBuffer format,
385
-            final boolean dontAsk, final String[] ctcpData,
386
-            final Object... arguments) {
387
-        final String nickname = ((ClientInfo) arguments[1]).getNickname();
388
-        if (dontAsk) {
389
-            final DCCChat chat = new DCCChat();
390
-            try {
391
-                chat.setAddress(Long.parseLong(ctcpData[2]),
392
-                        Integer.parseInt(ctcpData[3]));
393
-            } catch (NumberFormatException nfe) {
394
-                return;
395
-            }
396
-            final String myNickname = ((Server) arguments[0]).getParser()
397
-                    .getLocalClient().getNickname();
398
-            final DCCFrameContainer f = new ChatContainer(chat, config, getCommandController(),
399
-                    "Chat: " + nickname, myNickname, nickname, messageSinkManager);
400
-            windowManager.addWindow(getContainer(), f);
401
-            f.addLine("DCCChatStarting", nickname, chat.getHost(),
402
-                    chat.getPort());
403
-            chat.connect();
404
-        } else {
405
-            ActionManager.getActionManager().triggerEvent(
406
-                    DCCActions.DCC_CHAT_REQUEST, null, arguments[0],
407
-                    nickname);
408
-            askQuestion("User " + nickname + " on "
409
-                    + ((Server) arguments[0]).getName()
410
-                    + " would like to start a DCC Chat with you.\n\n"
411
-                    + "Do you want to continue?",
412
-                    "DCC Chat Request", JOptionPane.YES_OPTION,
413
-                    type, format, arguments);
414
-        }
415
-    }
416
-
417
-    /**
418
-     * Handles a DCC send request.
419
-     *
420
-     * @param type The type of the event to process
421
-     * @param format Format of messages that are about to be sent. (May be null)
422
-     * @param dontAsk Don't ask any questions, assume yes.
423
-     * @param ctcpData CTCP data bits
424
-     * @param arguments The arguments for the event
425
-     */
426
-    private void handleSend(final ActionType type, final StringBuffer format,
427
-            final boolean dontAsk, final String[] ctcpData,
428
-            final Object... arguments) {
429
-        final String nickname = ((ClientInfo) arguments[1]).getNickname();
430
-        final String filename;
431
-        String tmpFilename;
432
-        // Clients tend to put files with spaces in the name in ""
433
-        final StringBuilder filenameBits = new StringBuilder();
434
-        int i;
435
-        final boolean quoted = ctcpData[1].startsWith("\"");
436
-        if (quoted) {
437
-            for (i = 1; i < ctcpData.length; i++) {
438
-                String bit = ctcpData[i];
439
-                if (i == 1) {
440
-                    bit = bit.substring(1);
441
-                }
442
-                if (bit.endsWith("\"")) {
443
-                    filenameBits.append(" ")
444
-                            .append(bit.substring(0, bit.length() - 1));
445
-                    break;
446
-                } else {
447
-                    filenameBits.append(" ").append(bit);
448
-                }
449
-            }
450
-            tmpFilename = filenameBits.toString().trim();
451
-        } else {
452
-            tmpFilename = ctcpData[1];
453
-            i = 1;
454
-        }
455
-
456
-        // Try to remove path names if sent.
457
-        // Change file separatorChar from other OSs first
458
-        if (File.separatorChar == '/') {
459
-            tmpFilename = tmpFilename.replace('\\', File.separatorChar);
460
-        } else {
461
-            tmpFilename = tmpFilename.replace('/', File.separatorChar);
462
-        }
463
-        // Then get just the name of the file.
464
-        filename = new File(tmpFilename).getName();
465
-
466
-        final String ip = ctcpData[++i];
467
-        final String port = ctcpData[++i];
468
-        long size;
469
-        if (ctcpData.length + 1 > i) {
470
-            try {
471
-                size = Integer.parseInt(ctcpData[++i]);
472
-            } catch (NumberFormatException nfe) {
473
-                size = -1;
474
-            }
475
-        } else {
476
-            size = -1;
477
-        }
478
-        final String token = (ctcpData.length - 1 > i
479
-                && !ctcpData[i + 1].equals("T")) ? ctcpData[++i] : "";
480
-
481
-        // Ignore incorrect ports, or non-numeric IP/Port
482
-        try {
483
-            final int portInt = Integer.parseInt(port);
484
-            if (portInt > 65535 || portInt < 0) {
485
-                return;
486
-            }
487
-            Long.parseLong(ip);
488
-        } catch (NumberFormatException nfe) {
489
-            return;
490
-        }
491
-
492
-        DCCTransfer send = DCCTransfer.findByToken(token);
493
-
494
-        if (send == null && !dontAsk) {
495
-            if (!token.isEmpty() && !port.equals("0")) {
496
-                // This is a reverse DCC Send that we no longer care about.
497
-            } else {
498
-                ActionManager.getActionManager().triggerEvent(
499
-                        DCCActions.DCC_SEND_REQUEST, null,
500
-                        arguments[0], nickname, filename);
501
-                askQuestion("User " + nickname + " on "
502
-                        + ((Server) arguments[0]).getName()
503
-                        + " would like to send you a file over DCC.\n\nFile: "
504
-                        + filename + "\n\nDo you want to continue?",
505
-                        "DCC Send Request", JOptionPane.YES_OPTION, type,
506
-                        format, arguments);
507
-            }
508
-        } else {
509
-            final boolean newSend = send == null;
510
-            if (newSend) {
511
-                send = new DCCTransfer(config.getOptionInt(getDomain(),
512
-                        "send.blocksize"));
513
-                send.setTurbo(config.getOptionBool(getDomain(), "send.forceturbo"));
514
-            }
515
-            try {
516
-                send.setAddress(Long.parseLong(ip), Integer.parseInt(port));
517
-            } catch (NumberFormatException nfe) {
518
-                return;
519
-            }
520
-            if (newSend) {
521
-                send.setFileName(filename);
522
-                send.setFileSize(size);
523
-                saveFile(nickname, send, ((Server) arguments[0]).getParser(),
524
-                        "0".equals(port), token);
525
-            } else {
526
-                send.connect();
527
-            }
528
-        }
529
-    }
530
-
531
-    /**
532
-     * Handles a DCC chat request.
533
-     *
534
-     * @param ctcpData CTCP data bits
535
-     * @param arguments The arguments for the event
536
-     */
537
-    private void handleReceive(final String[] ctcpData,
538
-            final Object... arguments) {
539
-        final String filename;
540
-        // Clients tend to put files with spaces in the name in ""
541
-        final StringBuilder filenameBits = new StringBuilder();
542
-        int i;
543
-        final boolean quoted = ctcpData[1].startsWith("\"");
544
-        if (quoted) {
545
-            for (i = 1; i < ctcpData.length; i++) {
546
-                String bit = ctcpData[i];
547
-                if (i == 1) {
548
-                    bit = bit.substring(1);
549
-                }
550
-                if (bit.endsWith("\"")) {
551
-                    filenameBits.append(" ")
552
-                            .append(bit.substring(0, bit.length() - 1));
553
-                    break;
554
-                } else {
555
-                    filenameBits.append(" ").append(bit);
556
-                }
557
-            }
558
-            filename = filenameBits.toString().trim();
559
-        } else {
560
-            filename = ctcpData[1];
561
-            i = 1;
562
-        }
563
-
564
-        final int port;
565
-        final int position;
566
-        try {
567
-            port = Integer.parseInt(ctcpData[++i]);
568
-            position = Integer.parseInt(ctcpData[++i]);
569
-            } catch (NumberFormatException nfe) {
570
-                return;
571
-        }
572
-        final String token = (ctcpData.length - 1 > i) ? " "
573
-                + ctcpData[++i] : "";
574
-
575
-        // Now look for a dcc that matches.
576
-        for (DCCTransfer send : DCCTransfer.getTransfers()) {
577
-            if (send.getPort() == port && (new File(send.getFileName()))
578
-                    .getName().equalsIgnoreCase(filename)) {
579
-                if ((!token.isEmpty() && !send.getToken().isEmpty())
580
-                        && (!token.equals(send.getToken()))) {
581
-                    continue;
582
-                }
583
-                final Parser parser = ((Server) arguments[0]).getParser();
584
-                final String nick = ((ClientInfo) arguments[1]).getNickname();
585
-                if (ctcpData[0].equalsIgnoreCase("resume")) {
586
-                    parser.sendCTCP(nick, "DCC", "ACCEPT "+ ((quoted) ? "\""
587
-                            + filename + "\"" : filename) + " " + port + " "
588
-                            + send.setFileStart(position) + token);
589
-                } else {
590
-                    send.setFileStart(position);
591
-                    if (port == 0) {
592
-                        // Reverse dcc
593
-                        if (listen(send)) {
594
-                            if (send.getToken().isEmpty()) {
595
-                                parser.sendCTCP(nick, "DCC", "SEND "
596
-                                        + ((quoted) ? "\"" + filename
597
-                                        + "\"" : filename) + " "
598
-                                        + DCC.ipToLong(send.getHost())
599
-                                        + " " + send.getPort()
600
-                                        + " " + send.getFileSize());
601
-                            } else {
602
-                                parser.sendCTCP(nick, "DCC", "SEND "
603
-                                        + ((quoted) ? "\"" + filename
604
-                                        + "\"" : filename)
605
-                                        + " " + DCC.ipToLong(send.getHost())
606
-                                        + " " + send.getPort()
607
-                                        + " " + send.getFileSize() + " "
608
-                                        + send.getToken());
609
-                            }
610
-                        }
611
-                    } else {
612
-                        send.connect();
613
-                    }
614
-                }
615
-            }
616
-        }
617
-    }
618
-
619
-
620
-
621
-    /**
622
-     * Retrieves the container for the placeholder.
623
-     *
624
-     * @since 0.6.4
625
-     * @return This plugin's placeholder container
626
-     */
627
-    public synchronized PlaceholderContainer getContainer() {
628
-        if (container == null) {
629
-            createContainer();
630
-        }
631
-
632
-        return container;
633
-    }
634
-
635
-    /**
636
-     * Removes the cached container.
637
-     *
638
-     * @since 0.6.4
639
-     */
640
-    public synchronized void removeContainer() {
641
-        container = null;
642
-    }
643
-
644
-    /**
645
-     * Create the container window.
646
-     */
647
-    protected void createContainer() {
648
-        container = new PlaceholderContainer(this, config, controller);
649
-        windowManager.addWindow(container);
43
+        setObjectGraph(graph.plus(new DCCPluginModule(pluginInfo)));
44
+        dccManager = getObjectGraph().get(DCCManager.class);
45
+        registerCommand(DCCCommand.class, DCCCommand.INFO);
650 46
     }
651 47
 
652 48
     /** {@inheritDoc} */
653 49
     @Override
654
-    public void domainUpdated() {
655
-        final ConfigProvider defaults = identityController.getAddonSettings();
656
-
657
-        defaults.setOption(getDomain(), "receive.savelocation",
658
-                identityController.getConfigurationDirectory() + "downloads"
659
-                + System.getProperty("file.separator"));
660
-    }
661
-
662
-    /**
663
-     * Called when the plugin is loaded.
664
-     */
665
-    @Override
666 50
     public void onLoad() {
667
-        final File dir = new File(config.getOption(getDomain(),
668
-                "receive.savelocation"));
669
-        if (dir.exists()) {
670
-            if (!dir.isDirectory()) {
671
-                Logger.userError(ErrorLevel.LOW,
672
-                        "Unable to create download dir (file exists instead)");
673
-            }
674
-        } else {
675
-            try {
676
-                dir.mkdirs();
677
-                dir.createNewFile();
678
-            } catch (IOException ex) {
679
-                Logger.userError(ErrorLevel.LOW,
680
-                        "Unable to create download dir");
681
-            }
682
-        }
683
-
684
-        ActionManager.getActionManager().registerTypes(DCCActions.values());
685
-        ActionManager.getActionManager().registerListener(this,
686
-                CoreActionType.SERVER_CTCP);
687 51
         super.onLoad();
52
+        dccManager.onLoad();
688 53
     }
689 54
 
690
-    /**
691
-     * Called when this plugin is Unloaded.
692
-     */
55
+    /** {@inheritDoc} */
693 56
     @Override
694
-    public synchronized void onUnload() {
695
-        ActionManager.getActionManager().unregisterListener(this);
696
-        if (container != null) {
697
-            container.close();
698
-        }
57
+    public void onUnload() {
699 58
         super.onUnload();
700
-    }
701
-
702
-    /**
703
-     * Get the IP Address we should send as our listening IP.
704
-     *
705
-     * @return The IP Address we should send as our listening IP.
706
-     */
707
-    public String getListenIP() {
708
-        return getListenIP(null);
709
-    }
710
-
711
-    /**
712
-     * Get the IP Address we should send as our listening IP.
713
-     *
714
-     * @param parser Parser the IRC Parser where this dcc is initiated
715
-     * @return The IP Address we should send as our listening IP.
716
-     */
717
-    public String getListenIP(final Parser parser) {
718
-        final String configIP = config.getOption(getDomain(), "firewall.ip");
719
-        if (!configIP.isEmpty()) {
720
-            try {
721
-                return InetAddress.getByName(configIP).getHostAddress();
722
-            } catch (UnknownHostException ex) { //NOPMD - handled below
723
-                //Continue below
724
-            }
725
-        }
726
-        if (parser != null) {
727
-            final String myHost = parser.getLocalClient().getHostname();
728
-            if (!myHost.isEmpty()) {
729
-                try {
730
-                    return InetAddress.getByName(myHost).getHostAddress();
731
-                } catch (UnknownHostException e) { //NOPMD - handled below
732
-                    //Continue below
733
-                }
734
-            }
735
-        }
736
-        try {
737
-            return InetAddress.getLocalHost().getHostAddress();
738
-        } catch (UnknownHostException e) {
739
-            // This is almost certainly not what we want, but we can't work out
740
-            // the right one.
741
-            return "127.0.0.1"; //NOPMD
742
-        }
59
+        dccManager.onUnload();
743 60
     }
744 61
 
745 62
     /** {@inheritDoc} */
746 63
     @Override
747 64
     public void showConfig(final PreferencesDialogModel manager) {
748
-        final PreferencesCategory general = new PluginPreferencesCategory(
749
-                pluginInfo, "DCC", "", "category-dcc");
750
-        final PreferencesCategory firewall = new PluginPreferencesCategory(
751
-                pluginInfo, "Firewall", "");
752
-        final PreferencesCategory sending = new PluginPreferencesCategory(
753
-                pluginInfo, "Sending", "");
754
-        final PreferencesCategory receiving = new PluginPreferencesCategory(
755
-                pluginInfo, "Receiving", "");
756
-
757
-        manager.getCategory("Plugins").addSubCategory(general.setInlineAfter());
758
-        general.addSubCategory(firewall.setInline());
759
-        general.addSubCategory(sending.setInline());
760
-        general.addSubCategory(receiving.setInline());
761
-
762
-        firewall.addSetting(new PreferencesSetting(PreferencesType.TEXT,
763
-                getDomain(), "firewall.ip", "Forced IP",
764
-                "What IP should be sent as our IP (Blank = work it out)",
765
-                manager.getConfigManager(), manager.getIdentity()));
766
-        firewall.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
767
-                getDomain(), "firewall.ports.usePortRange", "Use Port Range",
768
-                "Useful if you have a firewall that only forwards specific "
769
-                + "ports", manager.getConfigManager(), manager.getIdentity()));
770
-        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
771
-                getDomain(), "firewall.ports.startPort", "Start Port",
772
-                "Port to try to listen on first", manager.getConfigManager(),
773
-                manager.getIdentity()));
774
-        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
775
-                getDomain(), "firewall.ports.endPort", "End Port",
776
-                "Port to try to listen on last", manager.getConfigManager(),
777
-                manager.getIdentity()));
778
-        receiving.addSetting(new PreferencesSetting(PreferencesType.DIRECTORY,
779
-                getDomain(), "receive.savelocation", "Default save location",
780
-                "Where the save as window defaults to?",
781
-                manager.getConfigManager(), manager.getIdentity()));
782
-        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
783
-                getDomain(), "send.reverse", "Reverse DCC",
784
-                "With reverse DCC, the sender connects rather than "
785
-                + "listens like normal dcc", manager.getConfigManager(),
786
-                manager.getIdentity()));
787
-        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
788
-                getDomain(), "send.forceturbo", "Use Turbo DCC",
789
-                "Turbo DCC doesn't wait for ack packets. this is "
790
-                + "faster but not always supported.",
791
-                manager.getConfigManager(), manager.getIdentity()));
792
-        receiving.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
793
-                getDomain(), "receive.reverse.sendtoken",
794
-                "Send token in reverse receive",
795
-                "If you have problems with reverse dcc receive resume,"
796
-                + " try toggling this.", manager.getConfigManager(),
797
-                manager.getIdentity()));
798
-        general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
799
-                getDomain(), "send.blocksize", "Blocksize to use for DCC",
800
-                "Change the block size for send/receive, this can "
801
-                + "sometimes speed up transfers.", manager.getConfigManager(),
802
-                manager.getIdentity()));
803
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
804
-                getDomain(), "general.percentageInTitle",
805
-                "Show percentage of transfers in the window title",
806
-                "Show the current percentage of transfers in the DCC window "
807
-                + "title", manager.getConfigManager(), manager.getIdentity()));
65
+        dccManager.showConfig(manager);
808 66
     }
809 67
 
810 68
 }

+ 49
- 0
src/com/dmdirc/addons/dcc/DCCPluginModule.java Visa fil

@@ -0,0 +1,49 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.dcc;
24
+
25
+import com.dmdirc.addons.ui_swing.SwingModule;
26
+import com.dmdirc.plugins.PluginInfo;
27
+
28
+import dagger.Module;
29
+import dagger.Provides;
30
+
31
+/**
32
+ * DI module for the DCC plugin.
33
+ */
34
+@Module(injects = {DCCManager.class, DCCCommand.class}, addsTo = SwingModule.class)
35
+public class DCCPluginModule {
36
+
37
+    /** The DCC plugin's plugin info. */
38
+    private final PluginInfo pluginInfo;
39
+
40
+    public DCCPluginModule(final PluginInfo pluginInfo) {
41
+        this.pluginInfo = pluginInfo;
42
+    }
43
+
44
+    @Provides
45
+    public PluginInfo getPluginInfo() {
46
+        return pluginInfo;
47
+    }
48
+
49
+}

+ 2
- 2
src/com/dmdirc/addons/dcc/PlaceholderContainer.java Visa fil

@@ -37,7 +37,7 @@ import java.util.Arrays;
37 37
 public class PlaceholderContainer extends FrameContainer {
38 38
 
39 39
     /** The plugin which owns this placeholder. */
40
-    private final DCCPlugin plugin;
40
+    private final DCCManager plugin;
41 41
     /** Parent swing controller. */
42 42
     private final SwingController controller;
43 43
 
@@ -48,7 +48,7 @@ public class PlaceholderContainer extends FrameContainer {
48 48
      * @param config Config manager
49 49
      * @param controller Swing controller
50 50
      */
51
-    public PlaceholderContainer(final DCCPlugin plugin,
51
+    public PlaceholderContainer(final DCCManager plugin,
52 52
             final AggregateConfigProvider config, final SwingController controller) {
53 53
         super("dcc", "DCCs", "DCCs", config, Arrays.asList(
54 54
                 "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));

+ 3
- 3
src/com/dmdirc/addons/dcc/TransferContainer.java Visa fil

@@ -47,7 +47,7 @@ public class TransferContainer extends FrameContainer implements
47 47
         DCCTransferHandler, SocketCloseListener {
48 48
 
49 49
     /** The dcc plugin that owns this frame */
50
-    protected final DCCPlugin plugin;
50
+    protected final DCCManager plugin;
51 51
 
52 52
     /** Config manager. */
53 53
     private final AggregateConfigProvider config;
@@ -68,7 +68,7 @@ public class TransferContainer extends FrameContainer implements
68 68
     private long timeStarted = 0;
69 69
 
70 70
     /** Plugin that this send belongs to. */
71
-    private final DCCPlugin myPlugin;
71
+    private final DCCManager myPlugin;
72 72
 
73 73
     /** IRC Parser that caused this send */
74 74
     private Parser parser = null;
@@ -91,7 +91,7 @@ public class TransferContainer extends FrameContainer implements
91 91
      * @param targetNick Nickname of target
92 92
      * @param server The server that initiated this send
93 93
      */
94
-    public TransferContainer(final DCCPlugin plugin, final DCCTransfer dcc,
94
+    public TransferContainer(final DCCManager plugin, final DCCTransfer dcc,
95 95
             final AggregateConfigProvider config, final String title,
96 96
             final String targetNick, final Server server) {
97 97
         super(dcc.getType() == DCCTransfer.TransferType.SEND

+ 15
- 15
src/com/dmdirc/addons/dcc/kde/KFileChooser.java Visa fil

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.dcc.kde;
24 24
 
25
-import com.dmdirc.addons.dcc.DCCPlugin;
25
+import com.dmdirc.addons.dcc.DCCManager;
26 26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 27
 
28 28
 import java.awt.Component;
@@ -67,7 +67,7 @@ public final class KFileChooser extends JFileChooser {
67 67
     private String fileFilter = null;
68 68
 
69 69
     /** The plugin that this file chooser is for. */
70
-    private final DCCPlugin plugin;
70
+    private final DCCManager plugin;
71 71
     /** Used to read settings from. */
72 72
     private final AggregateConfigProvider config;
73 73
 
@@ -76,7 +76,7 @@ public final class KFileChooser extends JFileChooser {
76 76
      *
77 77
      * @param plugin The plugin that owns this KFileChooser
78 78
      */
79
-    private KFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin) {
79
+    private KFileChooser(final AggregateConfigProvider config, final DCCManager plugin) {
80 80
         super();
81 81
 
82 82
         this.plugin = plugin;
@@ -89,7 +89,7 @@ public final class KFileChooser extends JFileChooser {
89 89
      * @param plugin The plugin that owns this KFileChooser
90 90
      * @param currentDirectory Directory to use as the base directory
91 91
      */
92
-    private KFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final File currentDirectory) {
92
+    private KFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final File currentDirectory) {
93 93
         super(currentDirectory);
94 94
 
95 95
         this.plugin = plugin;
@@ -103,7 +103,7 @@ public final class KFileChooser extends JFileChooser {
103 103
      * @param currentDirectory Directory to use as the base directory
104 104
      * @param fsv The FileSystemView to use
105 105
      */
106
-    private KFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
106
+    private KFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final File currentDirectory, final FileSystemView fsv) {
107 107
         super(currentDirectory, fsv);
108 108
 
109 109
         this.plugin = plugin;
@@ -116,7 +116,7 @@ public final class KFileChooser extends JFileChooser {
116 116
      * @param plugin The plugin that owns this KFileChooser
117 117
      * @param fsv The FileSystemView to use
118 118
      */
119
-    private KFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final FileSystemView fsv) {
119
+    private KFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final FileSystemView fsv) {
120 120
         super(fsv);
121 121
 
122 122
         this.plugin = plugin;
@@ -129,7 +129,7 @@ public final class KFileChooser extends JFileChooser {
129 129
      * @param plugin The plugin that owns this KFileChooser
130 130
      * @param currentDirectoryPath Directory to use as the base directory
131 131
      */
132
-    private KFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final String currentDirectoryPath) {
132
+    private KFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final String currentDirectoryPath) {
133 133
         super(currentDirectoryPath);
134 134
 
135 135
         this.plugin = plugin;
@@ -143,7 +143,7 @@ public final class KFileChooser extends JFileChooser {
143 143
      * @param currentDirectoryPath Directory to use as the base directory
144 144
      * @param fsv The FileSystemView to use
145 145
      */
146
-    private KFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
146
+    private KFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final String currentDirectoryPath, final FileSystemView fsv) {
147 147
         super(currentDirectoryPath, fsv);
148 148
 
149 149
         this.plugin = plugin;
@@ -158,7 +158,7 @@ public final class KFileChooser extends JFileChooser {
158 158
      * @return return true if getFileChooser() will return a KFileChooser not a
159 159
      *         JFileChooser
160 160
      */
161
-    public static boolean useKFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin) {
161
+    public static boolean useKFileChooser(final AggregateConfigProvider config, final DCCManager plugin) {
162 162
         return KDialogProcess.hasKDialog() && config.getOptionBool(plugin.getDomain(), "general.useKFileChooser");
163 163
     }
164 164
 
@@ -168,7 +168,7 @@ public final class KFileChooser extends JFileChooser {
168 168
      * @param plugin The DCC Plugin that is requesting a chooser
169 169
      * @return The relevant FileChooser
170 170
      */
171
-    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin) {
171
+    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCManager plugin) {
172 172
         return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin) : new JFileChooser();
173 173
     }
174 174
 
@@ -179,7 +179,7 @@ public final class KFileChooser extends JFileChooser {
179 179
      * @param currentDirectory Directory to use as the base directory
180 180
      * @return The relevant FileChooser
181 181
      */
182
-    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final File currentDirectory) {
182
+    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final File currentDirectory) {
183 183
         return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectory) : new JFileChooser(currentDirectory);
184 184
     }
185 185
 
@@ -191,7 +191,7 @@ public final class KFileChooser extends JFileChooser {
191 191
      * @param fsv The FileSystemView to use
192 192
      * @return The relevant FileChooser
193 193
      */
194
-    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
194
+    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final File currentDirectory, final FileSystemView fsv) {
195 195
         return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectory, fsv) : new JFileChooser(currentDirectory, fsv);
196 196
     }
197 197
 
@@ -202,7 +202,7 @@ public final class KFileChooser extends JFileChooser {
202 202
      * @param fsv The FileSystemView to use
203 203
      * @return The relevant FileChooser
204 204
      */
205
-    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final FileSystemView fsv) {
205
+    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final FileSystemView fsv) {
206 206
         return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, fsv) : new JFileChooser(fsv);
207 207
     }
208 208
 
@@ -213,7 +213,7 @@ public final class KFileChooser extends JFileChooser {
213 213
      * @param currentDirectoryPath Directory to use as the base directory
214 214
      * @return The relevant FileChooser
215 215
      */
216
-    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final String currentDirectoryPath) {
216
+    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final String currentDirectoryPath) {
217 217
         return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectoryPath) : new JFileChooser(currentDirectoryPath);
218 218
     }
219 219
 
@@ -225,7 +225,7 @@ public final class KFileChooser extends JFileChooser {
225 225
      * @param fsv The FileSystemView to use
226 226
      * @return The relevant FileChooser
227 227
      */
228
-    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
228
+    public static JFileChooser getFileChooser(final AggregateConfigProvider config, final DCCManager plugin, final String currentDirectoryPath, final FileSystemView fsv) {
229 229
         return useKFileChooser(config, plugin) ? new KFileChooser(config, plugin, currentDirectoryPath, fsv) : new JFileChooser(currentDirectoryPath, fsv);
230 230
     }
231 231
 

+ 0
- 9
src/com/dmdirc/addons/osd/OsdPlugin.java Visa fil

@@ -92,15 +92,6 @@ public class OsdPlugin extends BaseCommandPlugin implements
92 92
         registerCommand(new OsdCommand(commandController, osdManager), OsdCommand.INFO);
93 93
     }
94 94
 
95
-    /**
96
-     * Get our PluginInfo.
97
-     *
98
-     * @return our PluginInfo.
99
-     */
100
-    public PluginInfo getPluginInfo() {
101
-        return pluginInfo;
102
-    }
103
-
104 95
     /** {@inheritDoc} */
105 96
     @Override
106 97
     public void showConfig(final PreferencesDialogModel manager) {

Laddar…
Avbryt
Spara