/*
 * Copyright (c) 2006-2012 DMDirc Developers
 *
 * 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.addons.nma;

import com.dmdirc.FrameContainer;
import com.dmdirc.commandparser.BaseCommandInfo;
import com.dmdirc.commandparser.CommandArguments;
import com.dmdirc.commandparser.CommandType;
import com.dmdirc.commandparser.commands.Command;
import com.dmdirc.commandparser.commands.context.CommandContext;

import java.io.IOException;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * Command to raise notifications with NotifyMyAndroid.
 */
@Slf4j
public class NotifyMyAndroidCommand extends Command {

    /** A command info object for this command. */
    public static final BaseCommandInfo INFO = new BaseCommandInfo(
            "notifymyandroid",
            "notifymyandroid <title> -- <body>"
                + " - Sends notification to NotifyMyAndroid",
            CommandType.TYPE_GLOBAL);

    /** The configuration domain to retrieve settings from. */
    @Setter
    private String configDomain;

    /** {@inheritDoc} */
    @Override
    public void execute(final FrameContainer origin,
            final CommandArguments args, final CommandContext context) {
        final String[] parts = args.getArgumentsAsString().split("\\s+--\\s+", 2);
        log.trace("Split input: {}", parts);

        if (parts.length != 2) {
            showUsage(origin, args.isSilent(), INFO.getName(), INFO.getHelp());
        }

        log.trace("Retrieving settings from domain '{}'", configDomain);
        final NotifyMyAndroidClient client = new NotifyMyAndroidClient(
                origin.getConfigManager().getOption(configDomain, "apikey"),
                origin.getConfigManager().getOption(configDomain, "application"));

        try {
            client.notify(parts[0], parts[1]);
            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Notification sent");
        } catch (IOException ex) {
            log.info("Exception when trying to notify NMA", ex);
            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to send: " + ex.getMessage());
        }
    }

}

@@ -2803,14 +2803,121 @@
     
-try %7B%0A
+new Thread(new Runnable() %7B%0A%0A            @Override%0A            public void run() %7B%0A                try %7B%0A        
     
@@ -2959,16 +2959,24 @@
 ts%5B1%5D);%0A
+        
         
@@ -3050,16 +3050,24 @@
 sent%22);%0A
+        
         
@@ -3101,24 +3101,32 @@
             
+        
 log.info(%22Ex
@@ -3166,16 +3166,24 @@
 %22, ex);%0A
+        
         
@@ -3269,24 +3269,32 @@
 Message());%0A
+        
         %7D%0A  
@@ -3291,16 +3291,64 @@
       %7D%0A
+            %7D%0A        %7D, %22NMA Thread%22).start();%0A
     %7D%0A%0A%7D

Use NMA API in new thread.