2009-12-17 15:27:57 -05:00
|
|
|
/*
|
2010-03-12 14:35:25 -05:00
|
|
|
Yaaic - Yet Another Android IRC Client
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-13 10:52:20 -05:00
|
|
|
Copyright 2009-2010 Sebastian Kaspari
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
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.model;
|
|
|
|
|
2010-03-02 13:40:05 -05:00
|
|
|
import java.util.Collection;
|
2010-03-13 09:51:39 -05:00
|
|
|
import java.util.LinkedHashMap;
|
2010-03-02 13:27:35 -05:00
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.yaaic.R;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A server as we know it
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
|
|
|
public class Server
|
|
|
|
{
|
|
|
|
private int id;
|
|
|
|
private String title;
|
|
|
|
private String host;
|
|
|
|
private int port;
|
2010-03-13 10:44:05 -05:00
|
|
|
private String password;
|
2010-04-05 12:46:33 -04:00
|
|
|
private String charset;
|
2010-03-13 08:45:45 -05:00
|
|
|
private Identity identity;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-13 09:51:39 -05:00
|
|
|
private LinkedHashMap<String, Conversation> conversations = new LinkedHashMap<String, Conversation>();
|
2010-03-02 13:27:35 -05:00
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
private int status = Status.DISCONNECTED;
|
2010-03-10 16:56:44 -05:00
|
|
|
private String selected = "";
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-10 16:42:05 -05:00
|
|
|
/**
|
|
|
|
* Create a new server object
|
|
|
|
*/
|
|
|
|
public Server()
|
|
|
|
{
|
|
|
|
conversations.put(ServerInfo.DEFAULT_NAME, new ServerInfo());
|
2010-03-10 16:56:44 -05:00
|
|
|
this.selected = ServerInfo.DEFAULT_NAME;
|
2010-03-10 16:42:05 -05:00
|
|
|
}
|
|
|
|
|
2010-03-13 08:45:45 -05:00
|
|
|
/**
|
|
|
|
* Set the identity for this server
|
|
|
|
*
|
|
|
|
* @param identity The identity for this server
|
|
|
|
*/
|
|
|
|
public void setIdentity(Identity identity)
|
|
|
|
{
|
|
|
|
this.identity = identity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the identity for this server
|
|
|
|
*
|
|
|
|
* @return identity
|
|
|
|
*/
|
|
|
|
public Identity getIdentity()
|
|
|
|
{
|
|
|
|
return identity;
|
|
|
|
}
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
/**
|
|
|
|
* Get unique id of server
|
|
|
|
*
|
|
|
|
* @return id
|
|
|
|
*/
|
|
|
|
public int getId()
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set unique id of server
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
public void setId(int id)
|
|
|
|
{
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:44:05 -05:00
|
|
|
/**
|
|
|
|
* Set password of the server
|
|
|
|
*
|
|
|
|
* @param password The password of the server
|
|
|
|
*/
|
|
|
|
public void setPassword(String password)
|
|
|
|
{
|
|
|
|
this.password = password;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the password of the server
|
|
|
|
*
|
|
|
|
* @return The password of the server
|
|
|
|
*/
|
|
|
|
public String getPassword()
|
|
|
|
{
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
/**
|
|
|
|
* Get title of server
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getTitle()
|
|
|
|
{
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set title of server
|
|
|
|
*
|
|
|
|
* @param title
|
|
|
|
*/
|
|
|
|
public void setTitle(String title)
|
|
|
|
{
|
|
|
|
this.title = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get hostname of server
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getHost()
|
|
|
|
{
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set hostname of server
|
|
|
|
*
|
|
|
|
* @param host
|
|
|
|
*/
|
|
|
|
public void setHost(String host)
|
|
|
|
{
|
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get port of server
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public int getPort()
|
|
|
|
{
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set port of server
|
|
|
|
*
|
|
|
|
* @param port
|
|
|
|
*/
|
|
|
|
public void setPort(int port)
|
|
|
|
{
|
|
|
|
this.port = port;
|
|
|
|
}
|
|
|
|
|
2010-04-05 12:46:33 -04:00
|
|
|
/**
|
|
|
|
* Set the charset to be used for all messages sent to the server
|
|
|
|
*
|
|
|
|
* @param charset The name of the charset
|
|
|
|
*/
|
|
|
|
public void setCharset(String charset)
|
|
|
|
{
|
|
|
|
this.charset = charset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the charset to be used with this server
|
|
|
|
*
|
|
|
|
* @return String charset The name of the charset
|
|
|
|
*/
|
|
|
|
public String getCharset()
|
|
|
|
{
|
|
|
|
return charset;
|
|
|
|
}
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
/**
|
|
|
|
* Set connection status of server
|
|
|
|
*
|
|
|
|
* @status See constants Status.*
|
|
|
|
*/
|
|
|
|
public void setStatus(int status)
|
|
|
|
{
|
|
|
|
this.status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get connection status of server
|
|
|
|
*
|
|
|
|
* @return See constants Status.*
|
|
|
|
*/
|
|
|
|
public int getStatus()
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is disconnected?
|
|
|
|
*
|
2010-03-02 13:27:35 -05:00
|
|
|
* @return true if the user is disconnected, false if the user is connected or currently connecting
|
2009-12-17 15:27:57 -05:00
|
|
|
*/
|
|
|
|
public boolean isDisconnected()
|
|
|
|
{
|
|
|
|
return status == Status.DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is connected?
|
2010-03-02 13:27:35 -05:00
|
|
|
*
|
|
|
|
* @return true if the user is (successfully) connected to this server, false otherwise
|
2009-12-17 15:27:57 -05:00
|
|
|
*/
|
|
|
|
public boolean isConnected()
|
|
|
|
{
|
|
|
|
return status == Status.CONNECTED;
|
|
|
|
}
|
|
|
|
|
2010-03-02 13:27:35 -05:00
|
|
|
/**
|
2010-03-10 14:33:43 -05:00
|
|
|
* Get all conversations
|
2010-03-02 13:27:35 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2010-03-10 14:33:43 -05:00
|
|
|
public Collection<Conversation> getConversations()
|
2010-03-02 13:27:35 -05:00
|
|
|
{
|
2010-03-10 14:33:43 -05:00
|
|
|
return conversations.values();
|
2010-03-02 13:40:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-10 14:33:43 -05:00
|
|
|
* Get conversation by name
|
2010-03-02 13:40:05 -05:00
|
|
|
*/
|
2010-03-10 14:33:43 -05:00
|
|
|
public Conversation getConversation(String name)
|
2010-03-02 13:40:05 -05:00
|
|
|
{
|
2010-03-13 17:46:35 -05:00
|
|
|
return conversations.get(name.toLowerCase());
|
2010-03-02 13:27:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-10 14:33:43 -05:00
|
|
|
* Add a new conversation
|
2010-03-02 13:27:35 -05:00
|
|
|
*
|
2010-03-10 14:33:43 -05:00
|
|
|
* @param conversation The conversation to add
|
2010-03-02 13:27:35 -05:00
|
|
|
*/
|
2010-03-10 14:33:43 -05:00
|
|
|
public void addConversationl(Conversation conversation)
|
2010-03-02 13:27:35 -05:00
|
|
|
{
|
2010-03-13 17:46:35 -05:00
|
|
|
conversations.put(conversation.getName().toLowerCase(), conversation);
|
2010-03-02 13:27:35 -05:00
|
|
|
}
|
|
|
|
|
2010-03-02 13:47:43 -05:00
|
|
|
/**
|
2010-03-10 14:33:43 -05:00
|
|
|
* Removes a conversation by name
|
2010-03-02 13:47:43 -05:00
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
*/
|
2010-03-10 14:33:43 -05:00
|
|
|
public void removeConversation(String name)
|
2010-03-02 13:47:43 -05:00
|
|
|
{
|
2010-03-13 17:46:35 -05:00
|
|
|
conversations.remove(name.toLowerCase());
|
2010-03-02 13:47:43 -05:00
|
|
|
}
|
|
|
|
|
2010-03-05 13:43:02 -05:00
|
|
|
/**
|
2010-03-10 14:33:43 -05:00
|
|
|
* Remove all conversations
|
2010-03-05 13:43:02 -05:00
|
|
|
*/
|
2010-03-10 14:33:43 -05:00
|
|
|
public void clearConversations()
|
2010-03-05 13:43:02 -05:00
|
|
|
{
|
2010-03-10 14:33:43 -05:00
|
|
|
conversations.clear();
|
2010-03-13 14:18:24 -05:00
|
|
|
|
|
|
|
// reset defaults
|
|
|
|
conversations.put(ServerInfo.DEFAULT_NAME, new ServerInfo());
|
|
|
|
this.selected = ServerInfo.DEFAULT_NAME;
|
2010-03-05 13:43:02 -05:00
|
|
|
}
|
|
|
|
|
2010-03-10 16:56:44 -05:00
|
|
|
/**
|
|
|
|
* Set name of currently selected conversation
|
|
|
|
*
|
|
|
|
* @param selected The name of the selected conversation
|
|
|
|
*/
|
|
|
|
public void setSelectedConversation(String selected)
|
|
|
|
{
|
|
|
|
this.selected = selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get name of currently selected conversation
|
|
|
|
*
|
|
|
|
* @return The name of the selected conversation
|
|
|
|
*/
|
|
|
|
public String getSelectedConversation()
|
|
|
|
{
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2010-03-02 13:27:35 -05:00
|
|
|
/**
|
|
|
|
* Get icon for current server status
|
|
|
|
*
|
|
|
|
* @return int Status icon ressource
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
public int getStatusIcon()
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case Status.CONNECTED:
|
|
|
|
return R.drawable.connected;
|
|
|
|
case Status.DISCONNECTED:
|
|
|
|
return R.drawable.disconnected;
|
2010-03-21 10:26:11 -04:00
|
|
|
case Status.PRE_CONNECTING:
|
2009-12-17 15:27:57 -05:00
|
|
|
case Status.CONNECTING:
|
|
|
|
return R.drawable.connecting;
|
|
|
|
}
|
|
|
|
|
|
|
|
return R.drawable.connecting;
|
|
|
|
}
|
|
|
|
}
|