1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 19:23:13 +02:00

trigger: add option trigger.look.enabled (can be changed with /trigger enable|disable|toggle)

This commit is contained in:
Sebastien Helleu
2014-02-14 18:35:29 +01:00
parent f52770137f
commit 8e63a9a52f
6 changed files with 102 additions and 40 deletions
+2
View File
@@ -27,6 +27,8 @@
pointers = NULL; \
extra_vars = NULL; \
(void) trigger_rc; \
if (!trigger_enabled) \
return __rc; \
trigger = (struct t_trigger *)data; \
if (!trigger || trigger->hook_running) \
return __rc; \
+43 -10
View File
@@ -29,6 +29,18 @@
#include "trigger-config.h"
/*
* Displays the status of triggers (global status).
*/
void
trigger_command_display_status ()
{
weechat_printf_tags (NULL, "no_trigger",
(trigger_enabled) ?
_("Triggers enabled") : _("Triggers disabled"));
}
/*
* Displays one trigger (internal function, must not be called directly).
*/
@@ -234,13 +246,15 @@ trigger_command_list (const char *message, int verbose)
{
struct t_trigger *ptr_trigger;
weechat_printf_tags (NULL, "no_trigger", "");
trigger_command_display_status ();
if (!triggers)
{
weechat_printf_tags (NULL, "no_trigger", _("No trigger defined"));
return;
}
weechat_printf_tags (NULL, "no_trigger", "");
weechat_printf_tags (NULL, "no_trigger", message);
for (ptr_trigger = triggers; ptr_trigger;
@@ -720,10 +734,25 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
{
if (argc < 3)
{
weechat_printf_tags (NULL, "no_trigger",
_("%sError: missing arguments for \"%s\" "
"command"),
weechat_prefix ("error"), "trigger");
if (weechat_strcasecmp (argv[1], "restart") == 0)
{
weechat_printf_tags (NULL, "no_trigger",
_("%sError: missing arguments for \"%s\" "
"command"),
weechat_prefix ("error"), "trigger");
goto end;
}
if (weechat_strcasecmp (argv[1], "enable") == 0)
weechat_config_option_set (trigger_config_look_enabled, "1", 1);
else if (weechat_strcasecmp (argv[1], "disable") == 0)
weechat_config_option_set (trigger_config_look_enabled, "0", 1);
else if (weechat_strcasecmp (argv[1], "toggle") == 0)
{
weechat_config_option_set (trigger_config_look_enabled,
(trigger_enabled) ? "0" : "1",
1);
}
trigger_command_display_status ();
goto end;
}
enable = -1;
@@ -875,7 +904,8 @@ trigger_command_init ()
" || input|output|recreate <name>"
" || set <name> <option> <value>"
" || rename|copy <name> <new_name>"
" || enable|disable|toggle|restart <name>|-all [<name>...]"
" || enable|disable|toggle [<name>|-all [<name>...]]"
" || restart <name>|-all [<name>...]"
" || show <name>"
" || del <name>|-all [<name>...]"
" || default -yes"
@@ -918,10 +948,13 @@ trigger_command_init ()
" value: new value for the option\n"
" rename: rename a trigger\n"
" copy: copy a trigger\n"
" enable: enable trigger(s)\n"
" disable: disable trigger(s)\n"
" toggle: toggle trigger(s)\n"
" restart: restart trigger(s) (for timer)\n"
" enable: enable trigger(s) (without arguments: enable triggers "
"globally)\n"
" disable: disable trigger(s) (without arguments: disable triggers "
"globally)\n"
" toggle: toggle trigger(s) (without arguments: toggle triggers "
"globally)\n"
" restart: restart trigger(s) (only for a timer)\n"
" show: show detailed info on a trigger (with some stats)\n"
" del: delete a trigger\n"
" -all: do action on all triggers\n"
+49 -26
View File
@@ -33,6 +33,7 @@ struct t_config_section *trigger_config_section_trigger = NULL;
/* trigger config, look section */
struct t_config_option *trigger_config_look_enabled;
struct t_config_option *trigger_config_look_monitor_strip_colors;
/* trigger config, color section */
@@ -93,11 +94,25 @@ char *trigger_config_default_list[][1 + TRIGGER_NUM_OPTIONS] =
/*
* Callback called when trigger option "enabled" is changed.
* Callback for changes on option "trigger.look.enabled".
*/
void
trigger_config_change_enabled (void *data, struct t_config_option *option)
{
/* make C compiler happy */
(void) data;
trigger_enabled = weechat_config_boolean (option);
}
/*
* Callback for changes on option "trigger.trigger.xxx.enabled".
*/
void
trigger_config_change_trigger_enabled (void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
@@ -115,11 +130,11 @@ trigger_config_change_enabled (void *data, struct t_config_option *option)
}
/*
* Callback called when trigger option "hook" is changed.
* Callback for changes on option "trigger.trigger.xxx.hook".
*/
void
trigger_config_change_hook (void *data, struct t_config_option *option)
trigger_config_change_trigger_hook (void *data, struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
@@ -135,11 +150,12 @@ trigger_config_change_hook (void *data, struct t_config_option *option)
}
/*
* Callback called when trigger option "arguments" is changed.
* Callback for changes on option "trigger.trigger.xxx.arguments".
*/
void
trigger_config_change_arguments (void *data, struct t_config_option *option)
trigger_config_change_trigger_arguments (void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
@@ -155,11 +171,11 @@ trigger_config_change_arguments (void *data, struct t_config_option *option)
}
/*
* Callback called when trigger option "regex" is changed.
* Callback for changes on option "trigger.trigger.xxx.regex".
*/
void
trigger_config_change_regex (void *data, struct t_config_option *option)
trigger_config_change_trigger_regex (void *data, struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
@@ -175,11 +191,12 @@ trigger_config_change_regex (void *data, struct t_config_option *option)
}
/*
* Callback called when trigger option "command" is changed.
* Callback for changes on option "trigger.trigger.xxx.command".
*/
void
trigger_config_change_command (void *data, struct t_config_option *option)
trigger_config_change_trigger_command (void *data,
struct t_config_option *option)
{
struct t_trigger *ptr_trigger;
@@ -202,8 +219,8 @@ trigger_config_change_command (void *data, struct t_config_option *option)
*/
struct t_config_option *
trigger_config_create_option (const char *trigger_name, int index_option,
const char *value)
trigger_config_create_trigger_option (const char *trigger_name, int index_option,
const char *value)
{
struct t_config_option *ptr_option;
int length;
@@ -228,8 +245,8 @@ trigger_config_create_option (const char *trigger_name, int index_option,
option_name, "boolean",
N_("if disabled, the hooks are removed from trigger, so it is "
"not called any more"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, &trigger_config_change_enabled, NULL, NULL, NULL);
NULL, 0, 0, value, NULL, 0, NULL, NULL,
&trigger_config_change_trigger_enabled, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_HOOK:
ptr_option = weechat_config_new_option (
@@ -237,8 +254,8 @@ trigger_config_create_option (const char *trigger_name, int index_option,
option_name, "integer",
N_("type of hook used"),
trigger_hook_option_values,
0, 0, value, NULL, 0,
NULL, NULL, &trigger_config_change_hook, NULL, NULL, NULL);
0, 0, value, NULL, 0, NULL, NULL,
&trigger_config_change_trigger_hook, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_ARGUMENTS:
ptr_option = weechat_config_new_option (
@@ -248,8 +265,8 @@ trigger_config_create_option (const char *trigger_name, int index_option,
"signal/hsignal/modifier: name[;name...], for print: "
"buffer;tags;strip_colors;message, for timer: "
"interval;align_second;max_calls"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, &trigger_config_change_arguments, NULL, NULL, NULL);
NULL, 0, 0, value, NULL, 0, NULL, NULL,
&trigger_config_change_trigger_arguments, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_CONDITIONS:
ptr_option = weechat_config_new_option (
@@ -276,16 +293,16 @@ trigger_config_create_option (const char *trigger_name, int index_option,
"identical chars), except '\\' and parentheses; matching "
"groups can be used in replace: $0 to $99, $+ for last "
"match and $.cN to replace all chars of group N by char c"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, &trigger_config_change_regex, NULL, NULL, NULL);
NULL, 0, 0, value, NULL, 0, NULL, NULL,
&trigger_config_change_trigger_regex, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_COMMAND:
ptr_option = weechat_config_new_option (
trigger_config_file, trigger_config_section_trigger,
option_name, "string",
N_("command run if conditions are OK, after regex replacements"),
NULL, 0, 0, value, NULL, 0,
NULL, NULL, &trigger_config_change_command, NULL, NULL, NULL);
NULL, 0, 0, value, NULL, 0, NULL, NULL,
&trigger_config_change_trigger_command, NULL, NULL, NULL);
break;
case TRIGGER_OPTION_RETURN_CODE:
ptr_option = weechat_config_new_option (
@@ -315,8 +332,8 @@ trigger_config_create_option_temp (struct t_trigger *temp_trigger,
{
struct t_config_option *new_option;
new_option = trigger_config_create_option (temp_trigger->name,
index_option, value);
new_option = trigger_config_create_trigger_option (temp_trigger->name,
index_option, value);
if (new_option
&& (index_option >= 0) && (index_option < TRIGGER_NUM_OPTIONS))
{
@@ -343,9 +360,9 @@ trigger_config_use_temp_triggers ()
if (!ptr_temp_trigger->options[i])
{
ptr_temp_trigger->options[i] =
trigger_config_create_option (ptr_temp_trigger->name,
i,
trigger_option_default[i]);
trigger_config_create_trigger_option (ptr_temp_trigger->name,
i,
trigger_option_default[i]);
}
if (ptr_temp_trigger->options[i])
num_options_ok++;
@@ -545,6 +562,12 @@ trigger_config_init ()
return 0;
}
trigger_config_look_enabled = weechat_config_new_option (
trigger_config_file, ptr_section,
"enabled", "boolean",
N_("enable trigger support"),
NULL, 0, 0, "on", NULL, 0, NULL, NULL,
&trigger_config_change_enabled, NULL, NULL, NULL);
trigger_config_look_monitor_strip_colors = weechat_config_new_option (
trigger_config_file, ptr_section,
"monitor_strip_colors", "boolean",
+4 -3
View File
@@ -26,6 +26,7 @@
extern struct t_config_file *trigger_config_file;
extern struct t_config_section *trigger_config_section_trigger;
extern struct t_config_option *trigger_config_look_enabled;
extern struct t_config_option *trigger_config_look_monitor_strip_colors;
extern struct t_config_option *trigger_config_color_flag_command;
@@ -39,9 +40,9 @@ extern struct t_config_option *trigger_config_color_trigger_disabled;
extern char *trigger_config_default_list[][1 + TRIGGER_NUM_OPTIONS];
extern struct t_config_option *trigger_config_create_option (const char *trigger_name,
int index_option,
const char *value);
extern struct t_config_option *trigger_config_create_trigger_option (const char *trigger_name,
int index_option,
const char *value);
extern int trigger_config_init ();
extern int trigger_config_read ();
extern int trigger_config_write ();
+3 -1
View File
@@ -75,6 +75,8 @@ int triggers_count = 0; /* number of triggers */
struct t_trigger *triggers_temp = NULL; /* first temporary trigger */
struct t_trigger *last_trigger_temp = NULL; /* last temporary trigger */
int trigger_enabled = 1; /* 0 if triggers are disabled */
/*
* Searches for a trigger option name.
@@ -874,7 +876,7 @@ trigger_new (const char *name, const char *enabled, const char *hook,
for (i = 0; i < TRIGGER_NUM_OPTIONS; i++)
{
option[i] = trigger_config_create_option (name, i, value[i]);
option[i] = trigger_config_create_trigger_option (name, i, value[i]);
}
new_trigger = trigger_new_with_options (name, option);
+1
View File
@@ -119,6 +119,7 @@ extern struct t_trigger *last_trigger;
extern int triggers_count;
extern struct t_trigger *triggers_temp;
extern struct t_trigger *last_trigger_temp;
extern int trigger_enabled;
extern int trigger_search_option (const char *option_name);
extern int trigger_search_hook_type (const char *type);