* 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 typedef struct _PurpleChatPrivate PurpleChatPrivate; /* Private data for a chat node */ struct _PurpleChatPrivate { char *alias; /* The display name of this chat. */ PurpleAccount *account; /* The account this chat is attached to */ GHashTable *components; /* the stuff the protocol needs to know to gboolean is_constructed; /* Indicates if the chat has finished being /* Chat property enums */ /****************************************************************************** *****************************************************************************/ static GParamSpec *properties[PROP_LAST]; G_DEFINE_TYPE_WITH_PRIVATE(PurpleChat, purple_chat, PURPLE_TYPE_BLIST_NODE); /****************************************************************************** *****************************************************************************/ const char *purple_chat_get_name(PurpleChat *chat) PurpleChatPrivate *priv = NULL; g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL); priv = purple_chat_get_instance_private(chat); if ((priv->alias != NULL) && (*priv->alias != '\0')) return purple_chat_get_name_only(chat); const char *purple_chat_get_name_only(PurpleChat *chat) PurpleChatPrivate *priv = NULL; PurpleProtocol *protocol = NULL; g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL); priv = purple_chat_get_instance_private(chat); protocol = purple_protocols_find(purple_account_get_protocol_id(priv->account)); if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, CHAT, info)) { PurpleProtocolChatEntry *pce; GList *parts = purple_protocol_chat_iface_info(protocol, purple_account_get_connection(priv->account)); ret = g_hash_table_lookup(priv->components, pce->identifier); g_list_free_full(parts, g_free); purple_chat_set_alias(PurpleChat *chat, const char *alias) PurpleChatPrivate *priv = NULL; g_return_if_fail(PURPLE_IS_CHAT(chat)); priv = purple_chat_get_instance_private(chat); 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(chat), properties[PROP_ALIAS]); purple_blist_save_node(purple_blist_get_default(), PURPLE_BLIST_NODE(chat)); purple_blist_update_node(purple_blist_get_default(), PURPLE_BLIST_NODE(chat)); purple_signal_emit(purple_blist_get_handle(), "blist-node-aliased", purple_chat_get_group(PurpleChat *chat) g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL); return PURPLE_GROUP(PURPLE_BLIST_NODE(chat)->parent); purple_chat_get_account(PurpleChat *chat) PurpleChatPrivate *priv = NULL; g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL); priv = purple_chat_get_instance_private(chat); purple_chat_get_components(PurpleChat *chat) PurpleChatPrivate *priv = NULL; g_return_val_if_fail(PURPLE_IS_CHAT(chat), NULL); priv = purple_chat_get_instance_private(chat); /****************************************************************************** *****************************************************************************/ purple_chat_set_property(GObject *obj, guint param_id, const GValue *value, PurpleChat *chat = PURPLE_CHAT(obj); PurpleChatPrivate *priv = purple_chat_get_instance_private(chat); if (priv->is_constructed) purple_chat_set_alias(chat, g_value_get_string(value)); purple_utf8_strip_unprintables(g_value_get_string(value)); priv->account = g_value_get_object(value); priv->components = g_value_get_pointer(value); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); purple_chat_get_property(GObject *obj, guint param_id, GValue *value, PurpleChat *chat = PURPLE_CHAT(obj); PurpleChatPrivate *priv = purple_chat_get_instance_private(chat); g_value_set_string(value, priv->alias); g_value_set_object(value, purple_chat_get_account(chat)); g_value_set_pointer(value, purple_chat_get_components(chat)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); /* GObject initialization function */ purple_chat_init(PurpleChat *chat) /* Called when done constructing */ purple_chat_constructed(GObject *object) PurpleChat *chat = PURPLE_CHAT(object); PurpleChatPrivate *priv = purple_chat_get_instance_private(chat); G_OBJECT_CLASS(purple_chat_parent_class)->constructed(object); purple_blist_new_node(purple_blist_get_default(), PURPLE_BLIST_NODE(chat)); priv->is_constructed = TRUE; /* GObject finalize function */ purple_chat_finalize(GObject *object) PurpleChatPrivate *priv = purple_chat_get_instance_private(PURPLE_CHAT(object)); g_hash_table_destroy(priv->components); G_OBJECT_CLASS(purple_chat_parent_class)->finalize(object); /* Class initializer function */ static void purple_chat_class_init(PurpleChatClass *klass) GObjectClass *obj_class = G_OBJECT_CLASS(klass); obj_class->finalize = purple_chat_finalize; obj_class->get_property = purple_chat_get_property; obj_class->set_property = purple_chat_set_property; obj_class->constructed = purple_chat_constructed; properties[PROP_ALIAS] = g_param_spec_string( "The alias for the chat.", G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS properties[PROP_ACCOUNT] = g_param_spec_object( "The account that the chat belongs to.", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS properties[PROP_COMPONENTS] = g_param_spec_pointer( "The protocol components of the chat.", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS g_object_class_install_properties(obj_class, PROP_LAST, properties); purple_chat_new(PurpleAccount *account, const char *alias, GHashTable *components) g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); g_return_val_if_fail(components != NULL, NULL); return g_object_new(PURPLE_TYPE_CHAT, "components", components,