diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 43 | ||||
-rw-r--r-- | src/common/command.h | 1 | ||||
-rw-r--r-- | src/common/weechat.c | 49 | ||||
-rw-r--r-- | src/common/weechat.h | 2 | ||||
-rw-r--r-- | src/common/weeconfig.c | 10 | ||||
-rw-r--r-- | src/common/weeconfig.h | 2 | ||||
-rw-r--r-- | src/gui/curses/gui-display.c | 20 | ||||
-rw-r--r-- | src/irc/irc-server.c | 10 |
8 files changed, 128 insertions, 9 deletions
diff --git a/src/common/command.c b/src/common/command.c index a20b5ea03..61765b570 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -97,6 +97,9 @@ t_weechat_command weechat_commands[] = { "unalias", N_("remove an alias"), N_("alias_name"), N_("alias_name: name of alias to remove"), 1, 1, NULL, weechat_cmd_unalias }, + { "unset", N_("reset config parameters"), + N_("option"), N_("option: name of an option"), + 1, 1, NULL, weechat_cmd_unset }, { "window", N_("manage windows"), N_("[action]"), N_("action: action to do:\n" @@ -1836,6 +1839,46 @@ weechat_cmd_unalias (char *arguments) } /* + * weechat_cmd_unset: reset options + */ + +int +weechat_cmd_unset (char *arguments) +{ + t_config_option *ptr_option; + + ptr_option = config_option_search (arguments); + 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, arguments); + } + else + { + if (config_option_set_value (ptr_option, "") == 0) + { + (void) (ptr_option->handler_change()); + gui_printf (NULL, "[%s]\n", config_get_section (ptr_option)); + gui_printf (NULL, " %s =\n", arguments); + } + else + gui_printf (NULL, _("%s option \"%s\" can not be reset (use " + "/set command to change this option)\n"), + WEECHAT_ERROR, arguments); + } + } + else + { + gui_printf (NULL, _("%s config option \"%s\" not found\n"), + WEECHAT_ERROR, arguments); + } + return 0; +} + +/* * weechat_cmd_window: manage windows */ diff --git a/src/common/command.h b/src/common/command.h index a8ecd8e3b..586cb7737 100644 --- a/src/common/command.h +++ b/src/common/command.h @@ -77,6 +77,7 @@ extern int weechat_cmd_save (int, char **); extern int weechat_cmd_server (int, char **); extern int weechat_cmd_set (char *); extern int weechat_cmd_unalias (char *); +extern int weechat_cmd_unset (char *); extern int weechat_cmd_window (int, char **); #endif /* command.h */ diff --git a/src/common/weechat.c b/src/common/weechat.c index 0e9724243..4c4ba7f6c 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -49,6 +49,8 @@ #include <sys/stat.h> #include <time.h> #include <signal.h> +#include <iconv.h> +#include <langinfo.h> #include "weechat.h" #include "weeconfig.h" @@ -62,6 +64,8 @@ int quit_weechat; /* = 1 if quit request from user... why ? :'( */ char *weechat_home; /* WeeChat home dir. (example: /home/toto/.weechat) */ FILE *weechat_log_file; /* WeeChat log file (~/.weechat/weechat.log) */ +char *local_charset = NULL; /* local charset, for example: ISO-8859-1 */ + int server_cmd_line; /* at least one server on WeeChat command line */ @@ -77,6 +81,49 @@ my_sigint () } /* + * weechat_convert_encoding: convert string to another encoding + */ + +char * +weechat_convert_encoding (char *from_code, char *to_code, char *string) +{ + iconv_t cd; + char *inbuf, *ptr_inbuf, *outbuf, *ptr_outbuf; + int inbytesleft, outbytesleft; + + if (from_code && from_code[0] && to_code && to_code[0] + && (strcasecmp(from_code, to_code) != 0)) + { + cd = iconv_open (to_code, from_code); + if (cd == (iconv_t)(-1)) + outbuf = strdup (string); + else + { + inbuf = strdup (string); + ptr_inbuf = inbuf; + inbytesleft = strlen (inbuf); + outbytesleft = inbytesleft * 4; + outbuf = (char *) malloc (outbytesleft + 2); + ptr_outbuf = outbuf; + iconv (cd, &ptr_inbuf, &inbytesleft, &ptr_outbuf, &outbytesleft); + if (inbytesleft != 0) + { + free (outbuf); + outbuf = strdup (string); + } + else + ptr_outbuf[0] = '\0'; + free (inbuf); + iconv_close (cd); + } + } + else + outbuf = strdup (string); + + return outbuf; +} + +/* * wee_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log) */ @@ -469,6 +516,8 @@ main (int argc, char *argv[]) textdomain (PACKAGE); #endif + local_charset = strdup (nl_langinfo (CODESET)); + signal (SIGINT, my_sigint); /* ignore SIGINT signal */ gui_pre_init (&argc, &argv); /* pre-initiliaze interface */ wee_init_vars (); /* initialize some variables */ diff --git a/src/common/weechat.h b/src/common/weechat.h index c2fdaab42..df8691433 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -102,7 +102,9 @@ extern int quit_weechat; extern char *weechat_home; +extern char *local_charset; +extern char *weechat_convert_encoding (char *, char *, char *); extern void wee_log_printf (char *, ...); extern void wee_shutdown (); diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index 05f8a6731..ea88d11b7 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -60,6 +60,8 @@ int cfg_look_set_title; int cfg_look_startup_logo; int cfg_look_startup_version; char *cfg_look_weechat_slogan; +char *cfg_look_charset_decode; +char *cfg_look_charset_encode; int cfg_look_color_nicks; int cfg_look_color_actions; int cfg_look_remove_colors_from_msgs; @@ -95,6 +97,14 @@ t_config_option weechat_options_look[] = N_("WeeChat slogan (if empty, slogan is not used)"), OPTION_TYPE_STRING, 0, 0, 0, "the geekest IRC client!", NULL, NULL, &cfg_look_weechat_slogan, config_change_noop }, + { "look_charset_decode", N_("charset for decoding messages from server"), + N_("charset for decoding messages from server, examples: UTF-8, ISO-8859-1 (if empty, messages are not converted)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &cfg_look_charset_decode, config_change_buffer_content }, + { "look_charset_encode", N_("charset for encoding messages sent to server"), + N_("charset for encoding messages sent to server, examples: UFT-8, ISO-8859-1 (if empty, local charset is used)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &cfg_look_charset_encode, config_change_buffer_content }, { "look_color_nicks", N_("display nick names with different colors"), N_("display nick names with different colors"), OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h index 15b822d9b..e9b3d26b3 100644 --- a/src/common/weeconfig.h +++ b/src/common/weeconfig.h @@ -77,6 +77,8 @@ extern int cfg_look_set_title; extern int cfg_look_startup_logo; extern int cfg_look_startup_version; extern char *cfg_look_weechat_slogan; +extern char *cfg_look_charset_decode; +extern char *cfg_look_charset_encode; extern int cfg_look_color_nicks; extern int cfg_look_color_actions; extern int cfg_look_remove_colors_from_msgs; diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index e74be4d7b..46638edcc 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -307,7 +307,7 @@ void gui_draw_buffer_title (t_gui_buffer *buffer, int erase) { t_gui_window *ptr_win; - char format[32]; + char format[32], *buf; if (!gui_ok) return; @@ -330,8 +330,13 @@ gui_draw_buffer_title (t_gui_buffer *buffer, int erase) { snprintf (format, 32, "%%-%ds", ptr_win->win_width); if (CHANNEL(buffer)->topic) - mvwprintw (ptr_win->win_title, 0, 0, format, - CHANNEL(buffer)->topic); + { + buf = weechat_convert_encoding (cfg_look_charset_decode, + local_charset, + CHANNEL(buffer)->topic); + mvwprintw (ptr_win->win_title, 0, 0, format, buf); + free (buf); + } } else { @@ -1993,7 +1998,7 @@ gui_printf_color_type (t_gui_buffer *buffer, int type, int color, char *message, { static char buf[8192]; char timestamp[16]; - char *pos, *buf2; + char *pos, *buf2, *buf3; int i, j; va_list argptr; static time_t seconds; @@ -2051,12 +2056,14 @@ gui_printf_color_type (t_gui_buffer *buffer, int type, int color, char *message, else buf2 = strdup (buf); + buf3 = weechat_convert_encoding (cfg_look_charset_decode, local_charset, buf2); + if (gui_init_ok) { seconds = time (NULL); date_tmp = localtime (&seconds); - pos = buf2 - 1; + pos = buf3 - 1; while (pos) { /* TODO: read timestamp format from config! */ @@ -2087,7 +2094,8 @@ gui_printf_color_type (t_gui_buffer *buffer, int type, int color, char *message, refresh ();*/ } else - printf ("%s", buf2); + printf ("%s", buf3); free (buf2); + free (buf3); } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 03c3ba8cf..2a9d184c1 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -39,6 +39,7 @@ #include "../common/weechat.h" #include "irc.h" +#include "../common/weeconfig.h" #include "../gui/gui.h" @@ -369,6 +370,7 @@ server_sendf (t_irc_server * server, char *fmt, ...) { va_list args; static char buffer[1024]; + char *buf2; int size_buf; if (!server) @@ -384,14 +386,16 @@ server_sendf (t_irc_server * server, char *fmt, ...) buffer[sizeof (buffer) - 1] = '\0'; if ((size_buf < 0) || (size_buf > (int) (sizeof (buffer) - 1))) size_buf = strlen (buffer); - buffer[size_buf - 2] = '\0'; #ifdef DEBUG + buffer[size_buf - 2] = '\0'; gui_printf (server->buffer, "[DEBUG] Sending to server >>> %s\n", buffer); - #endif buffer[size_buf - 2] = '\r'; - if (server_send (server, buffer, size_buf) <= 0) + #endif + buf2 = weechat_convert_encoding (local_charset, cfg_look_charset_encode, buffer); + if (server_send (server, buf2, strlen (buf2)) <= 0) gui_printf (server->buffer, _("%s error sending data to IRC server\n"), WEECHAT_ERROR); + free (buf2); } /* |