1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Merge branch 'master' into plugins-python

This commit is contained in:
James Booth 2016-03-07 20:44:18 +00:00
commit 9850e041c8
7 changed files with 38 additions and 8 deletions

View File

@ -239,12 +239,16 @@ api_win_exists(const char *tag)
}
void
api_win_create(const char *tag, void *callback,
api_win_create(
const char *tag,
void *callback,
void(*destroy)(void *callback),
void(*callback_func)(PluginWindowCallback *window_callback, const char *tag, const char * const line))
{
PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback));
window->callback = callback;
window->callback_func = callback_func;
window->destroy = destroy;
callbacks_add_window_handler(tag, window);
wins_new_plugin(tag);

View File

@ -61,7 +61,10 @@ void api_log_warning(const char *message);
void api_log_error(const char *message);
int api_win_exists(const char *tag);
void api_win_create(const char *tag, void *callback,
void api_win_create(
const char *tag,
void *callback,
void(*destroy)(void *callback),
void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line));
int api_win_focus(const char *tag);
int api_win_show(const char *tag, const char *line);

View File

@ -167,7 +167,7 @@ c_api_win_create(char *tag, void(*callback)(char *tag, char *line))
{
WindowWrapper *wrapper = malloc(sizeof(WindowWrapper));
wrapper->func = callback;
api_win_create(tag, wrapper, c_window_callback);
api_win_create(tag, wrapper, free, c_window_callback);
}
static int

View File

@ -46,6 +46,27 @@ static GSList *p_commands = NULL;
static GSList *p_timed_functions = NULL;
static GHashTable *p_window_callbacks = NULL;
static void
_free_window_callback(PluginWindowCallback *window_callback)
{
if (window_callback->destroy) {
window_callback->destroy(window_callback->callback);
}
free(window_callback);
}
void
callbacks_init(void)
{
p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback);
}
void
callbacks_close(void)
{
g_hash_table_destroy(p_window_callbacks);
}
void
callbacks_add_command(PluginCommand *command)
{
@ -64,10 +85,6 @@ callbacks_add_timed(PluginTimedFunction *timed_function)
void
callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback)
{
if (p_window_callbacks == NULL) {
p_window_callbacks = g_hash_table_new(g_str_hash, g_str_equal);
}
g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback);
}

View File

@ -57,9 +57,13 @@ typedef struct p_timed_function {
typedef struct p_window_input_callback {
void *callback;
void (*destroy)(void *callback);
void (*callback_func)(struct p_window_input_callback *window_callback, const char *tag, const char * const line);
} PluginWindowCallback;
void callbacks_init(void);
void callbacks_close(void);
void callbacks_add_command(PluginCommand *command);
void callbacks_add_timed(PluginTimedFunction *timed_function);
void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback);

View File

@ -63,6 +63,7 @@ void
plugins_init(void)
{
plugins = NULL;
callbacks_init();
autocompleters_init();
#ifdef PROF_HAVE_PYTHON
@ -434,6 +435,7 @@ plugins_shutdown(void)
autocompleters_destroy();
plugin_themes_close();
callbacks_close();
}
gchar *

View File

@ -325,7 +325,7 @@ python_api_win_create(PyObject *self, PyObject *args)
}
if (p_callback && PyCallable_Check(p_callback)) {
api_win_create(tag, p_callback, python_window_callback);
api_win_create(tag, p_callback, NULL, python_window_callback);
}
return Py_BuildValue("");