|
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) : |
|
27 QWidget(parent), mainLayout(this) |
|
28 { |
|
29 serversList = new QListWidget(this); |
|
30 mainLayout.setMargin(0); |
|
31 mainLayout.addWidget(serversList); |
|
32 |
|
33 http = new QHttp(this); |
|
34 http->setHost("www.hedgewars.org", 80); |
|
35 connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(onClientRead(int, bool))); |
|
36 updateList(); |
|
37 } |
|
38 // http://hedgewars.org/games/create |
|
39 // http://www.hedgewars.org/games/update_game?id=1&key=pufidzuk |
|
40 // http://www.hedgewars.org/games/destroy_game?id=5&key=wrdeough |
|
41 void HWNetWwwWidget::updateList() |
|
42 { |
|
43 http->abort(); |
|
44 // example for adding game to server list |
|
45 /* QString request = QString("game[title]=%1&game[port]=%2&game[password]=%3&game[protocol_version]=%4") |
|
46 .arg("hedgewarsserver") |
|
47 .arg(46631) |
|
48 .arg(false ? "true" : "false") |
|
49 .arg(*cProtoVer); |
|
50 http->post("/games/create", request.toUtf8()); |
|
51 */ |
|
52 // query game list |
|
53 QString request = QString("protocol_version=%1") |
|
54 .arg(*cProtoVer); |
|
55 http->post("/games/list_games", request.toUtf8()); |
|
56 |
|
57 serversList->clear(); |
|
58 } |
|
59 |
|
60 void HWNetWwwWidget::onClientRead(int id, bool error) |
|
61 { |
|
62 if (error) |
|
63 { |
|
64 QMessageBox::critical(this, tr("Error"), http->errorString()); |
|
65 return; |
|
66 } |
|
67 serversList->addItem(http->readAll()); |
|
68 } |