From 4882e839707419cc60a3e70b1a8779087e77c934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Fri, 19 Sep 2014 18:55:50 +0200 Subject: [PATCH] Added tox_connected_identities and tox_disconnected_identities. --- src/tox-weechat-completion.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/tox-weechat-completion.c b/src/tox-weechat-completion.c index 7aa5b34..657b618 100644 --- a/src/tox-weechat-completion.c +++ b/src/tox-weechat-completion.c @@ -1,4 +1,5 @@ #include +#include #include @@ -7,20 +8,34 @@ #include "tox-weechat-completion.h" +enum +{ + TOX_WEECHAT_ALL_IDENTITIES, + TOX_WEECHAT_CONNECTED_IDENTITIES, + TOX_WEECHAT_DISCONNECTED_IDENTITIES, +}; + int tox_weechat_completion_identity(void *data, const char *completion_item, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { + int flag = (int)(intptr_t)data; + for (struct t_tox_weechat_identity *identity = tox_weechat_identities; identity; identity = identity->next_identity) { - weechat_hook_completion_list_add(completion, - identity->name, - 0, - WEECHAT_LIST_POS_SORT); + if (flag == TOX_WEECHAT_ALL_IDENTITIES + || (flag == TOX_WEECHAT_CONNECTED_IDENTITIES && identity->tox != NULL) + || (flag == TOX_WEECHAT_DISCONNECTED_IDENTITIES && identity->tox == NULL)) + { + weechat_hook_completion_list_add(completion, + identity->name, + 0, + WEECHAT_LIST_POS_SORT); + } } return WEECHAT_RC_OK; @@ -31,5 +46,14 @@ tox_weechat_completion_init() { weechat_hook_completion("tox_identities", "identity", - tox_weechat_completion_identity, NULL); + tox_weechat_completion_identity, + (void *)(intptr_t)TOX_WEECHAT_ALL_IDENTITIES); + weechat_hook_completion("tox_connected_identities", + "identity", + tox_weechat_completion_identity, + (void *)(intptr_t)TOX_WEECHAT_CONNECTED_IDENTITIES); + weechat_hook_completion("tox_disconnected_identities", + "identity", + tox_weechat_completion_identity, + (void *)(intptr_t)TOX_WEECHAT_DISCONNECTED_IDENTITIES); }