The Battle for Wesnoth  1.19.8+dev
addon_server_info.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2024 - 2024
3  Part of the Battle for Wesnoth Project https://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 "gettext.hpp"
21 #include "gui/dialogs/message.hpp"
22 #include "gui/dialogs/prompt.hpp"
24 #include "gui/widgets/button.hpp"
25 
26 namespace gui2::dialogs
27 {
28 
30 
31 addon_server_info::addon_server_info(addons_client& client, const std::string& addon, bool& needs_refresh)
32  : modal_dialog(window_id())
33  , client_(client)
34  , addon_(addon)
35  , needs_refresh_(needs_refresh)
36 {
38  find_widget<button>("downloads_by_version"),
39  std::bind(&addon_server_info::downloads_by_version, this));
40 
42  find_widget<button>("addon_count_by_forum_auth"),
44 
46  find_widget<button>("admin_delete_addon"),
47  std::bind(&addon_server_info::admin_delete_addon, this));
48 
50  find_widget<button>("admin_hide_addon"),
51  std::bind(&addon_server_info::admin_hide_addon, this));
52 
54  find_widget<button>("admin_unhide_addon"),
55  std::bind(&addon_server_info::admin_unhide_addon, this));
56 
58  find_widget<button>("admin_list_hidden"),
59  std::bind(&addon_server_info::admin_list_hidden, this));
60 }
61 
63 {
64 
65 }
66 
68 {
69 
70 }
71 
73 {
75  PLAIN_LOG << downloads.debug();
76 }
77 
79 {
80  config forum_auths = client_.get_forum_auth_usage();
81  PLAIN_LOG << forum_auths.debug();
82 }
83 
85 {
86  config admins = client_.get_addon_admins();
87 
88  std::set<std::string> admin_set;
89  for(const auto& admin : admins.child_range("admin")) {
90  admin_set.emplace(admin["username"]);
91  }
92 
93  std::string msg;
94  if(!client_.delete_remote_addon(addon_, msg, admin_set)) {
95  gui2::show_error_message(_("The server responded with an error:") + "\n" + client_.get_last_server_error());
96  } else {
97  gui2::show_transient_message(_("Response"), msg);
98  needs_refresh_ = true;
99  }
100 }
101 
103 {
104  if(!addon_.empty()) {
105  config admins = client_.get_addon_admins();
106 
107  std::set<std::string> admin_set;
108  for(const auto& admin : admins.child_range("admin")) {
109  admin_set.emplace(admin["username"]);
110  }
111 
112  config cfg;
113  cfg["primary_authors"] = utils::join(admin_set);
114  if(!gui2::dialogs::addon_auth::execute(cfg)) {
115  gui2::show_error_message(_("Password not provided"));
116  return;
117  }
118 
119  if(!client_.hide_addon(addon_, cfg["uploader"].str(), cfg["passphrase"].str())) {
120  gui2::show_error_message(_("The server responded with an error:") + "\n" + client_.get_last_server_error());
121  } else {
122  needs_refresh_ = true;
123  }
124  }
125 }
126 
128 {
129  std::string addon;
130  gui2::dialogs::prompt::execute(addon);
131 
132  if(!addon.empty()) {
133  config admins = client_.get_addon_admins();
134 
135  std::set<std::string> admin_set;
136  for(const auto& admin : admins.child_range("admin")) {
137  admin_set.emplace(admin["username"]);
138  }
139 
140  config cfg;
141  cfg["primary_authors"] = utils::join(admin_set);
142  if(!gui2::dialogs::addon_auth::execute(cfg)) {
143  gui2::show_error_message(_("Password not provided"));
144  return;
145  }
146 
147  if(!client_.unhide_addon(addon, cfg["uploader"].str(), cfg["passphrase"].str())) {
148  gui2::show_error_message(_("The server responded with an error:") + "\n" + client_.get_last_server_error());
149  } else {
150  needs_refresh_ = true;
151  }
152  }
153 }
154 
156 {
157  config admins = client_.get_addon_admins();
158 
159  std::set<std::string> admin_set;
160  for(const auto& admin : admins.child_range("admin")) {
161  admin_set.emplace(admin["username"]);
162  }
163 
164  config cfg;
165  cfg["primary_authors"] = utils::join(admin_set);
166  if(!gui2::dialogs::addon_auth::execute(cfg)) {
167  gui2::show_error_message(_("Password not provided"));
168  return;
169  }
170 
171  PLAIN_LOG << client_.get_hidden_addons(cfg["uploader"].str(), cfg["passphrase"].str());
172 }
173 
174 } // namespace dialogs
Add-ons (campaignd) client class.
Definition: client.hpp:41
bool unhide_addon(const std::string &addon, const std::string &username, const std::string &passphrase)
Definition: client.cpp:233
config get_forum_auth_usage()
Definition: client.cpp:157
config get_addon_downloads_by_version(const std::string &addon)
Definition: client.cpp:138
bool hide_addon(const std::string &addon, const std::string &username, const std::string &passphrase)
Definition: client.cpp:213
config get_hidden_addons(const std::string &username, const std::string &passphrase)
Definition: client.cpp:193
bool delete_remote_addon(const std::string &id, std::string &response_message, const std::set< std::string > &admin_set={})
Requests the specified add-on to be removed from the server.
Definition: client.cpp:417
config get_addon_admins()
Definition: client.cpp:175
const std::string & get_last_server_error() const
Returns the last error message sent by the server, or an empty string.
Definition: client.hpp:77
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
child_itors child_range(config_key_type key)
Definition: config.cpp:268
std::string debug() const
Definition: config.cpp:1236
virtual void pre_show() override
Actions to be taken before showing the window.
virtual void post_show() override
Actions to be taken after the window has been shown.
Abstract base class for all modal dialogs.
static std::string _(const char *str)
Definition: gettext.hpp:93
#define PLAIN_LOG
Definition: log.hpp:297
bool addon_server_info
Definition: game_config.cpp:79
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
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
Definition: message.cpp:201
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109