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;
62 TpPropertyFlags flags;
66 static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass);
67 static void empathy_tp_chat_init (EmpathyTpChat *chat);
68 static void tp_chat_iface_init (EmpathyContactListIface *iface);
87 static guint signals[LAST_SIGNAL];
89 G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT,
90 G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST,
94 tp_chat_invalidated_cb (TpProxy *proxy,
100 empathy_debug (DEBUG_DOMAIN, "Channel invalidated: %s", message);
101 g_signal_emit (chat, signals[DESTROY], 0);
105 tp_chat_async_cb (TpChannel *proxy,
108 GObject *weak_object)
111 empathy_debug (DEBUG_DOMAIN, "Error %s: %s",
112 user_data, error->message);
117 tp_chat_member_added_cb (EmpathyTpGroup *group,
118 EmpathyContact *contact,
119 EmpathyContact *actor,
121 const gchar *message,
124 g_signal_emit_by_name (chat, "members-changed",
125 contact, actor, reason, message,
130 tp_chat_member_removed_cb (EmpathyTpGroup *group,
131 EmpathyContact *contact,
132 EmpathyContact *actor,
134 const gchar *message,
137 g_signal_emit_by_name (chat, "members-changed",
138 contact, actor, reason, message,
142 tp_chat_local_pending_cb (EmpathyTpGroup *group,
143 EmpathyContact *contact,
144 EmpathyContact *actor,
146 const gchar *message,
149 g_signal_emit_by_name (chat, "pendings-changed",
150 contact, actor, reason, message,
155 tp_chat_add (EmpathyContactList *list,
156 EmpathyContact *contact,
157 const gchar *message)
159 EmpathyTpChatPriv *priv = GET_PRIV (list);
161 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
162 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
165 empathy_tp_group_add_member (priv->group, contact, message);
170 tp_chat_remove (EmpathyContactList *list,
171 EmpathyContact *contact,
172 const gchar *message)
174 EmpathyTpChatPriv *priv = GET_PRIV (list);
176 g_return_if_fail (EMPATHY_IS_TP_CHAT (list));
177 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
180 empathy_tp_group_remove_member (priv->group, contact, message);
185 tp_chat_get_members (EmpathyContactList *list)
187 EmpathyTpChatPriv *priv = GET_PRIV (list);
188 GList *members = NULL;
190 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL);
193 members = empathy_tp_group_get_members (priv->group);
195 members = g_list_prepend (members, g_object_ref (priv->user));
196 members = g_list_prepend (members, g_object_ref (priv->remote_contact));
202 static EmpathyMessage *
203 tp_chat_build_message (EmpathyTpChat *chat,
207 const gchar *message_body)
209 EmpathyTpChatPriv *priv;
210 EmpathyMessage *message;
211 EmpathyContact *sender;
213 priv = GET_PRIV (chat);
215 if (from_handle == 0) {
216 sender = g_object_ref (priv->user);
218 sender = empathy_contact_factory_get_from_handle (priv->factory,
223 message = empathy_message_new (message_body);
224 empathy_message_set_type (message, type);
225 empathy_message_set_sender (message, sender);
226 empathy_message_set_receiver (message, priv->user);
227 empathy_message_set_timestamp (message, timestamp);
229 g_object_unref (sender);
235 tp_chat_sender_ready_notify_cb (EmpathyContact *contact,
236 GParamSpec *param_spec,
239 EmpathyTpChatPriv *priv = GET_PRIV (chat);
240 EmpathyMessage *message;
241 EmpathyContactReady ready;
242 EmpathyContact *sender;
243 gboolean removed = FALSE;
245 /* Emit all messages queued until we find a message with not
246 * ready sender. When leaving this loop, sender is the first not ready
247 * contact queued and removed tells if at least one message got removed
249 while (priv->message_queue) {
250 message = priv->message_queue->data;
251 sender = empathy_message_get_sender (message);
252 ready = empathy_contact_get_ready (sender);
254 if (!(ready & EMPATHY_CONTACT_READY_NAME)) {
258 empathy_debug (DEBUG_DOMAIN, "Queued message ready");
259 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
260 priv->message_queue = g_slist_remove (priv->message_queue,
262 g_object_unref (message);
267 g_signal_handlers_disconnect_by_func (contact,
268 tp_chat_sender_ready_notify_cb,
271 if (priv->message_queue) {
272 g_signal_connect (sender, "notify::ready",
273 G_CALLBACK (tp_chat_sender_ready_notify_cb),
280 tp_chat_emit_or_queue_message (EmpathyTpChat *chat,
281 EmpathyMessage *message)
283 EmpathyTpChatPriv *priv = GET_PRIV (chat);
284 EmpathyContact *sender;
285 EmpathyContactReady ready;
287 if (priv->message_queue != NULL) {
288 empathy_debug (DEBUG_DOMAIN, "Message queue not empty");
289 priv->message_queue = g_slist_append (priv->message_queue,
290 g_object_ref (message));
294 sender = empathy_message_get_sender (message);
295 ready = empathy_contact_get_ready (sender);
296 if (ready & EMPATHY_CONTACT_READY_NAME) {
297 empathy_debug (DEBUG_DOMAIN, "Message queue empty and sender ready");
298 g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
302 empathy_debug (DEBUG_DOMAIN, "Sender not ready");
303 priv->message_queue = g_slist_append (priv->message_queue,
304 g_object_ref (message));
305 g_signal_connect (sender, "notify::ready",
306 G_CALLBACK (tp_chat_sender_ready_notify_cb),
311 tp_chat_received_cb (TpChannel *channel,
317 const gchar *message_body,
321 EmpathyTpChatPriv *priv = GET_PRIV (chat);
322 EmpathyMessage *message;
324 if (!priv->had_pending_messages) {
328 empathy_debug (DEBUG_DOMAIN, "Message received: %s", message_body);
330 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
336 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
337 g_object_unref (message);
339 if (priv->acknowledge) {
342 message_ids = g_array_new (FALSE, FALSE, sizeof (guint));
343 g_array_append_val (message_ids, message_id);
344 tp_cli_channel_type_text_call_acknowledge_pending_messages (priv->channel,
348 "acknowledging received message",
351 g_array_free (message_ids, TRUE);
356 tp_chat_sent_cb (TpChannel *channel,
359 const gchar *message_body,
363 EmpathyMessage *message;
365 empathy_debug (DEBUG_DOMAIN, "Message sent: %s", message_body);
367 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
373 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
374 g_object_unref (message);
378 tp_chat_send_error_cb (TpChannel *channel,
382 const gchar *message_body,
386 EmpathyMessage *message;
388 empathy_debug (DEBUG_DOMAIN, "Message sent error: %s (%d)",
389 message_body, error_code);
391 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
397 g_signal_emit (chat, signals[SEND_ERROR], 0, message, error_code);
398 g_object_unref (message);
402 tp_chat_state_changed_cb (TpChannel *channel,
408 EmpathyTpChatPriv *priv = GET_PRIV (chat);
409 EmpathyContact *contact;
411 contact = empathy_contact_factory_get_from_handle (priv->factory,
415 empathy_debug (DEBUG_DOMAIN, "Chat state changed for %s (%d): %d",
416 empathy_contact_get_name (contact),
419 g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state);
420 g_object_unref (contact);
424 tp_chat_list_pending_messages_cb (TpChannel *channel,
425 const GPtrArray *messages_list,
430 EmpathyTpChatPriv *priv = GET_PRIV (chat);
432 GArray *message_ids = NULL;
434 priv->had_pending_messages = TRUE;
437 empathy_debug (DEBUG_DOMAIN, "Error listing pending messages: %s",
442 if (priv->acknowledge) {
443 message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint),
447 for (i = 0; i < messages_list->len; i++) {
448 EmpathyMessage *message;
449 GValueArray *message_struct;
450 const gchar *message_body;
457 message_struct = g_ptr_array_index (messages_list, i);
459 message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
460 timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
461 from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
462 message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
463 message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
464 message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
466 empathy_debug (DEBUG_DOMAIN, "Message pending: %s", message_body);
469 g_array_append_val (message_ids, message_id);
472 message = tp_chat_build_message (EMPATHY_TP_CHAT (chat),
478 tp_chat_emit_or_queue_message (EMPATHY_TP_CHAT (chat), message);
479 g_object_unref (message);
483 tp_cli_channel_type_text_call_acknowledge_pending_messages (priv->channel,
487 "acknowledging pending messages",
490 g_array_free (message_ids, TRUE);
495 tp_chat_property_flags_changed_cb (TpProxy *proxy,
496 const GPtrArray *properties,
500 EmpathyTpChatPriv *priv = GET_PRIV (chat);
503 if (!priv->had_properties_list || !properties) {
507 for (i = 0; i < properties->len; i++) {
508 GValueArray *prop_struct;
509 TpChatProperty *property;
513 prop_struct = g_ptr_array_index (properties, i);
514 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
515 flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 1));
517 for (j = 0; j < priv->properties->len; j++) {
518 property = g_ptr_array_index (priv->properties, j);
519 if (property->id == id) {
520 property->flags = flags;
521 empathy_debug (DEBUG_DOMAIN,
522 "property %s flags changed: %d",
523 property->name, property->flags);
531 tp_chat_properties_changed_cb (TpProxy *proxy,
532 const GPtrArray *properties,
536 EmpathyTpChatPriv *priv = GET_PRIV (chat);
539 if (!priv->had_properties_list || !properties) {
543 for (i = 0; i < properties->len; i++) {
544 GValueArray *prop_struct;
545 TpChatProperty *property;
549 prop_struct = g_ptr_array_index (properties, i);
550 id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
551 src_value = g_value_get_boxed (g_value_array_get_nth (prop_struct, 1));
553 for (j = 0; j < priv->properties->len; j++) {
554 property = g_ptr_array_index (priv->properties, j);
555 if (property->id == id) {
556 if (property->value) {
557 g_value_copy (src_value, property->value);
559 property->value = tp_g_value_slice_dup (src_value);
562 empathy_debug (DEBUG_DOMAIN, "property %s changed",
564 g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
565 property->name, property->value);
573 tp_chat_get_properties_cb (TpProxy *proxy,
574 const GPtrArray *properties,
580 empathy_debug (DEBUG_DOMAIN, "Error getting properties: %s",
585 tp_chat_properties_changed_cb (proxy, properties, user_data, chat);
589 tp_chat_list_properties_cb (TpProxy *proxy,
590 const GPtrArray *properties,
595 EmpathyTpChatPriv *priv = GET_PRIV (chat);
599 priv->had_properties_list = TRUE;
602 empathy_debug (DEBUG_DOMAIN, "Error listing properties: %s",
607 ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
608 priv->properties = g_ptr_array_sized_new (properties->len);
609 for (i = 0; i < properties->len; i++) {
610 GValueArray *prop_struct;
611 TpChatProperty *property;
613 prop_struct = g_ptr_array_index (properties, i);
614 property = g_slice_new0 (TpChatProperty);
615 property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
616 property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
617 property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
619 empathy_debug (DEBUG_DOMAIN, "Adding property name=%s id=%d flags=%d",
620 property->name, property->id, property->flags);
621 g_ptr_array_add (priv->properties, property);
622 if (property->flags & TP_PROPERTY_FLAG_READ) {
623 g_array_append_val (ids, property->id);
627 tp_cli_properties_interface_call_get_properties (proxy, -1,
629 tp_chat_get_properties_cb,
633 g_array_free (ids, TRUE);
637 empathy_tp_chat_set_property (EmpathyTpChat *chat,
641 EmpathyTpChatPriv *priv = GET_PRIV (chat);
642 TpChatProperty *property;
645 g_return_if_fail (priv->ready);
647 for (i = 0; i < priv->properties->len; i++) {
648 property = g_ptr_array_index (priv->properties, i);
649 if (!tp_strdiff (property->name, name)) {
650 GPtrArray *properties;
653 GValue dest_value = {0, };
655 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
659 g_value_init (&id, G_TYPE_UINT);
660 g_value_init (&dest_value, G_TYPE_VALUE);
661 g_value_set_uint (&id, property->id);
662 g_value_set_boxed (&dest_value, value);
664 prop = g_value_array_new (2);
665 g_value_array_append (prop, &id);
666 g_value_array_append (prop, &dest_value);
668 properties = g_ptr_array_sized_new (1);
669 g_ptr_array_add (properties, prop);
671 empathy_debug (DEBUG_DOMAIN, "Set property %s", name);
672 tp_cli_properties_interface_call_set_properties (priv->channel, -1,
674 (tp_cli_properties_interface_callback_for_set_properties)
676 "Seting property", NULL,
679 g_ptr_array_free (properties, TRUE);
680 g_value_array_free (prop);
688 tp_chat_channel_ready_cb (EmpathyTpChat *chat)
690 EmpathyTpChatPriv *priv = GET_PRIV (chat);
691 TpConnection *connection;
692 guint handle, handle_type;
696 empathy_debug (DEBUG_DOMAIN, "Channel ready");
698 g_object_get (priv->channel,
699 "connection", &connection,
701 "handle_type", &handle_type,
704 handles = g_array_new (FALSE, FALSE, sizeof (guint));
705 g_array_append_val (handles, handle);
706 tp_cli_connection_run_inspect_handles (connection, -1,
707 handle_type, handles,
709 g_array_free (handles, TRUE);
715 g_object_notify (G_OBJECT (chat), "ready");
717 if (tp_proxy_has_interface_by_id (priv->channel,
718 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
719 priv->group = empathy_tp_group_new (priv->channel);
721 g_signal_connect (priv->group, "member-added",
722 G_CALLBACK (tp_chat_member_added_cb),
724 g_signal_connect (priv->group, "member-removed",
725 G_CALLBACK (tp_chat_member_removed_cb),
727 g_signal_connect (priv->group, "local-pending",
728 G_CALLBACK (tp_chat_local_pending_cb),
731 priv->remote_contact = empathy_contact_factory_get_from_handle (priv->factory,
734 g_object_notify (G_OBJECT (chat), "remote-contact");
737 if (tp_proxy_has_interface_by_id (priv->channel,
738 TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
739 tp_cli_properties_interface_call_list_properties (priv->channel, -1,
740 tp_chat_list_properties_cb,
743 tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
744 tp_chat_properties_changed_cb,
746 G_OBJECT (chat), NULL);
747 tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
748 tp_chat_property_flags_changed_cb,
750 G_OBJECT (chat), NULL);
753 tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
755 tp_chat_list_pending_messages_cb,
759 tp_cli_channel_type_text_connect_to_received (priv->channel,
762 G_OBJECT (chat), NULL);
763 tp_cli_channel_type_text_connect_to_sent (priv->channel,
766 G_OBJECT (chat), NULL);
767 tp_cli_channel_type_text_connect_to_send_error (priv->channel,
768 tp_chat_send_error_cb,
770 G_OBJECT (chat), NULL);
771 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
772 tp_chat_state_changed_cb,
774 G_OBJECT (chat), NULL);
775 tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
776 tp_chat_state_changed_cb,
778 G_OBJECT (chat), NULL);
782 tp_chat_finalize (GObject *object)
784 EmpathyTpChatPriv *priv = GET_PRIV (object);
787 if (priv->acknowledge && priv->channel) {
788 empathy_debug (DEBUG_DOMAIN, "Closing channel...");
789 tp_cli_channel_call_close (priv->channel, -1,
791 "closing channel", NULL,
796 g_signal_handlers_disconnect_by_func (priv->channel,
797 tp_chat_invalidated_cb,
799 g_object_unref (priv->channel);
802 if (priv->properties) {
803 for (i = 0; i < priv->properties->len; i++) {
804 TpChatProperty *property;
806 property = g_ptr_array_index (priv->properties, i);
807 g_free (property->name);
808 if (property->value) {
809 tp_g_value_slice_free (property->value);
811 g_slice_free (TpChatProperty, property);
813 g_ptr_array_free (priv->properties, TRUE);
816 if (priv->remote_contact) {
817 g_object_unref (priv->remote_contact);
820 g_object_unref (priv->group);
823 g_object_unref (priv->factory);
824 g_object_unref (priv->user);
825 g_object_unref (priv->account);
828 G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
832 tp_chat_constructor (GType type,
834 GObjectConstructParam *props)
837 EmpathyTpChatPriv *priv;
838 gboolean channel_ready;
840 chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
842 priv = GET_PRIV (chat);
843 priv->account = empathy_channel_get_account (priv->channel);
844 priv->factory = empathy_contact_factory_new ();
845 priv->user = empathy_contact_factory_get_user (priv->factory, priv->account);
847 g_signal_connect (priv->channel, "invalidated",
848 G_CALLBACK (tp_chat_invalidated_cb),
851 g_object_get (priv->channel, "channel-ready", &channel_ready, NULL);
853 tp_chat_channel_ready_cb (EMPATHY_TP_CHAT (chat));
855 g_signal_connect_swapped (priv->channel, "notify::channel-ready",
856 G_CALLBACK (tp_chat_channel_ready_cb),
864 tp_chat_get_property (GObject *object,
869 EmpathyTpChatPriv *priv = GET_PRIV (object);
873 g_value_set_object (value, priv->channel);
875 case PROP_ACKNOWLEDGE:
876 g_value_set_boolean (value, priv->acknowledge);
878 case PROP_REMOTE_CONTACT:
879 g_value_set_object (value, priv->remote_contact);
882 g_value_set_boolean (value, priv->ready);
885 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
891 tp_chat_set_property (GObject *object,
896 EmpathyTpChatPriv *priv = GET_PRIV (object);
900 priv->channel = g_object_ref (g_value_get_object (value));
902 case PROP_ACKNOWLEDGE:
903 priv->acknowledge = g_value_get_boolean (value);
906 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
912 empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
914 GObjectClass *object_class = G_OBJECT_CLASS (klass);
916 object_class->finalize = tp_chat_finalize;
917 object_class->constructor = tp_chat_constructor;
918 object_class->get_property = tp_chat_get_property;
919 object_class->set_property = tp_chat_set_property;
921 g_object_class_install_property (object_class,
923 g_param_spec_object ("channel",
925 "The text channel for the chat",
928 G_PARAM_CONSTRUCT_ONLY));
929 g_object_class_install_property (object_class,
931 g_param_spec_boolean ("acknowledge",
932 "acknowledge messages",
933 "Wheter or not received messages should be acknowledged",
938 g_object_class_install_property (object_class,
940 g_param_spec_object ("remote-contact",
941 "The remote contact",
942 "The remote contact if there is no group iface on the channel",
943 EMPATHY_TYPE_CONTACT,
945 g_object_class_install_property (object_class,
947 g_param_spec_boolean ("ready",
948 "Is the object ready",
949 "This object can't be used until this becomes true",
954 signals[MESSAGE_RECEIVED] =
955 g_signal_new ("message-received",
956 G_TYPE_FROM_CLASS (klass),
960 g_cclosure_marshal_VOID__OBJECT,
962 1, EMPATHY_TYPE_MESSAGE);
964 signals[SEND_ERROR] =
965 g_signal_new ("send-error",
966 G_TYPE_FROM_CLASS (klass),
970 _empathy_marshal_VOID__OBJECT_UINT,
972 2, EMPATHY_TYPE_MESSAGE, G_TYPE_UINT);
974 signals[CHAT_STATE_CHANGED] =
975 g_signal_new ("chat-state-changed",
976 G_TYPE_FROM_CLASS (klass),
980 _empathy_marshal_VOID__OBJECT_UINT,
982 2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
984 signals[PROPERTY_CHANGED] =
985 g_signal_new ("property-changed",
986 G_TYPE_FROM_CLASS (klass),
990 _empathy_marshal_VOID__STRING_BOXED,
992 2, G_TYPE_STRING, G_TYPE_VALUE);
995 g_signal_new ("destroy",
996 G_TYPE_FROM_CLASS (klass),
1000 g_cclosure_marshal_VOID__VOID,
1004 g_type_class_add_private (object_class, sizeof (EmpathyTpChatPriv));
1008 empathy_tp_chat_init (EmpathyTpChat *chat)
1013 tp_chat_iface_init (EmpathyContactListIface *iface)
1015 iface->add = tp_chat_add;
1016 iface->remove = tp_chat_remove;
1017 iface->get_members = tp_chat_get_members;
1021 empathy_tp_chat_new (TpChannel *channel,
1022 gboolean acknowledge)
1024 return g_object_new (EMPATHY_TYPE_TP_CHAT,
1026 "acknowledge", acknowledge,
1031 empathy_tp_chat_send (EmpathyTpChat *chat,
1032 EmpathyMessage *message)
1034 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1035 const gchar *message_body;
1036 EmpathyMessageType message_type;
1038 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1039 g_return_if_fail (EMPATHY_IS_MESSAGE (message));
1040 g_return_if_fail (priv->ready);
1042 message_body = empathy_message_get_body (message);
1043 message_type = empathy_message_get_type (message);
1045 empathy_debug (DEBUG_DOMAIN, "Sending message: %s", message_body);
1046 tp_cli_channel_type_text_call_send (priv->channel, -1,
1050 "sending message", NULL,
1055 empathy_tp_chat_set_state (EmpathyTpChat *chat,
1056 TpChannelChatState state)
1058 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1060 g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
1061 g_return_if_fail (priv->ready);
1063 empathy_debug (DEBUG_DOMAIN, "Set state: %d", state);
1064 tp_cli_channel_interface_chat_state_call_set_chat_state (priv->channel, -1,
1067 "setting chat state",
1073 empathy_tp_chat_get_id (EmpathyTpChat *chat)
1075 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1077 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1078 g_return_val_if_fail (priv->ready, NULL);
1084 empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
1086 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1088 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
1090 return priv->remote_contact;
1094 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
1096 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1098 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1104 empathy_tp_chat_get_account (EmpathyTpChat *chat)
1106 EmpathyTpChatPriv *priv = GET_PRIV (chat);
1108 g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE);
1110 return priv->account;