about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/api.c6
-rw-r--r--src/plugins/api.h1
-rw-r--r--src/plugins/autocompleters.c11
-rw-r--r--src/plugins/autocompleters.h1
-rw-r--r--src/plugins/c_api.c7
-rw-r--r--src/plugins/profapi.c1
-rw-r--r--src/plugins/profapi.h1
-rw-r--r--src/plugins/python_api.c17
8 files changed, 45 insertions, 0 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c
index 12b40828..c4130498 100644
--- a/src/plugins/api.c
+++ b/src/plugins/api.c
@@ -167,6 +167,12 @@ api_completer_remove(const char *key, char **items)
 }
 
 void
+api_completer_clear(const char *key)
+{
+    autocompleters_clear(key);
+}
+
+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 bf2b3754..fd6dba26 100644
--- a/src/plugins/api.h
+++ b/src/plugins/api.h
@@ -56,6 +56,7 @@ void api_register_timed(void *callback, int interval_seconds,
 
 void api_completer_add(const char *key, char **items);
 void api_completer_remove(const char *key, char **items);
+void api_completer_clear(const char *key);
 
 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 b6877c4e..36ffea4a 100644
--- a/src/plugins/autocompleters.c
+++ b/src/plugins/autocompleters.c
@@ -80,6 +80,17 @@ autocompleters_remove(const char *key, char **items)
     }
 }
 
+void
+autocompleters_clear(const char *key)
+{
+    if (!g_hash_table_contains(autocompleters, key)) {
+        return;
+    }
+
+    Autocomplete ac = g_hash_table_lookup(autocompleters, key);
+    autocomplete_clear(ac);
+}
+
 char *
 autocompleters_complete(const char * const input)
 {
diff --git a/src/plugins/autocompleters.h b/src/plugins/autocompleters.h
index 71520828..a04dfe2f 100644
--- a/src/plugins/autocompleters.h
+++ b/src/plugins/autocompleters.h
@@ -40,6 +40,7 @@
 void autocompleters_init(void);
 void autocompleters_add(const char *key, char **items);
 void autocompleters_remove(const char *key, char **items);
+void autocompleters_clear(const char *key);
 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 38555237..74b5d92d 100644
--- a/src/plugins/c_api.c
+++ b/src/plugins/c_api.c
@@ -109,6 +109,12 @@ c_api_completer_remove(const char *key, char **items)
 }
 
 static void
+c_api_completer_clear(const char *key)
+{
+    api_completer_clear(key);
+}
+
+static void
 c_api_notify(const char *message, int timeout_ms, const char *category)
 {
     api_notify(message, category, timeout_ms);
@@ -277,6 +283,7 @@ c_api_init(void)
     prof_register_timed = c_api_register_timed;
     prof_completer_add = c_api_completer_add;
     prof_completer_remove = c_api_completer_remove;
+    prof_completer_clear = c_api_completer_clear;
     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 8cf562b8..207f5e69 100644
--- a/src/plugins/profapi.c
+++ b/src/plugins/profapi.c
@@ -50,6 +50,7 @@ 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_completer_clear)(const char *key) = 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 28c67763..043a1548 100644
--- a/src/plugins/profapi.h
+++ b/src/plugins/profapi.h
@@ -50,6 +50,7 @@ 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_completer_clear)(const char *key);
 
 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 90b72619..d3f684b1 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -241,6 +241,22 @@ python_api_completer_remove(PyObject *self, PyObject *args)
     return Py_BuildValue("");
 }
 
+static PyObject *
+python_api_completer_clear(PyObject *self, PyObject *args)
+{
+    const char *key = NULL;
+
+    if (!PyArg_ParseTuple(args, "s", &key)) {
+        return Py_BuildValue("");
+    }
+
+    allow_python_threads();
+    autocompleters_clear(key);
+    disable_python_threads();
+
+    return Py_BuildValue("");
+}
+
 static PyObject*
 python_api_notify(PyObject *self, PyObject *args)
 {
@@ -693,6 +709,7 @@ static PyMethodDef apiMethods[] = {
     { "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." },
+    { "completer_clear", python_api_completer_clear, METH_VARARGS, "Remove all 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." },