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