The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
addon_server_info.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 - 2025
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"
25
26namespace gui2::dialogs
27{
28
29REGISTER_DIALOG(addon_server_info)
30
31addon_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{
37 connect_signal_mouse_left_click(
38 find_widget<button>("downloads_by_version"),
40
41 connect_signal_mouse_left_click(
42 find_widget<button>("addon_count_by_forum_auth"),
44
45 connect_signal_mouse_left_click(
46 find_widget<button>("admin_delete_addon"),
48
49 connect_signal_mouse_left_click(
50 find_widget<button>("admin_hide_addon"),
51 std::bind(&addon_server_info::admin_hide_addon, this));
52
53 connect_signal_mouse_left_click(
54 find_widget<button>("admin_unhide_addon"),
56
57 connect_signal_mouse_left_click(
58 find_widget<button>("admin_list_hidden"),
59 std::bind(&addon_server_info::admin_list_hidden, this));
60}
61
66
71
77
83
85{
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(), true);
96 } else {
97 gui2::show_transient_message(_("Response"), msg);
98 needs_refresh_ = true;
99 }
100}
101
103{
104 if(!addon_.empty()) {
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()) {
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{
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:157
child_itors child_range(std::string_view key)
Definition config.cpp:268
std::string debug() const
Definition config.cpp:1214
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.
const config * cfg
static std::string _(const char *str)
Definition gettext.hpp:100
#define PLAIN_LOG
Definition log.hpp:296
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
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
STL namespace.
std::string join(const Range &v, const std::string &s=",")
Generates a new string joining container items in a list.