mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Merge branch 'master' into osx-functional
This commit is contained in:
commit
30b18a978d
@ -155,11 +155,23 @@ api_register_timed(void *callback, int interval_seconds,
|
||||
}
|
||||
|
||||
void
|
||||
api_register_ac(const char *key, char **items)
|
||||
api_completer_add(const char *key, char **items)
|
||||
{
|
||||
autocompleters_add(key, items);
|
||||
}
|
||||
|
||||
void
|
||||
api_completer_remove(const char *key, char **items)
|
||||
{
|
||||
autocompleters_remove(key, items);
|
||||
}
|
||||
|
||||
void
|
||||
api_completer_clear(const char *key)
|
||||
{
|
||||
autocompleters_clear(key);
|
||||
}
|
||||
|
||||
void
|
||||
api_notify(const char *message, const char *category, int timeout_ms)
|
||||
{
|
||||
|
@ -53,7 +53,10 @@ void api_register_command(const char *command_name, int min_args, int max_args,
|
||||
void *callback, void(*callback_func)(PluginCommand *command, gchar **args));
|
||||
void api_register_timed(void *callback, int interval_seconds,
|
||||
void (*callback_func)(PluginTimedFunction *timed_function));
|
||||
void api_register_ac(const char *key, char **items);
|
||||
|
||||
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);
|
||||
|
@ -66,6 +66,31 @@ 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]);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -39,6 +39,8 @@
|
||||
|
||||
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);
|
||||
|
@ -97,9 +97,21 @@ c_api_register_timed(void(*callback)(void), int interval_seconds)
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_register_ac(const char *key, char **items)
|
||||
c_api_completer_add(const char *key, char **items)
|
||||
{
|
||||
api_register_ac(key, items);
|
||||
api_completer_add(key, items);
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_completer_remove(const char *key, char **items)
|
||||
{
|
||||
api_completer_remove(key, items);
|
||||
}
|
||||
|
||||
static void
|
||||
c_api_completer_clear(const char *key)
|
||||
{
|
||||
api_completer_clear(key);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -269,7 +281,9 @@ c_api_init(void)
|
||||
prof_cons_bad_cmd_usage = c_api_cons_bad_cmd_usage;
|
||||
prof_register_command = c_api_register_command;
|
||||
prof_register_timed = c_api_register_timed;
|
||||
prof_register_ac = c_api_register_ac;
|
||||
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;
|
||||
|
@ -105,6 +105,8 @@ 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;
|
||||
plugin->on_room_win_focus = c_on_room_win_focus_hook;
|
||||
|
||||
g_string_free(path, TRUE);
|
||||
g_free(module_name);
|
||||
@ -472,6 +474,34 @@ c_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, const
|
||||
func(barejid, resource, presence, status, priority);
|
||||
}
|
||||
|
||||
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_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid)
|
||||
{
|
||||
void *f = NULL;
|
||||
void (*func)(const char *const __roomjid);
|
||||
assert(plugin && plugin->module);
|
||||
|
||||
if (NULL == (f = dlsym(plugin->module, "prof_on_room_win_focus")))
|
||||
return;
|
||||
|
||||
func = (void (*)(const char *const))f;
|
||||
func(roomjid);
|
||||
}
|
||||
|
||||
void
|
||||
c_plugin_destroy(ProfPlugin *plugin)
|
||||
{
|
||||
|
@ -84,4 +84,7 @@ 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);
|
||||
void c_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid);
|
||||
|
||||
#endif
|
||||
|
@ -548,6 +548,28 @@ 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_on_room_win_focus(const char *const roomjid)
|
||||
{
|
||||
GSList *curr = plugins;
|
||||
while (curr) {
|
||||
ProfPlugin *plugin = curr->data;
|
||||
plugin->on_room_win_focus(plugin, roomjid);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
plugins_shutdown(void)
|
||||
{
|
||||
|
@ -90,6 +90,9 @@ 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);
|
||||
void (*on_room_win_focus)(struct prof_plugin_t* plugin, const char *const roomjid);
|
||||
} ProfPlugin;
|
||||
|
||||
void plugins_init(void);
|
||||
@ -135,6 +138,9 @@ 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);
|
||||
void plugins_on_room_win_focus(const char *const roomjid);
|
||||
|
||||
gboolean plugins_run_command(const char * const cmd);
|
||||
void plugins_run_timed(void);
|
||||
GList* plugins_get_command_names(void);
|
||||
|
@ -48,7 +48,9 @@ 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_register_ac)(const char *key, char **items) = 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;
|
||||
|
||||
|
@ -48,7 +48,9 @@ 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_register_ac)(const char *key, char **items);
|
||||
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);
|
||||
|
||||
|
@ -186,7 +186,7 @@ python_api_register_timed(PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_api_register_ac(PyObject *self, PyObject *args)
|
||||
python_api_completer_add(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *key = NULL;
|
||||
PyObject *items = NULL;
|
||||
@ -213,6 +213,50 @@ python_api_register_ac(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_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)
|
||||
{
|
||||
@ -663,7 +707,9 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "cons_bad_cmd_usage", python_api_cons_bad_cmd_usage, METH_VARARGS, "Show invalid command message in console" },
|
||||
{ "register_command", python_api_register_command, METH_VARARGS, "Register a command." },
|
||||
{ "register_timed", python_api_register_timed, METH_VARARGS, "Register a timed function." },
|
||||
{ "register_ac", python_api_register_ac, METH_VARARGS, "Register an autocompleter." },
|
||||
{ "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." },
|
||||
|
@ -123,6 +123,8 @@ 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;
|
||||
plugin->on_room_win_focus = python_on_room_win_focus_hook;
|
||||
g_free(module_name);
|
||||
|
||||
allow_python_threads();
|
||||
@ -818,6 +820,48 @@ python_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, c
|
||||
allow_python_threads();
|
||||
}
|
||||
|
||||
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_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid)
|
||||
{
|
||||
disable_python_threads();
|
||||
PyObject *p_args = Py_BuildValue("(s)", roomjid);
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
if (PyObject_HasAttrString(p_module, "prof_on_room_win_focus")) {
|
||||
p_function = PyObject_GetAttrString(p_module, "prof_on_room_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)
|
||||
{
|
||||
|
@ -82,4 +82,7 @@ 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);
|
||||
void python_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid);
|
||||
|
||||
#endif
|
||||
|
@ -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,12 +326,14 @@ 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);
|
||||
mucwin->unread = 0;
|
||||
mucwin->unread_mentions = FALSE;
|
||||
mucwin->unread_triggers = FALSE;
|
||||
plugins_on_room_win_focus(mucwin->roomjid);
|
||||
} else if (window->type == WIN_PRIVATE) {
|
||||
ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
|
||||
privatewin->unread = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user