|
@@ -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
|
}
|