1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2017-2019 The ManaPlus Developers |
4 |
|
|
* |
5 |
|
|
* This file is part of The ManaPlus Client. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "gui/windows/serverinfowindow.h" |
22 |
|
|
|
23 |
|
|
#include "enums/gui/layouttype.h" |
24 |
|
|
|
25 |
|
|
#include "gui/gui.h" |
26 |
|
|
|
27 |
|
|
#include "gui/widgets/layout.h" |
28 |
|
|
#include "gui/widgets/scrollarea.h" |
29 |
|
|
#include "gui/widgets/staticbrowserbox.h" |
30 |
|
|
|
31 |
|
|
#include "utils/foreach.h" |
32 |
|
|
#include "utils/gettext.h" |
33 |
|
|
#include "utils/process.h" |
34 |
|
|
|
35 |
|
|
#include "debug.h" |
36 |
|
|
|
37 |
|
|
ServerInfoWindow *serverInfoWindow = nullptr; |
38 |
|
|
|
39 |
|
1 |
ServerInfoWindow::ServerInfoWindow(ServerInfo &serverInfo) : |
40 |
|
|
// TRANSLATORS: servers dialog name |
41 |
|
1 |
Window(_("Server info"), Modal_false, nullptr, "serverinfo.xml"), |
42 |
|
|
LinkHandler(), |
43 |
|
|
mServerInfo(serverInfo), |
44 |
|
|
mBrowserBox(new StaticBrowserBox(this, Opaque_true, |
45 |
✓✗✓✗
|
1 |
"browserbox.xml")), |
46 |
|
1 |
mScrollArea(new ScrollArea(this, mBrowserBox, |
47 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
16 |
Opaque_true, "serverinfo_background.xml")) |
48 |
|
|
{ |
49 |
✓✗ |
1 |
setMinWidth(300); |
50 |
✓✗ |
1 |
setMinHeight(220); |
51 |
✓✗ |
1 |
setContentSize(455, 350); |
52 |
✓✗ |
5 |
setWindowName("ServerInfoWindow"); |
53 |
✓✗ |
1 |
setCloseButton(true); |
54 |
✓✗ |
1 |
setResizable(true); |
55 |
✓✗ |
1 |
setStickyButtonLock(true); |
56 |
|
|
|
57 |
✓✗ |
1 |
setDefaultSize(500, 400, ImagePosition::CENTER, 0, 0); |
58 |
|
|
|
59 |
|
2 |
mBrowserBox->setOpaque(Opaque_false); |
60 |
✓✗ |
1 |
mBrowserBox->setLinkHandler(this); |
61 |
✓✗ |
1 |
if (gui != nullptr) |
62 |
✓✗ |
2 |
mBrowserBox->setFont(gui->getHelpFont()); |
63 |
|
2 |
mBrowserBox->setProcessVars(true); |
64 |
|
2 |
mBrowserBox->setEnableTabs(true); |
65 |
|
|
|
66 |
✓✗ |
2 |
place(0, 0, mScrollArea, 5, 3).setPadding(3); |
67 |
|
|
|
68 |
✓✗ |
1 |
Layout &layout = getLayout(); |
69 |
✓✗ |
1 |
layout.setRowHeight(0, LayoutType::SET); |
70 |
|
|
|
71 |
✓✗ |
1 |
loadWindowState(); |
72 |
|
2 |
enableVisibleSound(true); |
73 |
✓✗ |
1 |
widgetResized(Event(nullptr)); |
74 |
|
1 |
} |
75 |
|
|
|
76 |
|
1 |
void ServerInfoWindow::postInit() |
77 |
|
|
{ |
78 |
|
1 |
Window::postInit(); |
79 |
|
1 |
setVisible(Visible_true); |
80 |
|
1 |
showServerInfo(); |
81 |
|
1 |
} |
82 |
|
|
|
83 |
|
3 |
ServerInfoWindow::~ServerInfoWindow() |
84 |
|
|
{ |
85 |
|
2 |
} |
86 |
|
|
|
87 |
|
|
void ServerInfoWindow::handleLink(const std::string &link, |
88 |
|
|
MouseEvent *const event A_UNUSED) |
89 |
|
|
{ |
90 |
|
|
if (strStartWith(link, "http://") || |
91 |
|
|
strStartWith(link, "https://")) |
92 |
|
|
{ |
93 |
|
|
openBrowser(link); |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
|
97 |
|
1 |
void ServerInfoWindow::showServerInfo() |
98 |
|
|
{ |
99 |
|
1 |
const ServerFreeTypeT type = mServerInfo.freeType; |
100 |
✗✓ |
1 |
if (type == ServerFreeType::Free) |
101 |
|
|
{ |
102 |
|
|
// TRANSLATORS: server info comment |
103 |
|
|
mBrowserBox->addRow(_("##BServer with free license."), |
104 |
|
|
false); |
105 |
|
|
} |
106 |
✗✓ |
1 |
else if (type == ServerFreeType::NonFree) |
107 |
|
|
{ |
108 |
|
|
// TRANSLATORS: server info comment |
109 |
|
|
mBrowserBox->addRow(_("##BServer with non free license."), |
110 |
|
|
false); |
111 |
|
|
} |
112 |
✓✗ |
1 |
else if (type == ServerFreeType::Unknown || |
113 |
|
|
type == ServerFreeType::NotSet) |
114 |
|
|
{ |
115 |
|
|
// TRANSLATORS: server info comment |
116 |
|
4 |
mBrowserBox->addRow(_("##BServer unknown license."), |
117 |
✓✗ |
1 |
false); |
118 |
|
|
} |
119 |
✓✗ |
4 |
mBrowserBox->addRow("", false); |
120 |
|
4 |
addServerComment(mServerInfo.serverUrl, |
121 |
|
|
// TRANSLATORS: server info comment |
122 |
✓✗ |
2 |
_("Server")); |
123 |
|
4 |
addServerComment(mServerInfo.supportUrl, |
124 |
|
|
// TRANSLATORS: server info comment |
125 |
✓✗ |
2 |
_("Support")); |
126 |
|
4 |
addServerComment(mServerInfo.registerUrl, |
127 |
|
|
// TRANSLATORS: server info comment |
128 |
✓✗ |
2 |
_("Register")); |
129 |
|
|
|
130 |
|
4 |
addSourcesList(mServerInfo.nonFreeSources, |
131 |
|
|
// TRANSLATORS: server info non free comment |
132 |
✓✗ |
2 |
_("##BNon free sources")); |
133 |
|
4 |
addSourcesList(mServerInfo.freeSources, |
134 |
|
|
// TRANSLATORS: server info free comment |
135 |
✓✗ |
2 |
_("##BFree sources")); |
136 |
|
4 |
addSourcesList(mServerInfo.docs, |
137 |
|
|
// TRANSLATORS: server info documentation comment |
138 |
✓✗ |
2 |
_("##BDocumentation")); |
139 |
|
1 |
mBrowserBox->updateHeight(); |
140 |
|
1 |
} |
141 |
|
|
|
142 |
|
3 |
void ServerInfoWindow::addSourcesList(const STD_VECTOR<ServerUrlInfo> &list, |
143 |
|
|
const std::string &comment) |
144 |
|
|
{ |
145 |
✗✓ |
3 |
if (!list.empty()) |
146 |
|
|
{ |
147 |
|
|
mBrowserBox->addRow("", false); |
148 |
|
|
mBrowserBox->addRow(comment, false); |
149 |
|
|
FOR_EACH (STD_VECTOR<ServerUrlInfo>::const_iterator, it, list) |
150 |
|
|
{ |
151 |
|
|
const ServerUrlInfo &info = *it; |
152 |
|
|
addServerComment(info.url, |
153 |
|
|
info.name); |
154 |
|
|
} |
155 |
|
|
} |
156 |
|
3 |
} |
157 |
|
|
|
158 |
|
3 |
void ServerInfoWindow::addServerComment(const std::string &url, |
159 |
|
|
const std::string &comment) |
160 |
|
|
{ |
161 |
|
6 |
std::string str; |
162 |
✗✓ |
3 |
if (!url.empty()) |
163 |
|
|
{ |
164 |
|
|
if (strStartWith(url, "http://") || |
165 |
|
|
strStartWith(url, "https://")) |
166 |
|
|
{ |
167 |
|
|
str = strprintf("%s: @@%s|@@##0", |
168 |
|
|
comment.c_str(), |
169 |
|
|
url.c_str()); |
170 |
|
|
} |
171 |
|
|
else |
172 |
|
|
{ |
173 |
|
|
str = strprintf("%s: %s", |
174 |
|
|
comment.c_str(), |
175 |
|
|
url.c_str()); |
176 |
|
|
} |
177 |
|
|
mBrowserBox->addRow(str, |
178 |
|
|
false); |
179 |
|
|
} |
180 |
|
3 |
} |
181 |
|
|
|
182 |
|
|
void ServerInfoWindow::close() |
183 |
|
|
{ |
184 |
|
|
Window::close(); |
185 |
|
|
if (serverInfoWindow == this) |
186 |
|
|
serverInfoWindow = nullptr; |
187 |
|
|
scheduleDelete(); |
188 |
|
|
} |