The Battle for Wesnoth  1.19.2+dev
game_version_dialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "build_info.hpp"
21 #include "desktop/clipboard.hpp"
22 #include "desktop/open.hpp"
23 #include "desktop/version.hpp"
24 #include "filesystem.hpp"
25 #include "formula/string_utils.hpp"
28 #include "gui/widgets/button.hpp"
30 #include "gui/widgets/listbox.hpp"
33 #include "gui/widgets/window.hpp"
34 #include "gui/dialogs/message.hpp"
36 #include "gettext.hpp"
37 #include "help/help.hpp"
38 
39 #include <functional>
40 
41 namespace
42 {
43 
44 const std::string text_feature_on = "<span color='#0f0'>&#9679;</span>";
45 const std::string text_feature_off = "<span color='#f00'>&#9679;</span>";
46 
47 } // end anonymous namespace
48 
49 namespace gui2::dialogs
50 {
51 
52 REGISTER_DIALOG(game_version)
53 
54 game_version::game_version(unsigned start_page)
55  : modal_dialog(window_id())
56  , path_wid_stem_("path_")
57  , copy_wid_stem_("copy_")
58  , browse_wid_stem_("browse_")
59  , path_map_()
60  , log_path_(lg::get_log_file_path())
61  , deps_()
63  , report_()
64  , start_page_(start_page)
65 {
66  // NOTE: these path_map_ entries are referenced by the GUI2 WML
67  // definition of this dialog using preprocessor macros.
68  path_map_["datadir"] = game_config::path;
69  path_map_["userdata"] = filesystem::get_user_data_dir();
70  path_map_["saves"] = filesystem::get_saves_dir();
71  path_map_["addons"] = filesystem::get_addons_dir();
72  path_map_["cache"] = filesystem::get_cache_dir();
73  // path to logs directory
74  path_map_["logs"] = filesystem::get_logs_dir();
75  path_map_["screenshots"] = filesystem::get_screenshot_dir();
76 
77  for(unsigned k = 0; k < game_config::LIB_COUNT; ++k) {
79 
81  e[0] = game_config::library_name(lib);
82  if(e[0].empty()) {
83  continue;
84  }
87  deps_.push_back(e);
88  }
89 
90  generate_plain_text_report();
91 }
92 
94 {
95  utils::string_map i18n_syms;
96 
97  tab_container& tabs = find_widget<tab_container>(&window, "tabs", false);
98 
99  //
100  // General information.
101  //
102  tabs.select_tab(0);
103 
104  styled_widget& version_label = find_widget<styled_widget>(&window, "version", false);
105  styled_widget& os_label = find_widget<styled_widget>(&window, "os", false);
106  styled_widget& arch_label = find_widget<styled_widget>(&window, "arch", false);
107 
108  version_label.set_label(game_config::revision);
109  os_label.set_label("<i>"+desktop::os_version()+"</i>");
110  arch_label.set_label(game_config::build_arch());
111 
112  button& copy_all = find_widget<button>(&window, "copy_all", false);
114 
115  // Bottom row buttons
116  button& credits_button = find_widget<button>(&window, "credits", false);
117  connect_signal_mouse_left_click(credits_button, std::bind(&game_version::show_credits_dialog, this));
118 
119  button& license_button = find_widget<button>(&window, "license", false);
120  connect_signal_mouse_left_click(license_button, std::bind(&game_version::show_license, this));
121 
122  button& issue_button = find_widget<button>(&window, "issue", false);
123  connect_signal_mouse_left_click(issue_button, std::bind(&game_version::report_issue, this));
124 
125  connect_signal_mouse_left_click(find_widget<button>(&window, "run_migrator", false), std::bind(&game_version::run_migrator, this));
126 
127  //
128  // Game paths tab.
129  //
130  tabs.select_tab(1);
131 
132  for(const auto & path_ent : path_map_)
133  {
134  const std::string& path_id = path_ent.first;
135  const std::string& path_path = filesystem::normalize_path(path_ent.second, true);
136 
137  text_box_base& path_w = find_widget<text_box_base>(&window, path_wid_stem_ + path_id, false);
138  button& copy_w = find_widget<button>(&window, copy_wid_stem_ + path_id, false);
139  button& browse_w = find_widget<button>(&window, browse_wid_stem_ + path_id, false);
140 
141  path_w.set_value(path_path);
142 
144  copy_w,
145  std::bind(&game_version::copy_to_clipboard_callback, this, path_path, copy_wid_stem_ + path_id));
147  browse_w,
148  std::bind(&game_version::browse_directory_callback, this, path_path));
149 
151  // No point in displaying these on platforms that can't do
152  // open_object().
154  }
155 
157  copy_w.set_active(false);
158  copy_w.set_tooltip(_("Clipboard support not found, contact your packager"));
159  }
160  }
161 
162  button& stderr_button = find_widget<button>(&window, "open_stderr", false);
164  stderr_button.set_active(!log_path_.empty() && filesystem::file_exists(log_path_));
165 
166  //
167  // Build info tab.
168  //
169  tabs.select_tab(2);
170 
171  widget_data list_data;
172 
173  listbox& deps_listbox
174  = find_widget<listbox>(&window, "deps_listbox", false);
175 
176  for(const auto & dep : deps_)
177  {
178  list_data["dep_name"]["label"] = dep[0];
179 
180  list_data["dep_build_version"]["label"] = dep[1];
181 
182  // The build version is always known, but runtime version isn't, esp.
183  // for header-only libraries like Boost for which the concept does not
184  // apply.
185  if(!dep[2].empty()) {
186  list_data["dep_rt_version"]["label"] = dep[2];
187  } else {
188  list_data["dep_rt_version"]["label"] = font::unicode_em_dash;
189  }
190 
191  deps_listbox.add_row(list_data);
192  }
193 
194  deps_listbox.select_row(0);
195  list_data.clear();
196 
197  //
198  // Features tab.
199  //
200  tabs.select_tab(3);
201 
202  listbox& opts_listbox
203  = find_widget<listbox>(&window, "opts_listbox", false);
204 
205  for(const auto & opt : opts_)
206  {
207  list_data["opt_name"]["label"] = opt.name;
208 
209  if(opt.enabled) {
210  list_data["opt_status"]["label"] = text_feature_on;
211  } else {
212  list_data["opt_status"]["label"] = text_feature_off;
213  }
214  list_data["opt_status"]["use_markup"] = "true";
215 
216  opts_listbox.add_row(list_data);
217  }
218 
219  opts_listbox.select_row(0);
220  list_data.clear();
221 
222  //
223  // Community tab
224  //
225  tabs.select_tab(4);
226 
227  connect_signal_mouse_left_click(find_widget<button>(&window, "forums", false), std::bind(&desktop::open_object, "https://forums.wesnoth.org/"));
228  connect_signal_mouse_left_click(find_widget<button>(&window, "discord", false), std::bind(&desktop::open_object, "https://discord.gg/battleforwesnoth"));
229  connect_signal_mouse_left_click(find_widget<button>(&window, "irc", false), std::bind(&desktop::open_object, "https://web.libera.chat/#wesnoth"));
230  connect_signal_mouse_left_click(find_widget<button>(&window, "steam", false), std::bind(&desktop::open_object, "https://steamcommunity.com/app/599390/discussions/"));
231  connect_signal_mouse_left_click(find_widget<button>(&window, "reddit", false), std::bind(&desktop::open_object, "https://www.reddit.com/r/wesnoth/"));
232  connect_signal_mouse_left_click(find_widget<button>(&window, "donate", false), std::bind(&desktop::open_object, "https://www.spi-inc.org/projects/wesnoth/"));
233 
234  //
235  // Set-up page stack and auxiliary controls last.
236  //
237 
238  tabs.select_tab(start_page_);
239 }
240 
242 {
244 }
245 
247 {
249 }
250 
251 void game_version::copy_to_clipboard_callback(const std::string& path, const std::string btn_id)
252 {
254 
255  button& copy_w = find_widget<button>(get_window(), btn_id, false);
256  copy_w.set_success(true);
257 }
258 
260 {
262 
263  button& copy_all = find_widget<button>(get_window(), "copy_all", false);
264  copy_all.set_success(true);
265 }
266 
268 {
270 }
271 
273  gui2::dialogs::end_credits::display();
274 }
275 
277  help::show_help("license");
278 }
279 
282  show_message("", _("Opening links is not supported, contact your packager"), dialogs::message::auto_close);
283  return;
284  } else {
285  desktop::open_object("https://bugs.wesnoth.org");
286  }
287 }
288 
289 } // namespace dialogs
Simple push button.
Definition: button.hpp:36
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:64
void set_success(bool success)
Definition: button.cpp:89
const std::string path_wid_stem_
The display function.
void report_issue()
Open browser to report issue.
std::array< std::string, 4 > deplist_entry
void report_copy_callback()
Callback function for the dialog-wide copy-to-clipboard button.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void copy_to_clipboard_callback(const std::string &path, const std::string btn_id)
Callback function for copy-to-clipboard action buttons.
std::map< std::string, std::string > path_map_
const std::string log_path_
path to current log file
void run_migrator()
Callback function to re-run the version migration dialog.
void show_credits_dialog()
Show credits dialogs.
std::vector< deplist_entry > deps_
void browse_directory_callback(const std::string &path)
Callback function for browse-directory action buttons.
std::vector< game_config::optional_feature > opts_
@ auto_close
Enables auto close.
Definition: message.hpp:71
Abstract base class for all modal dialogs.
window * get_window()
Returns a pointer to the dialog's window.
The listbox class.
Definition: listbox.hpp:43
grid & add_row(const widget_item &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:59
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:243
void set_tooltip(const t_string &tooltip)
virtual void set_label(const t_string &text)
A container widget that shows one of its pages of widgets depending on which tab the user clicked.
void select_tab(unsigned index)
Abstract base class for text items.
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
void set_visible(const visibility visible)
Definition: widget.cpp:469
@ invisible
The user set the widget invisible, that means:
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
Platform identification and version information functions.
Declarations for File-IO.
static std::string _(const char *str)
Definition: gettext.hpp:93
This file contains the window object, this object is a top level container which has the event manage...
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
Definition: clipboard.cpp:32
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:53
bool open_object([[maybe_unused]] const std::string &path_or_url)
Definition: open.cpp:46
constexpr bool open_object_is_supported()
Returns whether open_object() is supported/implemented for the current platform.
Definition: open.hpp:54
std::string os_version()
Returns a string with the running OS name and version information.
Definition: version.cpp:216
std::string get_cache_dir()
Definition: filesystem.cpp:803
std::string get_user_data_dir()
Definition: filesystem.cpp:793
static bool file_exists(const bfs::path &fpath)
Definition: filesystem.cpp:324
std::string get_saves_dir()
std::string get_screenshot_dir()
std::string get_logs_dir()
Definition: filesystem.cpp:798
std::string get_addons_dir()
std::string normalize_path(const std::string &fpath, bool normalize_separators, bool resolve_dot_entries)
Returns the absolute path of a file.
const std::string unicode_em_dash
Definition: constants.cpp:44
Game configuration data as global variables.
Definition: build_info.cpp:61
const std::string & library_name(LIBRARY_ID lib)
Retrieve the user-visible name for the given library.
Definition: build_info.cpp:387
std::string path
Definition: filesystem.cpp:89
std::string full_build_report()
Produce a bug report-style info dump.
Definition: build_info.cpp:665
std::vector< optional_feature > optional_features_table(bool localize)
Retrieve the features table.
Definition: build_info.cpp:350
const std::string & library_runtime_version(LIBRARY_ID lib)
Retrieve the runtime version number of the given library.
Definition: build_info.cpp:378
const std::string & library_build_version(LIBRARY_ID lib)
Retrieve the build-time version number of the given library.
Definition: build_info.cpp:369
std::string build_arch()
Obtain the processor architecture for this build.
Definition: build_info.cpp:316
const std::string revision
REGISTER_DIALOG(editor_edit_unit)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:177
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:34
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
Definition: message.cpp:150
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
Definition: help.cpp:140
Definition: pump.hpp:41
std::string get_log_file_path()
Definition: log.cpp:282
std::map< std::string, t_string > string_map
Desktop environment interaction functions.
#define e