1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.util;
21
22 import org.xnap.plugin.opennap.OpenNapPlugin;
23 import org.xnap.util.AbstractPluginPreferences;
24 import org.xnap.util.FileHelper;
25 import org.xnap.util.Preferences;
26 import org.xnap.util.prefs.IntValidator;
27 import org.xnap.util.prefs.PortRangeValidator;
28
29 /***
30 * Provides the preferences for the {@link OpenNapPlugin}. This class should
31 * only be instanziated once. Use {@link OpenNapPlugin.getPreferences()} to
32 * access that instance.
33 *
34 * <p>If you hack around, make sure all pathes are returned with a trailing
35 * file separator and all values are initialized to something other than
36 * null.
37 *
38 * <p>Most important, keep all preferences sorted alphabetically everywhere.
39 */
40 public class OpenNapPreferences extends AbstractPluginPreferences {
41
42
43
44 public static final int VERSION = 9;
45
46
47
48
49
50 public OpenNapPreferences()
51 {
52 super("plugin.nap", VERSION);
53
54 String defaultClientInfo
55 = "XNap " + OpenNapPlugin.getInstance().getInfo().getVersion();
56
57 setDefault("autoFetchNapigator", "true");
58 setDefault("autoFetchNapigatorInterval", "24");
59 setDefault("autoLoadNapigator", "true");
60 setDefault("autoResumeDownloads", "false");
61 setDefault("autoResumeConnectedCount", "5");
62 setDefault("autoSaveNapigator", "true");
63 setDefault("clientInfo", defaultClientInfo);
64 setDefault("customizeClientInfo", "false");
65 setDefault("fakeNetworks", "n/a");
66 setDefault("filterNetworks", "OpenNapster");
67 setDefault("firewalled", "false");
68 setDefault("hotlistUsers", "");
69 setDefault("limitSearchResultsPerServer", "false");
70 setDefault("limitSearchServers", "false");
71 setDefault("limitSharesPerServer", "false");
72 setDefault("localPort", "6600-6700", new PortRangeValidator());
73 setDefault("maxAutoconnectServers", "10");
74 setDefault("maxLoginsPerNetwork", "1");
75 setDefault("maxPacketsPerTick", "50");
76 setDefault("maxSearchResultsPerServer", "200",
77 new IntValidator(0, Integer.MAX_VALUE));
78 setDefault("maxSearchServers", "5");
79 setDefault("maxSharesPerServer", "500");
80 setDefault("multiSourceDownloading", "false");
81 setDefault("napigatorFile", FileHelper.getHomeDir()
82 + "napigator_hosts");
83 setDefault("napigatorURL",
84 "http://www.gotnap.com/servers.txt\n"
85 + "http://naplist.com/servers.txt\n"
86 + "#http://www.napigator.com/servers.php?version=112&client=napigator\n");
87 setDefault("removeFailedServers", "false");
88 setDefault("seenStartupWizard", "false");
89 setDefault("sendWholeRepository", "false");
90 setDefault("serverFile", FileHelper.getHomeDir() + "hosts");
91 setDefault("serverTableColumns",
92 "name;status;localPort;version;files;size;users");
93 setDefault("startupDialogShow", "false");
94 setDefault("useAutoconnector", "true");
95 setDefault("useUTF8Encoding", "true");
96 setDefault("tickLength", "100");
97 setDefault("whoisQueryOnTransfer", "false");
98 setDefault("whoisTableColumns",
99 "user;server;fileCount;linkSpeed;level;status;downloads;uploads;client;lastSeen;online");
100
101 if (!getCustomizeClientInfo()) {
102 setClientInfo(defaultClientInfo);
103 }
104 }
105
106
107
108 public void convert(int oldVersion)
109 {
110 if (oldVersion <= 0) {
111 set("userTableColumns", "0;2;3;4;5;6;7;8");
112 set("serverTableColumns", "0;1;4;5;6;7");
113 }
114
115 if (oldVersion <= 1) {
116 removeProperty("xnap.plugin.nap.userTableColumns");
117 renameProperty("xnap.serverTableColumns",
118 "xnap.plugin.nap.serverTableColumns");
119 renameProperty("xnap.serverTableColumnWidth",
120 "xnap.plugin.nap.serverTableColumnWidth");
121 renameProperty("xnap.serverTableMaintainSortOrder",
122 "xnap.plugin.nap.serverTableMaintainSortOrder");
123 renameProperty("xnap.serverTableSortedColumn",
124 "xnap.plugin.nap.serverTableSortedColumn");
125 }
126
127 if (oldVersion <= 2) {
128
129
130
131 }
132
133 if (oldVersion <= 3) {
134 removeProperty("hotlistDividerLocation");
135 removeProperty("hotlistTableColumns");
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 }
156
157 if (oldVersion <= 4) {
158 removeProperty("useSinglePort");
159 }
160
161 Preferences prefs = Preferences.getInstance();
162
163 if (oldVersion == 5) {
164 prefs.setMinimumShares(getInt("minimumShares"));
165 prefs.setMinimumSharesMessage(get("minimumSharesMessage"));
166 prefs.setSendMinimumSharesMessage
167 (getBoolean("sendMinimumSharesMessage"));
168 prefs.setUseMinimumShares(getBoolean("useMinimumShares"));
169 }
170
171 if (oldVersion <= 6) {
172 setFirewalled(prefs.getBoolean("firewalled"));
173
174 set("serverTableColumns",
175 "name;status;localPort;version;files;size;users");
176 set("whoisTableColumns",
177 "user;server;fileCount;linkSpeed;level;status;downloads;uploads;client;lastSeen;online");
178
179 }
180
181 if (oldVersion <= 7) {
182 renameProperty("xnap.plugin.nap.autoFetchNaptigator",
183 "xnap.plugin.nap.autoFetchNapigator");
184 renameProperty("xnap.plugin.nap.autoLoadNaptigator",
185 "xnap.plugin.nap.autoLoadNapigator");
186 renameProperty("xnap.plugin.nap.autoSaveNaptigator",
187 "xnap.plugin.nap.autoSaveNapigator");
188 }
189
190 if (oldVersion <= 8) {
191 if (getNapigatorURL().equals("http://www.napigator.com/servers.php?version=112&client=napigator")) {
192 setNapigatorURL("http://www.gotnap.com/servers.txt\n"
193 + "http://naplist.com/servers.txt\n"
194 + "#http://www.napigator.com/servers.php?version=112&client=napigator\n");
195 }
196 }
197 }
198
199 public boolean getAutoFetchNapigator() {
200 return getBoolean("autoFetchNaptigator");
201 }
202
203 public void setAutoFetchNapigator(boolean newValue) {
204 set("autoFetchNaptigator", newValue);
205 }
206
207 public int getAutoFetchNapigatorInterval() {
208 return getInt("autoFetchNapigatorInterval");
209 }
210
211 public void setAutoFetchNapigatorInterval(int newValue) {
212 set("autoFetchNapigatorInterval", newValue);
213 }
214
215 public boolean getAutoLoadNapigator() {
216 return getBoolean("autoLoadNapigator");
217 }
218
219 public void setAutoLoadNapigator(boolean newValue) {
220 set("autoLoadNapigator", newValue);
221 }
222
223 public boolean getAutoResumeDownloads() {
224 return getBoolean("autoResumeDownloads");
225 }
226
227 public void setAutoResumeDownloads(boolean newValue) {
228 set("autoResumeDownloads", newValue);
229 }
230
231 public int getAutoResumeConnectedCount() {
232 return getInt("autoResumeConnectedCount");
233 }
234
235 public void setAutoResumeConnectedCount(int newValue) {
236 set("autoResumeConnectedCount", newValue);
237 }
238
239 public boolean getAutoSaveNapigator() {
240 return getBoolean("autoSaveNapigator");
241 }
242
243 public void setAutoSaveNapigator(boolean newValue) {
244 set("autoSaveNapigator", newValue);
245 }
246
247 public String getClientInfo() {
248 return get("clientInfo");
249 }
250
251 public void setClientInfo(String newValue) {
252 if (newValue.equals("")) {
253 return;
254 }
255 set("clientInfo", newValue);
256 }
257
258 public boolean getCustomizeClientInfo() {
259 return getBoolean("customizeClientInfo");
260 }
261
262 public void setCustomizeClientInfo(boolean newValue) {
263 set("customizeClientInfo", newValue);
264 }
265
266 public String getFakeNetworks() {
267 return get("fakeNetworks");
268 }
269
270 public String getFilterNetworks() {
271 return get("filterNetworks");
272 }
273
274 public boolean getFirewalled() {
275 return getBoolean("firewalled");
276 }
277
278 public void setFirewalled(boolean newValue) {
279 set("firewalled", newValue);
280 }
281
282 public boolean getLimitSearchServers() {
283 return getBoolean("limitSearchServers");
284 }
285
286 public void setLimitSearchServers(boolean newValue) {
287 set("limitSearchServers", newValue);
288 }
289
290 public boolean getLimitSearchResultsPerServer() {
291 return getBoolean("limitSearchResultsPerServer");
292 }
293
294 public void setLimitSearchResultsPerServer(boolean newValue) {
295 set("limitSearchResultsPerServer", newValue);
296 }
297
298 public boolean getLimitSharesPerServer() {
299 return getBoolean("limitSharesPerServer");
300 }
301
302 public void setLimitSharesPerServer(boolean newValue) {
303 set("limitSharesPerServer", newValue);
304 }
305
306 public String getLocalPortRange() {
307 return get("localPort");
308 }
309
310 public void setLocalPortRange(String newValue) {
311 set("localPort", newValue);
312 }
313
314 public int getMaxAutoconnectServers() {
315 return getInt("maxAutoconnectServers");
316 }
317
318 public void setMaxAutoconnectServers(int newValue) {
319 if (newValue < 0) {
320 return;
321 }
322 set("maxAutoconnectServers", newValue);
323 }
324
325 public int getMaxLoginsPerNetwork() {
326 return getInt("maxLoginsPerNetwork");
327 }
328
329 public int getMaxPacketsPerTick() {
330 return getInt("maxPacketsPerTick");
331 }
332
333 public int getMaxSearchResultsPerServer() {
334 return getInt("maxSearchResultsPerServer");
335 }
336
337 public void setMaxSearchResultsPerServer(int newValue) {
338 set("maxSearchResultsPerServer", newValue);
339 }
340
341 public int getMaxSearchServers() {
342 return getInt("maxSearchServers");
343 }
344
345 public void setMaxSearchServers(int newValue) {
346 if (newValue < 1) {
347 return;
348 }
349 set("maxSearchServers", newValue);
350 }
351
352 public int getMaxSharesPerServer() {
353 return getInt("maxSharesPerServer");
354 }
355
356 public void setMaxSharesPerServer(int newValue) {
357 set("maxSharesPerServer", newValue);
358 }
359
360 public boolean getMultiSourceDownloading() {
361 return getBoolean("multiSourceDownloading");
362 }
363
364 public void setMultiSourceDownloading(boolean newValue) {
365 set("multiSourceDownloading", newValue);
366 }
367
368 public String getNapigatorFile() {
369 return get("napigatorFile");
370 }
371
372 public String getNapigatorURL() {
373 return get("napigatorURL");
374 }
375
376 public void setNapigatorURL(String url) {
377 set("napigatorURL", url);
378 }
379
380 public boolean getRemoveFailedServers() {
381 return getBoolean("removeFailedServers");
382 }
383
384 public void setRemoveFailedServers(boolean newValue) {
385 set("removeFailedServers", newValue);
386 }
387
388 public boolean getSendWholeRepository() {
389 return getBoolean("sendWholeRepository");
390 }
391
392 public void setSendWholeRepository(boolean newValue) {
393 set("sendWholeRepository", newValue);
394 }
395
396 public String getServerFile() {
397 return get("serverFile");
398 }
399
400 public boolean getUseAutoconnector() {
401 return getBoolean("useAutoconnector");
402 }
403
404 public void setUseAutoconnector(boolean newValue) {
405 set("useAutoconnector", newValue);
406 }
407
408 public boolean getUseUTF8Encoding() {
409 return getBoolean("useUTF8Encoding");
410 }
411
412 public void setUseUTF8Encoding(boolean newValue) {
413 set("useUTF8Encoding", newValue);
414 }
415
416 public boolean getSeenStartupWizard() {
417 return getBoolean("seenStartupWizard");
418 }
419
420 public void setSeenStartupWizard(boolean newValue) {
421 set("seenStartupWizard", newValue);
422 }
423
424 public long getTickLength() {
425 return getLong("tickLength");
426 }
427
428 public boolean getWhoisQueryOnTransfer() {
429 return getBoolean("whoisQueryOnTransfer");
430 }
431
432 public void setWhoisQueryOnTransfer(boolean newValue) {
433 set("whoisQueryOnTransfer", newValue);
434 }
435 }