Parcourir la source

Use events for showconfig in DCC Plugin.

pull/286/head
Greg Holmes il y a 9 ans
Parent
révision
e40828bb27

+ 77
- 5
dcc/src/com/dmdirc/addons/dcc/DCCManager.java Voir le fichier

41
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
41
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
42
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
42
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
43
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
43
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
44
+import com.dmdirc.config.prefs.PluginPreferencesCategory;
45
+import com.dmdirc.config.prefs.PreferencesCategory;
46
+import com.dmdirc.config.prefs.PreferencesDialogModel;
47
+import com.dmdirc.config.prefs.PreferencesSetting;
48
+import com.dmdirc.config.prefs.PreferencesType;
49
+import com.dmdirc.events.ClientPrefsOpenedEvent;
44
 import com.dmdirc.events.ServerCtcpEvent;
50
 import com.dmdirc.events.ServerCtcpEvent;
45
 import com.dmdirc.events.UserErrorEvent;
51
 import com.dmdirc.events.UserErrorEvent;
46
 import com.dmdirc.interfaces.CommandController;
52
 import com.dmdirc.interfaces.CommandController;
56
 import com.dmdirc.ui.input.TabCompleterFactory;
62
 import com.dmdirc.ui.input.TabCompleterFactory;
57
 import com.dmdirc.ui.messages.BackBufferFactory;
63
 import com.dmdirc.ui.messages.BackBufferFactory;
58
 import com.dmdirc.ui.messages.sink.MessageSinkManager;
64
 import com.dmdirc.ui.messages.sink.MessageSinkManager;
59
-import com.dmdirc.util.URLBuilder;
60
 
65
 
61
 import com.google.common.collect.Lists;
66
 import com.google.common.collect.Lists;
62
 
67
 
66
 import java.io.IOException;
71
 import java.io.IOException;
67
 import java.net.InetAddress;
72
 import java.net.InetAddress;
68
 import java.net.UnknownHostException;
73
 import java.net.UnknownHostException;
69
-import java.util.Arrays;
74
+import java.util.Collections;
70
 import java.util.HashSet;
75
 import java.util.HashSet;
71
 import java.util.Set;
76
 import java.util.Set;
72
 import java.util.function.Supplier;
77
 import java.util.function.Supplier;
104
     private final String domain;
109
     private final String domain;
105
     /** The bus to dispatch events on. */
110
     /** The bus to dispatch events on. */
106
     private final DMDircMBassador eventBus;
111
     private final DMDircMBassador eventBus;
112
+    /** Plugin info. */
113
+    private final PluginInfo pluginInfo;
107
 
114
 
108
     /**
115
     /**
109
      * Creates a new instance of this plugin.
116
      * Creates a new instance of this plugin.
120
             final TabCompleterFactory tabCompleterFactory,
127
             final TabCompleterFactory tabCompleterFactory,
121
             final SwingWindowFactory windowFactory,
128
             final SwingWindowFactory windowFactory,
122
             final ComponentFrameFactory componentFrameFactory,
129
             final ComponentFrameFactory componentFrameFactory,
123
-            final URLBuilder urlBuilder,
124
             final DMDircMBassador eventBus,
130
             final DMDircMBassador eventBus,
125
             final GlobalCommandParser commandParser,
131
             final GlobalCommandParser commandParser,
126
             @Directory(DirectoryType.BASE) final String baseDirectory,
132
             @Directory(DirectoryType.BASE) final String baseDirectory,
130
         this.windowManager = windowManager;
136
         this.windowManager = windowManager;
131
         this.commandController = commandController;
137
         this.commandController = commandController;
132
         this.tabCompleterFactory = tabCompleterFactory;
138
         this.tabCompleterFactory = tabCompleterFactory;
139
+        this.pluginInfo = pluginInfo;
133
         this.domain = pluginInfo.getDomain();
140
         this.domain = pluginInfo.getDomain();
134
         this.config = globalConfig;
141
         this.config = globalConfig;
135
         this.eventBus = eventBus;
142
         this.eventBus = eventBus;
146
 
153
 
147
                     @Override
154
                     @Override
148
                     public Set<String> getComponents() {
155
                     public Set<String> getComponents() {
149
-                        return new HashSet<>(Arrays.asList(
156
+                        return new HashSet<>(Collections.singletonList(
150
                                 "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
157
                                 "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
151
                     }
158
                     }
152
                 });
159
                 });
161
 
168
 
162
                     @Override
169
                     @Override
163
                     public Set<String> getComponents() {
170
                     public Set<String> getComponents() {
164
-                        return new HashSet<>(Arrays.asList(
171
+                        return new HashSet<>(Collections.singletonList(
165
                                 "com.dmdirc.addons.dcc.ui.TransferPanel"));
172
                                 "com.dmdirc.addons.dcc.ui.TransferPanel"));
166
                     }
173
                     }
167
                 });
174
                 });
171
                 baseDirectory + "downloads" + File.separator);
178
                 baseDirectory + "downloads" + File.separator);
172
     }
179
     }
173
 
180
 
181
+    @Handler
182
+    public void handlePrefsOpened(final ClientPrefsOpenedEvent event) {
183
+        final PreferencesDialogModel manager = event.getModel();
184
+        final PreferencesCategory general = new PluginPreferencesCategory(
185
+                pluginInfo, "DCC", "", "category-dcc");
186
+        final PreferencesCategory firewall = new PluginPreferencesCategory(
187
+                pluginInfo, "Firewall", "");
188
+        final PreferencesCategory sending = new PluginPreferencesCategory(
189
+                pluginInfo, "Sending", "");
190
+        final PreferencesCategory receiving = new PluginPreferencesCategory(
191
+                pluginInfo, "Receiving", "");
192
+
193
+        manager.getCategory("Plugins").addSubCategory(general.setInlineAfter());
194
+        general.addSubCategory(firewall.setInline());
195
+        general.addSubCategory(sending.setInline());
196
+        general.addSubCategory(receiving.setInline());
197
+
198
+        firewall.addSetting(new PreferencesSetting(PreferencesType.TEXT,
199
+                pluginInfo.getDomain(), "firewall.ip", "Forced IP",
200
+                "What IP should be sent as our IP (Blank = work it out)",
201
+                manager.getConfigManager(), manager.getIdentity()));
202
+        firewall.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
203
+                pluginInfo.getDomain(), "firewall.ports.usePortRange", "Use Port Range",
204
+                "Useful if you have a firewall that only forwards specific "
205
+                        + "ports", manager.getConfigManager(), manager.getIdentity()));
206
+        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
207
+                pluginInfo.getDomain(), "firewall.ports.startPort", "Start Port",
208
+                "Port to try to listen on first", manager.getConfigManager(),
209
+                manager.getIdentity()));
210
+        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
211
+                pluginInfo.getDomain(), "firewall.ports.endPort", "End Port",
212
+                "Port to try to listen on last", manager.getConfigManager(),
213
+                manager.getIdentity()));
214
+        receiving.addSetting(new PreferencesSetting(PreferencesType.DIRECTORY,
215
+                pluginInfo.getDomain(), "receive.savelocation", "Default save location",
216
+                "Where the save as window defaults to?",
217
+                manager.getConfigManager(), manager.getIdentity()));
218
+        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
219
+                pluginInfo.getDomain(), "send.reverse", "Reverse DCC",
220
+                "With reverse DCC, the sender connects rather than "
221
+                        + "listens like normal dcc", manager.getConfigManager(),
222
+                manager.getIdentity()));
223
+        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
224
+                pluginInfo.getDomain(), "send.forceturbo", "Use Turbo DCC",
225
+                "Turbo DCC doesn't wait for ack packets. this is "
226
+                        + "faster but not always supported.",
227
+                manager.getConfigManager(), manager.getIdentity()));
228
+        receiving.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
229
+                pluginInfo.getDomain(), "receive.reverse.sendtoken",
230
+                "Send token in reverse receive",
231
+                "If you have problems with reverse dcc receive resume,"
232
+                        + " try toggling this.", manager.getConfigManager(),
233
+                manager.getIdentity()));
234
+        general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
235
+                pluginInfo.getDomain(), "send.blocksize", "Blocksize to use for DCC",
236
+                "Change the block size for send/receive, this can "
237
+                        + "sometimes speed up transfers.", manager.getConfigManager(),
238
+                manager.getIdentity()));
239
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
240
+                pluginInfo.getDomain(), "general.percentageInTitle",
241
+                "Show percentage of transfers in the window title",
242
+                "Show the current percentage of transfers in the DCC window "
243
+                        + "title", manager.getConfigManager(), manager.getIdentity()));
244
+    }
245
+
174
     public String getDomain() {
246
     public String getDomain() {
175
         return domain;
247
         return domain;
176
     }
248
     }

+ 0
- 74
dcc/src/com/dmdirc/addons/dcc/DCCPlugin.java Voir le fichier

22
 
22
 
23
 package com.dmdirc.addons.dcc;
23
 package com.dmdirc.addons.dcc;
24
 
24
 
25
-import com.dmdirc.config.prefs.PluginPreferencesCategory;
26
-import com.dmdirc.config.prefs.PreferencesCategory;
27
-import com.dmdirc.config.prefs.PreferencesDialogModel;
28
-import com.dmdirc.config.prefs.PreferencesSetting;
29
-import com.dmdirc.config.prefs.PreferencesType;
30
 import com.dmdirc.plugins.PluginInfo;
25
 import com.dmdirc.plugins.PluginInfo;
31
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
32
 
27
 
37
  */
32
  */
38
 public class DCCPlugin extends BaseCommandPlugin {
33
 public class DCCPlugin extends BaseCommandPlugin {
39
 
34
 
40
-    private final PluginInfo pluginInfo;
41
     private DCCManager dccManager;
35
     private DCCManager dccManager;
42
 
36
 
43
-    public DCCPlugin(final PluginInfo pluginInfo) {
44
-        this.pluginInfo = pluginInfo;
45
-    }
46
-
47
     @Override
37
     @Override
48
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
38
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
49
         super.load(pluginInfo, graph);
39
         super.load(pluginInfo, graph);
65
         dccManager.onUnload();
55
         dccManager.onUnload();
66
     }
56
     }
67
 
57
 
68
-    @Override
69
-    public void showConfig(final PreferencesDialogModel manager) {
70
-        final PreferencesCategory general = new PluginPreferencesCategory(
71
-                pluginInfo, "DCC", "", "category-dcc");
72
-        final PreferencesCategory firewall = new PluginPreferencesCategory(
73
-                pluginInfo, "Firewall", "");
74
-        final PreferencesCategory sending = new PluginPreferencesCategory(
75
-                pluginInfo, "Sending", "");
76
-        final PreferencesCategory receiving = new PluginPreferencesCategory(
77
-                pluginInfo, "Receiving", "");
78
-
79
-        manager.getCategory("Plugins").addSubCategory(general.setInlineAfter());
80
-        general.addSubCategory(firewall.setInline());
81
-        general.addSubCategory(sending.setInline());
82
-        general.addSubCategory(receiving.setInline());
83
-
84
-        firewall.addSetting(new PreferencesSetting(PreferencesType.TEXT,
85
-                pluginInfo.getDomain(), "firewall.ip", "Forced IP",
86
-                "What IP should be sent as our IP (Blank = work it out)",
87
-                manager.getConfigManager(), manager.getIdentity()));
88
-        firewall.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
89
-                pluginInfo.getDomain(), "firewall.ports.usePortRange", "Use Port Range",
90
-                "Useful if you have a firewall that only forwards specific "
91
-                + "ports", manager.getConfigManager(), manager.getIdentity()));
92
-        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
93
-                pluginInfo.getDomain(), "firewall.ports.startPort", "Start Port",
94
-                "Port to try to listen on first", manager.getConfigManager(),
95
-                manager.getIdentity()));
96
-        firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
97
-                pluginInfo.getDomain(), "firewall.ports.endPort", "End Port",
98
-                "Port to try to listen on last", manager.getConfigManager(),
99
-                manager.getIdentity()));
100
-        receiving.addSetting(new PreferencesSetting(PreferencesType.DIRECTORY,
101
-                pluginInfo.getDomain(), "receive.savelocation", "Default save location",
102
-                "Where the save as window defaults to?",
103
-                manager.getConfigManager(), manager.getIdentity()));
104
-        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
105
-                pluginInfo.getDomain(), "send.reverse", "Reverse DCC",
106
-                "With reverse DCC, the sender connects rather than "
107
-                + "listens like normal dcc", manager.getConfigManager(),
108
-                manager.getIdentity()));
109
-        sending.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
110
-                pluginInfo.getDomain(), "send.forceturbo", "Use Turbo DCC",
111
-                "Turbo DCC doesn't wait for ack packets. this is "
112
-                + "faster but not always supported.",
113
-                manager.getConfigManager(), manager.getIdentity()));
114
-        receiving.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
115
-                pluginInfo.getDomain(), "receive.reverse.sendtoken",
116
-                "Send token in reverse receive",
117
-                "If you have problems with reverse dcc receive resume,"
118
-                + " try toggling this.", manager.getConfigManager(),
119
-                manager.getIdentity()));
120
-        general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
121
-                pluginInfo.getDomain(), "send.blocksize", "Blocksize to use for DCC",
122
-                "Change the block size for send/receive, this can "
123
-                + "sometimes speed up transfers.", manager.getConfigManager(),
124
-                manager.getIdentity()));
125
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
126
-                pluginInfo.getDomain(), "general.percentageInTitle",
127
-                "Show percentage of transfers in the window title",
128
-                "Show the current percentage of transfers in the DCC window "
129
-                + "title", manager.getConfigManager(), manager.getIdentity()));
130
-    }
131
-
132
 }
58
 }

Chargement…
Annuler
Enregistrer