diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-01-05 23:07:08 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-01-05 23:07:08 +0000 |
commit | 6d3c24361d8efc5b14e6b6cf1aba13d294b32078 (patch) | |
tree | c278a8a0dd58c9f485979565075ba7fd3b98f75f /src | |
parent | 2f5c9a8fd480c7ba0caa1a88ae832f6ea8edfd79 (diff) | |
download | weechat-6d3c24361d8efc5b14e6b6cf1aba13d294b32078.zip |
Improved /set command: new colors, server options can be changed while WeeChat is running
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 249 | ||||
-rw-r--r-- | src/common/weechat.h | 9 | ||||
-rw-r--r-- | src/common/weeconfig.c | 129 | ||||
-rw-r--r-- | src/common/weeconfig.h | 4 | ||||
-rw-r--r-- | src/gui/curses/gui-display.c | 6 |
5 files changed, 318 insertions, 79 deletions
diff --git a/src/common/command.c b/src/common/command.c index fd30e0d58..5d3bf7def 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -1593,16 +1593,89 @@ weechat_cmd_server (int argc, char **argv) } /* + * weechat_set_cmd_display_option: display config option + */ + +void +weechat_set_cmd_display_option (t_config_option *option, char *prefix, void *value) +{ + char *color_name, *pos_nickserv, *pos_pwd, *value2; + + gui_printf (NULL, " %s%s%s", + (prefix) ? prefix : "", + (prefix) ? "." : "", + option->option_name); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, " = "); + if (!value) + { + if (option->option_type == OPTION_TYPE_STRING) + value = option->ptr_string; + else + value = option->ptr_int; + } + switch (option->option_type) + { + case OPTION_TYPE_BOOLEAN: + gui_printf_color (NULL, COLOR_WIN_CHAT_HOST, + "%s\n", (*((int *)value)) ? "ON" : "OFF"); + break; + case OPTION_TYPE_INT: + gui_printf_color (NULL, COLOR_WIN_CHAT_HOST, + "%d\n", *((int *)value)); + break; + case OPTION_TYPE_INT_WITH_STRING: + gui_printf_color (NULL, COLOR_WIN_CHAT_HOST, + "%s\n", option->array_values[*((int *)value)]); + break; + case OPTION_TYPE_COLOR: + color_name = gui_get_color_by_value (*((int *)value)); + gui_printf_color (NULL, COLOR_WIN_CHAT_HOST, + "%s\n", (color_name) ? color_name : _("(unknown)")); + break; + case OPTION_TYPE_STRING: + if (*((char **)value)) + { + value2 = strdup (*((char **)value)); + pos_nickserv = NULL; + pos_pwd = NULL; + pos_nickserv = strstr (value2, "nickserv"); + if (pos_nickserv) + { + pos_pwd = strstr (value2, "identify "); + if (!pos_pwd) + pos_pwd = strstr (value2, "register "); + } + if (cfg_log_hide_nickserv_pwd && pos_nickserv && pos_pwd) + { + pos_pwd += 9; + while (pos_pwd[0]) + { + pos_pwd[0] = '*'; + pos_pwd++; + } + gui_printf (NULL, _("(password hidden) ")); + } + gui_printf_color (NULL, COLOR_WIN_CHAT_HOST, "%s", value2); + free (value2); + } + gui_printf (NULL, "\n"); + break; + } +} + +/* * weechat_cmd_set: set options */ int weechat_cmd_set (char *arguments) { - char *option, *value; + char *option, *value, *pos; int i, j, section_displayed; - char *color_name; t_config_option *ptr_option; + t_irc_server *ptr_server; + char option_name[256]; + void *ptr_option_value; int number_found; option = NULL; @@ -1620,32 +1693,86 @@ weechat_cmd_set (char *arguments) if (value) { - ptr_option = config_option_search (option); - if (ptr_option) + pos = strchr (option, '.'); + if (pos) { - if (ptr_option->handler_change == NULL) - { + /* server config option modification */ + pos[0] = '\0'; + ptr_server = server_search (option); + if (!ptr_server) gui_printf (NULL, - _("%s option \"%s\" can not be changed while WeeChat is running\n"), + _("%s server \"%s\" not found\n"), WEECHAT_ERROR, option); - } else { - if (config_option_set_value (ptr_option, value) == 0) + switch (config_set_server_value (ptr_server, pos + 1, value)) { - (void) (ptr_option->handler_change()); - gui_printf (NULL, "[%s]\n", config_get_section (ptr_option)); - gui_printf (NULL, " %s = %s\n", option, value); + case 0: + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "["); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, "%s", + config_sections[CONFIG_SECTION_SERVER].section_name); + gui_printf_color (NULL, COLOR_WIN_CHAT_NICK, " %s", + ptr_server->name); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "]\n"); + for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) + { + if (strcmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, pos + 1) == 0) + break; + } + if (weechat_options[CONFIG_SECTION_SERVER][i].option_name) + { + ptr_option_value = config_get_server_option_ptr (ptr_server, + weechat_options[CONFIG_SECTION_SERVER][i].option_name); + weechat_set_cmd_display_option (&weechat_options[CONFIG_SECTION_SERVER][i], + ptr_server->name, + ptr_option_value); + } + config_change_buffer_content (); + break; + case -1: + gui_printf (NULL, _("%s config option \"%s\" not found\n"), + WEECHAT_ERROR, pos + 1); + break; + case -2: + gui_printf (NULL, _("%s incorrect value for option \"%s\"\n"), + WEECHAT_ERROR, pos + 1); + break; } - else - gui_printf (NULL, _("%s incorrect value for option \"%s\"\n"), - WEECHAT_ERROR, option); } + pos[0] = '.'; } else { - gui_printf (NULL, _("%s config option \"%s\" not found\n"), - WEECHAT_ERROR, option); + ptr_option = config_option_search (option); + if (ptr_option) + { + if (ptr_option->handler_change == NULL) + { + gui_printf (NULL, + _("%s option \"%s\" can not be changed while WeeChat is running\n"), + WEECHAT_ERROR, option); + } + else + { + if (config_option_set_value (ptr_option, value) == 0) + { + (void) (ptr_option->handler_change()); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "["); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, + "%s", config_get_section (ptr_option)); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "]\n"); + weechat_set_cmd_display_option (ptr_option, NULL, NULL); + } + else + gui_printf (NULL, _("%s incorrect value for option \"%s\"\n"), + WEECHAT_ERROR, option); + } + } + else + { + gui_printf (NULL, _("%s config option \"%s\" not found\n"), + WEECHAT_ERROR, option); + } } } else @@ -1665,47 +1792,49 @@ weechat_cmd_set (char *arguments) { if (!section_displayed) { - gui_printf (NULL, "[%s]\n", - config_sections[i].section_name); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "["); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, + "%s", + config_sections[i].section_name); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "]\n"); section_displayed = 1; } - switch (weechat_options[i][j].option_type) - { - case OPTION_TYPE_BOOLEAN: - gui_printf (NULL, " %s = %s\n", - weechat_options[i][j].option_name, - (*weechat_options[i][j].ptr_int) ? - "ON" : "OFF"); - break; - case OPTION_TYPE_INT: - gui_printf (NULL, - " %s = %d\n", - weechat_options[i][j].option_name, - *weechat_options[i][j].ptr_int); - break; - case OPTION_TYPE_INT_WITH_STRING: - gui_printf (NULL, - " %s = %s\n", - weechat_options[i][j].option_name, - weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]); - break; - case OPTION_TYPE_COLOR: - color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int); - gui_printf (NULL, - " %s = %s\n", - weechat_options[i][j].option_name, - (color_name) ? color_name : _("(unknown)")); - break; - case OPTION_TYPE_STRING: - gui_printf (NULL, " %s = %s\n", - weechat_options[i][j]. - option_name, - (*weechat_options[i][j]. - ptr_string) ? - *weechat_options[i][j]. - ptr_string : ""); - break; - } + weechat_set_cmd_display_option (&weechat_options[i][j], NULL, NULL); + number_found++; + } + } + } + } + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + section_displayed = 0; + for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) + { + snprintf (option_name, sizeof (option_name), "%s.%s", + ptr_server->name, + weechat_options[CONFIG_SECTION_SERVER][i].option_name); + if ((!option) || + ((option) && (option[0]) + && (strstr (option_name, option) != NULL))) + { + if (!section_displayed) + { + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "["); + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, "%s", + config_sections[CONFIG_SECTION_SERVER].section_name); + gui_printf_color (NULL, COLOR_WIN_CHAT_NICK, " %s", + ptr_server->name); + gui_printf_color (NULL, COLOR_WIN_CHAT_DARK, "]\n"); + section_displayed = 1; + } + ptr_option_value = config_get_server_option_ptr (ptr_server, + weechat_options[CONFIG_SECTION_SERVER][i].option_name); + if (ptr_option_value) + { + weechat_set_cmd_display_option (&weechat_options[CONFIG_SECTION_SERVER][i], + ptr_server->name, + ptr_option_value); number_found++; } } @@ -1721,12 +1850,12 @@ weechat_cmd_set (char *arguments) } else { + gui_printf_color (NULL, COLOR_WIN_CHAT_CHANNEL, "%d ", number_found); if (option) - gui_printf (NULL, _("%d config option(s) found with \"%s\"\n"), - number_found, option); + gui_printf (NULL, _("config option(s) found with \"%s\"\n"), + option); else - gui_printf (NULL, _("%d config option(s) found\n"), - number_found); + gui_printf (NULL, _("config option(s) found\n")); } } return 0; diff --git a/src/common/weechat.h b/src/common/weechat.h index df8691433..acc416ea5 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -43,7 +43,7 @@ #endif -#define WEECHAT_COPYRIGHT PACKAGE_NAME " (c) 2003-2005 by Wee Team" +#define WEECHAT_COPYRIGHT_DATE "(c) 2003-2005" #define WEECHAT_WEBSITE "http://weechat.flashtux.org" #define WEECHAT_ERROR _(PACKAGE_NAME " Error:") @@ -57,10 +57,7 @@ #define WEE_LICENSE \ PACKAGE_STRING " (c) Copyright 2003-2005, compiled on " __DATE__ " " __TIME__ \ - "\nDeveloped by FlashCode <flashcode@flashtux.org>\n" \ - " Bounga <bounga@altern.org>\n" \ - " Xahlexx <xahlexx@weeland.org>\n" \ - "Website: " WEECHAT_WEBSITE "\n\n" \ + "\nDeveloped by FlashCode <flashcode@flashtux.org> - " WEECHAT_WEBSITE "\n\n" \ "This program is free software; you can redistribute it and/or modify\n" \ "it under the terms of the GNU General Public License as published by\n" \ "the Free Software Foundation; either version 2 of the License, or\n" \ @@ -78,7 +75,7 @@ #define WEE_USAGE1 \ PACKAGE_STRING " (c) Copyright 2003-2005, compiled on " __DATE__ " " __TIME__ \ - "\nDeveloped by FlashCode, Bounga and Xahlexx - " WEECHAT_WEBSITE "\n\n" \ + "\nDeveloped by FlashCode <flashcode@flashtux.org> - " WEECHAT_WEBSITE "\n\n" \ "Usage: %s [options ...]\n" \ " or: %s [irc://[nickname[:password]@]irc.example.org[:port][/channel] ...]\n\n" diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index b0825c1e5..0051ad970 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -409,11 +409,11 @@ t_config_option weechat_options_history[] = N_("maximum number of lines in history " "for one server/channel/private window (0 = unlimited)"), OPTION_TYPE_INT, 0, INT_MAX, 4096, - NULL, NULL, &cfg_history_max_lines, NULL, NULL }, + NULL, NULL, &cfg_history_max_lines, NULL, config_change_noop }, { "history_max_commands", N_("max user commands in history"), N_("maximum number of user commands in history (0 = unlimited)"), OPTION_TYPE_INT, 0, INT_MAX, 100, - NULL, NULL, &cfg_history_max_commands, NULL, NULL }, + NULL, NULL, &cfg_history_max_commands, NULL, config_change_noop }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -442,15 +442,15 @@ t_config_option weechat_options_log[] = { "log_path", N_("path for log files"), N_("path for WeeChat log files"), OPTION_TYPE_STRING, 0, 0, 0, - "~/.weechat/logs/", NULL, NULL, &cfg_log_path, NULL }, + "~/.weechat/logs/", NULL, NULL, &cfg_log_path, config_change_noop }, { "log_timestamp", N_("timestamp for log"), N_("timestamp for log (see man strftime for date/time specifiers)"), OPTION_TYPE_STRING, 0, 0, 0, - "%Y %b %d %H:%M:%S", NULL, NULL, &cfg_log_timestamp, NULL }, + "%Y %b %d %H:%M:%S", NULL, NULL, &cfg_log_timestamp, config_change_noop }, { "log_hide_nickserv_pwd", N_("hide password displayed by nickserv"), N_("hide password displayed by nickserv"), OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, - NULL, NULL, &cfg_log_hide_nickserv_pwd, NULL, NULL }, + NULL, NULL, &cfg_log_hide_nickserv_pwd, NULL, config_change_noop }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -539,19 +539,19 @@ t_config_option weechat_options_proxy[] = { { "proxy_use", N_("use proxy"), N_("use a proxy server to connect to irc server"), OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE, - NULL, NULL, &cfg_proxy_use, NULL, NULL }, + NULL, NULL, &cfg_proxy_use, NULL, config_change_noop }, { "proxy_address", N_("proxy address"), N_("proxy server address (IP or hostname)"), OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_proxy_address, NULL }, + "", NULL, NULL, &cfg_proxy_address, config_change_noop }, { "proxy_port", N_("port for proxy"), N_("port for connecting to proxy server"), OPTION_TYPE_INT, 0, 65535, 1080, - NULL, NULL, &cfg_proxy_port, NULL, NULL }, + NULL, NULL, &cfg_proxy_port, NULL, config_change_noop }, { "proxy_password", N_("proxy password"), N_("password for proxy server"), OPTION_TYPE_STRING, 0, 0, 0, - "", NULL, NULL, &cfg_proxy_password, NULL }, + "", NULL, NULL, &cfg_proxy_password, config_change_noop }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -781,6 +781,117 @@ config_option_set_value (t_config_option *option, char *value) } /* + * config_get_server_option_ptr: get a pointer to a server config option + */ + +void * +config_get_server_option_ptr (t_irc_server *server, char *option_name) +{ + if (strcasecmp (option_name, "server_name") == 0) + return (void *)(&server->name); + if (strcasecmp (option_name, "server_autoconnect") == 0) + return (void *)(&server->autoconnect); + if (strcasecmp (option_name, "server_autoreconnect") == 0) + return (void *)(&server->autoreconnect); + if (strcasecmp (option_name, "server_autoreconnect_delay") == 0) + return (void *)(&server->autoreconnect_delay); + if (strcasecmp (option_name, "server_address") == 0) + return (void *)(&server->address); + if (strcasecmp (option_name, "server_port") == 0) + return (void *)(&server->port); + if (strcasecmp (option_name, "server_password") == 0) + return (void *)(&server->password); + if (strcasecmp (option_name, "server_nick1") == 0) + return (void *)(&server->nick1); + if (strcasecmp (option_name, "server_nick2") == 0) + return (void *)(&server->nick2); + if (strcasecmp (option_name, "server_nick3") == 0) + return (void *)(&server->nick3); + if (strcasecmp (option_name, "server_username") == 0) + return (void *)(&server->username); + if (strcasecmp (option_name, "server_realname") == 0) + return (void *)(&server->realname); + if (strcasecmp (option_name, "server_command") == 0) + return (void *)(&server->command); + if (strcasecmp (option_name, "server_command_delay") == 0) + return (void *)(&server->command_delay); + if (strcasecmp (option_name, "server_autojoin") == 0) + return (void *)(&server->autojoin); + if (strcasecmp (option_name, "server_autorejoin") == 0) + return (void *)(&server->autorejoin); + /* option not found */ + return NULL; +} + +/* + * config_set_server_value: set new value for an option + * return: 0 if success + * -1 if option not found + * -2 if bad value + */ + +int +config_set_server_value (t_irc_server *server, char *option_name, + char *value) +{ + t_config_option *ptr_option; + int i; + void *ptr_data; + int int_value; + + ptr_data = config_get_server_option_ptr (server, option_name); + if (!ptr_data) + return -1; + + ptr_option = NULL; + for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) + { + /* if option found, return pointer */ + if (strcasecmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, option_name) == 0) + { + ptr_option = &weechat_options[CONFIG_SECTION_SERVER][i]; + break; + } + } + if (!ptr_option) + return -1; + + switch (ptr_option->option_type) + { + case OPTION_TYPE_BOOLEAN: + if (strcasecmp (value, "on") == 0) + *((int *)(ptr_data)) = BOOL_TRUE; + else if (strcasecmp (value, "off") == 0) + *((int *)(ptr_data)) = BOOL_FALSE; + else + return -2; + break; + case OPTION_TYPE_INT: + int_value = atoi (value); + if ((int_value < ptr_option->min) || (int_value > ptr_option->max)) + return -2; + *((int *)(ptr_data)) = int_value; + break; + case OPTION_TYPE_INT_WITH_STRING: + int_value = get_pos_array_values (ptr_option->array_values, value); + if (int_value < 0) + return -2; + *((int *)(ptr_data)) = int_value; + break; + case OPTION_TYPE_COLOR: + if (!gui_assign_color ((int *)ptr_data, value)) + return -2; + break; + case OPTION_TYPE_STRING: + if (*((char **)ptr_data)) + free (*((char **)ptr_data)); + *((char **)ptr_data) = strdup (value); + break; + } + return 0; +} + +/* * config_option_search: look for an option and return pointer to this option * if option is not found, NULL is returned */ diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h index e92a6e61d..7e10c4255 100644 --- a/src/common/weeconfig.h +++ b/src/common/weeconfig.h @@ -21,6 +21,8 @@ #ifndef __WEECHAT_CONFIG_H #define __WEECHAT_CONFIG_H 1 +#include "../irc/irc.h" + #define WEECHAT_CONFIG_NAME "weechat.rc" #define CONFIG_SECTION_NONE -1 @@ -179,6 +181,8 @@ extern void config_change_color (); extern int config_option_set_value (t_config_option *, char *); extern t_config_option *config_option_search (char *); extern int config_set_value (char *, char *); +extern void *config_get_server_option_ptr (t_irc_server *, char *); +extern int config_set_server_value (t_irc_server *, char *, char *); extern int config_read (); extern int config_create_default (); extern int config_write (); diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index 935afa8c4..679ba1016 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -344,10 +344,8 @@ gui_draw_buffer_title (t_gui_buffer *buffer, int erase) { /* TODO: change this copyright as title? */ mvwprintw (ptr_win->win_title, 0, 0, - "%s", PACKAGE_STRING " - " WEECHAT_WEBSITE); - mvwprintw (ptr_win->win_title, 0, - ptr_win->win_width - strlen (WEECHAT_COPYRIGHT), - "%s", WEECHAT_COPYRIGHT); + "%s", + PACKAGE_STRING " " WEECHAT_COPYRIGHT_DATE " - " WEECHAT_WEBSITE); } } wrefresh (ptr_win->win_title); |