Changeset 6a48992 for protocols/purple
- Timestamp:
- 2015-03-14T01:02:56Z (10 years ago)
- 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)
- Location:
- protocols/purple
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/bpurple.h
rfedc8f1 r6a48992 5 5 #include <glib.h> 6 6 7 #define PURPLE_REQUEST_HANDLE "purple_request" 8 7 9 struct purple_data 8 10 { 9 11 PurpleAccount *account; 12 13 GHashTable *input_requests; 14 guint next_request_id; 10 15 }; 11 16 -
protocols/purple/purple.c
rfedc8f1 r6a48992 40 40 static char *set_eval_display_name(set_t *set, char *value); 41 41 42 void purple_request_input_callback(guint id, struct im_connection *ic, 43 const char *message, const char *who); 44 45 /* purple_request_input specific stuff */ 46 typedef void (*ri_callback_t)(gpointer, const gchar *); 47 48 struct request_input_data { 49 ri_callback_t data_callback; 50 void *user_data; 51 }; 52 42 53 struct im_connection *purple_ic_by_pa(PurpleAccount *pa) 43 54 { … … 311 322 ic->proto_data = pd = g_new0(struct purple_data, 1); 312 323 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; 313 327 purple_account_set_password(pd->account, acc->pass); 314 328 purple_sync_settings(acc, pd->account); … … 324 338 purple_connections = g_slist_remove(purple_connections, ic); 325 339 purple_accounts_remove(pd->account); 340 g_hash_table_destroy(pd->input_requests); 326 341 g_free(pd); 327 342 } … … 331 346 PurpleConversation *conv; 332 347 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 } 333 354 334 355 if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, … … 1068 1089 */ 1069 1090 1091 void* 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 1114 void 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 1070 1130 static PurpleRequestUiOps bee_request_uiops = 1071 1131 { 1072 NULL,1132 prplcb_request_input, 1073 1133 NULL, 1074 1134 prplcb_request_action,
Note: See TracChangeset
for help on using the changeset viewer.