#ifndef _KVI_IRCSERVER_H_
#define _KVI_IRCSERVER_H_

//=============================================================================
//
//   File : kvi_ircserver.h
//   Creation date : Mon Jul 10 2000 03:24:11 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 1999-2004 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program 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 2
//   of the License, or (at your opinion) any later version.
//
//   This program 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 this program. If not, write to the Free Software Foundation,
//   Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//=============================================================================

#include "kvi_settings.h"
#include "kvi_heapobject.h"
#include "kvi_qstring.h"
#include "kvi_list.h"

#include <qstringlist.h>

#define KVI_IRCSERVER_FLAG_IPV6 1
#define KVI_IRCSERVER_FLAG_CACHEIP 2
#define KVI_IRCSERVER_FLAG_SSL 4

class KVILIB_API KviIrcServer : public KviHeapObject
{
public:
	KviIrcServer();
	KviIrcServer(const KviIrcServer &serv);
	~KviIrcServer();
public:
	QString            m_szHostname;          // the server hostname (or ip eventually)
	QString            m_szIp;                // the server's cached ip (if we're caching)
	QString            m_szDescription;       // the server description
	unsigned short int m_uPort;               // the server's port
	unsigned short int m_uFlags;              // flags

	// Extended data
	QString            m_szUser;              // special username
	QString            m_szPass;              // special password
	QString            m_szNick;              // special nickname
	QString            m_szRealName;          // special real name
	QString            m_szInitUMode;         // special user mode
	QString            m_szOnConnectCommand;  // the command to run on connect
	QString            m_szOnLoginCommand;    // the command to run after login
	QString            m_szLinkFilter;        // the link filter object
    QStringList      * m_pChannelList;        // Channels to auto join
	bool               m_bAutoConnect;        // autoconnect

public:
	const QString &ipAddress() const { return m_szIp; };
	void setIpAddress(const QString &a){ m_szIp = a; };

	unsigned short int port() const { return m_uPort; };
	void setPort(unsigned short int p){ m_uPort = p; };

	void setHostname(const QString &n){ m_szHostname = n; };
	void setDescription(const QString &d){ m_szDescription = d; };
	void setUser(const QString &u){ m_szUser = u; };
	void setPassword(const QString &p){ m_szPass = p; };
	void setNickname(const QString &n){ m_szNick = n; };
	const QString & password() const { return m_szPass; };
	const QString & nickname() const { return m_szNick; };
    const QString & initUMode() const { return m_szInitUMode; };
	const QString & hostname() const { return m_szHostname; };
	const QString & ip() const { return m_szIp; };
	const QString & onLoginCommand() const { return m_szOnLoginCommand; };
	const QString & onConnectCommand() const { return m_szOnConnectCommand; };
	const QString & username() const { return m_szUser; };
	const QString & realName() const { return m_szRealName; };
	const QString & linkFilter(){ return m_szLinkFilter; };
	const QString & initUMode(){ return m_szInitUMode; };
	const QString & description(){ return m_szDescription; };
	void setRealName(const QString &r){ m_szRealName = r; };
    void setInitUMode(const QString &u){ m_szInitUMode = u; };
	void setOnConnectCommand(const QString &cmd){ m_szOnConnectCommand = cmd; };
	void setOnLoginCommand(const QString &cmd){ m_szOnLoginCommand = cmd; };
	void setLinkFilter(const QString &f){ m_szLinkFilter = f; };
	// the channel list must be allocated with new!
	void setAutoJoinChannelList(QStringList * pNewChannelList);
	QStringList* autoJoinChannelList(){ return m_pChannelList; };
	void setAutoConnect(bool autoconnect) { m_bAutoConnect = autoconnect;};
	bool autoConnect(){ return m_bAutoConnect; };

	bool isIpV6() const { return (m_uFlags & KVI_IRCSERVER_FLAG_IPV6); };
	void setIpV6(bool bSet)
	{
		if(bSet)m_uFlags |= KVI_IRCSERVER_FLAG_IPV6;
		else m_uFlags &= ((unsigned short)~KVI_IRCSERVER_FLAG_IPV6);
	};

	bool useSSL() const { return (m_uFlags & KVI_IRCSERVER_FLAG_SSL); };
	void setUseSSL(bool bSet)
	{
		if(bSet)m_uFlags |= KVI_IRCSERVER_FLAG_SSL;
		else m_uFlags &= ((unsigned short)~KVI_IRCSERVER_FLAG_SSL);
	};

	bool cacheIp() const { return (m_uFlags & KVI_IRCSERVER_FLAG_CACHEIP); };
	void setCacheIp(bool bSet)
	{
		if(bSet)m_uFlags |= KVI_IRCSERVER_FLAG_CACHEIP;
		else m_uFlags &= ((unsigned short)~KVI_IRCSERVER_FLAG_CACHEIP);
	};


	// Old api : deprecated
	// .. and now dead
	void operator =(const KviIrcServer &s);
};

class KVILIB_API KviIrcNetwork : public KviHeapObject
{
	friend class KviIrcServerDataBase;
public:
	KviIrcNetwork(const QString & name);
	~KviIrcNetwork();
protected:
	KviIrcServer             * m_pCurrentServer;
	QString                    m_szName;
	KviPtrList<KviIrcServer> * m_pServerList;
public:
	const QString & name(){ return m_szName; };
	KviPtrList<KviIrcServer> * serverList(){ return m_pServerList; };
	KviIrcServer * currentServer(){ return m_pCurrentServer; };
	void insertServer(KviIrcServer *srv);
	KviIrcServer * findServer(const QString &szHostname, unsigned short int port);
	void setCurrentServer(KviIrcServer *srv);
};

#endif //_KVI_IRCSERVER_H_
