The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
manager.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
3 by Mark de Wever <koraq@xs4all.nl>
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 "addon/info.hpp"
21#include "addon/manager.hpp"
22#include "addon/state.hpp"
23
24#include "help/help.hpp"
25#include "gettext.hpp"
32#include "gui/widgets/label.hpp"
43#include "picture.hpp"
44#include "language.hpp"
45#include "utils/general.hpp"
46
47#include "config.hpp"
48
49#include <functional>
50#include <set>
51#include <sstream>
52
53namespace gui2::dialogs
54{
55
56namespace {
57 struct filter_transform
58 {
59 explicit filter_transform(const std::vector<std::string>& filtertext) : filtertext_(filtertext) {}
60 bool operator()(const config& cfg) const
61 {
62 for(const auto& filter : filtertext_)
63 {
64 bool found = false;
65 for(const auto& [_, value] : cfg.attribute_range())
66 {
67 if(translation::ci_search(value.str(), filter))
68 {
69 found = true;
70 break;
71 }
72 }
73 for(const config& child : cfg.child_range("translation")) {
74 for(const auto& [_, value] : child.attribute_range()) {
75 if(translation::ci_search(value.str(), filter)) {
76 found = true;
77 break;
78 }
79 }
80 }
81 if(!found) {
82 return false;
83 }
84 }
85 return true;
86 }
87 const std::vector<std::string> filtertext_;
88 };
89
90 std::string make_display_dependencies(
91 const std::string& addon_id,
93 const addons_tracking_list& addon_states)
94 {
95 const addon_info& addon = addons_list.at(addon_id);
96 std::string str;
97
98 const std::set<std::string>& deps = addon.resolve_dependencies(addons_list);
99
100 for(const auto& dep_id : deps) {
101 addon_info dep;
102 addon_tracking_info depstate;
103
104 addons_list::const_iterator ali = addons_list.find(dep_id);
105 addons_tracking_list::const_iterator tli = addon_states.find(dep_id);
106
107 if(ali == addons_list.end()) {
108 dep.id = dep_id; // Build dummy addon_info.
109 } else {
110 dep = ali->second;
111 }
112
113 if(tli == addon_states.end()) {
114 depstate = get_addon_tracking_info(dep);
115 } else {
116 depstate = tli->second;
117 }
118
119 if(!str.empty()) {
120 str += ", ";
121 }
122
124 }
125
126 return str;
127 }
128
129 std::string langcode_to_string(const std::string& lcode)
130 {
131 for(const auto & ld : get_languages(true))
132 {
133 if(ld.localename == lcode || ld.localename.substr(0, 2) == lcode) {
134 return ld.language;
135 }
136 }
137
138 return "";
139 }
140}
141
142REGISTER_DIALOG(addon_manager)
143
144const std::vector<std::pair<ADDON_STATUS_FILTER, std::string>> addon_manager::status_filter_types_{
145 {FILTER_ALL, N_("addons_view^All Add-ons")},
146 {FILTER_INSTALLED, N_("addons_view^Installed")},
147 {FILTER_UPGRADABLE, N_("addons_view^Upgradable")},
148 {FILTER_PUBLISHABLE, N_("addons_view^Publishable")},
149 {FILTER_NOT_INSTALLED, N_("addons_view^Not Installed")},
150};
151
152const std::vector<std::pair<ADDON_TYPE, std::string>> addon_manager::type_filter_types_{
153 {ADDON_SP_CAMPAIGN, N_("addons_of_type^Campaigns")},
154 {ADDON_SP_SCENARIO, N_("addons_of_type^Scenarios")},
155 {ADDON_SP_MP_CAMPAIGN, N_("addons_of_type^SP/MP campaigns")},
156 {ADDON_MP_CAMPAIGN, N_("addons_of_type^MP campaigns")},
157 {ADDON_MP_SCENARIO, N_("addons_of_type^MP scenarios")},
158 {ADDON_MP_MAPS, N_("addons_of_type^MP map-packs")},
159 {ADDON_MP_ERA, N_("addons_of_type^MP eras")},
160 {ADDON_MP_FACTION, N_("addons_of_type^MP factions")},
161 {ADDON_MOD, N_("addons_of_type^Modifications")},
162 {ADDON_CORE, N_("addons_of_type^Cores")},
163 {ADDON_THEME, N_("addons_of_type^Themes")},
164 {ADDON_MEDIA, N_("addons_of_type^Resources")},
165 // FIXME: (also in WML) should this and Unknown be a single option in the UI?
166 {ADDON_OTHER, N_("addons_of_type^Other")},
167 {ADDON_UNKNOWN, N_("addons_of_type^Unknown")},
168};
169
170const std::vector<addon_manager::addon_order> addon_manager::all_orders_{
171 {N_("addons_order^Name ($order)"), "name", 0,
172 [](const addon_info& a, const addon_info& b) { return a.title < b.title; },
173 [](const addon_info& a, const addon_info& b) { return a.title > b.title; }},
174 {N_("addons_order^Author ($order)"), "author", 1,
175 [](const addon_info& a, const addon_info& b) { return a.author < b.author; },
176 [](const addon_info& a, const addon_info& b) { return a.author > b.author; }},
177 {N_("addons_order^Size ($order)"), "size", 2,
178 [](const addon_info& a, const addon_info& b) { return a.size < b.size; },
179 [](const addon_info& a, const addon_info& b) { return a.size > b.size; }},
180 {N_("addons_order^Downloads ($order)"), "downloads", 3,
181 [](const addon_info& a, const addon_info& b) { return a.downloads < b.downloads; },
182 [](const addon_info& a, const addon_info& b) { return a.downloads > b.downloads; }},
183 {N_("addons_order^Type ($order)"), "type", 4,
184 [](const addon_info& a, const addon_info& b) { return a.display_type() < b.display_type(); },
185 [](const addon_info& a, const addon_info& b) { return a.display_type() > b.display_type(); }},
186 {N_("addons_order^Last updated ($datelike_order)"), "last_updated", -1,
187 [](const addon_info& a, const addon_info& b) { return a.updated < b.updated; },
188 [](const addon_info& a, const addon_info& b) { return a.updated > b.updated; }},
189 {N_("addons_order^First uploaded ($datelike_order)"), "first_uploaded", -1,
190 [](const addon_info& a, const addon_info& b) { return a.created < b.created; },
191 [](const addon_info& a, const addon_info& b) { return a.created > b.created; }}
192};
193
194namespace
195{
196struct addon_tag
197{
198 /** Text to match against addon_info.tags() */
199 std::string id;
200 /** What to show in the filter's drop-down list */
201 std::string label;
202 /** Shown when hovering over an entry in the filter's drop-down list */
203 std::string tooltip;
204};
205
206const std::vector<addon_tag> tag_filter_types_{
207 {"cooperative", N_("addon_tag^Cooperative"),
208 // TRANSLATORS: tooltip in the drop-down menu for filtering add-ons
209 N_("addon_tag^All human players are on the same team, versus the AI")},
210 {"cosmetic", N_("addon_tag^Cosmetic"),
211 // TRANSLATORS: tooltip in the drop-down menu for filtering add-ons
212 N_("addon_tag^These make the game look different, without changing gameplay")},
213 {"difficulty", N_("addon_tag^Difficulty"),
214 // TRANSLATORS: tooltip in the drop-down menu for filtering add-ons
215 N_("addon_tag^Can make campaigns easier or harder")},
216 {"rng", N_("addon_tag^RNG"),
217 // TRANSLATORS: tooltip in the drop-down menu for filtering add-ons
218 N_("addon_tag^Modify the randomness in the combat mechanics, or remove it entirely")},
219 {"survival", N_("addon_tag^Survival"),
220 // TRANSLATORS: tooltip in the drop-down menu for filtering add-ons
221 N_("addon_tag^Fight against waves of enemies")},
222 {"terraforming", N_("addon_tag^Terraforming"),
223 // TRANSLATORS: tooltip in the drop-down menu for filtering add-ons
224 N_("addon_tag^Players can change the terrain")},
225};
226};
227
228addon_manager::addon_manager(addons_client& client, const utils::optional<ADDON_TYPE> initial_type_filter)
229 : modal_dialog(window_id())
230 , orders_()
231 , cfg_()
232 , client_(client)
233 , initial_type_filter_(initial_type_filter)
234 , addons_()
235 , tracking_info_()
236 , need_wml_cache_refresh_(false)
237{
238}
239
240static std::string describe_status_verbose(const addon_tracking_info& state)
241{
242 std::string s;
243
244 utils::string_map i18n_symbols {{"local_version", state.installed_version.str()}};
245
246 switch(state.state) {
247 case ADDON_NONE:
248 s = !state.can_publish
249 ? _("addon_state^Not installed")
250 : _("addon_state^Published, not installed");
251 break;
252 case ADDON_INSTALLED:
253 s = !state.can_publish
254 ? _("addon_state^Installed")
255 : _("addon_state^Published");
256 break;
258 s = !state.can_publish
259 ? _("addon_state^Installed, not tracking local version")
260 // Published add-ons often don't have local status information,
261 // hence untracked. This should be considered normal.
262 : _("addon_state^Published, not tracking local version");
263 break;
265 const std::string vstr = !state.can_publish
266 ? _("addon_state^Installed ($local_version|), upgradable")
267 : _("addon_state^Published ($local_version| installed), upgradable");
268
269 s = utils::interpolate_variables_into_string(vstr, &i18n_symbols);
270 } break;
272 const std::string vstr = !state.can_publish
273 ? _("addon_state^Installed ($local_version|), outdated on server")
274 : _("addon_state^Published ($local_version| installed), outdated on server");
275
276 s = utils::interpolate_variables_into_string(vstr, &i18n_symbols);
277 } break;
279 s = !state.can_publish
280 ? _("addon_state^Installed, not ready to publish")
281 : _("addon_state^Ready to publish");
282 break;
284 s = !state.can_publish
285 ? _("addon_state^Installed, broken")
286 : _("addon_state^Published, broken");
287 break;
288 default:
289 s = _("addon_state^Unknown");
290 }
291
293}
294
296{
298
299 stacked_widget& addr_info = find_widget<stacked_widget>("server_conn_info");
300 grid* addr_visible;
301
302 if(client_.using_tls()) {
303 addr_info.select_layer(1);
304 addr_visible = addr_info.get_layer_grid(1);
305 } else {
306 addr_info.select_layer(0);
307 addr_visible = addr_info.get_layer_grid(0);
308 }
309
310 if(addr_visible) {
311 auto addr_box = dynamic_cast<styled_widget*>(addr_visible->find("server_addr", false));
312 if(addr_box) {
313 if(!client_.server_id().empty()) {
314 auto full_id = formatter()
315 << client_.addr() << ' '
316 << font::unicode_em_dash << ' '
317 << client_.server_id();
318 if(game_config::debug && !client_.server_version().empty()) {
319 full_id << " (" << client_.server_version() << ')';
320 }
321 addr_box->set_label(full_id.str());
322 } else {
323 addr_box->set_label(client_.addr());
324 }
325 }
326 }
327
328 addon_list& list = find_widget<addon_list>("addons");
329
330 text_box& filter = find_widget<text_box>("filter");
331 filter.on_modified([this](const auto&) { apply_filters(); });
332
334 this, std::placeholders::_1));
336 this, std::placeholders::_1));
338 this, std::placeholders::_1));
339
341 this, std::placeholders::_1));
343 this, std::placeholders::_1));
344
345 connect_signal_notify_modified(list, [this](auto&&...) { on_addon_select(); });
346
349
350 menu_button& status_filter = find_widget<menu_button>("install_status_filter");
351
352 std::vector<config> status_filter_entries;
353 for(const auto& f : status_filter_types_) {
354 if(f.first == FILTER_ALL) {
355 status_filter_entries.emplace_back("label", t_string(f.second, GETTEXT_DOMAIN)+" ("+std::to_string(addons_.size())+")");
356 } else if(f.first == FILTER_INSTALLED) {
357 status_filter_entries.emplace_back("label", t_string(f.second, GETTEXT_DOMAIN)+" ("+std::to_string(installed_addons().size())+")");
358 } else {
359 status_filter_entries.emplace_back("label", t_string(f.second, GETTEXT_DOMAIN));
360 }
361 }
362
363 status_filter.set_values(status_filter_entries);
364
365 connect_signal_notify_modified(status_filter,
366 std::bind(&addon_manager::apply_filters, this));
367
368 // The tag filter
369 auto& tag_filter = find_widget<multimenu_button>("tag_filter");
370
371 std::vector<config> tag_filter_entries;
372 for(const auto& f : tag_filter_types_) {
373 tag_filter_entries.emplace_back("label", t_string(f.label, GETTEXT_DOMAIN), "checkbox", false);
374 if(!f.tooltip.empty()) {
375 tag_filter_entries.back()["tooltip"] = t_string(f.tooltip, GETTEXT_DOMAIN);
376 }
377 }
378
379 tag_filter.set_values(tag_filter_entries);
380
381 connect_signal_notify_modified(tag_filter, std::bind(&addon_manager::apply_filters, this));
382
383 // The type filter
384 multimenu_button& type_filter = find_widget<multimenu_button>("type_filter");
385
386 std::map<ADDON_TYPE, int> type_counts = {
392 {ADDON_MP_MAPS, 0},
393 {ADDON_MP_ERA, 0},
394 {ADDON_MP_FACTION, 0},
395 {ADDON_MOD, 0},
396 {ADDON_CORE, 0},
397 {ADDON_THEME, 0},
398 {ADDON_MEDIA, 0},
399 {ADDON_OTHER, 0},
400 {ADDON_UNKNOWN, 0}
401 };
402 for(const auto& addon : addons_) {
403 type_counts[addon.second.type]++;
404 }
405
406 std::vector<config> type_filter_entries;
407 for(const auto& f : type_filter_types_) {
408 type_filter_entries.emplace_back("label", t_string(f.second, GETTEXT_DOMAIN)+" ("+std::to_string(type_counts[f.first])+")", "checkbox", false);
409 }
410
411 type_filter.set_values(type_filter_entries);
412 if(initial_type_filter_.has_value()) {
414 [](const std::pair<ADDON_TYPE, std::string>& entry) { return entry.first; });
415 if(it != type_filter_types_.end()) {
416 const int index = std::distance(type_filter_types_.begin(), it);
417 type_filter.select_option(index, true);
418 }
419 }
420
421 connect_signal_notify_modified(type_filter,
422 std::bind(&addon_manager::apply_filters, this));
423
424 // Language filter
425 // Prepare shown languages, source all available languages from the addons themselves
426 std::set<std::string> languages_available;
427 for(const auto& a : addons_) {
428 for (const auto& b : a.second.locales) {
429 languages_available.insert(b);
430 }
431 }
432 std::set<std::string> language_strings_available;
433 for (const auto& i: languages_available) {
434 // Only show languages, which have a translation as per langcode_to_string() method
435 // Do not show tranlations with their langcode e.g. "sv_SV"
436 // Also put them into a set, so same lang strings are not producing doublettes
437 if (std::string lang_code_string = langcode_to_string(i); !lang_code_string.empty()) {
438 language_strings_available.insert(lang_code_string);
439 }
440 }
441 for (auto& i: language_strings_available) {
442 language_filter_types_.emplace_back(language_filter_types_.size(), i);
443 }
444 // The language filter
445 multimenu_button& language_filter = find_widget<multimenu_button>("language_filter");
446 std::vector<config> language_filter_entries;
447 for(const auto& f : language_filter_types_) {
448 language_filter_entries.emplace_back("label", f.second, "checkbox", false);
449 }
450
451 language_filter.set_values(language_filter_entries);
452
453 connect_signal_notify_modified(language_filter,
454 std::bind(&addon_manager::apply_filters, this));
455
456 // Sorting order
457 menu_button& order_dropdown = find_widget<menu_button>("order_dropdown");
458
459 std::vector<config> order_dropdown_entries;
460 for(const auto& f : all_orders_) {
461 utils::string_map symbols;
462
463 symbols["order"] = _("ascending");
464 // TRANSLATORS: Sorting order of dates, oldest first
465 symbols["datelike_order"] = _("oldest to newest");
466 config entry{"label", VGETTEXT(f.label.c_str(), symbols)};
467 order_dropdown_entries.push_back(entry);
468 symbols["order"] = _("descending");
469 // TRANSLATORS: Sorting order of dates, newest first
470 symbols["datelike_order"] = _("newest to oldest");
471 entry["label"] = VGETTEXT(f.label.c_str(), symbols);
472 order_dropdown_entries.push_back(entry);
473 }
474
475 order_dropdown.set_values(order_dropdown_entries);
476 {
477 const std::string saved_order_name = prefs::get().addon_manager_saved_order_name();
478 const sort_order::type saved_order_direction = prefs::get().addon_manager_saved_order_direction();
479
480 if(!saved_order_name.empty()) {
481 auto order_it = utils::ranges::find(all_orders_, saved_order_name, &addon_order::as_preference);
482 if(order_it != all_orders_.end()) {
483 int index = 2 * (std::distance(all_orders_.begin(), order_it));
485 if(saved_order_direction == sort_order::type::ascending) {
486 func = order_it->sort_func_asc;
487 } else {
488 func = order_it->sort_func_desc;
489 ++index;
490 }
491 find_widget<menu_button>("order_dropdown").set_value(index);
492 auto& addons = find_widget<addon_list>("addons");
493 addons.set_addon_order(func);
494 addons.select_first_addon();
495 }
496 }
497 }
498
499 connect_signal_notify_modified(order_dropdown,
500 std::bind(&addon_manager::order_addons, this));
501
502 label& url_label = find_widget<label>("url");
503
504 url_label.set_use_markup(true);
505 url_label.set_link_aware(true);
506
507 connect_signal_mouse_left_click(
508 find_widget<button>("install"),
509 std::bind(&addon_manager::install_selected_addon, this));
510
511 connect_signal_mouse_left_click(
512 find_widget<button>("uninstall"),
514
515 connect_signal_mouse_left_click(
516 find_widget<button>("update"),
517 std::bind(&addon_manager::update_selected_addon, this));
518
519 connect_signal_mouse_left_click(
520 find_widget<button>("publish"),
521 std::bind(&addon_manager::publish_selected_addon, this));
522
523 connect_signal_mouse_left_click(
524 find_widget<button>("delete"),
525 std::bind(&addon_manager::delete_selected_addon, this));
526
528 connect_signal_mouse_left_click(
529 find_widget<button>("info"),
530 std::bind(&addon_manager::info, this));
531 } else {
532 find_widget<button>("info").set_visible(false);
533 }
534
535 connect_signal_mouse_left_click(
536 find_widget<button>("update_all"),
537 std::bind(&addon_manager::update_all_addons, this));
538
539 connect_signal_mouse_left_click(
540 find_widget<button>("show_help"),
541 std::bind(&addon_manager::show_help, this));
542
543 if(stacked_widget* stk = find_widget<stacked_widget>("main_stack", false, false)) {
544 button& btn = find_widget<button>("details_toggle");
545 connect_signal_mouse_left_click(btn,
546 std::bind(&addon_manager::toggle_details, this, std::ref(btn), std::ref(*stk)));
547
548 stk->select_layer(0);
549
550 connect_signal_notify_modified(
551 stk->get_layer_grid(1)->find_widget<menu_button>("version_filter"),
553 } else {
554 connect_signal_notify_modified(
555 find_widget<menu_button>("version_filter"),
557 }
558
559 // Apply the selection from type_filter.select_option() above after initializing
560 // the remaining filters, sorting and list view.
561 if(initial_type_filter_.has_value()) {
563 }
565
566 set_enter_disabled(true);
567
568#ifdef __IPHONEOS__
569 // On iOS, opening the add-ons manager should not immediately summon the
570 // software keyboard just because the optional filter field exists.
571 keyboard_capture(&list);
572#else
573 keyboard_capture(&filter);
574#endif
576
577 list.set_callback_order_change(std::bind(&addon_manager::on_order_changed, this, std::placeholders::_1, std::placeholders::_2));
578
579 // Use handle the special addon_list retval to allow installing addons on double click
581}
582
584{
585 if(stk.current_layer() == 0) {
586 btn.set_label(_("addons^Back to List"));
587 stk.select_layer(1);
588 } else {
589 btn.set_label(_("Add-on Details"));
590 stk.select_layer(0);
591 }
592}
593
595{
596 bool success = client_.request_addons_list(cfg_, prefs::get().addon_icons());
597 if(!success) {
598 gui2::show_error_message(_("An error occurred while downloading the add-ons list from the server."));
599 close();
600 }
601}
602
604{
607 }
608
610
611 std::vector<std::string> publishable_addons = available_addons();
612
613 for(std::string id : publishable_addons) {
614 if(addons_.find(id) == addons_.end()) {
615 // Get a config from the addon's pbl file
616 // Note that the name= key is necessary or stuff breaks, since the filter code uses this key
617 // to match add-ons in the config list. It also fills in addon_info's id field. It's also
618 // neccessay to set local_only here so that flag can be properly set after addons_ is cleared
619 // and recreated by read_addons_list.
620 try {
621 config pbl_cfg = get_addon_pbl_info(id, false);
622 pbl_cfg["name"] = id;
623 pbl_cfg["local_only"] = true;
624
625 // Add the add-on to the list.
626 addon_info addon(pbl_cfg);
627 addons_[id] = addon;
628
629 // Add the addon to the config entry
630 cfg_.add_child("campaign", std::move(pbl_cfg));
631 } catch(invalid_pbl_exception&) {}
632 }
633 }
634
635 if(addons_.empty()) {
636 show_transient_message(_("No Add-ons Available"), _("There are no add-ons available for download from this server."));
637 }
638
639 addon_list& list = find_widget<addon_list>("addons");
640 list.set_addons(addons_);
641
642 bool has_upgradable_addons = false;
643 for(const auto& a : addons_) {
644 tracking_info_[a.first] = get_addon_tracking_info(a.second);
645
646 if(tracking_info_[a.first].state == ADDON_INSTALLED_UPGRADABLE) {
647 has_upgradable_addons = true;
648 }
649 }
650
651 find_widget<button>("update_all").set_active(has_upgradable_addons);
652
654}
655
657{
659
660 // Reselect the add-on.
661 find_widget<addon_list>("addons").select_addon(id);
663}
664
665boost::dynamic_bitset<> addon_manager::get_name_filter_visibility() const
666{
667 const text_box& name_filter = find_widget<const text_box>("filter");
668 const std::string& text = name_filter.get_value();
669
670 filter_transform filter(utils::split(text, ' '));
671 boost::dynamic_bitset<> res;
672
673 const config::const_child_itors& addon_cfgs = cfg_.child_range("campaign");
674
675 for(const auto& a : addons_)
676 {
677 const config& addon_cfg = *utils::ranges::find(addon_cfgs, a.first,
678 [](const config& cfg) { return cfg["name"]; });
679
680 res.push_back(filter(addon_cfg));
681 }
682
683 return res;
684}
685
686boost::dynamic_bitset<> addon_manager::get_status_filter_visibility() const
687{
688 const menu_button& status_filter = find_widget<const menu_button>("install_status_filter");
689 const ADDON_STATUS_FILTER selection = status_filter_types_[status_filter.get_value()].first;
690
691 boost::dynamic_bitset<> res;
692 for(const auto& a : addons_) {
693 const addon_tracking_info& info = tracking_info_.at(a.second.id);
694
695 res.push_back(
696 (selection == FILTER_ALL) ||
697 (selection == FILTER_INSTALLED && is_installed_addon_status(info.state)) ||
698 (selection == FILTER_UPGRADABLE && info.state == ADDON_INSTALLED_UPGRADABLE) ||
699 (selection == FILTER_PUBLISHABLE && info.can_publish == true) ||
700 (selection == FILTER_NOT_INSTALLED && info.state == ADDON_NONE)
701 );
702 }
703
704 return res;
705}
706
707boost::dynamic_bitset<> addon_manager::get_tag_filter_visibility() const
708{
709 const auto& tag_filter = find_widget<const multimenu_button>("tag_filter");
710 const auto toggle_states = tag_filter.get_toggle_states();
711 if(toggle_states.none()) {
712 // Nothing selected. It means that all add-ons are shown.
713 boost::dynamic_bitset<> res_flipped(addons_.size());
714 return ~res_flipped;
715 }
716
717 std::vector<std::string> selected_tags;
718 for(std::size_t i = 0; i < tag_filter_types_.size(); ++i) {
719 if(toggle_states[i]) {
720 selected_tags.push_back(tag_filter_types_[i].id);
721 }
722 }
723
724 boost::dynamic_bitset<> res;
725 for(const auto& a : addons_) {
726 bool matched_tag = false;
727 for(const auto& id : selected_tags) {
728 if(utils::contains(a.second.tags, id)) {
729 matched_tag = true;
730 break;
731 }
732 }
733 res.push_back(matched_tag);
734 }
735
736 return res;
737}
738
739boost::dynamic_bitset<> addon_manager::get_type_filter_visibility() const
740{
741 const multimenu_button& type_filter = find_widget<const multimenu_button>("type_filter");
742
743 boost::dynamic_bitset<> toggle_states = type_filter.get_toggle_states();
744 if(toggle_states.none()) {
745 // Nothing selected. It means that *all* add-ons are shown.
746 boost::dynamic_bitset<> res_flipped(addons_.size());
747 return ~res_flipped;
748 } else {
749 boost::dynamic_bitset<> res;
750
751 for(const auto& a : addons_) {
752 int index = std::distance(type_filter_types_.begin(),
754 [](const std::pair<ADDON_TYPE, std::string>& entry) { return entry.first; }));
755 res.push_back(toggle_states[index]);
756 }
757 return res;
758 }
759}
760
761boost::dynamic_bitset<> addon_manager::get_lang_filter_visibility() const
762{
763 const multimenu_button& lang_filter = find_widget<const multimenu_button>("language_filter");
764
765 boost::dynamic_bitset<> toggle_states = lang_filter.get_toggle_states();
766
767 if(toggle_states.none()) {
768 boost::dynamic_bitset<> res_flipped(addons_.size());
769 return ~res_flipped;
770 } else {
771 boost::dynamic_bitset<> res;
772 for(const auto& a : addons_) {
773 bool retval = false;
774 // langcode -> string conversion vector, to be able to detect either
775 // langcodes or langstring entries
776 std::vector<std::string> lang_string_vector;
777 for (long unsigned int i = 0; i < a.second.locales.size(); i++) {
778 lang_string_vector.push_back(langcode_to_string(a.second.locales[i]));
779 }
780 // Find all toggle states, where toggle = true and lang = lang
781 for (long unsigned int i = 0; i < toggle_states.size(); i++) {
782 if (toggle_states[i] == true) {
783 // does lang_code match?
784 bool contains_lang_code = utils::contains(a.second.locales, language_filter_types_[i].second);
785 // does land_string match?
786 bool contains_lang_string = utils::contains(lang_string_vector, language_filter_types_[i].second);
787 if ((contains_lang_code || contains_lang_string) == true)
788 retval = true;
789 }
790 }
791 res.push_back(retval);
792 }
793 return res;
794 }
795}
796
798{
799 // In the small-screen layout, the text_box for the filter keeps keyboard focus even when the
800 // details panel is visible, which means this can be called when the list isn't visible. That
801 // causes problems both because find_widget can throw exceptions, but also because changing the
802 // filters can hide the currently-shown add-on, triggering a different one to be selected in a
803 // way that would seem random unless the user realised that they were typing into a filter box.
804 //
805 // Quick workaround is to not process the new filter if the list isn't visible.
806 auto list = find_widget<addon_list>("addons", false, false);
807 if(!list) {
808 return;
809 }
810
811 boost::dynamic_bitset<> res =
817 list->set_addon_shown(res);
818}
819
821{
822 const menu_button& order_menu = find_widget<const menu_button>("order_dropdown");
823 const addon_order& order_struct = all_orders_.at(order_menu.get_value() / 2);
824 sort_order::type order = order_menu.get_value() % 2 == 0 ? sort_order::type::ascending : sort_order::type::descending;
826 if(order == sort_order::type::ascending) {
827 func = order_struct.sort_func_asc;
828 } else {
829 func = order_struct.sort_func_desc;
830 }
831
832 find_widget<addon_list>("addons").set_addon_order(func);
833 prefs::get().set_addon_manager_saved_order_name(order_struct.as_preference);
835}
836
837void addon_manager::on_order_changed(unsigned int sort_column, sort_order::type order)
838{
839 menu_button& order_menu = find_widget<menu_button>("order_dropdown");
840 auto order_it = utils::ranges::find(all_orders_, static_cast<int>(sort_column), &addon_order::column_index);
841 int index = 2 * (std::distance(all_orders_.begin(), order_it));
842 if(order == sort_order::type::descending) {
843 ++index;
844 }
845 order_menu.set_value(index);
846 prefs::get().set_addon_manager_saved_order_name(order_it->as_preference);
848}
849
850template<void(addon_manager::*fptr)(const addon_info& addon)>
852{
853 // Explicitly return to the main page if we're in low-res mode so the list is visible.
854 if(stacked_widget* stk = find_widget<stacked_widget>("main_stack", false, false)) {
855 stk->select_layer(0);
856 find_widget<button>("details_toggle").set_label(_("Add-on Details"));
857 }
858
859 addon_list& addons = find_widget<addon_list>("addons");
860 // The pointer returned by get_selected_addon comes from the vector<addon_info*> owned by the addon_list.
861 // This is a pointer into the addons_list map owned by the addon_manager. Any modification to the map
862 // kicked off by this method call will cause that pointer to dangle. Copying the addon_info here prevents
863 // that.
864 const addon_info* p_addon = addons.get_selected_addon();
865 if(p_addon == nullptr) {
866 return;
867 }
868 addon_info selected_addon = *p_addon;
869
870 try {
871 (this->*fptr)(selected_addon);
872 } catch(const addons_client::user_exit&) {
873 // User canceled the op.
874 }
875}
876
878{
879 addon_info versioned_addon = addon;
880 if(addon.id == find_widget<addon_list>("addons").get_selected_addon()->id) {
881 widget* parent = this;
882 if(stacked_widget* stk = find_widget<stacked_widget>("main_stack", false, false)) {
883 parent = stk->get_layer_grid(1);
884 }
885 // At this point the version list should always be found, so error if it's not there
886 menu_button& list = parent->find_widget<menu_button>("version_filter");
887 versioned_addon.current_version = list.get_value_string();
888 }
889
891
892 // Take note if any wml_changes occurred
894
897 }
898}
899
901{
902 if(have_addon_pbl_info(addon.id) || have_addon_in_vcs_tree(addon.id)) {
904 _("The following add-on appears to have publishing or version control information stored locally, and will not be removed:")
905 + " " + addon.display_title_full());
906 return;
907 }
908
909 bool success = remove_local_addon(addon.id);
910
911 if(!success) {
912 gui2::show_error_message(_("The following add-on could not be deleted properly:") + " " + addon.display_title_full());
913 } else {
915
917 }
918}
919
921{
922 /* Currently, the install and update codepaths are the same, so this function simply
923 * calls the other. Since this might change in the future, I'm leaving this function
924 * here for now.
925 *
926 * - vultraz, 2017-03-12
927 */
928 install_addon(addon);
929}
930
932{
933 for(const auto& a : addons_) {
934 if(tracking_info_[a.first].state == ADDON_INSTALLED_UPGRADABLE) {
936
937 if(result.wml_changed) {
938 // Updating an add-on may have resulted in its dependencies being updated
939 // as well, so we need to reread version info blocks afterwards to make sure
940 // we don't try to re-download newly updated add-ons.
942 }
943
944 // Take note if any wml_changes occurred
946 }
947 }
948
951 }
952}
953
955{
956 // TODO: make this a separate method to avoid code duplication
957
958 // Explicitly return to the main page if we're in low-res mode so the list is visible.
959 if(stacked_widget* stk = find_widget<stacked_widget>("main_stack", false, false)) {
960 stk->select_layer(0);
961 find_widget<button>("details_toggle").set_label(_("Add-on Details"));
962 }
963
964 addon_list& addons = find_widget<addon_list>("addons");
965 const addon_info* addon = addons.get_selected_addon();
966
967 bool needs_refresh = false;
968 if(addon == nullptr) {
969 gui2::dialogs::addon_server_info::execute(client_, "", needs_refresh);
970 } else {
971 gui2::dialogs::addon_server_info::execute(client_, addon->id, needs_refresh);
972 }
973
974 if(needs_refresh) {
977 }
978}
979
980/** Performs all backend and UI actions for publishing the specified add-on. */
982{
983 std::string server_msg;
984
985 const std::string addon_id = addon.id;
986 // Since the user is planning to upload an addon, this is the right time to validate the .pbl.
987 config cfg = get_addon_pbl_info(addon_id, true);
988
989 const version_info& version_to_publish = cfg["version"].str();
990
991 if(version_to_publish <= tracking_info_[addon_id].remote_version) {
992 const int res = gui2::show_message(_("Warning"),
993 _("The remote version of this add-on is greater or equal to the version being uploaded. Do you really wish to continue?"),
995
996 if(res != gui2::retval::OK) {
997 return;
998 }
999 }
1000
1001 // if the passphrase isn't provided from the _server.pbl, try to pre-populate it from the preferences before prompting for it
1002 if(cfg["passphrase"].empty()) {
1003 cfg["passphrase"] = prefs::get().password(prefs::get().campaign_server(), cfg["author"]);
1004 if(!gui2::dialogs::addon_auth::execute(cfg)) {
1005 return;
1006 } else {
1007 prefs::get().set_password(prefs::get().campaign_server(), cfg["author"], cfg["passphrase"]);
1008 }
1009 } else if(cfg["forum_auth"].to_bool()) {
1010 // if the uploader's forum password is present in the _server.pbl
1011 gui2::show_error_message(_("The passphrase attribute cannot be present when forum_auth is used."));
1012 return;
1013 }
1014
1015 if(!cfg["icon"].empty() && !::image::exists(cfg["icon"].str())) {
1016 gui2::show_error_message(_("Invalid icon path. Make sure the path points to a valid image."));
1017 } else if(!client_.request_distribution_terms(server_msg)) {
1019 _("The server responded with an error:") + "\n" + client_.get_last_server_error(), true);
1020 } else if(gui2::dialogs::addon_license_prompt::execute(server_msg)) {
1021 if(!client_.upload_addon(addon_id, server_msg, cfg, tracking_info_[addon_id].state == ADDON_INSTALLED_LOCAL_ONLY)) {
1022 const std::string& msg = _("The add-on was rejected by the server:") +
1023 "\n\n" + client_.get_last_server_error();
1024 const std::string& extra_data = client_.get_last_server_error_data();
1025 if (!extra_data.empty()) {
1026 // TODO: Allow user to copy the extra data portion to clipboard
1027 // or something, maybe display it in a dialog similar to
1028 // the WML load errors report in a monospace font and
1029 // stuff (having a scroll container is especially
1030 // important since a long list can cause the dialog to
1031 // overflow).
1032 gui2::show_error_message(msg + "\n\n" + extra_data, true);
1033 } else {
1034 gui2::show_error_message(msg, true);
1035 }
1036 } else {
1037 gui2::show_transient_message(_("Response"), server_msg);
1040 }
1041 }
1042}
1043
1044/** Performs all backend and UI actions for taking down the specified add-on. */
1046{
1047 const std::string addon_id = addon.id;
1048 const std::string& text = VGETTEXT(
1049 "Deleting '$addon|' will permanently erase its download and upload counts on the add-ons server. Do you really wish to continue?",
1050 {{"addon", make_addon_title(addon_id)}} // FIXME: need the real title!
1051 );
1052
1053 const int res = gui2::show_message(_("Confirm"), text, gui2::dialogs::message::yes_no_buttons);
1054
1055 if(res != gui2::retval::OK) {
1056 return;
1057 }
1058
1059 std::string server_msg;
1060 if(!client_.delete_remote_addon(addon_id, server_msg)) {
1061 gui2::show_error_message(_("The server responded with an error:") + "\n" + client_.get_last_server_error(), true);
1062 } else {
1063 // FIXME: translation needed!
1064 gui2::show_transient_message(_("Response"), server_msg);
1067 }
1068}
1069
1070/** Called when the player double-clicks an add-on. */
1072{
1073 switch(tracking_info_[addon.id].state) {
1074 case ADDON_NONE:
1075 install_addon(addon);
1076 break;
1077 case ADDON_INSTALLED:
1078 if(!tracking_info_[addon.id].can_publish) {
1079 utils::string_map symbols{ { "addon", addon.display_title_full() } };
1080 int res = gui2::show_message(_("Uninstall add-on"),
1081 VGETTEXT("Do you want to uninstall '$addon|'?", symbols),
1083 if(res == gui2::retval::OK) {
1084 uninstall_addon(addon);
1085 }
1086 }
1087 break;
1089 update_addon(addon);
1090 break;
1093 publish_addon(addon);
1094 break;
1095 default:
1096 break;
1097 }
1098}
1099
1101{
1102 help::show_help("installing_addons");
1103}
1104
1105static std::string format_addon_time(const std::chrono::system_clock::time_point& time)
1106{
1107 if(time == std::chrono::system_clock::time_point{}) {
1108 return font::unicode_em_dash;
1109 }
1110
1111 const std::string format = prefs::get().use_twelve_hour_clock_format()
1112 // TRANSLATORS: Month + day of month + year + 12-hour time, eg 'November 02 2021, 1:59 PM'. Format for your locale.
1113 // Format reference: https://www.boost.org/doc/libs/1_85_0/doc/html/date_time/date_time_io.html#date_time.format_flags
1114 ? _("%B %d %Y, %I:%M %p")
1115 // TRANSLATORS: Month + day of month + year + 24-hour time, eg 'November 02 2021, 13:59'. Format for your locale.
1116 // Format reference: https://www.boost.org/doc/libs/1_85_0/doc/html/date_time/date_time_io.html#date_time.format_flags
1117 : _("%B %d %Y, %H:%M");
1118
1120}
1121
1123{
1124 widget* parent = this;
1125 const addon_info* info = nullptr;
1126 if(stacked_widget* stk = find_widget<stacked_widget>("main_stack", false, false)) {
1127 parent = stk->get_layer_grid(1);
1128 info = stk->get_layer_grid(0)->find_widget<addon_list>("addons").get_selected_addon();
1129 } else {
1130 info = find_widget<addon_list>("addons").get_selected_addon();
1131 }
1132
1133 if(info == nullptr) {
1134 return;
1135 }
1136
1137 parent->find_widget<drawing>("image").set_label(info->display_icon());
1138 parent->find_widget<styled_widget>("title").set_label(info->display_title_translated_or_original());
1139 parent->find_widget<styled_widget>("description").set_label(info->description_translated());
1140 menu_button& version_filter = parent->find_widget<menu_button>("version_filter");
1141 parent->find_widget<styled_widget>("author").set_label(info->author);
1142 parent->find_widget<styled_widget>("type").set_label(info->display_type());
1143
1146 status.set_use_markup(true);
1147
1149 parent->find_widget<styled_widget>("downloads").set_label(std::to_string(info->downloads));
1152
1153 parent->find_widget<styled_widget>("dependencies").set_label(!info->depends.empty()
1154 ? make_display_dependencies(info->id, addons_, tracking_info_)
1155 : _("addon_dependencies^None"));
1156
1157 std::string languages;
1158
1159 for(const auto& lc : info->locales) {
1160 const std::string& langlabel = langcode_to_string(lc);
1161 if(!langlabel.empty()) {
1162 if(!languages.empty()) {
1163 languages += ", ";
1164 }
1165 languages += langlabel;
1166 }
1167 }
1168
1169 parent->find_widget<styled_widget>("translations").set_label(!languages.empty() ? languages : _("translations^None"));
1170
1171 const std::string& feedback_url = info->feedback_url;
1172 parent->find_widget<label>("url").set_label(!feedback_url.empty() ? feedback_url : _("url^None"));
1173 parent->find_widget<label>("id").set_label(info->id);
1174
1175 bool installed = is_installed_addon_status(tracking_info_[info->id].state);
1176 bool updatable = tracking_info_[info->id].state == ADDON_INSTALLED_UPGRADABLE;
1177
1178 stacked_widget& action_stack = parent->find_widget<stacked_widget>("action_stack");
1179 // #TODO: Add tooltips with upload time and pack size
1180 std::vector<config> version_filter_entries;
1181
1182 if(!tracking_info_[info->id].can_publish) {
1183 action_stack.select_layer(0);
1184
1185 stacked_widget& install_update_stack = parent->find_widget<stacked_widget>("install_update_stack");
1186 install_update_stack.select_layer(updatable ? 1 : 0);
1187
1188 if(!updatable) {
1189 parent->find_widget<button>("install").set_active(!installed);
1190 } else {
1191 parent->find_widget<button>("update").set_active(true);
1192 }
1193
1194 parent->find_widget<button>("uninstall").set_active(installed);
1195
1196 for(const auto& f : info->versions) {
1197 version_filter_entries.emplace_back("label", f.str());
1198 }
1199 } else {
1200 action_stack.select_layer(1);
1201
1202 // Always enable the publish button, but disable the delete button if not yet published.
1203 parent->find_widget<button>("publish").set_active(true);
1204 parent->find_widget<button>("delete").set_active(!info->local_only);
1205
1206 // Show only the version to be published
1207 version_filter_entries.emplace_back("label", info->current_version.str());
1208 }
1209
1210 version_filter.set_values(version_filter_entries);
1211 version_filter.set_active(version_filter_entries.size() > 1);
1212}
1213
1215{
1216 widget* parent = this;
1217 const addon_info* info = nullptr;
1218 if(stacked_widget* stk = find_widget<stacked_widget>("main_stack", false, false)) {
1219 parent = stk->get_layer_grid(1);
1220 info = stk->get_layer_grid(0)->find_widget<addon_list>("addons").get_selected_addon();
1221 } else {
1222 info = find_widget<addon_list>("addons").get_selected_addon();
1223 }
1224
1225 if(info == nullptr) {
1226 return;
1227 }
1228
1229 if(!tracking_info_[info->id].can_publish && is_installed_addon_status(tracking_info_[info->id].state)) {
1230 bool updatable = tracking_info_[info->id].installed_version
1231 != parent->find_widget<menu_button>("version_filter").get_value_string();
1232 stacked_widget& action_stack = parent->find_widget<stacked_widget>("action_stack");
1233 action_stack.select_layer(0);
1234
1235 stacked_widget& install_update_stack = parent->find_widget<stacked_widget>("install_update_stack");
1236 install_update_stack.select_layer(1);
1237 parent->find_widget<button>("update").set_active(updatable);
1238 }
1239}
1240
1242{
1245 return false;
1246 }
1247
1248 return true;
1249}
1250
1251} // namespace dialogs
bool remove_local_addon(const std::string &addon)
Removes the specified add-on, deleting its full directory structure.
Definition manager.cpp:138
config get_addon_pbl_info(const std::string &addon_name, bool do_validate)
Gets the publish information for an add-on.
Definition manager.cpp:71
bool have_addon_in_vcs_tree(const std::string &addon_name)
Returns whether the specified add-on appears to be managed by a VCS or not.
Definition manager.cpp:57
std::vector< std::string > available_addons()
Returns a list of local add-ons that can be published.
Definition manager.cpp:181
bool have_addon_pbl_info(const std::string &addon_name)
Returns whether a .pbl file is present for the specified add-on or not.
Definition manager.cpp:66
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition manager.cpp:186
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on's version information structs.
Definition manager.cpp:381
#define GETTEXT_DOMAIN
Add-ons (campaignd) client class.
Definition client.hpp:41
install_result install_addon_with_checks(const addons_list &addons, const addon_info &addon)
Performs an add-on download and install cycle.
Definition client.cpp:725
const std::string & server_version() const
Definition client.hpp:236
const std::string & get_last_server_error_data() const
Returns the last error message extra data sent by the server, or an empty string.
Definition client.hpp:80
@ abort
User aborted the operation because of an issue with dependencies or chose not to overwrite the add-on...
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
bool using_tls() const
Returns whether the current connection uses TLS.
Definition client.hpp:226
const std::string & server_id() const
Definition client.hpp:231
const std::string & addr() const
Returns the current hostname:port used for this connection.
Definition client.hpp:74
bool request_distribution_terms(std::string &terms)
Request the add-ons server distribution terms message.
Definition client.cpp:274
bool request_addons_list(config &cfg, bool icons)
Request the add-ons list from the server.
Definition client.cpp:253
bool upload_addon(const std::string &id, std::string &response_message, config &cfg, bool local_only)
Uploads an add-on to the server.
Definition client.cpp:297
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
config & add_child(std::string_view key)
Definition config.cpp:428
const_attr_itors attribute_range() const
Definition config.cpp:732
child_itors child_range(std::string_view key)
Definition config.cpp:260
boost::iterator_range< const_child_iterator > const_child_itors
Definition config.hpp:281
std::ostringstream wrapper.
Definition formatter.hpp:40
void set_uninstall_function(addon_op_func_t function)
Sets the function to call when the player clicks the uninstall button.
std::function< bool(const addon_info &, const addon_info &)> addon_sort_func
void set_publish_function(addon_op_func_t function)
Sets the function to upload an addon to the addons server.
void add_list_to_keyboard_chain()
Adds the internal listbox to the keyboard event chain.
void set_install_function(addon_op_func_t function)
Sets the function to call when the player clicks the install button.
void set_delete_function(addon_op_func_t function)
Sets the function to install an addon from the addons server.
const addon_info * get_selected_addon() const
Returns the selected add-on.
void set_update_function(addon_op_func_t function)
Sets the function to call when the player clicks the update button.
void set_callback_order_change(std::function< void(unsigned, sort_order::type)> callback)
Sets up a callback that will be called when the player changes the sorting order.
static const int DEFAULT_ACTION_RETVAL
Special retval for the toggle panels in the addons list.
static std::string colorize_addon_state_string(const std::string &str, ADDON_STATUS state, bool verbose=false)
Changes the color of an add-on state string (installed, outdated, etc.) according to the state itself...
void set_addons(const addons_list &addons)
Sets the add-ons to show.
Simple push button.
Definition button.hpp:36
virtual void set_active(const bool active) override
See styled_widget::set_active.
void uninstall_addon(const addon_info &addon)
Definition manager.cpp:900
void on_order_changed(unsigned int sort_column, sort_order::type order)
Definition manager.cpp:837
static const std::vector< std::pair< ADDON_STATUS_FILTER, std::string > > status_filter_types_
Definition manager.hpp:90
virtual void pre_show() override
Actions to be taken before showing the window.
Definition manager.cpp:295
boost::dynamic_bitset get_lang_filter_visibility() const
Definition manager.cpp:761
addons_client & client_
Definition manager.hpp:82
boost::dynamic_bitset get_status_filter_visibility() const
Definition manager.cpp:686
void execute_default_action(const addon_info &addon)
Called when the player double-clicks an add-on.
Definition manager.cpp:1071
void reload_list_and_reselect_item(const std::string &id)
Definition manager.cpp:656
std::vector< std::pair< int, std::string > > language_filter_types_
Definition manager.hpp:92
void execute_default_action_on_selected_addon()
Definition manager.hpp:131
boost::dynamic_bitset get_name_filter_visibility() const
Definition manager.cpp:665
void toggle_details(button &btn, stacked_widget &stk)
Definition manager.cpp:583
void delete_addon(const addon_info &addon)
Performs all backend and UI actions for taking down the specified add-on.
Definition manager.cpp:1045
config cfg_
Config which contains the list with the campaigns.
Definition manager.hpp:80
boost::dynamic_bitset get_type_filter_visibility() const
Definition manager.cpp:739
addons_tracking_list tracking_info_
Definition manager.hpp:88
static const std::vector< addon_order > all_orders_
Definition manager.hpp:93
boost::dynamic_bitset get_tag_filter_visibility() const
Definition manager.cpp:707
static const std::vector< std::pair< ADDON_TYPE, std::string > > type_filter_types_
Definition manager.hpp:91
utils::optional< ADDON_TYPE > initial_type_filter_
Definition manager.hpp:84
addon_manager(addons_client &client, const utils::optional< ADDON_TYPE > initial_type_filter=utils::nullopt)
Definition manager.cpp:228
void install_addon(const addon_info &addon)
Definition manager.cpp:877
void update_addon(const addon_info &addon)
Definition manager.cpp:920
void publish_addon(const addon_info &addon)
Performs all backend and UI actions for publishing the specified add-on.
Definition manager.cpp:981
@ yes_no_buttons
Shows a yes and no button.
Definition message.hpp:81
@ ok_cancel_buttons
Shows an ok and cancel button.
Definition message.hpp:77
Abstract base class for all modal dialogs.
Base container class.
Definition grid.hpp:32
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
Definition grid.cpp:645
void set_link_aware(bool l)
Definition label.cpp:89
virtual void set_value(unsigned value, bool fire_event=false) override
Inherited from selectable_item.
std::string get_value_string() const
Returns the value of the selected row.
void set_values(const std::vector<::config > &values, unsigned selected=0)
virtual unsigned get_value() const override
Inherited from selectable_item.
void set_values(const std::vector<::config > &values)
Set the available menu options.
void select_option(const unsigned option, const bool selected=true)
Select an option in the menu.
boost::dynamic_bitset get_toggle_states() const
Get the current state of the menu options.
int current_layer() const
Gets the current visible layer number.
grid * get_layer_grid(unsigned int i)
Gets the grid for a specified layer.
void select_layer(const int layer)
Selects and displays a particular layer.
virtual void set_label(const t_string &text)
virtual void set_use_markup(bool use_markup)
std::string get_value() const
A widget that allows the user to input text in single line.
Definition text_box.hpp:125
Base class for all widgets.
Definition widget.hpp:55
T * find_widget(const std::string_view id, const bool must_be_active, const bool must_exist)
Gets a widget with the wanted id.
Definition widget.hpp:747
widget * parent()
Definition widget.cpp:170
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.
Definition window.hpp:313
void keyboard_capture(widget *widget)
Definition window.cpp:1205
void close()
Requests to close the window.
Definition window.hpp:216
status
The status of the window.
Definition window.hpp:203
void set_escape_disabled(const bool escape_disabled)
Disable the escape key.
Definition window.hpp:326
void set_exit_hook(exit_hook mode, const Func &hook)
Sets the window's exit hook.
Definition window.hpp:435
int get_retval()
Definition window.hpp:394
static prefs & get()
void set_addon_manager_saved_order_direction(sort_order::type value)
void set_password(const std::string &server, const std::string &login, const std::string &key)
sort_order::type addon_manager_saved_order_direction()
bool use_twelve_hour_clock_format()
std::string password(const std::string &server, const std::string &login)
Represents version numbers.
std::string str() const
Serializes the version number into string form.
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
#define N_(String)
Definition gettext.hpp:108
static std::string _(const char *str)
Definition gettext.hpp:100
std::string label
What to show in the filter's drop-down list.
Definition manager.cpp:201
const std::vector< std::string > filtertext_
Definition manager.cpp:87
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
Definition manager.cpp:203
std::string id
Text to match against addon_info.tags()
Definition manager.cpp:199
This file contains the window object, this object is a top level container which has the event manage...
std::string size_display_string(double size)
Get a human-readable representation of the specified byte count.
Definition info.cpp:294
std::string make_addon_title(const std::string &id)
Replaces underscores to dress up file or dirnames as add-on titles.
Definition info.cpp:299
void read_addons_list(const config &cfg, addons_list &dest)
Parse the specified add-ons list WML into an actual addons_list object.
Definition info.cpp:277
std::map< std::string, addon_info > addons_list
Definition info.hpp:28
std::vector< language_def > get_languages(bool all)
Return a list of available translations.
Definition language.cpp:159
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
auto get_local_timestamp(const std::chrono::system_clock::time_point &time)
Definition chrono.hpp:63
const std::string unicode_em_dash
Definition constants.cpp:44
bool addon_server_info
const bool & debug
static std::string describe_status_verbose(const addon_tracking_info &state)
Definition manager.cpp:240
static std::string format_addon_time(const std::chrono::system_clock::time_point &time)
Definition manager.cpp:1105
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
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:148
retval
Default window/dialog return values.
Definition retval.hpp:30
@ OK
Dialog was closed with the OK button.
Definition retval.hpp:35
void show_help(const std::string &show_topic)
Open the help browser.
Definition help.cpp:84
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
Definition picture.cpp:993
std::string translate_timestamp(time_t time, std::string_view format)
Translates the passed timestamp and returns it in the requested format.
Definition gettext.cpp:577
bool ci_search(const std::string &s1, const std::string &s2)
Case-insensitive search.
Definition gettext.cpp:559
auto find(Container &container, const Value &value, const Projection &projection={})
Definition general.hpp:213
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
Definition general.hpp:88
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
Definition sound.cpp:139
addon_tracking_info get_addon_tracking_info(const addon_info &addon)
Get information about an add-on comparing its local state with the add-ons server entry.
Definition state.cpp:25
bool is_installed_addon_status(ADDON_STATUS s)
Definition state.hpp:40
@ ADDON_NOT_TRACKED
No tracking information available.
Definition state.hpp:37
@ ADDON_INSTALLED_OUTDATED
Version in the server is older than local installation.
Definition state.hpp:30
@ ADDON_NONE
Add-on is not installed.
Definition state.hpp:24
@ ADDON_INSTALLED_UPGRADABLE
Version in the server is newer than local installation.
Definition state.hpp:28
@ ADDON_INSTALLED
Version in the server matches local installation.
Definition state.hpp:26
@ ADDON_INSTALLED_LOCAL_ONLY
No version in the server.
Definition state.hpp:32
@ ADDON_INSTALLED_BROKEN
Dependencies not satisfied.
Definition state.hpp:35
ADDON_STATUS_FILTER
Add-on installation status filters for the user interface.
Definition state.hpp:84
@ FILTER_INSTALLED
Definition state.hpp:86
@ FILTER_PUBLISHABLE
Definition state.hpp:88
@ FILTER_NOT_INSTALLED
Definition state.hpp:89
@ FILTER_ALL
Definition state.hpp:85
@ FILTER_UPGRADABLE
Definition state.hpp:87
std::map< std::string, addon_tracking_info > addons_tracking_list
Definition state.hpp:64
std::vector< std::string > tags
Definition info.hpp:92
version_info current_version
Definition info.hpp:81
std::string display_type() const
Get an add-on type identifier for display in the user's language.
Definition info.cpp:232
int downloads
Definition info.hpp:87
std::chrono::system_clock::time_point updated
Definition info.hpp:102
std::string title
Definition info.hpp:76
std::string display_title_translated_or_original() const
Definition info.cpp:198
std::chrono::system_clock::time_point created
Definition info.hpp:103
std::string author
Definition info.hpp:84
std::string display_title_full() const
Definition info.cpp:210
std::set< std::string > resolve_dependencies(const addons_list &addons) const
Resolve an add-on's dependency tree in a recursive fashion.
Definition info.cpp:264
int size
Definition info.hpp:86
std::vector< std::string > locales
Definition info.hpp:93
std::string id
Definition info.hpp:75
ADDON_TYPE type
Definition info.hpp:90
Stores additional status information about add-ons.
Definition state.hpp:47
ADDON_STATUS state
Definition state.hpp:57
version_info installed_version
Definition state.hpp:60
Contains the outcome of an add-on install operation.
Definition client.hpp:134
install_outcome outcome
Overall outcome of the operation.
Definition client.hpp:138
bool wml_changed
Specifies if WML on disk was altered and needs to be reloaded.
Definition client.hpp:147
addon_list::addon_sort_func sort_func_desc
Definition manager.hpp:54
addon_list::addon_sort_func sort_func_asc
Definition manager.hpp:53
std::string as_preference
The value used in the preferences file.
Definition manager.hpp:51
Exception thrown when the WML parser fails to read a .pbl file.
Definition manager.hpp:45
static map_location::direction s
@ ADDON_UNKNOWN
a.k.a.
@ ADDON_THEME
GUI2 Themes.
@ ADDON_SP_SCENARIO
Single-player scenario.
@ ADDON_MP_SCENARIO
Multiplayer scenario.
@ ADDON_MP_CAMPAIGN
Multiplayer campaign.
@ ADDON_MP_FACTION
Multiplayer faction.
@ ADDON_MEDIA
Miscellaneous content/media (unit packs, terrain packs, music packs, etc.).
@ ADDON_MP_ERA
Multiplayer era.
@ ADDON_CORE
Total Conversion Core.
@ ADDON_SP_CAMPAIGN
Single-player campaign.
@ ADDON_OTHER
an add-on that fits in no other category
@ ADDON_SP_MP_CAMPAIGN
Hybrid campaign.
@ ADDON_MP_MAPS
Multiplayer plain (no WML) map pack.
@ ADDON_MOD
Modification of the game.
#define i
#define f
#define b