/***************************************************************************
 *   Copyright (C) 2005 by yunfan                                          *
 *   yunfan_zg@163.com                                                     *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   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.             *
 ***************************************************************************/
#ifndef EVACHATWINDOWMANAGER_H
#define EVACHATWINDOWMANAGER_H

#include <qobject.h>
#include <qptrlist.h>
#include <qdatetime.h>
#include <list>

class QQFriend;
class EvaImageResource;
class EvaUserSetting;
class EvaChatWindow;
class EvaQunChatWindow;
class Qun;

class EvaChatWindowManager : public QObject
{
	Q_OBJECT
public:
	EvaChatWindowManager(EvaImageResource *img, EvaUserSetting *setting, QString myNickname, const int id);
	~EvaChatWindowManager();
	
	bool isChatWindowExisted(const int id);
	void openChatWindow(const QQFriend * frd);
	
	bool isQunChatWindowExisted(const int id);
	void openQunChatWindow(Qun *qun);
	
	void closeAllWindows();
	
	std::list<int> getMessages();
	
	std::list<int> getQunMessages();
public slots:
	void graphicChanged();
	void slotReceivedMessage(int sender, bool isNormal, QString message, QDateTime time, const char size=9, 
			const bool u=false, const bool i=false, const bool b=false, 
			const char blue=0, const char green=0, const char red=0);
	void slotSendResult(int id, bool ok);
	void slotBuddyQQShowReady(const int id);
	void slotMyQQShowReady();
	EvaChatWindow *getWindow(const int id);
	void setMyName(QString myName, const int id);
	
	/// qun
	void slotReceivedQunMessage( int qunID, int senderQQ, QString message, QDateTime time, const char size, 
					const bool u, const bool i, const bool b, 
					const char blue, const char green, const char red );
	void slotQunSendResult(int id, bool ok, QString msg);
	EvaQunChatWindow *getQunWindow(const int id);
	
	void slotQunOnlineMembers(const int);
	//void slotUpdateQunMembers(int);
	void slotQunPicReady(const int id, const QString fileName, const QString tmpFileName);
	void slotQunPicSent(const int, const unsigned int, const unsigned int, const unsigned short);
	void slotSendImageError(const int id, const QString message);
	void slotQunMemberInfoReady( const int);
signals:
	void requestQunCard(const int id, const int qq);
	void requestDetails(const int id);
	void sendMessage(const int receiver, const bool isNormal, QString &message, const char size, 
			const bool u, const bool i, const bool b, 
			const char blue, const char green, const char red);
	void requestHistory(const int );
	void requestBuddyQQShow(const int);
	void requestMyQQShow();
	
	/// qun
	void requestQunDetails(const int id);
	void sendQunMessage(const int, QString &, const char , 
			const bool, const bool, const bool, 
			const char, const char, const char);
	void requestQunHistory(const int );
	void requestQunOnlineList(const int);
	void requestQunMembers(const int);
	
private:
	EvaChatWindow *newWindow(const QQFriend *frd);
	QPtrList<EvaChatWindow> windowList;
	typedef struct{
		int sender;
		bool isNormal;
		QString message;
		QDateTime time;
		char size;
		bool u, i, b;
		char blue, green, red;
	} Message;
	
	QPtrList<Message> messageQueue;
	EvaUserSetting *userSetting;
	
	// here is all qun windows' structure
	EvaQunChatWindow *newQunWindow(Qun *qun);
	QPtrList<EvaQunChatWindow> qunWindowList;
	typedef struct{
		int qunID;
		int sender;
		QString message;
		QDateTime time;
		char size;
		bool u, i, b;
		char blue, green, red;
	} QunMessage;
	QPtrList<QunMessage> qunMessageQueue;
};

#endif
