The Battle for Wesnoth  1.15.2+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 /** Shows the list of addons on the server. */
40 {
41 public:
42  explicit addon_manager(addons_client& client);
43 
45  {
47  }
48 
49 private:
50  struct addon_order
51  {
52  std::string label;
53  int column_index; // -1 if there is no such column
56 
57  addon_order(std::string label_, int column, addon_list::addon_sort_func sort_func_asc_, addon_list::addon_sort_func sort_func_desc_)
58  : label(label_), column_index(column), sort_func_asc(sort_func_asc_), sort_func_desc(sort_func_desc_)
59  {}
60  };
61 
62  void on_filtertext_changed(text_box_base* textbox);
63 
64  std::vector<selectable_item*> orders_;
65 
67  void toggle_details(button& btn, stacked_widget& stk);
68 
69  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
70  virtual const std::string& window_id() const override;
71 
72  /** Inherited from modal_dialog. */
73  virtual void pre_show(window& window) override;
74 
77 
78  void reload_list_and_reselect_item(const std::string id, window& window);
79 
80  /** Config which contains the list with the campaigns. */
82 
84 
86 
88 
89  static const std::vector<std::pair<ADDON_STATUS_FILTER, std::string>> status_filter_types_;
90  static const std::vector<std::pair<ADDON_TYPE, std::string>> type_filter_types_;
91  static const std::vector<addon_order> all_orders_;
92 
94 
95  template<void(addon_manager::*fptr)(const addon_info& addon, window& window)>
97 
98  void install_addon(const addon_info& addon, window& window);
100  {
101  execute_action_on_selected_addon<&addon_manager::install_addon>(window);
102  }
103 
104  void uninstall_addon(const addon_info& addon, window& window);
105  void uninstall_selected_addon(window& window)
106  {
107  execute_action_on_selected_addon<&addon_manager::uninstall_addon>(window);
108  }
109 
110  void update_addon(const addon_info& addon, window& window);
111  void update_selected_addon(window& window)
112  {
113  execute_action_on_selected_addon<&addon_manager::update_addon>(window);
114  }
115 
116  void publish_addon(const addon_info& addon, window& window);
117  void publish_selected_addon(window& window)
118  {
119  execute_action_on_selected_addon<&addon_manager::publish_addon>(window);
120  }
121 
122  void delete_addon(const addon_info& addon, window& window);
123  void delete_selected_addon(window& window)
124  {
125  execute_action_on_selected_addon<&addon_manager::delete_addon>(window);
126  }
127 
128  void execute_default_action(const addon_info& addon, window& window);
130  {
131  execute_action_on_selected_addon<&addon_manager::execute_default_action>(window);
132  }
133 
134  void update_all_addons(window& window);
135 
136  void browse_url_callback(text_box& url_box);
137  void copy_url_callback(text_box& url_box);
138 
139  void apply_filters(window& window);
140  void order_addons(window& window);
141  void on_order_changed(window& window, unsigned int sort_column, listbox::SORT_ORDER order);
142  void show_help();
143 
144  boost::dynamic_bitset<> get_name_filter_visibility(const window& window) const;
145  boost::dynamic_bitset<> get_status_filter_visibility(const window& window) const;
146  boost::dynamic_bitset<> get_type_filter_visibility(const window& window) const;
147 
148  bool exit_hook(window& window);
149 };
150 
151 } // namespace dialogs
152 } // namespace gui2
Shows the list of addons on the server.
Definition: manager.hpp:39
config cfg_
Config which contains the list with the campaigns.
Definition: manager.hpp:81
Abstract base class for text items.
bool exit_hook(window &window)
Definition: manager.cpp:939
void load_addon_list(window &window)
Definition: manager.cpp:468
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:87
void execute_default_action_on_selected_addon(window &window)
Definition: manager.hpp:129
void update_all_addons(window &window)
Definition: manager.cpp:701
static const std::vector< std::pair< ADDON_STATUS_FILTER, std::string > > status_filter_types_
Definition: manager.hpp:89
void install_selected_addon(window &window)
Definition: manager.hpp:99
addon_list::addon_sort_func sort_func_asc
Definition: manager.hpp:54
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
void execute_action_on_selected_addon(window &window)
Definition: manager.cpp:636
boost::dynamic_bitset get_type_filter_visibility(const window &window) const
Definition: manager.cpp:573
void on_addon_select(window &window)
Definition: manager.cpp:855
bool get_need_wml_cache_refresh() const
Definition: manager.hpp:44
void reload_list_and_reselect_item(const std::string id, window &window)
Definition: manager.cpp:519
void uninstall_addon(const addon_info &addon, window &window)
Definition: manager.cpp:670
void toggle_details(button &btn, stacked_widget &stk)
Definition: manager.cpp:448
addon_list::addon_sort_func sort_func_desc
Definition: manager.hpp:55
addon_order(std::string label_, int column, addon_list::addon_sort_func sort_func_asc_, addon_list::addon_sort_func sort_func_desc_)
Definition: manager.hpp:57
void copy_url_callback(text_box &url_box)
Definition: manager.cpp:833
Add-ons (campaignd) client class.
Definition: client.hpp:29
Various uncategorised dialogs.
void delete_addon(const addon_info &addon, window &window)
Performs all backend and UI actions for taking down the specified add-on.
Definition: manager.cpp:767
void on_order_changed(window &window, unsigned int sort_column, listbox::SORT_ORDER order)
Definition: manager.cpp:623
boost::dynamic_bitset get_name_filter_visibility(const window &window) const
Definition: manager.cpp:528
void install_addon(const addon_info &addon, window &window)
Definition: manager.cpp:658
void browse_url_callback(text_box &url_box)
Definition: manager.cpp:827
addons_client & client_
Definition: manager.hpp:83
void uninstall_selected_addon(window &window)
Definition: manager.hpp:105
void execute_default_action(const addon_info &addon, window &window)
Called when the player double-clicks an add-on.
Definition: manager.cpp:793
addon_manager(addons_client &client)
Definition: manager.cpp:232
void fetch_addons_list(window &window)
Definition: manager.cpp:459
void delete_selected_addon(window &window)
Definition: manager.hpp:123
void apply_filters(window &window)
Definition: manager.cpp:599
boost::dynamic_bitset get_status_filter_visibility(const window &window) const
Definition: manager.cpp:552
static const std::vector< std::pair< ADDON_TYPE, std::string > > type_filter_types_
Definition: manager.hpp:90
void order_addons(window &window)
Definition: manager.cpp:608
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
Inherited from modal_dialog, implemented by REGISTER_DIALOG.
void publish_selected_addon(window &window)
Definition: manager.hpp:117
void on_filtertext_changed(text_box_base *textbox)
Definition: manager.cpp:242
std::vector< selectable_item * > orders_
Definition: manager.hpp:64
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
void update_selected_addon(window &window)
Definition: manager.hpp:111
void update_addon(const addon_info &addon, window &window)
Definition: manager.cpp:690
std::map< std::string, addon_info > addons_list
Definition: info.hpp:26
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: manager.cpp:302
static const std::vector< addon_order > all_orders_
Definition: manager.hpp:91
void publish_addon(const addon_info &addon, window &window)
Performs all backend and UI actions for publishing the specified add-on.
Definition: manager.cpp:718