diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-08-05 23:15:23 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-08-05 23:15:23 +0200 |
commit | 8d2c23209fe115fb7b7829437406c24f50ac0ec2 (patch) | |
tree | a8b0848801b889c676095178ba8680a4b30b36ea | |
parent | 4919a943fdb1b6137aeda9e040782e2cf9a718f4 (diff) | |
download | weechat-8d2c23209fe115fb7b7829437406c24f50ac0ec2.zip |
core: save and restore layout for buffers and windows on /upgrade
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/core/wee-command.c | 10 | ||||
-rw-r--r-- | src/core/wee-completion.c | 2 | ||||
-rw-r--r-- | src/core/wee-config.c | 2 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 140 | ||||
-rw-r--r-- | src/core/wee-upgrade.h | 3 | ||||
-rw-r--r-- | src/core/weechat.c | 3 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 1 | ||||
-rw-r--r-- | src/gui/gui-bar-item.c | 2 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 88 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 7 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 4 | ||||
-rw-r--r-- | src/gui/gui-filter.c | 3 | ||||
-rw-r--r-- | src/gui/gui-hotlist.c | 2 | ||||
-rw-r--r-- | src/gui/gui-layout.c | 144 | ||||
-rw-r--r-- | src/gui/gui-layout.h | 7 | ||||
-rw-r--r-- | src/gui/gui-line.c | 6 | ||||
-rw-r--r-- | src/gui/gui-window.c | 3 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 2 |
19 files changed, 300 insertions, 130 deletions
@@ -7,6 +7,7 @@ v0.3.6-dev, 2011-08-05 Version 0.3.6 (under dev!) -------------------------- +* core: save and restore layout for buffers and windows on /upgrade * core: fix bugs with automatic layout (bug #26110), add support of merged buffers in layout (task #10893) * core: add option -all for command /buffer unmerge diff --git a/src/core/wee-command.c b/src/core/wee-command.c index a20f62dc0..352fe0bb9 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -531,7 +531,7 @@ COMMAND_CALLBACK(buffer) ptr_buffer->number, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), - plugin_get_name (ptr_buffer->plugin), + gui_buffer_get_plugin_name (ptr_buffer), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), ptr_buffer->name, GUI_COLOR(GUI_COLOR_CHAT), @@ -819,7 +819,7 @@ COMMAND_CALLBACK(buffer) { gui_chat_printf (NULL, "%s%s.%s%s: (int) %s = %d", GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name, GUI_COLOR(GUI_COLOR_CHAT), argv[2], @@ -830,7 +830,7 @@ COMMAND_CALLBACK(buffer) { gui_chat_printf (NULL, "%s%s.%s%s: (str) %s = %s", GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name, GUI_COLOR(GUI_COLOR_CHAT), argv[2], @@ -841,7 +841,7 @@ COMMAND_CALLBACK(buffer) { gui_chat_printf (NULL, "%s%s.%s%s: (ptr) %s = 0x%lx", GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name, GUI_COLOR(GUI_COLOR_CHAT), argv[2], @@ -4693,7 +4693,7 @@ COMMAND_CALLBACK(wait) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - timer_args[0] = strdup (plugin_get_name (buffer->plugin)); + timer_args[0] = strdup (gui_buffer_get_plugin_name (buffer)); timer_args[1] = strdup (buffer->name); timer_args[2] = strdup (argv_eol[2]); diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index 15ccc05e5..8cc3c974e 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -185,7 +185,7 @@ completion_list_add_buffers_plugins_names_cb (void *data, ptr_buffer = ptr_buffer->next_buffer) { snprintf (name, sizeof (name), "%s.%s", - plugin_get_name (ptr_buffer->plugin), + gui_buffer_get_plugin_name (ptr_buffer), ptr_buffer->name); gui_completion_list_add (completion, name, 0, WEECHAT_LIST_POS_SORT); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index cd4654027..690e7dfab 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -1340,7 +1340,7 @@ config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify) if ((value < 0) && (strcmp (notify, "reset") != 0)) return 0; - plugin_name = plugin_get_name (buffer->plugin); + plugin_name = gui_buffer_get_plugin_name (buffer); length = strlen (plugin_name) + 1 + strlen (buffer->name) + 1; option_name = malloc (length); if (option_name) diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index bfc19f01c..d58ef0652 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -42,6 +42,7 @@ #include "../gui/gui-color.h" #include "../gui/gui-history.h" #include "../gui/gui-hotlist.h" +#include "../gui/gui-layout.h" #include "../gui/gui-line.h" #include "../gui/gui-nicklist.h" #include "../gui/gui-window.h" @@ -50,8 +51,11 @@ struct t_gui_buffer *upgrade_current_buffer = NULL; struct t_gui_buffer *upgrade_set_current_buffer = NULL; -int upgrade_last_buffer_number = 1; +int upgrade_set_current_window = 0; int hotlist_reset = 0; +struct t_gui_layout_buffer *upgrade_layout_buffers = NULL; +struct t_gui_layout_buffer *last_upgrade_layout_buffer = NULL; +struct t_gui_layout_window *upgrade_layout_windows = NULL; /* @@ -190,11 +194,11 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) } /* - * upgrade_weechat_save_uptime: save uptime info to upgrade file + * upgrade_weechat_save_misc: save miscellaneous info to upgrade file */ int -upgrade_weechat_save_uptime (struct t_upgrade_file *upgrade_file) +upgrade_weechat_save_misc (struct t_upgrade_file *upgrade_file) { struct t_infolist *ptr_infolist; struct t_infolist_item *ptr_item; @@ -220,9 +224,14 @@ upgrade_weechat_save_uptime (struct t_upgrade_file *upgrade_file) infolist_free (ptr_infolist); return 0; } + if (!infolist_new_var_integer (ptr_item, "current_window_number", gui_current_window->number)) + { + infolist_free (ptr_infolist); + return 0; + } rc = upgrade_file_write_object (upgrade_file, - UPGRADE_WEECHAT_TYPE_UPTIME, + UPGRADE_WEECHAT_TYPE_MISC, ptr_infolist); infolist_free (ptr_infolist); @@ -263,6 +272,75 @@ upgrade_weechat_save_hotlist (struct t_upgrade_file *upgrade_file) } /* + * upgrade_weechat_save_layout_window_tree: save tree with layout for windows + * to upgrade file + */ + +int +upgrade_weechat_save_layout_window_tree (struct t_upgrade_file *upgrade_file, + struct t_gui_layout_window *layout_window) +{ + struct t_infolist *ptr_infolist; + int rc; + + ptr_infolist = infolist_new (); + if (!ptr_infolist) + return 0; + + if (!gui_layout_window_add_to_infolist (ptr_infolist, layout_window)) + { + infolist_free (ptr_infolist); + return 0; + } + + rc = upgrade_file_write_object (upgrade_file, + UPGRADE_WEECHAT_TYPE_LAYOUT_WINDOW, + ptr_infolist); + + infolist_free (ptr_infolist); + if (!rc) + return 0; + + if (layout_window->child1) + { + if (!upgrade_weechat_save_layout_window_tree (upgrade_file, + layout_window->child1)) + return 0; + } + + if (layout_window->child2) + { + if (!upgrade_weechat_save_layout_window_tree (upgrade_file, + layout_window->child2)) + return 0; + } + + return 1; +} + +/* + * upgrade_weechat_save_layout_window: save layout for windows to upgrade file + */ + +int +upgrade_weechat_save_layout_window (struct t_upgrade_file *upgrade_file) +{ + struct t_gui_layout_window *layout_windows; + int rc; + + /* get current layout for windows */ + layout_windows = NULL; + gui_layout_window_save (&layout_windows); + + /* save tree with layout of windows */ + rc = upgrade_weechat_save_layout_window_tree (upgrade_file, layout_windows); + + gui_layout_window_remove_all (&layout_windows); + + return rc; +} + +/* * upgrade_weechat_save: save upgrade file * return 1 if ok, 0 if error */ @@ -280,8 +358,9 @@ upgrade_weechat_save () rc = 1; rc &= upgrade_weechat_save_history (upgrade_file, last_history_global); rc &= upgrade_weechat_save_buffers (upgrade_file); - rc &= upgrade_weechat_save_uptime (upgrade_file); + rc &= upgrade_weechat_save_misc (upgrade_file); rc &= upgrade_weechat_save_hotlist (upgrade_file); + rc &= upgrade_weechat_save_layout_window (upgrade_file); upgrade_file_close (upgrade_file); @@ -302,7 +381,7 @@ upgrade_weechat_read_cb (void *data, const char *buffer_name; char option_name[64], *option_key, *option_var; struct t_gui_nick_group *ptr_group; - struct t_gui_buffer *ptr_buffer, *ptr_buffer_for_merge; + struct t_gui_buffer *ptr_buffer; struct t_gui_line *new_line; struct t_gui_hotlist *new_hotlist; struct timeval creation_time; @@ -332,6 +411,10 @@ upgrade_weechat_read_cb (void *data, case UPGRADE_WEECHAT_TYPE_BUFFER: plugin_name = infolist_string (infolist, "plugin_name"); name = infolist_string (infolist, "name"); + gui_layout_buffer_add (&upgrade_layout_buffers, + &last_upgrade_layout_buffer, + plugin_name, name, + infolist_integer (infolist, "number")); if (gui_buffer_is_main (plugin_name, name)) { /* use WeeChat main buffer */ @@ -343,7 +426,6 @@ upgrade_weechat_read_cb (void *data, * create buffer if it was created by a plugin (ie not * WeeChat main buffer) */ - ptr_buffer_for_merge = last_gui_buffer; upgrade_current_buffer = gui_buffer_new ( NULL, infolist_string (infolist, "name"), @@ -355,10 +437,6 @@ upgrade_weechat_read_cb (void *data, upgrade_set_current_buffer = upgrade_current_buffer; upgrade_current_buffer->plugin_name_for_upgrade = strdup (infolist_string (infolist, "plugin_name")); - upgrade_current_buffer->merge_for_upgrade = NULL; - if (infolist_integer (infolist, "number") == upgrade_last_buffer_number) - upgrade_current_buffer->merge_for_upgrade = ptr_buffer_for_merge; - upgrade_last_buffer_number = infolist_integer (infolist, "number"); upgrade_current_buffer->short_name = (infolist_string (infolist, "short_name")) ? strdup (infolist_string (infolist, "short_name")) : @@ -544,9 +622,10 @@ upgrade_weechat_read_cb (void *data, } } break; - case UPGRADE_WEECHAT_TYPE_UPTIME: + case UPGRADE_WEECHAT_TYPE_MISC: weechat_first_start_time = infolist_time (infolist, "start_time"); weechat_upgrade_count = infolist_integer (infolist, "upgrade_count"); + upgrade_set_current_window = infolist_integer (infolist, "current_window_number"); break; case UPGRADE_WEECHAT_TYPE_HOTLIST: if (!hotlist_reset) @@ -583,6 +662,16 @@ upgrade_weechat_read_cb (void *data, } } break; + case UPGRADE_WEECHAT_TYPE_LAYOUT_WINDOW: + gui_layout_window_add (&upgrade_layout_windows, + infolist_integer (infolist, "internal_id"), + gui_layout_window_search_by_id (upgrade_layout_windows, + infolist_integer (infolist, "parent_id")), + infolist_integer (infolist, "split_pct"), + infolist_integer (infolist, "split_horiz"), + infolist_string (infolist, "plugin_name"), + infolist_string (infolist, "buffer_name")); + break; } } @@ -599,30 +688,39 @@ upgrade_weechat_load () { int rc; struct t_upgrade_file *upgrade_file; - struct t_gui_buffer *ptr_buffer; upgrade_file = upgrade_file_new (WEECHAT_UPGRADE_FILENAME, 0); rc = upgrade_file_read (upgrade_file, &upgrade_weechat_read_cb, NULL); if (!hotlist_reset) gui_hotlist_clear (); - - /* merge buffers */ - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) + + gui_color_buffer_assign (); + gui_color_buffer_display (); + + if (upgrade_layout_buffers) + { + gui_layout_buffer_apply (upgrade_layout_buffers); + gui_layout_buffer_remove_all (&upgrade_layout_buffers, + &last_upgrade_layout_buffer); + } + + if (upgrade_layout_windows) { - if (ptr_buffer->merge_for_upgrade) - gui_buffer_merge (ptr_buffer, ptr_buffer->merge_for_upgrade); + gui_layout_window_apply (upgrade_layout_windows, -1); + gui_layout_window_remove_all (&upgrade_layout_windows); } + if (upgrade_set_current_window > 0) + gui_window_switch_by_number (upgrade_set_current_window); + if (upgrade_set_current_buffer) { gui_window_switch_to_buffer (gui_current_window, upgrade_set_current_buffer, 0); } - gui_color_buffer_assign (); - gui_color_buffer_display (); + gui_layout_buffer_get_number_all (gui_layout_buffers); return rc; } diff --git a/src/core/wee-upgrade.h b/src/core/wee-upgrade.h index 95675e1fc..b0939b582 100644 --- a/src/core/wee-upgrade.h +++ b/src/core/wee-upgrade.h @@ -32,8 +32,9 @@ enum t_upgrade_weechat_type UPGRADE_WEECHAT_TYPE_BUFFER, UPGRADE_WEECHAT_TYPE_NICKLIST, UPGRADE_WEECHAT_TYPE_BUFFER_LINE, - UPGRADE_WEECHAT_TYPE_UPTIME, + UPGRADE_WEECHAT_TYPE_MISC, UPGRADE_WEECHAT_TYPE_HOTLIST, + UPGRADE_WEECHAT_TYPE_LAYOUT_WINDOW, }; int upgrade_weechat_save (); diff --git a/src/core/weechat.c b/src/core/weechat.c index aebfda775..7b997226a 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -444,7 +444,8 @@ main (int argc, char *argv[]) plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* command executed after plugins */ - gui_layout_window_apply (gui_layout_windows, -1); /* apply saved layout */ + if (!weechat_upgrading) + gui_layout_window_apply (gui_layout_windows, -1); /* apply win layout */ if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 07826d04c..d7214829a 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -971,7 +971,6 @@ gui_window_draw_separator (struct t_gui_window *window) mvwvline (GUI_WINDOW_OBJECTS(window)->win_separator, 0, 0, separator_vertical, window->win_height); wnoutrefresh (GUI_WINDOW_OBJECTS(window)->win_separator); - refresh (); } } diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index b3873f94b..2e071e9bc 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -867,7 +867,7 @@ gui_bar_item_default_buffer_plugin (void *data, struct t_gui_bar_item *item, if (!window) window = gui_current_window; - plugin_name = plugin_get_name (window->buffer->plugin); + plugin_name = gui_buffer_get_plugin_name (window->buffer); return (plugin_name) ? strdup (plugin_name) : strdup (""); } diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 62a1a0d7c..e2272474d 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -107,6 +107,22 @@ char *gui_buffer_properties_set[] = /* + * gui_buffer_get_plugin_name: get plugin name of buffer + * Note: during upgrade process (at startup after + * /upgrade), the name of plugin is retrieved + * in temporary variable "plugin_name_for_upgrade" + */ + +const char * +gui_buffer_get_plugin_name (struct t_gui_buffer *buffer) +{ + if (buffer->plugin_name_for_upgrade) + return buffer->plugin_name_for_upgrade; + + return plugin_get_name (buffer->plugin); +} + +/* * gui_buffer_local_var_add: add a new local variable to a buffer */ @@ -176,7 +192,7 @@ gui_buffer_notify_get (struct t_gui_buffer *buffer) int length; struct t_config_option *ptr_option; - plugin_name = plugin_get_name (buffer->plugin); + plugin_name = gui_buffer_get_plugin_name (buffer); length = strlen (plugin_name) + 1 + strlen (buffer->name) + 1; option_name = malloc (length); if (option_name) @@ -234,7 +250,7 @@ gui_buffer_notify_set (struct t_gui_buffer *buffer) gui_chat_printf (NULL, _("Notify changed for \"%s%s.%s%s\": \"%s%s%s\" to \"%s%s%s\""), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name, GUI_COLOR(GUI_COLOR_CHAT), GUI_COLOR(GUI_COLOR_CHAT_VALUE), @@ -283,7 +299,12 @@ gui_buffer_find_pos (struct t_gui_buffer *buffer) || ((buffer->layout_number == ptr_buffer->layout_number) && (buffer->layout_number_merge_order <= ptr_buffer->layout_number_merge_order))) { - return ptr_buffer; + /* not possible to insert a buffer between 2 merged buffers */ + if (!ptr_buffer->prev_buffer + || ((ptr_buffer->prev_buffer)->number != ptr_buffer->number)) + { + return ptr_buffer; + } } } @@ -330,7 +351,7 @@ gui_buffer_insert (struct t_gui_buffer *buffer, int automatic_merge) gui_buffers = buffer; last_gui_buffer = buffer; } - + /* merge buffer with previous or next, if they have layout number */ if (automatic_merge && (buffer->layout_number >= 1)) { @@ -403,7 +424,6 @@ gui_buffer_new (struct t_weechat_plugin *plugin, /* init buffer */ new_buffer->plugin = plugin; new_buffer->plugin_name_for_upgrade = NULL; - new_buffer->merge_for_upgrade = NULL; /* number will be set later (when inserting buffer in list) */ gui_layout_buffer_get_number (gui_layout_buffers, @@ -703,8 +723,7 @@ gui_buffer_match_list (struct t_gui_buffer *buffer, const char *string) if (buffers) { snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s", - (!buffer->plugin && buffer->plugin_name_for_upgrade) ? - buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name); match = gui_buffer_full_name_match_list (buffer_full_name, num_buffers, buffers); @@ -839,7 +858,7 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property) if (buffer && property) { if (string_strcasecmp (property, "plugin") == 0) - return plugin_get_name (buffer->plugin); + return gui_buffer_get_plugin_name (buffer); else if (string_strcasecmp (property, "name") == 0) return buffer->name; else if (string_strcasecmp (property, "short_name") == 0) @@ -1735,24 +1754,8 @@ gui_buffer_search_by_name (const char *plugin, const char *name) plugin_match = 1; if (plugin && plugin[0]) { - if (ptr_buffer->plugin_name_for_upgrade) - { - if (strcmp (plugin, ptr_buffer->plugin_name_for_upgrade) != 0) - plugin_match = 0; - } - else - { - if (ptr_buffer->plugin) - { - if (strcmp (plugin, ptr_buffer->plugin->name) != 0) - plugin_match = 0; - } - else - { - if (strcmp (plugin, PLUGIN_CORE) != 0) - plugin_match = 0; - } - } + if (strcmp (plugin, gui_buffer_get_plugin_name (ptr_buffer)) != 0) + plugin_match = 0; } if (plugin_match && (strcmp (ptr_buffer->name, name) == 0)) { @@ -1826,16 +1829,8 @@ gui_buffer_search_by_partial_name (const char *plugin, const char *name) plugin_match = 1; if (plugin && plugin[0]) { - if (ptr_buffer->plugin) - { - if (strcmp (plugin, ptr_buffer->plugin->name) != 0) - plugin_match = 0; - } - else - { - if (strcmp (plugin, PLUGIN_CORE) != 0) - plugin_match = 0; - } + if (strcmp (plugin, gui_buffer_get_plugin_name (ptr_buffer)) != 0) + plugin_match = 0; } if (plugin_match) { @@ -2634,21 +2629,19 @@ gui_buffer_unmerge (struct t_gui_buffer *buffer, int number) void gui_buffer_unmerge_all () { - int number, count_merged, i; + int number; struct t_gui_buffer *ptr_buffer; number = 1; while (number <= last_gui_buffer->number) { - count_merged = gui_buffer_count_merged_buffers (number); - if (count_merged > 1) + while (gui_buffer_count_merged_buffers (number) > 1) { - for (i = 0; i < count_merged - 1; i++) - { - ptr_buffer = gui_buffer_search_by_number (number); - if (ptr_buffer) - gui_buffer_unmerge (ptr_buffer, -1); - } + ptr_buffer = gui_buffer_search_by_number (number); + if (ptr_buffer) + gui_buffer_unmerge (ptr_buffer, -1); + else + break; } number++; } @@ -3051,7 +3044,6 @@ gui_buffer_hdata_buffer_cb (void *data, const char *hdata_name) { HDATA_VAR(struct t_gui_buffer, plugin, POINTER, "plugin"); HDATA_VAR(struct t_gui_buffer, plugin_name_for_upgrade, STRING, NULL); - HDATA_VAR(struct t_gui_buffer, merge_for_upgrade, POINTER, NULL); HDATA_VAR(struct t_gui_buffer, number, INTEGER, NULL); HDATA_VAR(struct t_gui_buffer, layout_number, INTEGER, NULL); HDATA_VAR(struct t_gui_buffer, layout_number_merge_order, INTEGER, NULL); @@ -3195,7 +3187,7 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist, if (!infolist_new_var_pointer (ptr_item, "plugin", buffer->plugin)) return 0; if (!infolist_new_var_string (ptr_item, "plugin_name", - plugin_get_name (buffer->plugin))) + gui_buffer_get_plugin_name (buffer))) return 0; if (!infolist_new_var_integer (ptr_item, "number", buffer->number)) return 0; @@ -3381,7 +3373,7 @@ gui_buffer_print_log () log_printf (""); log_printf ("[buffer (addr:0x%lx)]", ptr_buffer); log_printf (" plugin. . . . . . . . . : 0x%lx ('%s')", - ptr_buffer->plugin, plugin_get_name (ptr_buffer->plugin)); + ptr_buffer->plugin, gui_buffer_get_plugin_name (ptr_buffer)); log_printf (" plugin_name_for_upgrade : '%s'", ptr_buffer->plugin_name_for_upgrade); log_printf (" number. . . . . . . . . : %d", ptr_buffer->number); log_printf (" layout_number . . . . . : %d", ptr_buffer->layout_number); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 97acff1c0..83357059f 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -72,12 +72,6 @@ struct t_gui_buffer * loaded */ char *plugin_name_for_upgrade; /* plugin name when upgrading */ - /* - * when upgrading, we use this pointer to remember that this buffer - * must merge with another buffer (it's done when all buffers are - * restored) - */ - struct t_gui_buffer *merge_for_upgrade; int number; /* buffer number (first is 1) */ int layout_number; /* number of buffer saved in layout */ @@ -208,6 +202,7 @@ extern char *gui_buffer_properties_set[]; /* buffer functions */ +extern const char *gui_buffer_get_plugin_name (struct t_gui_buffer *buffer); extern void gui_buffer_notify_set_all (); extern void gui_buffer_input_buffer_init (struct t_gui_buffer *buffer); extern struct t_gui_buffer *gui_buffer_new (struct t_weechat_plugin *plugin, diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 514506cd8..250b654f3 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -589,13 +589,13 @@ gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date, new_msg = NULL; if (buffer) { - length = strlen (plugin_get_name (buffer->plugin)) + 1 + + length = strlen (gui_buffer_get_plugin_name (buffer)) + 1 + strlen (buffer->name) + 1 + ((tags) ? strlen (tags) : 0) + 1; modifier_data = malloc (length); if (modifier_data) { snprintf (modifier_data, length, "%s;%s;%s", - plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name, (tags) ? tags : ""); new_msg = hook_modifier_exec (NULL, diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 15c5b055c..ae2496eef 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -141,8 +141,7 @@ gui_filter_buffer (struct t_gui_buffer *buffer) buffer->lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min); snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s", - (!buffer->plugin && buffer->plugin_name_for_upgrade) ? - buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name); for (ptr_line = buffer->lines->first_line; ptr_line; diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c index 9e88e085e..c0f41e69a 100644 --- a/src/gui/gui-hotlist.c +++ b/src/gui/gui-hotlist.c @@ -515,7 +515,7 @@ gui_hotlist_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_integer (ptr_item, "buffer_number", hotlist->buffer->number)) return 0; - if (!infolist_new_var_string (ptr_item, "plugin_name", plugin_get_name (hotlist->buffer->plugin))) + if (!infolist_new_var_string (ptr_item, "plugin_name", gui_buffer_get_plugin_name (hotlist->buffer))) return 0; if (!infolist_new_var_string (ptr_item, "buffer_name", hotlist->buffer->name)) return 0; diff --git a/src/gui/gui-layout.c b/src/gui/gui-layout.c index 586632063..52f711548 100644 --- a/src/gui/gui-layout.c +++ b/src/gui/gui-layout.c @@ -31,6 +31,7 @@ #include "../core/weechat.h" #include "../core/wee-log.h" #include "../core/wee-config.h" +#include "../core/wee-infolist.h" #include "../core/wee-string.h" #include "../plugins/plugin.h" #include "gui-layout.h" @@ -167,15 +168,14 @@ gui_layout_buffer_save (struct t_gui_layout_buffer **layout_buffers, ptr_buffer = ptr_buffer->next_buffer) { gui_layout_buffer_add (layout_buffers, last_layout_buffer, - plugin_get_name (ptr_buffer->plugin), + gui_buffer_get_plugin_name (ptr_buffer), ptr_buffer->name, ptr_buffer->number); } } /* - * gui_layout_buffer_get_number: get number for a plugin/buffer - * return 0 if not found + * gui_layout_buffer_get_number: get layout number for a plugin/buffer */ void @@ -215,27 +215,40 @@ gui_layout_buffer_get_number (struct t_gui_layout_buffer *layout_buffers, } /* - * gui_layout_buffer_apply: apply a layout for buffers + * gui_layout_buffer_get_number_all: get layout numbers for all buffers */ void -gui_layout_buffer_apply (struct t_gui_layout_buffer *layout_buffers) +gui_layout_buffer_get_number_all (struct t_gui_layout_buffer *layout_buffers) { - struct t_gui_buffer *ptr_buffer, *ptr_next_buffer; - const char *plugin_name; - int number, count_merged; + struct t_gui_buffer *ptr_buffer; + + if (!layout_buffers) + return; - /* compute layout number for all buffers */ for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { - plugin_name = plugin_get_name (ptr_buffer->plugin); gui_layout_buffer_get_number (layout_buffers, - plugin_name, + gui_buffer_get_plugin_name (ptr_buffer), ptr_buffer->name, &(ptr_buffer->layout_number), &(ptr_buffer->layout_number_merge_order)); } +} + +/* + * gui_layout_buffer_apply: apply a layout for buffers + */ + +void +gui_layout_buffer_apply (struct t_gui_layout_buffer *layout_buffers) +{ + struct t_gui_buffer *ptr_buffer, *ptr_next_buffer; + int number, count_merged; + + /* get layout number for all buffers */ + gui_layout_buffer_get_number_all (layout_buffers); /* unmerge all buffers */ gui_buffer_unmerge_all (); @@ -432,7 +445,7 @@ gui_layout_window_save_tree (struct t_gui_layout_window **layout_windows, gui_layout_internal_id, parent_layout, 0, 0, - plugin_get_name (tree->window->buffer->plugin), + gui_buffer_get_plugin_name (tree->window->buffer), tree->window->buffer->name); } else @@ -485,7 +498,7 @@ gui_layout_window_check_buffer (struct t_gui_buffer *buffer) struct t_gui_window *ptr_win; const char *plugin_name; - plugin_name = plugin_get_name (buffer->plugin); + plugin_name = gui_buffer_get_plugin_name (buffer); for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { @@ -511,7 +524,6 @@ gui_layout_window_check_all_buffers () { struct t_gui_window *ptr_win; struct t_gui_buffer *ptr_buffer; - const char *plugin_name; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { @@ -520,9 +532,7 @@ gui_layout_window_check_all_buffers () for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { - plugin_name = plugin_get_name (ptr_buffer->plugin); - - if ((strcmp (ptr_win->layout_plugin_name, plugin_name) == 0) + if ((strcmp (ptr_win->layout_plugin_name, gui_buffer_get_plugin_name (ptr_buffer)) == 0) && (strcmp (ptr_win->layout_buffer_name, ptr_buffer->name) == 0)) { gui_window_switch_to_buffer (ptr_win, ptr_buffer, 0); @@ -594,21 +604,21 @@ gui_layout_window_apply (struct t_gui_layout_window *layout_windows, { struct t_gui_window *old_window; - if (layout_windows) - { - gui_window_merge_all (gui_current_window); - - old_window = gui_current_window; - gui_layout_ptr_current_window = NULL; - - gui_layout_window_apply_tree (layout_windows, - internal_id_current_window); - - gui_layout_window_check_all_buffers (); - - gui_window_switch ((gui_layout_ptr_current_window) ? - gui_layout_ptr_current_window : old_window); - } + if (!layout_windows) + return; + + gui_window_merge_all (gui_current_window); + + old_window = gui_current_window; + gui_layout_ptr_current_window = NULL; + + gui_layout_window_apply_tree (layout_windows, + internal_id_current_window); + + gui_layout_window_check_all_buffers (); + + gui_window_switch ((gui_layout_ptr_current_window) ? + gui_layout_ptr_current_window : old_window); } /* @@ -638,6 +648,76 @@ gui_layout_save_on_exit () } /* + * gui_layout_buffer_add_to_infolist: add a buffer layout in an infolist + * return 1 if ok, 0 if error + */ + +int +gui_layout_buffer_add_to_infolist (struct t_infolist *infolist, + struct t_gui_layout_buffer *layout_buffer) +{ + struct t_infolist_item *ptr_item; + + if (!infolist || !layout_buffer) + return 0; + + ptr_item = infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!infolist_new_var_string (ptr_item, "plugin_name", layout_buffer->plugin_name)) + return 0; + if (!infolist_new_var_string (ptr_item, "buffer_name", layout_buffer->buffer_name)) + return 0; + if (!infolist_new_var_integer (ptr_item, "number", layout_buffer->number)) + return 0; + + return 1; +} + +/* + * gui_layout_window_add_to_infolist: add a window layout in an infolist + * return 1 if ok, 0 if error + */ + +int +gui_layout_window_add_to_infolist (struct t_infolist *infolist, + struct t_gui_layout_window *layout_window) +{ + struct t_infolist_item *ptr_item; + + if (!infolist || !layout_window) + return 0; + + ptr_item = infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!infolist_new_var_integer (ptr_item, "internal_id", layout_window->internal_id)) + return 0; + if (!infolist_new_var_integer (ptr_item, "parent_id", + (layout_window->parent_node) ? + (layout_window->parent_node)->internal_id : 0)) + return 0; + if (!infolist_new_var_pointer (ptr_item, "parent_node", layout_window->parent_node)) + return 0; + if (!infolist_new_var_integer (ptr_item, "split_pct", layout_window->split_pct)) + return 0; + if (!infolist_new_var_integer (ptr_item, "split_horiz", layout_window->split_horiz)) + return 0; + if (!infolist_new_var_pointer (ptr_item, "child1", layout_window->child1)) + return 0; + if (!infolist_new_var_pointer (ptr_item, "child2", layout_window->child2)) + return 0; + if (!infolist_new_var_string (ptr_item, "plugin_name", layout_window->plugin_name)) + return 0; + if (!infolist_new_var_string (ptr_item, "buffer_name", layout_window->buffer_name)) + return 0; + + return 1; +} + +/* * gui_layout_print_log_window: print windows layout infos in log (usually for * crash dump) */ diff --git a/src/gui/gui-layout.h b/src/gui/gui-layout.h index 0b094f6a1..e147cc5d1 100644 --- a/src/gui/gui-layout.h +++ b/src/gui/gui-layout.h @@ -72,6 +72,7 @@ extern void gui_layout_buffer_get_number (struct t_gui_layout_buffer *layout_buf const char *buffer_name, int *layout_number, int *layout_number_merge_order); +extern void gui_layout_buffer_get_number_all (struct t_gui_layout_buffer *layout_buffers); extern void gui_layout_buffer_apply (struct t_gui_layout_buffer *layout_buffers); extern void gui_layout_window_remove_all (struct t_gui_layout_window **layout_windows); @@ -89,9 +90,11 @@ extern int gui_layout_window_save (struct t_gui_layout_window **layout_windows); extern void gui_layout_window_apply (struct t_gui_layout_window *layout_windows, int internal_id_current_window); extern void gui_layout_window_check_buffer (struct t_gui_buffer *buffer); - extern void gui_layout_save_on_exit (); - +extern int gui_layout_buffer_add_to_infolist (struct t_infolist *infolist, + struct t_gui_layout_buffer *layout_buffer); +extern int gui_layout_window_add_to_infolist (struct t_infolist *infolist, + struct t_gui_layout_window *layout_window); extern void gui_layout_print_log (); #endif /* __WEECHAT_GUI_LAYOUT_H */ diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index a4f5ded65..a23784906 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -847,8 +847,7 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date, /* check if line is filtered or not */ snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s", - (!buffer->plugin && buffer->plugin_name_for_upgrade) ? - buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name); new_line->data->displayed = gui_filter_check_line (new_line, buffer_full_name); @@ -1009,8 +1008,7 @@ gui_line_add_y (struct t_gui_buffer *buffer, int y, const char *message) /* check if line is filtered or not */ snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s", - (!buffer->plugin && buffer->plugin_name_for_upgrade) ? - buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin), + gui_buffer_get_plugin_name (buffer), buffer->name); ptr_line->data->displayed = gui_filter_check_line (ptr_line, buffer_full_name); diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 2f5b342cd..9c1c253ce 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -1469,6 +1469,9 @@ gui_window_add_to_infolist (struct t_infolist *infolist, if (!infolist_new_var_pointer (ptr_item, "pointer", window)) return 0; + if (!infolist_new_var_integer (ptr_item, "current_window", + (gui_current_window == window) ? 1 : 0)) + return 0; if (!infolist_new_var_integer (ptr_item, "number", window->number)) return 0; if (!infolist_new_var_integer (ptr_item, "x", window->win_x)) diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index b38ed60e3..0dd8cbc9b 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -563,7 +563,7 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, { snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s", - plugin_get_name (ptr_buffer->plugin), + gui_buffer_get_plugin_name (ptr_buffer), ptr_buffer->name); if (!arguments || !arguments[0] || string_match (buffer_full_name, arguments, 0)) |