The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_version.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2016 by Ignacio Riquelme Morelle <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "build_info.hpp"
20 #include "desktop/clipboard.hpp"
21 #include "desktop/open.hpp"
22 #include "desktop/version.hpp"
23 #include "filesystem.hpp"
24 #include "formula/string_utils.hpp"
25 #include "game_config.hpp"
26 #include "gettext.hpp"
28 #include "gui/dialogs/helper.hpp"
29 #include "gui/widgets/button.hpp"
30 #include "gui/widgets/control.hpp"
31 #ifdef GUI2_EXPERIMENTAL_LISTBOX
32 #include "gui/widgets/list.hpp"
33 #else
34 #include "gui/widgets/listbox.hpp"
35 #endif
37 #include "gui/widgets/settings.hpp"
39 #include "gui/widgets/text.hpp"
40 #include "gui/widgets/window.hpp"
41 #ifdef _WIN32
42 #include "log_windows.hpp"
43 #endif
45 
46 #include "gettext.hpp"
47 
48 #include "utils/functional.hpp"
49 
50 namespace
51 {
52 
53 const std::string text_feature_on = "<span color='#0f0'>&#9679;</span>";
54 const std::string text_feature_off = "<span color='#f00'>&#9679;</span>";
55 
56 } // end anonymous namespace
57 
58 namespace gui2
59 {
60 
61 /*WIKI
62  * @page = GUIWindowDefinitionWML
63  * @order = 2_game_version
64  *
65  * == Game paths ==
66  *
67  * Dialog displaying the various paths used by the game to locate
68  * resource and configuration files.
69  *
70  * There are several item types used to build widget ids in this dialog.
71  * All references to TYPE below refer to the following suffixes:
72  * datadir, config, userdata, saves, addons, cache.
73  *
74  * @begin{table}{dialog_widgets}
75  *
76  * path_TYPE & & text_box & m &
77  * Textbox containing the filesystem path for the given item. $
78  *
79  * copy_TYPE & & button & m &
80  * Copies the given item's path to clipboard. $
81  *
82  * browse_TYPE & & button & m &
83  * Launches the default file browser on the given item's path. $
84  *
85  * @end{table}
86  */
87 
88 REGISTER_DIALOG(game_version)
89 
91  : path_wid_stem_("path_")
92  , copy_wid_stem_("copy_")
93  , browse_wid_stem_("browse_")
94  , path_map_()
95 #ifdef _WIN32
96  , log_path_(lg::log_file_path())
97 #endif
98  , deps_()
100  , report_()
101 {
102  // NOTE: these path_map_ entries are referenced by the GUI2 WML
103  // definition of this dialog using preprocessor macros.
104  path_map_["datadir"] = game_config::path;
105  path_map_["config"] = filesystem::get_user_config_dir();
106  path_map_["userdata"] = filesystem::get_user_data_dir();
107  path_map_["saves"] = filesystem::get_saves_dir();
108  path_map_["addons"] = filesystem::get_addons_dir();
109  path_map_["cache"] = filesystem::get_cache_dir();
110 
111  for(unsigned k = 0; k < game_config::LIB_COUNT; ++k) {
113 
115  e[0] = game_config::library_name(lib);
116  if(e[0].empty()) {
117  continue;
118  }
121  deps_.push_back(e);
122  }
123 
124  generate_plain_text_report();
125 }
126 
128 {
129  string_map i18n_syms;
130 
131  //
132  // General information.
133  //
134 
135  tcontrol& version_label = find_widget<tcontrol>(&window, "version", false);
136  i18n_syms["version"] = game_config::revision;
137  version_label.set_label(VGETTEXT("Version $version", i18n_syms));
138 
139  tcontrol& os_label = find_widget<tcontrol>(&window, "os", false);
140  i18n_syms["os"] = desktop::os_version();
141  os_label.set_label(VGETTEXT("Running on $os", i18n_syms));
142 
143  tbutton& copy_all = find_widget<tbutton>(&window, "copy_all", false);
145  copy_all,
146  std::bind(&tgame_version::report_copy_callback, this));
147 
148  //
149  // Game paths tab.
150  //
151 
152  for(const auto & path_ent : path_map_)
153  {
154  const std::string& path_id = path_ent.first;
155  const std::string& path_path = path_ent.second;
156 
157  ttext_& path_w
158  = find_widget<ttext_>(&window, path_wid_stem_ + path_id, false);
159  tbutton& copy_w = find_widget<tbutton>(
160  &window, copy_wid_stem_ + path_id, false);
161  tbutton& browse_w = find_widget<tbutton>(
162  &window, browse_wid_stem_ + path_id, false);
163 
164  path_w.set_value(path_path);
165  path_w.set_active(false);
166 
168  copy_w,
170  this,
171  path_path));
173  browse_w,
175  this,
176  path_path));
177 
179  // No point in displaying these on platforms that can't do
180  // open_object().
181  browse_w.set_visible(tcontrol::tvisible::invisible);
182  }
183 
185  copy_w.set_active(false);
186  copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
187  }
188  }
189 
190 #ifndef _WIN32
191  tgrid& w32_options_grid
192  = find_widget<tgrid>(&window, "win32_paths", false);
193  w32_options_grid.set_visible(twidget::tvisible::invisible);
194 #else
195  tbutton& stderr_button
196  = find_widget<tbutton>(&window, "open_stderr", false);
198  stderr_button,
200  this,
201  log_path_));
202  stderr_button.set_active(!log_path_.empty());
203 #endif
204 
205  //
206  // Build info tab.
207  //
208 
209  std::map<std::string, string_map> list_data;
210 
211  tlistbox& deps_listbox
212  = find_widget<tlistbox>(&window, "deps_listbox", false);
213 
214  for(const auto & dep : deps_)
215  {
216  list_data["dep_name"]["label"] = dep[0];
217 
218  list_data["dep_build_version"]["label"] = dep[1];
219 
220  // The build version is always known, but runtime version isn't, esp.
221  // for header-only libraries like Boost for which the concept does not
222  // apply.
223  if(!dep[2].empty()) {
224  list_data["dep_rt_version"]["label"] = dep[2];
225  } else {
226  list_data["dep_rt_version"]["label"] = _("version^N/A");
227  }
228 
229  deps_listbox.add_row(list_data);
230  }
231 
232  deps_listbox.select_row(0);
233  list_data.clear();
234 
235  //
236  // Features tab.
237  //
238 
239  tlistbox& opts_listbox
240  = find_widget<tlistbox>(&window, "opts_listbox", false);
241 
242  for(const auto & opt : opts_)
243  {
244  list_data["opt_name"]["label"] = opt.name;
245 
246  if(opt.enabled) {
247  list_data["opt_status"]["label"] = text_feature_on;
248  } else {
249  list_data["opt_status"]["label"] = text_feature_off;
250  }
251  list_data["opt_status"]["use_markup"] = "true";
252 
253  opts_listbox.add_row(list_data);
254  }
255 
256  opts_listbox.select_row(0);
257  list_data.clear();
258 
259  //
260  // Set-up page stack and auxiliary controls last.
261  //
262 
263  tstacked_widget& pager
264  = find_widget<tstacked_widget>(&window, "tabs_container", false);
265  pager.select_layer(0);
266 
267  tlistbox& tab_bar
268  = find_widget<tlistbox>(&window, "tab_bar", false);
269 
270  list_data["tab_label"]["label"] = _("Paths");
271  tab_bar.add_row(list_data);
272 
273  list_data["tab_label"]["label"] = _("Libraries");
274  tab_bar.add_row(list_data);
275 
276  list_data["tab_label"]["label"] = _("Features");
277  tab_bar.add_row(list_data);
278 
279  tab_bar.select_row(0);
280  window.keyboard_capture(&tab_bar);
281 
282  const unsigned tab_count = tab_bar.get_item_count();
283  VALIDATE(tab_count == pager.get_layer_count(), "Tab bar and container size mismatch");
284 
285  for(unsigned k = 0; k < tab_count; ++k) {
286 #ifdef GUI2_EXPERIMENTAL_LISTBOX
289  *this,
290  std::ref(window)));
291 #else
293  dialog_callback<tgame_version, &tgame_version::tab_switch_callback>);
294 #endif
295  }
296 }
297 
299 {
300  tstacked_widget& pager
301  = find_widget<tstacked_widget>(&window, "tabs_container", false);
302  tlistbox& tab_bar
303  = find_widget<tlistbox>(&window, "tab_bar", false);
304 
305  pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
306 }
307 
309 {
310  desktop::open_object(path);
311 }
312 
314 {
316 }
317 
319 {
321 }
322 
324 {
325  std::ostringstream o;
326 
327  o << "The Battle for Wesnoth version " << game_config::revision << '\n'
328  << "Running on " << desktop::os_version() << '\n'
329  << '\n'
330  << "Game paths\n"
331  << "==========\n"
332  << '\n'
333  << "Data dir: " << path_map_["datadir"] << '\n'
334  << "User config dir: " << path_map_["config"] << '\n'
335  << "User data dir: " << path_map_["userdata"] << '\n'
336  << "Saves dir: " << path_map_["saves"] << '\n'
337  << "Add-ons dir: " << path_map_["addons"] << '\n'
338  << "Cache dir: " << path_map_["cache"] << '\n'
339  << '\n'
340  << "Libraries\n"
341  << "=========\n"
342  << '\n'
344  << '\n'
345  << "Features\n"
346  << "========\n"
347  << '\n'
349 
350  report_ = o.str();
351 }
352 
353 
354 } // end namespace gui2
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: button.cpp:58
void pre_show(twindow &window)
Inherited from tdialog.
std::string log_file_path()
Returns the path to the current log file.
std::string library_versions_report()
Produce a plain-text report of library versions suitable for stdout/stderr.
Definition: build_info.cpp:277
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:61
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: text.cpp:56
unsigned int get_layer_count() const
Gets the total number of layers.
std::string optional_features_report()
Produce a plain-text report of features suitable for stdout/stderr.
Definition: build_info.cpp:317
void browse_directory_callback(const std::string &path)
Callback function for browse-directory action buttons.
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.hpp:725
Base container class.
Definition: grid.hpp:29
This file contains the window object, this object is a top level container which has the event manage...
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
virtual void set_label(const t_string &label)
Definition: control.cpp:330
void select_layer(const int layer)
Selects and displays a particular layer.
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
const std::string & library_build_version(LIBRARY_ID lib)
Retrieve the build-time version number of the given library.
Definition: build_info.cpp:233
std::string get_saves_dir()
virtual void set_value(const std::string &text)
The set_value is virtual for the tpassword_box class.
Definition: text.cpp:95
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
void copy_to_clipboard_callback(const std::string &path)
Callback function for copy-to-clipboard action buttons.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Simple push button.
Definition: button.hpp:32
const std::string copy_wid_stem_
The user set the widget invisible, that means:
Definition: widget.hpp:103
Desktop environment interaction functions.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
GLsizei const char ** path
Definition: glew.h:4654
const std::string & library_name(LIBRARY_ID lib)
Retrieve the user-visible name for the given library.
Definition: build_info.cpp:251
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
std::vector< optional_feature > optional_features_table()
Return a localized features table.
Definition: build_info.cpp:223
This file contains the settings handling of the widget library.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:138
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
std::string get_user_data_dir()
const std::string path_wid_stem_
std::string path
const std::string browse_wid_stem_
std::map< std::string, std::string > path_map_
std::vector< deplist_entry > deps_
Platform identification and version information functions.
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
Definition: open.cpp:53
std::string get_cache_dir()
Log file control routines for Windows.
boost::array< std::string, 4 > deplist_entry
const std::string revision
Definition: game_config.cpp:57
#define VGETTEXT(msgid, symbols)
std::string os_version()
Returns a string with the running OS name and version information.
Definition: version.cpp:118
The listbox class.
Definition: listbox.hpp:39
const std::string & library_runtime_version(LIBRARY_ID lib)
Retrieve the runtime version number of the given library.
Definition: build_info.cpp:242
Declarations for File-IO.
std::vector< game_config::optional_feature > opts_
Base class for all visible items.
Definition: control.hpp:34
std::string get_user_config_dir()
bool open_object_is_supported()
Returns whether open_object() is supported/implemented for the current platform.
Definition: open.cpp:44
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Definition: clipboard.cpp:40
GLenum GLint ref
Definition: glew.h:1813
void report_copy_callback()
Callback function for the dialog-wide copy-to-clipboard button.
std::string get_addons_dir()
void generate_plain_text_report()
void tab_switch_callback(twindow &window)
Callback function called when switching tabs.
void set_callback_value_change(const std::function< void(twidget &)> &callback)
Definition: listbox.hpp:225
#define e
void set_visible(const tvisible::scoped_enum visible)
Definition: widget.cpp:445
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Abstract base class for text items.
Definition: text.hpp:43