diff options
author | Antoine Pietri <antoine.pietri@lrde.epita.fr> | 2015-03-01 19:20:32 +0100 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-03-13 22:02:56 -0300 |
commit | 6a489929c121c20f7fad55fb6ec15c52643ee5ae (patch) | |
tree | 36b114371edc532d6c985d209911c88774cc166e /protocols/purple/purple.c | |
parent | fedc8f18391b7d623a527c26dd70f21705968bcd (diff) |
purple: handle purple_request_input
Diffstat (limited to 'protocols/purple/purple.c')
-rw-r--r-- | protocols/purple/purple.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index 004032c4..524313e6 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -39,6 +39,17 @@ static bee_t *local_bee; static char *set_eval_display_name(set_t *set, char *value); +void purple_request_input_callback(guint id, struct im_connection *ic, + const char *message, const char *who); + +/* purple_request_input specific stuff */ +typedef void (*ri_callback_t)(gpointer, const gchar *); + +struct request_input_data { + ri_callback_t data_callback; + void *user_data; +}; + struct im_connection *purple_ic_by_pa(PurpleAccount *pa) { GSList *i; @@ -310,6 +321,9 @@ static void purple_login(account_t *acc) ic->proto_data = pd = g_new0(struct purple_data, 1); pd->account = purple_account_new(acc->user, (char *) acc->prpl->data); + pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal, + NULL, g_free); + pd->next_request_id = 0; purple_account_set_password(pd->account, acc->pass); purple_sync_settings(acc, pd->account); @@ -323,6 +337,7 @@ static void purple_logout(struct im_connection *ic) purple_account_set_enabled(pd->account, "BitlBee", FALSE); purple_connections = g_slist_remove(purple_connections, ic); purple_accounts_remove(pd->account); + g_hash_table_destroy(pd->input_requests); g_free(pd); } @@ -331,6 +346,12 @@ static int purple_buddy_msg(struct im_connection *ic, char *who, char *message, PurpleConversation *conv; struct purple_data *pd = ic->proto_data; + if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) { + guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE)); + purple_request_input_callback(request_id, ic, message, who); + return 1; + } + if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, pd->account)) == NULL) { conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, @@ -1067,9 +1088,48 @@ static void prplcb_request_test() } */ +void* prplcb_request_input(const char *title, const char *primary, + const char *secondary, const char *default_value, gboolean multiline, + gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, PurpleAccount *account, + const char *who, PurpleConversation *conv, void *user_data) +{ + struct im_connection *ic = purple_ic_by_pa(account); + struct purple_data *pd = ic->proto_data; + struct request_input_data *ri = g_new0(struct request_input_data, 1); + guint id = pd->next_request_id++; + gchar *buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id); + + ri->data_callback = (ri_callback_t) ok_cb; + ri->user_data = user_data; + g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri); + + imcb_add_buddy(ic, buddy, NULL); + imcb_buddy_msg(ic, buddy, secondary, 0, 0); + + g_free(buddy); + return 0; +} + +void purple_request_input_callback(guint id, struct im_connection *ic, + const char *message, const char *who) +{ + struct purple_data *pd = ic->proto_data; + struct request_input_data *ri = g_hash_table_lookup(pd->input_requests, + GUINT_TO_POINTER(id)); + + if (ri) { + ri->data_callback(ri->user_data, message); + } + + imcb_remove_buddy(ic, who, NULL); + g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(id)); +} + + static PurpleRequestUiOps bee_request_uiops = { - NULL, + prplcb_request_input, NULL, prplcb_request_action, NULL, |