/***************************************************************************
 *   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>
#include <kwallet.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 EvaHelper;
class EvaPicManager;
class EvaUHManager;
class KGlobalAccel;
//class Wallet;

class EvaMain : public QObject
{
	Q_OBJECT

public:
	EvaMain();
	~EvaMain();
	static KAboutData * mAboutData;
	static EvaUser *user;
	static EvaImageResource *images;
	static EvaHelper *helper;	
	static EvaConnecter *connecter;
	static EvaPicManager *picManager;
	static EvaUHManager *uhManager;
protected:
	virtual void customEvent( QCustomEvent * e );
private:
	void initSettings();
	void initUserLeaveMenu();
	//QString path;
	QTextCodec *codec;
	QTimer *onlineFriendTimer;
	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;
	int numLoginRetry;
	bool isClientSet;
	KGlobalAccel *accelKey;
	KWallet::Wallet *_wallet;
private slots:
	void slotLoadGroupedBuddiesReady();
	void slotLoadQunListReady();
	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 slotServerBusy();
	void slotSetupEvaClient();
	void slotFetchQQServer();
	void slotGotServer(QHostAddress addr);
	void slotLoginOK();
	void slotWrongPassword(QString msg);
	void slotKickedOut(const QString msg);
	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 slotRequestLevel(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 short, const uint8_t type, const int from, const int me, const QString message, const int internalQunID = 0);
	void slotRequestSystemMessages();
	
	void slotRequestDelete(const int);
	void slotDeleteBuddyReady(int, bool);
	
	void slotRequestSystemSettingWindow();
	void slotDeleteMeFrom(int);
	void slotDeleteMeReply(bool);
	void slotRequestAddBuddy(const int);
	
	void slotMyInfoReady();
	
	void slotQunInfomationReady(const int, const bool, QString);
	
	void slotRequestQunDetails(const int);
	void slotRequestQunHistory(const int);
	void slotRequestQunChat(const int);
	void slotReceivedQunMessage( int, int, QString, QDateTime, const char, 
			const bool, const bool, const bool, const char, const char, const char);
	void slotQunSystemMessageRequest(const int, QString);
	
	void slotQunPictureReady(const int id, const QString fileName, const QString tmpFileName);
	void slotRequestQunCardReady(const int id, const bool ok, const int qq, QString realName, const unsigned char gender, 
					QString phone, QString email, QString memo, QString msg);
	void slotDoQunExit(const int id);
	void slotQunExitReply(const int, const bool, QString);
	void slotQunCreateFailed(QString);
	void slotQunCreate();
	void slotRequestQunMembers(const int);

	void slotFriendSignatureChanged(const int qq, const QDateTime time, const QString signature);
	void slotUpdateQunMessageSettings(const int id, const signed char type);
	
	void slotUserSettingChanged();
	void slotUpdateShortcut();
	void slotShotcutKeyPressed();
	
	void slotLoginProcessReady();
	void slotAddAnonymous(const int id, const short face);
	
	void slotExtraInfoReady();
	void slotShowOnlineSelected();
	void slotShowAllSelected();
	
};

#endif

