diff options
author | James Booth <boothj5@gmail.com> | 2016-04-07 21:25:12 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-04-07 21:25:12 +0100 |
commit | bfdc3b88072e0231c026fa6ebadc942343a56e2c (patch) | |
tree | a5845c5a038144259f9a10ee71577151d6b4859c | |
parent | a328367eb400012a04b9aac9204c9fab2e2fc583 (diff) | |
download | profani-tty-bfdc3b88072e0231c026fa6ebadc942343a56e2c.tar.gz |
Plugins: Added completer_remove
-rw-r--r-- | src/plugins/api.c | 6 | ||||
-rw-r--r-- | src/plugins/api.h | 1 | ||||
-rw-r--r-- | src/plugins/autocompleters.c | 14 | ||||
-rw-r--r-- | src/plugins/autocompleters.h | 1 | ||||
-rw-r--r-- | src/plugins/c_api.c | 7 | ||||
-rw-r--r-- | src/plugins/profapi.c | 1 | ||||
-rw-r--r-- | src/plugins/profapi.h | 1 | ||||
-rw-r--r-- | src/plugins/python_api.c | 29 |
8 files changed, 60 insertions, 0 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c index 711bc02b..12b40828 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -161,6 +161,12 @@ api_completer_add(const char *key, char **items) } void +api_completer_remove(const char *key, char **items) +{ + autocompleters_remove(key, items); +} + +void api_notify(const char *message, const char *category, int timeout_ms) { notify(message, timeout_ms, category); diff --git a/src/plugins/api.h b/src/plugins/api.h index 357d506e..bf2b3754 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -55,6 +55,7 @@ void api_register_timed(void *callback, int interval_seconds, void (*callback_func)(PluginTimedFunction *timed_function)); void api_completer_add(const char *key, char **items); +void api_completer_remove(const char *key, char **items); void api_log_debug(const char *message); void api_log_info(const char *message); diff --git a/src/plugins/autocompleters.c b/src/plugins/autocompleters.c index 9acbf755..b6877c4e 100644 --- a/src/plugins/autocompleters.c +++ b/src/plugins/autocompleters.c @@ -66,6 +66,20 @@ autocompleters_add(const char *key, char **items) } } +void +autocompleters_remove(const char *key, char **items) +{ + if (!g_hash_table_contains(autocompleters, key)) { + return; + } + + Autocomplete ac = g_hash_table_lookup(autocompleters, key); + int i = 0; + for (i = 0; i < g_strv_length(items); i++) { + autocomplete_remove(ac, items[i]); + } +} + char * autocompleters_complete(const char * const input) { diff --git a/src/plugins/autocompleters.h b/src/plugins/autocompleters.h index 20b5d0fc..71520828 100644 --- a/src/plugins/autocompleters.h +++ b/src/plugins/autocompleters.h @@ -39,6 +39,7 @@ void autocompleters_init(void); void autocompleters_add(const char *key, char **items); +void autocompleters_remove(const char *key, char **items); char* autocompleters_complete(const char * const input); void autocompleters_reset(void); void autocompleters_destroy(void); diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 32369523..38555237 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -103,6 +103,12 @@ c_api_completer_add(const char *key, char **items) } static void +c_api_completer_remove(const char *key, char **items) +{ + api_completer_remove(key, items); +} + +static void c_api_notify(const char *message, int timeout_ms, const char *category) { api_notify(message, category, timeout_ms); @@ -270,6 +276,7 @@ c_api_init(void) prof_register_command = c_api_register_command; prof_register_timed = c_api_register_timed; prof_completer_add = c_api_completer_add; + prof_completer_remove = c_api_completer_remove; prof_notify = c_api_notify; prof_send_line = c_api_send_line; prof_get_current_recipient = c_api_get_current_recipient; diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 3d92fb23..8cf562b8 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -49,6 +49,7 @@ void (*prof_register_command)(const char *command_name, int min_args, int max_ar void (*prof_register_timed)(void(*callback)(void), int interval_seconds) = NULL; void (*prof_completer_add)(const char *key, char **items) = NULL; +void (*prof_completer_remove)(const char *key, char **items) = NULL; void (*prof_notify)(const char *message, int timeout_ms, const char *category) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 61d41cfc..28c67763 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -49,6 +49,7 @@ void (*prof_register_command)(const char *command_name, int min_args, int max_ar void (*prof_register_timed)(void(*callback)(void), int interval_seconds); void (*prof_completer_add)(const char *key, char **items); +void (*prof_completer_remove)(const char *key, char **items); void (*prof_notify)(const char *message, int timeout_ms, const char *category); diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 9cac70ae..90b72619 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -213,6 +213,34 @@ python_api_completer_add(PyObject *self, PyObject *args) return Py_BuildValue(""); } +static PyObject * +python_api_completer_remove(PyObject *self, PyObject *args) +{ + const char *key = NULL; + PyObject *items = NULL; + + if (!PyArg_ParseTuple(args, "sO", &key, &items)) { + return Py_BuildValue(""); + } + + Py_ssize_t len = PyList_Size(items); + char *c_items[len]; + + Py_ssize_t i = 0; + for (i = 0; i < len; i++) { + PyObject *item = PyList_GetItem(items, i); + char *c_item = PyString_AsString(item); + c_items[i] = c_item; + } + c_items[len] = NULL; + + allow_python_threads(); + autocompleters_remove(key, c_items); + disable_python_threads(); + + return Py_BuildValue(""); +} + static PyObject* python_api_notify(PyObject *self, PyObject *args) { @@ -664,6 +692,7 @@ static PyMethodDef apiMethods[] = { { "register_command", python_api_register_command, METH_VARARGS, "Register a command." }, { "register_timed", python_api_register_timed, METH_VARARGS, "Register a timed function." }, { "completer_add", python_api_completer_add, METH_VARARGS, "Add items to an autocompleter." }, + { "completer_remove", python_api_completer_remove, METH_VARARGS, "Remove items from an autocompleter." }, { "send_line", python_api_send_line, METH_VARARGS, "Send a line of input." }, { "notify", python_api_notify, METH_VARARGS, "Send desktop notification." }, { "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." }, |