Mercurial > pidgin
comparison finch/gntblist.c @ 22181:8509419a666c
Rework some of the code that deals with adding and removing blist nodes in the tree. There were some typoed code that just happened to work. This fixes those.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 23 Jan 2008 01:33:56 +0000 |
parents | b0bce463aa4e |
children | bcaf4a037704 |
comparison
equal
deleted
inserted
replaced
22180:2579d93849bb | 22181:8509419a666c |
---|---|
116 static void add_contact(PurpleContact *contact, FinchBlist *ggblist); | 116 static void add_contact(PurpleContact *contact, FinchBlist *ggblist); |
117 static void add_group(PurpleGroup *group, FinchBlist *ggblist); | 117 static void add_group(PurpleGroup *group, FinchBlist *ggblist); |
118 static void add_chat(PurpleChat *chat, FinchBlist *ggblist); | 118 static void add_chat(PurpleChat *chat, FinchBlist *ggblist); |
119 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist); | 119 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist); |
120 static void node_update(PurpleBuddyList *list, PurpleBlistNode *node); | 120 static void node_update(PurpleBuddyList *list, PurpleBlistNode *node); |
121 #if 0 | |
121 static gboolean is_contact_online(PurpleContact *contact); | 122 static gboolean is_contact_online(PurpleContact *contact); |
122 static gboolean is_group_online(PurpleGroup *group); | 123 static gboolean is_group_online(PurpleGroup *group); |
124 #endif | |
123 static void draw_tooltip(FinchBlist *ggblist); | 125 static void draw_tooltip(FinchBlist *ggblist); |
124 static void tooltip_for_buddy(PurpleBuddy *buddy, GString *str, gboolean full); | 126 static void tooltip_for_buddy(PurpleBuddy *buddy, GString *str, gboolean full); |
125 static gboolean remove_typing_cb(gpointer null); | 127 static gboolean remove_typing_cb(gpointer null); |
126 static void remove_peripherals(FinchBlist *ggblist); | 128 static void remove_peripherals(FinchBlist *ggblist); |
127 static const char * get_display_name(PurpleBlistNode *node); | 129 static const char * get_display_name(PurpleBlistNode *node); |
152 { | 154 { |
153 gboolean offline = purple_prefs_get_bool(PREF_ROOT "/showoffline"); | 155 gboolean offline = purple_prefs_get_bool(PREF_ROOT "/showoffline"); |
154 | 156 |
155 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 157 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
156 PurpleBuddy *buddy = (PurpleBuddy*)node; | 158 PurpleBuddy *buddy = (PurpleBuddy*)node; |
159 FinchBlistNode *fnode = node->ui_data; | |
157 if (!purple_buddy_get_contact(buddy)) | 160 if (!purple_buddy_get_contact(buddy)) |
158 return FALSE; /* When a new buddy is added and show-offline is set */ | 161 return FALSE; /* When a new buddy is added and show-offline is set */ |
159 if (PURPLE_BUDDY_IS_ONLINE(buddy)) | 162 if (PURPLE_BUDDY_IS_ONLINE(buddy)) |
160 return TRUE; /* The buddy is online */ | 163 return TRUE; /* The buddy is online */ |
161 if (!purple_account_is_connected(purple_buddy_get_account(buddy))) | 164 if (!purple_account_is_connected(purple_buddy_get_account(buddy))) |
162 return FALSE; /* The account is disconnected. Do not show */ | 165 return FALSE; /* The account is disconnected. Do not show */ |
163 if (offline) | 166 if (offline) |
164 return TRUE; /* We want to see offline buddies too */ | 167 return TRUE; /* We want to see offline buddies too */ |
168 if (fnode && fnode->signed_timer) | |
169 return TRUE; /* Show if the buddy just signed off */ | |
165 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { | 170 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
166 PurpleContact *contact = (PurpleContact*)node; | 171 PurpleBlistNode *nd; |
167 if (contact->currentsize < 1) | 172 for (nd = purple_blist_node_get_first_child(node); |
168 return FALSE; /* No online accounts in this contact */ | 173 nd; nd = purple_blist_node_get_sibling_next(nd)) { |
169 if (!offline && !is_contact_online(contact)) | 174 if (default_can_add_node(nd)) |
170 return FALSE; /* Don't want to see offline buddies */ | 175 return TRUE; |
171 return TRUE; | 176 } |
172 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | 177 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
173 PurpleChat *chat = (PurpleChat*)node; | 178 PurpleChat *chat = (PurpleChat*)node; |
174 if (purple_account_is_connected(purple_chat_get_account(chat))) | 179 if (purple_account_is_connected(purple_chat_get_account(chat))) |
175 return TRUE; /* Show whenever the account is online */ | 180 return TRUE; /* Show whenever the account is online */ |
176 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | 181 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { |
177 PurpleGroup *group = (PurpleGroup*)node; | 182 PurpleBlistNode *nd; |
178 gboolean empty = purple_prefs_get_bool(PREF_ROOT "/emptygroups"); | 183 gboolean empty = purple_prefs_get_bool(PREF_ROOT "/emptygroups"); |
179 if (empty) | 184 if (empty) |
180 return TRUE; /* If we want to see empty groups, we can show any group */ | 185 return TRUE; /* If we want to see empty groups, we can show any group */ |
181 | 186 |
182 if (group->currentsize < 1) | 187 for (nd = purple_blist_node_get_first_child(node); |
183 return FALSE; /* No online accounts for this group */ | 188 nd; nd = purple_blist_node_get_sibling_next(nd)) { |
184 | 189 if (default_can_add_node(nd)) |
185 if (!offline && !is_group_online(group)) | 190 return TRUE; |
186 return FALSE; /* Do not want to see group only with offline buddies */ | 191 } |
187 | |
188 return TRUE; | |
189 } | 192 } |
190 | 193 |
191 return FALSE; | 194 return FALSE; |
192 } | 195 } |
193 | 196 |
380 { | 383 { |
381 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node, get_blist_node_flag(node)); | 384 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node, get_blist_node_flag(node)); |
382 gnt_tree_set_row_color(GNT_TREE(ggblist->tree), node, get_display_color(node)); | 385 gnt_tree_set_row_color(GNT_TREE(ggblist->tree), node, get_display_color(node)); |
383 } | 386 } |
384 | 387 |
388 #if 0 | |
385 static gboolean | 389 static gboolean |
386 is_contact_online(PurpleContact *contact) | 390 is_contact_online(PurpleContact *contact) |
387 { | 391 { |
388 PurpleBlistNode *node; | 392 PurpleBlistNode *node; |
389 for (node = purple_blist_node_get_first_child(((PurpleBlistNode*)contact)); node; | 393 for (node = purple_blist_node_get_first_child(((PurpleBlistNode*)contact)); node; |
390 node = purple_blist_node_get_sibling_next(node)) { | 394 node = purple_blist_node_get_sibling_next(node)) { |
391 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) | 395 FinchBlistNode *fnode = node->ui_data; |
396 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node) || | |
397 (fnode && fnode->signed_timer)) | |
392 return TRUE; | 398 return TRUE; |
393 } | 399 } |
394 return FALSE; | 400 return FALSE; |
395 } | 401 } |
396 | 402 |
406 else if (is_contact_online((PurpleContact*)node)) | 412 else if (is_contact_online((PurpleContact*)node)) |
407 return TRUE; | 413 return TRUE; |
408 } | 414 } |
409 return FALSE; | 415 return FALSE; |
410 } | 416 } |
417 #endif | |
411 | 418 |
412 static void | 419 static void |
413 new_node(PurpleBlistNode *node) | 420 new_node(PurpleBlistNode *node) |
414 { | 421 { |
415 } | 422 } |
416 | 423 |
417 static void | 424 static void |
418 add_node(PurpleBlistNode *node, FinchBlist *ggblist) | 425 add_node(PurpleBlistNode *node, FinchBlist *ggblist) |
419 { | 426 { |
427 if (node->ui_data) | |
428 return; | |
429 | |
420 if (!ggblist->manager->can_add_node(node)) | 430 if (!ggblist->manager->can_add_node(node)) |
421 return; | 431 return; |
422 | 432 |
423 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) | 433 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
424 add_buddy((PurpleBuddy*)node, ggblist); | 434 add_buddy((PurpleBuddy*)node, ggblist); |
426 add_contact((PurpleContact*)node, ggblist); | 436 add_contact((PurpleContact*)node, ggblist); |
427 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) | 437 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
428 add_group((PurpleGroup*)node, ggblist); | 438 add_group((PurpleGroup*)node, ggblist); |
429 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) | 439 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
430 add_chat((PurpleChat *)node, ggblist); | 440 add_chat((PurpleChat *)node, ggblist); |
441 | |
431 draw_tooltip(ggblist); | 442 draw_tooltip(ggblist); |
432 } | 443 } |
433 | 444 |
434 void finch_blist_manager_add_node(PurpleBlistNode *node) | 445 void finch_blist_manager_add_node(PurpleBlistNode *node) |
435 { | 446 { |
446 | 457 |
447 static void | 458 static void |
448 node_remove(PurpleBuddyList *list, PurpleBlistNode *node) | 459 node_remove(PurpleBuddyList *list, PurpleBlistNode *node) |
449 { | 460 { |
450 FinchBlist *ggblist = list->ui_data; | 461 FinchBlist *ggblist = list->ui_data; |
462 PurpleBlistNode *parent; | |
451 | 463 |
452 if (ggblist == NULL || node->ui_data == NULL) | 464 if (ggblist == NULL || node->ui_data == NULL) |
453 return; | 465 return; |
454 | 466 |
455 gnt_tree_remove(GNT_TREE(ggblist->tree), node); | 467 gnt_tree_remove(GNT_TREE(ggblist->tree), node); |
456 reset_blist_node_ui_data(node); | 468 reset_blist_node_ui_data(node); |
457 if (ggblist->tagged) | 469 if (ggblist->tagged) |
458 ggblist->tagged = g_list_remove(ggblist->tagged, node); | 470 ggblist->tagged = g_list_remove(ggblist->tagged, node); |
459 | 471 |
460 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 472 parent = purple_blist_node_get_parent(node); |
461 PurpleContact *contact = (PurpleContact*)purple_blist_node_get_parent(node); | 473 for (node = purple_blist_node_get_first_child(node); node; |
462 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) || | 474 node = purple_blist_node_get_sibling_next(node)) |
463 contact->currentsize < 1) | 475 node_remove(list, node); |
464 node_remove(list, (PurpleBlistNode*)contact); | 476 |
477 if (parent) { | |
478 if (!ggblist->manager->can_add_node(parent)) | |
479 node_remove(list, parent); | |
465 else | 480 else |
466 node_update(list, (PurpleBlistNode*)contact); | 481 node_update(list, parent); |
467 } else if (!PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
468 PurpleGroup *group = (PurpleGroup*)purple_blist_node_get_parent(node); | |
469 if ((group->currentsize < 1 && !purple_prefs_get_bool(PREF_ROOT "/emptygroups")) || | |
470 (!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group))) | |
471 node_remove(list, purple_blist_node_get_parent(node)); | |
472 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node)) | |
473 reset_blist_node_ui_data(node); | |
474 } else { | |
475 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node)) | |
476 node_remove(list, node); | |
477 } | 482 } |
478 | 483 |
479 draw_tooltip(ggblist); | 484 draw_tooltip(ggblist); |
480 } | 485 } |
481 | 486 |
514 /* The core seems to expect the UI to add the buddies. */ | 519 /* The core seems to expect the UI to add the buddies. */ |
515 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node)) | 520 for (node = purple_blist_node_get_first_child(node); node; node = purple_blist_node_get_sibling_next(node)) |
516 add_node(node, list->ui_data); | 521 add_node(node, list->ui_data); |
517 } | 522 } |
518 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | 523 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { |
519 PurpleGroup *group = (PurpleGroup*)node; | 524 if (!ggblist->manager->can_add_node(node)) |
520 if (!purple_prefs_get_bool(PREF_ROOT "/emptygroups") && | |
521 ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group)) || | |
522 group->currentsize < 1)) | |
523 node_remove(list, node); | 525 node_remove(list, node); |
524 else | 526 else |
525 add_node(node, list->ui_data); | 527 add_node(node, list->ui_data); |
526 } | 528 } |
527 } | 529 } |
1567 tmp = g_strdup_printf("%s (%s)", | 1569 tmp = g_strdup_printf("%s (%s)", |
1568 purple_account_get_username(account), | 1570 purple_account_get_username(account), |
1569 purple_account_get_protocol_name(account)); | 1571 purple_account_get_protocol_name(account)); |
1570 purple_notify_user_info_add_pair(user_info, _("Account"), tmp); | 1572 purple_notify_user_info_add_pair(user_info, _("Account"), tmp); |
1571 g_free(tmp); | 1573 g_free(tmp); |
1572 | 1574 |
1573 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); | 1575 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); |
1574 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | 1576 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
1575 if (prpl_info && prpl_info->tooltip_text) { | 1577 if (prpl_info && prpl_info->tooltip_text) { |
1576 prpl_info->tooltip_text(buddy, user_info, full); | 1578 prpl_info->tooltip_text(buddy, user_info, full); |
1577 } | 1579 } |
2306 static gboolean | 2308 static gboolean |
2307 buddy_recent_signed_on_off(gpointer data) | 2309 buddy_recent_signed_on_off(gpointer data) |
2308 { | 2310 { |
2309 PurpleBlistNode *node = data; | 2311 PurpleBlistNode *node = data; |
2310 FinchBlistNode *fnode = node->ui_data; | 2312 FinchBlistNode *fnode = node->ui_data; |
2311 PurpleBuddy *buddy = (PurpleBuddy*)node; | |
2312 | 2313 |
2313 purple_timeout_remove(fnode->signed_timer); | 2314 purple_timeout_remove(fnode->signed_timer); |
2314 fnode->signed_timer = 0; | 2315 fnode->signed_timer = 0; |
2315 | 2316 |
2316 if (!purple_account_is_connected(buddy->account) || | 2317 if (!ggblist->manager->can_add_node(node)) { |
2317 (!PURPLE_BUDDY_IS_ONLINE(buddy) && !purple_prefs_get_bool(PREF_ROOT "/showoffline"))) { | |
2318 node_remove(purple_get_blist(), node); | 2318 node_remove(purple_get_blist(), node); |
2319 } else { | 2319 } else { |
2320 update_node_display(node, ggblist); | 2320 update_node_display(node, ggblist); |
2321 if (purple_blist_node_get_parent(node) && PURPLE_BLIST_NODE_IS_CONTACT(purple_blist_node_get_parent(node))) | 2321 if (purple_blist_node_get_parent(node) && PURPLE_BLIST_NODE_IS_CONTACT(purple_blist_node_get_parent(node))) |
2322 update_node_display(purple_blist_node_get_parent(node), ggblist); | 2322 update_node_display(purple_blist_node_get_parent(node), ggblist); |