#ifndef _KVI_IRCSERVERDB_H_
#define _KVI_IRCSERVERDB_H_
//=============================================================================
//
//   File : kvi_ircserverdb.h
//   Creation date : Mon Jul 10 2000 14:15:42 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_qstring.h"
#include "kvi_ircserver.h"

#include <qdict.h>

typedef struct _KviIrcServerDefinition
{
	QString            szServer;
	unsigned short int uPort;
	bool               bPortIsValid;
	bool               bIpV6;
	bool               bSSL;
	QString            szLinkFilter;
	QString            szPass;
	QString            szNick;
	QString            szInitUMode;
} KviIrcServerDefinition;



class KVILIB_API KviIrcServerDataBaseRecord
{
	friend class KviIrcServerDataBase;
public:
	KviIrcServerDataBaseRecord(KviIrcNetwork * n);
	~KviIrcServerDataBaseRecord();
protected:
	KviIrcNetwork            * m_pNetwork;
	KviPtrList<KviIrcServer> * m_pServerList;

	KviIrcServer             * m_pCurrentServer;
public:
	KviIrcNetwork * network(){ return m_pNetwork; };
	KviPtrList<KviIrcServer> * serverList(){ return m_pServerList; };
	KviIrcServer * currentServer();
	void insertServer(KviIrcServer *srv);
	KviIrcServer * findServer(const KviIrcServer * pServer);
	void setCurrentServer(KviIrcServer *srv);
};





class KVILIB_API KviIrcServerDataBase
{
public:
	KviIrcServerDataBase();
	~KviIrcServerDataBase();
private:
	QDict<KviIrcServerDataBaseRecord> * m_pRecords;
	QString                             m_szCurrentNetwork;
	// This list is computed when the data are loaded from disk
	// during the startup and is used by KviApp to
	// start the connections.
	// The pointer is zero if there are no autoConnect servers
	// The list is valid only during the startup phase
	// because it contains shallow pointers to the servers
	// really contained in the server/network list
	// and it is never updated later
	KviPtrList<KviIrcServer>          * m_pAutoConnectOnStartupServers;
public:
	void clear();
	QDict<KviIrcServerDataBaseRecord> * recordDict(){ return m_pRecords; };
	KviPtrList<KviIrcServer> * autoConnectOnStartupServers(){ return m_pAutoConnectOnStartupServers; };
	void clearAutoConnectOnStartupServers();
	void setCurrentNetwork(const QString &szNetName){ m_szCurrentNetwork = szNetName; };
	const QString & currentNetworkName(){ return m_szCurrentNetwork; };
	KviIrcServerDataBaseRecord * currentRecord();
	KviIrcServerDataBaseRecord * findRecord(const QString &szNetName);
	KviIrcNetwork * findNetwork(const QString &name);
	void load(const QString & filename);
	void save(const QString & filename);
	KviIrcServerDataBaseRecord * insertNetwork(KviIrcNetwork * n);
	void updateServerIp(KviIrcServer * pServer,const QString &ip);
	void makeCurrentServer(KviIrcServerDefinition * d);
};






#endif //_KVI_IRCSERVERDB_H_
