mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 11:43:13 +02:00
core: add option add in command /hotlist
This commit is contained in:
+28
-5
@@ -3275,6 +3275,8 @@ COMMAND_CALLBACK(history)
|
||||
|
||||
COMMAND_CALLBACK(hotlist)
|
||||
{
|
||||
int priority;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
@@ -3282,6 +3284,19 @@ COMMAND_CALLBACK(hotlist)
|
||||
|
||||
COMMAND_MIN_ARGS(2, "");
|
||||
|
||||
if (string_strcasecmp (argv[1], "add") == 0)
|
||||
{
|
||||
priority = GUI_HOTLIST_LOW;
|
||||
if (argc > 2)
|
||||
{
|
||||
priority = gui_hotlist_search_priority (argv[2]);
|
||||
if (priority < 0)
|
||||
COMMAND_ERROR;
|
||||
}
|
||||
gui_hotlist_add (buffer, priority, NULL, 0);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (string_strcasecmp (argv[1], "clear") == 0)
|
||||
{
|
||||
gui_hotlist_clear_level_string (buffer, (argc > 2) ? argv[2] : NULL);
|
||||
@@ -8067,17 +8082,25 @@ command_init ()
|
||||
hook_command (
|
||||
NULL, "hotlist",
|
||||
N_("manage hotlist"),
|
||||
N_("clear [<level>] || remove || restore [-all]"),
|
||||
N_("clear: clear hotlist\n"
|
||||
"level: \"lowest\" to clear only lowest level in hotlist, "
|
||||
N_("add [low|message|private|highlight]"
|
||||
" || clear [<level>]"
|
||||
" || remove"
|
||||
" || restore [-all]"),
|
||||
N_(" add: add current buffer in hotlist (default level: \"low\", "
|
||||
"conditions defined in option weechat.look.hotlist_add_conditions "
|
||||
"are NOT checked)\n"
|
||||
" clear: clear hotlist\n"
|
||||
" level: \"lowest\" to clear only lowest level in hotlist, "
|
||||
"highest\" to clear only highest level in hotlist, or level mask: "
|
||||
"integer which is a combination of 1=join/part, 2=message, "
|
||||
"4=private, 8=highlight)\n"
|
||||
"remove: remove current buffer from hotlist\n"
|
||||
" remove: remove current buffer from hotlist\n"
|
||||
"restore: restore latest hotlist removed in the current buffer "
|
||||
"(or all buffers with -all)"),
|
||||
"add low|message|private|highlight || "
|
||||
"clear 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|lowest|highest || "
|
||||
"remove || restore -all",
|
||||
"remove || "
|
||||
"restore -all",
|
||||
&command_hotlist, NULL, NULL);
|
||||
/*
|
||||
* give high priority (50000) so that an alias will not take precedence
|
||||
|
||||
@@ -769,7 +769,8 @@ upgrade_weechat_read_hotlist (struct t_infolist *infolist)
|
||||
memcpy (&creation_time, buf, size);
|
||||
new_hotlist = gui_hotlist_add (ptr_buffer,
|
||||
infolist_integer (infolist, "priority"),
|
||||
&creation_time);
|
||||
&creation_time,
|
||||
1);
|
||||
if (new_hotlist)
|
||||
{
|
||||
for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++)
|
||||
|
||||
@@ -2159,7 +2159,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
|
||||
if (number < 0)
|
||||
gui_hotlist_remove_buffer (buffer, 0);
|
||||
else
|
||||
(void) gui_hotlist_add (buffer, number, NULL);
|
||||
(void) gui_hotlist_add (buffer, number, NULL, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+80
-48
@@ -35,6 +35,7 @@
|
||||
#include "../core/wee-hook.h"
|
||||
#include "../core/wee-infolist.h"
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "../core/wee-util.h"
|
||||
#include "../plugins/plugin.h"
|
||||
#include "gui-hotlist.h"
|
||||
@@ -53,6 +54,9 @@ 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 */
|
||||
|
||||
char *gui_hotlist_priority_string[GUI_HOTLIST_NUM_PRIORITIES] =
|
||||
{ "low", "message", "private", "highlight" };
|
||||
|
||||
|
||||
/*
|
||||
* Sends signal "hotlist_changed".
|
||||
@@ -65,6 +69,29 @@ gui_hotlist_changed_signal (struct t_gui_buffer *buffer)
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Searches for hotlist priority.
|
||||
*
|
||||
* Returns index of hotlist priority found, -1 if not found.
|
||||
*/
|
||||
|
||||
int
|
||||
gui_hotlist_search_priority (const char *priority)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!priority)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++)
|
||||
{
|
||||
if (string_strcasecmp (gui_hotlist_priority_string[i], priority) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Searches for hotlist with buffer pointer.
|
||||
*
|
||||
@@ -331,7 +358,8 @@ gui_hotlist_add_hotlist (struct t_gui_hotlist **hotlist,
|
||||
struct t_gui_hotlist *
|
||||
gui_hotlist_add (struct t_gui_buffer *buffer,
|
||||
enum t_gui_hotlist_priority priority,
|
||||
struct timeval *creation_time)
|
||||
struct timeval *creation_time,
|
||||
int check_conditions)
|
||||
{
|
||||
struct t_gui_hotlist *new_hotlist, *ptr_hotlist;
|
||||
int i, count[GUI_HOTLIST_NUM_PRIORITIES], rc;
|
||||
@@ -351,60 +379,64 @@ 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)
|
||||
if (check_conditions)
|
||||
{
|
||||
gui_hotlist_hashtable_add_conditions_pointers = hashtable_new (
|
||||
32,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_POINTER,
|
||||
NULL, NULL);
|
||||
/* create hashtable if needed (to evaluate conditions) */
|
||||
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);
|
||||
{
|
||||
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)
|
||||
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);
|
||||
{
|
||||
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;
|
||||
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++)
|
||||
{
|
||||
|
||||
@@ -58,9 +58,11 @@ extern int gui_add_hotlist;
|
||||
|
||||
/* hotlist functions */
|
||||
|
||||
extern int gui_hotlist_search_priority (const char *priority);
|
||||
extern struct t_gui_hotlist *gui_hotlist_add (struct t_gui_buffer *buffer,
|
||||
enum t_gui_hotlist_priority priority,
|
||||
struct timeval *creation_time);
|
||||
struct timeval *creation_time,
|
||||
int check_conditions);
|
||||
extern void gui_hotlist_restore_buffer (struct t_gui_buffer *buffer);
|
||||
extern void gui_hotlist_restore_all_buffers ();
|
||||
extern void gui_hotlist_resort ();
|
||||
|
||||
+2
-2
@@ -1791,7 +1791,7 @@ gui_line_add (struct t_gui_line *line)
|
||||
&& line->data->highlight)
|
||||
{
|
||||
(void) gui_hotlist_add (line->data->buffer,
|
||||
GUI_HOTLIST_HIGHLIGHT, NULL);
|
||||
GUI_HOTLIST_HIGHLIGHT, NULL, 1);
|
||||
if (!weechat_upgrading)
|
||||
{
|
||||
message_for_signal = gui_line_build_string_prefix_message (
|
||||
@@ -1823,7 +1823,7 @@ gui_line_add (struct t_gui_line *line)
|
||||
if (line->data->notify_level >= GUI_HOTLIST_MIN)
|
||||
{
|
||||
(void) gui_hotlist_add (line->data->buffer,
|
||||
line->data->notify_level, NULL);
|
||||
line->data->notify_level, NULL, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user