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