Browse Source

DCC Plugin now has a resend button if the transfer is cancelled (sends only), or a close button if it completes.

Fixes issue 1290
Fixes issue 1291


git-svn-id: http://svn.dmdirc.com/trunk@4156 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack 16 years ago
parent
commit
25805a4d9a

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

@@ -146,11 +146,11 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
146 146
 					send.setFileSize(jc.getSelectedFile().length());
147 147
 					
148 148
 					if (IdentityManager.getGlobalConfig().getOptionBool(DCCPlugin.getDomain(), "send.reverse", false)) {
149
-						new DCCSendWindow(myPlugin, send, "Send: "+target, myNickname, target);
149
+						new DCCSendWindow(myPlugin, send, "Send: "+target, myNickname, target, parser);
150 150
 						parser.sendCTCP(target, "DCC", "SEND \""+jc.getSelectedFile().getName()+"\" "+DCC.ipToLong(DCCPlugin.getListenIP(parser))+" 0 "+send.getFileSize()+" "+send.makeToken()+((send.isTurbo()) ? " T" : ""));
151 151
 					} else {
152 152
 						if (myPlugin.listen(send)) {
153
-							new DCCSendWindow(myPlugin, send, "*Send: "+target, myNickname, target);
153
+							new DCCSendWindow(myPlugin, send, "*Send: "+target, myNickname, target, parser);
154 154
 							parser.sendCTCP(target, "DCC", "SEND \""+jc.getSelectedFile().getName()+"\" "+DCC.ipToLong(DCCPlugin.getListenIP(parser))+" "+send.getPort()+" "+send.getFileSize()+((send.isTurbo()) ? " T" : ""));
155 155
 						} else {
156 156
 							sendLine(origin, isSilent, "DCCSendError", "Unable to start dcc send with "+target+" - unable to create listen socket");

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

@@ -162,7 +162,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
162 162
 						}
163 163
 					}
164 164
 					if (reverse && !token.isEmpty()) {
165
-						new DCCSendWindow(DCCPlugin.this, send, "*Receive: "+nickname, parser.getMyNickname(), nickname);
165
+						new DCCSendWindow(DCCPlugin.this, send, "*Receive: "+nickname, parser.getMyNickname(), nickname, null);
166 166
 						send.setToken(token);
167 167
 						if (resume) {
168 168
 							if (IdentityManager.getGlobalConfig().getOptionBool(MY_DOMAIN, "receive.reverse.sendtoken", true)) {
@@ -178,7 +178,7 @@ public final class DCCPlugin extends Plugin implements ActionListener {
178 178
 							}
179 179
 						}
180 180
 					} else {
181
-						new DCCSendWindow(DCCPlugin.this, send, "Receive: "+nickname, parser.getMyNickname(), nickname);
181
+						new DCCSendWindow(DCCPlugin.this, send, "Receive: "+nickname, parser.getMyNickname(), nickname, null);
182 182
 						if (resume) {
183 183
 							parser.sendCTCP(nickname, "DCC", "RESUME "+sendFilename+" "+send.getPort()+" "+jc.getSelectedFile().length());
184 184
 						} else {

+ 9
- 0
src/com/dmdirc/addons/dcc/DCCSend.java View File

@@ -91,6 +91,15 @@ public class DCCSend extends DCC {
91 91
 		}
92 92
 	}
93 93
 	
94
+	/**
95
+	 * Reset this send to be used again (eg a resend).
96
+	 */
97
+	public void reset() {
98
+		close();
99
+		setFileName(filename);
100
+		setFileStart(startpos);
101
+	}
102
+	
94 103
 	/**
95 104
 	 * Get a copy of the list of active sends.
96 105
 	 *

+ 53
- 5
src/com/dmdirc/addons/dcc/DCCSendWindow.java View File

@@ -24,7 +24,7 @@ package com.dmdirc.addons.dcc;
24 24
 
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.addons.dcc.actions.DCCActions;
27
-
27
+import com.dmdirc.config.IdentityManager;
28 28
 import com.dmdirc.ui.swing.components.TextFrame;
29 29
 import com.dmdirc.ui.swing.components.TextLabel;
30 30
 
@@ -38,13 +38,16 @@ import java.awt.event.ActionListener;
38 38
 
39 39
 import net.miginfocom.swing.MigLayout;
40 40
 
41
+import com.dmdirc.parser.IRCParser;
42
+import com.dmdirc.parser.callbacks.interfaces.ISocketClosed;
43
+
41 44
 /**
42 45
  * This class links DCC Send objects to a window.
43 46
  *
44 47
  * @author Shane 'Dataforce' McCormack
45 48
  * @version $Id: DCC.java 969 2007-04-30 18:38:20Z ShaneMcC $
46 49
  */
47
-public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionListener {
50
+public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionListener, ISocketClosed {
48 51
 	/** The DCCSend object we are a window for */
49 52
 	private final DCCSend dcc;
50 53
 	
@@ -78,6 +81,9 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
78 81
 	/** Button */
79 82
 	private final JButton button = new JButton("Cancel");
80 83
 	
84
+	/** IRC Parser that caused this send */
85
+	private IRCParser parser = null;
86
+	
81 87
 	/**
82 88
 	 * Creates a new instance of DCCSendWindow with a given DCCSend object.
83 89
 	 *
@@ -86,10 +92,13 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
86 92
 	 * @param title The title of this window
87 93
 	 * @param nick My Current Nickname
88 94
 	 * @param targetNick Nickname of target
95
+	 * @param parser The IRC parser that initiated this send
89 96
 	 */
90
-	public DCCSendWindow(final DCCPlugin plugin, final DCCSend dcc, final String title, final String nick, final String targetNick) {
97
+	public DCCSendWindow(final DCCPlugin plugin, final DCCSend dcc, final String title, final String nick, final String targetNick, final IRCParser parser) {
91 98
 		super(plugin, title, dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-inactive" : "dcc-receive-inactive");
92 99
 		this.dcc = dcc;
100
+		this.parser = parser;
101
+		parser.getCallbackManager().addNonCriticalCallback("onSocketClosed", this);
93 102
 		dcc.setHandler(this);
94 103
 		nickname = nick;
95 104
 		otherNickname = targetNick;
@@ -120,6 +129,17 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
120 129
 		plugin.addWindow(this);
121 130
 	}
122 131
 	
132
+	/** {@inheritDoc} */
133
+	public void onSocketClosed(final IRCParser tParser) {
134
+		// Remove our reference to the parser (and its reference to us)
135
+		parser.getCallbackManager().delAllCallback(this);
136
+		parser = null;
137
+		// Can't resend without the parser.
138
+		if (button.getText() == "Resend") {
139
+			button.setText("Close Window");
140
+		}
141
+	}
142
+	
123 143
 	/**
124 144
 	 * Get the DCCSend Object associated with this window
125 145
 	 *
@@ -132,8 +152,31 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
132 152
 	/** {@inheritDoc} */
133 153
 	public void actionPerformed(final ActionEvent e) {
134 154
 		if (e.getActionCommand().equals("Cancel")) {
135
-			button.setEnabled(false);
155
+			if (dcc.getType() == DCCSend.TransferType.SEND) {
156
+				button.setText("Resend");
157
+			} else {
158
+				button.setText("Close Window");
159
+			}
136 160
 			dcc.close();
161
+		} else if (e.getActionCommand().equals("Resend")) {
162
+			button.setText("Cancel");
163
+			status.setText("Status: Resending...");
164
+			transferCount = 0;
165
+			dcc.reset();
166
+			if (parser != null && parser.getSocketState() == IRCParser.STATE_OPEN) {
167
+				if (IdentityManager.getGlobalConfig().getOptionBool(DCCPlugin.getDomain(), "send.reverse", false)) {
168
+					parser.sendCTCP(otherNickname, "DCC", "SEND \""+dcc.getFileName()+"\" "+DCC.ipToLong(DCCPlugin.getListenIP(parser))+" 0 "+dcc.getFileSize()+" "+dcc.makeToken()+((dcc.isTurbo()) ? " T" : ""));
169
+					return;
170
+				} else if (plugin.listen(dcc)) {
171
+					parser.sendCTCP(otherNickname, "DCC", "SEND \""+dcc.getFileName()+"\" "+DCC.ipToLong(DCCPlugin.getListenIP(parser))+" "+dcc.getPort()+" "+dcc.getFileSize()+((dcc.isTurbo()) ? " T" : ""));
172
+					return;
173
+				}
174
+			} else {
175
+				status.setText("Status: Resend failed.");
176
+				button.setText("Close Window");
177
+			}
178
+		} else if (e.getActionCommand().equals("Close Window")) {
179
+			close();
137 180
 		}
138 181
 	}
139 182
 	
@@ -209,14 +252,19 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
209 252
 	public void socketClosed(final DCCSend dcc) {
210 253
 		ActionManager.processEvent(DCCActions.DCC_SEND_SOCKETCLOSED, null, this);
211 254
 		if (!isWindowClosing()) {
212
-			button.setEnabled(false);
213 255
 			if (transferCount == dcc.getFileSize()) {
214 256
 				status.setText("Status: Transfer Compelete.");
215 257
 				progress.setValue(100);
216 258
 				setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-done" : "dcc-receive-done");
259
+				button.setText("Close Window");
217 260
 			} else {
218 261
 				status.setText("Status: Transfer Failed.");
219 262
 				setIcon(dcc.getType() == DCCSend.TransferType.SEND ? "dcc-send-failed" : "dcc-receive-failed");
263
+				if (dcc.getType() == DCCSend.TransferType.SEND) {
264
+					button.setText("Resend");
265
+				} else {
266
+					button.setText("Close Window");
267
+				}
220 268
 			}
221 269
 			updateSpeedAndTime();
222 270
 		}

Loading…
Cancel
Save