annotate libpurple/protocols/oscar/visibility.c @ 30807:48fe4720d795

Removed callback data that was causing a segfault in Finch, because Finch overwrites it with its own data.
author ivan.komarov@soc.pidgin.im
date Wed, 30 Jun 2010 15:57:43 +0000
parents 4e804413b12b
children ab7e28b1b478
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
1 /*
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
2 * Purple's oscar protocol plugin
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
3 * This file is the legal property of its developers.
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
5 *
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
10 *
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
14 * Lesser General Public License for more details.
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
15 *
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
19 */
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
20
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
21 #include "visibility.h"
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
22
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
23 static guint16
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
24 get_buddy_list_type(OscarData *od, const char *bname)
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
25 {
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
26 PurpleAccount *account = purple_connection_get_account(od->gc);
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
27 return purple_account_is_status_active(account, OSCAR_STATUS_ID_INVISIBLE) ? AIM_SSI_TYPE_PERMIT : AIM_SSI_TYPE_DENY;
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
28 }
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
29
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
30 static gboolean
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
31 is_buddy_on_list(OscarData *od, const char *bname)
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
32 {
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
33 return aim_ssi_itemlist_finditem(od->ssi.local, NULL, bname, get_buddy_list_type(od, bname)) != NULL;
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
34 }
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
35
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
36 static void
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
37 visibility_cb(PurpleBlistNode *node, gpointer whatever)
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
38 {
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
39 PurpleBuddy *buddy = PURPLE_BUDDY(node);
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
40 const char* bname = purple_buddy_get_name(buddy);
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
41 OscarData *od = purple_connection_get_protocol_data(purple_account_get_connection(purple_buddy_get_account(buddy)));
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
42 guint16 list_type = get_buddy_list_type(od, bname);
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
43
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
44 if (!is_buddy_on_list(od, bname)) {
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
45 aim_ssi_add_to_private_list(od, bname, list_type);
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
46 } else {
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
47 aim_ssi_del_from_private_list(od, bname, list_type);
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
48 }
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
49 }
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
50
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
51 PurpleMenuAction *
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
52 create_visibility_menu_item(OscarData *od, const char *bname)
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
53 {
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
54 PurpleAccount *account = purple_connection_get_account(od->gc);
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
55 gboolean invisible = purple_account_is_status_active(account, OSCAR_STATUS_ID_INVISIBLE);
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
56 gboolean on_list = is_buddy_on_list(od, bname);
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
57 gchar *label;
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
58 PurpleMenuAction *result;
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
59
30807
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
60 label = g_strdup_printf("%s %s", on_list ? "Don't Appear" : "Appear", invisible ? "Online" : "Offline");
48fe4720d795 Removed callback data that was causing a segfault in Finch, because
ivan.komarov@soc.pidgin.im
parents: 30806
diff changeset
61 result = purple_menu_action_new(label, PURPLE_CALLBACK(visibility_cb), NULL, NULL);
30805
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
62 g_free(label);
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
63 return result;
5bfef3338383 Added a way to add a user to the (In)Visible list via the context menu.
ivan.komarov@soc.pidgin.im
parents:
diff changeset
64 }
30806
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
65
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
66 static void
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
67 show_private_list(PurplePluginAction *action, guint16 list_type, const gchar *list_description, const gchar *menu_action_name)
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
68 {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
69 PurpleConnection *gc = (PurpleConnection *) action->context;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
70 OscarData *od = purple_connection_get_protocol_data(gc);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
71 PurpleAccount *account = purple_connection_get_account(gc);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
72 GSList *buddies, *filtered_buddies, *cur;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
73 gchar *text, *secondary;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
74
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
75 buddies = purple_find_buddies(account, NULL);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
76 filtered_buddies = NULL;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
77 for (cur = buddies; cur != NULL; cur = cur->next) {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
78 PurpleBuddy *buddy;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
79 const gchar *bname;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
80
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
81 buddy = cur->data;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
82 bname = purple_buddy_get_name(buddy);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
83 if (aim_ssi_itemlist_finditem(od->ssi.local, NULL, bname, list_type)) {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
84 filtered_buddies = g_slist_prepend(filtered_buddies, buddy);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
85 }
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
86 }
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
87
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
88 g_slist_free(buddies);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
89
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
90 filtered_buddies = g_slist_reverse(filtered_buddies);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
91 text = oscar_format_buddies(filtered_buddies, "you have no buddies on this list");
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
92 g_slist_free(filtered_buddies);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
93
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
94 secondary = g_strdup_printf("You can add a buddy to this list "
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
95 "by right-clicking on them and "
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
96 "selecting \"%s\"", menu_action_name);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
97 purple_notify_formatted(gc, NULL, list_description, secondary, text, NULL, NULL);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
98 g_free(secondary);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
99 g_free(text);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
100 }
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
101
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
102 void
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
103 oscar_show_visible_list(PurplePluginAction *action)
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
104 {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
105 show_private_list(action, AIM_SSI_TYPE_PERMIT, "These buddies will always see "
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
106 "your status, even when you switch "
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
107 "to \"Invisible\"", "Appear Online");
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
108 }
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
109
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
110 void
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
111 oscar_show_invisible_list(PurplePluginAction *action)
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
112 {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
113 show_private_list(action, AIM_SSI_TYPE_DENY, "These buddies will always see you as offline", "Appear Offline");
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30805
diff changeset
114 }