/***************************************************************************
 *   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 "evachatwindow.h"
#include <qobject.h>
#include <qptrlist.h>
#include <qdatetime.h>
#include <list>

class QQFriend;
class EvaImageResource;
class EvaUserSetting;

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);
	void closeAllWindows();
	
	std::list<int> getMessages();
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);
signals:
	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();
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;
};

#endif
