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
|
|
|
|
2011-02-05 07:00:12 -05:00
|
|
|
Copyright 2009-2011 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/>.
|
2011-01-25 15:02:27 -05:00
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
package org.yaaic.model;
|
|
|
|
|
2010-04-13 15:55:25 -04:00
|
|
|
import java.util.ArrayList;
|
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
|
|
|
|
{
|
2010-11-18 12:52:19 -05:00
|
|
|
private int id;
|
|
|
|
private String title;
|
|
|
|
private String host;
|
|
|
|
private int port;
|
|
|
|
private String password;
|
|
|
|
private String charset;
|
|
|
|
private boolean useSSL = false;
|
2011-03-06 07:47:14 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
private Identity identity;
|
2011-03-06 07:47:14 -05:00
|
|
|
private Authentication authentication;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
|
|
|
private final LinkedHashMap<String, Conversation> conversations = new LinkedHashMap<String, Conversation>();
|
2010-11-18 12:52:19 -05:00
|
|
|
private ArrayList<String> autoJoinChannels;
|
|
|
|
private ArrayList<String> connectCommands;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
private int status = Status.DISCONNECTED;
|
|
|
|
private String selected = "";
|
2011-05-29 20:49:07 -04:00
|
|
|
private boolean isForeground = false;
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Create a new server object
|
|
|
|
*/
|
|
|
|
public Server()
|
|
|
|
{
|
|
|
|
conversations.put(ServerInfo.DEFAULT_NAME, new ServerInfo());
|
|
|
|
this.selected = ServerInfo.DEFAULT_NAME;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set the identity for this server
|
|
|
|
*
|
|
|
|
* @param identity The identity for this server
|
|
|
|
*/
|
|
|
|
public void setIdentity(Identity identity)
|
|
|
|
{
|
|
|
|
this.identity = identity;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2011-03-06 07:47:14 -05:00
|
|
|
/**
|
|
|
|
* Set the authentication methods for this server
|
|
|
|
*
|
|
|
|
* @param authentication
|
|
|
|
*/
|
|
|
|
public void setAuthentication(Authentication authentication)
|
|
|
|
{
|
|
|
|
this.authentication = authentication;
|
|
|
|
}
|
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the identity for this server
|
|
|
|
*
|
|
|
|
* @return identity
|
|
|
|
*/
|
|
|
|
public Identity getIdentity()
|
|
|
|
{
|
|
|
|
return identity;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2011-03-06 07:47:14 -05:00
|
|
|
/**
|
|
|
|
* Get the authentication methods for this server;
|
|
|
|
*
|
|
|
|
* @return authentication
|
|
|
|
*/
|
|
|
|
public Authentication getAuthentication()
|
|
|
|
{
|
|
|
|
return authentication;
|
|
|
|
}
|
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get unique id of server
|
|
|
|
*
|
|
|
|
* @return id
|
|
|
|
*/
|
|
|
|
public int getId()
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set unique id of server
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
public void setId(int id)
|
|
|
|
{
|
|
|
|
this.id = id;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set password of the server
|
|
|
|
*
|
|
|
|
* @param password The password of the server
|
|
|
|
*/
|
|
|
|
public void setPassword(String password)
|
|
|
|
{
|
|
|
|
this.password = password;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the password of the server
|
|
|
|
*
|
|
|
|
* @return The password of the server
|
|
|
|
*/
|
|
|
|
public String getPassword()
|
|
|
|
{
|
|
|
|
return password;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get title of server
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getTitle()
|
|
|
|
{
|
|
|
|
return title;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set title of server
|
|
|
|
*
|
|
|
|
* @param title
|
|
|
|
*/
|
|
|
|
public void setTitle(String title)
|
|
|
|
{
|
|
|
|
this.title = title;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get hostname of server
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getHost()
|
|
|
|
{
|
|
|
|
return host;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set hostname of server
|
|
|
|
*
|
|
|
|
* @param host
|
|
|
|
*/
|
|
|
|
public void setHost(String host)
|
|
|
|
{
|
|
|
|
this.host = host;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get port of server
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public int getPort()
|
|
|
|
{
|
|
|
|
return port;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set port of server
|
|
|
|
*
|
|
|
|
* @param port
|
|
|
|
*/
|
|
|
|
public void setPort(int port)
|
|
|
|
{
|
|
|
|
this.port = port;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05: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;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the charset to be used with this server
|
|
|
|
*
|
|
|
|
* @return String charset The name of the charset
|
|
|
|
*/
|
|
|
|
public String getCharset()
|
|
|
|
{
|
|
|
|
return charset;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set if this connections needs to use ssl
|
|
|
|
*/
|
|
|
|
public void setUseSSL(boolean useSSL)
|
|
|
|
{
|
|
|
|
this.useSSL = useSSL;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Does this connection use SSL?
|
|
|
|
*
|
|
|
|
* @return true if SSL should be used, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean useSSL()
|
|
|
|
{
|
|
|
|
return useSSL;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set connection status of server
|
|
|
|
*
|
|
|
|
* @status See constants Status.*
|
|
|
|
*/
|
|
|
|
public void setStatus(int status)
|
|
|
|
{
|
|
|
|
this.status = status;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get connection status of server
|
|
|
|
*
|
|
|
|
* @return See constants Status.*
|
|
|
|
*/
|
|
|
|
public int getStatus()
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set list of channels to auto join after connect
|
|
|
|
*
|
|
|
|
* @param channels List of channel names
|
|
|
|
*/
|
|
|
|
public void setAutoJoinChannels(ArrayList<String> autoJoinChannels)
|
|
|
|
{
|
|
|
|
this.autoJoinChannels = autoJoinChannels;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get list of channels to auto join after connect
|
|
|
|
*
|
|
|
|
* @return List of channel names
|
|
|
|
*/
|
|
|
|
public ArrayList<String> getAutoJoinChannels()
|
|
|
|
{
|
|
|
|
return autoJoinChannels;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set commands to execute after connect
|
|
|
|
*
|
|
|
|
* @param commands List of commands
|
|
|
|
*/
|
|
|
|
public void setConnectCommands(ArrayList<String> connectCommands)
|
|
|
|
{
|
|
|
|
this.connectCommands = connectCommands;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get commands to execute after connect
|
|
|
|
*
|
|
|
|
* @return List of commands
|
|
|
|
*/
|
|
|
|
public ArrayList<String> getConnectCommands()
|
|
|
|
{
|
|
|
|
return connectCommands;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Is disconnected?
|
|
|
|
*
|
2011-01-25 15:02:27 -05:00
|
|
|
* @return true if the user is disconnected, false if the user is connected or currently connecting
|
2010-11-18 12:52:19 -05:00
|
|
|
*/
|
|
|
|
public boolean isDisconnected()
|
|
|
|
{
|
|
|
|
return status == Status.DISCONNECTED;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Is connected?
|
|
|
|
*
|
|
|
|
* @return true if the user is (successfully) connected to this server, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean isConnected()
|
|
|
|
{
|
|
|
|
return status == Status.CONNECTED;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get all conversations
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Collection<Conversation> getConversations()
|
|
|
|
{
|
|
|
|
return conversations.values();
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get conversation by name
|
|
|
|
*/
|
|
|
|
public Conversation getConversation(String name)
|
|
|
|
{
|
|
|
|
return conversations.get(name.toLowerCase());
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Add a new conversation
|
|
|
|
*
|
|
|
|
* @param conversation The conversation to add
|
|
|
|
*/
|
2011-03-15 18:59:49 -04:00
|
|
|
public void addConversation(Conversation conversation)
|
2010-11-18 12:52:19 -05:00
|
|
|
{
|
|
|
|
conversations.put(conversation.getName().toLowerCase(), conversation);
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Removes a conversation by name
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
*/
|
|
|
|
public void removeConversation(String name)
|
|
|
|
{
|
|
|
|
conversations.remove(name.toLowerCase());
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Remove all conversations
|
|
|
|
*/
|
|
|
|
public void clearConversations()
|
|
|
|
{
|
|
|
|
conversations.clear();
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
// reset defaults
|
|
|
|
conversations.put(ServerInfo.DEFAULT_NAME, new ServerInfo());
|
|
|
|
this.selected = ServerInfo.DEFAULT_NAME;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Set name of currently selected conversation
|
|
|
|
*
|
|
|
|
* @param selected The name of the selected conversation
|
|
|
|
*/
|
|
|
|
public void setSelectedConversation(String selected)
|
|
|
|
{
|
|
|
|
this.selected = selected;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
2011-01-25 15:02:27 -05:00
|
|
|
* Get name of currently selected conversation
|
2010-11-18 12:52:19 -05:00
|
|
|
*
|
|
|
|
* @return The name of the selected conversation
|
|
|
|
*/
|
|
|
|
public String getSelectedConversation()
|
|
|
|
{
|
|
|
|
return selected;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get names of the currently joined channels
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public ArrayList<String> getCurrentChannelNames()
|
|
|
|
{
|
|
|
|
ArrayList<String> channels = new ArrayList<String>();
|
|
|
|
Collection<Conversation> mConversations = conversations.values();
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
for (Conversation conversation : mConversations) {
|
|
|
|
if (conversation.getType() == Conversation.TYPE_CHANNEL) {
|
|
|
|
channels.add(conversation.getName());
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
return channels;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get icon for current server status
|
|
|
|
*
|
|
|
|
* @return int Status icon ressource
|
|
|
|
*/
|
|
|
|
public int getStatusIcon()
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case Status.CONNECTED:
|
|
|
|
return R.drawable.connected;
|
|
|
|
case Status.DISCONNECTED:
|
|
|
|
return R.drawable.disconnected;
|
|
|
|
case Status.PRE_CONNECTING:
|
|
|
|
case Status.CONNECTING:
|
|
|
|
return R.drawable.connecting;
|
|
|
|
}
|
2011-01-25 15:02:27 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
return R.drawable.connecting;
|
|
|
|
}
|
2011-05-29 20:49:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get whether a ConversationActivity for this server is currently in the foreground.
|
|
|
|
*/
|
|
|
|
public boolean getIsForeground()
|
|
|
|
{
|
|
|
|
return isForeground;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether a ConversationActivity for this server is currently in the foreground.
|
|
|
|
*/
|
|
|
|
public void setIsForeground(boolean isForeground)
|
|
|
|
{
|
|
|
|
this.isForeground = isForeground;
|
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|