1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 13:26:38 +02:00

core: add option weechat.look.hotlist_add_conditions, remove option weechat.look.hotlist_add_buffer_if_away

This commit is contained in:
Sebastien Helleu
2014-03-06 19:29:08 +01:00
parent 6fbba54bf0
commit dc2365104f
25 changed files with 249 additions and 151 deletions
+4
View File
@@ -49,6 +49,7 @@
#include "../gui-color.h"
#include "../gui-cursor.h"
#include "../gui-filter.h"
#include "../gui-hotlist.h"
#include "../gui-input.h"
#include "../gui-layout.h"
#include "../gui-line.h"
@@ -583,6 +584,9 @@ gui_main_end (int clean_exit)
/* free some variables used for nicklist */
gui_nicklist_end ();
/* free some variables used for hotlist */
gui_hotlist_end ();
}
/* end of Curses output */
+87 -13
View File
@@ -29,6 +29,7 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-eval.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-hdata.h"
#include "../core/wee-hook.h"
@@ -45,6 +46,9 @@
struct t_gui_hotlist *gui_hotlist = NULL;
struct t_gui_hotlist *last_gui_hotlist = NULL;
struct t_gui_buffer *gui_hotlist_initial_buffer = NULL;
struct t_hashtable *gui_hotlist_hashtable_add_conditions_pointers = NULL;
struct t_hashtable *gui_hotlist_hashtable_add_conditions_vars = NULL;
struct t_hashtable *gui_hotlist_hashtable_add_conditions_options = NULL;
int gui_add_hotlist = 1; /* 0 is for temporarily disable */
/* hotlist add for all buffers */
@@ -289,8 +293,8 @@ gui_hotlist_add (struct t_gui_buffer *buffer,
struct timeval *creation_time)
{
struct t_gui_hotlist *new_hotlist, *ptr_hotlist;
int i, count[GUI_HOTLIST_NUM_PRIORITIES];
const char *away;
int i, count[GUI_HOTLIST_NUM_PRIORITIES], rc;
char *value, str_value[32];
if (!buffer || !gui_add_hotlist)
return NULL;
@@ -299,13 +303,6 @@ gui_hotlist_add (struct t_gui_buffer *buffer,
if (weechat_upgrading && (buffer == gui_buffer_search_main ()))
return NULL;
/* do not add buffer if it is displayed and away is not set */
away = hashtable_get (buffer->local_variables, "away");
if ((buffer->num_displayed > 0)
&& ((!away || !away[0])
|| !CONFIG_BOOLEAN(config_look_hotlist_add_buffer_if_away)))
return NULL;
if (priority > GUI_HOTLIST_MAX)
priority = GUI_HOTLIST_MAX;
@@ -313,6 +310,63 @@ gui_hotlist_add (struct t_gui_buffer *buffer,
if (!gui_hotlist_check_buffer_notify (buffer, priority))
return NULL;
/* create hashtable if needed (to evaluate conditions) */
if (!gui_hotlist_hashtable_add_conditions_pointers)
{
gui_hotlist_hashtable_add_conditions_pointers = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL,
NULL);
if (!gui_hotlist_hashtable_add_conditions_pointers)
return NULL;
}
if (!gui_hotlist_hashtable_add_conditions_vars)
{
gui_hotlist_hashtable_add_conditions_vars = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
if (!gui_hotlist_hashtable_add_conditions_vars)
return NULL;
}
if (!gui_hotlist_hashtable_add_conditions_options)
{
gui_hotlist_hashtable_add_conditions_options = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
if (!gui_hotlist_hashtable_add_conditions_options)
return NULL;
hashtable_set (gui_hotlist_hashtable_add_conditions_options,
"type", "condition");
}
/* set data in hashtables */
hashtable_set (gui_hotlist_hashtable_add_conditions_pointers,
"window", gui_current_window);
hashtable_set (gui_hotlist_hashtable_add_conditions_pointers,
"buffer", buffer);
snprintf (str_value, sizeof (str_value), "%d", priority);
hashtable_set (gui_hotlist_hashtable_add_conditions_vars,
"priority", str_value);
/* check if conditions are true */
value = eval_expression (CONFIG_STRING(config_look_hotlist_add_conditions),
gui_hotlist_hashtable_add_conditions_pointers,
gui_hotlist_hashtable_add_conditions_vars,
gui_hotlist_hashtable_add_conditions_options);
rc = (value && (strcmp (value, "1") == 0));
if (value)
free (value);
if (!rc)
return NULL;
/* init count */
for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++)
{
@@ -340,11 +394,7 @@ gui_hotlist_add (struct t_gui_buffer *buffer,
new_hotlist = malloc (sizeof (*new_hotlist));
if (!new_hotlist)
{
log_printf (_("Error: not enough memory to add a buffer to "
"hotlist"));
return NULL;
}
new_hotlist->priority = priority;
if (creation_time)
@@ -595,3 +645,27 @@ gui_hotlist_print_log ()
log_printf (" next_hotlist . . . . . : 0x%lx", ptr_hotlist->next_hotlist);
}
}
/*
* Ends hotlist.
*/
void
gui_hotlist_end ()
{
if (gui_hotlist_hashtable_add_conditions_pointers)
{
hashtable_free (gui_hotlist_hashtable_add_conditions_pointers);
gui_hotlist_hashtable_add_conditions_pointers = NULL;
}
if (gui_hotlist_hashtable_add_conditions_vars)
{
hashtable_free (gui_hotlist_hashtable_add_conditions_vars);
gui_hotlist_hashtable_add_conditions_vars = NULL;
}
if (gui_hotlist_hashtable_add_conditions_options)
{
hashtable_free (gui_hotlist_hashtable_add_conditions_options);
gui_hotlist_hashtable_add_conditions_options = NULL;
}
}
+1
View File
@@ -65,5 +65,6 @@ extern struct t_hdata *gui_hotlist_hdata_hotlist_cb (void *data,
extern int gui_hotlist_add_to_infolist (struct t_infolist *infolist,
struct t_gui_hotlist *hotlist);
extern void gui_hotlist_print_log ();
extern void gui_hotlist_end ();
#endif /* __WEECHAT_GUI_HOTLIST_H */