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

Added on_connect event to plugins api

This commit is contained in:
James Booth 2013-08-03 00:22:00 +01:00
parent 799fd06680
commit 6cb32996a5
4 changed files with 35 additions and 3 deletions

View File

@ -14,6 +14,9 @@ def prof_init(version, status):
def prof_on_start(): def prof_on_start():
helloworld() helloworld()
def prof_on_connect():
helloworld();
# local functions # local functions
def helloworld(): def helloworld():

View File

@ -22,13 +22,15 @@
#include <Python.h> #include <Python.h>
#include "api/api.h"
#include "ui/ui.h" #include "ui/ui.h"
static GSList* _get_module_names(void); static GSList* _get_module_names(void);
static void _init(void); static void _init(void);
static void _on_start(void); static void _on_start(void);
static GSList* plugins;
static GSList* plugins;
static PyObject *prof_module;
// API // API
static PyObject* static PyObject*
@ -56,7 +58,7 @@ api_init(void)
GSList *module_names = _get_module_names(); GSList *module_names = _get_module_names();
Py_Initialize(); Py_Initialize();
Py_InitModule("prof", apiMethods); prof_module = Py_InitModule("prof", apiMethods);
// TODO change to use XDG spec // TODO change to use XDG spec
PySys_SetPath("$PYTHONPATH:./plugins/"); PySys_SetPath("$PYTHONPATH:./plugins/");
@ -81,10 +83,15 @@ api_init(void)
_init(); _init();
_on_start(); _on_start();
} }
Py_Finalize();
return; return;
} }
void
api_shutdown(void)
{
Py_Finalize();
}
static GSList * static GSList *
_get_module_names(void) _get_module_names(void)
{ {
@ -146,3 +153,21 @@ _on_start(void)
plugin = g_slist_next(plugin); plugin = g_slist_next(plugin);
} }
} }
void
plugins_on_connect(void)
{
GSList *plugin = plugins;
PyObject *p_prof_on_connect;
while (plugin != NULL) {
PyObject *module = plugin->data;
p_prof_on_connect = PyObject_GetAttrString(module, "prof_on_connect");
if (p_prof_on_connect && PyCallable_Check(p_prof_on_connect)) {
PyObject_CallObject(p_prof_on_connect, NULL);
Py_XDECREF(p_prof_on_connect);
}
plugin = g_slist_next(plugin);
}
}

View File

@ -24,5 +24,7 @@
#define API_H #define API_H
void api_init(void); void api_init(void);
void plugins_on_connect(void);
void api_shutdown(void);
#endif #endif

View File

@ -260,6 +260,7 @@ prof_handle_login_account_success(char *account_name)
status_bar_refresh(); status_bar_refresh();
accounts_free_account(account); accounts_free_account(account);
plugins_on_connect();
} }
void void
@ -651,6 +652,7 @@ _shutdown(void)
accounts_close(); accounts_close();
cmd_close(); cmd_close();
log_close(); log_close();
api_shutdown();
} }
static void static void