mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 21:05:42 +02:00
Event hook added
This commit is contained in:
+75
-54
File diff suppressed because it is too large
Load Diff
+241
-154
File diff suppressed because it is too large
Load Diff
+45
-30
File diff suppressed because it is too large
Load Diff
+18
-15
@@ -44,6 +44,7 @@
|
||||
#include "gui-window.h"
|
||||
#include "../core/wee-command.h"
|
||||
#include "../core/wee-config.h"
|
||||
#include "../core/wee-hook.h"
|
||||
#include "../core/wee-log.h"
|
||||
#include "../core/wee-string.h"
|
||||
#include "../core/wee-utf8.h"
|
||||
@@ -67,7 +68,6 @@ gui_buffer_new (void *plugin, char *category, char *name)
|
||||
{
|
||||
struct t_gui_buffer *new_buffer;
|
||||
struct t_gui_completion *new_completion;
|
||||
char buffer_str[16], *argv[1] = { NULL };
|
||||
|
||||
#ifdef DEBUG
|
||||
weechat_log_printf ("Creating new buffer\n");
|
||||
@@ -76,6 +76,16 @@ gui_buffer_new (void *plugin, char *category, char *name)
|
||||
if (!category || !name)
|
||||
return NULL;
|
||||
|
||||
if (gui_buffer_search_by_category_name (category, name))
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: a buffer with same name already exists "
|
||||
"(%s / %s)"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
category, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create new buffer */
|
||||
if ((new_buffer = (struct t_gui_buffer *)(malloc (sizeof (struct t_gui_buffer)))))
|
||||
{
|
||||
@@ -166,10 +176,7 @@ gui_buffer_new (void *plugin, char *category, char *name)
|
||||
gui_window_redraw_buffer (new_buffer);
|
||||
}
|
||||
|
||||
snprintf (buffer_str, sizeof (buffer_str) - 1, "%d", new_buffer->number);
|
||||
argv[0] = buffer_str;
|
||||
/* TODO: send buffer_open event */
|
||||
/*(void) plugin_event_handler_exec ("buffer_open", 1, argv);*/
|
||||
(void) hook_event_exec ("buffer_open", new_buffer);
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
@@ -384,15 +391,15 @@ gui_buffer_search_by_category_name (char *category, char *name)
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
if (!category && !name)
|
||||
return gui_current_window->buffer;
|
||||
return NULL;
|
||||
|
||||
for (ptr_buffer = gui_buffers; ptr_buffer;
|
||||
ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
if ((category && ptr_buffer->category
|
||||
&& strcmp (ptr_buffer->category, category) == 0)
|
||||
|| (name && ptr_buffer->name
|
||||
&& strcmp (ptr_buffer->name, name) == 0))
|
||||
if ((!category || (ptr_buffer->category
|
||||
&& (strcmp (ptr_buffer->category, category) == 0)))
|
||||
&& (!name || (ptr_buffer->name
|
||||
&& (strcmp (ptr_buffer->name, name) == 0))))
|
||||
return ptr_buffer;
|
||||
}
|
||||
|
||||
@@ -576,12 +583,8 @@ gui_buffer_free (struct t_gui_buffer *buffer, int switch_to_another)
|
||||
struct t_gui_window *ptr_window;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
struct t_gui_line *ptr_line;
|
||||
char buffer_str[16], *argv[1] = { NULL };
|
||||
|
||||
snprintf (buffer_str, sizeof (buffer_str) - 1, "%d", buffer->number);
|
||||
argv[0] = buffer_str;
|
||||
/* TODO: send buffer_close event */
|
||||
/*(void) plugin_event_handler_exec ("buffer_close", 1, argv);*/
|
||||
(void) hook_event_exec ("buffer_close", buffer);
|
||||
|
||||
if (switch_to_another)
|
||||
{
|
||||
|
||||
+54
-12
File diff suppressed because it is too large
Load Diff
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -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