1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Plugins: Added on_room_win_focus

This commit is contained in:
James Booth 2016-04-07 22:15:03 +01:00
parent 271278dd20
commit 7ca6084657
7 changed files with 53 additions and 0 deletions

View File

@ -106,6 +106,7 @@ c_plugin_create(const char *const filename)
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;
plugin->on_room_win_focus = c_on_room_win_focus_hook;
g_string_free(path, TRUE);
g_free(module_name);
@ -487,6 +488,20 @@ c_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid)
func(barejid);
}
void
c_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid)
{
void *f = NULL;
void (*func)(const char *const __roomjid);
assert(plugin && plugin->module);
if (NULL == (f = dlsym(plugin->module, "prof_on_room_win_focus")))
return;
func = (void (*)(const char *const))f;
func(roomjid);
}
void
c_plugin_destroy(ProfPlugin *plugin)
{

View File

@ -85,5 +85,6 @@ void c_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, c
const char *const presence, const char *const status, const int priority);
void c_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid);
void c_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid);
#endif

View File

@ -559,6 +559,17 @@ plugins_on_chat_win_focus(const char *const barejid)
}
}
void
plugins_on_room_win_focus(const char *const roomjid)
{
GSList *curr = plugins;
while (curr) {
ProfPlugin *plugin = curr->data;
plugin->on_room_win_focus(plugin, roomjid);
curr = g_slist_next(curr);
}
}
void
plugins_shutdown(void)
{

View File

@ -92,6 +92,7 @@ typedef struct prof_plugin_t {
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);
void (*on_room_win_focus)(struct prof_plugin_t* plugin, const char *const roomjid);
} ProfPlugin;
void plugins_init(void);
@ -138,6 +139,7 @@ void plugins_on_contact_presence(const char *const barejid, const char *const re
const char *const status, const int priority);
void plugins_on_chat_win_focus(const char *const barejid);
void plugins_on_room_win_focus(const char *const roomjid);
gboolean plugins_run_command(const char * const cmd);
void plugins_run_timed(void);

View File

@ -124,6 +124,7 @@ python_plugin_create(const char *const filename)
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;
plugin->on_room_win_focus = python_on_room_win_focus_hook;
g_free(module_name);
allow_python_threads();
@ -840,6 +841,27 @@ python_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid)
allow_python_threads();
}
void
python_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid)
{
disable_python_threads();
PyObject *p_args = Py_BuildValue("(s)", roomjid);
PyObject *p_function;
PyObject *p_module = plugin->module;
if (PyObject_HasAttrString(p_module, "prof_on_room_win_focus")) {
p_function = PyObject_GetAttrString(p_module, "prof_on_room_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)
{

View File

@ -83,5 +83,6 @@ void python_on_contact_presence_hook(ProfPlugin *plugin, const char *const barej
const char *const presence, const char *const status, const int priority);
void python_on_chat_win_focus_hook(ProfPlugin *plugin, const char *const barejid);
void python_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid);
#endif

View File

@ -333,6 +333,7 @@ wins_set_current_by_num(int i)
mucwin->unread = 0;
mucwin->unread_mentions = FALSE;
mucwin->unread_triggers = FALSE;
plugins_on_room_win_focus(mucwin->roomjid);
} else if (window->type == WIN_PRIVATE) {
ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
privatewin->unread = 0;