Browse Source

Mass DCC tidying/refactoring

Change-Id: Ifd926f3603ebe9fc0a876efd6407d743766df967
Reviewed-on: http://gerrit.dmdirc.com/763
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3
Chris Smith 14 years ago
parent
commit
42227f3665

+ 31
- 25
src/com/dmdirc/addons/dcc/DCC.java View File

@@ -26,10 +26,11 @@ import java.net.Socket;
26 26
 import java.net.ServerSocket;
27 27
 import java.io.IOException;
28 28
 import java.util.concurrent.Semaphore;
29
+import java.util.concurrent.atomic.AtomicBoolean;
29 30
 
30 31
 /**
31
- * This class handles the main "grunt work" of DCC, subclasses process the data
32
- * received by this class.
32
+ * This class manages the socket and low-level I/O functionality for all
33
+ * types of DCC. Subclasses process the data received by this class.
33 34
  *
34 35
  * @author Shane 'Dataforce' McCormack
35 36
  */
@@ -48,7 +49,7 @@ public abstract class DCC implements Runnable {
48 49
     private volatile Thread myThread;
49 50
 
50 51
     /** Are we already running? */
51
-    protected boolean running = false;
52
+    protected final AtomicBoolean running = new AtomicBoolean();
52 53
 
53 54
     /** Are we a listen socket? */
54 55
     protected boolean listen = false;
@@ -56,28 +57,28 @@ public abstract class DCC implements Runnable {
56 57
     /**
57 58
      * The current socket in use if this is a listen socket.
58 59
      * This reference may be changed if and only if exactly one permit from the
59
-     * <code>serverSocketSem</code> and <code>serverListenignSem</code>
60
-     * semaphores is held by the thread doing the modification.
60
+     * {@link #serverSocketSem} and {@link #serverListeningSem} semaphores is
61
+     * held by the thread doing the modification.
61 62
      */
62 63
     private ServerSocket serverSocket;
63 64
 
64 65
     /**
65 66
      * Semaphore to control write access to ServerSocket.
66
-     * If an object acquires a permit from the <code>serverSocketSem</code>, then
67
-     * <code>serverSocket</code> is <em>guaranteed</em> not to be externally
67
+     * If an object acquires a permit from the {@link #serverSocketSem}, then
68
+     * {@link #serverSocket} is <em>guaranteed</em> not to be externally
68 69
      * modified until that permit is released, <em>unless</em> the object also
69
-     * acquires a permit from the <code>serverListeningSem</code>.
70
+     * acquires a permit from the {@link #serverListeningSem}.
70 71
      */
71 72
     private final Semaphore serverSocketSem = new Semaphore(1);
72 73
 
73 74
     /**
74 75
      * Semaphore used when we're blocking waiting for connections.
75
-     * If an object acquires a permit from the <code>serverListeningSem</code>,
76
+     * If an object acquires a permit from the {@link #serverListeningSem},
76 77
      * then it is <em>guaranteed</em> that the {@link #run()} method is blocking
77 78
      * waiting for incoming connections. In addition, it is <em>guaranteed</em>
78
-     * that the {@link #run()} method is holding the <code>serverSocketSem</code>
79
+     * that the {@link #run()} method is holding the {@link #serverSocketSem}
79 80
      * permit, and it will continue holding that permit until it can reaquire
80
-     * the <code>serverListeningSem</code> permit.
81
+     * the {@link #serverListeningSem} permit.
81 82
      */
82 83
     private final Semaphore serverListeningSem = new Semaphore(0);
83 84
 
@@ -97,7 +98,6 @@ public abstract class DCC implements Runnable {
97 98
                 address = 0;
98 99
                 port = serverSocket.getLocalPort();
99 100
             } else {
100
-                // socket = new Socket(longToIP(address), port, bindIP, 0);
101 101
                 socket = new Socket(longToIP(address), port);
102 102
                 socketOpened();
103 103
             }
@@ -161,13 +161,13 @@ public abstract class DCC implements Runnable {
161 161
      */
162 162
     @Override
163 163
     public void run() {
164
-        if (running) {
164
+        if (running.getAndSet(true)) {
165 165
             return;
166 166
         }
167
-        running = true;
167
+
168 168
         // handleSocket is implemented by sub classes, and should return false
169 169
         // when the socket is closed.
170
-        Thread thisThread = Thread.currentThread();
170
+        final Thread thisThread = Thread.currentThread();
171 171
 
172 172
         while (myThread == thisThread) {
173 173
             serverSocketSem.acquireUninterruptibly();
@@ -200,8 +200,7 @@ public abstract class DCC implements Runnable {
200 200
         }
201 201
         // Socket closed
202 202
 
203
-        thisThread = null;
204
-        running = false;
203
+        running.set(false);
205 204
     }
206 205
 
207 206
     /**
@@ -211,11 +210,7 @@ public abstract class DCC implements Runnable {
211 210
         boolean haveSLS = false;
212 211
 
213 212
         while (!serverSocketSem.tryAcquire() && !(haveSLS = serverListeningSem.tryAcquire())) {
214
-            try {
215
-                Thread.sleep(100);
216
-            } catch (InterruptedException ex) {
217
-                // Do we care? I doubt we do! Should be unchecked damnit.
218
-            }
213
+            Thread.yield();
219 214
         }
220 215
 
221 216
         if (serverSocket != null) {
@@ -268,7 +263,16 @@ public abstract class DCC implements Runnable {
268 263
     }
269 264
 
270 265
     /**
271
-     * Handle the socket.
266
+     * Called periodically to read or write data to this DCC's socket.
267
+     * Implementations should attempt to send or receive one unit of data
268
+     * (for example one block of binary data, or one line of ASCII data) each
269
+     * time this method is called.
270
+     * <p>
271
+     * The return value of this method is used to determine whether the DCC
272
+     * has been completed. If the method returns <code>false</code>, the
273
+     * DCC is assumed to have finished (i.e., the socket has closed), and the
274
+     * method will not be called again. A return value of <code>true</code> will
275
+     * cause the method to be recalled.
272 276
      *
273 277
      * @return false when socket is closed, true will cause the method to be
274 278
      *         called again.
@@ -322,7 +326,8 @@ public abstract class DCC implements Runnable {
322 326
     public static long ipToLong(final String ip) {
323 327
         final String bits[] = ip.split("\\.");
324 328
         if (bits.length > 3) {
325
-            return (Long.parseLong(bits[0]) << 24) + (Long.parseLong(bits[1]) << 16) + (Long.parseLong(bits[2]) << 8) + Long.parseLong(bits[3]);
329
+            return (Long.parseLong(bits[0]) << 24) + (Long.parseLong(bits[1]) << 16)
330
+                    + (Long.parseLong(bits[2]) << 8) + Long.parseLong(bits[3]);
326 331
         }
327 332
         return 0;
328 333
     }
@@ -334,7 +339,8 @@ public abstract class DCC implements Runnable {
334 339
      * @return long as an IP
335 340
      */
336 341
     public static String longToIP(final long in) {
337
-        return ((in & 0xff000000) >> 24) + "." + ((in & 0x00ff0000) >> 16) + "." + ((in & 0x0000ff00) >> 8) + "." + (in & 0x000000ff);
342
+        return ((in & 0xff000000) >> 24) + "." + ((in & 0x00ff0000) >> 16) + "."
343
+                + ((in & 0x0000ff00) >> 8) + "." + (in & 0x000000ff);
338 344
     }
339 345
 
340 346
 }

+ 7
- 18
src/com/dmdirc/addons/dcc/DCCChat.java View File

@@ -35,7 +35,7 @@ import java.io.PrintWriter;
35 35
 public class DCCChat extends DCC {
36 36
 
37 37
     /** The handler for this DCCChat. */
38
-    private DCCChatInterface handler = null;
38
+    private DCCChatHandler handler = null;
39 39
 
40 40
     /** Used to send data out the socket. */
41 41
     private PrintWriter out;
@@ -56,15 +56,13 @@ public class DCCChat extends DCC {
56 56
     /**
57 57
      * Change the handler for this DCC Chat.
58 58
      *
59
-     * @param handler A class implementing DCCChatInterface
59
+     * @param handler A class implementing DCCChatHandler
60 60
      */
61
-    public void setHandler(final DCCChatInterface handler) {
61
+    public void setHandler(final DCCChatHandler handler) {
62 62
         this.handler = handler;
63 63
     }
64 64
 
65
-    /**
66
-     * Called when the socket is first opened, before any data is handled.
67
-     */
65
+    /** {@inheritDoc} */
68 66
     @Override
69 67
     protected void socketOpened() {
70 68
         active = true;
@@ -79,9 +77,7 @@ public class DCCChat extends DCC {
79 77
         }
80 78
     }
81 79
 
82
-    /**
83
-     * Called when the socket is closed, before the thread terminates.
84
-     */
80
+    /** {@inheritDoc} */
85 81
     @Override
86 82
     protected void socketClosed() {
87 83
         out = null;
@@ -92,12 +88,7 @@ public class DCCChat extends DCC {
92 88
         active = false;
93 89
     }
94 90
 
95
-    /**
96
-     * Handle the socket.
97
-     *
98
-     * @return false when socket is closed, true will cause the method to be
99
-     *         called again.
100
-     */
91
+    /** {@inheritDoc} */
101 92
     @Override
102 93
     protected boolean handleSocket() {
103 94
         if (out == null || in == null) {
@@ -119,9 +110,7 @@ public class DCCChat extends DCC {
119 110
         }
120 111
     }
121 112
 
122
-    /**
123
-     * Check if this socket can be written to.
124
-     */
113
+    /** {@inheritDoc} */
125 114
     @Override
126 115
     public boolean isWriteable() {
127 116
         return out != null;

src/com/dmdirc/addons/dcc/DCCChatInterface.java → src/com/dmdirc/addons/dcc/DCCChatHandler.java View File

@@ -27,7 +27,7 @@ package com.dmdirc.addons.dcc;
27 27
  *
28 28
  * @author Shane 'Dataforce' McCormack
29 29
  */
30
-public interface DCCChatInterface {
30
+public interface DCCChatHandler {
31 31
 
32 32
     /**
33 33
      * Handle a received message

+ 10
- 27
src/com/dmdirc/addons/dcc/DCCChatWindow.java View File

@@ -31,7 +31,7 @@ import com.dmdirc.Main;
31 31
  *
32 32
  * @author Shane 'Dataforce' McCormack
33 33
  */
34
-public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
34
+public class DCCChatWindow extends DCCFrame implements DCCChatHandler {
35 35
 
36 36
     /** The DCCChat object we are a window for */
37 37
     private final DCCChat dcc;
@@ -51,7 +51,8 @@ public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
51 51
      * @param nick My Current Nickname
52 52
      * @param targetNick Nickname of target
53 53
      */
54
-    public DCCChatWindow(final DCCPlugin plugin, final DCCChat dcc, final String title, final String nick, final String targetNick) {
54
+    public DCCChatWindow(final DCCPlugin plugin, final DCCChat dcc,
55
+            final String title, final String nick, final String targetNick) {
55 56
         super(plugin, title, "dcc-chat-inactive", false);
56 57
         this.dcc = dcc;
57 58
         dcc.setHandler(this);
@@ -74,11 +75,7 @@ public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
74 75
         return dcc;
75 76
     }
76 77
 
77
-    /**
78
-     * Sends a line of text to this container's source.
79
-     *
80
-     * @param line The line to be sent
81
-     */
78
+    /** {@inheritDoc} */
82 79
     @Override
83 80
     public void sendLine(final String line) {
84 81
         if (dcc.isWriteable()) {
@@ -92,24 +89,16 @@ public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
92 89
         }
93 90
     }
94 91
 
95
-    /**
96
-     * Handle a received message
97
-     *
98
-     * @param dcc The DCCChat that this message is from
99
-     * @param message The message
100
-     */
92
+    /** {@inheritDoc} */
101 93
     @Override
102 94
     public void handleChatMessage(final DCCChat dcc, final String message) {
103 95
         final StringBuffer buff = new StringBuffer("DCCChatMessage");
104
-        ActionManager.processEvent(DCCActions.DCC_CHAT_MESSAGE, buff, this, otherNickname, message);
96
+        ActionManager.processEvent(DCCActions.DCC_CHAT_MESSAGE, buff, this,
97
+                otherNickname, message);
105 98
         addLine(buff, otherNickname, myWindow.getTranscoder().encode(message));
106 99
     }
107 100
 
108
-    /**
109
-     * Called when the socket is closed
110
-     *
111
-     * @param dcc The DCCChat that this message is from
112
-     */
101
+    /** {@inheritDoc} */
113 102
     @Override
114 103
     public void socketClosed(final DCCChat dcc) {
115 104
         final StringBuffer buff = new StringBuffer("DCCChatInfo");
@@ -120,11 +109,7 @@ public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
120 109
         }
121 110
     }
122 111
 
123
-    /**
124
-     * Called when the socket is opened
125
-     *
126
-     * @param dcc The DCCChat that this message is from
127
-     */
112
+    /** {@inheritDoc} */
128 113
     @Override
129 114
     public void socketOpened(final DCCChat dcc) {
130 115
         final StringBuffer buff = new StringBuffer("DCCChatInfo");
@@ -133,9 +118,7 @@ public class DCCChatWindow extends DCCFrame implements DCCChatInterface {
133 118
         setIcon("dcc-chat-active");
134 119
     }
135 120
 
136
-    /**
137
-     * Closes this container (and it's associated frame).
138
-     */
121
+    /** {@inheritDoc} */
139 122
     @Override
140 123
     public void windowClosing() {
141 124
         super.windowClosing();

+ 66
- 48
src/com/dmdirc/addons/dcc/DCCCommand.java View File

@@ -68,23 +68,26 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
68 68
     /** {@inheritDoc} */
69 69
     @Override
70 70
     public void execute(final InputWindow origin, final Server server,
71
-                        final boolean isSilent, final CommandArguments args) {
71
+            final boolean isSilent, final CommandArguments args) {
72 72
         if (args.getArguments().length > 1) {
73 73
             final String type = args.getArguments()[0];
74 74
             final String target = args.getArguments()[1];
75 75
             final Parser parser = server.getParser();
76 76
             final String myNickname = parser.getLocalClient().getNickname();
77 77
 
78
-            if (parser.isValidChannelName(target) || parser.getStringConverter().equalsIgnoreCase(target, myNickname)) {
78
+            if (parser.isValidChannelName(target)
79
+                    || parser.getStringConverter().equalsIgnoreCase(target, myNickname)) {
79 80
                 final Thread errorThread = new Thread(new Runnable() {
80 81
 
81 82
                     /** {@inheritDoc} */
82 83
                     @Override
83 84
                     public void run() {
84 85
                         if (parser.getStringConverter().equalsIgnoreCase(target, myNickname)) {
85
-                            JOptionPane.showMessageDialog(null, "You can't DCC yourself.", "DCC Error", JOptionPane.ERROR_MESSAGE);
86
+                            JOptionPane.showMessageDialog(null, "You can't DCC yourself.",
87
+                                    "DCC Error", JOptionPane.ERROR_MESSAGE);
86 88
                         } else {
87
-                            JOptionPane.showMessageDialog(null, "You can't DCC a channel.", "DCC Error", JOptionPane.ERROR_MESSAGE);
89
+                            JOptionPane.showMessageDialog(null, "You can't DCC a channel.",
90
+                                    "DCC Error", JOptionPane.ERROR_MESSAGE);
88 91
                         }
89 92
                     }
90 93
 
@@ -95,16 +98,24 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
95 98
             if (type.equalsIgnoreCase("chat")) {
96 99
                 final DCCChat chat = new DCCChat();
97 100
                 if (myPlugin.listen(chat)) {
98
-                    final DCCChatWindow window = new DCCChatWindow(myPlugin, chat, "*Chat: " + target, myNickname, target);
101
+                    final DCCChatWindow window = new DCCChatWindow(myPlugin, chat,
102
+                            "*Chat: " + target, myNickname, target);
99 103
 
100
-                    parser.sendCTCP(target, "DCC", "CHAT chat " + DCC.ipToLong(myPlugin.getListenIP(parser)) + " " + chat.getPort());
104
+                    parser.sendCTCP(target, "DCC", "CHAT chat "
105
+                            + DCC.ipToLong(myPlugin.getListenIP(parser)) + " "
106
+                            + chat.getPort());
101 107
 
102
-                    ActionManager.processEvent(DCCActions.DCC_CHAT_REQUEST_SENT, null, server, target);
108
+                    ActionManager.processEvent(DCCActions.DCC_CHAT_REQUEST_SENT,
109
+                            null, server, target);
103 110
 
104
-                    sendLine(origin, isSilent, "DCCChatStarting", target, chat.getHost(), chat.getPort());
105
-                    window.getFrame().addLine("DCCChatStarting", target, chat.getHost(), chat.getPort());
111
+                    sendLine(origin, isSilent, "DCCChatStarting", target,
112
+                            chat.getHost(), chat.getPort());
113
+                    window.getFrame().addLine("DCCChatStarting", target,
114
+                            chat.getHost(), chat.getPort());
106 115
                 } else {
107
-                    sendLine(origin, isSilent, "DCCChatError", "Unable to start chat with " + target + " - unable to create listen socket");
116
+                    sendLine(origin, isSilent, "DCCChatError",
117
+                            "Unable to start chat with " + target
118
+                            + " - unable to create listen socket");
108 119
                 }
109 120
             } else if (type.equalsIgnoreCase("send")) {
110 121
                 sendFile(target, origin, server, isSilent, args.getArgumentsAsString(2));
@@ -126,7 +137,8 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
126 137
      * @param filename The file to send
127 138
      * @since 0.6.3m1
128 139
      */
129
-    public void sendFile(final String target, final InputWindow origin, final Server server, final boolean isSilent, final String filename) {
140
+    public void sendFile(final String target, final InputWindow origin,
141
+            final Server server, final boolean isSilent, final String filename) {
130 142
         // New thread to ask the user what file to send
131 143
         final File givenFile = new File(filename);
132 144
         final Thread dccThread = new Thread(new Runnable() {
@@ -134,7 +146,9 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
134 146
             /** {@inheritDoc} */
135 147
             @Override
136 148
             public void run() {
137
-                final JFileChooser jc = (givenFile.exists()) ? KFileChooser.getFileChooser(myPlugin, givenFile) : KFileChooser.getFileChooser(myPlugin);
149
+                final JFileChooser jc = givenFile.exists()
150
+                        ? KFileChooser.getFileChooser(myPlugin, givenFile)
151
+                        : KFileChooser.getFileChooser(myPlugin);
138 152
                 int result;
139 153
                 if (!givenFile.exists() || !givenFile.isFile()) {
140 154
                     jc.setDialogTitle("Send file to " + target + " - DMDirc ");
@@ -147,33 +161,55 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
147 161
                 }
148 162
                 if (result == JFileChooser.APPROVE_OPTION) {
149 163
                     if (jc.getSelectedFile().length() == 0) {
150
-                        JOptionPane.showMessageDialog(null, "You can't send empty files over DCC.", "DCC Error", JOptionPane.ERROR_MESSAGE);
164
+                        JOptionPane.showMessageDialog(null,
165
+                                "You can't send empty files over DCC.", "DCC Error",
166
+                                JOptionPane.ERROR_MESSAGE);
151 167
                         return;
152 168
                     } else if (!jc.getSelectedFile().exists()) {
153
-                        JOptionPane.showMessageDialog(null, "Invalid file specified", "DCC Error", JOptionPane.ERROR_MESSAGE);
169
+                        JOptionPane.showMessageDialog(null,
170
+                                "Invalid file specified", "DCC Error",
171
+                                JOptionPane.ERROR_MESSAGE);
154 172
                         return;
155 173
                     }
156 174
                     final Parser parser = server.getParser();
157
-                    DCCSend send = new DCCSend(IdentityManager.getGlobalConfig().getOptionInt(myPlugin.getDomain(), "send.blocksize"));
158
-                    send.setTurbo(IdentityManager.getGlobalConfig().getOptionBool(myPlugin.getDomain(), "send.forceturbo"));
159
-                    send.setType(DCCSend.TransferType.SEND);
175
+                    DCCTransfer send = new DCCTransfer(IdentityManager
176
+                            .getGlobalConfig().getOptionInt(myPlugin.getDomain(),
177
+                            "send.blocksize"));
178
+                    send.setTurbo(IdentityManager.getGlobalConfig()
179
+                            .getOptionBool(myPlugin.getDomain(), "send.forceturbo"));
180
+                    send.setType(DCCTransfer.TransferType.SEND);
160 181
 
161
-                    ActionManager.processEvent(DCCActions.DCC_SEND_REQUEST_SENT, null, server, target, jc.getSelectedFile());
182
+                    ActionManager.processEvent(DCCActions.DCC_SEND_REQUEST_SENT,
183
+                            null, server, target, jc.getSelectedFile());
162 184
 
163
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Starting DCC Send with: " + target);
185
+                    sendLine(origin, isSilent, FORMAT_OUTPUT,
186
+                            "Starting DCC Send with: " + target);
164 187
 
165 188
                     send.setFileName(jc.getSelectedFile().getAbsolutePath());
166 189
                     send.setFileSize(jc.getSelectedFile().length());
167 190
 
168
-                    if (IdentityManager.getGlobalConfig().getOptionBool(myPlugin.getDomain(), "send.reverse")) {
169
-                        new DCCSendWindow(myPlugin, send, "Send: " + target, target, server);
170
-                        parser.sendCTCP(target, "DCC", "SEND \"" + jc.getSelectedFile().getName() + "\" " + DCC.ipToLong(myPlugin.getListenIP(parser)) + " 0 " + send.getFileSize() + " " + send.makeToken() + ((send.isTurbo()) ? " T" : ""));
191
+                    if (IdentityManager.getGlobalConfig().getOptionBool(
192
+                            myPlugin.getDomain(), "send.reverse")) {
193
+                        new DCCTransferWindow(myPlugin, send, "Send: "
194
+                                + target, target, server);
195
+                        parser.sendCTCP(target, "DCC", "SEND \""
196
+                                + jc.getSelectedFile().getName() + "\" "
197
+                                + DCC.ipToLong(myPlugin.getListenIP(parser))
198
+                                + " 0 " + send.getFileSize() + " " + send.makeToken()
199
+                                + (send.isTurbo() ? " T" : ""));
171 200
                     } else {
172 201
                         if (myPlugin.listen(send)) {
173
-                            new DCCSendWindow(myPlugin, send, "*Send: " + target, target, server);
174
-                            parser.sendCTCP(target, "DCC", "SEND \"" + jc.getSelectedFile().getName() + "\" " + DCC.ipToLong(myPlugin.getListenIP(parser)) + " " + send.getPort() + " " + send.getFileSize() + ((send.isTurbo()) ? " T" : ""));
202
+                            new DCCTransferWindow(myPlugin, send, "*Send: "
203
+                                    + target, target, server);
204
+                            parser.sendCTCP(target, "DCC", "SEND \""
205
+                                    + jc.getSelectedFile().getName() + "\" "
206
+                                    + DCC.ipToLong(myPlugin.getListenIP(parser))
207
+                                    + " " + send.getPort() + " " + send.getFileSize()
208
+                                    + (send.isTurbo() ? " T" : ""));
175 209
                         } else {
176
-                            sendLine(origin, isSilent, "DCCSendError", "Unable to start dcc send with " + target + " - unable to create listen socket");
210
+                            sendLine(origin, isSilent, "DCCSendError",
211
+                                    "Unable to start dcc send with " + target
212
+                                    + " - unable to create listen socket");
177 213
                         }
178 214
                     }
179 215
                 }
@@ -184,43 +220,25 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
184 220
         dccThread.start();
185 221
     }
186 222
 
187
-    /**
188
-     * Returns this command's name.
189
-     *
190
-     * @return The name of this command
191
-     */
223
+    /** {@inheritDoc} */
192 224
     @Override
193 225
     public String getName() {
194 226
         return "dcc";
195 227
     }
196 228
 
197
-    /**
198
-     * Returns whether or not this command should be shown in help messages.
199
-     *
200
-     * @return True iff the command should be shown, false otherwise
201
-     */
229
+    /** {@inheritDoc} */
202 230
     @Override
203 231
     public boolean showInHelp() {
204 232
         return true;
205 233
     }
206 234
 
207
-    /**
208
-     * Returns a string representing the help message for this command.
209
-     *
210
-     * @return the help message for this command
211
-     */
235
+    /** {@inheritDoc} */
212 236
     @Override
213 237
     public String getHelp() {
214
-        return "dcc - Allows DCC";
238
+        return "dcc <SEND|CHAT> <target> [params] - Allows DCC";
215 239
     }
216 240
 
217
-    /**
218
-     * Returns a list of suggestions for the specified argument, given the list
219
-     * of previous arguments.
220
-     * @param arg The argument that is being completed
221
-     * @param previousArgs The contents of the previous arguments, if any
222
-     * @return A list of suggestions for the argument
223
-     */
241
+    /** {@inheritDoc} */
224 242
     @Override
225 243
     public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
226 244
         final AdditionalTabTargets res = new AdditionalTabTargets();

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

@@ -123,7 +123,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
123 123
      * @param sendFilename The name of the file which is being received
124 124
      * @param token Token used in reverse dcc.
125 125
      */
126
-    public void saveFile(final String nickname, final DCCSend send, final Parser parser, final boolean reverse, final String sendFilename, final String token) {
126
+    public void saveFile(final String nickname, final DCCTransfer send, final Parser parser, final boolean reverse, final String sendFilename, final String token) {
127 127
         // New thread to ask the user where to save in to stop us locking the UI
128 128
         final Thread dccThread = new Thread(new Runnable() {
129 129
 
@@ -163,7 +163,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
163 163
                         }
164 164
                     }
165 165
                     if (reverse && !token.isEmpty()) {
166
-                        new DCCSendWindow(DCCPlugin.this, send, "*Receive: " + nickname, nickname, null);
166
+                        new DCCTransferWindow(DCCPlugin.this, send, "*Receive: " + nickname, nickname, null);
167 167
                         send.setToken(token);
168 168
                         if (resume) {
169 169
                             if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "receive.reverse.sendtoken")) {
@@ -179,7 +179,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
179 179
                             }
180 180
                         }
181 181
                     } else {
182
-                        new DCCSendWindow(DCCPlugin.this, send, "Receive: " + nickname, nickname, null);
182
+                        new DCCTransferWindow(DCCPlugin.this, send, "Receive: " + nickname, nickname, null);
183 183
                         if (resume) {
184 184
                             parser.sendCTCP(nickname, "DCC", "RESUME " + sendFilename + " " + send.getPort() + " " + jc.getSelectedFile().length());
185 185
                         } else {
@@ -330,7 +330,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
330 330
                         return;
331 331
                     }
332 332
 
333
-                    DCCSend send = DCCSend.findByToken(token);
333
+                    DCCTransfer send = DCCTransfer.findByToken(token);
334 334
 
335 335
                     if (send == null && !dontAsk) {
336 336
                         if (!token.isEmpty() && !port.equals("0")) {
@@ -344,7 +344,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
344 344
                     } else {
345 345
                         final boolean newSend = send == null;
346 346
                         if (newSend) {
347
-                            send = new DCCSend(IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "send.blocksize"));
347
+                            send = new DCCTransfer(IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "send.blocksize"));
348 348
                             send.setTurbo(IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "send.forceturbo"));
349 349
                         }
350 350
                         try {
@@ -392,7 +392,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
392 392
                         final String token = (ctcpData.length - 1 > i) ? " " + ctcpData[++i] : "";
393 393
 
394 394
                         // Now look for a dcc that matches.
395
-                        for (DCCSend send : DCCSend.getSends()) {
395
+                        for (DCCTransfer send : DCCTransfer.getTransfers()) {
396 396
                             if (send.port == port && (new File(send.getFileName())).getName().equalsIgnoreCase(filename)) {
397 397
                                 if ((!token.isEmpty() && !send.getToken().isEmpty()) && (!token.equals(send.getToken()))) {
398 398
                                     continue;
@@ -638,7 +638,7 @@ class PlaceholderDCCFrame extends DCCFrame {
638 638
         int dccs = 0;
639 639
         for (Window window : windows) {
640 640
             if (window instanceof EmptyFrame) {
641
-                if (((DCCSendWindow)((EmptyFrame) window).getContainer()).getDCC().isActive()) {
641
+                if (((DCCTransferWindow)((EmptyFrame) window).getContainer()).getDCC().isActive()) {
642 642
                     dccs++;
643 643
                 }
644 644
             } else if (window instanceof DCCChatWindow) {

src/com/dmdirc/addons/dcc/DCCSend.java → src/com/dmdirc/addons/dcc/DCCTransfer.java View File

@@ -33,14 +33,14 @@ import java.util.ArrayList;
33 33
 import java.util.List;
34 34
 
35 35
 /**
36
- * This class handles a DCC Send.
36
+ * This class handles a DCC transfer.
37 37
  *
38 38
  * @author Shane 'Dataforce' McCormack
39 39
  */
40
-public class DCCSend extends DCC {
40
+public class DCCTransfer extends DCC {
41 41
 
42 42
     /** List of active sends. */
43
-    private static final List<DCCSend> SENDS = new ArrayList<DCCSend>();
43
+    private static final List<DCCTransfer> TRANSFERS = new ArrayList<DCCTransfer>();
44 44
 
45 45
     /** File Transfer Types. */
46 46
     public enum TransferType {
@@ -53,7 +53,7 @@ public class DCCSend extends DCC {
53 53
     private TransferType transferType = TransferType.RECEIVE;
54 54
 
55 55
     /** The handler for this DCCSend. */
56
-    private DCCSendInterface handler;
56
+    private DCCTransferHandler handler;
57 57
 
58 58
     /** Used to send data out the socket. */
59 59
     private DataOutputStream out;
@@ -93,21 +93,21 @@ public class DCCSend extends DCC {
93 93
 
94 94
     private boolean active = false;
95 95
 
96
-    /** Creates a new instance of DCCSend with a default block size. */
97
-    public DCCSend() {
96
+    /** Creates a new instance of DCCTransfer with a default block size. */
97
+    public DCCTransfer() {
98 98
         this(1024);
99 99
     }
100 100
 
101 101
     /**
102
-     * Creates a new instance of DCCSend.
102
+     * Creates a new instance of DCCTransfer.
103 103
      *
104 104
      * @param blockSize Block size to use
105 105
      */
106
-    public DCCSend(final int blockSize) {
106
+    public DCCTransfer(final int blockSize) {
107 107
         super();
108 108
         this.blockSize = blockSize;
109
-        synchronized (SENDS) {
110
-            SENDS.add(this);
109
+        synchronized (TRANSFERS) {
110
+            TRANSFERS.add(this);
111 111
         }
112 112
     }
113 113
 
@@ -125,18 +125,18 @@ public class DCCSend extends DCC {
125 125
      *
126 126
      * @return A copy of the list of active sends.
127 127
      */
128
-    public static List<DCCSend> getSends() {
129
-        synchronized (SENDS) {
130
-            return new ArrayList<DCCSend>(SENDS);
128
+    public static List<DCCTransfer> getTransfers() {
129
+        synchronized (TRANSFERS) {
130
+            return new ArrayList<DCCTransfer>(TRANSFERS);
131 131
         }
132 132
     }
133 133
 
134 134
     /**
135 135
      * Called to remove this object from the sends list.
136 136
      */
137
-    public void removeFromSends() {
138
-        synchronized (SENDS) {
139
-            SENDS.remove(this);
137
+    public void removeFromTransfers() {
138
+        synchronized (TRANSFERS) {
139
+            TRANSFERS.remove(this);
140 140
         }
141 141
     }
142 142
 
@@ -150,7 +150,8 @@ public class DCCSend extends DCC {
150 150
         if (transferType == TransferType.SEND) {
151 151
             transferFile = new File(filename);
152 152
             try {
153
-                fileIn = new DataInputStream(new FileInputStream(transferFile.getAbsolutePath()));
153
+                fileIn = new DataInputStream(new FileInputStream(
154
+                        transferFile.getAbsolutePath()));
154 155
             } catch (FileNotFoundException e) {
155 156
                 fileIn = null;
156 157
             } catch (SecurityException e) {
@@ -174,13 +175,13 @@ public class DCCSend extends DCC {
174 175
      * @return Filename without path
175 176
      */
176 177
     public String getShortFileName() {
177
-        return (new File(filename)).getName();
178
+        return new File(filename).getName();
178 179
     }
179 180
 
180 181
     /**
181 182
      * Set dcc Type.
182 183
      *
183
-     * @param type Type of DCC Send this is.
184
+     * @param type Type of DCC transfer this is.
184 185
      */
185 186
     public void setType(final TransferType type) {
186 187
         this.transferType = type;
@@ -189,7 +190,7 @@ public class DCCSend extends DCC {
189 190
     /**
190 191
      * Get dcc Type.
191 192
      *
192
-     * @return Type of DCC Send this is.
193
+     * @return Type of DCC transfer this is.
193 194
      */
194 195
     public TransferType getType() {
195 196
         return transferType;
@@ -241,11 +242,9 @@ public class DCCSend extends DCC {
241 242
      */
242 243
     public String makeToken() {
243 244
         String myToken = "";
244
-        boolean unique = true;
245 245
         do {
246 246
             myToken = Integer.toString(Math.abs((myToken + filename).hashCode()));
247
-            unique = (findByToken(myToken) == null);
248
-        } while (!unique);
247
+        } while (findByToken(myToken) != null);
249 248
         setToken(myToken);
250 249
         return myToken;
251 250
     }
@@ -254,16 +253,16 @@ public class DCCSend extends DCC {
254 253
      * Find a send based on a given token.
255 254
      *
256 255
      * @param token Token to look for. (case sensitive)
257
-     * @return The first DCCSend that matches the given token.
256
+     * @return The first DCCTransfer that matches the given token.
258 257
      *         null if none match, or token is "" or null.
259 258
      */
260
-    public static DCCSend findByToken(final String token) {
259
+    public static DCCTransfer findByToken(final String token) {
261 260
         if (token == null || token.isEmpty()) {
262 261
             return null;
263 262
         }
264
-        for (DCCSend send : getSends()) {
265
-            if (send.getToken().equals(token)) {
266
-                return send;
263
+        for (DCCTransfer transfer : getTransfers()) {
264
+            if (transfer.getToken().equals(token)) {
265
+                return transfer;
267 266
             }
268 267
         }
269 268
         return null;
@@ -291,7 +290,8 @@ public class DCCSend extends DCC {
291 290
      * Set the starting position of the file
292 291
      *
293 292
      * @param startpos Starting position
294
-     * @return -1 if fileIn is null or if dcc receive, else the result of fileIn.skipBytes()
293
+     * @return -1 if fileIn is null or if dcc receive, else the result of
294
+     * fileIn.skipBytes()
295 295
      */
296 296
     public int setFileStart(final int startpos) {
297 297
         this.startpos = startpos;
@@ -318,22 +318,21 @@ public class DCCSend extends DCC {
318 318
     /**
319 319
      * Change the handler for this DCC Send
320 320
      *
321
-     * @param handler A class implementing DCCSendInterface
321
+     * @param handler A class implementing DCCTransferHandler
322 322
      */
323
-    public void setHandler(final DCCSendInterface handler) {
323
+    public void setHandler(final DCCTransferHandler handler) {
324 324
         this.handler = handler;
325 325
     }
326 326
 
327
-    /**
328
-     * Called when the socket is first opened, before any data is handled.
329
-     */
327
+    /** {@inheritDoc} */
330 328
     @Override
331 329
     protected void socketOpened() {
332 330
         try {
333 331
             active = true;
334 332
             transferFile = new File(filename);
335 333
             if (transferType == TransferType.RECEIVE) {
336
-                fileOut = new DataOutputStream(new FileOutputStream(transferFile.getAbsolutePath(), (startpos > 0)));
334
+                fileOut = new DataOutputStream(new FileOutputStream(
335
+                        transferFile.getAbsolutePath(), (startpos > 0)));
337 336
             }
338 337
             out = new DataOutputStream(socket.getOutputStream());
339 338
             in = new DataInputStream(socket.getInputStream());
@@ -345,9 +344,7 @@ public class DCCSend extends DCC {
345 344
         }
346 345
     }
347 346
 
348
-    /**
349
-     * Called when the socket is closed, before the thread terminates.
350
-     */
347
+    /** {@inheritDoc} */
351 348
     @Override
352 349
     protected void socketClosed() {
353 350
         // Try to close both, even if one fails.
@@ -369,21 +366,17 @@ public class DCCSend extends DCC {
369 366
             handler.socketClosed(this);
370 367
         }
371 368
         // Try to delete empty files.
372
-        if (transferType == TransferType.RECEIVE && transferFile != null && transferFile.length() == 0) {
369
+        if (transferType == TransferType.RECEIVE && transferFile != null
370
+                && transferFile.length() == 0) {
373 371
             transferFile.delete();
374 372
         }
375
-        synchronized (SENDS) {
376
-            SENDS.remove(this);
373
+        synchronized (TRANSFERS) {
374
+            TRANSFERS.remove(this);
377 375
         }
378 376
         active = false;
379 377
     }
380 378
 
381
-    /**
382
-     * Handle the socket.
383
-     *
384
-     * @return false when socket is closed, true will cause the method to be
385
-     *         called again.
386
-     */
379
+    /** {@inheritDoc} */
387 380
     @Override
388 381
     protected boolean handleSocket() {
389 382
         if (out == null || in == null) {
@@ -399,8 +392,8 @@ public class DCCSend extends DCC {
399 392
     /**
400 393
      * Handle the socket as a RECEIVE.
401 394
      *
402
-     * @return false when socket is closed (or should be closed), true will cause the method to be
403
-     *         called again.
395
+     * @return false when socket is closed (or should be closed), true will
396
+     * cause the method to be called again.
404 397
      */
405 398
     protected boolean handleReceive() {
406 399
         try {
@@ -435,8 +428,8 @@ public class DCCSend extends DCC {
435 428
     /**
436 429
      * Handle the socket as a SEND.
437 430
      *
438
-     * @return false when socket is closed (or should be closed), true will cause the method to be
439
-     *         called again.
431
+     * @return false when socket is closed (or should be closed), true will
432
+     * cause the method to be called again.
440 433
      */
441 434
     protected boolean handleSend() {
442 435
         try {

src/com/dmdirc/addons/dcc/DCCSendInterface.java → src/com/dmdirc/addons/dcc/DCCTransferHandler.java View File

@@ -23,32 +23,33 @@
23 23
 package com.dmdirc.addons.dcc;
24 24
 
25 25
 /**
26
- * This interfaces allows DCC Send Windows to receive data from a DCCSend
26
+ * This interfaces allows DCC Transfer Windows to receive data from a
27
+ * DCCTransfer.
27 28
  *
28 29
  * @author Shane 'Dataforce' McCormack
29 30
  */
30
-public interface DCCSendInterface {
31
+public interface DCCTransferHandler {
31 32
 
32 33
     /**
33
-     * Called when the socket is closed
34
+     * Called when the socket is closed.
34 35
      *
35
-     * @param dcc The DCCSend that this message is from
36
+     * @param dcc The DCCTransfer that this message is from
36 37
      */
37
-    void socketClosed(final DCCSend dcc);
38
+    void socketClosed(final DCCTransfer dcc);
38 39
 
39 40
     /**
40
-     * Called when the socket is opened
41
+     * Called when the socket is opened.
41 42
      *
42
-     * @param dcc The DCCSend that this message is from
43
+     * @param dcc The DCCTransfer that this message is from
43 44
      */
44
-    void socketOpened(final DCCSend dcc);
45
+    void socketOpened(final DCCTransfer dcc);
45 46
 
46 47
     /**
47
-     * Called when data is sent/recieved
48
+     * Called when data is sent/recieved.
48 49
      *
49
-     * @param dcc The DCCSend that this message is from
50
+     * @param dcc The DCCTransfer that this message is from
50 51
      * @param bytes The number of new bytes that were transfered
51 52
      */
52
-    void dataTransfered(final DCCSend dcc, final int bytes);
53
+    void dataTransfered(final DCCTransfer dcc, final int bytes);
53 54
 
54 55
 }

src/com/dmdirc/addons/dcc/DCCSendWindow.java → src/com/dmdirc/addons/dcc/DCCTransferWindow.java View File

@@ -50,10 +50,11 @@ import net.miginfocom.swing.MigLayout;
50 50
  *
51 51
  * @author Shane 'Dataforce' McCormack
52 52
  */
53
-public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionListener, SocketCloseListener {
53
+public class DCCTransferWindow extends DCCFrame implements DCCTransferHandler,
54
+        ActionListener, SocketCloseListener {
54 55
 
55 56
     /** The DCCSend object we are a window for */
56
-    private final DCCSend dcc;
57
+    private final DCCTransfer dcc;
57 58
 
58 59
     /** Other Nickname */
59 60
     private final String otherNickname;
@@ -99,16 +100,18 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
99 100
             Desktop.getDesktop().isSupported(Desktop.Action.OPEN);
100 101
 
101 102
     /**
102
-     * Creates a new instance of DCCSendWindow with a given DCCSend object.
103
+     * Creates a new instance of DCCTransferWindow with a given DCCTransfer object.
103 104
      *
104 105
      * @param plugin the DCC Plugin responsible for this window
105
-     * @param dcc The DCCSend object this window wraps around
106
+     * @param dcc The DCCTransfer object this window wraps around
106 107
      * @param title The title of this window
107 108
      * @param targetNick Nickname of target
108 109
      * @param server The server that initiated this send
109 110
      */
110
-    public DCCSendWindow(final DCCPlugin plugin, final DCCSend dcc, final String title, final String targetNick, final Server server) {
111
-        super(plugin, title, dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-inactive" : "dcc-receive-inactive");
111
+    public DCCTransferWindow(final DCCPlugin plugin, final DCCTransfer dcc,
112
+            final String title, final String targetNick, final Server server) {
113
+        super(plugin, title, dcc.getType() == DCCTransfer.TransferType.SEND
114
+                ? "dcc-send-inactive" : "dcc-receive-inactive");
112 115
         this.dcc = dcc;
113 116
         this.server = server;
114 117
         this.parser = server == null ? null : server.getParser();
@@ -128,7 +131,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
128 131
         progress.setStringPainted(true);
129 132
         progress.setValue(0);
130 133
 
131
-        if (dcc.getType() == DCCSend.TransferType.SEND) {
134
+        if (dcc.getType() == DCCTransfer.TransferType.SEND) {
132 135
             getContentPane().add(new JLabel("Sending: " + dcc.getShortFileName()), "wrap");
133 136
             getContentPane().add(new JLabel("To: " + targetNick), "wrap");
134 137
         } else {
@@ -168,7 +171,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
168 171
      *
169 172
      * @return The DCCSend Object associated with this window
170 173
      */
171
-    public DCCSend getDCC() {
174
+    public DCCTransfer getDCC() {
172 175
         return dcc;
173 176
     }
174 177
 
@@ -180,7 +183,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
180 183
     @Override
181 184
     public void actionPerformed(final ActionEvent e) {
182 185
         if (e.getActionCommand().equals("Cancel")) {
183
-            if (dcc.getType() == DCCSend.TransferType.SEND) {
186
+            if (dcc.getType() == DCCTransfer.TransferType.SEND) {
184 187
                 button.setText("Resend");
185 188
             } else {
186 189
                 button.setText("Close Window");
@@ -204,18 +207,29 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
204 207
                         /** {@inheritDoc} */
205 208
                         @Override
206 209
                         public void run() {
207
-                            JOptionPane.showMessageDialog(null, "You can't DCC yourself.", "DCC Error", JOptionPane.ERROR_MESSAGE);
210
+                            JOptionPane.showMessageDialog(null,
211
+                                    "You can't DCC yourself.", "DCC Error",
212
+                                    JOptionPane.ERROR_MESSAGE);
208 213
                         }
209 214
 
210 215
                     });
211 216
                     errorThread.start();
212 217
                     return;
213 218
                 } else {
214
-                    if (IdentityManager.getGlobalConfig().getOptionBool(plugin.getDomain(), "send.reverse")) {
215
-                        parser.sendCTCP(otherNickname, "DCC", "SEND \"" + (new File(dcc.getFileName())).getName() + "\" " + DCC.ipToLong(myPlugin.getListenIP(parser)) + " 0 " + dcc.getFileSize() + " " + dcc.makeToken() + ((dcc.isTurbo()) ? " T" : ""));
219
+                    if (IdentityManager.getGlobalConfig().getOptionBool(
220
+                            plugin.getDomain(), "send.reverse")) {
221
+                        parser.sendCTCP(otherNickname, "DCC", "SEND \"" +
222
+                                new File(dcc.getFileName()).getName() + "\" "
223
+                                + DCC.ipToLong(myPlugin.getListenIP(parser))
224
+                                + " 0 " + dcc.getFileSize() + " " + dcc.makeToken()
225
+                                + ((dcc.isTurbo()) ? " T" : ""));
216 226
                         return;
217 227
                     } else if (plugin.listen(dcc)) {
218
-                        parser.sendCTCP(otherNickname, "DCC", "SEND \"" + (new File(dcc.getFileName())).getName() + "\" " + DCC.ipToLong(myPlugin.getListenIP(parser)) + " " + dcc.getPort() + " " + dcc.getFileSize() + ((dcc.isTurbo()) ? " T" : ""));
228
+                        parser.sendCTCP(otherNickname, "DCC", "SEND \""
229
+                                + new File(dcc.getFileName()).getName() + "\" "
230
+                                + DCC.ipToLong(myPlugin.getListenIP(parser)) + " "
231
+                                + dcc.getPort() + " " + dcc.getFileSize()
232
+                                + ((dcc.isTurbo()) ? " T" : ""));
219 233
                         return;
220 234
                     }
221 235
                 }
@@ -256,14 +270,14 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
256 270
      * @param bytes The number of new bytes that were transfered
257 271
      */
258 272
     @Override
259
-    public void dataTransfered(final DCCSend dcc, final int bytes) {
273
+    public void dataTransfered(final DCCTransfer dcc, final int bytes) {
260 274
         final double percent;
261 275
         synchronized (this) {
262 276
             transferCount += bytes;
263 277
             percent = (100.00 / dcc.getFileSize()) * (transferCount + dcc.getFileStart());
264 278
         }
265 279
 
266
-        if (dcc.getType() == DCCSend.TransferType.SEND) {
280
+        if (dcc.getType() == DCCTransfer.TransferType.SEND) {
267 281
             status.setText("Status: Sending");
268 282
         } else {
269 283
             status.setText("Status: Recieving");
@@ -298,10 +312,13 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
298 312
         synchronized (this) {
299 313
             remaningBytes = dcc.getFileSize() - dcc.getFileStart() - transferCount;
300 314
         }
301
-        final double remainingSeconds = (bytesPerSecond > 0) ? (remaningBytes / bytesPerSecond) : 1;
315
+        final double remainingSeconds = bytesPerSecond > 0
316
+                ? (remaningBytes / bytesPerSecond) : 1;
302 317
 
303
-        remaining.setText(String.format("Time Remaining: %s", duration((int) Math.floor(remainingSeconds))));
304
-        taken.setText(String.format("Time Taken: %s", timeStarted == 0 ? "N/A" : duration(time)));
318
+        remaining.setText(String.format("Time Remaining: %s", duration(
319
+                (int) Math.floor(remainingSeconds))));
320
+        taken.setText(String.format("Time Taken: %s", timeStarted == 0
321
+                ? "N/A" : duration(time)));
305 322
     }
306 323
 
307 324
     /**
@@ -330,23 +347,25 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
330 347
      * @param dcc The DCCSend that this message is from
331 348
      */
332 349
     @Override
333
-    public void socketClosed(final DCCSend dcc) {
350
+    public void socketClosed(final DCCTransfer dcc) {
334 351
         ActionManager.processEvent(DCCActions.DCC_SEND_SOCKETCLOSED, null, this);
335 352
         if (!isWindowClosing()) {
336 353
             synchronized (this) {
337 354
                 if (transferCount == dcc.getFileSize()) {
338 355
                     status.setText("Status: Transfer Compelete.");
339 356
 
340
-                    if (showOpen && dcc.getType() == DCCSend.TransferType.RECEIVE) {
357
+                    if (showOpen && dcc.getType() == DCCTransfer.TransferType.RECEIVE) {
341 358
                         openButton.setVisible(true);
342 359
                     }
343 360
                     progress.setValue(100);
344
-                    setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-done" : "dcc-receive-done");
361
+                    setIcon(dcc.getType() == DCCTransfer.TransferType.SEND
362
+                            ? "dcc-send-done" : "dcc-receive-done");
345 363
                     button.setText("Close Window");
346 364
                 } else {
347 365
                     status.setText("Status: Transfer Failed.");
348
-                    setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-failed" : "dcc-receive-failed");
349
-                    if (dcc.getType() == DCCSend.TransferType.SEND) {
366
+                    setIcon(dcc.getType() == DCCTransfer.TransferType.SEND
367
+                            ? "dcc-send-failed" : "dcc-receive-failed");
368
+                    if (dcc.getType() == DCCTransfer.TransferType.SEND) {
350 369
                         button.setText("Resend");
351 370
                     } else {
352 371
                         button.setText("Close Window");
@@ -363,11 +382,12 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
363 382
      * @param dcc The DCCSend that this message is from
364 383
      */
365 384
     @Override
366
-    public void socketOpened(final DCCSend dcc) {
385
+    public void socketOpened(final DCCTransfer dcc) {
367 386
         ActionManager.processEvent(DCCActions.DCC_SEND_SOCKETOPENED, null, this);
368 387
         status.setText("Status: Socket Opened");
369 388
         timeStarted = System.currentTimeMillis();
370
-        setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-active" : "dcc-receive-active");
389
+        setIcon(dcc.getType() == DCCTransfer.TransferType.SEND
390
+                ? "dcc-send-active" : "dcc-receive-active");
371 391
     }
372 392
 
373 393
     /**
@@ -376,7 +396,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
376 396
     @Override
377 397
     public void windowClosing() {
378 398
         super.windowClosing();
379
-        dcc.removeFromSends();
399
+        dcc.removeFromTransfers();
380 400
         dcc.close();
381 401
     }
382 402
 

+ 4
- 4
src/com/dmdirc/addons/dcc/actions/DCCEvents.java View File

@@ -26,7 +26,7 @@ import com.dmdirc.Server;
26 26
 import com.dmdirc.actions.interfaces.ActionMetaType;
27 27
 
28 28
 import com.dmdirc.addons.dcc.DCCChatWindow;
29
-import com.dmdirc.addons.dcc.DCCSendWindow;
29
+import com.dmdirc.addons.dcc.DCCTransferWindow;
30 30
 
31 31
 import java.io.File;
32 32
 
@@ -50,11 +50,11 @@ public enum DCCEvents implements ActionMetaType {
50 50
     /** DCC Chat Socket Opened. */
51 51
     DCC_CHAT_SOCKETOPENED(new String[]{"DCCChatWindow"}, DCCChatWindow.class),
52 52
     /** DCC Send Socket Closed. */
53
-    DCC_SEND_SOCKETCLOSED(new String[]{"DCCSendWindow"}, DCCSendWindow.class),
53
+    DCC_SEND_SOCKETCLOSED(new String[]{"DCCSendWindow"}, DCCTransferWindow.class),
54 54
     /** DCC Send Socket Opened. */
55
-    DCC_SEND_SOCKETOPENED(new String[]{"DCCSendWindow"}, DCCSendWindow.class),
55
+    DCC_SEND_SOCKETOPENED(new String[]{"DCCSendWindow"}, DCCTransferWindow.class),
56 56
     /** DCC Send Data Transfered */
57
-    DCC_SEND_DATATRANSFERED(new String[]{"DCCSendWindow", "Bytes Transfered"}, DCCSendWindow.class, int.class),
57
+    DCC_SEND_DATATRANSFERED(new String[]{"DCCSendWindow", "Bytes Transfered"}, DCCTransferWindow.class, int.class),
58 58
     /** DCC Send Request. */
59 59
     DCC_SEND_REQUEST(new String[]{"server", "client", "file"}, Server.class, String.class, String.class),
60 60
     /** DCC Send Request Sent. */

Loading…
Cancel
Save