core: create or update option weechat.notify.xxx when function buffer_set is called with "notify" property (closes #1390)
This commit is contained in:
parent
a409080d8b
commit
c411ee475a
@ -31,6 +31,7 @@ New features::
|
||||
|
||||
Bug fixes::
|
||||
|
||||
* core: create or update option weechat.notify.xxx when function buffer_set is called with "notify" property (issue #1390)
|
||||
* core: fix memory leak in case of error when building content of bar item for display (issue #1384)
|
||||
* core: send command line parameter to plugins only if the name starts with the plugin name followed by a colon
|
||||
* core: auto disable upgrade process (command line option "--upgrade") if the file weechat.upgrade is not found
|
||||
|
@ -2152,6 +2152,27 @@ config_weechat_layout_write_cb (const void *pointer, void *data,
|
||||
return WEECHAT_CONFIG_WRITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks notify option value.
|
||||
*
|
||||
* Returns:
|
||||
* 1: value OK
|
||||
* 0: invalid value
|
||||
*/
|
||||
|
||||
int
|
||||
config_weechat_notify_check_cb (const void *pointer, void *data,
|
||||
struct t_config_option *option,
|
||||
const char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
return (gui_buffer_search_notify (value) >= 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for changes on a notify option.
|
||||
*/
|
||||
@ -2180,7 +2201,7 @@ config_weechat_notify_create_option_cb (const void *pointer, void *data,
|
||||
const char *value)
|
||||
{
|
||||
struct t_config_option *ptr_option;
|
||||
int rc;
|
||||
int rc, notify;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
@ -2206,19 +2227,29 @@ config_weechat_notify_create_option_cb (const void *pointer, void *data,
|
||||
{
|
||||
if (value && value[0])
|
||||
{
|
||||
ptr_option = config_file_new_option (
|
||||
config_file, section,
|
||||
option_name, "integer", _("Notify level for buffer"),
|
||||
"none|highlight|message|all",
|
||||
0, 0, "", value, 0,
|
||||
NULL, NULL, NULL,
|
||||
&config_weechat_notify_change_cb, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
rc = (ptr_option) ?
|
||||
WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
notify = gui_buffer_search_notify (value);
|
||||
if (notify >= 0)
|
||||
{
|
||||
ptr_option = config_file_new_option (
|
||||
config_file, section,
|
||||
option_name, "integer", _("Notify level for buffer"),
|
||||
"none|highlight|message|all",
|
||||
0, 0, "", value, 0,
|
||||
&config_weechat_notify_check_cb, NULL, NULL,
|
||||
&config_weechat_notify_change_cb, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
rc = (ptr_option) ?
|
||||
WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2265,31 +2296,20 @@ config_weechat_notify_delete_option_cb (const void *pointer, void *data,
|
||||
int
|
||||
config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify)
|
||||
{
|
||||
int i, value;
|
||||
int rc;
|
||||
|
||||
if (!buffer || !notify)
|
||||
return 0;
|
||||
|
||||
value = -1;
|
||||
for (i = 0; i < GUI_BUFFER_NUM_NOTIFY; i++)
|
||||
{
|
||||
if (strcmp (gui_buffer_notify_string[i], notify) == 0)
|
||||
{
|
||||
value = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((value < 0) && (strcmp (notify, "reset") != 0))
|
||||
return 0;
|
||||
|
||||
/* create/update option */
|
||||
return (config_weechat_notify_create_option_cb (
|
||||
NULL, NULL,
|
||||
weechat_config_file,
|
||||
weechat_config_section_notify,
|
||||
buffer->full_name,
|
||||
(value < 0) ?
|
||||
NULL : gui_buffer_notify_string[value]) != WEECHAT_CONFIG_OPTION_SET_ERROR) ? 1 : 0;
|
||||
rc = config_weechat_notify_create_option_cb (
|
||||
NULL, NULL,
|
||||
weechat_config_file,
|
||||
weechat_config_section_notify,
|
||||
buffer->full_name,
|
||||
(strcmp (notify, "reset") == 0) ? "none" : notify);
|
||||
|
||||
return (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -124,7 +124,7 @@ char *gui_buffer_properties_set[] =
|
||||
/*
|
||||
* Searches for buffer type.
|
||||
*
|
||||
* Returns pointer to hotlist found, NULL if not found.
|
||||
* Returns index of bufffer type found, -1 if not found.
|
||||
*/
|
||||
|
||||
int
|
||||
@ -132,6 +132,9 @@ gui_buffer_search_type (const char *type)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!type)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < GUI_BUFFER_NUM_TYPES; i++)
|
||||
{
|
||||
if (string_strcasecmp (gui_buffer_type_string[i], type) == 0)
|
||||
@ -141,6 +144,29 @@ gui_buffer_search_type (const char *type)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Searches for buffer notif levely.
|
||||
*
|
||||
* Returns index of notify level, -1 if not found.
|
||||
*/
|
||||
|
||||
int
|
||||
gui_buffer_search_notify (const char *notify)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!notify)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < GUI_BUFFER_NUM_NOTIFY; i++)
|
||||
{
|
||||
if (string_strcasecmp (gui_buffer_notify_string[i], notify) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets plugin name of buffer.
|
||||
*
|
||||
@ -1873,8 +1899,10 @@ void
|
||||
gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
|
||||
const char *value)
|
||||
{
|
||||
int gui_chat_mute_old;
|
||||
long number;
|
||||
char *error;
|
||||
const char *ptr_notify;
|
||||
|
||||
if (!property || !value)
|
||||
return;
|
||||
@ -1993,15 +2021,28 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
|
||||
}
|
||||
else if (string_strcasecmp (property, "notify") == 0)
|
||||
{
|
||||
ptr_notify = NULL;
|
||||
error = NULL;
|
||||
number = strtol (value, &error, 10);
|
||||
if (error && !error[0]
|
||||
&& (number < GUI_BUFFER_NUM_NOTIFY))
|
||||
if (error && !error[0])
|
||||
{
|
||||
if (number < 0)
|
||||
buffer->notify = CONFIG_INTEGER(config_look_buffer_notify_default);
|
||||
else
|
||||
buffer->notify = number;
|
||||
if (number < GUI_BUFFER_NUM_NOTIFY)
|
||||
{
|
||||
if (number < 0)
|
||||
number = CONFIG_INTEGER(config_look_buffer_notify_default);
|
||||
ptr_notify = gui_buffer_notify_string[number];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr_notify = value;
|
||||
}
|
||||
if (ptr_notify)
|
||||
{
|
||||
gui_chat_mute_old = gui_chat_mute;
|
||||
gui_chat_mute = GUI_CHAT_MUTE_ALL_BUFFERS;
|
||||
config_weechat_notify_set (buffer, ptr_notify);
|
||||
gui_chat_mute = gui_chat_mute_old;
|
||||
}
|
||||
}
|
||||
else if (string_strcasecmp (property, "title") == 0)
|
||||
|
@ -246,6 +246,7 @@ extern char *gui_buffer_properties_set[];
|
||||
/* buffer functions */
|
||||
|
||||
extern int gui_buffer_search_type (const char *type);
|
||||
extern int gui_buffer_search_notify (const char *notify);
|
||||
extern const char *gui_buffer_get_plugin_name (struct t_gui_buffer *buffer);
|
||||
extern const char *gui_buffer_get_short_name (struct t_gui_buffer *buffer);
|
||||
extern void gui_buffer_build_full_name (struct t_gui_buffer *buffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user