Annotation of ChivanetAimPidgin/oscarprpl/src/c/visibility.c, revision 1.1
1.1 ! snw 1: /*
! 2: * Purple's oscar protocol plugin
! 3: * This file is the legal property of its developers.
! 4: * Please see the AUTHORS file distributed alongside this file.
! 5: *
! 6: * This library is free software; you can redistribute it and/or
! 7: * modify it under the terms of the GNU Lesser General Public
! 8: * License as published by the Free Software Foundation; either
! 9: * version 2 of the License, or (at your option) any later version.
! 10: *
! 11: * This library is distributed in the hope that it will be useful,
! 12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
! 13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! 14: * Lesser General Public License for more details.
! 15: *
! 16: * You should have received a copy of the GNU Lesser General Public
! 17: * License along with this library; if not, write to the Free Software
! 18: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
! 19: */
! 20:
! 21: #include "visibility.h"
! 22:
! 23: /* Translators: This string is a menu option that, if selected, will cause
! 24: you to appear online to the chosen user even when your status is set to
! 25: Invisible. */
! 26: #define APPEAR_ONLINE N_("Appear Online")
! 27:
! 28: /* Translators: This string is a menu option that, if selected, will cause
! 29: you to appear offline to the chosen user when your status is set to
! 30: Invisible (this is the default). */
! 31: #define DONT_APPEAR_ONLINE N_("Don't Appear Online")
! 32:
! 33: /* Translators: This string is a menu option that, if selected, will cause
! 34: you to always appear offline to the chosen user (even when your status
! 35: isn't Invisible). */
! 36: #define APPEAR_OFFLINE N_("Appear Offline")
! 37:
! 38: /* Translators: This string is a menu option that, if selected, will cause
! 39: you to appear offline to the chosen user if you are invisible, and
! 40: appear online to the chosen user if you are not invisible (this is the
! 41: default). */
! 42: #define DONT_APPEAR_OFFLINE N_("Don't Appear Offline")
! 43:
! 44: static guint16
! 45: get_buddy_list_type(OscarData *od)
! 46: {
! 47: PurpleAccount *account = purple_connection_get_account(od->gc);
! 48: return purple_account_is_status_active(account, OSCAR_STATUS_ID_INVISIBLE) ? AIM_SSI_TYPE_PERMIT : AIM_SSI_TYPE_DENY;
! 49: }
! 50:
! 51: static gboolean
! 52: is_buddy_on_list(OscarData *od, const char *bname)
! 53: {
! 54: return aim_ssi_itemlist_finditem(od->ssi.local, NULL, bname, get_buddy_list_type(od)) != NULL;
! 55: }
! 56:
! 57: static void
! 58: visibility_cb(PurpleBlistNode *node, gpointer whatever)
! 59: {
! 60: PurpleBuddy *buddy = PURPLE_BUDDY(node);
! 61: const char* bname = purple_buddy_get_name(buddy);
! 62: OscarData *od = purple_connection_get_protocol_data(purple_account_get_connection(purple_buddy_get_account(buddy)));
! 63: guint16 list_type = get_buddy_list_type(od);
! 64:
! 65: if (!is_buddy_on_list(od, bname)) {
! 66: aim_ssi_add_to_private_list(od, bname, list_type);
! 67: } else {
! 68: aim_ssi_del_from_private_list(od, bname, list_type);
! 69: }
! 70: }
! 71:
! 72: PurpleMenuAction *
! 73: create_visibility_menu_item(OscarData *od, const char *bname)
! 74: {
! 75: PurpleAccount *account = purple_connection_get_account(od->gc);
! 76: gboolean invisible = purple_account_is_status_active(account, OSCAR_STATUS_ID_INVISIBLE);
! 77: gboolean on_list = is_buddy_on_list(od, bname);
! 78: const gchar *label;
! 79:
! 80: if (invisible) {
! 81: label = on_list ? _(DONT_APPEAR_ONLINE) : _(APPEAR_ONLINE);
! 82: } else {
! 83: label = on_list ? _(DONT_APPEAR_OFFLINE) : _(APPEAR_OFFLINE);
! 84: }
! 85: return purple_menu_action_new(label, PURPLE_CALLBACK(visibility_cb), NULL, NULL);
! 86: }
! 87:
! 88: static void
! 89: show_private_list(PurplePluginAction *action, guint16 list_type, const gchar *title, const gchar *list_description, const gchar *menu_action_name)
! 90: {
! 91: PurpleConnection *gc = (PurpleConnection *) action->context;
! 92: OscarData *od = purple_connection_get_protocol_data(gc);
! 93: PurpleAccount *account = purple_connection_get_account(gc);
! 94: GSList *buddies, *filtered_buddies, *cur;
! 95: gchar *text, *secondary;
! 96:
! 97: buddies = purple_find_buddies(account, NULL);
! 98: filtered_buddies = NULL;
! 99: for (cur = buddies; cur != NULL; cur = cur->next) {
! 100: PurpleBuddy *buddy;
! 101: const gchar *bname;
! 102:
! 103: buddy = cur->data;
! 104: bname = purple_buddy_get_name(buddy);
! 105: if (aim_ssi_itemlist_finditem(od->ssi.local, NULL, bname, list_type)) {
! 106: filtered_buddies = g_slist_prepend(filtered_buddies, buddy);
! 107: }
! 108: }
! 109:
! 110: g_slist_free(buddies);
! 111:
! 112: filtered_buddies = g_slist_reverse(filtered_buddies);
! 113: text = oscar_format_buddies(filtered_buddies, _("you have no buddies on this list"));
! 114: g_slist_free(filtered_buddies);
! 115:
! 116: secondary = g_strdup_printf(_("You can add a buddy to this list "
! 117: "by right-clicking on them and "
! 118: "selecting \"%s\""), menu_action_name);
! 119: purple_notify_formatted(gc, title, list_description, secondary, text, NULL, NULL);
! 120: g_free(secondary);
! 121: g_free(text);
! 122: }
! 123:
! 124: void
! 125: oscar_show_visible_list(PurplePluginAction *action)
! 126: {
! 127: show_private_list(action, AIM_SSI_TYPE_PERMIT, _("Visible List"),
! 128: _("These buddies will see "
! 129: "your status when you switch "
! 130: "to \"Invisible\""),
! 131: _(APPEAR_ONLINE));
! 132: }
! 133:
! 134: void
! 135: oscar_show_invisible_list(PurplePluginAction *action)
! 136: {
! 137: show_private_list(action, AIM_SSI_TYPE_DENY, _("Invisible List"),
! 138: _("These buddies will always see you as offline"),
! 139: _(APPEAR_OFFLINE));
! 140: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>