1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 14:26:39 +02:00

core: convert option weechat.look.hotlist_sort to a list of fields (closes #2097)

This commit is contained in:
Sébastien Helleu
2024-03-15 21:43:32 +01:00
parent ea86f75319
commit 41fb29bbd0
18 changed files with 528 additions and 246 deletions
+88 -10
View File
@@ -369,6 +369,8 @@ int config_num_eval_syntax_colors = 0;
char *config_item_time_evaluated = NULL;
char *config_buffer_time_same_evaluated = NULL;
struct t_hashtable *config_hashtable_completion_partial_templates = NULL;
char **config_hotlist_sort_fields = NULL;
int config_num_hotlist_sort_fields = 0;
/*
@@ -1085,6 +1087,23 @@ config_change_hotlist_sort (const void *pointer, void *data,
(void) data;
(void) option;
if (config_hotlist_sort_fields)
{
string_free_split (config_hotlist_sort_fields);
config_hotlist_sort_fields = NULL;
}
config_num_hotlist_sort_fields = 0;
config_hotlist_sort_fields = string_split (
CONFIG_STRING(config_look_hotlist_sort),
",",
NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
0,
&config_num_hotlist_sort_fields);
gui_hotlist_resort ();
}
@@ -1563,6 +1582,8 @@ config_weechat_init_after_read ()
config_set_nick_colors ();
config_change_look_nick_color_force (NULL, NULL, NULL);
config_set_eval_syntax_colors ();
config_change_hotlist_sort (NULL, NULL, NULL);
}
/*
@@ -1575,7 +1596,7 @@ config_weechat_update_cb (const void *pointer, void *data,
int version_read,
struct t_hashtable *data_read)
{
const char *ptr_section, *ptr_option, *ptr_value;
const char *ptr_config, *ptr_section, *ptr_option, *ptr_value;
char *new_commands[][2] = {
/* old command, new command */
{ "/input jump_smart", "/buffer jump smart" },
@@ -1595,6 +1616,16 @@ config_weechat_update_cb (const void *pointer, void *data,
{ "/input zoom_merged_buffer", "/buffer zoom" },
{ NULL, NULL },
};
char *new_hotlist_sort[][2] = {
/* old hotlist sort (enum), new sort with fields */
{ "group_time_asc", "-priority,time,time.usec" },
{ "group_time_desc", "-priority,-time,-time.usec" },
{ "group_number_asc", "-priority,buffer.number" },
{ "group_number_desc", "-priority,-buffer.number" },
{ "number_asc", "buffer.number" },
{ "number_desc" "-buffer.number" },
{ NULL, NULL },
};
char *new_option;
int changes, i;
@@ -1615,6 +1646,7 @@ config_weechat_update_cb (const void *pointer, void *data,
* changes in v2 (WeeChat 4.0.0):
* - new format for keys (eg: meta2-1;3D -> meta-left)
* - keys removed: "meta2-200~" and "meta2-201~"
* - arguments changed in /input command
*/
ptr_section = hashtable_get (data_read, "section");
ptr_option = hashtable_get (data_read, "option");
@@ -1712,6 +1744,42 @@ config_weechat_update_cb (const void *pointer, void *data,
}
}
if (version_read < 3)
{
/*
* changes in v3 (WeeChat 4.3.0):
* - new format for option "weechat.look.hotlist_sort"
*/
ptr_config = hashtable_get (data_read, "config");
ptr_section = hashtable_get (data_read, "section");
ptr_option = hashtable_get (data_read, "option");
ptr_value = hashtable_get (data_read, "value");
if (ptr_config
&& ptr_section
&& ptr_option
&& (strcmp (ptr_section, "look") == 0)
&& (strcmp (ptr_option, "hotlist_sort") == 0))
{
for (i = 0; new_hotlist_sort[i][0]; i++)
{
if (ptr_value && (strcmp (ptr_value, new_hotlist_sort[i][0]) == 0))
{
gui_chat_printf (
NULL,
_("Value of option \"%s.%s.%s\" has been converted: \"%s\" => \"%s\""),
ptr_config,
ptr_section,
ptr_option,
new_hotlist_sort[i][0],
new_hotlist_sort[i][1]);
hashtable_set (data_read, "value", new_hotlist_sort[i][1]);
changes++;
break;
}
}
}
}
return (changes) ? data_read : NULL;
}
@@ -3626,15 +3694,18 @@ config_weechat_init_options ()
NULL, NULL, NULL);
config_look_hotlist_sort = config_file_new_option (
weechat_config_file, weechat_config_section_look,
"hotlist_sort", "enum",
N_("sort of hotlist: group_time_*: group by notify level "
"(highlights first) then sort by time, group_number_*: group "
"by notify level (highlights first) then sort by number, "
"number_*: sort by number; asc = ascending sort, desc = "
"descending sort"),
"group_time_asc|group_time_desc|group_number_asc|"
"group_number_desc|number_asc|number_desc",
0, 0, "group_time_asc", NULL, 0,
"hotlist_sort", "string",
N_("comma-separated list of fields to sort hotlist; each field is "
"a hdata variable of hotlist (\"var\") or a hdata variable of "
"buffer (\"buffer.var\"); "
"char \"-\" can be used before field to reverse order, "
"char \"~\" can be used to do a case insensitive comparison; "
"examples: "
"\"-priority,buffer.number\" for sort on hotlist priority then by "
"buffer number, "
"\"-~buffer.full_name\" for case insensitive and reverse "
"sort on buffer full name"),
NULL, 0, 0, "-priority,time,time.usec", NULL, 0,
NULL, NULL, NULL,
&config_change_hotlist_sort, NULL, NULL,
NULL, NULL, NULL);
@@ -5465,4 +5536,11 @@ config_weechat_free ()
hashtable_free (config_hashtable_completion_partial_templates);
config_hashtable_completion_partial_templates = NULL;
}
if (config_hotlist_sort_fields)
{
string_free_split (config_hotlist_sort_fields);
config_hotlist_sort_fields = NULL;
config_num_hotlist_sort_fields = 0;
}
}
+3 -1
View File
@@ -31,7 +31,7 @@ struct t_gui_buffer;
#define WEECHAT_CONFIG_NAME "weechat"
#define WEECHAT_CONFIG_PRIO_NAME "110000|weechat"
#define WEECHAT_CONFIG_VERSION 2
#define WEECHAT_CONFIG_VERSION 3
#define TAB_MAX_WIDTH 64
@@ -404,6 +404,8 @@ extern char **config_eval_syntax_colors;
extern int config_num_eval_syntax_colors;
extern char *config_buffer_time_same_evaluated;
extern struct t_hashtable *config_hashtable_completion_partial_templates;
extern char **config_hotlist_sort_fields;
extern int config_num_hotlist_sort_fields;
extern void config_set_nick_colors ();
extern struct t_config_option *config_weechat_debug_get (const char *plugin_name);
+65 -59
View File
@@ -228,6 +228,61 @@ gui_hotlist_check_buffer_notify (struct t_gui_buffer *buffer,
return 1;
}
/*
* Compares two hotlists in order to add them in the sorted list.
*
* The comparison is made using the list of fields defined in the option
* "weechat.look.hotlist_sort".
*
* Returns:
* -1: hotlist1 < hotlist2
* 0: hotlist1 == hotlist2
* 1: hotlist1 > hotlist2
*/
int
gui_hotlist_compare_hotlists (struct t_hdata *hdata_hotlist,
struct t_gui_hotlist *hotlist1,
struct t_gui_hotlist *hotlist2)
{
int i, reverse, case_sensitive, rc;
const char *ptr_field;
for (i = 0; i < config_num_hotlist_sort_fields; i++)
{
rc = 0;
reverse = 1;
case_sensitive = 1;
ptr_field = config_hotlist_sort_fields[i];
while ((ptr_field[0] == '-') || (ptr_field[0] == '~'))
{
if (ptr_field[0] == '-')
reverse *= -1;
else if (ptr_field[0] == '~')
case_sensitive ^= 1;
ptr_field++;
}
if (!hotlist1 && !hotlist2)
rc = 0;
else if (hotlist1 && !hotlist2)
rc = 1;
else if (!hotlist1 && hotlist2)
rc = -1;
else
{
rc = hdata_compare (hdata_hotlist,
hotlist1, hotlist2,
ptr_field,
case_sensitive);
}
rc *= reverse;
if (rc != 0)
return rc;
}
return 0;
}
/*
* Searches for position of hotlist (to keep hotlist sorted).
*/
@@ -236,69 +291,20 @@ struct t_gui_hotlist *
gui_hotlist_find_pos (struct t_gui_hotlist *hotlist,
struct t_gui_hotlist *new_hotlist)
{
struct t_hdata *hdata_hotlist;
struct t_gui_hotlist *ptr_hotlist;
switch (CONFIG_ENUM(config_look_hotlist_sort))
hdata_hotlist = hook_hdata_get (NULL, "hotlist");
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
case CONFIG_LOOK_HOTLIST_SORT_GROUP_TIME_ASC:
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
if ((new_hotlist->priority > ptr_hotlist->priority)
|| ((new_hotlist->priority == ptr_hotlist->priority)
&& (util_timeval_diff (&(new_hotlist->creation_time),
&(ptr_hotlist->creation_time)) > 0)))
return ptr_hotlist;
}
break;
case CONFIG_LOOK_HOTLIST_SORT_GROUP_TIME_DESC:
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
if ((new_hotlist->priority > ptr_hotlist->priority)
|| ((new_hotlist->priority == ptr_hotlist->priority)
&& (util_timeval_diff (&(new_hotlist->creation_time),
&(ptr_hotlist->creation_time)) < 0)))
return ptr_hotlist;
}
break;
case CONFIG_LOOK_HOTLIST_SORT_GROUP_NUMBER_ASC:
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
if ((new_hotlist->priority > ptr_hotlist->priority)
|| ((new_hotlist->priority == ptr_hotlist->priority)
&& (new_hotlist->buffer->number < ptr_hotlist->buffer->number)))
return ptr_hotlist;
}
break;
case CONFIG_LOOK_HOTLIST_SORT_GROUP_NUMBER_DESC:
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
if ((new_hotlist->priority > ptr_hotlist->priority)
|| ((new_hotlist->priority == ptr_hotlist->priority)
&& (new_hotlist->buffer->number > ptr_hotlist->buffer->number)))
return ptr_hotlist;
}
break;
case CONFIG_LOOK_HOTLIST_SORT_NUMBER_ASC:
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
if (new_hotlist->buffer->number < ptr_hotlist->buffer->number)
return ptr_hotlist;
}
break;
case CONFIG_LOOK_HOTLIST_SORT_NUMBER_DESC:
for (ptr_hotlist = hotlist; ptr_hotlist;
ptr_hotlist = ptr_hotlist->next_hotlist)
{
if (new_hotlist->buffer->number > ptr_hotlist->buffer->number)
return ptr_hotlist;
}
break;
if (gui_hotlist_compare_hotlists (hdata_hotlist,
new_hotlist, ptr_hotlist) < 0)
{
return ptr_hotlist;
}
}
return NULL;
}