summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-config.c18
-rw-r--r--src/core/wee-config.h2
-rw-r--r--src/gui/curses/gui-curses-main.c4
-rw-r--r--src/gui/gui-hotlist.c100
-rw-r--r--src/gui/gui-hotlist.h1
5 files changed, 105 insertions, 20 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index c7187d980..7aee73825 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -113,6 +113,7 @@ struct t_config_option *config_look_highlight;
struct t_config_option *config_look_highlight_regex;
struct t_config_option *config_look_highlight_tags;
struct t_config_option *config_look_hotlist_add_buffer_if_away;
+struct t_config_option *config_look_hotlist_add_conditions;
struct t_config_option *config_look_hotlist_buffer_separator;
struct t_config_option *config_look_hotlist_count_max;
struct t_config_option *config_look_hotlist_count_min_msg;
@@ -2293,12 +2294,17 @@ config_weechat_init_options ()
"messages from nick \"FlashCode\", \"irc_notice+nick_toto*\" for "
"notices from a nick starting with \"toto\""),
NULL, 0, 0, "", NULL, 0, NULL, NULL, &config_change_highlight_tags, NULL, NULL, NULL);
- config_look_hotlist_add_buffer_if_away = config_file_new_option (
- weechat_config_file, ptr_section,
- "hotlist_add_buffer_if_away", "boolean",
- N_("add any buffer to hotlist (including current or visible buffers) "
- "if local variable \"away\" is set on buffer"),
- NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+ config_look_hotlist_add_conditions = config_file_new_option (
+ weechat_config_file, ptr_section,
+ "hotlist_add_conditions", "string",
+ N_("conditions to add a buffer in hotlist (if notify level is OK for "
+ "the buffer); you can use in these conditions: \"window\" (current "
+ "window pointer), \"buffer\" (buffer pointer to add in hotlist), "
+ "\"priority\" (0 = low, 1 = message, 2 = private, 3 = highlight); "
+ "by default a buffer is added to hotlist if you are away, or if the "
+ "buffer is not visible on screen (not displayed in any window)"),
+ NULL, 0, 0, "${away} || ${buffer.num_displayed} == 0",
+ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_hotlist_buffer_separator = config_file_new_option (
weechat_config_file, ptr_section,
"hotlist_buffer_separator", "string",
diff --git a/src/core/wee-config.h b/src/core/wee-config.h
index 11e47c0da..ac4c79d24 100644
--- a/src/core/wee-config.h
+++ b/src/core/wee-config.h
@@ -144,7 +144,7 @@ extern struct t_config_option *config_look_emphasized_attributes;
extern struct t_config_option *config_look_highlight;
extern struct t_config_option *config_look_highlight_regex;
extern struct t_config_option *config_look_highlight_tags;
-extern struct t_config_option *config_look_hotlist_add_buffer_if_away;
+extern struct t_config_option *config_look_hotlist_add_conditions;
extern struct t_config_option *config_look_hotlist_buffer_separator;
extern struct t_config_option *config_look_hotlist_count_max;
extern struct t_config_option *config_look_hotlist_count_min_msg;
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c
index 3a0f27435..8bfd31882 100644
--- a/src/gui/curses/gui-curses-main.c
+++ b/src/gui/curses/gui-curses-main.c
@@ -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 */
diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c
index b1b570cdc..468785566 100644
--- a/src/gui/gui-hotlist.c
+++ b/src/gui/gui-hotlist.c
@@ -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;
+ }
+}
diff --git a/src/gui/gui-hotlist.h b/src/gui/gui-hotlist.h
index d78b7a570..89405a78b 100644
--- a/src/gui/gui-hotlist.h
+++ b/src/gui/gui-hotlist.h
@@ -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 */