Skip to content

Commit

Permalink
Addons Manager: only reload cache if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 18, 2017
1 parent b11ff96 commit 1c4102a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/addon/manager_ui.cpp
Expand Up @@ -782,7 +782,7 @@ bool addons_manager_ui(CVideo& v, const std::string& remote_address)
//if(gui2::new_widgets) {
gui2::dialogs::addon_manager dlg(client);
dlg.show(v);
return true;
return dlg.get_need_wml_cache_refresh_();
//}

if(!get_addons_list(client, addons)) {
Expand Down
14 changes: 11 additions & 3 deletions src/gui/dialogs/addon/manager.cpp
Expand Up @@ -217,6 +217,7 @@ addon_manager::addon_manager(addons_client& client)
, client_(client)
, addons_()
, tracking_info_()
, need_wml_cache_refresh_(false)
{
status_filter_types_ = {
{FILTER_ALL, _("addons_view^All Add-ons")},
Expand Down Expand Up @@ -420,7 +421,9 @@ void addon_manager::pre_show(window& window)

void addon_manager::load_addon_list(window& window)
{
refresh_addon_version_info_cache();
if(need_wml_cache_refresh_) {
refresh_addon_version_info_cache();
}

client_.request_addons_list(cfg_);
if(!cfg_) {
Expand Down Expand Up @@ -514,10 +517,13 @@ void addon_manager::install_addon(addon_info addon, window& window)
{
addon_list& addons = find_widget<addon_list>(&window, "addons", false);

addons_client::install_result result =
client_.install_addon_with_checks(addons_, addon);
addons_client::install_result result = client_.install_addon_with_checks(addons_, addon);

need_wml_cache_refresh_ |= result.wml_changed; // take note if any wml_changes occurred

if(result.outcome != addons_client::install_outcome::abort) {
need_wml_cache_refresh_ = true;

load_addon_list(window);

// Reselect the add-on.
Expand Down Expand Up @@ -554,6 +560,8 @@ void addon_manager::uninstall_addon(addon_info addon, window& window)
if(!success) {
show_error_message(window.video(), _("The following add-on could not be deleted properly:") + " " + addon.display_title());
} else {
need_wml_cache_refresh_ = true;

load_addon_list(window);

// Reselect the add-on.
Expand Down
7 changes: 7 additions & 0 deletions src/gui/dialogs/addon/manager.hpp
Expand Up @@ -38,6 +38,11 @@ class addon_manager : public modal_dialog
public:
explicit addon_manager(addons_client& client);

bool get_need_wml_cache_refresh_() const
{
return need_wml_cache_refresh_;
}

private:
void on_filtertext_changed(text_box_base* textbox, const std::string& text);

Expand Down Expand Up @@ -65,6 +70,8 @@ class addon_manager : public modal_dialog
std::vector<std::pair<ADDON_STATUS_FILTER, std::string>> status_filter_types_;
std::vector<std::pair<ADDON_TYPE, std::string>> type_filter_types_;

bool need_wml_cache_refresh_;

void install_selected_addon(window& window);
void install_addon(addon_info addon, window& window);

Expand Down

0 comments on commit 1c4102a

Please sign in to comment.