1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 11:13:12 +02:00

core: evaluate content of option "weechat.look.item_time_format" (issue #791)

This commit is contained in:
Sébastien Helleu
2016-09-03 08:28:05 +02:00
parent f4b96dfa0f
commit 0572d0c4f5
23 changed files with 159 additions and 230 deletions
+54 -2
View File
@@ -37,6 +37,7 @@
#include "weechat.h"
#include "wee-config.h"
#include "wee-eval.h"
#include "wee-hashtable.h"
#include "wee-hook.h"
#include "wee-log.h"
@@ -314,6 +315,7 @@ int config_word_chars_input_count = 0;
char **config_nick_colors = NULL;
int config_num_nick_colors = 0;
struct t_hashtable *config_hashtable_nick_color_force = NULL;
char *config_item_time_evaluated = NULL;
/*
@@ -953,6 +955,49 @@ config_change_item_away (const void *pointer, void *data,
gui_bar_item_update ("away");
}
/*
* Callback for changes on options "weechat.look.item_time_format".
*/
void
config_change_item_time_format (const void *pointer, void *data,
struct t_config_option *option)
{
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
if (config_item_time_evaluated)
free (config_item_time_evaluated);
config_item_time_evaluated = eval_expression (
CONFIG_STRING(config_look_item_time_format), NULL, NULL, NULL);
config_change_buffer_content (NULL, NULL, NULL);
}
/*
* Gets the current time formatted for the bar item status.
*/
void
config_get_item_time (char *text_time, int max_length)
{
time_t date;
struct tm *local_time;
if (!config_item_time_evaluated)
config_change_item_time_format (NULL, NULL, NULL);
text_time[0] = '\0';
date = time (NULL);
local_time = localtime (&date);
strftime (text_time, max_length,
config_item_time_evaluated,
local_time);
}
/*
* Callback for changes on option "weechat.look.paste_bracketed".
*/
@@ -2948,10 +2993,11 @@ config_weechat_init_options ()
weechat_config_file, ptr_section,
"item_time_format", "string",
N_("time format for \"time\" bar item (see man strftime for date/time "
"specifiers)"),
"specifiers) (note: content is evaluated, so you can use colors "
"with format \"${color:xxx}\", see /help eval)"),
NULL, 0, 0, "%H:%M", NULL, 0,
NULL, NULL, NULL,
&config_change_buffer_content, NULL, NULL,
&config_change_item_time_format, NULL, NULL,
NULL, NULL, NULL);
config_look_jump_current_to_previous_buffer = config_file_new_option (
weechat_config_file, ptr_section,
@@ -4509,4 +4555,10 @@ config_weechat_free ()
hashtable_free (config_hashtable_nick_color_force);
config_hashtable_nick_color_force = NULL;
}
if (config_item_time_evaluated)
{
free (config_item_time_evaluated);
config_item_time_evaluated = NULL;
}
}
+1
View File
@@ -358,6 +358,7 @@ extern int config_weechat_debug_set (const char *plugin_name,
extern void config_weechat_debug_set_all ();
extern int config_weechat_notify_set (struct t_gui_buffer *buffer,
const char *notify);
extern void config_get_item_time (char *text_time, int max_length);
extern int config_weechat_init ();
extern int config_weechat_read ();
extern int config_weechat_write ();
+3 -16
View File
@@ -26,7 +26,6 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include "../core/weechat.h"
#include "../core/wee-arraylist.h"
@@ -980,8 +979,6 @@ gui_bar_item_time_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
struct t_hashtable *extra_info)
{
time_t date;
struct tm *local_time;
char text_time[128], text_time2[128];
/* make C compiler happy */
@@ -992,11 +989,8 @@ gui_bar_item_time_cb (const void *pointer, void *data,
(void) buffer;
(void) extra_info;
date = time (NULL);
local_time = localtime (&date);
if (strftime (text_time, sizeof (text_time),
CONFIG_STRING(config_look_item_time_format),
local_time) == 0)
config_get_item_time (text_time, sizeof (text_time));
if (!text_time[0])
return NULL;
snprintf (text_time2, sizeof (text_time2), "%s%s",
@@ -2017,8 +2011,6 @@ gui_bar_item_focus_buffer_nicklist_cb (const void *pointer,
int
gui_bar_item_timer_cb (const void *pointer, void *data, int remaining_calls)
{
time_t date;
struct tm *local_time;
static char item_time_text[128] = { '\0' };
char new_item_time_text[128];
@@ -2026,12 +2018,7 @@ gui_bar_item_timer_cb (const void *pointer, void *data, int remaining_calls)
(void) data;
(void) remaining_calls;
date = time (NULL);
local_time = localtime (&date);
if (strftime (new_item_time_text, sizeof (new_item_time_text),
CONFIG_STRING(config_look_item_time_format),
local_time) == 0)
return WEECHAT_RC_OK;
config_get_item_time (new_item_time_text, sizeof (new_item_time_text));
/*
* we update item only if it changed since last time