1 /*****************************************************************************
2  * PokerTH - The open source texas holdem engine                             *
3  * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May          *
4  *                                                                           *
5  * This program is free software: you can redistribute it and/or modify      *
6  * it under the terms of the GNU Affero General Public License as            *
7  * published by the Free Software Foundation, either version 3 of the        *
8  * License, or (at your option) any later version.                           *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU Affero General Public License for more details.                       *
14  *                                                                           *
15  * You should have received a copy of the GNU Affero General Public License  *
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.     *
17  *                                                                           *
18  *                                                                           *
19  * Additional permission under GNU AGPL version 3 section 7                  *
20  *                                                                           *
21  * If you modify this program, or any covered work, by linking or            *
22  * combining it with the OpenSSL project's OpenSSL library (or a             *
23  * modified version of that library), containing parts covered by the        *
24  * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH           *
25  * (Felix Hammer, Florian Thauer, Lothar May) grant you additional           *
26  * permission to convey the resulting work.                                  *
27  * Corresponding Source for a non-source form of such a combination          *
28  * shall include the source code for the parts of OpenSSL used as well       *
29  * as that of the covered work.                                              *
30  *****************************************************************************/
31 #include "serverlistdialogimpl.h"
32 #include "configfile.h"
33 #include "startwindowimpl.h"
34 #include "connecttoserverdialogimpl.h"
35 #include "serverdata.h"
36 #include "session.h"
37 
serverListDialogImpl(startWindowImpl * sw,QMainWindow * parent,ConfigFile * c)38 serverListDialogImpl::serverListDialogImpl(startWindowImpl *sw, QMainWindow *parent, ConfigFile *c)
39 	: QDialog(parent), myConfig(c), mySw(sw)
40 {
41 #ifdef __APPLE__
42 	setWindowModality(Qt::ApplicationModal);
43 	setWindowFlags(Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint | Qt::Dialog);
44 #endif
45 	setupUi(this);
46 #ifdef ANDROID
47 	this->setWindowState(Qt::WindowFullScreen);
48 #endif
49 	connect( treeWidget_serverList, SIGNAL( itemDoubleClicked ( QTreeWidgetItem*, int) ), this, SLOT( connectToServer() ));
50 	connect( buttonBox, SIGNAL( accepted() ), this, SLOT( connectToServer() ));
51 	connect( buttonBox, SIGNAL( rejected() ), this, SLOT( closeNetworkClient() ));
52 	connect( this, SIGNAL( rejected() ), this, SLOT( closeNetworkClient() ));
53 }
54 
exec()55 int serverListDialogImpl::exec()
56 {
57 	return QDialog::exec();
58 }
59 
clearList()60 void serverListDialogImpl::clearList()
61 {
62 	treeWidget_serverList->clear();
63 }
64 
addServerItem(unsigned serverId)65 void serverListDialogImpl::addServerItem(unsigned serverId)
66 {
67 	ServerInfo info = mySw->getSession()->getClientServerInfo(serverId);
68 	QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_serverList);
69 	item->setData(0, Qt::DisplayRole, QString::fromUtf8(info.name.c_str()));
70 	item->setData(0, Qt::UserRole, serverId);
71 	item->setData(1, Qt::DisplayRole, QString::fromUtf8(info.country.c_str()));
72 
73 	treeWidget_serverList->resizeColumnToContents(0);
74 	treeWidget_serverList->setCurrentItem(treeWidget_serverList->topLevelItem(0));
75 }
76 
connectToServer()77 void serverListDialogImpl::connectToServer()
78 {
79 	QTreeWidgetItem *item = treeWidget_serverList->currentItem();
80 	if (item) {
81 		mySw->getSession()->selectServer(item->data(0, Qt::UserRole).toUInt());
82 	}
83 	this->hide();
84 }
85 
closeNetworkClient()86 void serverListDialogImpl::closeNetworkClient()
87 {
88 
89 	mySw->getSession()->terminateNetworkClient();
90 	mySw->getMyConnectToServerDialog()->reject();
91 }
92