Mercurial > pidgin
comparison libpurple/account.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 | ec6371d4cae8 |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
39 #include "signals.h" | 39 #include "signals.h" |
40 #include "status.h" | 40 #include "status.h" |
41 #include "util.h" | 41 #include "util.h" |
42 #include "xmlnode.h" | 42 #include "xmlnode.h" |
43 | 43 |
44 typedef struct | |
45 { | |
46 PurpleConnectionErrorInfo *current_error; | |
47 } PurpleAccountPrivate; | |
48 | |
49 #define PURPLE_ACCOUNT_GET_PRIVATE(account) \ | |
50 ((PurpleAccountPrivate *) (account->priv)) | |
51 | |
52 /* TODO: Should use PurpleValue instead of this? What about "ui"? */ | 44 /* TODO: Should use PurpleValue instead of this? What about "ui"? */ |
53 typedef struct | 45 typedef struct |
54 { | 46 { |
55 PurplePrefType type; | 47 PurplePrefType type; |
56 | 48 |
359 } | 351 } |
360 | 352 |
361 static xmlnode * | 353 static xmlnode * |
362 account_to_xmlnode(PurpleAccount *account) | 354 account_to_xmlnode(PurpleAccount *account) |
363 { | 355 { |
364 PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account); | |
365 | |
366 xmlnode *node, *child; | 356 xmlnode *node, *child; |
367 const char *tmp; | 357 const char *tmp; |
368 PurplePresence *presence; | 358 PurplePresence *presence; |
369 PurpleProxyInfo *proxy_info; | 359 PurpleProxyInfo *proxy_info; |
370 | 360 |
417 { | 407 { |
418 child = proxy_settings_to_xmlnode(proxy_info); | 408 child = proxy_settings_to_xmlnode(proxy_info); |
419 xmlnode_insert_child(node, child); | 409 xmlnode_insert_child(node, child); |
420 } | 410 } |
421 | 411 |
422 child = current_error_to_xmlnode(priv->current_error); | 412 child = current_error_to_xmlnode(account->current_error); |
423 xmlnode_insert_child(node, child); | 413 xmlnode_insert_child(node, child); |
424 | 414 |
425 return node; | 415 return node; |
426 } | 416 } |
427 | 417 |
872 g_free(protocol_id); | 862 g_free(protocol_id); |
873 g_free(name); | 863 g_free(name); |
874 return NULL; | 864 return NULL; |
875 } | 865 } |
876 | 866 |
877 ret = purple_account_new(name, _purple_oscar_convert(name, protocol_id)); /* XXX: */ | 867 ret = purple_account_new(name, protocol_id); |
878 g_free(name); | 868 g_free(name); |
879 g_free(protocol_id); | 869 g_free(protocol_id); |
880 | 870 |
881 /* Read the password */ | 871 /* Read the password */ |
882 child = xmlnode_get_child(node, "password"); | 872 child = xmlnode_get_child(node, "password"); |
922 | 912 |
923 if (g_file_get_contents(filename, &contents, &len, NULL)) | 913 if (g_file_get_contents(filename, &contents, &len, NULL)) |
924 { | 914 { |
925 purple_buddy_icons_set_account_icon(ret, (guchar *)contents, len); | 915 purple_buddy_icons_set_account_icon(ret, (guchar *)contents, len); |
926 } | 916 } |
927 else | |
928 { | |
929 /* Try to see if the icon got left behind in the old cache. */ | |
930 g_free(filename); | |
931 filename = g_build_filename(g_get_home_dir(), ".gaim", "icons", data, NULL); | |
932 if (g_file_get_contents(filename, &contents, &len, NULL)) { | |
933 purple_buddy_icons_set_account_icon(ret, (guchar*)contents, len); | |
934 } | |
935 } | |
936 | 917 |
937 g_free(filename); | 918 g_free(filename); |
938 g_free(data); | 919 g_free(data); |
939 } | 920 } |
940 | 921 |
1003 | 984 |
1004 PurpleAccount * | 985 PurpleAccount * |
1005 purple_account_new(const char *username, const char *protocol_id) | 986 purple_account_new(const char *username, const char *protocol_id) |
1006 { | 987 { |
1007 PurpleAccount *account = NULL; | 988 PurpleAccount *account = NULL; |
1008 PurpleAccountPrivate *priv = NULL; | |
1009 PurplePlugin *prpl = NULL; | 989 PurplePlugin *prpl = NULL; |
1010 PurplePluginProtocolInfo *prpl_info = NULL; | 990 PurplePluginProtocolInfo *prpl_info = NULL; |
1011 PurpleStatusType *status_type; | 991 PurpleStatusType *status_type; |
1012 | 992 |
1013 g_return_val_if_fail(username != NULL, NULL); | 993 g_return_val_if_fail(username != NULL, NULL); |
1018 if (account != NULL) | 998 if (account != NULL) |
1019 return account; | 999 return account; |
1020 | 1000 |
1021 account = g_new0(PurpleAccount, 1); | 1001 account = g_new0(PurpleAccount, 1); |
1022 PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount); | 1002 PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount); |
1023 priv = g_new0(PurpleAccountPrivate, 1); | |
1024 account->priv = priv; | |
1025 | 1003 |
1026 purple_account_set_username(account, username); | 1004 purple_account_set_username(account, username); |
1027 | 1005 |
1028 purple_account_set_protocol_id(account, protocol_id); | 1006 purple_account_set_protocol_id(account, protocol_id); |
1029 | 1007 |
1062 } | 1040 } |
1063 | 1041 |
1064 void | 1042 void |
1065 purple_account_destroy(PurpleAccount *account) | 1043 purple_account_destroy(PurpleAccount *account) |
1066 { | 1044 { |
1067 PurpleAccountPrivate *priv = NULL; | |
1068 GList *l; | 1045 GList *l; |
1069 | 1046 |
1070 g_return_if_fail(account != NULL); | 1047 g_return_if_fail(account != NULL); |
1071 | 1048 |
1072 purple_debug_info("account", "Destroying account %p\n", account); | 1049 purple_debug_info("account", "Destroying account %p\n", account); |
1093 if (account->proxy_info) | 1070 if (account->proxy_info) |
1094 purple_proxy_info_destroy(account->proxy_info); | 1071 purple_proxy_info_destroy(account->proxy_info); |
1095 | 1072 |
1096 purple_account_set_status_types(account, NULL); | 1073 purple_account_set_status_types(account, NULL); |
1097 | 1074 |
1098 purple_presence_destroy(account->presence); | 1075 if (account->presence) |
1076 purple_presence_destroy(account->presence); | |
1099 | 1077 |
1100 if(account->system_log) | 1078 if(account->system_log) |
1101 purple_log_free(account->system_log); | 1079 purple_log_free(account->system_log); |
1102 | 1080 |
1103 while (account->deny) { | 1081 while (account->deny) { |
1108 while (account->permit) { | 1086 while (account->permit) { |
1109 g_free(account->permit->data); | 1087 g_free(account->permit->data); |
1110 account->permit = g_slist_delete_link(account->permit, account->permit); | 1088 account->permit = g_slist_delete_link(account->permit, account->permit); |
1111 } | 1089 } |
1112 | 1090 |
1113 priv = PURPLE_ACCOUNT_GET_PRIVATE(account); | 1091 PURPLE_DBUS_UNREGISTER_POINTER(account->current_error); |
1114 PURPLE_DBUS_UNREGISTER_POINTER(priv->current_error); | 1092 if (account->current_error) { |
1115 if (priv->current_error) { | 1093 g_free(account->current_error->description); |
1116 g_free(priv->current_error->description); | 1094 g_free(account->current_error); |
1117 g_free(priv->current_error); | 1095 } |
1118 } | |
1119 g_free(priv); | |
1120 | 1096 |
1121 PURPLE_DBUS_UNREGISTER_POINTER(account); | 1097 PURPLE_DBUS_UNREGISTER_POINTER(account); |
1122 g_free(account); | 1098 g_free(account); |
1123 } | 1099 } |
1124 | 1100 |
1138 | 1114 |
1139 purple_debug_info("account", "Registering account %s\n", | 1115 purple_debug_info("account", "Registering account %s\n", |
1140 purple_account_get_username(account)); | 1116 purple_account_get_username(account)); |
1141 | 1117 |
1142 _purple_connection_new(account, TRUE, purple_account_get_password(account)); | 1118 _purple_connection_new(account, TRUE, purple_account_get_password(account)); |
1119 } | |
1120 | |
1121 void | |
1122 purple_account_register_completed(PurpleAccount *account, gboolean succeeded) | |
1123 { | |
1124 g_return_if_fail(account != NULL); | |
1125 | |
1126 if (account->registration_cb) | |
1127 (account->registration_cb)(account, succeeded, account->registration_cb_user_data); | |
1143 } | 1128 } |
1144 | 1129 |
1145 void | 1130 void |
1146 purple_account_unregister(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data) | 1131 purple_account_unregister(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data) |
1147 { | 1132 { |
1285 if (!purple_account_get_remember_password(account)) | 1270 if (!purple_account_get_remember_password(account)) |
1286 purple_account_set_password(account, NULL); | 1271 purple_account_set_password(account, NULL); |
1287 purple_account_set_connection(account, NULL); | 1272 purple_account_set_connection(account, NULL); |
1288 | 1273 |
1289 account->disconnecting = FALSE; | 1274 account->disconnecting = FALSE; |
1275 } | |
1276 | |
1277 gboolean | |
1278 purple_account_is_disconnecting(const PurpleAccount *account) | |
1279 { | |
1280 g_return_val_if_fail(account != NULL, TRUE); | |
1281 | |
1282 return account->disconnecting; | |
1290 } | 1283 } |
1291 | 1284 |
1292 void | 1285 void |
1293 purple_account_notify_added(PurpleAccount *account, const char *remote_user, | 1286 purple_account_notify_added(PurpleAccount *account, const char *remote_user, |
1294 const char *id, const char *alias, | 1287 const char *id, const char *alias, |
1613 purple_account_get_username(account)); | 1606 purple_account_get_username(account)); |
1614 | 1607 |
1615 purple_request_input(gc, _("Set User Info"), primary, NULL, | 1608 purple_request_input(gc, _("Set User Info"), primary, NULL, |
1616 purple_account_get_user_info(account), | 1609 purple_account_get_user_info(account), |
1617 TRUE, FALSE, ((gc != NULL) && | 1610 TRUE, FALSE, ((gc != NULL) && |
1618 (gc->flags & PURPLE_CONNECTION_HTML) ? "html" : NULL), | 1611 (purple_connection_get_flags(gc) & PURPLE_CONNECTION_HTML) ? "html" : NULL), |
1619 _("Save"), G_CALLBACK(set_user_info_cb), | 1612 _("Save"), G_CALLBACK(set_user_info_cb), |
1620 _("Cancel"), NULL, | 1613 _("Cancel"), NULL, |
1621 account, NULL, NULL, | 1614 account, NULL, NULL, |
1622 account); | 1615 account); |
1623 } | 1616 } |
2493 g_return_val_if_fail(setting->type == PURPLE_PREF_BOOLEAN, default_value); | 2486 g_return_val_if_fail(setting->type == PURPLE_PREF_BOOLEAN, default_value); |
2494 | 2487 |
2495 return setting->value.boolean; | 2488 return setting->value.boolean; |
2496 } | 2489 } |
2497 | 2490 |
2491 gpointer | |
2492 purple_account_get_ui_data(const PurpleAccount *account) | |
2493 { | |
2494 g_return_val_if_fail(account != NULL, NULL); | |
2495 | |
2496 return account->ui_data; | |
2497 } | |
2498 | |
2499 void | |
2500 purple_account_set_ui_data(PurpleAccount *account, | |
2501 gpointer ui_data) | |
2502 { | |
2503 g_return_if_fail(account != NULL); | |
2504 | |
2505 account->ui_data = ui_data; | |
2506 } | |
2507 | |
2508 | |
2498 PurpleLog * | 2509 PurpleLog * |
2499 purple_account_get_log(PurpleAccount *account, gboolean create) | 2510 purple_account_get_log(PurpleAccount *account, gboolean create) |
2500 { | 2511 { |
2501 g_return_val_if_fail(account != NULL, NULL); | 2512 g_return_val_if_fail(account != NULL, NULL); |
2502 | 2513 |
2525 account->system_log = NULL; | 2536 account->system_log = NULL; |
2526 } | 2537 } |
2527 } | 2538 } |
2528 | 2539 |
2529 void | 2540 void |
2530 purple_account_add_buddy(PurpleAccount *account, PurpleBuddy *buddy) | 2541 purple_account_add_buddy(PurpleAccount *account, PurpleBuddy *buddy, const char *message) |
2531 { | 2542 { |
2532 PurplePluginProtocolInfo *prpl_info = NULL; | 2543 PurplePluginProtocolInfo *prpl_info = NULL; |
2533 PurpleConnection *gc; | 2544 PurpleConnection *gc; |
2534 PurplePlugin *prpl = NULL; | 2545 PurplePlugin *prpl = NULL; |
2535 | 2546 |
2542 | 2553 |
2543 if (prpl != NULL) | 2554 if (prpl != NULL) |
2544 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | 2555 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
2545 | 2556 |
2546 if (prpl_info != NULL) { | 2557 if (prpl_info != NULL) { |
2547 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy_with_invite)) | 2558 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy)) |
2548 prpl_info->add_buddy_with_invite(gc, buddy, purple_buddy_get_group(buddy), NULL); | 2559 prpl_info->add_buddy(gc, buddy, purple_buddy_get_group(buddy), message); |
2549 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy)) | 2560 } |
2550 prpl_info->add_buddy(gc, buddy, purple_buddy_get_group(buddy)); | 2561 } |
2551 } | 2562 |
2552 } | 2563 void |
2553 | 2564 purple_account_add_buddies(PurpleAccount *account, GList *buddies, const char *message) |
2554 void | |
2555 purple_account_add_buddy_with_invite(PurpleAccount *account, PurpleBuddy *buddy, const char *message) | |
2556 { | |
2557 PurplePluginProtocolInfo *prpl_info = NULL; | |
2558 PurpleConnection *gc; | |
2559 PurplePlugin *prpl = NULL; | |
2560 | |
2561 g_return_if_fail(account != NULL); | |
2562 g_return_if_fail(buddy != NULL); | |
2563 | |
2564 gc = purple_account_get_connection(account); | |
2565 if (gc != NULL) | |
2566 prpl = purple_connection_get_prpl(gc); | |
2567 | |
2568 if (prpl != NULL) | |
2569 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
2570 | |
2571 if (prpl_info != NULL) { | |
2572 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy_with_invite)) | |
2573 prpl_info->add_buddy_with_invite(gc, buddy, purple_buddy_get_group(buddy), message); | |
2574 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy)) | |
2575 prpl_info->add_buddy(gc, buddy, purple_buddy_get_group(buddy)); | |
2576 } | |
2577 } | |
2578 | |
2579 void | |
2580 purple_account_add_buddies(PurpleAccount *account, GList *buddies) | |
2581 { | 2565 { |
2582 PurplePluginProtocolInfo *prpl_info = NULL; | 2566 PurplePluginProtocolInfo *prpl_info = NULL; |
2583 PurpleConnection *gc = purple_account_get_connection(account); | 2567 PurpleConnection *gc = purple_account_get_connection(account); |
2584 PurplePlugin *prpl = NULL; | 2568 PurplePlugin *prpl = NULL; |
2585 | 2569 |
2596 for (cur = buddies; cur != NULL; cur = cur->next) { | 2580 for (cur = buddies; cur != NULL; cur = cur->next) { |
2597 PurpleBuddy *buddy = cur->data; | 2581 PurpleBuddy *buddy = cur->data; |
2598 groups = g_list_append(groups, purple_buddy_get_group(buddy)); | 2582 groups = g_list_append(groups, purple_buddy_get_group(buddy)); |
2599 } | 2583 } |
2600 | 2584 |
2601 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddies_with_invite)) | 2585 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddies)) |
2602 prpl_info->add_buddies_with_invite(gc, buddies, groups, NULL); | 2586 prpl_info->add_buddies(gc, buddies, groups, message); |
2603 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddies)) | |
2604 prpl_info->add_buddies(gc, buddies, groups); | |
2605 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy_with_invite)) { | |
2606 GList *curb = buddies, *curg = groups; | |
2607 | |
2608 while ((curb != NULL) && (curg != NULL)) { | |
2609 prpl_info->add_buddy_with_invite(gc, curb->data, curg->data, NULL); | |
2610 curb = curb->next; | |
2611 curg = curg->next; | |
2612 } | |
2613 } | |
2614 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy)) { | 2587 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy)) { |
2615 GList *curb = buddies, *curg = groups; | 2588 GList *curb = buddies, *curg = groups; |
2616 | 2589 |
2617 while ((curb != NULL) && (curg != NULL)) { | 2590 while ((curb != NULL) && (curg != NULL)) { |
2618 prpl_info->add_buddy(gc, curb->data, curg->data); | 2591 prpl_info->add_buddy(gc, curb->data, curg->data, message); |
2619 curb = curb->next; | |
2620 curg = curg->next; | |
2621 } | |
2622 } | |
2623 | |
2624 g_list_free(groups); | |
2625 } | |
2626 } | |
2627 | |
2628 void | |
2629 purple_account_add_buddies_with_invite(PurpleAccount *account, GList *buddies, const char *message) | |
2630 { | |
2631 PurplePluginProtocolInfo *prpl_info = NULL; | |
2632 PurpleConnection *gc = purple_account_get_connection(account); | |
2633 PurplePlugin *prpl = NULL; | |
2634 | |
2635 if (gc != NULL) | |
2636 prpl = purple_connection_get_prpl(gc); | |
2637 | |
2638 if (prpl != NULL) | |
2639 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
2640 | |
2641 if (prpl_info) { | |
2642 GList *cur, *groups = NULL; | |
2643 | |
2644 /* Make a list of what group each buddy is in */ | |
2645 for (cur = buddies; cur != NULL; cur = cur->next) { | |
2646 PurpleBuddy *buddy = cur->data; | |
2647 groups = g_list_append(groups, purple_buddy_get_group(buddy)); | |
2648 } | |
2649 | |
2650 if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddies_with_invite)) | |
2651 prpl_info->add_buddies_with_invite(gc, buddies, groups, message); | |
2652 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy_with_invite)) { | |
2653 GList *curb = buddies, *curg = groups; | |
2654 | |
2655 while ((curb != NULL) && (curg != NULL)) { | |
2656 prpl_info->add_buddy_with_invite(gc, curb->data, curg->data, message); | |
2657 curb = curb->next; | |
2658 curg = curg->next; | |
2659 } | |
2660 } | |
2661 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddies)) | |
2662 prpl_info->add_buddies(gc, buddies, groups); | |
2663 else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, add_buddy)) { | |
2664 GList *curb = buddies, *curg = groups; | |
2665 | |
2666 while ((curb != NULL) && (curg != NULL)) { | |
2667 prpl_info->add_buddy(gc, curb->data, curg->data); | |
2668 curb = curb->next; | 2592 curb = curb->next; |
2669 curg = curg->next; | 2593 curg = curg->next; |
2670 } | 2594 } |
2671 } | 2595 } |
2672 | 2596 |
2802 } | 2726 } |
2803 | 2727 |
2804 static void | 2728 static void |
2805 set_current_error(PurpleAccount *account, PurpleConnectionErrorInfo *new_err) | 2729 set_current_error(PurpleAccount *account, PurpleConnectionErrorInfo *new_err) |
2806 { | 2730 { |
2807 PurpleAccountPrivate *priv; | |
2808 PurpleConnectionErrorInfo *old_err; | 2731 PurpleConnectionErrorInfo *old_err; |
2809 | 2732 |
2810 g_return_if_fail(account != NULL); | 2733 g_return_if_fail(account != NULL); |
2811 | 2734 |
2812 priv = PURPLE_ACCOUNT_GET_PRIVATE(account); | 2735 old_err = account->current_error; |
2813 old_err = priv->current_error; | |
2814 | 2736 |
2815 if(new_err == old_err) | 2737 if(new_err == old_err) |
2816 return; | 2738 return; |
2817 | 2739 |
2818 priv->current_error = new_err; | 2740 account->current_error = new_err; |
2819 | 2741 |
2820 purple_signal_emit(purple_accounts_get_handle(), | 2742 purple_signal_emit(purple_accounts_get_handle(), |
2821 "account-error-changed", | 2743 "account-error-changed", |
2822 account, old_err, new_err); | 2744 account, old_err, new_err); |
2823 schedule_accounts_save(); | 2745 schedule_accounts_save(); |
2855 } | 2777 } |
2856 | 2778 |
2857 const PurpleConnectionErrorInfo * | 2779 const PurpleConnectionErrorInfo * |
2858 purple_account_get_current_error(PurpleAccount *account) | 2780 purple_account_get_current_error(PurpleAccount *account) |
2859 { | 2781 { |
2860 PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account); | 2782 return account->current_error; |
2861 return priv->current_error; | |
2862 } | 2783 } |
2863 | 2784 |
2864 void | 2785 void |
2865 purple_account_clear_current_error(PurpleAccount *account) | 2786 purple_account_clear_current_error(PurpleAccount *account) |
2866 { | 2787 { |