update button for udp servers list
authordisplacer
Thu, 08 Feb 2007 19:03:23 +0000
changeset 416 595d8663254d
parent 415 d6d3a6a473a3
child 417 bc7fea9abd9c
update button for udp servers list
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/netudpwidget.cpp
QTfrontend/netudpwidget.h
QTfrontend/pages.cpp
QTfrontend/pages.h
--- a/QTfrontend/hwform.cpp	Thu Feb 08 16:29:33 2007 +0000
+++ b/QTfrontend/hwform.cpp	Thu Feb 08 19:03:23 2007 +0000
@@ -38,6 +38,7 @@
 #include "newnetclient.h"
 #include "gamecfgwidget.h"
 #include "netudpserver.h"
+#include "netudpwidget.h"
 
 HWForm::HWForm(QWidget *parent)
   : QMainWindow(parent), pnetserver(0), pUdpServer(0)
@@ -78,6 +79,8 @@
 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
+	connect(ui.pageNet->pUpdateUdpButt, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList()));
+	connect(ui.pageNet->pUdpClient->serversList,	SIGNAL(doubleClicked (const QModelIndex &)),	this, SLOT(NetConnectServer()));
 
 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
@@ -241,6 +244,19 @@
 	game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer);
 }
 
+void HWForm::NetConnectServer()
+{
+  QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem();
+  if (!curritem) {
+    QMessageBox::critical(this,
+			  tr("Error"),
+			  tr("Please, select server from the list above"),
+			  tr("OK"));
+    return ;
+  }
+  _NetConnect(curritem->text(), 46631, ui.pageNet->editNetNick->text());
+}
+
 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
 {
 	hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget);
--- a/QTfrontend/hwform.h	Thu Feb 08 16:29:33 2007 +0000
+++ b/QTfrontend/hwform.h	Thu Feb 08 19:03:23 2007 +0000
@@ -60,6 +60,7 @@
 	void SimpleGame();
 	void PlayDemo();
 	void NetConnect();
+	void NetConnectServer();
 	void NetStartServer();
 	void NetDisconnect();
 	void NetJoin();
--- a/QTfrontend/netudpwidget.cpp	Thu Feb 08 16:29:33 2007 +0000
+++ b/QTfrontend/netudpwidget.cpp	Thu Feb 08 19:03:23 2007 +0000
@@ -12,8 +12,14 @@
   mainLayout.addWidget(serversList);
   pUdpSocket = new QUdpSocket(this);
 
-  pUdpSocket->bind(46632);
+  pUdpSocket->bind(46632, QUdpSocket::ShareAddress);
   connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead()));
+  updateList();
+}
+
+void HWNetUdpWidget::updateList()
+{
+  serversList->clear();
   pUdpSocket->writeDatagram("hedgewars client", QHostAddress::Broadcast, 46631);
 }
 
--- a/QTfrontend/netudpwidget.h	Thu Feb 08 16:29:33 2007 +0000
+++ b/QTfrontend/netudpwidget.h	Thu Feb 08 19:03:23 2007 +0000
@@ -14,13 +14,17 @@
  public:
   HWNetUdpWidget(QWidget *parent = 0);
 
+  QListWidget* serversList;
+
+ public slots:
+  void updateList();
+
  private slots:
   void onClientRead();
 
  private:
   QVBoxLayout mainLayout;
   QUdpSocket* pUdpSocket;
-  QListWidget* serversList;
 };
 
 #endif // _NET_UDPWIDGET_INCLUDED
--- a/QTfrontend/pages.cpp	Thu Feb 08 16:29:33 2007 +0000
+++ b/QTfrontend/pages.cpp	Thu Feb 08 19:03:23 2007 +0000
@@ -397,7 +397,7 @@
 	NNGroupBox = new QGroupBox(this);
 	NNGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
 	NNGroupBox->setTitle(QGroupBox::tr("Net options"));
-	pageLayout->addWidget(NNGroupBox, 0, 1);
+	pageLayout->addWidget(NNGroupBox, 0, 1, 1, 2);
 
 	pageLayout->addWidget(new QWidget(), 1, 1);
 
@@ -419,18 +419,23 @@
 	editIP->setMaxLength(50);
 	GBNlayout->addWidget(editIP, 1, 1);
 
-	HWNetUdpWidget* pUdpClient=new HWNetUdpWidget(this);
-	pageLayout->addWidget(pUdpClient, 2, 1);
+	pUdpClient=new HWNetUdpWidget(this);
+	pageLayout->addWidget(pUdpClient, 2, 1, 1, 2);
 	
 	BtnNetConnect = new	QPushButton(this);
 	BtnNetConnect->setFont(*font14);
 	BtnNetConnect->setText(QPushButton::tr("Connect"));
-	pageLayout->addWidget(BtnNetConnect, 3, 2);
+	pageLayout->addWidget(BtnNetConnect, 3, 3);
+
+	pUpdateUdpButt = new QPushButton(this);
+	pUpdateUdpButt->setFont(*font14);
+	pUpdateUdpButt->setText(QPushButton::tr("Update"));
+	pageLayout->addWidget(pUpdateUdpButt, 3, 1);
 
 	BtnNetSvrStart = new	QPushButton(this);
 	BtnNetSvrStart->setFont(*font14);
 	BtnNetSvrStart->setText(QPushButton::tr("Start server"));
-	pageLayout->addWidget(BtnNetSvrStart, 3, 1);
+	pageLayout->addWidget(BtnNetSvrStart, 3, 2);
 
 	BtnBack = new QPushButton(this);
 	BtnBack->setFont(*font14);
--- a/QTfrontend/pages.h	Thu Feb 08 16:29:33 2007 +0000
+++ b/QTfrontend/pages.h	Thu Feb 08 19:03:23 2007 +0000
@@ -39,6 +39,7 @@
 class About;
 class QSpinBox;
 class FPSEdit;
+class HWNetUdpWidget;
 
 class PageMain : public QWidget
 {
@@ -159,6 +160,8 @@
 public:
 	PageNet(QWidget* parent = 0);
 
+	QPushButton* pUpdateUdpButt;
+	HWNetUdpWidget* pUdpClient;
 	QPushButton *BtnBack;
 	QPushButton *BtnNetConnect;
 	QPushButton* BtnNetSvrStart;