about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-04-07 22:06:14 +0100
committerJames Booth <boothj5@gmail.com>2016-04-07 22:06:14 +0100
commit271278dd20d1decfcfc06493698dc72e9fc24891 (patch)
treef5dc20544978f7da9b560e3884c93c5469ece02a
parentbfdc3b88072e0231c026fa6ebadc942343a56e2c (diff)
downloadprofani-tty-271278dd20d1decfcfc06493698dc72e9fc24891.tar.gz
Plugins: Added on_chat_win_focus
-rw-r--r--src/plugins/c_plugins.c15
-rw-r--r--src/plugins/c_plugins.h2
-rw-r--r--src/plugins/plugins.c11
-rw-r--r--src/plugins/plugins.h4
-rw-r--r--src/plugins/python_plugins.c22
-rw-r--r--src/plugins/python_plugins.h2
-rw-r--r--src/window_list.c3
7 files changed, 59 insertions, 0 deletions
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);
@@ -473,6 +474,20 @@ c_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, const
 }
 
 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)
 {
     assert (plugin && plugin->module);
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
@@ -549,6 +549,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)
 {
     GSList *curr = plugins;
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();
@@ -819,6 +820,27 @@ python_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, c
 }
 
 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)
 {
     if (PyErr_Occurred()) {
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);