Add ability to update individual add-ons

Instead of updating them all at once.
This commit is contained in:
Jyrki Vesterinen 2017-03-09 20:34:45 +02:00
parent ab6e245b7d
commit 0c6619905a
4 changed files with 47 additions and 1 deletions

View File

@ -335,6 +335,8 @@ void addon_manager::pre_show(window& window)
this, std::placeholders::_1, std::ref(window)));
list.set_uninstall_function(std::bind(&addon_manager::uninstall_addon,
this, std::placeholders::_1, std::ref(window)));
list.set_update_function(std::bind(&addon_manager::update_addon,
this, std::placeholders::_1, std::ref(window)));
list.set_publish_function(std::bind(&addon_manager::publish_addon,
this, std::placeholders::_1, std::ref(window)));
@ -589,6 +591,24 @@ void addon_manager::uninstall_addon(const addon_info& addon, window& window)
}
}
void addon_manager::update_addon(const addon_info& addon, window& window)
{
addon_list& addons = find_widget<addon_list>(&window, "addons", false);
const std::string id = addon.id;
addons_client::install_result result = client_.install_addon_with_checks(addons_, addon);
if(result.outcome != addons_client::install_outcome::abort) {
need_wml_cache_refresh_ = true;
load_addon_list(window);
// Reselect the add-on.
addons.select_addon(id);
on_addon_select(window);
}
}
void addon_manager::update_all_addons(window& window)
{
for(const auto& a : addons_) {

View File

@ -89,6 +89,12 @@ private:
execute_action_on_selected_addon<&addon_manager::uninstall_addon>(window);
}
void update_addon(const addon_info& addon, window& window);
void update_selected_addon(window& window)
{
execute_action_on_selected_addon<&addon_manager::update_addon>(window);
}
void publish_addon(const addon_info& addon, window& window);
void publish_selected_addon(window& window)
{

View File

@ -172,7 +172,8 @@ void addon_list::set_addons(const addons_list& addons)
if(!tracking_info.can_publish) {
const bool is_updatable = tracking_info.state == ADDON_INSTALLED_UPGRADABLE;
const bool is_installed = tracking_info.state == ADDON_INSTALLED;
const bool is_installed =
tracking_info.state == ADDON_INSTALLED || tracking_info.state == ADDON_INSTALLED_UPGRADABLE;
install_update_stack.select_layer(static_cast<int>(is_updatable));
@ -188,6 +189,18 @@ void addon_list::set_addons(const addons_list& addons)
halt = true;
});
}
} else {
find_widget<button>(row_grid, "single_update", false).set_active(true);
if(update_function_ != nullptr) {
gui2::event::connect_signal_mouse_left_click(
find_widget<button>(row_grid, "single_update", false),
[this, addon](gui2::event::dispatcher&, const gui2::event::ui_event, bool& handled, bool& halt)
{
update_function_(addon);
handled = true;
halt = true;
});
}
}
if(is_installed) {

View File

@ -83,6 +83,12 @@ public:
uninstall_function_ = function;
}
/** Sets the function to call when the player clicks the update button. */
void set_update_function(std::function<void(const addon_info&)> function)
{
update_function_ = function;
}
/** Sets the function to upload an addon to the addons server. */
void set_publish_function(std::function<void(const addon_info&)> function)
{
@ -145,6 +151,7 @@ private:
std::function<void(const addon_info&)> install_function_;
std::function<void(const addon_info&)> uninstall_function_;
std::function<void(const addon_info&)> update_function_;
std::function<void(const addon_info&)> publish_function_;
std::function<void(const addon_info&)> delete_function_;