1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2025-01-11 05:38:00 -05:00

Implemented /close

This commit is contained in:
Sebastian Kaspari 2010-03-13 16:02:48 +01:00
parent 5b54d66f70
commit 90878c9b34
2 changed files with 76 additions and 0 deletions

View File

@ -22,6 +22,7 @@ package org.yaaic.command;
import java.util.HashMap;
import org.yaaic.command.handler.CloseHandler;
import org.yaaic.command.handler.DeopHandler;
import org.yaaic.command.handler.DevoiceHandler;
import org.yaaic.command.handler.EchoHandler;
@ -78,6 +79,7 @@ public class CommandParser
commands.put("kick", new KickHandler());
commands.put("query", new QueryHandler());
commands.put("part", new PartHandler());
commands.put("close", new CloseHandler());
// Aliases
commands.put("j", commands.get("join"));

View File

@ -0,0 +1,74 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009 Sebastian Kaspari
This file is part of Yaaic.
Yaaic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Yaaic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.command.handler;
import org.yaaic.command.BaseHandler;
import org.yaaic.command.CommandException;
import org.yaaic.irc.IRCService;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Conversation;
import org.yaaic.model.Server;
import android.content.Intent;
/**
* Command: /close
*
* Closes the current window
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class CloseHandler extends BaseHandler
{
/**
* Execute /close
*/
@Override
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
{
if (conversation.getType() == Conversation.TYPE_SERVER) {
throw new CommandException("You can't close the server window");
}
if (params.length == 1) {
if (conversation.getType() == Conversation.TYPE_CHANNEL) {
service.getConnection(server.getId()).partChannel(conversation.getName());
}
if (conversation.getType() == Conversation.TYPE_QUERY) {
server.removeConversation(conversation.getName());
Intent intent = new Intent(Broadcast.CONVERSATION_REMOVE);
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
service.sendBroadcast(intent);
}
}
}
/**
* Usage of /close
*/
@Override
public String getUsage()
{
return "/close";
}
}