diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-02-09 17:19:14 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-02-09 17:19:14 +0100 |
commit | 785066832761966676d5382b047b9e2ef2d1c045 (patch) | |
tree | a322394f3385e951a77bdc935addc008fb6387f0 /src | |
parent | daee18621e752a1047337acbfd56e3d40d12976f (diff) | |
download | weechat-785066832761966676d5382b047b9e2ef2d1c045.zip |
Add new option weechat.look.time_format to customize default format for date/time displayed (localized date by default), add function weechat_util_get_time_string in plugin API (patch #6914)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 113 | ||||
-rw-r--r-- | src/core/wee-command.h | 3 | ||||
-rw-r--r-- | src/core/wee-config.c | 9 | ||||
-rw-r--r-- | src/core/wee-config.h | 1 | ||||
-rw-r--r-- | src/core/wee-util.c | 18 | ||||
-rw-r--r-- | src/core/wee-util.h | 1 | ||||
-rw-r--r-- | src/core/weechat.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-ctcp.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 20 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 4 | ||||
-rw-r--r-- | src/plugins/plugin.c | 7 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 23 |
12 files changed, 145 insertions, 59 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 2e2c48fd1..c862ce858 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -38,12 +38,13 @@ #include "wee-debug.h" #include "wee-hook.h" #include "wee-input.h" +#include "wee-list.h" #include "wee-log.h" #include "wee-proxy.h" #include "wee-string.h" #include "wee-upgrade.h" #include "wee-utf8.h" -#include "wee-list.h" +#include "wee-util.h" #include "../gui/gui-bar.h" #include "../gui/gui-bar-item.h" #include "../gui/gui-buffer.h" @@ -3514,7 +3515,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer, if ((argc >= 2) && (string_strcasecmp (argv[1], "-o") == 0)) { snprintf (string, sizeof (string), - _("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"), + "WeeChat uptime: %d %s %02d:%02d:%02d, started on %s", day, NG_("day", "days", day), hour, @@ -3524,6 +3525,18 @@ command_uptime (void *data, struct t_gui_buffer *buffer, string[strlen (string) - 1] = '\0'; input_data (buffer, string); } + else if ((argc >= 2) && (string_strcasecmp (argv[1], "-ol") == 0)) + { + snprintf (string, sizeof (string), + _("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"), + day, + NG_("day", "days", day), + hour, + min, + sec, + util_get_time_string (&weechat_start_time)); + input_data (buffer, string); + } else { gui_chat_printf (NULL, @@ -3544,7 +3557,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer, sec, GUI_COLOR(GUI_COLOR_CHAT), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - ctime (&weechat_start_time)); + util_get_time_string (&weechat_start_time)); } return WEECHAT_RC_OK; @@ -3556,28 +3569,52 @@ command_uptime (void *data, struct t_gui_buffer *buffer, void command_version_display (struct t_gui_buffer *buffer, - int send_to_buffer_as_input) + int send_to_buffer_as_input, + int translated_string) { char string[512]; if (send_to_buffer_as_input) { - snprintf (string, sizeof (string), - "WeeChat %s [%s %s %s]", - PACKAGE_VERSION, - _("compiled on"), - __DATE__, - __TIME__); - input_data (buffer, string); - if (weechat_upgrade_count > 0) + if (translated_string) { snprintf (string, sizeof (string), - _("Upgraded %d %s, first start: %s"), - weechat_upgrade_count, - NG_("time", "times", weechat_upgrade_count), - ctime (&weechat_start_time)); - string[strlen (string) - 1] = '\0'; + "WeeChat %s [%s %s %s]", + PACKAGE_VERSION, + _("compiled on"), + __DATE__, + __TIME__); input_data (buffer, string); + if (weechat_upgrade_count > 0) + { + snprintf (string, sizeof (string), + _("Upgraded %d %s, first start: %s"), + weechat_upgrade_count, + /* TRANSLATORS: text is: "upgraded xx times" */ + NG_("time", "times", weechat_upgrade_count), + util_get_time_string (&weechat_start_time)); + input_data (buffer, string); + } + } + else + { + snprintf (string, sizeof (string), + "WeeChat %s [%s %s %s]", + PACKAGE_VERSION, + "compiled on", + __DATE__, + __TIME__); + input_data (buffer, string); + if (weechat_upgrade_count > 0) + { + snprintf (string, sizeof (string), + "Upgraded %d %s, first start: %s", + weechat_upgrade_count, + (weechat_upgrade_count > 1) ? "times" : "time", + ctime (&weechat_start_time)); + string[strlen (string) - 1] = '\0'; + input_data (buffer, string); + } } } else @@ -3598,7 +3635,7 @@ command_version_display (struct t_gui_buffer *buffer, weechat_upgrade_count, /* TRANSLATORS: text is: "upgraded xx times" */ NG_("time", "times", weechat_upgrade_count), - ctime (&weechat_start_time)); + util_get_time_string (&weechat_start_time)); } } } @@ -3611,16 +3648,28 @@ int command_version (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - int send_to_buffer_as_input; + int send_to_buffer_as_input, translated_string; /* make C compiler happy */ (void) data; (void) argv_eol; + + send_to_buffer_as_input = 0; + translated_string = 0; + + if (argc >= 2) + { + if (string_strcasecmp (argv[1], "-o") == 0) + send_to_buffer_as_input = 1; + else if (string_strcasecmp (argv[1], "-ol") == 0) + { + send_to_buffer_as_input = 1; + translated_string = 1; + } + } - send_to_buffer_as_input = ((argc >= 2) - && (string_strcasecmp (argv[1], "-o") == 0)); - - command_version_display (buffer, send_to_buffer_as_input); + command_version_display (buffer, send_to_buffer_as_input, + translated_string); return WEECHAT_RC_OK; } @@ -4424,15 +4473,21 @@ command_init () &command_upgrade, NULL); hook_command (NULL, "uptime", N_("show WeeChat uptime"), - N_("[-o]"), - N_("-o: send uptime to current buffer as input"), - "-o", + "[-o | -ol]", + N_(" -o: send uptime to current buffer as input (english " + "string)\n" + "-ol: send uptime to current buffer as input (translated " + "string)"), + "-o|-ol", &command_uptime, NULL); hook_command (NULL, "version", N_("show WeeChat version and compilation date"), - N_("[-o]"), - N_("-o: send version to current buffer as input"), - "-o", + "[-o | -ol]", + N_(" -o: send version to current buffer as input (english " + "string)\n" + "-ol: send version to current buffer as input (translated " + "string)"), + "-o|-ol", &command_version, NULL); hook_command (NULL, "wait", N_("schedule a command execution in future"), diff --git a/src/core/wee-command.h b/src/core/wee-command.h index fab7d1e14..b689add38 100644 --- a/src/core/wee-command.h +++ b/src/core/wee-command.h @@ -27,6 +27,7 @@ extern int command_reload (void *data, struct t_gui_buffer *buffer, extern void command_init (); extern void command_startup (int plugins_looaded); extern void command_version_display (struct t_gui_buffer *buffer, - int send_to_buffer_as_input); + int send_to_buffer_as_input, + int translated_string); #endif /* wee-command.h */ diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 4436a9526..fa8f4a5b7 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -105,6 +105,7 @@ struct t_config_option *config_look_scroll_amount; struct t_config_option *config_look_scroll_page_percent; struct t_config_option *config_look_search_text_not_found_alert; struct t_config_option *config_look_set_title; +struct t_config_option *config_look_time_format; /* config, colors section */ @@ -1217,7 +1218,7 @@ config_weechat_init_options () config_look_buffer_time_format = config_file_new_option ( weechat_config_file, ptr_section, "buffer_time_format", "string", - N_("time format for buffers"), + N_("time format for each line displayed in buffers"), NULL, 0, 0, "%H:%M:%S", NULL, 0, NULL, NULL, &config_change_buffer_time_format, NULL, NULL, NULL); config_look_color_nicks_number = config_file_new_option ( weechat_config_file, ptr_section, @@ -1430,6 +1431,12 @@ config_weechat_init_options () N_("set title for window (terminal for Curses GUI) with " "name and version"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_title, NULL, NULL, NULL); + config_look_time_format = config_file_new_option ( + weechat_config_file, ptr_section, + "time_format", "string", + N_("time format for dates converted to strings and displayed in " + "messages"), + NULL, 0, 0, "%a, %d %b %Y %T", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); /* colors */ ptr_section = config_file_new_section (weechat_config_file, "color", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 6165f188f..b9337f051 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -120,6 +120,7 @@ extern struct t_config_option *config_look_scroll_amount; extern struct t_config_option *config_look_scroll_page_percent; extern struct t_config_option *config_look_search_text_not_found_alert; extern struct t_config_option *config_look_set_title; +extern struct t_config_option *config_look_time_format; extern struct t_config_option *config_color_separator; extern struct t_config_option *config_color_bar_more; diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 9918e6d6d..82f565c13 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -124,6 +124,24 @@ util_get_time_length (const char *time_format) } /* + * util_get_time_string: converts date to a string, using format of option + * weechat.look.time_format (can be localized) + */ + +char * +util_get_time_string (const time_t *date) +{ + struct tm *local_time; + static char text_time[128]; + + local_time = localtime (date); + strftime (text_time, sizeof (text_time), + CONFIG_STRING(config_look_time_format), local_time); + + return text_time; +} + +/* * util_catch_signal: catch a signal */ diff --git a/src/core/wee-util.h b/src/core/wee-util.h index 8a41eb551..5f74e15eb 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -24,6 +24,7 @@ extern int util_timeval_cmp (struct timeval *tv1, struct timeval *tv2); extern long util_timeval_diff (struct timeval *tv1, struct timeval *tv2); extern void util_timeval_add (struct timeval *tv, long interval); extern int util_get_time_length (const char *time_format); +extern char *util_get_time_string (const time_t *date); extern void util_catch_signal (int signum, void (*handler)(int)); extern int util_mkdir_home (const char *directory, int mode); extern int util_mkdir (const char *directory, int mode); diff --git a/src/core/weechat.c b/src/core/weechat.c index b8eee115f..177b2fc42 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -323,7 +323,7 @@ weechat_welcome_message () } if (CONFIG_BOOLEAN(config_startup_display_version)) { - command_version_display (NULL, 0); + command_version_display (NULL, 0, 0); } if (CONFIG_BOOLEAN(config_startup_display_logo) || (CONFIG_STRING(config_startup_weechat_slogan) diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c index 459ab2fee..85b1919e7 100644 --- a/src/plugins/irc/irc-ctcp.c +++ b/src/plugins/irc/irc-ctcp.c @@ -338,8 +338,7 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format) /* time */ now = time (NULL); - snprintf (buf, sizeof (buf), "%s", - ctime (&now)); + snprintf (buf, sizeof (buf), "%s", ctime (&now)); buf[strlen (buf) - 1] = '\0'; temp = weechat_string_replace (res, "$time", buf); free (res); diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 27b98c846..3cad0588b 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1095,8 +1095,8 @@ irc_protocol_cmd_pong (struct t_irc_server *server, const char *command, /* calculate lag (time diff with lag check) */ old_lag = server->lag; gettimeofday (&tv, NULL); - server->lag = (int) weechat_timeval_diff (&(server->lag_check_time), - &tv); + server->lag = (int) weechat_util_timeval_diff (&(server->lag_check_time), + &tv); if (old_lag != server->lag) weechat_bar_item_update ("lag"); @@ -2122,7 +2122,7 @@ irc_protocol_cmd_317 (struct t_irc_server *server, const char *command, IRC_COLOR_CHAT, NG_("second", "seconds", sec), IRC_COLOR_CHAT_CHANNEL, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } else { @@ -2150,7 +2150,7 @@ irc_protocol_cmd_317 (struct t_irc_server *server, const char *command, IRC_COLOR_CHAT, NG_("second", "seconds", sec), IRC_COLOR_CHAT_CHANNEL, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } return WEECHAT_RC_OK; @@ -2422,7 +2422,7 @@ irc_protocol_cmd_329 (struct t_irc_server *server, const char *command, irc_protocol_tags (command, "irc_numeric"), _("%sChannel created on %s"), weechat_prefix ("network"), - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); ptr_channel->display_creation_date = 0; } } @@ -2435,7 +2435,7 @@ irc_protocol_cmd_329 (struct t_irc_server *server, const char *command, IRC_COLOR_CHAT_CHANNEL, argv[3], IRC_COLOR_CHAT, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } return WEECHAT_RC_OK; @@ -2587,7 +2587,7 @@ irc_protocol_cmd_333 (struct t_irc_server *server, const char *command, IRC_COLOR_NICK_IN_SERVER_MESSAGE(ptr_nick), argv[4], IRC_COLOR_CHAT, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } else { @@ -2601,7 +2601,7 @@ irc_protocol_cmd_333 (struct t_irc_server *server, const char *command, IRC_COLOR_NICK_IN_SERVER_MESSAGE(ptr_nick), argv[4], IRC_COLOR_CHAT, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } return WEECHAT_RC_OK; @@ -2776,7 +2776,7 @@ irc_protocol_cmd_348 (struct t_irc_server *server, const char *command, irc_protocol_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } else { @@ -3279,7 +3279,7 @@ irc_protocol_cmd_367 (struct t_irc_server *server, const char *command, irc_protocol_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT, - ctime (&datetime)); + weechat_util_get_time_string (&datetime)); } else { diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index b757f6e70..0c1b8da7d 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -1751,8 +1751,8 @@ irc_server_timer_cb (void *data, int remaining_calls) && (weechat_config_integer (irc_config_network_lag_disconnect) > 0)) { gettimeofday (&tv, NULL); - diff = (int) weechat_timeval_diff (&(ptr_server->lag_check_time), - &tv); + diff = (int) weechat_util_timeval_diff (&(ptr_server->lag_check_time), + &tv); if (diff / 1000 > weechat_config_integer (irc_config_network_lag_disconnect) * 60) { weechat_printf (ptr_server->buffer, diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index a44bfb825..21a9437ec 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -409,9 +409,10 @@ plugin_load (const char *filename) new_plugin->exec_on_files = &util_exec_on_files; new_plugin->file_get_content = &util_file_get_content; - new_plugin->timeval_cmp = &util_timeval_cmp; - new_plugin->timeval_diff = &util_timeval_diff; - new_plugin->timeval_add = &util_timeval_add; + new_plugin->util_timeval_cmp = &util_timeval_cmp; + new_plugin->util_timeval_diff = &util_timeval_diff; + new_plugin->util_timeval_add = &util_timeval_add; + new_plugin->util_get_time_string = &util_get_time_string; new_plugin->list_new = &weelist_new; new_plugin->list_add = &weelist_add; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 575911703..5fafeec0c 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -34,7 +34,7 @@ struct t_weelist; struct timeval; /* API version (used to check that plugin has same API and can be loaded) */ -#define WEECHAT_PLUGIN_API_VERSION "20091218-01" +#define WEECHAT_PLUGIN_API_VERSION "20100209-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -199,9 +199,10 @@ struct t_weechat_plugin char *(*file_get_content) (const char *filename); /* util */ - int (*timeval_cmp) (struct timeval *tv1, struct timeval *tv2); - long (*timeval_diff) (struct timeval *tv1, struct timeval *tv2); - void (*timeval_add) (struct timeval *tv, long interval); + int (*util_timeval_cmp) (struct timeval *tv1, struct timeval *tv2); + long (*util_timeval_diff) (struct timeval *tv1, struct timeval *tv2); + void (*util_timeval_add) (struct timeval *tv, long interval); + char *(*util_get_time_string) (const time_t *date); /* sorted lists */ struct t_weelist *(*list_new) (); @@ -765,12 +766,14 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->file_get_content(__filename) /* util */ -#define weechat_timeval_cmp(__time1, __time2) \ - weechat_plugin->timeval_cmp(__time1, __time2) -#define weechat_timeval_diff(__time1, __time2) \ - weechat_plugin->timeval_diff(__time1, __time2) -#define weechat_timeval_add(__time, __interval) \ - weechat_plugin->timeval_add(__time, __interval) +#define weechat_util_timeval_cmp(__time1, __time2) \ + weechat_plugin->util_timeval_cmp(__time1, __time2) +#define weechat_util_timeval_diff(__time1, __time2) \ + weechat_plugin->util_timeval_diff(__time1, __time2) +#define weechat_util_timeval_add(__time, __interval) \ + weechat_plugin->util_timeval_add(__time, __interval) +#define weechat_util_get_time_string(__date) \ + weechat_plugin->util_get_time_string(__date) /* sorted list */ #define weechat_list_new() \ |