/***************************************************************************
 *   Copyright (C) 2004 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 EVAMAIN_H
#define EVAMAIN_H

#include <qobject.h>
#include <qdatetime.h>
#include <qstringlist.h>
#include <inttypes.h>
#include <qhostaddress.h>

class QPopupMenu;
class QTextCodec;
class QTimer;
class KAboutData;
class KAboutApplication;

class EvaUser;
class EvaConnecter;
class EvaPacketManager;
class EvaGlobal;
class EvaImageResource;
class EvaSetting;

class EvaLoginWindow;
class EvaMainWindow;
class EvaChatWindowManager;
class EvaSystemTray;

class EvaMain : public QObject
{
	Q_OBJECT

public:
	EvaMain();
	~EvaMain();
	static KAboutData * mAboutData;
	static EvaUser *user;
	static EvaImageResource *images;
private:
	void initSettings();
	void initUserLeaveMenu();
	//QString path;
	QTextCodec *codec;
	QTimer *onlineFriendTimer;	
	EvaConnecter *connecter;
	EvaPacketManager *packetManager;
	//QString lastSentName;
	//int lastSentID;
	int numOfLostKeepAlivePackets;
	bool loggedIn;
	QHostAddress QQServer;
	int deleteFromQQ;
	
	KAboutApplication *aboutEva;
	
	EvaGlobal *global;
	EvaSetting *sysSetting;
	
	QPopupMenu *sysMenu;
	QPopupMenu *statusMenu;
	QPopupMenu *autoMenu;
	EvaLoginWindow *loginWin;
	EvaMainWindow *mainWin;	
	EvaChatWindowManager *windowList;
	EvaSystemTray *tray;
	
private slots:
	void doAbout();
	void doQuit();
	bool doInitUI();
	void initMenus();
	void doSlotConnection();
	void initGroups();
	void slotGetOnlineStatus();
	
	void slotNetworkException(int);
	void slotPacketException(int);

	void slotConnectReady();
	void slotDoLoginClick();
	void slotGotServer(QHostAddress addr);
	void slotLoginOK();
	void slotWrongPassword();
	void slotOnlineReady();
	void slotInvisibleReady();
	void slotLeaveReady();
	void slotOfflineReady();
	void slotFriendStatusChanged(int);
	void slotFriendListReady();
	//void slotSentMessageResult(bool); 
	void slotTxtMessage(int sender, bool isNormal, QString message, QDateTime time, const char fontSize, 
			const bool u, const bool i, const bool b, 
			const char blue, const char green, const char red); 
	void slotFriendGroupsReady();  
	
	// login window
	void slotDoLogin();
	void slotDoCancel();
	
	void slotDoOnline();
	void slotDoOffline();
	void slotDoLeave();
	void slotAutoReplyMenuActivated(int id);
	void slotDoInvisible();
	void slotDoLogout();
	
	void slotDoDownloadGroups();
	void slotDoUploadGroups();
	void slotFriendGroupsUploadReady(bool);
	
	void slotDoDownloadBuddies();
	void slotDoChangeUser();
	
	void slotGroupDeleted(const int);
	void slotGroupAdded(QString, int);
	void slotGroupRenamed(QString, int);
	void slotGroupChanged(int, int);
	
	void slotRequestDetails(const int);
	void slotRequestChat(const int);
	void slotRequestHistory(const int);
	void slotRequestQQShow(const int);
	void slotRequestMyQQShow();
	void slotQQShowReady(const int);
	void slotRequestSearch();
	
	void slotSystemMeBeenAdded(int);
	void slotSystemAddMeRequest(int, QString);
	void slotSystemAddRequestApproved(int);
	void slotSystemAddRequestRejected(int, QString);
	
	void slotRequestSystemMessage();
	void slotShowSystemMessage(const uint8_t type, const int from, const int me, const QString message);
	void slotRequestSystemMessages();
	
	void slotRequestDelete(const int);
	void slotDeleteBuddyReady(int, bool);
	
	void slotRequestSystemSettingWindow();
	void slotDeleteMeFrom(int);
	void slotDeleteMeReply(bool);
	void slotRequestAddBuddy(int);
	
	void slotMyInfoReady();
};

#endif

