mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 21:06:38 +02:00
Event hook added
This commit is contained in:
+54
-12
@@ -40,17 +40,15 @@ static struct t_weechat_plugin *weechat_plugin = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* demo_printf_command: demo command for printf
|
||||
* demo_printf_command_cb: demo command for printf
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_printf_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_printf_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
(void) data;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
(void) argv_eol;
|
||||
|
||||
|
||||
if (argc > 1)
|
||||
weechat_printf (weechat_current_buffer,
|
||||
"demo_printf: %s", argv_eol[1]);
|
||||
@@ -77,6 +75,28 @@ demo_printf_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_buffer_command_cb: demo command for creatig new buffer
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_buffer_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_gui_buffer *buffer;
|
||||
|
||||
(void) data;
|
||||
(void) argv_eol;
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
buffer = weechat_buffer_new (argv[1], argv[2]);
|
||||
if (buffer)
|
||||
weechat_buffer_set (buffer, "display", "1");
|
||||
}
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_print_list: display a list
|
||||
*/
|
||||
@@ -138,11 +158,11 @@ demo_print_list (void *list, char *item_name)
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_list_command: demo command for list
|
||||
* demo_list_command_cb: demo command for list
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_list_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_list_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_plugin_list *list;
|
||||
|
||||
@@ -182,11 +202,11 @@ demo_list_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_info_command: demo command for info_get
|
||||
* demo_info_command_cb: demo command for info_get
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_info_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
demo_info_command_cb (void *data, int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -205,6 +225,21 @@ demo_info_command (void *data, int argc, char **argv, char **argv_eol)
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* demo_event_cb: callback for event hook
|
||||
*/
|
||||
|
||||
static int
|
||||
demo_event_cb (void *data, char *event, void *pointer)
|
||||
{
|
||||
(void) data;
|
||||
|
||||
weechat_printf (NULL, "demo_event: event: %s, pointer: %X",
|
||||
event, pointer);
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: init demo plugin
|
||||
*/
|
||||
@@ -217,14 +252,19 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_hook_command ("demo_printf", "demo command: print some messages",
|
||||
"[text]", "text: write some text on current buffer",
|
||||
"",
|
||||
demo_printf_command, NULL);
|
||||
demo_printf_command_cb, NULL);
|
||||
|
||||
weechat_hook_command ("demo_buffer", "open a new buffer",
|
||||
"category name", "",
|
||||
"",
|
||||
demo_buffer_command_cb, NULL);
|
||||
|
||||
weechat_hook_command ("demo_list", "demo command: get and display list",
|
||||
"list",
|
||||
"list: list to display (values: buffer, "
|
||||
"buffer_lines)",
|
||||
"buffer|buffer_lines",
|
||||
demo_list_command, NULL);
|
||||
demo_list_command_cb, NULL);
|
||||
|
||||
weechat_hook_command ("demo_info", "demo command: get and display info",
|
||||
"info",
|
||||
@@ -235,7 +275,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
"version|weechat_dir|weechat_libdir|"
|
||||
"weechat_sharedir|charset_terminal|charset_internal|"
|
||||
"inactivity|input|input_mask|input_pos",
|
||||
demo_info_command, NULL);
|
||||
demo_info_command_cb, NULL);
|
||||
|
||||
weechat_hook_event ("*", demo_event_cb, NULL);
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -295,11 +295,11 @@ fifo_read ()
|
||||
}
|
||||
|
||||
/*
|
||||
* fifo_config: fifo config callback (called when fifo option is changed)
|
||||
* fifo_config_cb: fifo config callback (called when fifo option is changed)
|
||||
*/
|
||||
|
||||
static int
|
||||
fifo_config (void *data, char *type, char *option, char *value)
|
||||
fifo_config_cb (void *data, char *type, char *option, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -333,7 +333,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
|
||||
fifo_fd_hook = weechat_hook_fd (fifo_fd, 1, 0, 0, fifo_read, NULL);
|
||||
|
||||
weechat_hook_config ("plugin", "fifo.fifo", fifo_config, NULL);
|
||||
weechat_hook_config ("plugin", "fifo.fifo", fifo_config_cb, NULL);
|
||||
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
+76
-35
@@ -154,6 +154,20 @@ plugin_api_strncasecmp (struct t_weechat_plugin *plugin,
|
||||
return string_strncasecmp (string1, string2, max);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_string_replace: replace a string by new one in a string
|
||||
*/
|
||||
|
||||
char *
|
||||
plugin_api_string_replace (struct t_weechat_plugin *plugin,
|
||||
char *string, char *search, char *replace)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) plugin;
|
||||
|
||||
return string_replace (string, search, replace);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_string_explode: explode a string
|
||||
*/
|
||||
@@ -401,40 +415,6 @@ plugin_api_hook_command (struct t_weechat_plugin *plugin, char *command,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_print: hook a printed message
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_api_hook_print (struct t_weechat_plugin *plugin, void *buffer,
|
||||
char *message,
|
||||
int (*callback)(void *, void *, time_t, char *, char *),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && gui_buffer_valid ((struct t_gui_buffer *)buffer)
|
||||
&& callback)
|
||||
return hook_print (plugin, buffer, message, callback, data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_config: hook a config option
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_api_hook_config (struct t_weechat_plugin *plugin, char *config_type,
|
||||
char *config_option,
|
||||
int (*callback)(void *, char *, char *, char *),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && callback)
|
||||
return hook_config (plugin, config_type, config_option,
|
||||
callback, data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_timer: hook a timer
|
||||
*/
|
||||
@@ -475,6 +455,56 @@ plugin_api_hook_fd (struct t_weechat_plugin *plugin, int fd,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_print: hook a printed message
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_api_hook_print (struct t_weechat_plugin *plugin, void *buffer,
|
||||
char *message, int strip_colors,
|
||||
int (*callback)(void *, void *, time_t, char *, char *),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && gui_buffer_valid ((struct t_gui_buffer *)buffer)
|
||||
&& callback)
|
||||
return hook_print (plugin, buffer, message, strip_colors,
|
||||
callback, data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_event: hook an event
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_api_hook_event (struct t_weechat_plugin *plugin, char *event,
|
||||
int (*callback)(void *, char *, void *),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && event && event[0] && callback)
|
||||
return hook_event (plugin, event, callback, data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_hook_config: hook a config option
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
plugin_api_hook_config (struct t_weechat_plugin *plugin, char *config_type,
|
||||
char *config_option,
|
||||
int (*callback)(void *, char *, char *, char *),
|
||||
void *data)
|
||||
{
|
||||
if (plugin && callback)
|
||||
return hook_config (plugin, config_type, config_option,
|
||||
callback, data);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_api_unhook: unhook something
|
||||
*/
|
||||
@@ -520,8 +550,15 @@ struct t_gui_buffer *
|
||||
plugin_api_buffer_search (struct t_weechat_plugin *plugin, char *category,
|
||||
char *name)
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
if (plugin)
|
||||
return gui_buffer_search_by_category_name (category, name);
|
||||
{
|
||||
ptr_buffer = gui_buffer_search_by_category_name (category, name);
|
||||
if (ptr_buffer)
|
||||
return ptr_buffer;
|
||||
return gui_current_window->buffer;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -646,6 +683,10 @@ plugin_api_info_get (struct t_weechat_plugin *plugin, char *info)
|
||||
{
|
||||
return strdup (PACKAGE_VERSION);
|
||||
}
|
||||
else if (string_strcasecmp (info, "dir_separator") == 0)
|
||||
{
|
||||
return strdup (DIR_SEPARATOR);
|
||||
}
|
||||
else if (string_strcasecmp (info, "weechat_dir") == 0)
|
||||
{
|
||||
return strdup (weechat_home);
|
||||
|
||||
@@ -32,6 +32,8 @@ extern char *plugin_api_ngettext (struct t_weechat_plugin *, char *, char *,
|
||||
extern int plugin_api_strcasecmp (struct t_weechat_plugin *,char *, char *);
|
||||
extern int plugin_api_strncasecmp (struct t_weechat_plugin *,char *, char *,
|
||||
int);
|
||||
extern char *plugin_api_string_replace (struct t_weechat_plugin *,char *,
|
||||
char *, char *);
|
||||
extern char **plugin_api_string_explode (struct t_weechat_plugin *, char *,
|
||||
char *, int, int, int *);
|
||||
extern void plugin_api_string_free_exploded (struct t_weechat_plugin *,
|
||||
@@ -59,20 +61,23 @@ extern struct t_hook *plugin_api_hook_command (struct t_weechat_plugin *,
|
||||
char *,
|
||||
int (*)(void *, int, char **, char **),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_print (struct t_weechat_plugin *,
|
||||
void *, char *,
|
||||
int (*)(void *, void *, time_t, char *, char *),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_config (struct t_weechat_plugin *,
|
||||
char *, char *,
|
||||
int (*)(void *, char *, char *, char *),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_timer (struct t_weechat_plugin *,
|
||||
long, int,
|
||||
int (*)(void *), void *);
|
||||
extern struct t_hook *plugin_api_hook_fd (struct t_weechat_plugin *,
|
||||
int, int, int, int,
|
||||
int (*)(void *), void *);
|
||||
extern struct t_hook *plugin_api_hook_print (struct t_weechat_plugin *,
|
||||
void *, char *, int,
|
||||
int (*)(void *, void *, time_t, char *, char *),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_event (struct t_weechat_plugin *, char *,
|
||||
int (*)(void *, char *, void *),
|
||||
void *);
|
||||
extern struct t_hook *plugin_api_hook_config (struct t_weechat_plugin *,
|
||||
char *, char *,
|
||||
int (*)(void *, char *, char *, char *),
|
||||
void *);
|
||||
extern void plugin_api_unhook (struct t_weechat_plugin *, void *);
|
||||
extern void plugin_api_unhook_all (struct t_weechat_plugin *);
|
||||
|
||||
|
||||
@@ -231,6 +231,7 @@ plugin_load (char *filename)
|
||||
new_plugin->ngettext = &plugin_api_ngettext;
|
||||
new_plugin->strcasecmp = &plugin_api_strcasecmp;
|
||||
new_plugin->strncasecmp = &plugin_api_strncasecmp;
|
||||
new_plugin->string_replace = &plugin_api_string_replace;
|
||||
new_plugin->string_explode = &plugin_api_string_explode;
|
||||
new_plugin->string_free_exploded = &plugin_api_string_free_exploded;
|
||||
|
||||
@@ -245,10 +246,11 @@ plugin_load (char *filename)
|
||||
new_plugin->infobar_remove = &plugin_api_infobar_remove;
|
||||
|
||||
new_plugin->hook_command = &plugin_api_hook_command;
|
||||
new_plugin->hook_print = &plugin_api_hook_print;
|
||||
new_plugin->hook_config = &plugin_api_hook_config;
|
||||
new_plugin->hook_timer = &plugin_api_hook_timer;
|
||||
new_plugin->hook_fd = &plugin_api_hook_fd;
|
||||
new_plugin->hook_print = &plugin_api_hook_print;
|
||||
new_plugin->hook_event = &plugin_api_hook_event;
|
||||
new_plugin->hook_config = &plugin_api_hook_config;
|
||||
new_plugin->unhook = &plugin_api_unhook;
|
||||
new_plugin->unhook_all = &plugin_api_unhook_all;
|
||||
|
||||
@@ -289,11 +291,6 @@ plugin_load (char *filename)
|
||||
weechat_plugins = new_plugin;
|
||||
last_weechat_plugin = new_plugin;
|
||||
|
||||
gui_chat_printf (NULL,
|
||||
_("%sInitializing plugin \"%s\" %s\n"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
|
||||
new_plugin->name, new_plugin->version);
|
||||
|
||||
/* init plugin */
|
||||
if (((t_weechat_init_func *)init_func) (new_plugin) < 0)
|
||||
{
|
||||
@@ -319,9 +316,9 @@ plugin_load (char *filename)
|
||||
}
|
||||
|
||||
gui_chat_printf (NULL,
|
||||
_("%sPlugin \"%s\" (%s) loaded.\n"),
|
||||
_("%sPlugin \"%s\" %s loaded.\n"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
|
||||
name, full_name);
|
||||
name, new_plugin->version);
|
||||
|
||||
free (full_name);
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ struct t_weechat_plugin
|
||||
char *(*ngettext) (struct t_weechat_plugin *, char *, char *, int);
|
||||
int (*strcasecmp) (struct t_weechat_plugin *, char *, char *);
|
||||
int (*strncasecmp) (struct t_weechat_plugin *, char *, char *, int);
|
||||
char *(*string_replace) (struct t_weechat_plugin *, char *, char *, char *);
|
||||
char **(*string_explode) (struct t_weechat_plugin *, char *, char *, int,
|
||||
int, int *);
|
||||
void (*string_free_exploded) (struct t_weechat_plugin *, char **);
|
||||
@@ -86,16 +87,19 @@ struct t_weechat_plugin
|
||||
char *, char *, char *,
|
||||
int (*)(void *, int, char **, char **),
|
||||
void *);
|
||||
struct t_hook *(*hook_print) (struct t_weechat_plugin *, void *, char *,
|
||||
int (*)(void *, void *, time_t, char *, char *),
|
||||
void *);
|
||||
struct t_hook *(*hook_config) (struct t_weechat_plugin *, char *, char *,
|
||||
int (*)(void *, char *, char *, char *),
|
||||
void *);
|
||||
struct t_hook *(*hook_timer) (struct t_weechat_plugin *, long, int,
|
||||
int (*)(void *), void *);
|
||||
struct t_hook *(*hook_fd) (struct t_weechat_plugin *, int, int, int, int,
|
||||
int (*)(void *), void *);
|
||||
struct t_hook *(*hook_print) (struct t_weechat_plugin *, void *, char *,
|
||||
int,
|
||||
int (*)(void *, void *, time_t, char *, char *),
|
||||
void *);
|
||||
struct t_hook *(*hook_event) (struct t_weechat_plugin *, char *,
|
||||
int (*)(void *, char *, void *), void *);
|
||||
struct t_hook *(*hook_config) (struct t_weechat_plugin *, char *, char *,
|
||||
int (*)(void *, char *, char *, char *),
|
||||
void *);
|
||||
void (*unhook) (struct t_weechat_plugin *, void *);
|
||||
void (*unhook_all) (struct t_weechat_plugin *);
|
||||
|
||||
@@ -142,6 +146,12 @@ struct t_weechat_plugin
|
||||
|
||||
/* macros for easy call to plugin API */
|
||||
|
||||
#define weechat_charset_set(chset, string) \
|
||||
weechat_plugin->charset_set(weechat_plugin, string)
|
||||
#define weechat_iconv_to_internal(chset, string) \
|
||||
weechat_plugin->iconv_to_internal(weechat_plugin, chset, string)
|
||||
#define weechat_iconv_from_internal(chset, string) \
|
||||
weechat_plugin->iconv_from_internal(weechat_plugin, chset, string)
|
||||
#ifndef __WEECHAT_H
|
||||
#define _(string) weechat_plugin->gettext(weechat_plugin, string)
|
||||
#define N_(string) (string)
|
||||
@@ -152,6 +162,9 @@ struct t_weechat_plugin
|
||||
weechat_plugin->strcasecmp(weechat_plugin, string1, string2)
|
||||
#define weechat_strncasecmp(string1, string2, max) \
|
||||
weechat_plugin->strncasecmp(weechat_plugin, string1, string2, max)
|
||||
#define weechat_string_replace(string1, search1, replace1) \
|
||||
weechat_plugin->string_replace(weechat_plugin, string1, search1, \
|
||||
replace1)
|
||||
#define weechat_string_explode(string1, separator, eol, max, \
|
||||
num_items) \
|
||||
weechat_plugin->string_explode(weechat_plugin, string1, separator, \
|
||||
@@ -174,12 +187,6 @@ struct t_weechat_plugin
|
||||
weechat_plugin->hook_command(weechat_plugin, command, description, \
|
||||
args, args_desc, completion, callback, \
|
||||
data)
|
||||
#define weechat_hook_print(buffer, msg, callback, data) \
|
||||
weechat_plugin->hook_print(weechat_plugin, buffer, msg, \
|
||||
callback, data)
|
||||
#define weechat_hook_config(type, option, callback, data) \
|
||||
weechat_plugin->hook_config(weechat_plugin, type, option, \
|
||||
callback, data)
|
||||
#define weechat_hook_timer(interval, max_calls, callback, data) \
|
||||
weechat_plugin->hook_timer(weechat_plugin, interval, max_calls, \
|
||||
callback, data)
|
||||
@@ -187,6 +194,14 @@ struct t_weechat_plugin
|
||||
callback, data) \
|
||||
weechat_plugin->hook_fd(weechat_plugin, fd, flag_read, flag_write, \
|
||||
flag_exception, callback, data)
|
||||
#define weechat_hook_print(buffer, msg, strip_colors, callback, data) \
|
||||
weechat_plugin->hook_print(weechat_plugin, buffer, msg, \
|
||||
strip_colors, callback, data)
|
||||
#define weechat_hook_event(evnt, callback, data) \
|
||||
weechat_plugin->hook_event(weechat_plugin, evnt, callback, data)
|
||||
#define weechat_hook_config(type, option, callback, data) \
|
||||
weechat_plugin->hook_config(weechat_plugin, type, option, \
|
||||
callback, data)
|
||||
#define weechat_unhook(hook) \
|
||||
weechat_plugin->unhook(weechat_plugin, hook)
|
||||
#define weechat_unhook_all() \
|
||||
|
||||
Reference in New Issue
Block a user