Mercurial > pidgin
comparison libpurple/blist.c @ 25918:bc8d1607f9b8
propagate from branch 'im.pidgin.pidgin' (head 566d2e86bfd45c806aba1b32d6f85a9a409ff9ea)
to branch 'im.pidgin.pidgin.next.minor' (head ffd76856f93610f7cd6178e943d0b61e4220b549)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 26 Jan 2009 02:39:55 +0000 |
parents | 3687049b4faf |
children | 584063555949 |
comparison
equal
deleted
inserted
replaced
25372:a8db457c421a | 25918:bc8d1607f9b8 |
---|---|
80 return g_str_hash(hb->name); | 80 return g_str_hash(hb->name); |
81 } | 81 } |
82 | 82 |
83 static guint _purple_blist_hbuddy_equal(struct _purple_hbuddy *hb1, struct _purple_hbuddy *hb2) | 83 static guint _purple_blist_hbuddy_equal(struct _purple_hbuddy *hb1, struct _purple_hbuddy *hb2) |
84 { | 84 { |
85 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); | 85 return (purple_strequal(hb1->name, hb2->name) && hb1->account == hb2->account && hb1->group == hb2->group); |
86 } | 86 } |
87 | 87 |
88 static void _purple_blist_hbuddy_free_key(struct _purple_hbuddy *hb) | 88 static void _purple_blist_hbuddy_free_key(struct _purple_hbuddy *hb) |
89 { | 89 { |
90 g_free(hb->name); | 90 g_free(hb->name); |
380 char *value = xmlnode_get_data(setting); | 380 char *value = xmlnode_get_data(setting); |
381 | 381 |
382 if (!value) | 382 if (!value) |
383 return; | 383 return; |
384 | 384 |
385 if (!type || !strcmp(type, "string")) | 385 if (!type || purple_strequal(type, "string")) |
386 purple_blist_node_set_string(node, name, value); | 386 purple_blist_node_set_string(node, name, value); |
387 else if (!strcmp(type, "bool")) | 387 else if (purple_strequal(type, "bool")) |
388 purple_blist_node_set_bool(node, name, atoi(value)); | 388 purple_blist_node_set_bool(node, name, atoi(value)); |
389 else if (!strcmp(type, "int")) | 389 else if (purple_strequal(type, "int")) |
390 purple_blist_node_set_int(node, name, atoi(value)); | 390 purple_blist_node_set_int(node, name, atoi(value)); |
391 | 391 |
392 g_free(value); | 392 g_free(value); |
393 } | 393 } |
394 | 394 |
451 } | 451 } |
452 | 452 |
453 for (x = cnode->child; x; x = x->next) { | 453 for (x = cnode->child; x; x = x->next) { |
454 if (x->type != XMLNODE_TYPE_TAG) | 454 if (x->type != XMLNODE_TYPE_TAG) |
455 continue; | 455 continue; |
456 if (!strcmp(x->name, "buddy")) | 456 if (purple_strequal(x->name, "buddy")) |
457 parse_buddy(group, contact, x); | 457 parse_buddy(group, contact, x); |
458 else if (!strcmp(x->name, "setting")) | 458 else if (purple_strequal(x->name, "setting")) |
459 parse_setting((PurpleBlistNode*)contact, x); | 459 parse_setting((PurpleBlistNode*)contact, x); |
460 } | 460 } |
461 | 461 |
462 /* if the contact is empty, don't keep it around. it causes problems */ | 462 /* if the contact is empty, don't keep it around. it causes problems */ |
463 if (!((PurpleBlistNode*)contact)->child) | 463 if (!((PurpleBlistNode*)contact)->child) |
526 purple_blist_get_last_sibling(purplebuddylist->root)); | 526 purple_blist_get_last_sibling(purplebuddylist->root)); |
527 | 527 |
528 for (cnode = groupnode->child; cnode; cnode = cnode->next) { | 528 for (cnode = groupnode->child; cnode; cnode = cnode->next) { |
529 if (cnode->type != XMLNODE_TYPE_TAG) | 529 if (cnode->type != XMLNODE_TYPE_TAG) |
530 continue; | 530 continue; |
531 if (!strcmp(cnode->name, "setting")) | 531 if (purple_strequal(cnode->name, "setting")) |
532 parse_setting((PurpleBlistNode*)group, cnode); | 532 parse_setting((PurpleBlistNode*)group, cnode); |
533 else if (!strcmp(cnode->name, "contact") || | 533 else if (purple_strequal(cnode->name, "contact") || |
534 !strcmp(cnode->name, "person")) | 534 purple_strequal(cnode->name, "person")) |
535 parse_contact(group, cnode); | 535 parse_contact(group, cnode); |
536 else if (!strcmp(cnode->name, "chat")) | 536 else if (purple_strequal(cnode->name, "chat")) |
537 parse_chat(group, cnode); | 537 parse_chat(group, cnode); |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 /* TODO: Make static and rename to load_blist */ | 541 /* TODO: Make static and rename to load_blist */ |
588 for (x = anode->child; x; x = x->next) { | 588 for (x = anode->child; x; x = x->next) { |
589 char *name; | 589 char *name; |
590 if (x->type != XMLNODE_TYPE_TAG) | 590 if (x->type != XMLNODE_TYPE_TAG) |
591 continue; | 591 continue; |
592 | 592 |
593 if (!strcmp(x->name, "permit")) { | 593 if (purple_strequal(x->name, "permit")) { |
594 name = xmlnode_get_data(x); | 594 name = xmlnode_get_data(x); |
595 purple_privacy_permit_add(account, name, TRUE); | 595 purple_privacy_permit_add(account, name, TRUE); |
596 g_free(name); | 596 g_free(name); |
597 } else if (!strcmp(x->name, "block")) { | 597 } else if (purple_strequal(x->name, "block")) { |
598 name = xmlnode_get_data(x); | 598 name = xmlnode_get_data(x); |
599 purple_privacy_deny_add(account, name, TRUE); | 599 purple_privacy_deny_add(account, name, TRUE); |
600 g_free(name); | 600 g_free(name); |
601 } | 601 } |
602 } | 602 } |
695 | 695 |
696 PurpleBlistNode * | 696 PurpleBlistNode * |
697 purple_blist_get_root() | 697 purple_blist_get_root() |
698 { | 698 { |
699 return purplebuddylist ? purplebuddylist->root : NULL; | 699 return purplebuddylist ? purplebuddylist->root : NULL; |
700 } | |
701 | |
702 GHashTable * | |
703 purple_blist_get_buddies() | |
704 { | |
705 return purplebuddylist ? purplebuddylist->buddies : NULL; | |
706 } | |
707 | |
708 void * | |
709 purple_blist_get_ui_data() | |
710 { | |
711 return purplebuddylist->ui_data; | |
712 } | |
713 | |
714 void | |
715 purple_blist_set_ui_data(void *ui_data) | |
716 { | |
717 purplebuddylist->ui_data = ui_data; | |
700 } | 718 } |
701 | 719 |
702 void purple_blist_show() | 720 void purple_blist_show() |
703 { | 721 { |
704 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); | 722 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); |
772 PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node) | 790 PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node) |
773 { | 791 { |
774 return node? node->prev : NULL; | 792 return node? node->prev : NULL; |
775 } | 793 } |
776 | 794 |
795 void * | |
796 purple_blist_node_get_ui_data(const PurpleBlistNode *node) | |
797 { | |
798 g_return_val_if_fail(node, NULL); | |
799 | |
800 return node->ui_data; | |
801 } | |
802 | |
803 void | |
804 purple_blist_node_set_ui_data(PurpleBlistNode *node, void *ui_data) { | |
805 g_return_if_fail(node); | |
806 | |
807 node->ui_data = ui_data; | |
808 } | |
809 | |
777 void | 810 void |
778 purple_blist_update_buddy_status(PurpleBuddy *buddy, PurpleStatus *old_status) | 811 purple_blist_update_buddy_status(PurpleBuddy *buddy, PurpleStatus *old_status) |
779 { | 812 { |
780 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); | 813 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); |
781 PurplePresence *presence; | 814 PurplePresence *presence; |
782 PurpleStatus *status; | 815 PurpleStatus *status; |
816 PurpleBlistNode *cnode; | |
783 | 817 |
784 g_return_if_fail(buddy != NULL); | 818 g_return_if_fail(buddy != NULL); |
785 | 819 |
786 presence = purple_buddy_get_presence(buddy); | 820 presence = purple_buddy_get_presence(buddy); |
787 status = purple_presence_get_active_status(presence); | 821 status = purple_presence_get_active_status(presence); |
792 if (purple_status_is_online(status) && | 826 if (purple_status_is_online(status) && |
793 !purple_status_is_online(old_status)) { | 827 !purple_status_is_online(old_status)) { |
794 | 828 |
795 purple_signal_emit(purple_blist_get_handle(), "buddy-signed-on", buddy); | 829 purple_signal_emit(purple_blist_get_handle(), "buddy-signed-on", buddy); |
796 | 830 |
797 ((PurpleContact*)((PurpleBlistNode*)buddy)->parent)->online++; | 831 cnode = buddy->node.parent; |
798 if (((PurpleContact*)((PurpleBlistNode*)buddy)->parent)->online == 1) | 832 if (++(PURPLE_CONTACT(cnode)->online) == 1) |
799 ((PurpleGroup *)((PurpleBlistNode *)buddy)->parent->parent)->online++; | 833 PURPLE_GROUP(cnode->parent)->online++; |
800 } else if (!purple_status_is_online(status) && | 834 } else if (!purple_status_is_online(status) && |
801 purple_status_is_online(old_status)) { | 835 purple_status_is_online(old_status)) { |
836 | |
802 purple_blist_node_set_int(&buddy->node, "last_seen", time(NULL)); | 837 purple_blist_node_set_int(&buddy->node, "last_seen", time(NULL)); |
803 purple_signal_emit(purple_blist_get_handle(), "buddy-signed-off", buddy); | 838 purple_signal_emit(purple_blist_get_handle(), "buddy-signed-off", buddy); |
804 ((PurpleContact*)((PurpleBlistNode*)buddy)->parent)->online--; | 839 |
805 if (((PurpleContact*)((PurpleBlistNode*)buddy)->parent)->online == 0) | 840 cnode = buddy->node.parent; |
806 ((PurpleGroup *)((PurpleBlistNode *)buddy)->parent->parent)->online--; | 841 if (--(PURPLE_CONTACT(cnode)->online) == 0) |
842 PURPLE_GROUP(cnode->parent)->online--; | |
807 } else { | 843 } else { |
808 purple_signal_emit(purple_blist_get_handle(), | 844 purple_signal_emit(purple_blist_get_handle(), |
809 "buddy-status-changed", buddy, old_status, | 845 "buddy-status-changed", buddy, old_status, |
810 status); | 846 status); |
811 } | 847 } |
1023 GSList *accts; | 1059 GSList *accts; |
1024 | 1060 |
1025 g_return_if_fail(source != NULL); | 1061 g_return_if_fail(source != NULL); |
1026 g_return_if_fail(new_name != NULL); | 1062 g_return_if_fail(new_name != NULL); |
1027 | 1063 |
1028 if (*new_name == '\0' || !strcmp(new_name, source->name)) | 1064 if (*new_name == '\0' || purple_strequal(new_name, source->name)) |
1029 return; | 1065 return; |
1030 | 1066 |
1031 dest = purple_find_group(new_name); | 1067 dest = purple_find_group(new_name); |
1032 if (dest != NULL && purple_utf8_strcasecmp(source->name, dest->name) != 0) { | 1068 if (dest != NULL && purple_utf8_strcasecmp(source->name, dest->name) != 0) { |
1033 /* We're merging two groups */ | 1069 /* We're merging two groups */ |
1090 if (ops && ops->update) | 1126 if (ops && ops->update) |
1091 ops->update(purplebuddylist, (PurpleBlistNode*)source); | 1127 ops->update(purplebuddylist, (PurpleBlistNode*)source); |
1092 | 1128 |
1093 /* Notify all PRPLs */ | 1129 /* Notify all PRPLs */ |
1094 /* TODO: Is this condition needed? Seems like it would always be TRUE */ | 1130 /* TODO: Is this condition needed? Seems like it would always be TRUE */ |
1095 if(old_name && source && strcmp(source->name, old_name)) { | 1131 if(old_name && purple_strequal(source->name, old_name)) { |
1096 for (accts = purple_group_get_accounts(source); accts; accts = g_slist_remove(accts, accts->data)) { | 1132 for (accts = purple_group_get_accounts(source); accts; accts = g_slist_remove(accts, accts->data)) { |
1097 PurpleAccount *account = accts->data; | 1133 PurpleAccount *account = accts->data; |
1098 PurpleConnection *gc = NULL; | 1134 PurpleConnection *gc = NULL; |
1099 PurplePlugin *prpl = NULL; | 1135 PurplePlugin *prpl = NULL; |
1100 PurplePluginProtocolInfo *prpl_info = NULL; | 1136 PurplePluginProtocolInfo *prpl_info = NULL; |
1229 { | 1265 { |
1230 g_return_val_if_fail(buddy != NULL, NULL); | 1266 g_return_val_if_fail(buddy != NULL, NULL); |
1231 | 1267 |
1232 return buddy->icon; | 1268 return buddy->icon; |
1233 } | 1269 } |
1270 | |
1271 gpointer | |
1272 purple_buddy_get_protocol_data(const PurpleBuddy *buddy) | |
1273 { | |
1274 g_return_val_if_fail(buddy != NULL, NULL); | |
1275 | |
1276 return buddy->proto_data; | |
1277 } | |
1278 | |
1279 void | |
1280 purple_buddy_set_protocol_data(PurpleBuddy *buddy, gpointer data) | |
1281 { | |
1282 g_return_if_fail(buddy != NULL); | |
1283 | |
1284 buddy->proto_data = data; | |
1285 } | |
1286 | |
1234 | 1287 |
1235 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node) | 1288 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node) |
1236 { | 1289 { |
1237 PurpleBlistNode *cnode = (PurpleBlistNode*)chat; | 1290 PurpleBlistNode *cnode = (PurpleBlistNode*)chat; |
1238 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); | 1291 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); |
1337 if (node && PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 1390 if (node && PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1338 c = (PurpleContact*)node->parent; | 1391 c = (PurpleContact*)node->parent; |
1339 g = (PurpleGroup*)node->parent->parent; | 1392 g = (PurpleGroup*)node->parent->parent; |
1340 } else if (contact) { | 1393 } else if (contact) { |
1341 c = contact; | 1394 c = contact; |
1342 g = (PurpleGroup *)((PurpleBlistNode *)c)->parent; | 1395 g = PURPLE_GROUP(PURPLE_BLIST_NODE(c)->parent); |
1343 } else { | 1396 } else { |
1344 g = group; | 1397 g = group; |
1345 if (g == NULL) | 1398 if (g == NULL) |
1346 g = purple_group_new(_("Buddies")); | 1399 g = purple_group_new(_("Buddies")); |
1347 /* Add group to blist if isn't already on it. Fixes #2752. */ | 1400 /* Add group to blist if isn't already on it. Fixes #2752. */ |
1419 cnode->child = bnode; | 1472 cnode->child = bnode; |
1420 bnode->parent = cnode; | 1473 bnode->parent = cnode; |
1421 } | 1474 } |
1422 | 1475 |
1423 if (PURPLE_BUDDY_IS_ONLINE(buddy)) { | 1476 if (PURPLE_BUDDY_IS_ONLINE(buddy)) { |
1424 ((PurpleContact*)bnode->parent)->online++; | 1477 if (++(PURPLE_CONTACT(bnode->parent)->online) == 1) |
1425 if (((PurpleContact*)bnode->parent)->online == 1) | 1478 PURPLE_GROUP(bnode->parent->parent)->online++; |
1426 ((PurpleGroup*)bnode->parent->parent)->online++; | |
1427 } | 1479 } |
1428 if (purple_account_is_connected(buddy->account)) { | 1480 if (purple_account_is_connected(buddy->account)) { |
1429 ((PurpleContact*)bnode->parent)->currentsize++; | 1481 if (++(PURPLE_CONTACT(bnode->parent)->currentsize) == 1) |
1430 if (((PurpleContact*)bnode->parent)->currentsize == 1) | 1482 PURPLE_GROUP(bnode->parent->parent)->currentsize++; |
1431 ((PurpleGroup*)bnode->parent->parent)->currentsize++; | 1483 } |
1432 } | 1484 PURPLE_CONTACT(bnode->parent)->totalsize++; |
1433 ((PurpleContact*)bnode->parent)->totalsize++; | |
1434 | 1485 |
1435 hb = g_new(struct _purple_hbuddy, 1); | 1486 hb = g_new(struct _purple_hbuddy, 1); |
1436 hb->name = g_strdup(purple_normalize(buddy->account, buddy->name)); | 1487 hb->name = g_strdup(purple_normalize(buddy->account, buddy->name)); |
1437 hb->account = buddy->account; | 1488 hb->account = buddy->account; |
1438 hb->group = ((PurpleBlistNode*)buddy)->parent->parent; | 1489 hb->group = ((PurpleBlistNode*)buddy)->parent->parent; |
1544 PurpleBlistNode *gnode, *cnode, *bnode; | 1595 PurpleBlistNode *gnode, *cnode, *bnode; |
1545 | 1596 |
1546 g_return_if_fail(contact != NULL); | 1597 g_return_if_fail(contact != NULL); |
1547 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT((PurpleBlistNode*)contact)); | 1598 g_return_if_fail(PURPLE_BLIST_NODE_IS_CONTACT((PurpleBlistNode*)contact)); |
1548 | 1599 |
1549 if ((PurpleBlistNode*)contact == node) | 1600 if (PURPLE_BLIST_NODE(contact) == node) |
1550 return; | 1601 return; |
1551 | 1602 |
1552 if (node && (PURPLE_BLIST_NODE_IS_CONTACT(node) || | 1603 if (node && (PURPLE_BLIST_NODE_IS_CONTACT(node) || |
1553 PURPLE_BLIST_NODE_IS_CHAT(node))) | 1604 PURPLE_BLIST_NODE_IS_CHAT(node))) |
1554 g = (PurpleGroup*)node->parent; | 1605 g = (PurpleGroup*)node->parent; |
2054 | 2105 |
2055 /* The buddy's user name (i.e. no alias) */ | 2106 /* The buddy's user name (i.e. no alias) */ |
2056 return buddy->name; | 2107 return buddy->name; |
2057 } | 2108 } |
2058 | 2109 |
2110 const char *purple_buddy_get_local_buddy_alias(PurpleBuddy *buddy) | |
2111 { | |
2112 g_return_val_if_fail(buddy, NULL); | |
2113 return buddy->alias; | |
2114 } | |
2115 | |
2059 const char *purple_buddy_get_server_alias(PurpleBuddy *buddy) | 2116 const char *purple_buddy_get_server_alias(PurpleBuddy *buddy) |
2060 { | 2117 { |
2061 g_return_val_if_fail(buddy != NULL, NULL); | 2118 g_return_val_if_fail(buddy != NULL, NULL); |
2062 | 2119 |
2063 if ((buddy->server_alias) && (*buddy->server_alias)) | 2120 if ((buddy->server_alias) && (*buddy->server_alias)) |
2298 | 2355 |
2299 PurpleContact *purple_buddy_get_contact(PurpleBuddy *buddy) | 2356 PurpleContact *purple_buddy_get_contact(PurpleBuddy *buddy) |
2300 { | 2357 { |
2301 g_return_val_if_fail(buddy != NULL, NULL); | 2358 g_return_val_if_fail(buddy != NULL, NULL); |
2302 | 2359 |
2303 return (PurpleContact*)((PurpleBlistNode*)buddy)->parent; | 2360 return PURPLE_CONTACT(PURPLE_BLIST_NODE(buddy)->parent); |
2304 } | 2361 } |
2305 | 2362 |
2306 PurplePresence *purple_buddy_get_presence(const PurpleBuddy *buddy) | 2363 PurplePresence *purple_buddy_get_presence(const PurpleBuddy *buddy) |
2307 { | 2364 { |
2308 g_return_val_if_fail(buddy != NULL, NULL); | 2365 g_return_val_if_fail(buddy != NULL, NULL); |