The Battle for Wesnoth  1.17.0-dev
manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 #include "gui/widgets/pane.hpp"
25 
26 #include <boost/dynamic_bitset.hpp>
27 
28 namespace gui2
29 {
30 class text_box_base;
31 class text_box;
32 class pane;
33 class selectable_item;
34 class button;
35 class stacked_widget;
36 namespace dialogs
37 {
38 
39 /**
40  * @ingroup GUIWindowDefinitionWML
41  *
42  * Shows the list of addons on the server available for installation.
43  *
44  * Key |Type |Mandatory|Description
45  * ------------------|--------------|---------|-----------
46  * addons | @ref listbox |yes |A listbox that will contain the info about all addons on the server.
47  * name | label |yes |The name of the addon.
48  * version_filter | menu_button |yes |List allowing current or older versions to be selected.
49  * author | label |yes |The author of the addon.
50  * downloads | label |yes |The number of times the addon has been downloaded.
51  * size | label |yes |The size of the addon.
52  * tags | label |yes |Contents of the PblWML "tags" attribute.
53  */
55 {
56 public:
57  explicit addon_manager(addons_client& client);
58 
60  {
62  }
63 
64 private:
65  struct addon_order
66  {
67  std::string label;
68  /** The value used in the preferences file */
69  std::string as_preference;
70  int column_index; // -1 if there is no such column
73 
74  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_)
75  : label(label_)
76  , as_preference(as_preference_)
77  , column_index(column)
78  , sort_func_asc(sort_func_asc_)
79  , sort_func_desc(sort_func_desc_)
80  {}
81  };
82 
83  std::vector<selectable_item*> orders_;
84 
85  void on_addon_select();
86  void toggle_details(button& btn, stacked_widget& stk);
87 
88  virtual const std::string& window_id() const override;
89 
90  virtual void pre_show(window& window) override;
91 
92  void fetch_addons_list();
93  void load_addon_list();
94 
95  void reload_list_and_reselect_item(const std::string id);
96 
97  /** Config which contains the list with the campaigns. */
99 
101 
103 
105 
106  static const std::vector<std::pair<ADDON_STATUS_FILTER, std::string>> status_filter_types_;
107  static const std::vector<std::pair<ADDON_TYPE, std::string>> type_filter_types_;
108  static const std::vector<addon_order> all_orders_;
109 
111 
112  template<void(addon_manager::*fptr)(const addon_info& addon)>
114 
115  void install_addon(const addon_info& addon);
117  {
118  execute_action_on_selected_addon<&addon_manager::install_addon>();
119  }
120 
121  void uninstall_addon(const addon_info& addon);
123  {
124  execute_action_on_selected_addon<&addon_manager::uninstall_addon>();
125  }
126 
127  void update_addon(const addon_info& addon);
129  {
130  execute_action_on_selected_addon<&addon_manager::update_addon>();
131  }
132 
133  void publish_addon(const addon_info& addon);
135  {
136  execute_action_on_selected_addon<&addon_manager::publish_addon>();
137  }
138 
139  void delete_addon(const addon_info& addon);
141  {
142  execute_action_on_selected_addon<&addon_manager::delete_addon>();
143  }
144 
145  void execute_default_action(const addon_info& addon);
147  {
148  execute_action_on_selected_addon<&addon_manager::execute_default_action>();
149  }
150 
151  void update_all_addons();
152 
153  void apply_filters();
154  void order_addons();
155  void on_order_changed(unsigned int sort_column, preferences::SORT_ORDER order);
156  void show_help();
157 
158  boost::dynamic_bitset<> get_name_filter_visibility() const;
159  boost::dynamic_bitset<> get_status_filter_visibility() const;
160  boost::dynamic_bitset<> get_tag_filter_visibility() const;
161  boost::dynamic_bitset<> get_type_filter_visibility() const;
162 
164  bool exit_hook(window& window);
165 };
166 
167 } // namespace dialogs
168 } // namespace gui2
Shows the list of addons on the server available for installation.
Definition: manager.hpp:54
config cfg_
Config which contains the list with the campaigns.
Definition: manager.hpp:98
boost::dynamic_bitset get_status_filter_visibility() const
Definition: manager.cpp:607
bool exit_hook(window &window)
Definition: manager.cpp:1087
std::function< bool(const addon_info &, const addon_info &)> addon_sort_func
Definition: addon_list.hpp:42
addons_tracking_list tracking_info_
Definition: manager.hpp:104
preferences::SORT_ORDER SORT_ORDER
Definition: listbox.cpp:42
std::string as_preference
The value used in the preferences file.
Definition: manager.hpp:69
void reload_list_and_reselect_item(const std::string id)
Definition: manager.cpp:574
void execute_default_action(const addon_info &addon)
Called when the player double-clicks an add-on.
Definition: manager.cpp:919
static const std::vector< std::pair< ADDON_STATUS_FILTER, std::string > > status_filter_types_
Definition: manager.hpp:106
addon_list::addon_sort_func sort_func_asc
Definition: manager.hpp:71
void update_addon(const addon_info &addon)
Definition: manager.cpp:802
Generic file dialog.
Definition: field-fwd.hpp:23
boost::dynamic_bitset get_name_filter_visibility() const
Definition: manager.cpp:583
bool get_need_wml_cache_refresh() const
Definition: manager.hpp:59
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:74
boost::dynamic_bitset get_tag_filter_visibility() const
Definition: manager.cpp:628
void toggle_details(button &btn, stacked_widget &stk)
Definition: manager.cpp:503
addon_list::addon_sort_func sort_func_desc
Definition: manager.hpp:72
Add-ons (campaignd) client class.
Definition: client.hpp:40
Various uncategorised dialogs.
void on_order_changed(unsigned int sort_column, preferences::SORT_ORDER order)
Definition: manager.cpp:724
void delete_addon(const addon_info &addon)
Performs all backend and UI actions for taking down the specified add-on.
Definition: manager.cpp:893
addons_client & client_
Definition: manager.hpp:100
addon_manager(addons_client &client)
Definition: manager.cpp:244
void execute_default_action_on_selected_addon()
Definition: manager.hpp:146
boost::dynamic_bitset get_type_filter_visibility() const
Definition: manager.cpp:660
void publish_addon(const addon_info &addon)
Performs all backend and UI actions for publishing the specified add-on.
Definition: manager.cpp:837
void install_addon(const addon_info &addon)
Definition: manager.cpp:761
void uninstall_addon(const addon_info &addon)
Definition: manager.cpp:782
static const std::vector< std::pair< ADDON_TYPE, std::string > > type_filter_types_
Definition: manager.hpp:107
std::map< std::string, addon_tracking_info > addons_tracking_list
Definition: state.hpp:64
Abstract base class for all modal dialogs.
Simple push button.
Definition: button.hpp:36
virtual const std::string & window_id() const override
The id of the window to build.
std::vector< selectable_item * > orders_
Definition: manager.hpp:83
A stacked widget holds several widgets on top of each other.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
std::map< std::string, addon_info > addons_list
Definition: info.hpp:28
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: manager.cpp:309
Networked add-ons (campaignd) client interface.
static const std::vector< addon_order > all_orders_
Definition: manager.hpp:108