mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 21:36:37 +02:00
Added new default bar item "time"
This commit is contained in:
+90
-14
@@ -92,6 +92,7 @@ struct t_config_option *config_look_infobar;
|
||||
struct t_config_option *config_look_infobar_time_format;
|
||||
struct t_config_option *config_look_infobar_seconds;
|
||||
struct t_config_option *config_look_infobar_delay_highlight;
|
||||
struct t_config_option *config_look_item_time_format;
|
||||
struct t_config_option *config_look_hotlist_names_count;
|
||||
struct t_config_option *config_look_hotlist_names_level;
|
||||
struct t_config_option *config_look_hotlist_names_length;
|
||||
@@ -204,8 +205,12 @@ struct t_hook *config_day_change_timer = NULL;
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_save_on_exit ()
|
||||
config_change_save_on_exit (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
if (!config_look_save_on_exit)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
@@ -219,8 +224,12 @@ config_change_save_on_exit ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_title ()
|
||||
config_change_title (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
if (config_look_set_title)
|
||||
gui_window_title_set ();
|
||||
else
|
||||
@@ -232,8 +241,12 @@ config_change_title ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_buffers ()
|
||||
config_change_buffers (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
gui_window_refresh_windows ();
|
||||
}
|
||||
|
||||
@@ -242,8 +255,12 @@ config_change_buffers ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_buffer_content ()
|
||||
config_change_buffer_content (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
if (gui_ok)
|
||||
gui_window_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
@@ -253,8 +270,12 @@ config_change_buffer_content ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_buffer_time_format ()
|
||||
config_change_buffer_time_format (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
gui_chat_time_length = util_get_time_length (CONFIG_STRING(config_look_buffer_time_format));
|
||||
gui_chat_change_time_format ();
|
||||
if (gui_ok)
|
||||
@@ -266,8 +287,12 @@ config_change_buffer_time_format ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_hotlist ()
|
||||
config_change_hotlist (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
gui_hotlist_resort ();
|
||||
gui_status_refresh_needed = 1;
|
||||
}
|
||||
@@ -277,8 +302,12 @@ config_change_hotlist ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_read_marker ()
|
||||
config_change_read_marker (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
gui_window_redraw_all_buffers ();
|
||||
}
|
||||
|
||||
@@ -287,8 +316,12 @@ config_change_read_marker ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_prefix ()
|
||||
config_change_prefix (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
gui_chat_prefix_build ();
|
||||
}
|
||||
|
||||
@@ -297,8 +330,12 @@ config_change_prefix ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_color ()
|
||||
config_change_color (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
if (gui_ok)
|
||||
{
|
||||
gui_color_init_pairs ();
|
||||
@@ -312,8 +349,12 @@ config_change_color ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_nicks_colors ()
|
||||
config_change_nicks_colors (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
/* TODO: change nicks colors */
|
||||
/*
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
@@ -339,8 +380,34 @@ config_change_nicks_colors ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_infobar_seconds ()
|
||||
config_change_infobar_seconds (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
int seconds;
|
||||
|
||||
if (gui_infobar_refresh_timer)
|
||||
unhook (gui_infobar_refresh_timer);
|
||||
|
||||
seconds = (CONFIG_BOOLEAN(config_look_infobar_seconds)) ? 1 : 60;
|
||||
gui_infobar_refresh_timer = hook_timer (NULL, seconds * 1000, seconds, 0,
|
||||
gui_infobar_refresh_timer_cb, NULL);
|
||||
(void) gui_infobar_refresh_timer_cb ("force");
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_item_time_format: called when time format for time item changed
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_item_time_format (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
int seconds;
|
||||
|
||||
if (gui_infobar_refresh_timer)
|
||||
@@ -397,8 +464,12 @@ config_day_change_timer_cb (void *data)
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_day_change ()
|
||||
config_change_day_change (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
if (CONFIG_BOOLEAN(config_look_day_change))
|
||||
{
|
||||
if (!config_day_change_timer)
|
||||
@@ -882,6 +953,11 @@ config_weechat_init ()
|
||||
"infobar (0 = disable highlight notifications in "
|
||||
"infobar)"),
|
||||
NULL, 0, INT_MAX, "7", NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
config_look_item_time_format = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"item_time_format", "string",
|
||||
N_("time format for time item"),
|
||||
NULL, 0, 0, "%H:%M", NULL, NULL, &config_change_item_time_format, NULL, NULL, NULL);
|
||||
config_look_hotlist_names_count = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"hotlist_names_count", "integer",
|
||||
@@ -1595,8 +1671,8 @@ config_weechat_read ()
|
||||
rc = config_file_read (weechat_config_file);
|
||||
if (rc == 0)
|
||||
{
|
||||
config_change_infobar_seconds ();
|
||||
config_change_day_change ();
|
||||
config_change_infobar_seconds (NULL, NULL);
|
||||
config_change_day_change (NULL, NULL);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -76,6 +76,7 @@ extern struct t_config_option *config_look_infobar;
|
||||
extern struct t_config_option *config_look_infobar_time_format;
|
||||
extern struct t_config_option *config_look_infobar_seconds;
|
||||
extern struct t_config_option *config_look_infobar_delay_highlight;
|
||||
extern struct t_config_option *config_look_item_time_format;
|
||||
extern struct t_config_option *config_look_hotlist_names_count;
|
||||
extern struct t_config_option *config_look_hotlist_names_level;
|
||||
extern struct t_config_option *config_look_hotlist_names_length;
|
||||
|
||||
+4
-1
@@ -463,7 +463,10 @@ hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second,
|
||||
|
||||
if ((interval >= 1000) && (align_second > 0))
|
||||
{
|
||||
new_hook_timer->last_exec.tv_usec = 0;
|
||||
/* here we should use 0, but with this value timer is sometimes called
|
||||
before second has changed, so for displaying time, it may display
|
||||
2 times the same second, that's why we use 1000 micro seconds */
|
||||
new_hook_timer->last_exec.tv_usec = 1000;
|
||||
new_hook_timer->last_exec.tv_sec =
|
||||
new_hook_timer->last_exec.tv_sec -
|
||||
((new_hook_timer->last_exec.tv_sec - (tz.tz_minuteswest * 60)) %
|
||||
|
||||
+94
-20
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-config.h"
|
||||
@@ -44,10 +45,11 @@
|
||||
struct t_gui_bar_item *gui_bar_items = NULL; /* first bar item */
|
||||
struct t_gui_bar_item *last_gui_bar_item = NULL; /* last bar item */
|
||||
char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] =
|
||||
{ "buffer_count", "buffer_plugin", "buffer_name", "buffer_filter",
|
||||
{ "time", "buffer_count", "buffer_plugin", "buffer_name", "buffer_filter",
|
||||
"nicklist_count", "scroll", "hotlist"
|
||||
};
|
||||
struct t_gui_bar_item_hook *gui_bar_item_hooks = NULL;
|
||||
struct t_hook *gui_bar_item_timer = NULL;
|
||||
|
||||
|
||||
/*
|
||||
@@ -237,6 +239,42 @@ gui_bar_item_free_all_plugin (struct t_weechat_plugin *plugin)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_default_time: default item for time
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_bar_item_default_time (void *data, struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window,
|
||||
int max_width, int max_height)
|
||||
{
|
||||
time_t date;
|
||||
struct tm *local_time;
|
||||
char text_time[128], buf[512];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) item;
|
||||
(void) window;
|
||||
(void) max_width;
|
||||
(void) max_height;
|
||||
|
||||
date = time (NULL);
|
||||
local_time = localtime (&date);
|
||||
if (strftime (text_time, sizeof (text_time),
|
||||
CONFIG_STRING(config_look_item_time_format),
|
||||
local_time) == 0)
|
||||
return NULL;
|
||||
|
||||
snprintf (buf, sizeof (buf), "%s[%s%s%s] ",
|
||||
GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS),
|
||||
GUI_COLOR(GUI_COLOR_STATUS),
|
||||
text_time,
|
||||
GUI_COLOR(GUI_COLOR_STATUS_DELIMITERS));
|
||||
|
||||
return strdup (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_default_buffer_count: default item for number of buffers
|
||||
*/
|
||||
@@ -512,6 +550,35 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item,
|
||||
return strdup (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_timer_cb: timer callback
|
||||
*/
|
||||
|
||||
int
|
||||
gui_bar_item_timer_cb (void *data)
|
||||
{
|
||||
time_t date;
|
||||
struct tm *local_time;
|
||||
static char item_time_text[128] = { '\0' };
|
||||
char new_item_time_text[128];
|
||||
|
||||
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;
|
||||
|
||||
if (strcmp (new_item_time_text, item_time_text) != 0)
|
||||
{
|
||||
snprintf (item_time_text, sizeof (item_time_text),
|
||||
"%s", new_item_time_text);
|
||||
gui_bar_item_update ((char *)data);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_bar_item_signal_cb: callback when a signal is received, for rebuilding
|
||||
* an item
|
||||
@@ -557,64 +624,71 @@ gui_bar_item_hook (char *signal, char *item)
|
||||
void
|
||||
gui_bar_item_init ()
|
||||
{
|
||||
/* time */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_TIME],
|
||||
&gui_bar_item_default_time, NULL);
|
||||
gui_bar_item_timer = hook_timer (NULL, 1000, 1, 0, &gui_bar_item_timer_cb,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_TIME]);
|
||||
|
||||
/* buffer count */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT],
|
||||
&gui_bar_item_default_buffer_count, NULL);
|
||||
gui_bar_item_hook ("buffer_open",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT]);
|
||||
gui_bar_item_hook ("buffer_closed",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_COUNT]);
|
||||
|
||||
/* buffer plugin */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN],
|
||||
&gui_bar_item_default_buffer_plugin, NULL);
|
||||
gui_bar_item_hook ("buffer_switch",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_PLUGIN]);
|
||||
|
||||
/* buffer name */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME],
|
||||
&gui_bar_item_default_buffer_name, NULL);
|
||||
gui_bar_item_hook ("buffer_switch",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]);
|
||||
gui_bar_item_hook ("buffer_renamed",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]);
|
||||
gui_bar_item_hook ("buffer_moved",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_NAME]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_NAME]);
|
||||
|
||||
/* buffer filter */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_FILTER],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER],
|
||||
&gui_bar_item_default_buffer_filter, NULL);
|
||||
gui_bar_item_hook ("buffer_lines_hidden",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_FILTER]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER]);
|
||||
gui_bar_item_hook ("filters_*",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_BUFFER_FILTER]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_BUFFER_FILTER]);
|
||||
|
||||
/* nicklist count */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_NICKLIST_COUNT],
|
||||
&gui_bar_item_default_nicklist_count, NULL);
|
||||
gui_bar_item_hook ("buffer_switch",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_NICKLIST_COUNT]);
|
||||
gui_bar_item_hook ("nicklist_changed",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_NICKLIST_COUNT]);
|
||||
|
||||
/* scroll indicator */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_SCROLL],
|
||||
&gui_bar_item_default_scroll, NULL);
|
||||
gui_bar_item_hook ("window_scrolled",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_SCROLL]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_SCROLL]);
|
||||
|
||||
/* hotlist */
|
||||
gui_bar_item_new (NULL,
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST],
|
||||
gui_bar_item_names[GUI_BAR_ITEM_HOTLIST],
|
||||
&gui_bar_item_default_hotlist, NULL);
|
||||
gui_bar_item_hook ("hotlist_changed",
|
||||
gui_bar_item_names[GUI_BAR_ITEM_WEECHAT_HOTLIST]);
|
||||
gui_bar_item_names[GUI_BAR_ITEM_HOTLIST]);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -22,13 +22,14 @@
|
||||
|
||||
enum t_gui_bar_item_weechat
|
||||
{
|
||||
GUI_BAR_ITEM_WEECHAT_BUFFER_COUNT = 0,
|
||||
GUI_BAR_ITEM_WEECHAT_BUFFER_PLUGIN,
|
||||
GUI_BAR_ITEM_WEECHAT_BUFFER_NAME,
|
||||
GUI_BAR_ITEM_WEECHAT_BUFFER_FILTER,
|
||||
GUI_BAR_ITEM_WEECHAT_NICKLIST_COUNT,
|
||||
GUI_BAR_ITEM_WEECHAT_SCROLL,
|
||||
GUI_BAR_ITEM_WEECHAT_HOTLIST,
|
||||
GUI_BAR_ITEM_TIME = 0,
|
||||
GUI_BAR_ITEM_BUFFER_COUNT,
|
||||
GUI_BAR_ITEM_BUFFER_PLUGIN,
|
||||
GUI_BAR_ITEM_BUFFER_NAME,
|
||||
GUI_BAR_ITEM_BUFFER_FILTER,
|
||||
GUI_BAR_ITEM_NICKLIST_COUNT,
|
||||
GUI_BAR_ITEM_SCROLL,
|
||||
GUI_BAR_ITEM_HOTLIST,
|
||||
/* number of bar items */
|
||||
GUI_BAR_NUM_ITEMS,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user