#ifndef _KVI_IRCCONTEXT_H_
#define _KVI_IRCCONTEXT_H_
//=============================================================================
//
//   File : kvi_irccontext.h
//   Created on Sun 09 May 2004 20:37:46 by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 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_list.h"

class KviConsole;
class KviChannel;
class KviQuery;
class KviFrame;
class KviExternalServerDataParser;

/*
	KviIrcContext is the structure that groups the objects and resources
	usable for a single irc connection: a console, a set of channels and queries,
	and a KviIrcConnection object.
	
	The objects grouped here are mostly permanent across connections.
	
	Each irc context has its own unique numeric identifier. The identifiers start
	from 1 so 0 is an invalid irc context id (this is useful in the scripting engine).
	
	The irc context is created in the KviConsole constructor and destroyed
	in the KviConsole destructor. No other class can allocate KviIrcContext objects.
*/

class KVIRC_API KviIrcContext
{
	friend class KviConsole;
protected:
	KviIrcContext(KviConsole * pConsole); // only KviConsole can create this
public:
	~KviIrcContext();
protected:
	KviConsole                       * m_pConsole;             // shallow, never null
	unsigned int                       m_uId;                  // this irc context id
	
	// helper pointers
	KviFrame                         * m_pFrm;                 // the owning frame, shallow, never null

	// permanent links and list window
	KviExternalServerDataParser      * m_pLinksWindow;
	KviExternalServerDataParser      * m_pListWindow;

	// dead channels and queries
	KviPtrList<KviChannel>           * m_pDeadChannels;
	KviPtrList<KviQuery>             * m_pDeadQueries;
public:
	unsigned int id(){ return m_uId; };

	KviConsole * console(){ return m_pConsole; };
	KviFrame * frame(){ return m_pFrm; };
	
	// dead channels and queries
	void closeAllDeadChannels();
	void closeAllDeadQueries();
	bool unregisterDeadChannel(KviChannel * c);
	bool unregisterDeadQuery(KviQuery * q);
	void registerDeadChannel(KviChannel * c);
	void registerDeadQuery(KviQuery * q);
	KviChannel * findDeadChannel(const char * name);
	KviQuery * findDeadQuery(const char * nick);
	KviQuery * firstDeadQuery();

	// links window
	void createLinksWindow();
	void setLinksWindowPointer(KviExternalServerDataParser * l){ m_pLinksWindow = l; };
	KviExternalServerDataParser * linksWindow(){ return m_pLinksWindow; };

	// list window
	void createListWindow();
	void setListWindowPointer(KviExternalServerDataParser * l){ m_pListWindow = l; };
	KviExternalServerDataParser * listWindow(){ return m_pListWindow; };
};


#endif //!_KVI_IRCCONTEXT_H_
