From 271278dd20d1decfcfc06493698dc72e9fc24891 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 Apr 2016 22:06:14 +0100 Subject: Plugins: Added on_chat_win_focus --- src/plugins/c_plugins.c | 15 +++++++++++++++ src/plugins/c_plugins.h | 2 ++ src/plugins/plugins.c | 11 +++++++++++ src/plugins/plugins.h | 4 ++++ src/plugins/python_plugins.c | 22 ++++++++++++++++++++++ src/plugins/python_plugins.h | 2 ++ src/window_list.c | 3 +++ 7 files changed, 59 insertions(+) diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index 2c555689..fb99765f 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -105,6 +105,7 @@ c_plugin_create(const char *const filename) plugin->on_iq_stanza_receive = c_on_iq_stanza_receive_hook; plugin->on_contact_offline = c_on_contact_offline_hook; plugin->on_contact_presence = c_on_contact_presence_hook; + plugin->on_chat_win_focus = c_on_chat_win_focus_hook; g_string_free(path, TRUE); g_free(module_name); @@ -472,6 +473,20 @@ c_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, const func(barejid, resource, presence, status, priority); } +void +c_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid) +{ + void *f = NULL; + void (*func)(const char *const __barejid); + assert(plugin && plugin->module); + + if (NULL == (f = dlsym(plugin->module, "prof_on_chat_win_focus"))) + return; + + func = (void (*)(const char *const))f; + func(barejid); +} + void c_plugin_destroy(ProfPlugin *plugin) { diff --git a/src/plugins/c_plugins.h b/src/plugins/c_plugins.h index b8d8ce4e..e9ae0c04 100644 --- a/src/plugins/c_plugins.h +++ b/src/plugins/c_plugins.h @@ -84,4 +84,6 @@ void c_on_contact_offline_hook(ProfPlugin *plugin, const char *const barejid, co void c_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, const char *const resource, const char *const presence, const char *const status, const int priority); +void c_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid); + #endif diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 87b892d1..910484a9 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -548,6 +548,17 @@ plugins_on_contact_presence(const char *const barejid, const char *const resourc } } +void +plugins_on_chat_win_focus(const char *const barejid) +{ + GSList *curr = plugins; + while (curr) { + ProfPlugin *plugin = curr->data; + plugin->on_chat_win_focus(plugin, barejid); + curr = g_slist_next(curr); + } +} + void plugins_shutdown(void) { diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index c1f9d4e8..df9293eb 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -90,6 +90,8 @@ typedef struct prof_plugin_t { const char *const status); void (*on_contact_presence)(struct prof_plugin_t* plugin, const char *const barejid, const char *const resource, const char *const presence, const char *const status, const int priority); + + void (*on_chat_win_focus)(struct prof_plugin_t* plugin, const char *const barejid); } ProfPlugin; void plugins_init(void); @@ -135,6 +137,8 @@ void plugins_on_contact_offline(const char *const barejid, const char *const res void plugins_on_contact_presence(const char *const barejid, const char *const resource, const char *const presence, const char *const status, const int priority); +void plugins_on_chat_win_focus(const char *const barejid); + gboolean plugins_run_command(const char * const cmd); void plugins_run_timed(void); GList* plugins_get_command_names(void); diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index e16fb521..cf492693 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -123,6 +123,7 @@ python_plugin_create(const char *const filename) plugin->on_iq_stanza_receive = python_on_iq_stanza_receive_hook; plugin->on_contact_offline = python_on_contact_offline_hook; plugin->on_contact_presence = python_on_contact_presence_hook; + plugin->on_chat_win_focus = python_on_chat_win_focus_hook; g_free(module_name); allow_python_threads(); @@ -818,6 +819,27 @@ python_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, c allow_python_threads(); } +void +python_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid) +{ + disable_python_threads(); + PyObject *p_args = Py_BuildValue("(s)", barejid); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_chat_win_focus")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_chat_win_focus"); + python_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject_CallObject(p_function, p_args); + python_check_error(); + Py_XDECREF(p_function); + } + } + + allow_python_threads(); +} + void python_check_error(void) { diff --git a/src/plugins/python_plugins.h b/src/plugins/python_plugins.h index 152e229e..f50a649b 100644 --- a/src/plugins/python_plugins.h +++ b/src/plugins/python_plugins.h @@ -82,4 +82,6 @@ void python_on_contact_offline_hook(ProfPlugin *plugin, const char *const bareji void python_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, const char *const resource, const char *const presence, const char *const status, const int priority); +void python_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid); + #endif diff --git a/src/window_list.c b/src/window_list.c index 65285898..de057a66 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -46,6 +46,8 @@ #include "ui/ui.h" #include "ui/statusbar.h" #include "window_list.h" +#include "plugins/plugins.h" + static GHashTable *windows; static int current; @@ -324,6 +326,7 @@ wins_set_current_by_num(int i) ProfChatWin *chatwin = (ProfChatWin*) window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); chatwin->unread = 0; + plugins_on_chat_win_focus(chatwin->barejid); } else if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*) window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); -- cgit 1.4.1-2-gfad0