Actually pass host and port values to NetConnect method
authorunc0rr
Sat, 15 Dec 2007 22:57:22 +0000
changeset 671 a8970859f50e
parent 670 b4cc7ac9011f
child 672 08ed55ea1e2a
Actually pass host and port values to NetConnect method
QTfrontend/pages.cpp
--- a/QTfrontend/pages.cpp	Sat Dec 15 21:10:43 2007 +0000
+++ b/QTfrontend/pages.cpp	Sat Dec 15 22:57:22 2007 +0000
@@ -30,6 +30,7 @@
 #include <QTextEdit>
 #include <QRadioButton>
 #include <QTableView>
+#include <QMessageBox>
 
 #include "pages.h"
 #include "sdlkeys.h"
@@ -463,6 +464,7 @@
 	GBClayout->addWidget(BtnNetConnect, 2, 2);
 
 	tvServersList = new QTableView(ConnGroupBox);
+	tvServersList->setSelectionBehavior(QAbstractItemView::SelectRows);
 	GBClayout->addWidget(tvServersList, 1, 0, 1, 3);
 
 	BtnUpdateSList = new QPushButton(ConnGroupBox);
@@ -487,19 +489,28 @@
 void PageNet::updateServersList()
 {
 	if (rbLocalGame->isChecked())
-		tvServersList->setModel(new HWNetUdpModel());
+		tvServersList->setModel(new HWNetUdpModel(tvServersList));
 	else
-		tvServersList->setModel(new HWNetWwwModel());
+		tvServersList->setModel(new HWNetWwwModel(tvServersList));
 
 	static_cast<HWNetServersModel *>(tvServersList->model())->updateList();
 
 	connect(BtnUpdateSList, SIGNAL(clicked()), static_cast<HWNetServersModel *>(tvServersList->model()), SLOT(updateList()));
-//	connect(netServersWidget->serversList, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotConnect()));
+	connect(tvServersList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotConnect()));
 }
 
 void PageNet::slotConnect()
 {
-	emit connectClicked("localhost", 46631);
+	HWNetServersModel * model = static_cast<HWNetServersModel *>(tvServersList->model());
+	QModelIndex mi = tvServersList->currentIndex();
+	if(!mi.isValid())
+	{
+		QMessageBox::information(this, tr("Error"), tr("Please, select server from the list above"));
+		return;
+	}
+	QString host = model->index(mi.row(), 1).data().toString();
+	quint16 port = model->index(mi.row(), 2).data().toUInt();
+	emit connectClicked(host, 46631);
 }
 
 PageNetServer::PageNetServer(QWidget* parent) : QWidget(parent)