/*
 * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.commandparser.commands.server;

import com.dmdirc.Server;
import com.dmdirc.commandparser.CommandManager;
import com.dmdirc.commandparser.commands.ServerCommand;
import com.dmdirc.ui.interfaces.InputWindow;

/**
 * Allows the user to open a query dialog with another user.
 * @author chris
 */
public final class OpenQuery extends ServerCommand {
    
    /**
     * Creates a new instance of Query.
     */
    public OpenQuery() {
        super();
        
        CommandManager.registerCommand(this);
    }
    
    /** {@inheritDoc} */
    @Override
    public void execute(final InputWindow origin, final Server server,
            final boolean isSilent, final String... args) {
        if (args.length == 0) {
            showUsage(origin, isSilent, "query", "<target> <message>");
        }
        if (args.length >= 1) {
            if (server.hasQuery(args[0])) {
                server.getQuery(args[0]).activateFrame();
            } else {
                server.addQuery(args[0]);
                server.getQuery(args[0]).show();                
            }
        }
        if (args.length > 1) {
            server.getQuery(args[0]).sendLine(implodeArgs(1, args));
        }
    }
    
    
    /** {@inheritDoc} */
    @Override
    public String getName() {
        return "query";
    }
    
    /** {@inheritDoc} */
    @Override
    public boolean showInHelp() {
        return true;
    }
    
    /** {@inheritDoc} */
    @Override
    public String getHelp() {
        return "query <user> [message] - opens a query with the specified user";
    }
    
}

@@ -1374,16 +1374,56 @@
 tWindow;
+%0Aimport com.dmdirc.ui.messages.Styliser;
 %0A%0A/**%0A *
@@ -2002,36 +2002,375 @@
 %22);%0A        
-%7D%0A        if
+    return;%0A        %7D%0A            %0A        if (server.getParser().isValidChannelName(args%5B0%5D)) %7B%0A            sendLine(origin, isSilent, FORMAT_ERROR, %22You can't open a query %22 +%0A                    %22with a channel; maybe you meant %22 + Styliser.CODE_FIXED +%0A                    Styliser.CODE_BOLD + CommandManager.getCommandChar()%0A                    +
  (args.lengt
@@ -2376,27 +2376,165 @@
 th %3E
-=
  1
-) %7B%0A      
+ ? %22msg%22 : %22join%22) + %22 %22 + implodeArgs(args)%0A                    + Styliser.CODE_BOLD + Styliser.CODE_FIXED + %22?%22);%0A            return;%0A        %7D%0A%0A
       
+  
 if (
@@ -2553,36 +2553,32 @@
 ery(args%5B0%5D)) %7B%0A
-    
             serv
@@ -2623,20 +2623,16 @@
         
-  
-  
 %7D else %7B
@@ -2632,20 +2632,16 @@
  else %7B%0A
-    
         
@@ -2674,36 +2674,32 @@
 %5D);%0A            
-  
-  
 server.getQuery(
@@ -2743,23 +2743,10 @@
     
-    %7D%0A        
 %7D
+%0A
 %0A   

Fix issue 724 (queries with channels)