/***************************************************************************
                          dcconnectionmanager.h  -  description
                             -------------------
    begin                : Mon Oct 1 2001
    copyright            : (C) 2001-2005 by Mathias Küster
    email                : mathen@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DCCONNECTIONMANAGER_H
#define DCCONNECTIONMANAGER_H

/**
  *@author Mathias Küster
  */

#include <qtimer.h>
#include <qtabbar.h>
//Added by qt3to4:
#include <QEvent>
#include <QCloseEvent>
#include <QList>

#include "DCDialogConnectionManager.h"

#include "dcconfig.h"

#include <dclib/cconnectionmanager.h>

class DCClient;
class QMdiArea;
class QMdiSubWindow;
class QToolBar;

/** */
class DCClientTab : public QObject {
public:
	/** construtor */
	DCClientTab() {
		m_pClient = 0;
		m_nMenuID = -1;
	};
	/** destructor */
	virtual ~DCClientTab() {};

	/** */
	DCClient * m_pClient;
	/** */
	int m_nMenuID;
};

class DCConnectionManager : public QWidget, private Ui::DCDialogConnectionManager, public CConnectionManager {
Q_OBJECT

public:
	/** construtor */
	DCConnectionManager( QWidget * parent, const char *name, Qt::WindowFlags wflags );
	/** destructor */
	virtual ~DCConnectionManager();

	/** */
	void InitDocument();
	/** */
	void DeInitDocument();
	
	/** */
	void AutoConnect();
	/** */
	void Connect( CString hubname, CString server, bool sslconnect = FALSE );

	/** */
	void OPKick( QString hubname, QString hubhost, QString nick, QString message );
	/** */
	void OPForceMove( QString hubname, QString hubhost, QString nick, QString message, QString host );

	/** */
	void OpenPrivateChat( QString hubname, QString hubhost, QString nick );
	/** */
	void CloseAllChats();
	/** */
	void DisconnectAllClients();
	/** */
	void CloseDisconnectedHubs();

	/** */
	void InitTabBar( QToolBar * toolbar );
	
	/** overridden so that the columns are resized on show() */
	/* virtual void show(); */

	/** callback function */
	virtual int DC_CallBack( CObject * );
	
	/** */
	void HubEvent( DCClient * client );

protected:
	/** resize the ListView columns */
	/* void ResizeListViewColumn(); */

	/** event filter */
	virtual bool eventFilter( QObject * object, QEvent * event );
	/** close event handler */
	virtual void closeEvent( QCloseEvent * ) { };

private:
	/** */
	void resetTabIcon( DCClientTab * ct );
	/** */
	DCClientTab * getDCClientTab( int index );
	
	/** */
	QTimer m_Timer;
	/** */
	QTabBar * m_pTabBar;
	/** */
	CList<CObject> * m_pMessageList;
	/** */
	QMdiArea * m_pMdiArea;
	/** */
	bool m_bDisableTabSelected;
	/** */
	int m_nSelectedTab;
	/** */
	QList<DCClientTab*> * m_pClientTabList;
	
private slots:
	/** */
	void timerDone();
	/** */
	void slotTabSelected( int );
	/** widget from mdi area activated */
	void slotMdiSubWindowActivated( QMdiSubWindow * w );
};

/** */
extern DCConnectionManager * g_pConnectionManager;

#endif
