libpurple/protocols/oscar/visibility.c

Mon, 28 Jun 2010 20:02:12 +0000

author
Ivan Komarov <ivan.komarov@pidgin.im>
date
Mon, 28 Jun 2010 20:02:12 +0000
branch
soc.2010.icq-tlc
changeset 30649
d96a69a9154e
child 30650
1e60e49674dd
permissions
-rw-r--r--

Added a way to add a user to the (In)Visible list via the context menu.

30649
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
1 /*
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
2 * Purple's oscar protocol plugin
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
3 * This file is the legal property of its developers.
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
5 *
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
10 *
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
14 * Lesser General Public License for more details.
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
15 *
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
19 */
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
20
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
21 #include "visibility.h"
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
22
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
23 struct visibility_cb_data
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
24 {
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
25 guint16 list_type;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
26 gboolean add_to_list;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
27 };
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
28
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
29 static void
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
30 visibility_cb(PurpleBlistNode *node, struct visibility_cb_data *data)
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
31 {
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
32 PurpleBuddy *buddy = PURPLE_BUDDY(node);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
33 const char* bname = purple_buddy_get_name(buddy);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
34 OscarData *od = purple_account_get_connection(purple_buddy_get_account(buddy))->proto_data;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
35
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
36 if (data->add_to_list) {
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
37 aim_ssi_add_to_private_list(od, bname, data->list_type);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
38 } else {
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
39 aim_ssi_del_from_private_list(od, bname, data->list_type);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
40 }
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
41
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
42 g_free(data);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
43 }
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
44
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
45 PurpleMenuAction *
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
46 create_visibility_menu_item(OscarData *od, const char *bname)
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
47 {
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
48 PurpleAccount *account = purple_connection_get_account(od->gc);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
49 gboolean invisible = purple_account_is_status_active(account, OSCAR_STATUS_ID_INVISIBLE);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
50 guint16 list_type = invisible ? AIM_SSI_TYPE_PERMIT : AIM_SSI_TYPE_DENY;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
51 gboolean on_list = aim_ssi_itemlist_finditem(od->ssi.local, NULL, bname, list_type) != NULL;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
52 gchar *label;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
53 struct visibility_cb_data *data;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
54 PurpleMenuAction *result;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
55
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
56 data = g_new0(struct visibility_cb_data, 1);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
57 data->list_type = list_type;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
58 data->add_to_list = !on_list;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
59
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
60 label = g_strdup_printf("%s %s", on_list ? "Don't appear" : "Appear", invisible ? "online" : "offline");
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
61 result = purple_menu_action_new(label, PURPLE_CALLBACK(visibility_cb), data, NULL);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
62 g_free(label);
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
63 return result;
d96a69a9154e Added a way to add a user to the (In)Visible list via the context menu.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
diff changeset
64 }

mercurial