Przeglądaj źródła

Use events for showconfig in DCC Plugin.

pull/286/head
Greg Holmes 9 lat temu
rodzic
commit
e40828bb27

+ 77
- 5
dcc/src/com/dmdirc/addons/dcc/DCCManager.java Wyświetl plik

@@ -41,6 +41,12 @@ import com.dmdirc.addons.ui_swing.injection.MainWindow;
41 41
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
42 42
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
43 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 50
 import com.dmdirc.events.ServerCtcpEvent;
45 51
 import com.dmdirc.events.UserErrorEvent;
46 52
 import com.dmdirc.interfaces.CommandController;
@@ -56,7 +62,6 @@ import com.dmdirc.ui.WindowManager;
56 62
 import com.dmdirc.ui.input.TabCompleterFactory;
57 63
 import com.dmdirc.ui.messages.BackBufferFactory;
58 64
 import com.dmdirc.ui.messages.sink.MessageSinkManager;
59
-import com.dmdirc.util.URLBuilder;
60 65
 
61 66
 import com.google.common.collect.Lists;
62 67
 
@@ -66,7 +71,7 @@ import java.io.File;
66 71
 import java.io.IOException;
67 72
 import java.net.InetAddress;
68 73
 import java.net.UnknownHostException;
69
-import java.util.Arrays;
74
+import java.util.Collections;
70 75
 import java.util.HashSet;
71 76
 import java.util.Set;
72 77
 import java.util.function.Supplier;
@@ -104,6 +109,8 @@ public class DCCManager {
104 109
     private final String domain;
105 110
     /** The bus to dispatch events on. */
106 111
     private final DMDircMBassador eventBus;
112
+    /** Plugin info. */
113
+    private final PluginInfo pluginInfo;
107 114
 
108 115
     /**
109 116
      * Creates a new instance of this plugin.
@@ -120,7 +127,6 @@ public class DCCManager {
120 127
             final TabCompleterFactory tabCompleterFactory,
121 128
             final SwingWindowFactory windowFactory,
122 129
             final ComponentFrameFactory componentFrameFactory,
123
-            final URLBuilder urlBuilder,
124 130
             final DMDircMBassador eventBus,
125 131
             final GlobalCommandParser commandParser,
126 132
             @Directory(DirectoryType.BASE) final String baseDirectory,
@@ -130,6 +136,7 @@ public class DCCManager {
130 136
         this.windowManager = windowManager;
131 137
         this.commandController = commandController;
132 138
         this.tabCompleterFactory = tabCompleterFactory;
139
+        this.pluginInfo = pluginInfo;
133 140
         this.domain = pluginInfo.getDomain();
134 141
         this.config = globalConfig;
135 142
         this.eventBus = eventBus;
@@ -146,7 +153,7 @@ public class DCCManager {
146 153
 
147 154
                     @Override
148 155
                     public Set<String> getComponents() {
149
-                        return new HashSet<>(Arrays.asList(
156
+                        return new HashSet<>(Collections.singletonList(
150 157
                                 "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
151 158
                     }
152 159
                 });
@@ -161,7 +168,7 @@ public class DCCManager {
161 168
 
162 169
                     @Override
163 170
                     public Set<String> getComponents() {
164
-                        return new HashSet<>(Arrays.asList(
171
+                        return new HashSet<>(Collections.singletonList(
165 172
                                 "com.dmdirc.addons.dcc.ui.TransferPanel"));
166 173
                     }
167 174
                 });
@@ -171,6 +178,71 @@ public class DCCManager {
171 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 246
     public String getDomain() {
175 247
         return domain;
176 248
     }

+ 0
- 74
dcc/src/com/dmdirc/addons/dcc/DCCPlugin.java Wyświetl plik

@@ -22,11 +22,6 @@
22 22
 
23 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 25
 import com.dmdirc.plugins.PluginInfo;
31 26
 import com.dmdirc.plugins.implementations.BaseCommandPlugin;
32 27
 
@@ -37,13 +32,8 @@ import dagger.ObjectGraph;
37 32
  */
38 33
 public class DCCPlugin extends BaseCommandPlugin {
39 34
 
40
-    private final PluginInfo pluginInfo;
41 35
     private DCCManager dccManager;
42 36
 
43
-    public DCCPlugin(final PluginInfo pluginInfo) {
44
-        this.pluginInfo = pluginInfo;
45
-    }
46
-
47 37
     @Override
48 38
     public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
49 39
         super.load(pluginInfo, graph);
@@ -65,68 +55,4 @@ public class DCCPlugin extends BaseCommandPlugin {
65 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
 }

Ładowanie…
Anuluj
Zapisz