Changeset fc650a8 for protocols/purple/purple.c
- Timestamp:
- 2015-03-15T09:29:01Z (10 years ago)
- Children:
- c0e4c22
- Parents:
- 89db90e (diff), 2dd23da (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/purple.c
r89db90e rfc650a8 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 struct im_connection *ic; 52 char *buddy; 53 guint id; 54 }; 55 42 56 struct im_connection *purple_ic_by_pa(PurpleAccount *pa) 43 57 { … … 311 325 ic->proto_data = pd = g_new0(struct purple_data, 1); 312 326 pd->account = purple_account_new(acc->user, (char *) acc->prpl->data); 327 pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal, 328 NULL, g_free); 329 pd->next_request_id = 0; 313 330 purple_account_set_password(pd->account, acc->pass); 314 331 purple_sync_settings(acc, pd->account); … … 320 337 { 321 338 struct purple_data *pd = ic->proto_data; 339 340 if (!pd) { 341 return; 342 } 322 343 323 344 purple_account_set_enabled(pd->account, "BitlBee", FALSE); 324 345 purple_connections = g_slist_remove(purple_connections, ic); 325 346 purple_accounts_remove(pd->account); 347 g_hash_table_destroy(pd->input_requests); 326 348 g_free(pd); 327 349 } … … 331 353 PurpleConversation *conv; 332 354 struct purple_data *pd = ic->proto_data; 355 356 if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) { 357 guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE)); 358 purple_request_input_callback(request_id, ic, message, who); 359 return 1; 360 } 333 361 334 362 if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, … … 996 1024 pqad->yes(pqad->user_data, pqad->yes_i); 997 1025 } 998 g_free(pqad);999 1026 } 1000 1027 … … 1006 1033 pqad->no(pqad->user_data, pqad->no_i); 1007 1034 } 1008 g_free(pqad); 1035 } 1036 1037 /* q->free() callback from query_del()*/ 1038 static void prplcb_request_action_free(void *data) 1039 { 1040 struct prplcb_request_action_data *pqad = data; 1041 1042 pqad->bee_data = NULL; 1043 purple_request_close(PURPLE_REQUEST_ACTION, pqad); 1009 1044 } 1010 1045 … … 1041 1076 q = g_strdup_printf("Request: %s\n\n%s\n\n%s", title, primary, secondary); 1042 1077 pqad->bee_data = query_add(local_bee->ui_data, purple_ic_by_pa(account), q, 1043 prplcb_request_action_yes, prplcb_request_action_no, g_free, pqad); 1078 prplcb_request_action_yes, prplcb_request_action_no, 1079 prplcb_request_action_free, pqad); 1044 1080 1045 1081 g_free(q); … … 1054 1090 static void prplcb_close_request(PurpleRequestType type, void *data) 1055 1091 { 1056 if (type == PURPLE_REQUEST_ACTION) { 1057 struct prplcb_request_action_data *pqad = data; 1058 query_del(local_bee->ui_data, pqad->bee_data); 1059 } 1060 /* Add the request input handler here when that becomes a thing */ 1061 } 1062 1063 /* 1064 static void prplcb_request_test() 1065 { 1066 fprintf( stderr, "bla\n" ); 1067 } 1068 */ 1092 struct prplcb_request_action_data *pqad; 1093 struct request_input_data *ri; 1094 struct purple_data *pd; 1095 1096 if (!data) { 1097 return; 1098 } 1099 1100 switch (type) { 1101 case PURPLE_REQUEST_ACTION: 1102 pqad = data; 1103 /* if this is null, it's because query_del was run already */ 1104 if (pqad->bee_data) { 1105 query_del(local_bee->ui_data, pqad->bee_data); 1106 } 1107 g_free(pqad); 1108 break; 1109 case PURPLE_REQUEST_INPUT: 1110 ri = data; 1111 pd = ri->ic->proto_data; 1112 imcb_remove_buddy(ri->ic, ri->buddy, NULL); 1113 g_free(ri->buddy); 1114 g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(ri->id)); 1115 break; 1116 default: 1117 g_free(data); 1118 break; 1119 } 1120 1121 } 1122 1123 void* prplcb_request_input(const char *title, const char *primary, 1124 const char *secondary, const char *default_value, gboolean multiline, 1125 gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb, 1126 const char *cancel_text, GCallback cancel_cb, PurpleAccount *account, 1127 const char *who, PurpleConversation *conv, void *user_data) 1128 { 1129 struct im_connection *ic = purple_ic_by_pa(account); 1130 struct purple_data *pd = ic->proto_data; 1131 struct request_input_data *ri = g_new0(struct request_input_data, 1); 1132 guint id = pd->next_request_id++; 1133 1134 ri->id = id; 1135 ri->ic = ic; 1136 ri->buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id); 1137 ri->data_callback = (ri_callback_t) ok_cb; 1138 ri->user_data = user_data; 1139 g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri); 1140 1141 imcb_add_buddy(ic, ri->buddy, NULL); 1142 imcb_buddy_msg(ic, ri->buddy, secondary, 0, 0); 1143 1144 return ri; 1145 } 1146 1147 void purple_request_input_callback(guint id, struct im_connection *ic, 1148 const char *message, const char *who) 1149 { 1150 struct purple_data *pd = ic->proto_data; 1151 struct request_input_data *ri; 1152 1153 if (!(ri = g_hash_table_lookup(pd->input_requests, GUINT_TO_POINTER(id)))) { 1154 return; 1155 } 1156 1157 ri->data_callback(ri->user_data, message); 1158 1159 purple_request_close(PURPLE_REQUEST_INPUT, ri); 1160 } 1161 1069 1162 1070 1163 static PurpleRequestUiOps bee_request_uiops = 1071 1164 { 1072 NULL,1165 prplcb_request_input, 1073 1166 NULL, 1074 1167 prplcb_request_action,
Note: See TracChangeset
for help on using the changeset viewer.