comparison finch/gntblist.c @ 22168:2bff44d78523

Add some accessor functions for PurpleBlistNode.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 21 Jan 2008 19:43:55 +0000
parents 0503cd74cb56
children 2c9646c55369
comparison
equal deleted inserted replaced
22154:f577201bf30f 22168:2bff44d78523
218 218
219 static gboolean 219 static gboolean
220 is_contact_online(PurpleContact *contact) 220 is_contact_online(PurpleContact *contact)
221 { 221 {
222 PurpleBlistNode *node; 222 PurpleBlistNode *node;
223 for (node = ((PurpleBlistNode*)contact)->child; node; node = node->next) { 223 for (node = purple_blist_node_get_first_child(((PurpleBlistNode*)contact)); node;
224 node = purple_blist_node_get_sibling_next(node)) {
224 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) 225 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node))
225 return TRUE; 226 return TRUE;
226 } 227 }
227 return FALSE; 228 return FALSE;
228 } 229 }
229 230
230 static gboolean 231 static gboolean
231 is_group_online(PurpleGroup *group) 232 is_group_online(PurpleGroup *group)
232 { 233 {
233 PurpleBlistNode *node; 234 PurpleBlistNode *node;
234 for (node = ((PurpleBlistNode*)group)->child; node; node = node->next) { 235 for (node = purple_blist_node_get_first_child(((PurpleBlistNode*)group)); node;
236 node = purple_blist_node_get_sibling_next(node)) {
235 if (PURPLE_BLIST_NODE_IS_CHAT(node) && 237 if (PURPLE_BLIST_NODE_IS_CHAT(node) &&
236 purple_account_is_connected(((PurpleChat *)node)->account)) 238 purple_account_is_connected(((PurpleChat *)node)->account))
237 return TRUE; 239 return TRUE;
238 else if (is_contact_online((PurpleContact*)node)) 240 else if (is_contact_online((PurpleContact*)node))
239 return TRUE; 241 return TRUE;
279 reset_blist_node_ui_data(node); 281 reset_blist_node_ui_data(node);
280 if (ggblist->tagged) 282 if (ggblist->tagged)
281 ggblist->tagged = g_list_remove(ggblist->tagged, node); 283 ggblist->tagged = g_list_remove(ggblist->tagged, node);
282 284
283 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { 285 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
284 PurpleContact *contact = (PurpleContact*)node->parent; 286 PurpleContact *contact = (PurpleContact*)purple_blist_node_get_parent(node);
285 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) || 287 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) ||
286 contact->currentsize < 1) 288 contact->currentsize < 1)
287 node_remove(list, (PurpleBlistNode*)contact); 289 node_remove(list, (PurpleBlistNode*)contact);
288 else 290 else
289 node_update(list, (PurpleBlistNode*)contact); 291 node_update(list, (PurpleBlistNode*)contact);
290 } else if (!PURPLE_BLIST_NODE_IS_GROUP(node)) { 292 } else if (!PURPLE_BLIST_NODE_IS_GROUP(node)) {
291 PurpleGroup *group = (PurpleGroup*)node->parent; 293 PurpleGroup *group = (PurpleGroup*)purple_blist_node_get_parent(node);
292 if ((group->currentsize < 1 && !purple_prefs_get_bool(PREF_ROOT "/emptygroups")) || 294 if ((group->currentsize < 1 && !purple_prefs_get_bool(PREF_ROOT "/emptygroups")) ||
293 (!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group))) 295 (!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group)))
294 node_remove(list, node->parent); 296 node_remove(list, purple_blist_node_get_parent(node));
295 for (node = node->child; node; node = node->next) 297 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node))
296 reset_blist_node_ui_data(node); 298 reset_blist_node_ui_data(node);
297 } else { 299 } else {
298 for (node = node->child; node; node = node->next) 300 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node))
299 node_remove(list, node); 301 node_remove(list, node);
300 } 302 }
301 303
302 draw_tooltip(ggblist); 304 draw_tooltip(ggblist);
303 } 305 }
323 blist_update_row_flags(node); 325 blist_update_row_flags(node);
324 } 326 }
325 327
326 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { 328 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
327 PurpleBuddy *buddy = (PurpleBuddy*)node; 329 PurpleBuddy *buddy = (PurpleBuddy*)node;
328 if (purple_account_is_connected(buddy->account) && 330 add_node((PurpleBlistNode*)buddy, list->ui_data);
329 (PURPLE_BUDDY_IS_ONLINE(buddy) || purple_prefs_get_bool(PREF_ROOT "/showoffline"))) 331
330 add_node((PurpleBlistNode*)buddy, list->ui_data); 332 node_update(list, purple_blist_node_get_parent(node));
331
332 node_update(list, node->parent);
333 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { 333 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
334 add_chat((PurpleChat *)node, list->ui_data); 334 add_chat((PurpleChat *)node, list->ui_data);
335 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { 335 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
336 PurpleContact *contact = (PurpleContact*)node; 336 PurpleContact *contact = (PurpleContact*)node;
337 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) || 337 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) ||
338 contact->currentsize < 1) 338 contact->currentsize < 1)
339 /* nothing */; 339 /* nothing */;
340 else { 340 else {
341 if (node->ui_data == NULL) { 341 if (node->ui_data == NULL) {
342 /* The core seems to expect the UI to add the buddies. */ 342 /* The core seems to expect the UI to add the buddies. */
343 for (node = node->child; node; node = node->next) 343 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node))
344 add_node(node, list->ui_data); 344 add_node(node, list->ui_data);
345 } 345 }
346 } 346 }
347 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { 347 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) {
348 PurpleGroup *group = (PurpleGroup*)node; 348 PurpleGroup *group = (PurpleGroup*)node;
396 if (!grp) 396 if (!grp)
397 { 397 {
398 grp = purple_group_new(group); 398 grp = purple_group_new(group);
399 purple_blist_add_group(grp, NULL); 399 purple_blist_add_group(grp, NULL);
400 } 400 }
401
402 /* XXX: Ask if there's already the same buddy in the same group (#4553) */
401 403
402 buddy = purple_buddy_new(account, username, alias); 404 buddy = purple_buddy_new(account, username, alias);
403 purple_blist_add_buddy(buddy, NULL, grp, NULL); 405 purple_blist_add_buddy(buddy, NULL, grp, NULL);
404 purple_account_add_buddy(account, buddy); 406 purple_account_add_buddy(account, buddy);
405 } 407 }
675 677
676 name = get_display_name(node); 678 name = get_display_name(node);
677 if (name == NULL) 679 if (name == NULL)
678 return; 680 return;
679 681
680 group = (PurpleGroup*)node->parent; 682 group = (PurpleGroup*)purple_blist_node_get_parent(node);
681 add_node((PurpleBlistNode*)group, ggblist); 683 add_node((PurpleBlistNode*)group, ggblist);
682 684
683 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), contact, 685 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), contact,
684 gnt_tree_create_row(GNT_TREE(ggblist->tree), name), 686 gnt_tree_create_row(GNT_TREE(ggblist->tree), name),
685 group, NULL)); 687 group, NULL));
697 return; 699 return;
698 700
699 if (!purple_account_is_connected(buddy->account)) 701 if (!purple_account_is_connected(buddy->account))
700 return; 702 return;
701 703
702 contact = (PurpleContact*)node->parent; 704 if (!PURPLE_BUDDY_IS_ONLINE(buddy) && !purple_prefs_get_bool(PREF_ROOT "/showoffline"))
705 return;
706
707 contact = (PurpleContact*)purple_blist_node_get_parent(node);
703 if (!contact) /* When a new buddy is added and show-offline is set */ 708 if (!contact) /* When a new buddy is added and show-offline is set */
704 return; 709 return;
705 add_node((PurpleBlistNode*)contact, ggblist); 710 add_node((PurpleBlistNode*)contact, ggblist);
706 711
707 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, 712 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy,
1033 { 1038 {
1034 PurpleBlistNode *bnode, *cnode; 1039 PurpleBlistNode *bnode, *cnode;
1035 PurpleGroup *group; 1040 PurpleGroup *group;
1036 1041
1037 cnode = (PurpleBlistNode *)contact; 1042 cnode = (PurpleBlistNode *)contact;
1038 group = (PurpleGroup*)cnode->parent; 1043 group = (PurpleGroup*)purple_blist_node_get_parent(cnode);
1039 for (bnode = cnode->child; bnode; bnode = bnode->next) { 1044 for (bnode = purple_blist_node_get_first_child(cnode); bnode; bnode = purple_blist_node_get_sibling_next(bnode)) {
1040 PurpleBuddy *buddy = (PurpleBuddy*)bnode; 1045 PurpleBuddy *buddy = (PurpleBuddy*)bnode;
1041 if (purple_account_is_connected(buddy->account)) 1046 if (purple_account_is_connected(buddy->account))
1042 purple_account_remove_buddy(buddy->account, buddy, group); 1047 purple_account_remove_buddy(buddy->account, buddy, group);
1043 } 1048 }
1044 purple_blist_remove_contact(contact); 1049 purple_blist_remove_contact(contact);
1102 static void 1107 static void
1103 remove_group(PurpleGroup *group) 1108 remove_group(PurpleGroup *group)
1104 { 1109 {
1105 PurpleBlistNode *cnode, *bnode; 1110 PurpleBlistNode *cnode, *bnode;
1106 1111
1107 cnode = ((PurpleBlistNode*)group)->child; 1112 cnode = purple_blist_node_get_first_child(((PurpleBlistNode*)group));
1108 1113
1109 while (cnode) { 1114 while (cnode) {
1110 if (PURPLE_BLIST_NODE_IS_CONTACT(cnode)) { 1115 if (PURPLE_BLIST_NODE_IS_CONTACT(cnode)) {
1111 bnode = cnode->child; 1116 bnode = purple_blist_node_get_first_child(cnode);
1112 cnode = cnode->next; 1117 cnode = purple_blist_node_get_sibling_next(cnode);
1113 while (bnode) { 1118 while (bnode) {
1114 PurpleBuddy *buddy; 1119 PurpleBuddy *buddy;
1115 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) { 1120 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) {
1116 buddy = (PurpleBuddy*)bnode; 1121 buddy = (PurpleBuddy*)bnode;
1117 bnode = bnode->next; 1122 bnode = purple_blist_node_get_sibling_next(bnode);
1118 if (purple_account_is_connected(buddy->account)) { 1123 if (purple_account_is_connected(buddy->account)) {
1119 purple_account_remove_buddy(buddy->account, buddy, group); 1124 purple_account_remove_buddy(buddy->account, buddy, group);
1120 purple_blist_remove_buddy(buddy); 1125 purple_blist_remove_buddy(buddy);
1121 } 1126 }
1122 } else { 1127 } else {
1123 bnode = bnode->next; 1128 bnode = purple_blist_node_get_sibling_next(bnode);
1124 } 1129 }
1125 } 1130 }
1126 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) { 1131 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) {
1127 PurpleChat *chat = (PurpleChat *)cnode; 1132 PurpleChat *chat = (PurpleChat *)cnode;
1128 cnode = cnode->next; 1133 cnode = purple_blist_node_get_sibling_next(cnode);
1129 if (purple_account_is_connected(chat->account)) 1134 if (purple_account_is_connected(chat->account))
1130 purple_blist_remove_chat(chat); 1135 purple_blist_remove_chat(chat);
1131 } else { 1136 } else {
1132 cnode = cnode->next; 1137 cnode = purple_blist_node_get_sibling_next(cnode);
1133 } 1138 }
1134 } 1139 }
1135 1140
1136 purple_blist_remove_group(group); 1141 purple_blist_remove_group(group);
1137 } 1142 }
1220 return; 1225 return;
1221 1226
1222 if (PURPLE_BLIST_NODE_IS_GROUP(target)) 1227 if (PURPLE_BLIST_NODE_IS_GROUP(target))
1223 tg = (PurpleGroup*)target; 1228 tg = (PurpleGroup*)target;
1224 else if (PURPLE_BLIST_NODE_IS_BUDDY(target)) { 1229 else if (PURPLE_BLIST_NODE_IS_BUDDY(target)) {
1225 tc = (PurpleContact*)target->parent; 1230 tc = (PurpleContact*)purple_blist_node_get_parent(target);
1226 tg = (PurpleGroup*)target->parent->parent; 1231 tg = (PurpleGroup*)purple_blist_node_get_parent((PurpleBlistNode*)tc);
1227 } else { 1232 } else {
1228 if (PURPLE_BLIST_NODE_IS_CONTACT(target)) 1233 if (PURPLE_BLIST_NODE_IS_CONTACT(target))
1229 tc = (PurpleContact*)target; 1234 tc = (PurpleContact*)target;
1230 tg = (PurpleGroup*)target->parent; 1235 tg = (PurpleGroup*)purple_blist_node_get_parent(target);
1231 } 1236 }
1232 1237
1233 if (ggblist->tagged) { 1238 if (ggblist->tagged) {
1234 GList *list = ggblist->tagged; 1239 GList *list = ggblist->tagged;
1235 ggblist->tagged = NULL; 1240 ggblist->tagged = NULL;
1474 gboolean showoffline = purple_prefs_get_bool(PREF_ROOT "/showoffline"); 1479 gboolean showoffline = purple_prefs_get_bool(PREF_ROOT "/showoffline");
1475 const char *name = purple_buddy_get_name(pr); 1480 const char *name = purple_buddy_get_name(pr);
1476 1481
1477 title = g_strdup(name); 1482 title = g_strdup(name);
1478 tooltip_for_buddy(pr, str, TRUE); 1483 tooltip_for_buddy(pr, str, TRUE);
1479 for (node = node->child; node; node = node->next) { 1484 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node)) {
1480 PurpleBuddy *buddy = (PurpleBuddy*)node; 1485 PurpleBuddy *buddy = (PurpleBuddy*)node;
1481 if (offline) { 1486 if (offline) {
1482 int value = purple_blist_node_get_int(node, "last_seen"); 1487 int value = purple_blist_node_get_int(node, "last_seen");
1483 if (value > lastseen) 1488 if (value > lastseen)
1484 lastseen = value; 1489 lastseen = value;
2080 get_contact_log_size(PurpleBlistNode *c) 2085 get_contact_log_size(PurpleBlistNode *c)
2081 { 2086 {
2082 int log = 0; 2087 int log = 0;
2083 PurpleBlistNode *node; 2088 PurpleBlistNode *node;
2084 2089
2085 for (node = c->child; node; node = node->next) { 2090 for (node = purple_blist_node_get_first_child(c); node; node = purple_blist_node_get_sibling_next(node)) {
2086 PurpleBuddy *b = (PurpleBuddy*)node; 2091 PurpleBuddy *b = (PurpleBuddy*)node;
2087 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account); 2092 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account);
2088 } 2093 }
2089 2094
2090 return log; 2095 return log;
2174 if (!purple_account_is_connected(buddy->account) || 2179 if (!purple_account_is_connected(buddy->account) ||
2175 (!PURPLE_BUDDY_IS_ONLINE(buddy) && !purple_prefs_get_bool(PREF_ROOT "/showoffline"))) { 2180 (!PURPLE_BUDDY_IS_ONLINE(buddy) && !purple_prefs_get_bool(PREF_ROOT "/showoffline"))) {
2176 node_remove(purple_get_blist(), node); 2181 node_remove(purple_get_blist(), node);
2177 } else { 2182 } else {
2178 update_node_display(node, ggblist); 2183 update_node_display(node, ggblist);
2179 if (node->parent && PURPLE_BLIST_NODE_IS_CONTACT(node->parent)) 2184 if (purple_blist_node_get_parent(node) && PURPLE_BLIST_NODE_IS_CONTACT(purple_blist_node_get_parent(node)))
2180 update_node_display(node->parent, ggblist); 2185 update_node_display(purple_blist_node_get_parent(node), ggblist);
2181 } 2186 }
2182 2187
2183 return FALSE; 2188 return FALSE;
2184 } 2189 }
2185 2190
2193 2198
2194 if (fnode->signed_timer) 2199 if (fnode->signed_timer)
2195 purple_timeout_remove(fnode->signed_timer); 2200 purple_timeout_remove(fnode->signed_timer);
2196 fnode->signed_timer = purple_timeout_add_seconds(6, (GSourceFunc)buddy_recent_signed_on_off, data); 2201 fnode->signed_timer = purple_timeout_add_seconds(6, (GSourceFunc)buddy_recent_signed_on_off, data);
2197 update_node_display(node, ggblist); 2202 update_node_display(node, ggblist);
2198 if (node->parent && PURPLE_BLIST_NODE_IS_CONTACT(node->parent)) 2203 if (purple_blist_node_get_parent(node) && PURPLE_BLIST_NODE_IS_CONTACT(purple_blist_node_get_parent(node)))
2199 update_node_display(node->parent, ggblist); 2204 update_node_display(purple_blist_node_get_parent(node), ggblist);
2200 return FALSE; 2205 return FALSE;
2201 } 2206 }
2202 2207
2203 static void 2208 static void
2204 buddy_signed_on_off(PurpleBuddy* buddy, gpointer null) 2209 buddy_signed_on_off(PurpleBuddy* buddy, gpointer null)