From dc4f5ea2e2653776fa692a89d93cb44cd3adebff Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 6 Nov 2007 13:17:28 +0100 Subject: [PATCH] Added option "set" for /buffer command --- src/core/wee-command.c | 89 ++++++-------------------- src/gui/curses/gui-curses-nicklist.c | 4 +- src/gui/curses/gui-curses-window.c | 2 +- src/gui/gui-buffer.c | 93 +++++++++++++++++++++++++--- src/gui/gui-buffer.h | 1 + src/plugins/plugin-api.c | 44 +------------ 6 files changed, 111 insertions(+), 122 deletions(-) diff --git a/src/core/wee-command.c b/src/core/wee-command.c index e36920677..c9af9998c 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -90,7 +90,7 @@ struct command weechat_commands[] = " scroll 15 min down: /buffer scroll +15m\n" " scroll 20 msgs up: /buffer scroll -20\n" " jump to #weechat: /buffer #weechat"), - "move|close|list|notify|scroll|%S|%C %S|%C", + "move|close|list|notify|scroll|set|%S|%C %S|%C", 0, MAX_ARGS, 0, command_buffer }, { "builtin", N_("launch WeeChat builtin command (do not look at commands hooked or " @@ -442,66 +442,6 @@ command_alias (struct t_gui_buffer *buffer, return 0; } -/* - * command_buffer_display_info: display info about a buffer - */ - -void -command_buffer_display_info (struct t_gui_buffer *buffer) -{ - /* TODO: write again this function */ - (void) buffer; -/* switch (buffer->type) - { - case GUI_BUFFER_TYPE_STANDARD: - if (GUI_BUFFER_IS_SERVER(buffer)) - { - if (GUI_SERVER(buffer)) - gui_chat_printf (NULL, _("%sServer: %s%s"), - GUI_COLOR(GUI_COLOR_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name); - else - gui_chat_printf (NULL, _("%snot connected"), - GUI_COLOR(GUI_COLOR_CHAT)); - } - else if (GUI_BUFFER_IS_CHANNEL (buffer)) - gui_chat_printf (NULL, _("%sChannel: %s%s %s(server: %s%s%s)"), - GUI_COLOR(GUI_COLOR_CHAT), - GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - GUI_CHANNEL(buffer)->name, - GUI_COLOR(GUI_COLOR_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name, - GUI_COLOR(GUI_COLOR_CHAT)); - else if (GUI_BUFFER_IS_PRIVATE (buffer)) - gui_chat_printf (NULL, _("%sPrivate with: %s%s %s(server: %s%s%s)"), - GUI_COLOR(GUI_COLOR_CHAT), - GUI_COLOR(GUI_COLOR_CHAT_NICK), - GUI_CHANNEL(buffer)->name, - GUI_COLOR(GUI_COLOR_CHAT), - GUI_COLOR(GUI_COLOR_WIN_CHAT_SERVER), - GUI_SERVER(buffer)->name, - GUI_COLOR(GUI_COLOR_CHAT)); - else - gui_chat_printf (NULL, _("%sunknown"), - GUI_COLOR(GUI_COLOR_CHAT)); - break; - case GUI_BUFFER_TYPE_DCC: - gui_chat_printf (NULL, "%sDCC", - GUI_COLOR(GUI_COLOR_CHAT_BUFFER)); - break; - case GUI_BUFFER_TYPE_RAW_DATA: - gui_chat_printf (NULL, _("%sraw IRC data"), - GUI_COLOR(GUI_COLOR_CHAT_BUFFER)); - break; - default: - gui_chat_printf (NULL, _("%sunknown"), - GUI_COLOR(GUI_COLOR_CHAT)); - break; - }*/ -} - /* * command_buffer: manage buffers */ @@ -512,11 +452,8 @@ command_buffer (struct t_gui_buffer *buffer, { struct t_gui_buffer *ptr_buffer; long number; - char *error; + char *error ,*value; int target_buffer; - - /* make C compiler happy */ - (void) argv_eol; if ((argc == 0) || ((argc == 1) && (string_strcasecmp (argv[0], "list") == 0))) @@ -541,7 +478,6 @@ command_buffer (struct t_gui_buffer *buffer, "weechat", ptr_buffer->category, ptr_buffer->name); - command_buffer_display_info (ptr_buffer); } } else @@ -669,6 +605,24 @@ command_buffer (struct t_gui_buffer *buffer, } } } + else if (string_strcasecmp (argv[0], "set") == 0) + { + /* set a property on buffer */ + + if (argc < 3) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "buffer"); + return -1; + } + value = string_remove_quotes (argv_eol[2], "'\""); + gui_buffer_set (buffer, argv[1], (value) ? value : argv_eol[2]); + if (value) + free (value); + } else { /* jump to buffer by number or server/channel name */ @@ -2149,9 +2103,6 @@ command_window (struct t_gui_buffer *buffer, ptr_win->win_width, ptr_win->win_height, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - - command_buffer_display_info (ptr_win->buffer); - i++; } } diff --git a/src/gui/curses/gui-curses-nicklist.c b/src/gui/curses/gui-curses-nicklist.c index 1a748561d..5be8c4984 100644 --- a/src/gui/curses/gui-curses-nicklist.c +++ b/src/gui/curses/gui-curses-nicklist.c @@ -56,7 +56,9 @@ gui_nicklist_draw (struct t_gui_buffer *buffer, int erase) if ((ptr_win->buffer == buffer) && (buffer->num_displayed > 0)) { max_length = gui_nicklist_get_max_length (buffer); - if (max_length != buffer->nick_max_length) + if ((max_length != buffer->nick_max_length) + || (buffer->nicklist && !GUI_CURSES(ptr_win)->win_nick) + || (!buffer->nicklist && GUI_CURSES(ptr_win)->win_nick)) { buffer->nick_max_length = max_length; if (gui_window_calculate_pos_size (ptr_win, 0)) diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 2161496fc..2658a53a3 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -200,7 +200,7 @@ gui_window_calculate_pos_size (struct t_gui_window *window, int force_calculate) return 0; /* init chat & nicklist settings */ - if (cfg_look_nicklist && window->buffer->nicklist) + if (window->buffer->nicklist) { max_length = gui_nicklist_get_max_length (window->buffer); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 60f0b57f8..09ad6df6c 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -36,13 +36,16 @@ #include "gui-completion.h" #include "gui-history.h" #include "gui-hotlist.h" +#include "gui-input.h" #include "gui-main.h" +#include "gui-nicklist.h" #include "gui-log.h" #include "gui-status.h" #include "gui-window.h" #include "../core/wee-command.h" #include "../core/wee-config.h" #include "../core/wee-log.h" +#include "../core/wee-string.h" #include "../core/wee-utf8.h" #include "../plugins/plugin.h" @@ -207,9 +210,12 @@ gui_buffer_valid (struct t_gui_buffer *buffer) void gui_buffer_set_category (struct t_gui_buffer *buffer, char *category) { - if (buffer->category) - free (buffer->category); - buffer->category = (category) ? strdup (category) : NULL; + if (category && category[0]) + { + if (buffer->category) + free (buffer->category); + buffer->category = strdup (category); + } } /* @@ -219,9 +225,12 @@ gui_buffer_set_category (struct t_gui_buffer *buffer, char *category) void gui_buffer_set_name (struct t_gui_buffer *buffer, char *name) { - if (buffer->name) - free (buffer->name); - buffer->name = (name) ? strdup (name) : NULL; + if (name && name[0]) + { + if (buffer->name) + free (buffer->name); + buffer->name = strdup (name); + } } /* @@ -250,7 +259,17 @@ gui_buffer_set_title (struct t_gui_buffer *buffer, char *new_title) { if (buffer->title) free (buffer->title); - buffer->title = (new_title) ? strdup (new_title) : NULL; + buffer->title = (new_title && new_title[0]) ? strdup (new_title) : NULL; +} + +/* + * gui_buffer_set_nicklist: set nicklist for a buffer + */ + +void +gui_buffer_set_nicklist (struct t_gui_buffer *buffer, int nicklist) +{ + buffer->nicklist = (nicklist) ? 1 : 0; } /* @@ -273,7 +292,65 @@ gui_buffer_set_nick (struct t_gui_buffer *buffer, char *new_nick) { if (buffer->input_nick) free (buffer->input_nick); - buffer->input_nick = (new_nick) ? strdup (new_nick) : NULL; + buffer->input_nick = (new_nick && new_nick[0]) ? strdup (new_nick) : NULL; +} + +/* + * gui_buffer_set: set a property for a buffer + */ + +void +gui_buffer_set (struct t_gui_buffer *buffer, char *property, char *value) +{ + long number; + char *error; + + if (string_strcasecmp (property, "display") == 0) + { + gui_window_switch_to_buffer (gui_current_window, buffer); + gui_window_redraw_buffer (buffer); + } + else if (string_strcasecmp (property, "category") == 0) + { + gui_buffer_set_category (buffer, value); + gui_status_draw (buffer, 1); + } + else if (string_strcasecmp (property, "name") == 0) + { + gui_buffer_set_name (buffer, value); + gui_status_draw (buffer, 1); + } + else if (string_strcasecmp (property, "log") == 0) + { + gui_buffer_set_log (buffer, value); + } + else if (string_strcasecmp (property, "title") == 0) + { + gui_buffer_set_title (buffer, value); + gui_chat_draw_title (buffer, 1); + } + else if (string_strcasecmp (property, "nicklist") == 0) + { + error = NULL; + number = strtol (value, &error, 10); + if (error && (error[0] == '\0')) + { + gui_buffer_set_nicklist (buffer, number); + gui_window_refresh_windows (); + } + } + else if (string_strcasecmp (property, "nick_case_sensitive") == 0) + { + error = NULL; + number = strtol (value, &error, 10); + if (error && (error[0] == '\0')) + gui_buffer_set_nick_case_sensitive (buffer, number); + } + else if (string_strcasecmp (property, "nick") == 0) + { + gui_buffer_set_nick (buffer, value); + gui_input_draw (buffer, 1); + } } /* diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 5380a54f3..9adac88a2 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -151,6 +151,7 @@ extern void gui_buffer_set_log (struct t_gui_buffer *, char *); extern void gui_buffer_set_title (struct t_gui_buffer *, char *); extern void gui_buffer_set_nick_case_sensitive (struct t_gui_buffer *, int); extern void gui_buffer_set_nick (struct t_gui_buffer *, char *); +extern void gui_buffer_set (struct t_gui_buffer *, char *, char *); extern struct t_gui_buffer *gui_buffer_search_main (); extern struct t_gui_buffer *gui_buffer_search_by_category_name (char *, char *); diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index c5b3da9ae..4803f3a8d 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -543,50 +543,8 @@ void plugin_api_buffer_set (struct t_weechat_plugin *plugin, void *buffer, char *property, char *value) { - long number; - char *error; - if (plugin && buffer && property && property[0]) - { - if (string_strcasecmp (property, "display") == 0) - { - gui_window_switch_to_buffer (gui_current_window, - (struct t_gui_buffer *)buffer); - gui_window_redraw_buffer ((struct t_gui_buffer *)buffer); - } - else if (string_strcasecmp (property, "category") == 0) - { - gui_buffer_set_category ((struct t_gui_buffer *)buffer, value); - gui_status_draw ((struct t_gui_buffer *)buffer, 0); - } - else if (string_strcasecmp (property, "name") == 0) - { - gui_buffer_set_name ((struct t_gui_buffer *)buffer, value); - gui_status_draw ((struct t_gui_buffer *)buffer, 0); - } - else if (string_strcasecmp (property, "log") == 0) - { - gui_buffer_set_log ((struct t_gui_buffer *)buffer, value); - } - else if (string_strcasecmp (property, "title") == 0) - { - gui_buffer_set_title ((struct t_gui_buffer *)buffer, value); - gui_chat_draw_title ((struct t_gui_buffer *)buffer, 0); - } - else if (string_strcasecmp (property, "nick_case_sensitive") == 0) - { - error = NULL; - number = strtol (value, &error, 10); - if (error && (error[0] == '\0')) - gui_buffer_set_nick_case_sensitive ((struct t_gui_buffer *)buffer, - number); - } - else if (string_strcasecmp (property, "nick") == 0) - { - gui_buffer_set_nick ((struct t_gui_buffer *)buffer, value); - gui_input_draw ((struct t_gui_buffer *)buffer, 0); - } - } + gui_buffer_set ((struct t_gui_buffer *)buffer, property, value); } /*