From 8fdd6164ef20e28ab39f24799930963874455619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 8 Jul 2017 14:44:28 +0200 Subject: core: call the config hook when options are removed --- src/core/wee-command.c | 2 +- src/core/wee-config-file.c | 16 +++++++++++++--- src/core/wee-config-file.h | 3 ++- src/core/wee-config.c | 12 ++++++------ src/core/wee-proxy.c | 16 ++++++++-------- src/gui/gui-bar.c | 32 ++++++++++++++++---------------- src/plugins/plugin-api.c | 10 ++++++++++ src/plugins/plugin-api.h | 1 + src/plugins/plugin-config.c | 2 +- src/plugins/plugin.c | 2 +- 10 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 21bae289a..8378a022e 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1840,7 +1840,7 @@ COMMAND_CALLBACK(debug) ptr_option = config_weechat_debug_get (argv[2]); if (ptr_option) { - config_file_option_free (ptr_option); + config_file_option_free (ptr_option, 1); config_weechat_debug_set_all (); gui_chat_printf (NULL, _("Debug disabled for \"%s\""), argv[2]); diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index e7820efdb..30c9935ae 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -1588,7 +1588,7 @@ config_file_option_unset (struct t_config_option *option) } else { - config_file_option_free (option); + config_file_option_free (option, 0); rc = WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } @@ -2868,14 +2868,18 @@ config_file_option_free_data (struct t_config_option *option) */ void -config_file_option_free (struct t_config_option *option) +config_file_option_free (struct t_config_option *option, int run_callback) { struct t_config_section *ptr_section; struct t_config_option *new_options; + char *option_full_name; if (!option) return; + option_full_name = (run_callback) ? + config_file_option_full_name (option) : NULL; + ptr_section = option->section; /* free data */ @@ -2899,6 +2903,12 @@ config_file_option_free (struct t_config_option *option) } free (option); + + if (option_full_name) + { + hook_config_exec (option_full_name, NULL); + free (option_full_name); + } } /* @@ -2913,7 +2923,7 @@ config_file_section_free_options (struct t_config_section *section) while (section->options) { - config_file_option_free (section->options); + config_file_option_free (section->options, 0); } } diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index 10b635e44..a310b353b 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -287,7 +287,8 @@ extern int config_file_write_line (struct t_config_file *config_file, extern int config_file_write (struct t_config_file *config_files); extern int config_file_read (struct t_config_file *config_file); extern int config_file_reload (struct t_config_file *config_file); -extern void config_file_option_free (struct t_config_option *option); +extern void config_file_option_free (struct t_config_option *option, + int run_callback); extern void config_file_section_free_options (struct t_config_section *section); extern void config_file_section_free (struct t_config_section *section); extern void config_file_free (struct t_config_file *config_file); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 3589a042a..850831171 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -1466,7 +1466,7 @@ config_weechat_debug_create_option_cb (const void *pointer, void *data, rc = config_file_option_set (ptr_option, value, 1); else { - config_file_option_free (ptr_option); + config_file_option_free (ptr_option, 1); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } @@ -1512,7 +1512,7 @@ config_weechat_debug_delete_option_cb (const void *pointer, void *data, (void) config_file; (void) section; - config_file_option_free (option); + config_file_option_free (option, 1); config_weechat_debug_set_all (); @@ -1592,7 +1592,7 @@ config_weechat_palette_create_option_cb (const void *pointer, void *data, rc = config_file_option_set (ptr_option, value, 1); else { - config_file_option_free (ptr_option); + config_file_option_free (ptr_option, 1); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } @@ -1652,7 +1652,7 @@ config_weechat_palette_delete_option_cb (const void *pointer, void *data, if (error && !error[0]) gui_color_palette_remove (number); - config_file_option_free (option); + config_file_option_free (option, 1); return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } @@ -2088,7 +2088,7 @@ config_weechat_notify_create_option_cb (const void *pointer, void *data, rc = config_file_option_set (ptr_option, value, 1); else { - config_file_option_free (ptr_option); + config_file_option_free (ptr_option, 1); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } @@ -2134,7 +2134,7 @@ config_weechat_notify_delete_option_cb (const void *pointer, void *data, (void) config_file; (void) section; - config_file_option_free (option); + config_file_option_free (option, 1); gui_buffer_notify_set_all (); diff --git a/src/core/wee-proxy.c b/src/core/wee-proxy.c index 2bb1b1880..3b5f311c4 100644 --- a/src/core/wee-proxy.c +++ b/src/core/wee-proxy.c @@ -458,17 +458,17 @@ proxy_new (const char *name, const char *type, const char *ipv6, if (!new_proxy) { if (option_type) - config_file_option_free (option_type); + config_file_option_free (option_type, 0); if (option_ipv6) - config_file_option_free (option_ipv6); + config_file_option_free (option_ipv6, 0); if (option_address) - config_file_option_free (option_address); + config_file_option_free (option_address, 0); if (option_port) - config_file_option_free (option_port); + config_file_option_free (option_port, 0); if (option_username) - config_file_option_free (option_username); + config_file_option_free (option_username, 0); if (option_password) - config_file_option_free (option_password); + config_file_option_free (option_password, 0); } return new_proxy; @@ -516,7 +516,7 @@ proxy_use_temp_proxies () { if (ptr_temp_proxy->options[i]) { - config_file_option_free (ptr_temp_proxy->options[i]); + config_file_option_free (ptr_temp_proxy->options[i], 0); ptr_temp_proxy->options[i] = NULL; } } @@ -564,7 +564,7 @@ proxy_free (struct t_proxy *proxy) free (proxy->name); for (i = 0; i < PROXY_NUM_OPTIONS; i++) { - config_file_option_free (proxy->options[i]); + config_file_option_free (proxy->options[i], 1); } free (proxy); diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index c2b3c2dfc..26f7cd41e 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -1708,33 +1708,33 @@ gui_bar_new (const char *name, const char *hidden, const char *priority, if (!new_bar) { if (option_hidden) - config_file_option_free (option_hidden); + config_file_option_free (option_hidden, 0); if (option_priority) - config_file_option_free (option_priority); + config_file_option_free (option_priority, 0); if (option_type) - config_file_option_free (option_type); + config_file_option_free (option_type, 0); if (option_conditions) - config_file_option_free (option_conditions); + config_file_option_free (option_conditions, 0); if (option_position) - config_file_option_free (option_position); + config_file_option_free (option_position, 0); if (option_filling_top_bottom) - config_file_option_free (option_filling_top_bottom); + config_file_option_free (option_filling_top_bottom, 0); if (option_filling_left_right) - config_file_option_free (option_filling_left_right); + config_file_option_free (option_filling_left_right, 0); if (option_size) - config_file_option_free (option_size); + config_file_option_free (option_size, 0); if (option_size_max) - config_file_option_free (option_size_max); + config_file_option_free (option_size_max, 0); if (option_color_fg) - config_file_option_free (option_color_fg); + config_file_option_free (option_color_fg, 0); if (option_color_delim) - config_file_option_free (option_color_delim); + config_file_option_free (option_color_delim, 0); if (option_color_bg) - config_file_option_free (option_color_bg); + config_file_option_free (option_color_bg, 0); if (option_separator) - config_file_option_free (option_separator); + config_file_option_free (option_separator, 0); if (option_items) - config_file_option_free (option_items); + config_file_option_free (option_items, 0); } return new_bar; @@ -1790,7 +1790,7 @@ gui_bar_use_temp_bars () { if (ptr_temp_bar->options[i]) { - config_file_option_free (ptr_temp_bar->options[i]); + config_file_option_free (ptr_temp_bar->options[i], 0); ptr_temp_bar->options[i] = NULL; } } @@ -2171,7 +2171,7 @@ gui_bar_free (struct t_gui_bar *bar) for (i = 0; i < GUI_BAR_NUM_OPTIONS; i++) { if (bar->options[i]) - config_file_option_free (bar->options[i]); + config_file_option_free (bar->options[i], 1); } gui_bar_free_items_arrays (bar); diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index f5958a4af..370b7fd41 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -107,6 +107,16 @@ plugin_api_ngettext (const char *single, const char *plural, int count) return NG_(single, plural, count); } +/* + * Frees an option. + */ + +void +plugin_api_config_file_option_free (struct t_config_option *option) +{ + config_file_option_free (option, 1); +} + /* * Gets pointer on an option. */ diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index e7f8f1ca2..90a19733e 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -30,6 +30,7 @@ extern const char *plugin_api_ngettext (const char *single, const char *plural, int count); /* config */ +extern void plugin_api_config_file_option_free (struct t_config_option *option); extern struct t_config_option *plugin_api_config_get (const char *option_name); extern const char *plugin_api_config_get_plugin (struct t_weechat_plugin *plugin, const char *option_name); diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index 9f2710678..cb37c64f1 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -335,7 +335,7 @@ plugin_config_delete_desc (const void *pointer, void *data, } } - config_file_option_free (option); + config_file_option_free (option, 1); return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 509f8d963..c0aabd180 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -745,7 +745,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->config_write = &config_file_write; new_plugin->config_read = &config_file_read; new_plugin->config_reload = &config_file_reload; - new_plugin->config_option_free = &config_file_option_free; + new_plugin->config_option_free = &plugin_api_config_file_option_free; new_plugin->config_section_free_options = &config_file_section_free_options; new_plugin->config_section_free = &config_file_section_free; new_plugin->config_free = &config_file_free; -- cgit v1.2.3