4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 typedef struct _PurpleChatPrivate PurpleChatPrivate
;
29 /* Private data for a chat node */
30 struct _PurpleChatPrivate
{
31 char *alias
; /* The display name of this chat. */
32 PurpleAccount
*account
; /* The account this chat is attached to */
33 GHashTable
*components
; /* the stuff the protocol needs to know to
36 gboolean is_constructed
; /* Indicates if the chat has finished being
40 /* Chat property enums */
50 /******************************************************************************
52 *****************************************************************************/
53 static GParamSpec
*properties
[PROP_LAST
];
55 G_DEFINE_TYPE_WITH_PRIVATE(PurpleChat
, purple_chat
, PURPLE_TYPE_BLIST_NODE
);
57 /******************************************************************************
59 *****************************************************************************/
61 const char *purple_chat_get_name(PurpleChat
*chat
)
63 PurpleChatPrivate
*priv
= NULL
;
65 g_return_val_if_fail(PURPLE_IS_CHAT(chat
), NULL
);
67 priv
= purple_chat_get_instance_private(chat
);
69 if ((priv
->alias
!= NULL
) && (*priv
->alias
!= '\0'))
72 return purple_chat_get_name_only(chat
);
75 const char *purple_chat_get_name_only(PurpleChat
*chat
)
77 PurpleChatPrivate
*priv
= NULL
;
79 PurpleProtocol
*protocol
= NULL
;
81 g_return_val_if_fail(PURPLE_IS_CHAT(chat
), NULL
);
83 priv
= purple_chat_get_instance_private(chat
);
85 protocol
= purple_protocols_find(purple_account_get_protocol_id(priv
->account
));
87 if (PURPLE_PROTOCOL_IMPLEMENTS(protocol
, CHAT
, info
)) {
88 PurpleProtocolChatEntry
*pce
;
89 GList
*parts
= purple_protocol_chat_iface_info(protocol
, purple_account_get_connection(priv
->account
));
91 ret
= g_hash_table_lookup(priv
->components
, pce
->identifier
);
92 g_list_free_full(parts
, g_free
);
99 purple_chat_set_alias(PurpleChat
*chat
, const char *alias
)
101 PurpleChatPrivate
*priv
= NULL
;
103 char *new_alias
= NULL
;
105 g_return_if_fail(PURPLE_IS_CHAT(chat
));
107 priv
= purple_chat_get_instance_private(chat
);
109 if ((alias
!= NULL
) && (*alias
!= '\0'))
110 new_alias
= purple_utf8_strip_unprintables(alias
);
112 if (!purple_strequal(priv
->alias
, new_alias
)) {
117 old_alias
= priv
->alias
;
119 if ((new_alias
!= NULL
) && (*new_alias
!= '\0'))
120 priv
->alias
= new_alias
;
123 g_free(new_alias
); /* could be "\0" */
126 g_object_notify_by_pspec(G_OBJECT(chat
), properties
[PROP_ALIAS
]);
128 purple_blist_save_node(purple_blist_get_default(),
129 PURPLE_BLIST_NODE(chat
));
130 purple_blist_update_node(purple_blist_get_default(),
131 PURPLE_BLIST_NODE(chat
));
133 purple_signal_emit(purple_blist_get_handle(), "blist-node-aliased",
139 purple_chat_get_group(PurpleChat
*chat
)
141 g_return_val_if_fail(PURPLE_IS_CHAT(chat
), NULL
);
143 return PURPLE_GROUP(PURPLE_BLIST_NODE(chat
)->parent
);
147 purple_chat_get_account(PurpleChat
*chat
)
149 PurpleChatPrivate
*priv
= NULL
;
151 g_return_val_if_fail(PURPLE_IS_CHAT(chat
), NULL
);
153 priv
= purple_chat_get_instance_private(chat
);
154 return priv
->account
;
158 purple_chat_get_components(PurpleChat
*chat
)
160 PurpleChatPrivate
*priv
= NULL
;
162 g_return_val_if_fail(PURPLE_IS_CHAT(chat
), NULL
);
164 priv
= purple_chat_get_instance_private(chat
);
165 return priv
->components
;
168 /******************************************************************************
170 *****************************************************************************/
172 purple_chat_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
175 PurpleChat
*chat
= PURPLE_CHAT(obj
);
176 PurpleChatPrivate
*priv
= purple_chat_get_instance_private(chat
);
180 if (priv
->is_constructed
)
181 purple_chat_set_alias(chat
, g_value_get_string(value
));
184 purple_utf8_strip_unprintables(g_value_get_string(value
));
187 priv
->account
= g_value_get_object(value
);
189 case PROP_COMPONENTS
:
190 priv
->components
= g_value_get_pointer(value
);
193 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
199 purple_chat_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
202 PurpleChat
*chat
= PURPLE_CHAT(obj
);
203 PurpleChatPrivate
*priv
= purple_chat_get_instance_private(chat
);
207 g_value_set_string(value
, priv
->alias
);
210 g_value_set_object(value
, purple_chat_get_account(chat
));
212 case PROP_COMPONENTS
:
213 g_value_set_pointer(value
, purple_chat_get_components(chat
));
216 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
221 /* GObject initialization function */
223 purple_chat_init(PurpleChat
*chat
)
227 /* Called when done constructing */
229 purple_chat_constructed(GObject
*object
)
231 PurpleChat
*chat
= PURPLE_CHAT(object
);
232 PurpleChatPrivate
*priv
= purple_chat_get_instance_private(chat
);
234 G_OBJECT_CLASS(purple_chat_parent_class
)->constructed(object
);
236 purple_blist_new_node(purple_blist_get_default(),
237 PURPLE_BLIST_NODE(chat
));
239 priv
->is_constructed
= TRUE
;
242 /* GObject finalize function */
244 purple_chat_finalize(GObject
*object
)
246 PurpleChatPrivate
*priv
=
247 purple_chat_get_instance_private(PURPLE_CHAT(object
));
250 g_hash_table_destroy(priv
->components
);
252 G_OBJECT_CLASS(purple_chat_parent_class
)->finalize(object
);
255 /* Class initializer function */
256 static void purple_chat_class_init(PurpleChatClass
*klass
)
258 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
260 obj_class
->finalize
= purple_chat_finalize
;
262 /* Setup properties */
263 obj_class
->get_property
= purple_chat_get_property
;
264 obj_class
->set_property
= purple_chat_set_property
;
265 obj_class
->constructed
= purple_chat_constructed
;
267 properties
[PROP_ALIAS
] = g_param_spec_string(
270 "The alias for the chat.",
272 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
275 properties
[PROP_ACCOUNT
] = g_param_spec_object(
278 "The account that the chat belongs to.",
280 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
283 properties
[PROP_COMPONENTS
] = g_param_spec_pointer(
286 "The protocol components of the chat.",
287 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
290 g_object_class_install_properties(obj_class
, PROP_LAST
, properties
);
294 purple_chat_new(PurpleAccount
*account
, const char *alias
, GHashTable
*components
)
296 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
297 g_return_val_if_fail(components
!= NULL
, NULL
);
299 return g_object_new(PURPLE_TYPE_CHAT
,
302 "components", components
,