01: /*
02: * Lucane - a collaborative platform
03: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package org.lucane.applications.kick;
20:
21: import org.lucane.client.*;
22: import org.lucane.client.widgets.DialogBox;
23: import org.lucane.common.*;
24: import org.lucane.common.net.ObjectConnection;
25:
26: import java.util.HashMap;
27: import java.util.Map;
28:
29: public class Kick extends Plugin {
30: private ConnectInfo[] friends;
31:
32: public Kick() {
33: }
34:
35: public Plugin newInstance(ConnectInfo[] friends) {
36: if (friends.length > 0)
37: return new Kick(friends);
38: else
39: return new Kick(null);
40: }
41:
42: public Kick(ConnectInfo[] friends) {
43: this .friends = friends;
44: }
45:
46: public void start() {
47: // selection check
48: if (this .friends == null) {
49: DialogBox.info(tr("msg.selectUsers"));
50: exit();
51: return;
52: }
53:
54: //ask for confirmation
55: String msg = tr("msg.reallyKickUsers");
56: msg = msg.replaceFirst("\\%1", String.valueOf(friends.length));
57: if (!DialogBox.question(getTitle(), msg)) {
58: exit();
59: return;
60: }
61:
62: //send deconnection
63: for (int i = 0; i < friends.length; i++) {
64: try {
65: Map action = new HashMap();
66: action.put("command", "DISCONNECT");
67: ObjectConnection oc = Communicator.getInstance()
68: .sendMessageTo(friends[i], "Client", action);
69: oc.close();
70: } catch (Exception e) {
71: Logging.getLogger().warning(
72: "Unable to kick : " + friends[i].getName());
73: e.printStackTrace();
74: }
75: }
76:
77: exit();
78: }
79: }
|