* Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #include "internal.h" /* TODO: this needs to die */ typedef struct _PurpleContactPrivate PurpleContactPrivate; struct _PurpleContactPrivate { char *alias; /* The user-set alias of the contact */ PurpleBuddy *priority_buddy; /* The "top" buddy for this contact */ gboolean priority_valid; /* Is priority valid? */ /****************************************************************************** *****************************************************************************/ static GParamSpec *properties[PROP_LAST]; G_DEFINE_TYPE_WITH_PRIVATE(PurpleContact, purple_contact, PURPLE_TYPE_COUNTING_NODE); /****************************************************************************** *****************************************************************************/ purple_contact_compute_priority_buddy(PurpleContact *contact) { PurpleBuddy *new_priority = NULL; PurpleContactPrivate *priv = purple_contact_get_instance_private(contact); priv->priority_buddy = NULL; for (bnode = PURPLE_BLIST_NODE(contact)->child; if (!PURPLE_IS_BUDDY(bnode)) buddy = PURPLE_BUDDY(bnode); if (new_priority == NULL) if (purple_account_is_connected(purple_buddy_get_account(buddy))) if (purple_account_is_connected(purple_buddy_get_account(new_priority))) cmp = purple_buddy_presence_compare( PURPLE_BUDDY_PRESENCE(purple_buddy_get_presence(new_priority)), PURPLE_BUDDY_PRESENCE(purple_buddy_get_presence(buddy))); if (cmp > 0 || (cmp == 0 && purple_prefs_get_bool("/purple/contact/last_match"))) priv->priority_buddy = new_priority; priv->priority_valid = TRUE; g_object_notify_by_pspec(G_OBJECT(contact), properties[PROP_PRIORITY_BUDDY]); purple_contact_get_group(const PurpleContact *contact) g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL); return PURPLE_GROUP(PURPLE_BLIST_NODE(contact)->parent); purple_contact_set_alias(PurpleContact *contact, const char *alias) PurpleContactPrivate *priv = NULL; PurpleIMConversation *im; g_return_if_fail(PURPLE_IS_CONTACT(contact)); priv = purple_contact_get_instance_private(contact); if ((alias != NULL) && (*alias != '\0')) new_alias = purple_utf8_strip_unprintables(alias); if (!purple_strequal(priv->alias, new_alias)) { if ((new_alias != NULL) && (*new_alias != '\0')) g_free(new_alias); /* could be "\0" */ g_object_notify_by_pspec(G_OBJECT(contact), purple_blist_save_node(purple_blist_get_default(), PURPLE_BLIST_NODE(contact)); purple_blist_update_node(purple_blist_get_default(), PURPLE_BLIST_NODE(contact)); for(bnode = PURPLE_BLIST_NODE(contact)->child; bnode != NULL; bnode = bnode->next) PurpleBuddy *buddy = PURPLE_BUDDY(bnode); im = purple_conversations_find_im_with_account(purple_buddy_get_name(buddy), purple_buddy_get_account(buddy)); purple_conversation_autoset_title(PURPLE_CONVERSATION(im)); purple_signal_emit(purple_blist_get_handle(), "blist-node-aliased", const char *purple_contact_get_alias(PurpleContact* contact) PurpleContactPrivate *priv = NULL; g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL); priv = purple_contact_get_instance_private(contact); return purple_buddy_get_alias(purple_contact_get_priority_buddy(contact)); gboolean purple_contact_on_account(PurpleContact *c, PurpleAccount *account) PurpleBlistNode *bnode, *cnode = (PurpleBlistNode *) c; g_return_val_if_fail(PURPLE_IS_CONTACT(c), FALSE); g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), FALSE); for (bnode = cnode->child; bnode; bnode = bnode->next) { if (! PURPLE_IS_BUDDY(bnode)) buddy = (PurpleBuddy *)bnode; if (purple_buddy_get_account(buddy) == account) void purple_contact_invalidate_priority_buddy(PurpleContact *contact) PurpleContactPrivate *priv = NULL; g_return_if_fail(PURPLE_IS_CONTACT(contact)); priv = purple_contact_get_instance_private(contact); priv->priority_valid = FALSE; PurpleBuddy *purple_contact_get_priority_buddy(PurpleContact *contact) PurpleContactPrivate *priv = NULL; g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL); priv = purple_contact_get_instance_private(contact); if (!priv->priority_valid) purple_contact_compute_priority_buddy(contact); return priv->priority_buddy; void purple_contact_merge(PurpleContact *source, PurpleBlistNode *node) PurpleBlistNode *sourcenode = (PurpleBlistNode*)source; PurpleBlistNode *prev, *cur, *next; g_return_if_fail(PURPLE_IS_CONTACT(source)); g_return_if_fail(PURPLE_IS_BLIST_NODE(node)); if (PURPLE_IS_CONTACT(node)) { target = (PurpleContact *)node; prev = _purple_blist_get_last_child(node); } else if (PURPLE_IS_BUDDY(node)) { target = (PurpleContact *)node->parent; if (source == target || !target) next = sourcenode->child; if (PURPLE_IS_BUDDY(cur)) { purple_blist_add_buddy((PurpleBuddy *)cur, target, NULL, prev); /************************************************************************** **************************************************************************/ /* Set method for GObject properties */ purple_contact_set_property(GObject *obj, guint param_id, const GValue *value, PurpleContact *contact = PURPLE_CONTACT(obj); purple_contact_set_alias(contact, g_value_get_string(value)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); /* Get method for GObject properties */ purple_contact_get_property(GObject *obj, guint param_id, GValue *value, PurpleContact *contact = PURPLE_CONTACT(obj); PurpleContactPrivate *priv = purple_contact_get_instance_private(contact); g_value_set_string(value, priv->alias); case PROP_PRIORITY_BUDDY: g_value_set_object(value, purple_contact_get_priority_buddy(contact)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); /* GObject initialization function */ purple_contact_init(PurpleContact *contact) purple_blist_new_node(purple_blist_get_default(), PURPLE_BLIST_NODE(contact)); /* GObject finalize function */ purple_contact_finalize(GObject *object) PurpleContactPrivate *priv = purple_contact_get_instance_private( G_OBJECT_CLASS(purple_contact_parent_class)->finalize(object); /* Class initializer function */ static void purple_contact_class_init(PurpleContactClass *klass) GObjectClass *obj_class = G_OBJECT_CLASS(klass); obj_class->finalize = purple_contact_finalize; obj_class->get_property = purple_contact_get_property; obj_class->set_property = purple_contact_set_property; properties[PROP_ALIAS] = g_param_spec_string( "The alias for the contact.", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS properties[PROP_PRIORITY_BUDDY] = g_param_spec_object( "The priority buddy of the contact.", G_PARAM_READABLE | G_PARAM_STATIC_STRINGS g_object_class_install_properties(obj_class, PROP_LAST, properties); return g_object_new(PURPLE_TYPE_CONTACT, NULL);