Browse Source

Change the way queries are stored, and made them update tab completers properly.

Fixes issue 611. Fixes issue 610.

git-svn-id: http://svn.dmdirc.com/trunk@3112 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
99b55c47e9

+ 21
- 8
src/com/dmdirc/Query.java View File

@@ -287,6 +287,9 @@ public final class Query extends MessageTarget implements
287 287
             
288 288
             ActionManager.processEvent(CoreActionType.QUERY_NICKCHANGE, format, this, sOldNick);
289 289
             
290
+            server.getTabCompleter().removeEntry(sOldNick);
291
+            server.getTabCompleter().addEntry(cClient.getNickname());
292
+            
290 293
             addLine(format, sOldNick, cClient.getIdent(),
291 294
                     cClient.getHost(), cClient.getNickname());
292 295
             host = cClient.getNickname() + "!" + cClient.getIdent() + "@" + cClient.getHost();
@@ -333,7 +336,7 @@ public final class Query extends MessageTarget implements
333 336
      * @param shouldRemove Whether or not we should remove the window from the server.
334 337
      */
335 338
     public void close(final boolean shouldRemove) {
336
-        if (server.getParser() != null) {
339
+        if (server != null && server.getParser() != null) {
337 340
             server.getParser().getCallbackManager().delCallback("onPrivateAction", this);
338 341
             server.getParser().getCallbackManager().delCallback("onPrivateMessage", this);
339 342
             server.getParser().getCallbackManager().delCallback("onNickChanged", this);
@@ -342,15 +345,16 @@ public final class Query extends MessageTarget implements
342 345
         
343 346
         ActionManager.processEvent(CoreActionType.QUERY_CLOSED, null, this);
344 347
         
345
-        window.setVisible(false);
346
-        
347
-        if (shouldRemove) {
348
-            server.delQuery(host);
348
+        if (server != null && shouldRemove) {
349
+            server.delQuery(this);
349 350
         }
350 351
         
351
-        Main.getUI().getMainWindow().delChild(window);
352
-        WindowManager.removeWindow(window);
353
-        window.close();
352
+        if (window != null) {
353
+            Main.getUI().getMainWindow().delChild(window);
354
+            WindowManager.removeWindow(window);
355
+            window.close();
356
+            window.setVisible(false);
357
+        }
354 358
         
355 359
         window = null;
356 360
         server = null;
@@ -375,6 +379,15 @@ public final class Query extends MessageTarget implements
375 379
         return host;
376 380
     }
377 381
     
382
+    /**
383
+     * Returns the current nickname of the user that this query is with.
384
+     * 
385
+     * @return The nickname of this query's user
386
+     */
387
+    public String getNickname() {
388
+        return ClientInfo.parseHost(host);
389
+    }
390
+    
378 391
     /** {@inheritDoc} */
379 392
     @Override
380 393
     public void activateFrame() {

+ 32
- 26
src/com/dmdirc/Server.java View File

@@ -81,7 +81,7 @@ public final class Server extends WritableFrameContainer implements Serializable
81 81
     /** Open channels that currently exist on the server. */
82 82
     private final Map<String, Channel> channels  = new Hashtable<String, Channel>();
83 83
     /** Open query windows on the server. */
84
-    private final Map<String, Query> queries = new Hashtable<String, Query>();
84
+    private final List<Query> queries = new ArrayList<Query>();
85 85
 
86 86
     /** The IRC Parser instance handling this server. */
87 87
     private transient IRCParser parser;
@@ -402,21 +402,33 @@ public final class Server extends WritableFrameContainer implements Serializable
402 402
     /**
403 403
      * Determines whether the server knows of the specified query.
404 404
      *
405
-     * @param query The query to be checked
405
+     * @param host The host of the query to look for
406 406
      * @return True iff the query is known, false otherwise
407 407
      */
408
-    public boolean hasQuery(final String query) {
409
-        return queries.containsKey(parser.toLowerCase(query));
408
+    public boolean hasQuery(final String host) {
409
+        for (Query query : queries) {
410
+            if (parser.equalsIgnoreCase(query.getHost(), host)) {
411
+                return true;
412
+            }
413
+        }
414
+        
415
+        return false;
410 416
     }
411 417
 
412 418
     /**
413 419
      * Retrieves the specified query belonging to this server.
414 420
      *
415
-     * @param query The query to be retrieved
421
+     * @param host The host of the query to look for
416 422
      * @return The appropriate query object
417 423
      */
418
-    public Query getQuery(final String query) {
419
-        return queries.get(parser.toLowerCase(query));
424
+    public Query getQuery(final String host) {
425
+        for (Query query : queries) {
426
+            if (parser.equalsIgnoreCase(query.getHost(), host)) {
427
+                return query;
428
+            }
429
+        }
430
+        
431
+        throw new IllegalArgumentException("No such query: " + host);
420 432
     }
421 433
 
422 434
     /**
@@ -424,14 +436,8 @@ public final class Server extends WritableFrameContainer implements Serializable
424 436
      *
425 437
      * @return list of queries belonging to this server
426 438
      */
427
-    public List<String> getQueries() {
428
-        final ArrayList<String> res = new ArrayList<String>();
429
-
430
-        for (String query : queries.keySet()) {
431
-            res.add(query);
432
-        }
433
-
434
-        return res;
439
+    public List<Query> getQueries() {
440
+        return new ArrayList<Query>(queries);
435 441
     }
436 442
 
437 443
     /**
@@ -500,22 +506,22 @@ public final class Server extends WritableFrameContainer implements Serializable
500 506
      * @param host host of the remote client being queried
501 507
      */
502 508
     public void addQuery(final String host) {
503
-        if (!queries.containsKey(parser.toLowerCase(ClientInfo.parseHost(host)))) {
509
+        if (!hasQuery(host)) {
504 510
             final Query newQuery = new Query(this, host);
505 511
 
506 512
             tabCompleter.addEntry(ClientInfo.parseHost(host));
507
-            queries.put(parser.toLowerCase(ClientInfo.parseHost(host)), newQuery);
513
+            queries.add(newQuery);
508 514
         }
509 515
     }
510 516
 
511 517
     /**
512 518
      * Deletes a query from this server.
513 519
      *
514
-     * @param host host of the remote client being queried
520
+     * @param query The query that should be removed.
515 521
      */
516
-    public void delQuery(final String host) {
517
-        tabCompleter.removeEntry(ClientInfo.parseHost(host));
518
-        queries.remove(parser.toLowerCase(ClientInfo.parseHost(host)));
522
+    public void delQuery(final Query query) {
523
+        tabCompleter.removeEntry(query.getNickname());
524
+        queries.remove(query);
519 525
     }
520 526
 
521 527
     /** {@inheritDoc} */
@@ -530,7 +536,7 @@ public final class Server extends WritableFrameContainer implements Serializable
530 536
             if (channel.ownsFrame(target)) { return true; }
531 537
         }
532 538
         // Check if it's a query frame
533
-        for (Query query : queries.values()) {
539
+        for (Query query : queries) {
534 540
             if (query.ownsFrame(target)) { return true; }
535 541
         }
536 542
         return false;
@@ -558,7 +564,7 @@ public final class Server extends WritableFrameContainer implements Serializable
558 564
         }
559 565
 
560 566
         res.addAll(channels.values());
561
-        res.addAll(queries.values());
567
+        res.addAll(queries);
562 568
 
563 569
         return res;
564 570
     }
@@ -609,7 +615,7 @@ public final class Server extends WritableFrameContainer implements Serializable
609 615
 
610 616
         eventHandler.registerCallbacks();
611 617
 
612
-        for (Query query : queries.values()) {
618
+        for (Query query : queries) {
613 619
             query.reregister();
614 620
         }
615 621
     }
@@ -864,7 +870,7 @@ public final class Server extends WritableFrameContainer implements Serializable
864 870
      * Closes all open query windows associated with this server.
865 871
      */
866 872
     private void closeQueries() {
867
-        for (Query query : new ArrayList<Query>(queries.values())) {
873
+        for (Query query : new ArrayList<Query>(queries)) {
868 874
             query.close(false);
869 875
         }
870 876
 
@@ -898,7 +904,7 @@ public final class Server extends WritableFrameContainer implements Serializable
898 904
             channel.getFrame().addLine(messageType, args);
899 905
         }
900 906
 
901
-        for (Query query : queries.values()) {
907
+        for (Query query : queries) {
902 908
             query.getFrame().addLine(messageType, args);
903 909
         }
904 910
 

+ 4
- 3
src/com/dmdirc/commandparser/CommandManager.java View File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
+import com.dmdirc.Query;
25 26
 import com.dmdirc.Server;
26 27
 import com.dmdirc.ServerManager;
27 28
 import com.dmdirc.commandparser.commands.ChannelCommand;
@@ -203,8 +204,8 @@ public final class CommandManager {
203 204
             }
204 205
             
205 206
             if (command instanceof QueryCommand || command instanceof ChatCommand) {
206
-                for (String queryName : server.getQueries()) {
207
-                    registerCommandName(server.getQuery(queryName).getTabCompleter(),
207
+                for (Query query : server.getQueries()) {
208
+                    registerCommandName(query.getTabCompleter(),
208 209
                             commandName, register);
209 210
                 }
210 211
             }
@@ -281,7 +282,7 @@ public final class CommandManager {
281 282
         new Message();
282 283
         new Nick();
283 284
         new Notice();
284
-        new Query();
285
+        new OpenQuery();
285 286
         new Raw();
286 287
         new Reconnect();
287 288
         new Umode();

src/com/dmdirc/commandparser/commands/server/Query.java → src/com/dmdirc/commandparser/commands/server/OpenQuery.java View File

@@ -31,12 +31,12 @@ import com.dmdirc.ui.interfaces.InputWindow;
31 31
  * Allows the user to open a query dialog with another user.
32 32
  * @author chris
33 33
  */
34
-public final class Query extends ServerCommand {
34
+public final class OpenQuery extends ServerCommand {
35 35
     
36 36
     /**
37 37
      * Creates a new instance of Query.
38 38
      */
39
-    public Query() {
39
+    public OpenQuery() {
40 40
         super();
41 41
         
42 42
         CommandManager.registerCommand(this);
@@ -51,11 +51,11 @@ public final class Query extends ServerCommand {
51 51
             showUsage(origin, isSilent, "query", "<target> <message>");
52 52
         }
53 53
         if (args.length >= 1) {
54
-            if (server.getQuery(args[0]) == null) {
55
-                server.addQuery(args[0]);
56
-                server.getQuery(args[0]).show();
57
-            } else {
54
+            if (server.hasQuery(args[0])) {
58 55
                 server.getQuery(args[0]).activateFrame();
56
+            } else {
57
+                server.addQuery(args[0]);
58
+                server.getQuery(args[0]).show();                
59 59
             }
60 60
         }
61 61
         if (args.length > 1) {

Loading…
Cancel
Save