comparison libpurple/blist.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents 53ae12ee0b68
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
312 char buf[10]; 312 char buf[10];
313 313
314 node = xmlnode_new("account"); 314 node = xmlnode_new("account");
315 xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account)); 315 xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account));
316 xmlnode_set_attrib(node, "name", purple_account_get_username(account)); 316 xmlnode_set_attrib(node, "name", purple_account_get_username(account));
317 g_snprintf(buf, sizeof(buf), "%d", account->perm_deny); 317 g_snprintf(buf, sizeof(buf), "%d", purple_account_get_privacy_type(account));
318 xmlnode_set_attrib(node, "mode", buf); 318 xmlnode_set_attrib(node, "mode", buf);
319 319
320 for (cur = account->permit; cur; cur = cur->next) 320 for (cur = account->permit; cur; cur = cur->next)
321 { 321 {
322 child = xmlnode_new_child(node, "permit"); 322 child = xmlnode_new_child(node, "permit");
459 parse_buddy(PurpleGroup *group, PurpleContact *contact, xmlnode *bnode) 459 parse_buddy(PurpleGroup *group, PurpleContact *contact, xmlnode *bnode)
460 { 460 {
461 PurpleAccount *account; 461 PurpleAccount *account;
462 PurpleBuddy *buddy; 462 PurpleBuddy *buddy;
463 char *name = NULL, *alias = NULL; 463 char *name = NULL, *alias = NULL;
464 const char *acct_name, *proto, *protocol; 464 const char *acct_name, *proto;
465 xmlnode *x; 465 xmlnode *x;
466 466
467 acct_name = xmlnode_get_attrib(bnode, "account"); 467 acct_name = xmlnode_get_attrib(bnode, "account");
468 protocol = xmlnode_get_attrib(bnode, "protocol");
469 protocol = _purple_oscar_convert(acct_name, protocol); /* XXX: Remove */
470 proto = xmlnode_get_attrib(bnode, "proto"); 468 proto = xmlnode_get_attrib(bnode, "proto");
471 proto = _purple_oscar_convert(acct_name, proto); /* XXX: Remove */ 469
472 470 if (!acct_name || !proto)
473 if (!acct_name || (!proto && !protocol))
474 return; 471 return;
475 472
476 account = purple_accounts_find(acct_name, proto ? proto : protocol); 473 account = purple_accounts_find(acct_name, proto);
477 474
478 if (!account) 475 if (!account)
479 return; 476 return;
480 477
481 if ((x = xmlnode_get_child(bnode, "name"))) 478 if ((x = xmlnode_get_child(bnode, "name")))
530 static void 527 static void
531 parse_chat(PurpleGroup *group, xmlnode *cnode) 528 parse_chat(PurpleGroup *group, xmlnode *cnode)
532 { 529 {
533 PurpleChat *chat; 530 PurpleChat *chat;
534 PurpleAccount *account; 531 PurpleAccount *account;
535 const char *acct_name, *proto, *protocol; 532 const char *acct_name, *proto;
536 xmlnode *x; 533 xmlnode *x;
537 char *alias = NULL; 534 char *alias = NULL;
538 GHashTable *components; 535 GHashTable *components;
539 536
540 acct_name = xmlnode_get_attrib(cnode, "account"); 537 acct_name = xmlnode_get_attrib(cnode, "account");
541 protocol = xmlnode_get_attrib(cnode, "protocol");
542 proto = xmlnode_get_attrib(cnode, "proto"); 538 proto = xmlnode_get_attrib(cnode, "proto");
543 539
544 if (!acct_name || (!proto && !protocol)) 540 if (!acct_name || !proto)
545 return; 541 return;
546 542
547 account = purple_accounts_find(acct_name, proto ? proto : protocol); 543 account = purple_accounts_find(acct_name, proto);
548 544
549 if (!account) 545 if (!account)
550 return; 546 return;
551 547
552 if ((x = xmlnode_get_child(cnode, "alias"))) 548 if ((x = xmlnode_get_child(cnode, "alias")))
628 xmlnode *anode; 624 xmlnode *anode;
629 for (anode = privacy->child; anode; anode = anode->next) { 625 for (anode = privacy->child; anode; anode = anode->next) {
630 xmlnode *x; 626 xmlnode *x;
631 PurpleAccount *account; 627 PurpleAccount *account;
632 int imode; 628 int imode;
633 const char *acct_name, *proto, *mode, *protocol; 629 const char *acct_name, *proto, *mode;
634 630
635 acct_name = xmlnode_get_attrib(anode, "name"); 631 acct_name = xmlnode_get_attrib(anode, "name");
636 protocol = xmlnode_get_attrib(anode, "protocol");
637 proto = xmlnode_get_attrib(anode, "proto"); 632 proto = xmlnode_get_attrib(anode, "proto");
638 mode = xmlnode_get_attrib(anode, "mode"); 633 mode = xmlnode_get_attrib(anode, "mode");
639 634
640 if (!acct_name || (!proto && !protocol) || !mode) 635 if (!acct_name || !proto || !mode)
641 continue; 636 continue;
642 637
643 account = purple_accounts_find(acct_name, proto ? proto : protocol); 638 account = purple_accounts_find(acct_name, proto);
644 639
645 if (!account) 640 if (!account)
646 continue; 641 continue;
647 642
648 imode = atoi(mode); 643 imode = atoi(mode);
649 account->perm_deny = (imode != 0 ? imode : PURPLE_PRIVACY_ALLOW_ALL); 644 purple_account_set_privacy_type(account, (imode != 0 ? imode : PURPLE_PRIVACY_ALLOW_ALL));
650 645
651 for (x = anode->child; x; x = x->next) { 646 for (x = anode->child; x; x = x->next) {
652 char *name; 647 char *name;
653 if (x->type != XMLNODE_TYPE_TAG) 648 if (x->type != XMLNODE_TYPE_TAG)
654 continue; 649 continue;
957 952
958 g_return_if_fail(node != NULL); 953 g_return_if_fail(node != NULL);
959 954
960 if (ops && ops->update) 955 if (ops && ops->update)
961 ops->update(purplebuddylist, node); 956 ops->update(purplebuddylist, node);
962 }
963
964 void
965 purple_blist_update_buddy_icon(PurpleBuddy *buddy)
966 {
967 purple_blist_update_node_icon((PurpleBlistNode *)buddy);
968 } 957 }
969 958
970 /* 959 /*
971 * TODO: Maybe remove the call to this from server.c and call it 960 * TODO: Maybe remove the call to this from server.c and call it
972 * from oscar.c and toc.c instead? 961 * from oscar.c and toc.c instead?
1316 groups = g_list_prepend(groups, node->parent->parent); 1305 groups = g_list_prepend(groups, node->parent->parent);
1317 } 1306 }
1318 1307
1319 purple_account_remove_buddies(account, buddies, groups); 1308 purple_account_remove_buddies(account, buddies, groups);
1320 g_list_free(groups); 1309 g_list_free(groups);
1321 purple_account_add_buddies(account, buddies); 1310 purple_account_add_buddies(account, buddies, NULL);
1322 } 1311 }
1323 1312
1324 g_list_free(buddies); 1313 g_list_free(buddies);
1325 } 1314 }
1326 } 1315 }
1746 g_return_val_if_fail(contact, NULL); 1735 g_return_val_if_fail(contact, NULL);
1747 1736
1748 return (PurpleGroup *)(((PurpleBlistNode *)contact)->parent); 1737 return (PurpleGroup *)(((PurpleBlistNode *)contact)->parent);
1749 } 1738 }
1750 1739
1751 void purple_contact_set_alias(PurpleContact *contact, const char *alias)
1752 {
1753 purple_blist_alias_contact(contact,alias);
1754 }
1755
1756 const char *purple_contact_get_alias(PurpleContact* contact) 1740 const char *purple_contact_get_alias(PurpleContact* contact)
1757 { 1741 {
1758 g_return_val_if_fail(contact != NULL, NULL); 1742 g_return_val_if_fail(contact != NULL, NULL);
1759 1743
1760 if (contact->alias) 1744 if (contact->alias)
1787 { 1771 {
1788 g_return_if_fail(contact != NULL); 1772 g_return_if_fail(contact != NULL);
1789 1773
1790 contact->priority_valid = FALSE; 1774 contact->priority_valid = FALSE;
1791 } 1775 }
1776
1777 int purple_contact_get_contact_size(PurpleContact *contact, gboolean offline)
1778 {
1779 g_return_val_if_fail(contact != NULL, 0);
1780
1781 return offline ? contact->totalsize : contact->currentsize;
1782 }
1792 1783
1793 PurpleGroup *purple_group_new(const char *name) 1784 PurpleGroup *purple_group_new(const char *name)
1794 { 1785 {
1795 PurpleBlistUiOps *ops = purple_blist_get_ui_ops(); 1786 PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
1796 PurpleGroup *group; 1787 PurpleGroup *group;
2376 2367
2377 if ((buddy->server_alias) && (*buddy->server_alias)) 2368 if ((buddy->server_alias) && (*buddy->server_alias))
2378 return buddy->server_alias; 2369 return buddy->server_alias;
2379 2370
2380 return NULL; 2371 return NULL;
2381 }
2382
2383 const char *purple_buddy_get_local_alias(PurpleBuddy *buddy)
2384 {
2385 PurpleContact *c;
2386
2387 g_return_val_if_fail(buddy != NULL, NULL);
2388
2389 /* Search for an alias for the buddy. In order of precedence: */
2390 /* The buddy alias */
2391 if (buddy->alias != NULL)
2392 return buddy->alias;
2393
2394 /* The contact alias */
2395 c = purple_buddy_get_contact(buddy);
2396 if ((c != NULL) && (c->alias != NULL))
2397 return c->alias;
2398
2399 /* The buddy's user name (i.e. no alias) */
2400 return buddy->name;
2401 } 2372 }
2402 2373
2403 const char *purple_chat_get_name(PurpleChat *chat) 2374 const char *purple_chat_get_name(PurpleChat *chat)
2404 { 2375 {
2405 char *ret = NULL; 2376 char *ret = NULL;
2935 { 2906 {
2936 g_return_val_if_fail(node != NULL, PURPLE_BLIST_OTHER_NODE); 2907 g_return_val_if_fail(node != NULL, PURPLE_BLIST_OTHER_NODE);
2937 return node->type; 2908 return node->type;
2938 } 2909 }
2939 2910
2911 gboolean
2912 purple_blist_node_has_setting(PurpleBlistNode* node, const char *key)
2913 {
2914 g_return_val_if_fail(node != NULL, FALSE);
2915 g_return_val_if_fail(node->settings != NULL, FALSE);
2916 g_return_val_if_fail(key != NULL, FALSE);
2917
2918 /* Boxed type, so it won't ever be NULL, so no need for _extended */
2919 return (g_hash_table_lookup(node->settings, key) != NULL);
2920 }
2921
2940 void 2922 void
2941 purple_blist_node_set_bool(PurpleBlistNode* node, const char *key, gboolean data) 2923 purple_blist_node_set_bool(PurpleBlistNode* node, const char *key, gboolean data)
2942 { 2924 {
2943 PurpleValue *value; 2925 PurpleValue *value;
2944 PurpleBlistUiOps *ops; 2926 PurpleBlistUiOps *ops;