author | unc0rr |
Sun, 09 Dec 2007 11:25:59 +0000 | |
changeset 633 | 9050a949db21 |
parent 632 | 5e09ae25729f |
child 634 | b9db5ff5cfdb |
permissions | -rw-r--r-- |
625 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QHttp> |
|
20 |
#include <QListWidget> |
|
21 |
#include <QMessageBox> |
|
22 |
||
23 |
#include "netwwwwidget.h" |
|
24 |
#include "hwconsts.h" |
|
25 |
||
26 |
HWNetWwwWidget::HWNetWwwWidget(QWidget* parent) : |
|
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
27 |
HWNetServersWidget(parent), mainLayout(this) |
625 | 28 |
{ |
29 |
http = new QHttp(this); |
|
30 |
http->setHost("www.hedgewars.org", 80); |
|
31 |
connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onClientRead(int, bool))); |
|
32 |
} |
|
33 |
// http://hedgewars.org/games/create |
|
34 |
// http://www.hedgewars.org/games/update_game?id=1&key=pufidzuk |
|
35 |
// http://www.hedgewars.org/games/destroy_game?id=5&key=wrdeough |
|
36 |
void HWNetWwwWidget::updateList() |
|
37 |
{ |
|
38 |
http->abort(); |
|
39 |
// example for adding game to server list |
|
40 |
/* QString request = QString("game[title]=%1&game[port]=%2&game[password]=%3&game[protocol_version]=%4") |
|
41 |
.arg("hedgewarsserver") |
|
42 |
.arg(46631) |
|
43 |
.arg(false ? "true" : "false") |
|
44 |
.arg(*cProtoVer); |
|
45 |
http->post("/games/create", request.toUtf8()); |
|
46 |
*/ |
|
47 |
// query game list |
|
48 |
QString request = QString("protocol_version=%1") |
|
49 |
.arg(*cProtoVer); |
|
50 |
http->post("/games/list_games", request.toUtf8()); |
|
51 |
||
52 |
serversList->clear(); |
|
53 |
} |
|
54 |
||
55 |
void HWNetWwwWidget::onClientRead(int id, bool error) |
|
56 |
{ |
|
57 |
if (error) |
|
58 |
{ |
|
59 |
QMessageBox::critical(this, tr("Error"), http->errorString()); |
|
60 |
return; |
|
61 |
} |
|
62 |
serversList->addItem(http->readAll()); |
|
63 |
} |