/***************************************************************************
 *   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 <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);
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);
private:	
	const int idMin;
	const int idMax;
	QString id, nick, email;
		
	bool searchFinished;
	bool showAllUsers;
	int p2CurrentPage;
	std::map<int, std::list<OnlineUser> > userPages;  // index is page number
	int currentPage;
	QValueStack<int> actionList;
	EvaImageResource *images;
	
	void resetWidgets();
	void processCurrentPage();
	void processPage0();
	void processPage1();
	void processPage2();
	void processPage3();
	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
