core: set "notify_level" to 3 if there is a highlight in the line (closes #1529)
This commit is contained in:
parent
45ce1d7604
commit
d15db0ecbb
@ -27,6 +27,7 @@ New features::
|
||||
|
||||
Bug fixes::
|
||||
|
||||
* core: set "notify_level" to 3 if there is a highlight in the line (issue #1529)
|
||||
* core: do not add line with highlight and tag "notify_none" to hotlist (issue #1529)
|
||||
* irc: send all channels in a single JOIN command when reconnecting to the server (issue #1551)
|
||||
* trigger: fix recursive calls to triggers using regex (issue #1546)
|
||||
|
@ -1241,77 +1241,80 @@ gui_line_free_all (struct t_gui_buffer *buffer)
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets notify level for a line.
|
||||
* Gets max notify level for a line, according to the nick.
|
||||
*
|
||||
* Returns notify level of line, -1 if tag "notify_none" is found (meaning no
|
||||
* notify at all for line).
|
||||
* Returns max notify level, between -1 and GUI_HOTLIST_HIGHLIGHT.
|
||||
*/
|
||||
|
||||
int
|
||||
gui_line_get_notify_level (struct t_gui_line *line)
|
||||
gui_line_get_max_notify_level (struct t_gui_line *line)
|
||||
{
|
||||
int i, notify_level, *max_notify_level;
|
||||
int max_notify_level, *ptr_max_notify_level;
|
||||
const char *nick;
|
||||
|
||||
notify_level = GUI_HOTLIST_LOW;
|
||||
max_notify_level = GUI_HOTLIST_HIGHLIGHT;
|
||||
|
||||
nick = gui_line_get_nick_tag (line);
|
||||
if (nick)
|
||||
{
|
||||
ptr_max_notify_level = hashtable_get (
|
||||
line->data->buffer->hotlist_max_level_nicks,
|
||||
nick);
|
||||
if (ptr_max_notify_level)
|
||||
max_notify_level = *ptr_max_notify_level;
|
||||
}
|
||||
|
||||
return max_notify_level;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the notify level in a line:
|
||||
* -1: no notify at all
|
||||
* 0: low (GUI_HOTLIST_LOW)
|
||||
* 1: message (GUI_HOTLIST_MESSAGE)
|
||||
* 2: private message (GUI_HOTLIST_PRIVATE)
|
||||
* 3: message with highlight (GUI_HOTLIST_HIGHLIGHT)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_line_set_notify_level (struct t_gui_line *line, int max_notify_level)
|
||||
{
|
||||
int i;
|
||||
|
||||
line->data->notify_level = GUI_HOTLIST_LOW;
|
||||
|
||||
for (i = 0; i < line->data->tags_count; i++)
|
||||
{
|
||||
if (string_strcasecmp (line->data->tags_array[i], "notify_none") == 0)
|
||||
notify_level = -1;
|
||||
if (string_strcasecmp (line->data->tags_array[i], "notify_highlight") == 0)
|
||||
notify_level = GUI_HOTLIST_HIGHLIGHT;
|
||||
if (string_strcasecmp (line->data->tags_array[i], "notify_private") == 0)
|
||||
notify_level = GUI_HOTLIST_PRIVATE;
|
||||
line->data->notify_level = -1;
|
||||
if (string_strcasecmp (line->data->tags_array[i], "notify_message") == 0)
|
||||
notify_level = GUI_HOTLIST_MESSAGE;
|
||||
line->data->notify_level = GUI_HOTLIST_MESSAGE;
|
||||
if (string_strcasecmp (line->data->tags_array[i], "notify_private") == 0)
|
||||
line->data->notify_level = GUI_HOTLIST_PRIVATE;
|
||||
if (string_strcasecmp (line->data->tags_array[i], "notify_highlight") == 0)
|
||||
line->data->notify_level = GUI_HOTLIST_HIGHLIGHT;
|
||||
}
|
||||
|
||||
max_notify_level = NULL;
|
||||
nick = gui_line_get_nick_tag (line);
|
||||
if (nick)
|
||||
{
|
||||
max_notify_level = hashtable_get (line->data->buffer->hotlist_max_level_nicks,
|
||||
nick);
|
||||
}
|
||||
if (max_notify_level && (*max_notify_level < notify_level))
|
||||
notify_level = *max_notify_level;
|
||||
|
||||
return notify_level;
|
||||
if (line->data->notify_level > max_notify_level)
|
||||
line->data->notify_level = max_notify_level;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets highlight flag for a line, using the notify level in the line.
|
||||
*
|
||||
* Returns 1 for highlight otherwise 0.
|
||||
* Sets highlight flag in a line:
|
||||
* 0: no highlight
|
||||
* 1: highlight
|
||||
*/
|
||||
|
||||
int
|
||||
gui_line_get_highlight (struct t_gui_line *line)
|
||||
void
|
||||
gui_line_set_highlight (struct t_gui_line *line, int max_notify_level)
|
||||
{
|
||||
int highlight, *max_notify_level;
|
||||
const char *nick;
|
||||
|
||||
if (line->data->notify_level == GUI_HOTLIST_HIGHLIGHT)
|
||||
{
|
||||
highlight = 1;
|
||||
}
|
||||
line->data->highlight = 1;
|
||||
else
|
||||
{
|
||||
max_notify_level = NULL;
|
||||
nick = gui_line_get_nick_tag (line);
|
||||
if (nick)
|
||||
{
|
||||
max_notify_level = hashtable_get (line->data->buffer->hotlist_max_level_nicks,
|
||||
nick);
|
||||
}
|
||||
if (max_notify_level && (*max_notify_level < GUI_HOTLIST_HIGHLIGHT))
|
||||
highlight = 0;
|
||||
else
|
||||
highlight = gui_line_has_highlight (line);
|
||||
line->data->highlight = (max_notify_level == GUI_HOTLIST_HIGHLIGHT) ?
|
||||
gui_line_has_highlight (line) : 0;
|
||||
}
|
||||
|
||||
return highlight;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1325,6 +1328,7 @@ gui_line_new (struct t_gui_buffer *buffer, int y, time_t date,
|
||||
{
|
||||
struct t_gui_line *new_line;
|
||||
struct t_gui_line_data *new_line_data;
|
||||
int max_notify_level;
|
||||
|
||||
/* create new line */
|
||||
new_line = malloc (sizeof (*new_line));
|
||||
@ -1356,8 +1360,11 @@ gui_line_new (struct t_gui_buffer *buffer, int y, time_t date,
|
||||
(char *)string_shared_get (prefix) : ((date != 0) ? (char *)string_shared_get ("") : NULL);
|
||||
new_line->data->prefix_length = (prefix) ?
|
||||
gui_chat_strlen_screen (prefix) : 0;
|
||||
new_line->data->notify_level = gui_line_get_notify_level (new_line);
|
||||
new_line->data->highlight = gui_line_get_highlight (new_line);
|
||||
max_notify_level = gui_line_get_max_notify_level (new_line);
|
||||
gui_line_set_notify_level (new_line, max_notify_level);
|
||||
gui_line_set_highlight (new_line, max_notify_level);
|
||||
if (new_line->data->highlight)
|
||||
new_line->data->notify_level = GUI_HOTLIST_HIGHLIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1398,6 +1405,7 @@ gui_line_hook_update (struct t_gui_line *line,
|
||||
long value;
|
||||
char *error;
|
||||
int rc, tags_updated, notify_level_updated, highlight_updated;
|
||||
int max_notify_level;
|
||||
|
||||
tags_updated = 0;
|
||||
notify_level_updated = 0;
|
||||
@ -1543,16 +1551,22 @@ gui_line_hook_update (struct t_gui_line *line,
|
||||
line->data->message = (ptr_value2) ? strdup (ptr_value2) : NULL;
|
||||
}
|
||||
|
||||
max_notify_level = gui_line_get_max_notify_level (line);
|
||||
|
||||
/* if tags were updated but not notify_level, adjust notify level */
|
||||
if (tags_updated && !notify_level_updated)
|
||||
line->data->notify_level = gui_line_get_notify_level (line);
|
||||
gui_line_set_notify_level (line, max_notify_level);
|
||||
|
||||
/* adjust flag "displayed" if tags were updated */
|
||||
if (tags_updated)
|
||||
line->data->displayed = gui_filter_check_line (line->data);
|
||||
|
||||
if ((tags_updated || notify_level_updated) && !highlight_updated)
|
||||
line->data->highlight = gui_line_get_highlight (line);
|
||||
{
|
||||
gui_line_set_highlight (line, max_notify_level);
|
||||
if (line->data->highlight && !notify_level_updated)
|
||||
line->data->notify_level = GUI_HOTLIST_HIGHLIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -107,7 +107,11 @@ extern void gui_line_free_data (struct t_gui_line *line);
|
||||
extern void gui_line_free (struct t_gui_buffer *buffer,
|
||||
struct t_gui_line *line);
|
||||
extern void gui_line_free_all (struct t_gui_buffer *buffer);
|
||||
extern int gui_line_get_notify_level (struct t_gui_line *line);
|
||||
extern int gui_line_get_max_notify_level (struct t_gui_line *line);
|
||||
extern void gui_line_set_notify_level (struct t_gui_line *line,
|
||||
int max_notify_level);
|
||||
extern void gui_line_set_highlight (struct t_gui_line *line,
|
||||
int max_notify_level);
|
||||
extern struct t_gui_line *gui_line_new (struct t_gui_buffer *buffer,
|
||||
int y,
|
||||
time_t date,
|
||||
|
@ -24,8 +24,11 @@
|
||||
extern "C"
|
||||
{
|
||||
#include <string.h>
|
||||
#include "src/core/wee-config.h"
|
||||
#include "src/core/wee-string.h"
|
||||
#include "src/gui/gui-buffer.h"
|
||||
#include "src/gui/gui-filter.h"
|
||||
#include "src/gui/gui-hotlist.h"
|
||||
#include "src/gui/gui-line.h"
|
||||
}
|
||||
|
||||
@ -169,7 +172,7 @@ TEST(GuiLine, IsDisplayed)
|
||||
int old_gui_filters_enabled;
|
||||
|
||||
memset (&line, 0, sizeof (line));
|
||||
line.data = (struct t_gui_line_data *)malloc (sizeof (struct t_gui_line_data));
|
||||
line.data = (struct t_gui_line_data *)calloc (1, sizeof (struct t_gui_line_data));
|
||||
|
||||
LONGS_EQUAL(0, gui_line_is_displayed (NULL));
|
||||
|
||||
@ -332,7 +335,7 @@ TEST(GuiLine, SearchTagStartingWith)
|
||||
struct t_gui_line line;
|
||||
|
||||
memset (&line, 0, sizeof (line));
|
||||
line.data = (struct t_gui_line_data *)malloc (sizeof (struct t_gui_line_data));
|
||||
line.data = (struct t_gui_line_data *)calloc (1, sizeof (struct t_gui_line_data));
|
||||
gui_line_tags_alloc (line.data, NULL);
|
||||
|
||||
POINTERS_EQUAL(NULL, gui_line_search_tag_starting_with (NULL, NULL));
|
||||
@ -366,7 +369,7 @@ TEST(GuiLine, GetNickTag)
|
||||
struct t_gui_line line;
|
||||
|
||||
memset (&line, 0, sizeof (line));
|
||||
line.data = (struct t_gui_line_data *)malloc (sizeof (struct t_gui_line_data));
|
||||
line.data = (struct t_gui_line_data *)calloc (1, sizeof (struct t_gui_line_data));
|
||||
gui_line_tags_alloc (line.data, NULL);
|
||||
|
||||
POINTERS_EQUAL(NULL, gui_line_get_nick_tag (NULL));
|
||||
@ -506,22 +509,214 @@ TEST(GuiLine, FreeAll)
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* gui_line_get_notify_level
|
||||
* gui_line_get_max_notify_level
|
||||
*/
|
||||
|
||||
TEST(GuiLine, GetNotifyLevel)
|
||||
TEST(GuiLine, GetMaxNotifyLevel)
|
||||
{
|
||||
/* TODO: write tests */
|
||||
struct t_gui_line line;
|
||||
|
||||
memset (&line, 0, sizeof (line));
|
||||
line.data = (struct t_gui_line_data *)calloc (1, sizeof (struct t_gui_line_data));
|
||||
line.data->buffer = gui_buffers;
|
||||
gui_line_tags_alloc (line.data, NULL);
|
||||
|
||||
LONGS_EQUAL(GUI_HOTLIST_HIGHLIGHT, gui_line_get_max_notify_level (&line));
|
||||
|
||||
gui_line_tags_alloc (line.data, "nick_alice");
|
||||
LONGS_EQUAL(GUI_HOTLIST_HIGHLIGHT, gui_line_get_max_notify_level (&line));
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
gui_buffer_set_hotlist_max_level_nicks (gui_buffers, "alice:3");
|
||||
gui_line_tags_alloc (line.data, "nick_alice");
|
||||
LONGS_EQUAL(GUI_HOTLIST_HIGHLIGHT, gui_line_get_max_notify_level (&line));
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
gui_buffer_set_hotlist_max_level_nicks (gui_buffers, "alice:2");
|
||||
gui_line_tags_alloc (line.data, "nick_alice");
|
||||
LONGS_EQUAL(GUI_HOTLIST_PRIVATE, gui_line_get_max_notify_level (&line));
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
gui_buffer_set_hotlist_max_level_nicks (gui_buffers, "alice:1");
|
||||
gui_line_tags_alloc (line.data, "nick_alice");
|
||||
LONGS_EQUAL(GUI_HOTLIST_MESSAGE, gui_line_get_max_notify_level (&line));
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
gui_buffer_set_hotlist_max_level_nicks (gui_buffers, "alice:0");
|
||||
gui_line_tags_alloc (line.data, "nick_alice");
|
||||
LONGS_EQUAL(GUI_HOTLIST_LOW, gui_line_get_max_notify_level (&line));
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
gui_buffer_set_hotlist_max_level_nicks (gui_buffers, "alice:-1");
|
||||
gui_line_tags_alloc (line.data, "nick_alice");
|
||||
LONGS_EQUAL(-1, gui_line_get_max_notify_level (&line));
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
gui_buffer_set_hotlist_max_level_nicks (gui_buffers, NULL);
|
||||
|
||||
free (line.data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* gui_line_get_highlight
|
||||
* gui_line_set_notify_level
|
||||
*/
|
||||
|
||||
TEST(GuiLine, GetHighlight)
|
||||
TEST(GuiLine, SetNotifyLevel)
|
||||
{
|
||||
/* TODO: write tests */
|
||||
struct t_gui_line line;
|
||||
|
||||
memset (&line, 0, sizeof (line));
|
||||
line.data = (struct t_gui_line_data *)calloc (1, sizeof (struct t_gui_line_data));
|
||||
line.data->buffer = gui_buffers;
|
||||
gui_line_tags_alloc (line.data, NULL);
|
||||
|
||||
line.data->notify_level = 99;
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(GUI_HOTLIST_LOW, line.data->notify_level);
|
||||
|
||||
/* notify: none */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_none");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(-1, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: message */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_message");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(GUI_HOTLIST_MESSAGE, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: private */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_private");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(GUI_HOTLIST_PRIVATE, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: highlight */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_highlight");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(GUI_HOTLIST_HIGHLIGHT, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: highlight, max: private */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_highlight");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_PRIVATE);
|
||||
LONGS_EQUAL(GUI_HOTLIST_PRIVATE, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: highlight, max: message */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_highlight");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_MESSAGE);
|
||||
LONGS_EQUAL(GUI_HOTLIST_MESSAGE, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: highlight, max: low */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_highlight");
|
||||
gui_line_set_notify_level (&line, GUI_HOTLIST_LOW);
|
||||
LONGS_EQUAL(GUI_HOTLIST_LOW, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
/* notify: highlight, max: -1 */
|
||||
line.data->notify_level = 99;
|
||||
gui_line_tags_alloc (line.data, "notify_highlight");
|
||||
gui_line_set_notify_level (&line, -1);
|
||||
LONGS_EQUAL(-1, line.data->notify_level);
|
||||
gui_line_tags_free (line.data);
|
||||
|
||||
free (line.data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests functions:
|
||||
* gui_line_set_highlight
|
||||
*/
|
||||
|
||||
TEST(GuiLine, SetHighlight)
|
||||
{
|
||||
struct t_gui_line line;
|
||||
|
||||
memset (&line, 0, sizeof (line));
|
||||
line.data = (struct t_gui_line_data *)calloc (1, sizeof (struct t_gui_line_data));
|
||||
line.data->buffer = gui_buffers;
|
||||
//line.data->message = strdup ("test");
|
||||
gui_line_tags_alloc (line.data, NULL);
|
||||
|
||||
/* notify: none */
|
||||
line.data->notify_level = -1;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: low */
|
||||
line.data->notify_level = 0;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: message */
|
||||
line.data->notify_level = 1;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: private */
|
||||
line.data->notify_level = 2;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: highlight */
|
||||
line.data->notify_level = 3;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(1, line.data->highlight);
|
||||
|
||||
/* notify: message, max: private */
|
||||
line.data->notify_level = 2;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_PRIVATE);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: message, max: message */
|
||||
line.data->notify_level = 1;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_MESSAGE);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: low, max: low */
|
||||
line.data->notify_level = 0;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_LOW);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
/* notify: none, max: -1 */
|
||||
line.data->notify_level = -1;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, -1);
|
||||
LONGS_EQUAL(0, line.data->highlight);
|
||||
|
||||
config_file_option_set (config_look_highlight, "test", 1);
|
||||
|
||||
/* notify: message, line with highlight */
|
||||
line.data->message = strdup ("this is a test");
|
||||
line.data->notify_level = 1;
|
||||
line.data->highlight = -1;
|
||||
gui_line_set_highlight (&line, GUI_HOTLIST_HIGHLIGHT);
|
||||
LONGS_EQUAL(1, line.data->highlight);
|
||||
free (line.data->message);
|
||||
line.data->message = NULL;
|
||||
|
||||
config_file_option_reset (config_look_highlight, 0);
|
||||
|
||||
free (line.data);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user