Half implement possibility for different backends of servers list
authorunc0rr
Sun, 09 Dec 2007 10:09:52 +0000
changeset 632 5e09ae25729f
parent 631 f7df3889f2ff
child 633 9050a949db21
Half implement possibility for different backends of servers list (www for getting list is supported now)
QTfrontend/CMakeLists.txt
QTfrontend/hedgewars.pro
QTfrontend/hwform.cpp
QTfrontend/netserverslist.cpp
QTfrontend/netserverslist.h
QTfrontend/netwwwwidget.cpp
QTfrontend/netwwwwidget.h
QTfrontend/pages.cpp
QTfrontend/pages.h
--- a/QTfrontend/CMakeLists.txt	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/CMakeLists.txt	Sun Dec 09 10:09:52 2007 +0000
@@ -63,6 +63,7 @@
 	netudpserver.cpp
 	netudpwidget.cpp
 	netwwwwidget.cpp
+	netserverslist.cpp
 	chatwidget.cpp
 	binds.cpp
 	SDLs.cpp
@@ -100,6 +101,7 @@
 	netudpserver.h
 	netudpwidget.h
 	netwwwwidget.h
+	netserverslist.h
 	chatwidget.h
 	SDLs.h
 	playrecordpage.h
--- a/QTfrontend/hedgewars.pro	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/hedgewars.pro	Sun Dec 09 10:09:52 2007 +0000
@@ -39,6 +39,7 @@
            netudpserver.h \
            netudpwidget.h \
 	   netwwwwidget.h \
+	   netserverslist.h \
            chatwidget.h \
            SDLs.h \
            playrecordpage.h \
@@ -73,7 +74,8 @@
            newnetclient.cpp \
            netudpserver.cpp \
            netudpwidget.cpp \
-	   netwwwwidget.h \
+	   netwwwwidget.cpp \
+	   netserverslist.cpp \
            chatwidget.cpp \
            SDLs.cpp \
            playrecordpage.cpp \
--- a/QTfrontend/hwform.cpp	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sun Dec 09 10:09:52 2007 +0000
@@ -40,7 +40,7 @@
 #include "hwconsts.h"
 #include "newnetclient.h"
 #include "gamecfgwidget.h"
-#include "netudpserver.h"
+#include "netserverslist.h"
 #include "netudpwidget.h"
 #include "netwwwwidget.h"
 #include "chatwidget.h"
@@ -50,7 +50,6 @@
   : QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0)
 {
 	ui.setupUi(this);
-
 	config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
 
 	UpdateTeamsLists();
@@ -91,9 +90,6 @@
 	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.pageMain->BtnNet,	SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList()));
-	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()));
@@ -192,6 +188,9 @@
 
 void HWForm::GoToNet()
 {
+	ui.pageNet->changeServersList();
+	connect(ui.pageNet->netServersWidget->serversList,	SIGNAL(doubleClicked (const QModelIndex &)),	this, SLOT(NetConnectServer()));
+
 	GoToPage(ID_PAGE_NET);
 }
 
@@ -332,7 +331,7 @@
 
 void HWForm::NetConnectServer()
 {
-  QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem();
+  QListWidgetItem * curritem = ui.pageNet->netServersWidget->serversList->currentItem();
   if (!curritem) {
     QMessageBox::critical(this,
 			  tr("Error"),
@@ -401,7 +400,7 @@
   pnetserver = new HWNetServer;
   pnetserver->StartServer();
   _NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text());
-  pUdpServer = new HWNetUdpServer();
+//  pUdpServer = new HWNetUdpServer();
 }
 
 void HWForm::NetDisconnect()
@@ -412,7 +411,7 @@
     hwnet=0;
   }
   if(pnetserver) {
-    pUdpServer->deleteLater();
+//    pUdpServer->deleteLater();
     pnetserver->StopServer();
     delete pnetserver;
     pnetserver=0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/netserverslist.cpp	Sun Dec 09 10:09:52 2007 +0000
@@ -0,0 +1,35 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.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; version 2 of the License
+ *
+ * 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
+ */
+
+#include <QUdpSocket>
+#include <QListWidget>
+
+#include "netserverslist.h"
+
+HWNetServersWidget::HWNetServersWidget(QWidget* parent) :
+  QWidget(parent), mainLayout(this)
+{
+	serversList = new QListWidget(this);
+	mainLayout.setMargin(0);
+	mainLayout.addWidget(serversList);
+}
+
+void HWNetServersWidget::updateList()
+{
+	serversList->clear();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/netserverslist.h	Sun Dec 09 10:09:52 2007 +0000
@@ -0,0 +1,42 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.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; version 2 of the License
+ *
+ * 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 _NET_SERVERSLIST_INCLUDED
+#define _NET_SERVERSLIST_INCLUDED
+
+#include <QWidget>
+#include <QVBoxLayout>
+#include <QListWidget>
+
+class HWNetServersWidget : public QWidget
+{
+	Q_OBJECT
+
+public:
+	HWNetServersWidget (QWidget *parent = 0);
+
+	QListWidget* serversList;
+
+public slots:
+	void updateList();
+
+private:
+	QVBoxLayout mainLayout;
+};
+
+#endif // _NET_SERVERSLIST_INCLUDED
--- a/QTfrontend/netwwwwidget.cpp	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/netwwwwidget.cpp	Sun Dec 09 10:09:52 2007 +0000
@@ -24,16 +24,11 @@
 #include "hwconsts.h"
 
 HWNetWwwWidget::HWNetWwwWidget(QWidget* parent) :
-  QWidget(parent), mainLayout(this)
+  HWNetServersWidget(parent), mainLayout(this)
 {
-	serversList = new QListWidget(this);
-	mainLayout.setMargin(0);
-	mainLayout.addWidget(serversList);
-
 	http = new QHttp(this);
 	http->setHost("www.hedgewars.org", 80);
 	connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onClientRead(int, bool)));
-	updateList();
 }
 // http://hedgewars.org/games/create
 // http://www.hedgewars.org/games/update_game?id=1&key=pufidzuk
--- a/QTfrontend/netwwwwidget.h	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/netwwwwidget.h	Sun Dec 09 10:09:52 2007 +0000
@@ -19,21 +19,18 @@
 #ifndef _NET_WWWWIDGET_INCLUDED
 #define _NET_WWWWIDGET_INCLUDED
 
-#include <QWidget>
-#include <QVBoxLayout>
+#include "netserverslist.h"
 
 class QListWidget;
 class QHttp;
 
-class HWNetWwwWidget : public QWidget
+class HWNetWwwWidget : public HWNetServersWidget
 {
-  Q_OBJECT
+ 	Q_OBJECT
 
 public:
 	HWNetWwwWidget(QWidget *parent = 0);
 
-	QListWidget* serversList;
-
 public slots:
 	void updateList();
 
--- a/QTfrontend/pages.cpp	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/pages.cpp	Sun Dec 09 10:09:52 2007 +0000
@@ -39,7 +39,9 @@
 #include "mapContainer.h"
 #include "about.h"
 #include "fpsedit.h"
+#include "netserverslist.h"
 #include "netudpwidget.h"
+#include "netwwwwidget.h"
 #include "chatwidget.h"
 #include "SDLs.h"
 #include "playrecordpage.h"
@@ -432,10 +434,10 @@
 	editNetNick->setText(QLineEdit::tr("unnamed"));
 	GBNlayout->addWidget(editNetNick, 0, 1);
 
-	QGroupBox * ConnGroupBox = new QGroupBox(this);
+	ConnGroupBox = new QGroupBox(this);
 	ConnGroupBox->setTitle(QGroupBox::tr("Net game"));
 	pageLayout->addWidget(ConnGroupBox, 2, 0, 1, 3);
-	QGridLayout * GBClayout = new QGridLayout(ConnGroupBox);
+	GBClayout = new QGridLayout(ConnGroupBox);
 	GBClayout->setColumnStretch(0, 0);
 	GBClayout->setColumnStretch(1, 1);
 	GBClayout->setColumnStretch(2, 1);
@@ -451,18 +453,17 @@
 	editIP->setMaxLength(50);
 	GBClayout->addWidget(editIP, 0, 1);
 
-	BtnNetConnect = new	QPushButton(ConnGroupBox);
+	BtnNetConnect = new QPushButton(ConnGroupBox);
 	BtnNetConnect->setFont(*font14);
 	BtnNetConnect->setText(QPushButton::tr("Connect"));
 	GBClayout->addWidget(BtnNetConnect, 0, 2);
 
-	pUdpClient=new HWNetUdpWidget(ConnGroupBox);
-	GBClayout->addWidget(pUdpClient, 1, 0, 2, 2);
+	netServersWidget = 0;
 
-	pUpdateUdpButt = new QPushButton(ConnGroupBox);
-	pUpdateUdpButt->setFont(*font14);
-	pUpdateUdpButt->setText(QPushButton::tr("Update"));
-	GBClayout->addWidget(pUpdateUdpButt, 1, 2);
+	BtnUpdateSList = new QPushButton(ConnGroupBox);
+	BtnUpdateSList->setFont(*font14);
+	BtnUpdateSList->setText(QPushButton::tr("Update"));
+	GBClayout->addWidget(BtnUpdateSList, 1, 2);
 
 	BtnBack = new QPushButton(this);
 	BtnBack->setFont(*font14);
@@ -470,6 +471,17 @@
 	pageLayout->addWidget(BtnBack, 3, 0);
 }
 
+void PageNet::changeServersList()
+{
+	if (netServersWidget) delete netServersWidget;
+
+	netServersWidget = new HWNetWwwWidget(ConnGroupBox);
+	GBClayout->addWidget(netServersWidget, 1, 0, 2, 2);
+
+	connect(BtnUpdateSList, SIGNAL(clicked()), netServersWidget, SLOT(updateList()));
+	netServersWidget->updateList();
+}
+
 PageNetGame::PageNetGame(QWidget* parent) : QWidget(parent)
 {
 	QFont * font14 = new QFont("MS Shell Dlg", 14);
--- a/QTfrontend/pages.h	Thu Dec 06 20:31:56 2007 +0000
+++ b/QTfrontend/pages.h	Sun Dec 09 10:09:52 2007 +0000
@@ -43,6 +43,7 @@
 class QTextEdit;
 class HWChatWidget;
 class SelWeaponWidget;
+class HWNetServersWidget;
 
 class PageMain : public QWidget
 {
@@ -154,8 +155,8 @@
 public:
 	PageNet(QWidget* parent = 0);
 
-	QPushButton* pUpdateUdpButt;
-	HWNetUdpWidget* pUdpClient;
+	QPushButton* BtnUpdateSList;
+	HWNetServersWidget* netServersWidget;
 	QPushButton *BtnBack;
 	QPushButton *BtnNetConnect;
 	QPushButton* BtnNetSvrStart;
@@ -164,6 +165,13 @@
 	QLineEdit *editNetNick;
 	QLabel *labelIP;
 	QLineEdit * editIP;
+
+private:
+	QGroupBox * ConnGroupBox;
+	QGridLayout * GBClayout;
+
+public slots:
+	void changeServersList();
 };
 
 class PageNetGame : public QWidget