Changeset 6a48992 for protocols/purple


Ignore:
Timestamp:
2015-03-14T01:02:56Z (10 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
2c5ab49
Parents:
fedc8f1
git-author:
Antoine Pietri <antoine.pietri@…> (01-03-15 18:20:32)
git-committer:
dequis <dx@…> (14-03-15 01:02:56)
Message:

purple: handle purple_request_input

Location:
protocols/purple
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/bpurple.h

    rfedc8f1 r6a48992  
    55#include <glib.h>
    66
     7#define PURPLE_REQUEST_HANDLE "purple_request"
     8
    79struct purple_data
    810{
    911    PurpleAccount *account;
     12
     13    GHashTable *input_requests;
     14    guint next_request_id;
    1015};
    1116
  • protocols/purple/purple.c

    rfedc8f1 r6a48992  
    4040static char *set_eval_display_name(set_t *set, char *value);
    4141
     42void purple_request_input_callback(guint id, struct im_connection *ic,
     43                                   const char *message, const char *who);
     44
     45/* purple_request_input specific stuff */
     46typedef void (*ri_callback_t)(gpointer, const gchar *);
     47
     48struct request_input_data {
     49        ri_callback_t data_callback;
     50        void *user_data;
     51};
     52
    4253struct im_connection *purple_ic_by_pa(PurpleAccount *pa)
    4354{
     
    311322        ic->proto_data = pd = g_new0(struct purple_data, 1);
    312323        pd->account = purple_account_new(acc->user, (char *) acc->prpl->data);
     324        pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal,
     325                                                   NULL, g_free);
     326        pd->next_request_id = 0;
    313327        purple_account_set_password(pd->account, acc->pass);
    314328        purple_sync_settings(acc, pd->account);
     
    324338        purple_connections = g_slist_remove(purple_connections, ic);
    325339        purple_accounts_remove(pd->account);
     340        g_hash_table_destroy(pd->input_requests);
    326341        g_free(pd);
    327342}
     
    331346        PurpleConversation *conv;
    332347        struct purple_data *pd = ic->proto_data;
     348
     349        if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) {
     350                guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE));
     351                purple_request_input_callback(request_id, ic, message, who);
     352                return 1;
     353        }
    333354
    334355        if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
     
    10681089*/
    10691090
     1091void* prplcb_request_input(const char *title, const char *primary,
     1092        const char *secondary, const char *default_value, gboolean multiline,
     1093        gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb,
     1094        const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
     1095        const char *who, PurpleConversation *conv, void *user_data)
     1096{
     1097        struct im_connection *ic = purple_ic_by_pa(account);
     1098        struct purple_data *pd = ic->proto_data;
     1099        struct request_input_data *ri = g_new0(struct request_input_data, 1);
     1100        guint id = pd->next_request_id++;
     1101        gchar *buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id);
     1102
     1103        ri->data_callback = (ri_callback_t) ok_cb;
     1104        ri->user_data = user_data;
     1105        g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri);
     1106
     1107        imcb_add_buddy(ic, buddy, NULL);
     1108        imcb_buddy_msg(ic, buddy, secondary, 0, 0);
     1109
     1110        g_free(buddy);
     1111        return 0;
     1112}
     1113
     1114void purple_request_input_callback(guint id, struct im_connection *ic,
     1115                                   const char *message, const char *who)
     1116{
     1117        struct purple_data *pd = ic->proto_data;
     1118        struct request_input_data *ri = g_hash_table_lookup(pd->input_requests,
     1119                                                            GUINT_TO_POINTER(id));
     1120
     1121        if (ri) {
     1122                ri->data_callback(ri->user_data, message);
     1123        }
     1124
     1125        imcb_remove_buddy(ic, who, NULL);
     1126        g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(id));
     1127}
     1128
     1129
    10701130static PurpleRequestUiOps bee_request_uiops =
    10711131{
    1072         NULL,
     1132        prplcb_request_input,
    10731133        NULL,
    10741134        prplcb_request_action,
Note: See TracChangeset for help on using the changeset viewer.