The Battle for Wesnoth  1.19.1+dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 #pragma once
17 
18 #include "addon/client.hpp"
19 #include "addon/info.hpp"
20 #include "addon/state.hpp"
21 
24 
25 
26 namespace gui2
27 {
28 class selectable_item;
29 class button;
30 class stacked_widget;
31 namespace dialogs
32 {
33 
35 {
36 public:
37  explicit addon_manager(addons_client& client);
38 
40  {
42  }
43 
44 private:
45  struct addon_order
46  {
47  std::string label;
48  /** The value used in the preferences file */
49  std::string as_preference;
50  int column_index; // -1 if there is no such column
53 
54  addon_order(std::string label_, std::string as_preference_, int column, addon_list::addon_sort_func sort_func_asc_, addon_list::addon_sort_func sort_func_desc_)
55  : label(label_)
56  , as_preference(as_preference_)
57  , column_index(column)
58  , sort_func_asc(sort_func_asc_)
59  , sort_func_desc(sort_func_desc_)
60  {}
61  };
62 
63  std::vector<selectable_item*> orders_;
64 
65  void on_addon_select();
66  void toggle_details(button& btn, stacked_widget& stk);
67 
68  virtual const std::string& window_id() const override;
69 
70  virtual void pre_show(window& window) override;
71 
72  void fetch_addons_list();
73  void load_addon_list();
74 
75  void reload_list_and_reselect_item(const std::string id);
76 
77  /** Config which contains the list with the campaigns. */
79 
81 
83 
85 
86  static const std::vector<std::pair<ADDON_STATUS_FILTER, std::string>> status_filter_types_;
87  static const std::vector<std::pair<ADDON_TYPE, std::string>> type_filter_types_;
88  std::vector<std::pair<int, std::string>> language_filter_types_;
89  static const std::vector<addon_order> all_orders_;
90 
92 
93  template<void(addon_manager::*fptr)(const addon_info& addon)>
95 
96  void install_addon(const addon_info& addon);
98  {
99  execute_action_on_selected_addon<&addon_manager::install_addon>();
100  }
101 
102  void uninstall_addon(const addon_info& addon);
104  {
105  execute_action_on_selected_addon<&addon_manager::uninstall_addon>();
106  }
107 
108  void update_addon(const addon_info& addon);
110  {
111  execute_action_on_selected_addon<&addon_manager::update_addon>();
112  }
113 
114  void publish_addon(const addon_info& addon);
116  {
117  execute_action_on_selected_addon<&addon_manager::publish_addon>();
118  }
119 
120  void delete_addon(const addon_info& addon);
122  {
123  execute_action_on_selected_addon<&addon_manager::delete_addon>();
124  }
125 
126  void execute_default_action(const addon_info& addon);
128  {
129  execute_action_on_selected_addon<&addon_manager::execute_default_action>();
130  }
131 
132  void update_all_addons();
133 
134  void apply_filters();
135  void order_addons();
136  void on_order_changed(unsigned int sort_column, sort_order::type order);
137  void show_help();
138 
139  boost::dynamic_bitset<> get_name_filter_visibility() const;
140  boost::dynamic_bitset<> get_status_filter_visibility() const;
141  boost::dynamic_bitset<> get_tag_filter_visibility() const;
142  boost::dynamic_bitset<> get_type_filter_visibility() const;
143  boost::dynamic_bitset<> get_lang_filter_visibility() const;
144 
146  bool exit_hook(window& window);
147 };
148 
149 } // namespace dialogs
150 } // namespace gui2
Add-ons (campaignd) client class.
Definition: client.hpp:41
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::function< bool(const addon_info &, const addon_info &)> addon_sort_func
Definition: addon_list.hpp:40
Simple push button.
Definition: button.hpp:36
void uninstall_addon(const addon_info &addon)
Definition: manager.cpp:858
void on_order_changed(unsigned int sort_column, sort_order::type order)
Definition: manager.cpp:800
static const std::vector< std::pair< ADDON_STATUS_FILTER, std::string > > status_filter_types_
Definition: manager.hpp:86
boost::dynamic_bitset get_lang_filter_visibility() const
Definition: manager.cpp:724
addons_client & client_
Definition: manager.hpp:80
virtual const std::string & window_id() const override
The ID of the window to build.
boost::dynamic_bitset get_status_filter_visibility() const
Definition: manager.cpp:646
void execute_default_action(const addon_info &addon)
Called when the player double-clicks an add-on.
Definition: manager.cpp:1003
std::vector< std::pair< int, std::string > > language_filter_types_
Definition: manager.hpp:88
void execute_default_action_on_selected_addon()
Definition: manager.hpp:127
boost::dynamic_bitset get_name_filter_visibility() const
Definition: manager.cpp:622
void toggle_details(button &btn, stacked_widget &stk)
Definition: manager.cpp:540
void reload_list_and_reselect_item(const std::string id)
Definition: manager.cpp:613
void delete_addon(const addon_info &addon)
Performs all backend and UI actions for taking down the specified add-on.
Definition: manager.cpp:977
addon_manager(addons_client &client)
Definition: manager.cpp:234
config cfg_
Config which contains the list with the campaigns.
Definition: manager.hpp:78
boost::dynamic_bitset get_type_filter_visibility() const
Definition: manager.cpp:699
addons_tracking_list tracking_info_
Definition: manager.hpp:84
static const std::vector< addon_order > all_orders_
Definition: manager.hpp:89
boost::dynamic_bitset get_tag_filter_visibility() const
Definition: manager.cpp:667
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: manager.cpp:300
static const std::vector< std::pair< ADDON_TYPE, std::string > > type_filter_types_
Definition: manager.hpp:87
bool get_need_wml_cache_refresh() const
Definition: manager.hpp:39
void install_addon(const addon_info &addon)
Definition: manager.cpp:837
void update_addon(const addon_info &addon)
Definition: manager.cpp:878
std::vector< selectable_item * > orders_
Definition: manager.hpp:63
void publish_addon(const addon_info &addon)
Performs all backend and UI actions for publishing the specified add-on.
Definition: manager.cpp:913
Abstract base class for all modal dialogs.
t_string label_
Contain the non-editable text associated with styled_widget.
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
Networked add-ons (campaignd) client interface.
std::map< std::string, addon_info > addons_list
Definition: info.hpp:27
Various uncategorised dialogs.
Generic file dialog.
std::map< std::string, addon_tracking_info > addons_tracking_list
Definition: state.hpp:64
addon_list::addon_sort_func sort_func_desc
Definition: manager.hpp:52
addon_list::addon_sort_func sort_func_asc
Definition: manager.hpp:51
std::string as_preference
The value used in the preferences file.
Definition: manager.hpp:49
addon_order(std::string label_, std::string as_preference_, int column, addon_list::addon_sort_func sort_func_asc_, addon_list::addon_sort_func sort_func_desc_)
Definition: manager.hpp:54