QTfrontend/ui/page/pagenetserver.cpp
author Simon McVittie <smcv@debian.org>
Mon, 12 Sep 2022 10:40:53 -0400
branch1.0.0
changeset 15859 7b1d6dfa3173
parent 12267 dad24eb53873
child 15788 acf70c44065b
permissions -rw-r--r--
Remove FindSDL2 find-module, use sdl2-config.cmake instead This requires SDL >= 2.0.4. Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was not itself built using CMake: it installs a sdl2-config.cmake file to ${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and library, analogous to a pkg-config .pc file. As a result, we no longer need to copy/paste a "find-module package" to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2). Find-module packages are now discouraged by the CMake developers, in favour of having upstream projects behave as config-file packages. This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR and SDL2_LIBRARY, but the standard behaviour for config-file packages is to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword to make sure we search in config-file package mode, and will not find a FindSDL2.cmake in some other directory that implements the old interface. In addition to deleting redundant code, this avoids some assumptions in FindSDL2 about the layout of a SDL installation. The current libsdl2-dev package in Debian breaks those assumptions; this is considered a bug and will hopefully be fixed soon, but it illustrates how fragile these assumptions can be. We can be more robust against different installation layouts by relying on SDL's own CMake integration. When linking to a copy of CMake in a non-standard location, users can now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point to it; previously, these users would have used the SDL2DIR environment variable. This continues to be unnecessary if using matching system-wide installations of CMake and SDL2, for example both from Debian.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5080
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     1
/*
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
5080
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     4
 *
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     8
 *
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    13
 *
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10017
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
5080
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    17
 */
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    18
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    22
#include <QPushButton>
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    23
#include <QGroupBox>
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    24
#include <QLabel>
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    25
#include <QLineEdit>
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    30
5204
e1a5f4d5d86a split pages.h into several header files
koda
parents: 5080
diff changeset
    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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    38
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    41
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    42
    QGridLayout * wgLayout = new QGridLayout(wg);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    43
    wgLayout->setColumnStretch(0, 1);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    44
    wgLayout->setColumnStretch(1, 3);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    45
    wgLayout->setColumnStretch(2, 1);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    46
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    47
    wgLayout->setRowStretch(0, 0);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    48
    wgLayout->setRowStretch(1, 1);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    49
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    50
    QGroupBox * gb = new QGroupBox(wg);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    51
    wgLayout->addWidget(gb, 0, 1);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    52
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    53
    QGridLayout * gbLayout = new QGridLayout(gb);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    54
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    55
    labelSD = new QLabel(gb);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    56
    labelSD->setText(QLabel::tr("Server name:"));
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    57
    gbLayout->addWidget(labelSD, 0, 0);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    58
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    59
    leServerDescr = new QLineEdit(gb);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    60
    gbLayout->addWidget(leServerDescr, 0, 1);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    61
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    62
    labelPort = new QLabel(gb);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    63
    labelPort->setText(QLabel::tr("Server port:"));
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    64
    gbLayout->addWidget(labelPort, 1, 0);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    65
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    66
    sbPort = new QSpinBox(gb);
8747
878aa4c92424 do not host server on well-known ports
koda
parents: 8609
diff changeset
    67
    sbPort->setMinimum(1024);
5080
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    68
    sbPort->setMaximum(65535);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    69
    gbLayout->addWidget(sbPort, 1, 1);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    70
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    71
    BtnDefault = new QPushButton(gb);
8748
fbd7f0b21e12 help text for pagenetserver
koda
parents: 8747
diff changeset
    72
    BtnDefault->setMinimumWidth(50);
fbd7f0b21e12 help text for pagenetserver
koda
parents: 8747
diff changeset
    73
    BtnDefault->setText(QPushButton::tr("Reset"));
fbd7f0b21e12 help text for pagenetserver
koda
parents: 8747
diff changeset
    74
    BtnDefault->setWhatsThis(QPushButton::tr("Set the default server port for Hedgewars"));
5080
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    75
    gbLayout->addWidget(BtnDefault, 1, 2);
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    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
fc805fc427a6 typo fix
nemo
parents: 9080
diff changeset
    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
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    82
    labelURL = new QLabel(gb);
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    83
    labelURL->setText(
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    84
              "<style type=\"text/css\"> a { color: #ffcc00; } </style>"
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    85
              "<div align=\"center\">"
12267
dad24eb53873 Fix broken URL in pagenetserver
Wuzzy <almikes@aol.com>
parents: 11819
diff changeset
    86
              "<a href=\"https://hedgewars.org/kb/HWPlaySchemeSyntax\">" +
8785
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    87
              tr("Click here for details") +
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    88
              "</a></div>");
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    89
    labelURL->setOpenExternalLinks(true);
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    90
    gbLayout->addWidget(labelURL, 3, 1);
b26bc69022f7 add wiki link for the scheme handling
koda
parents: 8749
diff changeset
    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
8627698134b6 fix layout of net page
sheepluva
parents: 6060
diff changeset
    99
    BtnStart = formattedButton(QPushButton::tr("Start"));
8748
fbd7f0b21e12 help text for pagenetserver
koda
parents: 8747
diff changeset
   100
    BtnStart->setWhatsThis(QPushButton::tr("Start private server"));
11819
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11515
diff changeset
   101
    BtnStart->setMinimumSize(180, 50);
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();
11819
7642955690bc Tweak sizes and icons of most footer buttons of frontend
Wuzzy <almikes@aol.com>
parents: 11515
diff changeset
   104
    bottomLayout->addWidget(BtnStart, 0, Qt::AlignBottom);
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
   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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   113
}
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   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
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   120
void PageNetServer::setDefaultPort()
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   121
{
8609
3f6c08223aa1 use NETGAME_DEFAULT_PORT macro across frontend sources
koda
parents: 6952
diff changeset
   122
    sbPort->setValue(NETGAME_DEFAULT_PORT);
5080
2e29c1e1c9cd I forgot to add this file.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   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
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   127
// IP we briefly connect to Hedgewars website and fallback to user intervention
8749
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