author | unc0rr |
Sat, 04 Jan 2014 23:55:54 +0400 | |
branch | webgl |
changeset 9950 | 2759212a27de |
parent 9360 | fc805fc427a6 |
child 9998 | 736015b847e3 |
permissions | -rw-r--r-- |
5080 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
9080 | 3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
5080 | 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 <QGridLayout> |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
20 |
#include <QHBoxLayout> |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
21 |
#include <QVBoxLayout> |
5080 | 22 |
#include <QPushButton> |
23 |
#include <QGroupBox> |
|
24 |
#include <QLabel> |
|
25 |
#include <QLineEdit> |
|
26 |
#include <QSpinBox> |
|
8749
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
27 |
#include <QTcpSocket> |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
28 |
#include <QHostAddress> |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
29 |
#include <QClipboard> |
5080 | 30 |
|
5204 | 31 |
#include "pagenetserver.h" |
8609
3f6c08223aa1
use NETGAME_DEFAULT_PORT macro across frontend sources
koda
parents:
6952
diff
changeset
|
32 |
#include "hwconsts.h" |
8749
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
33 |
#include "HWApplication.h" |
5080 | 34 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
35 |
QLayout * PageNetServer::bodyLayoutDefinition() |
5080 | 36 |
{ |
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
37 |
QVBoxLayout * pageLayout = new QVBoxLayout(); |
5080 | 38 |
|
39 |
QWidget * wg = new QWidget(this); |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
40 |
pageLayout->addWidget(wg); |
5080 | 41 |
|
42 |
QGridLayout * wgLayout = new QGridLayout(wg); |
|
43 |
wgLayout->setColumnStretch(0, 1); |
|
44 |
wgLayout->setColumnStretch(1, 3); |
|
45 |
wgLayout->setColumnStretch(2, 1); |
|
46 |
||
47 |
wgLayout->setRowStretch(0, 0); |
|
48 |
wgLayout->setRowStretch(1, 1); |
|
49 |
||
50 |
QGroupBox * gb = new QGroupBox(wg); |
|
51 |
wgLayout->addWidget(gb, 0, 1); |
|
52 |
||
53 |
QGridLayout * gbLayout = new QGridLayout(gb); |
|
54 |
||
55 |
labelSD = new QLabel(gb); |
|
56 |
labelSD->setText(QLabel::tr("Server name:")); |
|
57 |
gbLayout->addWidget(labelSD, 0, 0); |
|
58 |
||
59 |
leServerDescr = new QLineEdit(gb); |
|
60 |
gbLayout->addWidget(leServerDescr, 0, 1); |
|
61 |
||
62 |
labelPort = new QLabel(gb); |
|
63 |
labelPort->setText(QLabel::tr("Server port:")); |
|
64 |
gbLayout->addWidget(labelPort, 1, 0); |
|
65 |
||
66 |
sbPort = new QSpinBox(gb); |
|
8747 | 67 |
sbPort->setMinimum(1024); |
5080 | 68 |
sbPort->setMaximum(65535); |
69 |
gbLayout->addWidget(sbPort, 1, 1); |
|
70 |
||
71 |
BtnDefault = new QPushButton(gb); |
|
8748 | 72 |
BtnDefault->setMinimumWidth(50); |
73 |
BtnDefault->setText(QPushButton::tr("Reset")); |
|
74 |
BtnDefault->setWhatsThis(QPushButton::tr("Set the default server port for Hedgewars")); |
|
5080 | 75 |
gbLayout->addWidget(BtnDefault, 1, 2); |
76 |
||
8749
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
77 |
BtnShare = new QPushButton(gb); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
78 |
BtnShare->setText(QPushButton::tr("Invite your friends to your server in just 1 click!")); |
9360 | 79 |
BtnShare->setWhatsThis(QPushButton::tr("Click to copy your unique server URL to your clipboard. Send this link to your friends and they will be able to join you.")); |
8749
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
80 |
gbLayout->addWidget(BtnShare, 2, 1); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
81 |
|
8785 | 82 |
labelURL = new QLabel(gb); |
83 |
labelURL->setText( |
|
84 |
"<style type=\"text/css\"> a { color: #ffcc00; } </style>" |
|
85 |
"<div align=\"center\">" |
|
86 |
"<a href=\"https://code.google.com/p/hedgewars/wiki/HWPlaySchemeSyntax\">" + |
|
87 |
tr("Click here for details") + |
|
88 |
"</a></div>"); |
|
89 |
labelURL->setOpenExternalLinks(true); |
|
90 |
gbLayout->addWidget(labelURL, 3, 1); |
|
91 |
||
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
92 |
return pageLayout; |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
93 |
} |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
94 |
|
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
95 |
QLayout * PageNetServer::footerLayoutDefinition() |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
96 |
{ |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
97 |
QHBoxLayout * bottomLayout = new QHBoxLayout(); |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
98 |
|
6171 | 99 |
BtnStart = formattedButton(QPushButton::tr("Start")); |
8748 | 100 |
BtnStart->setWhatsThis(QPushButton::tr("Start private server")); |
6171 | 101 |
BtnStart->setMinimumWidth(180); |
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
102 |
|
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
103 |
bottomLayout->addStretch(); |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
104 |
bottomLayout->addWidget(BtnStart); |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
105 |
|
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
106 |
return bottomLayout; |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
107 |
} |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
108 |
|
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
109 |
void PageNetServer::connectSignals() |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
110 |
{ |
5080 | 111 |
connect(BtnDefault, SIGNAL(clicked()), this, SLOT(setDefaultPort())); |
8749
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
112 |
connect(BtnShare, SIGNAL(clicked()), this, SLOT(copyUrl())); |
5080 | 113 |
} |
114 |
||
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
115 |
PageNetServer::PageNetServer(QWidget* parent) : AbstractPage(parent) |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
116 |
{ |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
117 |
initPage(); |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
118 |
} |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
119 |
|
5080 | 120 |
void PageNetServer::setDefaultPort() |
121 |
{ |
|
8609
3f6c08223aa1
use NETGAME_DEFAULT_PORT macro across frontend sources
koda
parents:
6952
diff
changeset
|
122 |
sbPort->setValue(NETGAME_DEFAULT_PORT); |
5080 | 123 |
} |
8749
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
124 |
|
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
125 |
// This function assumes that the user wants to share his server while connected to |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
126 |
// the Internet and that he/she is using direct access (eg no NATs). To determine the |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
127 |
// IP we briefly connect to Hedgewars website and fallback to user intervention |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
128 |
// after 4 seconds of timeout. |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
129 |
void PageNetServer::copyUrl() |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
130 |
{ |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
131 |
QString address = "hwplay://"; |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
132 |
|
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
133 |
QTcpSocket socket; |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
134 |
socket.connectToHost("www.hedgewars.org", 80); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
135 |
if (socket.waitForConnected(4000)) |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
136 |
address += socket.localAddress().toString(); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
137 |
else |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
138 |
address += "<" + tr("Insert your address here") + ">"; |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
139 |
|
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
140 |
if (sbPort->value() != NETGAME_DEFAULT_PORT) |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
141 |
address += ":" + QString::number(sbPort->value()); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
142 |
|
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
143 |
QClipboard *clipboard = HWApplication::clipboard(); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
144 |
clipboard->setText(address); |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
145 |
qDebug() << address << "copied to clipboard"; |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
146 |
} |
1b9f026e9fc6
add one button to improve sharing of hwplay:// schemes
koda
parents:
8748
diff
changeset
|
147 |