The Battle for Wesnoth  1.13.11+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 - 2018 by Iris Morelle <shadowm2006@gmail.com>
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 "game_config.hpp"
25 #include "gettext.hpp"
27 #include "gui/dialogs/helper.hpp"
28 #include "gui/widgets/button.hpp"
30 #ifdef GUI2_EXPERIMENTAL_LISTBOX
31 #include "gui/widgets/list.hpp"
32 #else
33 #include "gui/widgets/listbox.hpp"
34 #endif
36 #include "gui/widgets/settings.hpp"
39 #include "gui/widgets/window.hpp"
40 #ifdef _WIN32
41 #include "log_windows.hpp"
42 #endif
43 #include "formula/string_utils.hpp"
44 
45 #include "gettext.hpp"
46 
47 #include "utils/functional.hpp"
48 
49 namespace
50 {
51 
52 const std::string text_feature_on = "<span color='#0f0'>&#9679;</span>";
53 const std::string text_feature_off = "<span color='#f00'>&#9679;</span>";
54 
55 } // end anonymous namespace
56 
57 namespace gui2
58 {
59 namespace dialogs
60 {
61 
62 /*WIKI
63  * @page = GUIWindowDefinitionWML
64  * @order = 2_game_version
65  *
66  * == Game paths ==
67  *
68  * Dialog displaying the various paths used by the game to locate
69  * resource and configuration files.
70  *
71  * There are several item types used to build widget ids in this dialog.
72  * All references to TYPE below refer to the following suffixes:
73  * datadir, config, userdata, saves, addons, cache.
74  *
75  * @begin{table}{dialog_widgets}
76  *
77  * path_TYPE & & text_box & m &
78  * Textbox containing the filesystem path for the given item. $
79  *
80  * copy_TYPE & & button & m &
81  * Copies the given item's path to clipboard. $
82  *
83  * browse_TYPE & & button & m &
84  * Launches the default file browser on the given item's path. $
85  *
86  * @end{table}
87  */
88 
89 REGISTER_DIALOG(game_version)
90 
92  : path_wid_stem_("path_")
93  , copy_wid_stem_("copy_")
94  , browse_wid_stem_("browse_")
95  , path_map_()
96 #ifdef _WIN32
97  , log_path_(lg::log_file_path())
98 #endif
99  , deps_()
101  , report_()
102 {
103  // NOTE: these path_map_ entries are referenced by the GUI2 WML
104  // definition of this dialog using preprocessor macros.
105  path_map_["datadir"] = game_config::path;
106  path_map_["config"] = filesystem::get_user_config_dir();
107  path_map_["userdata"] = filesystem::get_user_data_dir();
108  path_map_["saves"] = filesystem::get_saves_dir();
109  path_map_["addons"] = filesystem::get_addons_dir();
110  path_map_["cache"] = filesystem::get_cache_dir();
111 
112  for(unsigned k = 0; k < game_config::LIB_COUNT; ++k) {
114 
116  e[0] = game_config::library_name(lib);
117  if(e[0].empty()) {
118  continue;
119  }
122  deps_.push_back(e);
123  }
124 
125  generate_plain_text_report();
126 }
127 
129 {
130  string_map i18n_syms;
131 
132  //
133  // General information.
134  //
135 
136  styled_widget& version_label = find_widget<styled_widget>(&window, "version", false);
137  i18n_syms["version"] = game_config::revision;
138  version_label.set_label(VGETTEXT("Version $version", i18n_syms));
139 
140  styled_widget& os_label = find_widget<styled_widget>(&window, "os", false);
141  i18n_syms["os"] = desktop::os_version();
142  os_label.set_label(VGETTEXT("Running on $os", i18n_syms));
143 
144  button& copy_all = find_widget<button>(&window, "copy_all", false);
146  copy_all,
147  std::bind(&game_version::report_copy_callback, this));
148 
149  //
150  // Game paths tab.
151  //
152 
153  for(const auto & path_ent : path_map_)
154  {
155  const std::string& path_id = path_ent.first;
156  const std::string& path_path = path_ent.second;
157 
158  text_box_base& path_w
159  = find_widget<text_box_base>(&window, path_wid_stem_ + path_id, false);
160  button& copy_w = find_widget<button>(
161  &window, copy_wid_stem_ + path_id, false);
162  button& browse_w = find_widget<button>(
163  &window, browse_wid_stem_ + path_id, false);
164 
165  path_w.set_value(path_path);
166  path_w.set_active(false);
167 
169  copy_w,
171  this,
172  path_path));
174  browse_w,
176  this,
177  path_path));
178 
180  // No point in displaying these on platforms that can't do
181  // open_object().
182  browse_w.set_visible(widget::visibility::invisible);
183  }
184 
186  copy_w.set_active(false);
187  copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
188  }
189  }
190 
191 #ifndef _WIN32
192  grid& w32_options_grid
193  = find_widget<grid>(&window, "win32_paths", false);
194  w32_options_grid.set_visible(widget::visibility::invisible);
195 #else
196  button& stderr_button
197  = find_widget<button>(&window, "open_stderr", false);
199  stderr_button,
201  this,
202  log_path_));
203  stderr_button.set_active(!log_path_.empty());
204 #endif
205 
206  //
207  // Build info tab.
208  //
209 
210  std::map<std::string, string_map> list_data;
211 
212  listbox& deps_listbox
213  = find_widget<listbox>(&window, "deps_listbox", false);
214 
215  for(const auto & dep : deps_)
216  {
217  list_data["dep_name"]["label"] = dep[0];
218 
219  list_data["dep_build_version"]["label"] = dep[1];
220 
221  // The build version is always known, but runtime version isn't, esp.
222  // for header-only libraries like Boost for which the concept does not
223  // apply.
224  if(!dep[2].empty()) {
225  list_data["dep_rt_version"]["label"] = dep[2];
226  } else {
227  list_data["dep_rt_version"]["label"] = _("version^N/A");
228  }
229 
230  deps_listbox.add_row(list_data);
231  }
232 
233  deps_listbox.select_row(0);
234  list_data.clear();
235 
236  //
237  // Features tab.
238  //
239 
240  listbox& opts_listbox
241  = find_widget<listbox>(&window, "opts_listbox", false);
242 
243  for(const auto & opt : opts_)
244  {
245  list_data["opt_name"]["label"] = opt.name;
246 
247  if(opt.enabled) {
248  list_data["opt_status"]["label"] = text_feature_on;
249  } else {
250  list_data["opt_status"]["label"] = text_feature_off;
251  }
252  list_data["opt_status"]["use_markup"] = "true";
253 
254  opts_listbox.add_row(list_data);
255  }
256 
257  opts_listbox.select_row(0);
258  list_data.clear();
259 
260  //
261  // Set-up page stack and auxiliary controls last.
262  //
263 
264  stacked_widget& pager
265  = find_widget<stacked_widget>(&window, "tabs_container", false);
266  pager.select_layer(0);
267 
268  listbox& tab_bar
269  = find_widget<listbox>(&window, "tab_bar", false);
270 
271  window.keyboard_capture(&tab_bar);
272 
273  const unsigned tab_count = tab_bar.get_item_count();
274  VALIDATE(tab_count == pager.get_layer_count(), "Tab bar and container size mismatch");
275 
277  std::bind(&game_version::tab_switch_callback, this, std::ref(window)));
278 }
279 
281 {
282  stacked_widget& pager
283  = find_widget<stacked_widget>(&window, "tabs_container", false);
284  listbox& tab_bar
285  = find_widget<listbox>(&window, "tab_bar", false);
286 
287  pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
288 }
289 
291 {
292  desktop::open_object(path);
293 }
294 
296 {
298 }
299 
301 {
303 }
304 
306 {
308 }
309 
310 } // namespace dialogs
311 } // namespace gui2
std::vector< char_t > string
void report_copy_callback()
Callback function for the dialog-wide copy-to-clipboard button.
Abstract base class for text items.
const std::string path_wid_stem_
The display function.
std::string log_file_path()
Returns the path to the current log file.
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:56
std::map< std::string, std::string > path_map_
This file contains the window object, this object is a top level container which has the event manage...
std::array< std::string, 4 > deplist_entry
const std::string & library_build_version(LIBRARY_ID lib)
Retrieve the build-time version number of the given library.
Definition: build_info.cpp:341
virtual void pre_show(window &window) override
Inherited from modal_dialog.
std::string get_saves_dir()
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:252
Generic file dialog.
Definition: field-fwd.hpp:22
virtual void set_label(const t_string &label)
const std::string browse_wid_stem_
The listbox class.
Definition: listbox.hpp:42
Base container class.
Definition: grid.hpp:30
Desktop environment interaction functions.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
void copy_to_clipboard_callback(const std::string &path)
Callback function for copy-to-clipboard action buttons.
const std::string & library_name(LIBRARY_ID lib)
Retrieve the user-visible name for the given library.
Definition: build_info.cpp:359
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:233
std::vector< deplist_entry > deps_
#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:331
This file contains the settings handling of the widget library.
std::string get_user_data_dir()
void set_visible(const visibility visible)
Definition: widget.cpp:479
void browse_directory_callback(const std::string &path)
Callback function for browse-directory action buttons.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:218
unsigned int get_layer_count() const
Gets the total number of layers.
std::string path
Definition: game_config.cpp:56
const std::string copy_wid_stem_
Platform identification and version information functions.
Various uncategorised dialogs.
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.
const std::string revision
Definition: game_config.cpp:50
The user set the widget invisible, that means:
std::string os_version()
Returns a string with the running OS name and version information.
Definition: version.cpp:118
const std::string & library_runtime_version(LIBRARY_ID lib)
Retrieve the runtime version number of the given library.
Definition: build_info.cpp:350
std::map< std::string, t_string > string_map
Definition: widget.hpp:24
grid & 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:68
Declarations for File-IO.
Base class for all visible items.
#define VGETTEXT(msgid,...)
void select_layer(const int layer)
Selects and displays a particular layer.
std::vector< game_config::optional_feature > opts_
std::string get_user_config_dir()
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
bool open_object_is_supported()
Returns whether open_object() is supported/implemented for the current platform.
Definition: open.cpp:44
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:62
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Definition: clipboard.cpp:35
std::string get_addons_dir()
Simple push button.
Definition: button.hpp:35
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:133
#define e
void tab_switch_callback(window &window)
Callback function called when switching tabs.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
std::string full_build_report()
Produce a bug report-style info dump.
Definition: build_info.cpp:457
virtual void set_active(const bool active) override
See styled_widget::set_active.