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