comparison finch/gntblist.c @ 22219:797230b3e48e

Add accessor and update finch to not touch the internals of PurpleBuddy and PurpleChat.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 27 Jan 2008 04:06:39 +0000
parents ad357ca94de9
children 1f256f63c52c
comparison
equal deleted inserted replaced
22218:5152a14d06a3 22219:797230b3e48e
241 if (value > lastseen) 241 if (value > lastseen)
242 lastseen = value; 242 lastseen = value;
243 } 243 }
244 if (node == (PurpleBlistNode*)pr) 244 if (node == (PurpleBlistNode*)pr)
245 continue; 245 continue;
246 if (!purple_account_is_connected(buddy->account)) 246 if (!purple_account_is_connected(purple_buddy_get_account(buddy)))
247 continue; 247 continue;
248 if (!showoffline && !PURPLE_BUDDY_IS_ONLINE(buddy)) 248 if (!showoffline && !PURPLE_BUDDY_IS_ONLINE(buddy))
249 continue; 249 continue;
250 str = g_string_append(str, "\n----------\n"); 250 str = g_string_append(str, "\n----------\n");
251 tooltip_for_buddy(buddy, str, FALSE); 251 tooltip_for_buddy(buddy, str, FALSE);
264 purple_blist_get_group_size(group, FALSE)); 264 purple_blist_get_group_size(group, FALSE));
265 265
266 title = g_strdup(group->name); 266 title = g_strdup(group->name);
267 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { 267 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
268 PurpleChat *chat = (PurpleChat *)node; 268 PurpleChat *chat = (PurpleChat *)node;
269 PurpleAccount *account = chat->account; 269 PurpleAccount *account = purple_chat_get_account(chat);
270 270
271 g_string_append_printf(str, _("Account: %s (%s)"), 271 g_string_append_printf(str, _("Account: %s (%s)"),
272 purple_account_get_username(account), 272 purple_account_get_username(account),
273 purple_account_get_protocol_name(account)); 273 purple_account_get_protocol_name(account));
274 274
657 } 657 }
658 purple_blist_add_chat(chat, grp, NULL); 658 purple_blist_add_chat(chat, grp, NULL);
659 purple_blist_alias_chat(chat, alias); 659 purple_blist_alias_chat(chat, alias);
660 purple_blist_node_set_bool((PurpleBlistNode*)chat, "gnt-autojoin", autojoin); 660 purple_blist_node_set_bool((PurpleBlistNode*)chat, "gnt-autojoin", autojoin);
661 if (autojoin) 661 if (autojoin)
662 serv_join_chat(purple_account_get_connection(chat->account), chat->components); 662 serv_join_chat(purple_account_get_connection(purple_chat_get_account(chat)), purple_chat_get_components(chat));
663 } 663 }
664 } 664 }
665 665
666 static void 666 static void
667 finch_request_add_chat(PurpleAccount *account, PurpleGroup *grp, const char *alias, const char *name) 667 finch_request_add_chat(PurpleAccount *account, PurpleGroup *grp, const char *alias, const char *name)
836 { 836 {
837 gpointer parent; 837 gpointer parent;
838 PurpleBlistNode *node = (PurpleBlistNode *)chat; 838 PurpleBlistNode *node = (PurpleBlistNode *)chat;
839 if (FINCH_GET_DATA(node)) 839 if (FINCH_GET_DATA(node))
840 return; 840 return;
841 if (!purple_account_is_connected(chat->account)) 841 if (!purple_account_is_connected(purple_chat_get_account(chat)))
842 return; 842 return;
843 843
844 parent = ggblist->manager->find_parent((PurpleBlistNode*)chat); 844 parent = ggblist->manager->find_parent((PurpleBlistNode*)chat);
845 845
846 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat, 846 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat,
942 finch_conversation_set_active(conv); 942 finch_conversation_set_active(conv);
943 } 943 }
944 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) 944 else if (PURPLE_BLIST_NODE_IS_CHAT(node))
945 { 945 {
946 PurpleChat *chat = (PurpleChat*)node; 946 PurpleChat *chat = (PurpleChat*)node;
947 serv_join_chat(purple_account_get_connection(chat->account), chat->components); 947 serv_join_chat(purple_account_get_connection(purple_chat_get_account(chat)), purple_chat_get_components(chat));
948 } 948 }
949 } 949 }
950 950
951 static void 951 static void
952 context_menu_callback(GntMenuItem *item, gpointer data) 952 context_menu_callback(GntMenuItem *item, gpointer data)
1029 if (purple_request_field_get_type(field) == PURPLE_REQUEST_FIELD_INTEGER) 1029 if (purple_request_field_get_type(field) == PURPLE_REQUEST_FIELD_INTEGER)
1030 val = g_strdup_printf("%d", purple_request_field_int_get_value(field)); 1030 val = g_strdup_printf("%d", purple_request_field_int_get_value(field));
1031 else 1031 else
1032 val = g_strdup(purple_request_field_string_get_value(field)); 1032 val = g_strdup(purple_request_field_string_get_value(field));
1033 1033
1034 g_hash_table_replace(chat->components, g_strdup(id), val); /* val should not be free'd */ 1034 g_hash_table_replace(purple_chat_get_components(chat), g_strdup(id), val); /* val should not be free'd */
1035 } 1035 }
1036 } 1036 }
1037 } 1037 }
1038 1038
1039 static void 1039 static void
1046 struct proto_chat_entry *pce; 1046 struct proto_chat_entry *pce;
1047 PurpleConnection *gc; 1047 PurpleConnection *gc;
1048 1048
1049 purple_request_fields_add_group(fields, group); 1049 purple_request_fields_add_group(fields, group);
1050 1050
1051 gc = purple_account_get_connection(chat->account); 1051 gc = purple_account_get_connection(purple_chat_get_account(chat));
1052 parts = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc))->chat_info(gc); 1052 parts = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc))->chat_info(gc);
1053 1053
1054 for (iter = parts; iter; iter = iter->next) { 1054 for (iter = parts; iter; iter = iter->next) {
1055 pce = iter->data; 1055 pce = iter->data;
1056 if (pce->is_int) { 1056 if (pce->is_int) {
1057 int val; 1057 int val;
1058 const char *str = g_hash_table_lookup(chat->components, pce->identifier); 1058 const char *str = g_hash_table_lookup(purple_chat_get_components(chat), pce->identifier);
1059 if (!str || sscanf(str, "%d", &val) != 1) 1059 if (!str || sscanf(str, "%d", &val) != 1)
1060 val = pce->min; 1060 val = pce->min;
1061 field = purple_request_field_int_new(pce->identifier, pce->label, val); 1061 field = purple_request_field_int_new(pce->identifier, pce->label, val);
1062 } else { 1062 } else {
1063 field = purple_request_field_string_new(pce->identifier, pce->label, 1063 field = purple_request_field_string_new(pce->identifier, pce->label,
1064 g_hash_table_lookup(chat->components, pce->identifier), FALSE); 1064 g_hash_table_lookup(purple_chat_get_components(chat), pce->identifier), FALSE);
1065 } 1065 }
1066 1066
1067 purple_request_field_group_add_field(group, field); 1067 purple_request_field_group_add_field(group, field);
1068 g_free(pce); 1068 g_free(pce);
1069 } 1069 }
1141 } 1141 }
1142 1142
1143 static void 1143 static void
1144 finch_blist_get_buddy_info_cb(PurpleBlistNode *selected, PurpleBuddy *buddy) 1144 finch_blist_get_buddy_info_cb(PurpleBlistNode *selected, PurpleBuddy *buddy)
1145 { 1145 {
1146 finch_retrieve_user_info(purple_account_get_connection(buddy->account), purple_buddy_get_name(buddy)); 1146 finch_retrieve_user_info(purple_account_get_connection(purple_buddy_get_account(buddy)), purple_buddy_get_name(buddy));
1147 } 1147 }
1148 1148
1149 static void 1149 static void
1150 finch_blist_menu_send_file_cb(PurpleBlistNode *selected, PurpleBuddy *buddy) 1150 finch_blist_menu_send_file_cb(PurpleBlistNode *selected, PurpleBuddy *buddy)
1151 { 1151 {
1152 serv_send_file(purple_account_get_connection(buddy->account), buddy->name, NULL); 1152 serv_send_file(purple_account_get_connection(purple_buddy_get_account(buddy)), purple_buddy_get_name(buddy), NULL);
1153 } 1153 }
1154 1154
1155 static void 1155 static void
1156 finch_blist_pounce_node_cb(PurpleBlistNode *selected, PurpleBlistNode *node) 1156 finch_blist_pounce_node_cb(PurpleBlistNode *selected, PurpleBlistNode *node)
1157 { 1157 {
1158 PurpleBuddy *b; 1158 PurpleBuddy *b;
1159 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) 1159 if (PURPLE_BLIST_NODE_IS_CONTACT(node))
1160 b = purple_contact_get_priority_buddy((PurpleContact *)node); 1160 b = purple_contact_get_priority_buddy((PurpleContact *)node);
1161 else 1161 else
1162 b = (PurpleBuddy *)node; 1162 b = (PurpleBuddy *)node;
1163 finch_pounce_editor_show(b->account, b->name, NULL); 1163 finch_pounce_editor_show(purple_buddy_get_account(b), purple_buddy_get_name(b), NULL);
1164 } 1164 }
1165 1165
1166 1166
1167 static void 1167 static void
1168 create_buddy_menu(GntMenu *menu, PurpleBuddy *buddy) 1168 create_buddy_menu(GntMenu *menu, PurpleBuddy *buddy)
1169 { 1169 {
1170 PurplePluginProtocolInfo *prpl_info; 1170 PurplePluginProtocolInfo *prpl_info;
1171 PurpleConnection *gc = purple_account_get_connection(buddy->account); 1171 PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1172 1172
1173 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); 1173 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
1174 if (prpl_info && prpl_info->get_info) 1174 if (prpl_info && prpl_info->get_info)
1175 { 1175 {
1176 add_custom_action(menu, _("Get Info"), 1176 add_custom_action(menu, _("Get Info"),
1181 PURPLE_CALLBACK(finch_blist_pounce_node_cb), buddy); 1181 PURPLE_CALLBACK(finch_blist_pounce_node_cb), buddy);
1182 1182
1183 if (prpl_info && prpl_info->send_file) 1183 if (prpl_info && prpl_info->send_file)
1184 { 1184 {
1185 if (!prpl_info->can_receive_file || 1185 if (!prpl_info->can_receive_file ||
1186 prpl_info->can_receive_file(gc, buddy->name)) 1186 prpl_info->can_receive_file(gc, purple_buddy_get_name(buddy)))
1187 add_custom_action(menu, _("Send File"), 1187 add_custom_action(menu, _("Send File"),
1188 PURPLE_CALLBACK(finch_blist_menu_send_file_cb), buddy); 1188 PURPLE_CALLBACK(finch_blist_menu_send_file_cb), buddy);
1189 } 1189 }
1190 #if 0 1190 #if 0
1191 add_custom_action(tree, _("View Log"), 1191 add_custom_action(tree, _("View Log"),
1219 1219
1220 cnode = (PurpleBlistNode *)contact; 1220 cnode = (PurpleBlistNode *)contact;
1221 group = (PurpleGroup*)purple_blist_node_get_parent(cnode); 1221 group = (PurpleGroup*)purple_blist_node_get_parent(cnode);
1222 for (bnode = purple_blist_node_get_first_child(cnode); bnode; bnode = purple_blist_node_get_sibling_next(bnode)) { 1222 for (bnode = purple_blist_node_get_first_child(cnode); bnode; bnode = purple_blist_node_get_sibling_next(bnode)) {
1223 PurpleBuddy *buddy = (PurpleBuddy*)bnode; 1223 PurpleBuddy *buddy = (PurpleBuddy*)bnode;
1224 if (purple_account_is_connected(buddy->account)) 1224 PurpleAccount *account = purple_buddy_get_account(buddy);
1225 purple_account_remove_buddy(buddy->account, buddy, group); 1225 if (purple_account_is_connected(account))
1226 purple_account_remove_buddy(account, buddy, group);
1226 } 1227 }
1227 purple_blist_remove_contact(contact); 1228 purple_blist_remove_contact(contact);
1228 } 1229 }
1229 1230
1230 static void 1231 static void
1294 bnode = purple_blist_node_get_first_child(cnode); 1295 bnode = purple_blist_node_get_first_child(cnode);
1295 cnode = purple_blist_node_get_sibling_next(cnode); 1296 cnode = purple_blist_node_get_sibling_next(cnode);
1296 while (bnode) { 1297 while (bnode) {
1297 PurpleBuddy *buddy; 1298 PurpleBuddy *buddy;
1298 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) { 1299 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) {
1300 PurpleAccount *account;
1299 buddy = (PurpleBuddy*)bnode; 1301 buddy = (PurpleBuddy*)bnode;
1300 bnode = purple_blist_node_get_sibling_next(bnode); 1302 bnode = purple_blist_node_get_sibling_next(bnode);
1301 if (purple_account_is_connected(buddy->account)) { 1303 account = purple_buddy_get_account(buddy);
1302 purple_account_remove_buddy(buddy->account, buddy, group); 1304 if (purple_account_is_connected(account)) {
1305 purple_account_remove_buddy(account, buddy, group);
1303 purple_blist_remove_buddy(buddy); 1306 purple_blist_remove_buddy(buddy);
1304 } 1307 }
1305 } else { 1308 } else {
1306 bnode = purple_blist_node_get_sibling_next(bnode); 1309 bnode = purple_blist_node_get_sibling_next(bnode);
1307 } 1310 }
1308 } 1311 }
1309 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) { 1312 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) {
1310 PurpleChat *chat = (PurpleChat *)cnode; 1313 PurpleChat *chat = (PurpleChat *)cnode;
1311 cnode = purple_blist_node_get_sibling_next(cnode); 1314 cnode = purple_blist_node_get_sibling_next(cnode);
1312 if (purple_account_is_connected(chat->account)) 1315 if (purple_account_is_connected(purple_chat_get_account(chat)))
1313 purple_blist_remove_chat(chat); 1316 purple_blist_remove_chat(chat);
1314 } else { 1317 } else {
1315 cnode = purple_blist_node_get_sibling_next(cnode); 1318 cnode = purple_blist_node_get_sibling_next(cnode);
1316 } 1319 }
1317 } 1320 }
2241 int log = 0; 2244 int log = 0;
2242 PurpleBlistNode *node; 2245 PurpleBlistNode *node;
2243 2246
2244 for (node = purple_blist_node_get_first_child(c); node; node = purple_blist_node_get_sibling_next(node)) { 2247 for (node = purple_blist_node_get_first_child(c); node; node = purple_blist_node_get_sibling_next(node)) {
2245 PurpleBuddy *b = (PurpleBuddy*)node; 2248 PurpleBuddy *b = (PurpleBuddy*)node;
2246 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account); 2249 log += purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b),
2250 purple_buddy_get_account(b));
2247 } 2251 }
2248 2252
2249 return log; 2253 return log;
2250 } 2254 }
2251 2255
2260 2264
2261 switch (purple_blist_node_get_type(n1)) { 2265 switch (purple_blist_node_get_type(n1)) {
2262 case PURPLE_BLIST_BUDDY_NODE: 2266 case PURPLE_BLIST_BUDDY_NODE:
2263 b1 = (PurpleBuddy*)n1; 2267 b1 = (PurpleBuddy*)n1;
2264 b2 = (PurpleBuddy*)n2; 2268 b2 = (PurpleBuddy*)n2;
2265 ret = purple_log_get_total_size(PURPLE_LOG_IM, b2->name, b2->account) - 2269 ret = purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b2), purple_buddy_get_account(b2)) -
2266 purple_log_get_total_size(PURPLE_LOG_IM, b1->name, b1->account); 2270 purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b1), purple_buddy_get_account(b1));
2267 if (ret != 0) 2271 if (ret != 0)
2268 return ret; 2272 return ret;
2269 break; 2273 break;
2270 case PURPLE_BLIST_CONTACT_NODE: 2274 case PURPLE_BLIST_CONTACT_NODE:
2271 ret = get_contact_log_size(n2) - get_contact_log_size(n1); 2275 ret = get_contact_log_size(n2) - get_contact_log_size(n1);
2463 2467
2464 for (node = purple_blist_get_root(); node; 2468 for (node = purple_blist_get_root(); node;
2465 node = purple_blist_node_next(node, FALSE)) { 2469 node = purple_blist_node_next(node, FALSE)) {
2466 if (PURPLE_BLIST_NODE_IS_CHAT(node)) { 2470 if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
2467 PurpleChat *chat = (PurpleChat*)node; 2471 PurpleChat *chat = (PurpleChat*)node;
2468 if (chat->account == account && 2472 if (purple_chat_get_account(chat) == account &&
2469 purple_blist_node_get_bool(node, "gnt-autojoin")) 2473 purple_blist_node_get_bool(node, "gnt-autojoin"))
2470 serv_join_chat(purple_account_get_connection(chat->account), chat->components); 2474 serv_join_chat(purple_account_get_connection(account), purple_chat_get_components(chat));
2471 } 2475 }
2472 } 2476 }
2473 return FALSE; 2477 return FALSE;
2474 } 2478 }
2475 2479
2559 if (chat == NULL) { 2563 if (chat == NULL) {
2560 PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); 2564 PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
2561 if (info->chat_info_defaults != NULL) 2565 if (info->chat_info_defaults != NULL)
2562 hash = info->chat_info_defaults(gc, name); 2566 hash = info->chat_info_defaults(gc, name);
2563 } else { 2567 } else {
2564 hash = chat->components; 2568 hash = purple_chat_get_components(chat);
2565 } 2569 }
2566 serv_join_chat(gc, hash); 2570 serv_join_chat(gc, hash);
2567 if (chat == NULL && hash != NULL) 2571 if (chat == NULL && hash != NULL)
2568 g_hash_table_destroy(hash); 2572 g_hash_table_destroy(hash);
2569 } 2573 }