1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <telepathy-glib/channel.h>
27 #include <telepathy-glib/dbus.h>
28 #include <telepathy-glib/util.h>
30 #include "empathy-tp-chat.h"
31 #include "empathy-contact-factory.h"
32 #include "empathy-contact-list.h"
33 #include "empathy-marshal.h"
34 #include "empathy-debug.h"
35 #include "empathy-time.h"
36 #include "empathy-utils.h"
38 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
39 EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv))
41 #define DEBUG_DOMAIN "TpChat"
43 struct _EmpathyTpChatPriv {
44 EmpathyContactFactory *factory;
46 EmpathyContact *remote_contact;
47 EmpathyTpGroup *group;
52 gboolean had_pending_messages;
53 GSList *message_queue;
54 gboolean had_properties_list;
55 GPtrArray *properties;
63 TpPropertyFlags flags;
67 static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass);
68 static void empathy_tp_chat_init (EmpathyTpChat *chat);
69 static void tp_chat_iface_init (EmpathyContactListIface *iface);
88 static guint signals[LAST_SIGNAL];
90 G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
91 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
95 tp_chat_invalidated_cb (TpProxy *proxy,
101 empathy_debug (DEBUG_DOMAIN, "Channel invalidated: %s", message);
102 g_signal_emit (chat, signals[DESTROY], 0);
106 tp_chat_async_cb (TpChannel *proxy,
109 GObject *weak_object)
112 empathy_debug (DEBUG_DOMAIN, "Error %s: %s",
113 user_data, error->message);
118 tp_chat_member_added_cb (EmpathyTpGroup *group,
119 EmpathyContact *contact,
120 EmpathyContact *actor,
122 const gchar *message,
125 EmpathyTpChatPriv *priv = GET_PRIV (chat);
128 if (priv->nb_members > 2 && priv->remote_contact) {
129 /* We now have more than 2 members, this is not a p2p chat
130 * anymore. Remove the remote-contact as it makes no sense, the
131 * EmpathyContactList interface must be used now. */
132 g_object_unref (priv->remote_contact);
133 priv->remote_contact = NULL;
134 g_object_notify (G_OBJECT (chat), "remote-contact");
136 if (priv->nb_members <= 2 && !priv->remote_contact &&
137 !empathy_contact_is_user (contact)) {
138 /* This is a p2p chat, if it's not ourself that means this is
139 * the remote contact with who we are chatting. This is to
140 * avoid forcing the usage of the EmpathyContactList interface
142 priv->remote_contact = g_object_ref (contact);
143 g_object_notify (G_OBJECT (chat), "remote-contact");
146 g_signal_emit_by_name (chat, "members-changed",
147 contact, actor, reason, message,
152 tp_chat_member_removed_cb (EmpathyTpGroup *group,
153 EmpathyContact *contact,
154 EmpathyContact *actor,
156 const gchar *message,
159 EmpathyTpChatPriv *priv = GET_PRIV (chat);
162 if (priv->nb_members <= 2 && !priv->remote_contact) {
165 /* We are not a MUC anymore, get the remote contact back */
166 members = empathy_tp_group_get_members (group);
167 for (l = members; l; l = l->next) {
168 if (!empathy_contact_is_user (l->data)) {
169 priv->remote_contact = g_object_ref (l->data);
170 g_object_notify (G_OBJECT (chat), "remote-contact");
174 g_list_foreach (members, (GFunc) g_object_unref, NULL);
175 g_list_free (members);
178 g_signal_emit_by_name (chat, "members-changed",
179 contact, actor, reason, message,
183 tp_chat_local_pending_cb (EmpathyTpGroup *group,
184 EmpathyContact *contact,
185 EmpathyContact *actor,
187 const gchar *message,
190 g_signal_emit_by_name (chat, "pendings-changed",
191 contact, actor, reason, message,
196 tp_chat_add (EmpathyContactList *list,
197 EmpathyContact *contact,
198 const gchar *message)
200 EmpathyTpChatPriv *priv = GET_PRIV (list);
202 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
203 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
206 empathy_tp_group_add_member (priv->group, contact, message);
211 tp_chat_remove (EmpathyContactList *list,
212 EmpathyContact *contact,
213 const gchar *message)
215 EmpathyTpChatPriv *priv = GET_PRIV (list);
217 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
218 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
221 empathy_tp_group_remove_member (priv->group, contact, message);
226 tp_chat_get_members (EmpathyContactList *list)
228 EmpathyTpChatPriv *priv = GET_PRIV (list);
229 GList *members = NULL;
231 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
234 members = empathy_tp_group_get_members (priv->group);
236 members = g_list_prepend (members, g_object_ref (priv->user));
237 members = g_list_prepend (members, g_object_ref (priv->remote_contact));
243 static EmpathyMessage *
244 tp_chat_build_message (EmpathyTpChat *chat,
248 const gchar *message_body)
250 EmpathyTpChatPriv *priv;
251 EmpathyMessage *message;
252 EmpathyContact *sender;
254 priv = GET_PRIV (chat);
256 if (from_handle == 0) {
257 sender = g_object_ref (priv->user);
259 sender = empathy_contact_factory_get_from_handle (priv->factory,
264 message = empathy_message_new (message_body);
265 empathy_message_set_type (message, type);
266 empathy_message_set_sender (message, sender);
267 empathy_message_set_receiver (message, priv->user);
268 empathy_message_set_timestamp (message, timestamp);
270 g_object_unref (sender);
276 tp_chat_sender_ready_notify_cb (EmpathyContact *contact,
277 GParamSpec *param_spec,
280 EmpathyTpChatPriv *priv = GET_PRIV (chat);
281 EmpathyMessage *message;
282 EmpathyContactReady ready;
283 EmpathyContact *sender;
284 gboolean removed = FALSE;
286 /* Emit all messages queued until we find a message with not
287 * ready sender. When leaving this loop, sender is the first not ready
288 * contact queued and removed tells if at least one message got removed
290 while (priv->message_queue) {
291 message = priv->message_queue->data;
292 sender = empathy_message_get_sender (message);
293 ready = empathy_contact_get_ready (sender);
295 if (!(ready & EMPATHY_CONTACT_READY_NAME)) {
299 empathy_debug (DEBUG_DOMAIN, "Queued message ready");
300 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
301 priv->message_queue = g_slist_remove (priv->message_queue,
303 g_object_unref (message);
308 g_signal_handlers_disconnect_by_func (contact,
309 tp_chat_sender_ready_notify_cb,
312 if (priv->message_queue) {
313 g_signal_connect (sender, "notify::ready",
314 G_CALLBACK (tp_chat_sender_ready_notify_cb),
321 tp_chat_emit_or_queue_message (EmpathyTpChat *chat,
322 EmpathyMessage *message)
324 EmpathyTpChatPriv *priv = GET_PRIV (chat);
325 EmpathyContact *sender;
326 EmpathyContactReady ready;
328 if (priv->message_queue != NULL) {
329 empathy_debug (DEBUG_DOMAIN, "Message queue not empty");
330 priv->message_queue = g_slist_append (priv->message_queue,
331 g_object_ref (message));
335 sender = empathy_message_get_sender (message);
336 ready = empathy_contact_get_ready (sender);
337 if (ready & EMPATHY_CONTACT_READY_NAME) {
338 empathy_debug (DEBUG_DOMAIN, "Message queue empty and sender ready");
339 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
343 empathy_debug (DEBUG_DOMAIN, "Sender not ready");
344 priv->message_queue = g_slist_append (priv->message_queue,
345 g_object_ref (message));
346 g_signal_connect (sender, "notify::ready",
347 G_CALLBACK (tp_chat_sender_ready_notify_cb),
352 tp_chat_received_cb (TpChannel *channel,
358 const gchar *message_body,
362 EmpathyTpChatPriv *priv = GET_PRIV (chat);
363 EmpathyMessage *message;
365 if (!priv->had_pending_messages) {
369 empathy_debug (DEBUG_DOMAIN, "Message received: %s", message_body);
371 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
377 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
378 g_object_unref (message);
380 if (priv->acknowledge) {
383 message_ids = g_array_new (FALSE, FALSE, sizeof (guint));
384 g_array_append_val (message_ids, message_id);
385 tp_cli_channel_type_text_call_acknowledge_pending_messages (priv->channel,
389 "acknowledging received message",
392 g_array_free (message_ids, TRUE);
397 tp_chat_sent_cb (TpChannel *channel,
400 const gchar *message_body,
404 EmpathyMessage *message;
406 empathy_debug (DEBUG_DOMAIN, "Message sent: %s", message_body);
408 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
414 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
415 g_object_unref (message);
419 tp_chat_send_error_cb (TpChannel *channel,
423 const gchar *message_body,
427 EmpathyMessage *message;
429 empathy_debug (DEBUG_DOMAIN, "Message sent error: %s (%d)",
430 message_body, error_code);
432 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
438 g_signal_emit (chat, signals[SEND_ERROR], 0, message, error_code);
439 g_object_unref (message);
443 tp_chat_state_changed_cb (TpChannel *channel,
449 EmpathyTpChatPriv *priv = GET_PRIV (chat);
450 EmpathyContact *contact;
452 contact = empathy_contact_factory_get_from_handle (priv->factory,
456 empathy_debug (DEBUG_DOMAIN, "Chat state changed for %s (%d): %d",
457 empathy_contact_get_name (contact),
460 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
461 g_object_unref (contact);
465 tp_chat_list_pending_messages_cb (TpChannel *channel,
466 const GPtrArray *messages_list,
471 EmpathyTpChatPriv *priv = GET_PRIV (chat);
473 GArray *message_ids = NULL;
475 priv->had_pending_messages = TRUE;
478 empathy_debug (DEBUG_DOMAIN, "Error listing pending messages: %s",
483 if (priv->acknowledge) {
484 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint),
488 for (i = 0; i < messages_list->len; i++) {
489 EmpathyMessage *message;
490 GValueArray *message_struct;
491 const gchar *message_body;
498 message_struct = g_ptr_array_index (messages_list, i);
500 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
501 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
502 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
503 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
504 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
505 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
507 empathy_debug (DEBUG_DOMAIN, "Message pending: %s", message_body);
510 g_array_append_val (message_ids, message_id);
513 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
519 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
520 g_object_unref (message);
524 tp_cli_channel_type_text_call_acknowledge_pending_messages (priv->channel,
528 "acknowledging pending messages",
531 g_array_free (message_ids, TRUE);
536 tp_chat_property_flags_changed_cb (TpProxy *proxy,
537 const GPtrArray *properties,
541 EmpathyTpChatPriv *priv = GET_PRIV (chat);
544 if (!priv->had_properties_list || !properties) {
548 for (i = 0; i < properties->len; i++) {
549 GValueArray *prop_struct;
550 TpChatProperty *property;
554 prop_struct = g_ptr_array_index (properties, i);
555 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
556 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
558 for (j = 0; j < priv->properties->len; j++) {
559 property = g_ptr_array_index (priv->properties, j);
560 if (property->id == id) {
561 property->flags = flags;
562 empathy_debug (DEBUG_DOMAIN,
563 "property %s flags changed: %d",
564 property->name, property->flags);
572 tp_chat_properties_changed_cb (TpProxy *proxy,
573 const GPtrArray *properties,
577 EmpathyTpChatPriv *priv = GET_PRIV (chat);
580 if (!priv->had_properties_list || !properties) {
584 for (i = 0; i < properties->len; i++) {
585 GValueArray *prop_struct;
586 TpChatProperty *property;
590 prop_struct = g_ptr_array_index (properties, i);
591 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
592 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
594 for (j = 0; j < priv->properties->len; j++) {
595 property = g_ptr_array_index (priv->properties, j);
596 if (property->id == id) {
597 if (property->value) {
598 g_value_copy (src_value, property->value);
600 property->value = tp_g_value_slice_dup (src_value);
603 empathy_debug (DEBUG_DOMAIN, "property %s changed",
605 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
606 property->name, property->value);
614 tp_chat_get_properties_cb (TpProxy *proxy,
615 const GPtrArray *properties,
621 empathy_debug (DEBUG_DOMAIN, "Error getting properties: %s",
626 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
630 tp_chat_list_properties_cb (TpProxy *proxy,
631 const GPtrArray *properties,
636 EmpathyTpChatPriv *priv = GET_PRIV (chat);
640 priv->had_properties_list = TRUE;
643 empathy_debug (DEBUG_DOMAIN, "Error listing properties: %s",
648 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
649 priv->properties = g_ptr_array_sized_new (properties->len);
650 for (i = 0; i < properties->len; i++) {
651 GValueArray *prop_struct;
652 TpChatProperty *property;
654 prop_struct = g_ptr_array_index (properties, i);
655 property = g_slice_new0 (TpChatProperty);
656 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
657 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
658 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
660 empathy_debug (DEBUG_DOMAIN, "Adding property name=%s id=%d flags=%d",
661 property->name, property->id, property->flags);
662 g_ptr_array_add (priv->properties, property);
663 if (property->flags & TP_PROPERTY_FLAG_READ) {
664 g_array_append_val (ids, property->id);
668 tp_cli_properties_interface_call_get_properties (proxy, -1,
670 tp_chat_get_properties_cb,
674 g_array_free (ids, TRUE);
678 empathy_tp_chat_set_property (EmpathyTpChat *chat,
682 EmpathyTpChatPriv *priv = GET_PRIV (chat);
683 TpChatProperty *property;
686 g_return_if_fail (priv->ready);
688 for (i = 0; i < priv->properties->len; i++) {
689 property = g_ptr_array_index (priv->properties, i);
690 if (!tp_strdiff (property->name, name)) {
691 GPtrArray *properties;
694 GValue dest_value = {0, };
696 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
700 g_value_init (&id, G_TYPE_UINT);
701 g_value_init (&dest_value, G_TYPE_VALUE);
702 g_value_set_uint (&id, property->id);
703 g_value_set_boxed (&dest_value, value);
705 prop = g_value_array_new (2);
706 g_value_array_append (prop, &id);
707 g_value_array_append (prop, &dest_value);
709 properties = g_ptr_array_sized_new (1);
710 g_ptr_array_add (properties, prop);
712 empathy_debug (DEBUG_DOMAIN, "Set property %s", name);
713 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
715 (tp_cli_properties_interface_callback_for_set_properties)
717 "Seting property", NULL,
720 g_ptr_array_free (properties, TRUE);
721 g_value_array_free (prop);
729 tp_chat_channel_ready_cb (EmpathyTpChat *chat)
731 EmpathyTpChatPriv *priv = GET_PRIV (chat);
732 TpConnection *connection;
733 guint handle, handle_type;
737 empathy_debug (DEBUG_DOMAIN, "Channel ready");
739 g_object_get (priv->channel,
740 "connection", &connection,
742 "handle_type", &handle_type,
745 handles = g_array_new (FALSE, FALSE, sizeof (guint));
746 g_array_append_val (handles, handle);
747 tp_cli_connection_run_inspect_handles (connection, -1,
748 handle_type, handles,
750 g_array_free (handles, TRUE);
756 g_object_notify (G_OBJECT (chat), "ready");
758 if (tp_proxy_has_interface_by_id (priv->channel,
759 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
760 priv->group = empathy_tp_group_new (priv->channel);
762 g_signal_connect (priv->group, "member-added",
763 G_CALLBACK (tp_chat_member_added_cb),
765 g_signal_connect (priv->group, "member-removed",
766 G_CALLBACK (tp_chat_member_removed_cb),
768 g_signal_connect (priv->group, "local-pending",
769 G_CALLBACK (tp_chat_local_pending_cb),
772 priv->remote_contact = empathy_contact_factory_get_from_handle (priv->factory,
775 g_object_notify (G_OBJECT (chat), "remote-contact");
778 if (tp_proxy_has_interface_by_id (priv->channel,
779 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
780 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
781 tp_chat_list_properties_cb,
784 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
785 tp_chat_properties_changed_cb,
787 G_OBJECT (chat), NULL);
788 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
789 tp_chat_property_flags_changed_cb,
791 G_OBJECT (chat), NULL);
794 tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
796 tp_chat_list_pending_messages_cb,
800 tp_cli_channel_type_text_connect_to_received (priv->channel,
803 G_OBJECT (chat), NULL);
804 tp_cli_channel_type_text_connect_to_sent (priv->channel,
807 G_OBJECT (chat), NULL);
808 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
809 tp_chat_send_error_cb,
811 G_OBJECT (chat), NULL);
812 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
813 tp_chat_state_changed_cb,
815 G_OBJECT (chat), NULL);
816 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
817 tp_chat_state_changed_cb,
819 G_OBJECT (chat), NULL);
823 tp_chat_finalize (GObject *object)
825 EmpathyTpChatPriv *priv = GET_PRIV (object);
828 if (priv->acknowledge && priv->channel) {
829 empathy_debug (DEBUG_DOMAIN, "Closing channel...");
830 tp_cli_channel_call_close (priv->channel, -1,
832 "closing channel", NULL,
837 g_signal_handlers_disconnect_by_func (priv->channel,
838 tp_chat_invalidated_cb,
840 g_object_unref (priv->channel);
843 if (priv->properties) {
844 for (i = 0; i < priv->properties->len; i++) {
845 TpChatProperty *property;
847 property = g_ptr_array_index (priv->properties, i);
848 g_free (property->name);
849 if (property->value) {
850 tp_g_value_slice_free (property->value);
852 g_slice_free (TpChatProperty, property);
854 g_ptr_array_free (priv->properties, TRUE);
857 if (priv->remote_contact) {
858 g_object_unref (priv->remote_contact);
861 g_object_unref (priv->group);
864 g_object_unref (priv->factory);
865 g_object_unref (priv->user);
866 g_object_unref (priv->account);
869 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
873 tp_chat_constructor (GType type,
875 GObjectConstructParam *props)
878 EmpathyTpChatPriv *priv;
879 gboolean channel_ready;
881 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
883 priv = GET_PRIV (chat);
884 priv->account = empathy_channel_get_account (priv->channel);
885 priv->factory = empathy_contact_factory_new ();
886 priv->user = empathy_contact_factory_get_user (priv->factory, priv->account);
888 g_signal_connect (priv->channel, "invalidated",
889 G_CALLBACK (tp_chat_invalidated_cb),
892 g_object_get (priv->channel, "channel-ready", &channel_ready, NULL);
894 tp_chat_channel_ready_cb (EMPATHY_TP_CHAT (chat));
896 g_signal_connect_swapped (priv->channel, "notify::channel-ready",
897 G_CALLBACK (tp_chat_channel_ready_cb),
905 tp_chat_get_property (GObject *object,
910 EmpathyTpChatPriv *priv = GET_PRIV (object);
914 g_value_set_object (value, priv->channel);
916 case PROP_ACKNOWLEDGE:
917 g_value_set_boolean (value, priv->acknowledge);
919 case PROP_REMOTE_CONTACT:
920 g_value_set_object (value, priv->remote_contact);
923 g_value_set_boolean (value, priv->ready);
926 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
932 tp_chat_set_property (GObject *object,
937 EmpathyTpChatPriv *priv = GET_PRIV (object);
941 priv->channel = g_object_ref (g_value_get_object (value));
943 case PROP_ACKNOWLEDGE:
944 priv->acknowledge = g_value_get_boolean (value);
947 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
953 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
955 GObjectClass *object_class = G_OBJECT_CLASS (klass);
957 object_class->finalize = tp_chat_finalize;
958 object_class->constructor = tp_chat_constructor;
959 object_class->get_property = tp_chat_get_property;
960 object_class->set_property = tp_chat_set_property;
962 g_object_class_install_property (object_class,
964 g_param_spec_object ("channel",
966 "The text channel for the chat",
969 G_PARAM_CONSTRUCT_ONLY));
970 g_object_class_install_property (object_class,
972 g_param_spec_boolean ("acknowledge",
973 "acknowledge messages",
974 "Wheter or not received messages should be acknowledged",
979 g_object_class_install_property (object_class,
981 g_param_spec_object ("remote-contact",
982 "The remote contact",
983 "The remote contact if there is no group iface on the channel",
984 EMPATHY_TYPE_CONTACT,
986 g_object_class_install_property (object_class,
988 g_param_spec_boolean ("ready",
989 "Is the object ready",
990 "This object can't be used until this becomes true",
995 signals[MESSAGE_RECEIVED] =
996 g_signal_new ("message-received",
997 G_TYPE_FROM_CLASS (klass),
1001 g_cclosure_marshal_VOID__OBJECT,
1003 1, EMPATHY_TYPE_MESSAGE);
1005 signals[SEND_ERROR] =
1006 g_signal_new ("send-error",
1007 G_TYPE_FROM_CLASS (klass),
1011 _empathy_marshal_VOID__OBJECT_UINT,
1013 2, EMPATHY_TYPE_MESSAGE, G_TYPE_UINT);
1015 signals[CHAT_STATE_CHANGED] =
1016 g_signal_new ("chat-state-changed",
1017 G_TYPE_FROM_CLASS (klass),
1021 _empathy_marshal_VOID__OBJECT_UINT,
1023 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
1025 signals[PROPERTY_CHANGED] =
1026 g_signal_new ("property-changed",
1027 G_TYPE_FROM_CLASS (klass),
1031 _empathy_marshal_VOID__STRING_BOXED,
1033 2, G_TYPE_STRING, G_TYPE_VALUE);
1036 g_signal_new ("destroy",
1037 G_TYPE_FROM_CLASS (klass),
1041 g_cclosure_marshal_VOID__VOID,
1045 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1049 empathy_tp_chat_init (EmpathyTpChat *chat)
1054 tp_chat_iface_init (EmpathyContactListIface *iface)
1056 iface->add = tp_chat_add;
1057 iface->remove = tp_chat_remove;
1058 iface->get_members = tp_chat_get_members;
1062 empathy_tp_chat_new (TpChannel *channel,
1063 gboolean acknowledge)
1065 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1067 "acknowledge", acknowledge,
1072 empathy_tp_chat_send (EmpathyTpChat *chat,
1073 EmpathyMessage *message)
1075 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1076 const gchar *message_body;
1077 EmpathyMessageType message_type;
1079 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1080 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1081 g_return_if_fail (priv->ready);
1083 message_body = empathy_message_get_body (message);
1084 message_type = empathy_message_get_type (message);
1086 empathy_debug (DEBUG_DOMAIN, "Sending message: %s", message_body);
1087 tp_cli_channel_type_text_call_send (priv->channel, -1,
1091 "sending message", NULL,
1096 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1097 TpChannelChatState state)
1099 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1101 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1102 g_return_if_fail (priv->ready);
1104 empathy_debug (DEBUG_DOMAIN, "Set state: %d", state);
1105 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1108 "setting chat state",
1114 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1116 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1118 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1119 g_return_val_if_fail (priv->ready, NULL);
1125 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1127 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1129 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1131 return priv->remote_contact;
1135 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1137 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1139 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1145 empathy_tp_chat_get_account (EmpathyTpChat *chat)
1147 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1149 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1151 return priv->account;