diff --git a/changelog b/changelog index f857175605ff..15109049cd77 100644 --- a/changelog +++ b/changelog @@ -75,6 +75,7 @@ Version 1.13.0-dev: * Fixed most of the minimap buttons and the End Turn button appearing without contents or in the wrong state during WML start events until they are interacted with or control is given to the player for the first time. + * Added a new subdialog in Preferences to clean or purge the WML cache. * WML engine: * Added customizable recall costs for unit types and individual units, using the new recall_cost attribute in [unit_type] and [unit]. diff --git a/data/gui/default/window/game_cache_options.cfg b/data/gui/default/window/game_cache_options.cfg new file mode 100644 index 000000000000..963814ec8e60 --- /dev/null +++ b/data/gui/default/window/game_cache_options.cfg @@ -0,0 +1,267 @@ +#textdomain wesnoth-lib + +[window] + id = "game_cache_options" + description = "Game data cache management dialog." + + [resolution] + definition = "default" + + click_dismiss = "true" + maximum_width = 600 + + [tooltip] + id = "tooltip_large" + [/tooltip] + + [helptip] + id = "tooltip_large" + [/helptip] + + [grid] + + [row] + grow_factor = 0 + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + [label] + id = "title" + definition = "title" + + label = _ "WML Cache" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "left" + [label] + definition = "default" + + label = _ "Wesnoth maintains a cache of preprocessed WML data for campaigns, multiplayer scenarios, and other add-ons to speed up the loading process. The cache may be safely cleaned to free up disk space, thus removing stale files generated by older versions; or you may purge its entire contents if you are experiencing issues when loading the game data." + wrap = "true" + [/label] + + [/column] + + [/row] + + [row] + grow_factor = 1 + + [column] + horizontal_grow = "true" + + [grid] + + [row] + + [column] + grow_factor = 0 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + definition = "default" + + label = _ "Path:" + [/label] + + [/column] + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_grow = "true" + + [text_box] + id = "path" + definition = "default" + label = "" + [/text_box] + + [/column] + + [column] + grow_factor = 0 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [button] + id = "copy" + definition = "action_copy" + label = _ "filesystem^Copy" + tooltip = _ "Copy this path to clipboard" + [/button] + + [/column] + + [column] + grow_factor = 0 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [button] + id = "browse" + definition = "action_go" + label = _ "filesystem^Browse" + tooltip = _ "Browse this location using a file manager" + [/button] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + [row] + grow_factor = 1 + + [column] + horizontal_grow = "true" + + [grid] + + [row] + + [column] + grow_factor = 0 + + border = "all" + border_size = 5 + horizontal_alignment = "left" + + [label] + definition = "default" + + label = _ "Size:" + [/label] + + [/column] + + [column] + grow_factor = 1 + + border = "all" + border_size = 5 + horizontal_grow = "true" + + [label] + definition = "default" + + id = "size" + label = "" + [/label] + + [/column] + + [column] + horizontal_alignment = "right" + + [grid] + + [row] + + [column] + border = "all" + border_size = 5 + + [button] + id = "clean" + definition = "default" + label = _ "cache^Clean" + tooltip = _ "Clear stale and unused cache files" + [/button] + + [/column] + + [column] + border = "all" + border_size = 5 + + [button] + id = "purge" + definition = "default" + label = _ "cache^Purge" + tooltip = _ "Purge the entire contents of the cache" + [/button] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + [row] + grow_factor = 0 + + [column] + horizontal_alignment = "right" + + [grid] + + [row] + grow_factor = 0 + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [button] + id = "ok" + definition = "default" + + label = _ "OK" + [/button] + + [/column] + + [/row] + + [/grid] + + [/column] + + [/row] + + + [/grid] + + [/resolution] + +[/window] diff --git a/players_changelog b/players_changelog index faf4fd8a1510..7edbe29c77a9 100644 --- a/players_changelog +++ b/players_changelog @@ -22,6 +22,7 @@ Version 1.13.0-dev: * Fixed most of the minimap buttons and the End Turn button appearing without contents or in the wrong state during WML start events until they are interacted with or control is given to the player for the first time. + * Added a new subdialog in Preferences to clean or purge the WML cache. * Miscellaneous and bug fixes: * Fixed halos glitching through locations that become shrouded after the diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b790241d91c..bcc6f3847388 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -784,6 +784,7 @@ set(wesnoth-main_SRC gui/dialogs/editor_set_starting_position.cpp gui/dialogs/folder_create.cpp gui/dialogs/formula_debugger.cpp + gui/dialogs/game_cache_options.cpp gui/dialogs/game_delete.cpp gui/dialogs/game_load.cpp gui/dialogs/game_paths.cpp diff --git a/src/SConscript b/src/SConscript index e3feffe61107..4ad80e33370d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -379,6 +379,7 @@ wesnoth_sources = Split(""" gui/dialogs/editor_set_starting_position.cpp gui/dialogs/folder_create.cpp gui/dialogs/formula_debugger.cpp + gui/dialogs/game_cache_options.cpp gui/dialogs/game_delete.cpp gui/dialogs/game_load.cpp gui/dialogs/game_paths.cpp diff --git a/src/game_preferences_display.cpp b/src/game_preferences_display.cpp index b349a790a0d0..9562544d7f49 100644 --- a/src/game_preferences_display.cpp +++ b/src/game_preferences_display.cpp @@ -20,6 +20,7 @@ #include "filechooser.hpp" #include "game_preferences.hpp" #include "gettext.hpp" +#include "gui/dialogs/game_cache_options.hpp" #include "gui/dialogs/game_paths.hpp" #include "gui/dialogs/simple_item_selector.hpp" #include "gui/dialogs/theme_list.hpp" @@ -129,6 +130,7 @@ class preferences_dialog : public gui::preview_pane show_haloing_button_, video_mode_button_, theme_button_, hotkeys_button_, paths_button_, colors_button_, + cache_button_, advanced_button_, sound_button_, music_button_, chat_timestamp_button_, advanced_sound_button_, normal_sound_button_, @@ -222,6 +224,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg) hotkeys_button_(disp.video(), _("Hotkeys")), paths_button_(disp.video(), _("Paths")), colors_button_(disp.video(), _("Colors")), + cache_button_(disp.video(), _("Cache")), advanced_button_(disp.video(), "", gui::button::TYPE_CHECK), sound_button_(disp.video(), _("Sound effects"), gui::button::TYPE_CHECK), music_button_(disp.video(), _("Music"), gui::button::TYPE_CHECK), @@ -509,6 +512,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg) hotkeys_button_.set_help_string(_("View and configure keyboard shortcuts")); paths_button_.set_help_string(_("View game file paths")); colors_button_.set_help_string(_("Adjust orb colors")); + cache_button_.set_help_string(_("Manage the game WML cache")); set_advanced_menu(); set_friends_menu(); @@ -565,6 +569,7 @@ handler_vector preferences_dialog::handler_members() h.push_back(&hotkeys_button_); h.push_back(&paths_button_); h.push_back(&colors_button_); + h.push_back(&cache_button_); h.push_back(&advanced_button_); h.push_back(&sound_button_); h.push_back(&music_button_); @@ -659,6 +664,7 @@ void preferences_dialog::update_location(SDL_Rect const &rect) autosavemax_slider_.set_location(autosavemax_rect); hotkeys_button_.set_location(rect.x, bottom_row_y - hotkeys_button_.height()); paths_button_.set_location(rect.x + hotkeys_button_.width() + 10, bottom_row_y - paths_button_.height()); + cache_button_.set_location(paths_button_.location().x + paths_button_.width() + 10, bottom_row_y - cache_button_.height()); // Display tab ypos = rect.y + top_border; @@ -918,6 +924,10 @@ void preferences_dialog::process_event() show_paths_dialog(disp_); parent->clear_buttons(); } + if (cache_button_.pressed()) { + gui2::tgame_cache_options::display(disp_.video()); + parent->clear_buttons(); + } set_scroll_speed(scroll_slider_.value()); set_autosavemax(autosavemax_slider_.value()); @@ -1543,6 +1553,7 @@ void preferences_dialog::set_selection(int index) interrupt_when_ally_sighted_button_.hide(hide_general); hotkeys_button_.hide(hide_general); paths_button_.hide(hide_general); + cache_button_.hide(hide_general); save_replays_button_.hide(hide_general); delete_saves_button_.hide(hide_general); autosavemax_slider_label_.hide(hide_general); diff --git a/src/gui/dialogs/game_cache_options.cpp b/src/gui/dialogs/game_cache_options.cpp new file mode 100644 index 000000000000..a9f7a4e185d8 --- /dev/null +++ b/src/gui/dialogs/game_cache_options.cpp @@ -0,0 +1,155 @@ +/* + Copyright (C) 2014 by Ignacio Riquelme Morelle + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "gui/dialogs/game_cache_options.hpp" + +#include "clipboard.hpp" +#include "config_cache.hpp" +#include "desktop_util.hpp" +#include "filesystem.hpp" +#include "gui/auxiliary/find_widget.tpp" +#include "gui/dialogs/message.hpp" +#include "gui/widgets/button.hpp" +#include "gui/widgets/label.hpp" +#include "gui/widgets/settings.hpp" +#include "gui/widgets/text_box.hpp" +#include "gui/widgets/window.hpp" + +#include + +#include "gettext.hpp" + +namespace gui2 +{ + +// TODO: wikidoc! + +REGISTER_DIALOG(game_cache_options) + +tgame_cache_options::tgame_cache_options() + : cache_path_(get_cache_dir()) + , size_label_(NULL) +{ +} + +void tgame_cache_options::pre_show(CVideo& video, twindow& window) +{ + size_label_ = &find_widget(&window, "size", false); + update_cache_size_display(); + + ttext_& path_box = find_widget(&window, "path", false); + path_box.set_value(cache_path_); + path_box.set_active(false); + + tbutton& copy = find_widget(&window, "copy", false); + connect_signal_mouse_left_click(copy, + boost::bind(&tgame_cache_options::copy_to_clipboard_callback, + this)); + + tbutton& browse = find_widget(&window, "browse", false); + connect_signal_mouse_left_click(browse, + boost::bind(&tgame_cache_options::browse_cache_callback, + this)); + + tbutton& clean = find_widget(&window, "clean", false); + connect_signal_mouse_left_click(clean, + boost::bind(&tgame_cache_options::clean_cache_callback, + this, + boost::ref(video))); + + tbutton& purge = find_widget(&window, "purge", false); + connect_signal_mouse_left_click(purge, + boost::bind(&tgame_cache_options::purge_cache_callback, + this, + boost::ref(video))); +} + +void tgame_cache_options::post_show(twindow& /*window*/) +{ + size_label_ = NULL; +} + +void tgame_cache_options::update_cache_size_display() +{ + if(!size_label_) { + return; + } + + size_label_->set_label(utils::si_string(dir_size(cache_path_), + true, + _("unit_byte^B"))); +} + +void tgame_cache_options::copy_to_clipboard_callback() +{ + copy_to_clipboard(cache_path_, false); +} + +void tgame_cache_options::browse_cache_callback() +{ + desktop::open_object(cache_path_); +} + +void tgame_cache_options::clean_cache_callback(CVideo& video) +{ + if(clean_cache()) { + show_message(video, + _("Cache Cleaned"), + _("The game data cache has been cleaned.")); + } else { + show_error_message(video, + _("The game data cache could not be completely cleaned.")); + } + + update_cache_size_display(); +} + +bool tgame_cache_options::clean_cache() +{ + return game_config::config_cache::instance().clean_cache(); +} + +void tgame_cache_options::purge_cache_callback(CVideo& video) +{ + if(show_message(video, + _("Purge Cache"), + _("Are you sure you want to purge the game data cache? " + "All files in the cache directory will be deleted, and " + "the cache will be regenerated next time it is " + "required."), + gui2::tmessage::yes_no_buttons) != gui2::twindow::OK) + { + return; + } + + if(purge_cache()) { + show_message(video, + _("Cache Purged"), + _("The game data cache has been purged.")); + } else { + show_error_message(video, + _("The game data cache could not be purged.")); + } + + update_cache_size_display(); +} + +bool tgame_cache_options::purge_cache() +{ + return game_config::config_cache::instance().purge_cache(); +} + +} // end namespace gui2 diff --git a/src/gui/dialogs/game_cache_options.hpp b/src/gui/dialogs/game_cache_options.hpp new file mode 100644 index 000000000000..62624c2d4d15 --- /dev/null +++ b/src/gui/dialogs/game_cache_options.hpp @@ -0,0 +1,68 @@ +/* + Copyright (C) 2014 by Ignacio Riquelme Morelle + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#ifndef GUI_DIALOGS_GAME_CACHE_OPTIONS_HPP_INCLUDED +#define GUI_DIALOGS_GAME_CACHE_OPTIONS_HPP_INCLUDED + +#include "gui/dialogs/dialog.hpp" + +namespace gui2 +{ +class tlabel; + +class tgame_cache_options : public tdialog +{ +public: + /** Constructor. */ + tgame_cache_options(); + + /** + * The display function. + * + * See @ref tdialog for more information. + */ + static void display(CVideo& video) + { + tgame_cache_options().show(video); + } + +private: + std::string cache_path_; + tlabel* size_label_; + + void clean_cache_callback(CVideo& video); + bool clean_cache(); + + void purge_cache_callback(CVideo& video); + bool purge_cache(); + + void copy_to_clipboard_callback(); + + void browse_cache_callback(); + + void update_cache_size_display(); + + /** Inherited from tdialog, implemented by REGISTER_DIALOG. */ + virtual const std::string& window_id() const; + + /** Inherited from tdialog. */ + void pre_show(CVideo& video, twindow& window); + + /** Inherited from tdialog. */ + void post_show(twindow& window); +}; + +} + +#endif