/***************************************************************************
 *   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 EVASEARCHWINDOW_H
#define EVASEARCHWINDOW_H

#include "evasearchuibase.h"
#include "evasearchuser.h"
#include "evaqun.h"
#include <list>
#include <map>
#include <qvaluestack.h>

class EvaImageResource;

class EvaSearchWindow : public EvaSearchUIBase
{
	Q_OBJECT

public:
	EvaSearchWindow(EvaImageResource *res = NULL, const int onlineUsers = 0, QWidget* parent = 0, const char* name = 0, 
			WFlags fl = Qt::WStyle_Customize | Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_Minimize
				| Qt::WStyle_Maximize | Qt::WStyle_NormalBorder | Qt::WDestructiveClose);
	~EvaSearchWindow();

public slots:
	void slotSearchUsersReady(const bool finished, const std::list<OnlineUser> list);
	void slotAddBuddyReady();
	void slotAddBuddyRejected();
	void slotBuddyNeedAuth();
	void slotAddBuddySentToServer(bool ok);
	void slotQunSearchReady(const std::list<QunInfo>, QString);
	
	void slotQunJoinReplyOK(const int);
	void slotQunJoinReplyNeedAuth(const int);
	void slotQunJoinReplyDenied(const int);
	void slotQunJoinAuthReply(const int);
signals:
	void requestSearchUsers(const bool, const QString, const QString, const QString, const QString, const bool);
	void requestUserInfo(const int);
	void requestAddAuthBuddy(const int, const QString &);
	void requestAddBuddy(const int);
	
	void requestSearchQun(const int);
	void requestJoinQun(const int);
	void requestJoinQunAuth(const int, const QString &);
private:	
	const int idMin;
	const int idMax;
	QString id, nick, email;
		
	bool searchFinished;
	bool showAllUsers;
	bool isSearchQun;
	int selectedQunIndex;
	QunInfo selectedQun;
	int p2CurrentPage;
	std::map<int, std::list<OnlineUser> > userPages;  // index is page number
	
	std::list<QunInfo> qunList; // search qun result
	int currentPage;
	QValueStack<int> actionList;
	EvaImageResource *images;
	
	void resetWidgets();
	void processCurrentPage();
	void processPage0();
	void processPage1();
	void processPage2();
	void processPage3();
	void processPage4();
	int selectedP0Id;
	OnlineUser selectedUser;
	void displayUsers();

private slots:
	void  slotBgP0Clicked(int);
	void  slotPbP3P0SendClicked();
	void  slotPbP2DetailsClicked();
	void  slotPbP2NextClicked();
	void  slotPbP2PreClicked();
	void  slotPbP2AllClicked();
	void  slotNextClicked();
	void  slotPrevClicked();

	void  slotUserSelected(int);
};

#endif
