diff options
-rw-r--r-- | libempathy/Makefile.am | 2 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.c | 166 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.h | 6 | ||||
-rw-r--r-- | libempathy/empathy-tp-chatroom.c | 279 | ||||
-rw-r--r-- | libempathy/empathy-tp-chatroom.h | 63 |
5 files changed, 131 insertions, 385 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index f88a8cbc8..fc5b326a1 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -35,7 +35,6 @@ libempathy_la_SOURCES = \ empathy-tp-group.c \ empathy-tp-contact-list.c \ empathy-tp-chat.c \ - empathy-tp-chatroom.c \ empathy-tp-roomlist.c \ empathy-tp-call.c \ empathy-chandler.c \ @@ -76,7 +75,6 @@ libempathy_headers = \ empathy-tp-group.h \ empathy-tp-contact-list.h \ empathy-tp-chat.h \ - empathy-tp-chatroom.h \ empathy-tp-roomlist.h \ empathy-tp-call.h \ empathy-chandler.h \ diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index e9977cd93..431c38290 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -29,6 +29,7 @@ #include "empathy-tp-chat.h" #include "empathy-contact-factory.h" +#include "empathy-contact-list.h" #include "empathy-marshal.h" #include "empathy-debug.h" #include "empathy-time.h" @@ -42,6 +43,8 @@ struct _EmpathyTpChatPriv { EmpathyContactFactory *factory; EmpathyContact *user; + EmpathyContact *initiator; + EmpathyTpGroup *group; McAccount *account; TpChannel *channel; gchar *id; @@ -61,8 +64,9 @@ typedef struct { GValue *value; } TpChatProperty; -static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass); -static void empathy_tp_chat_init (EmpathyTpChat *chat); +static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass); +static void empathy_tp_chat_init (EmpathyTpChat *chat); +static void tp_chat_iface_init (EmpathyContactListIface *iface); enum { PROP_0, @@ -83,7 +87,9 @@ enum { static guint signals[LAST_SIGNAL]; -G_DEFINE_TYPE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_CODE (EmpathyTpChat, empathy_tp_chat, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST, + tp_chat_iface_init)); static void tp_chat_invalidated_cb (TpProxy *proxy, @@ -116,6 +122,92 @@ tp_chat_async_cb (TpChannel *proxy, } } +static void +tp_chat_member_added_cb (EmpathyTpGroup *group, + EmpathyContact *contact, + EmpathyContact *actor, + guint reason, + const gchar *message, + EmpathyTpChat *chat) +{ + g_signal_emit_by_name (chat, "members-changed", + contact, actor, reason, message, + TRUE); +} + +static void +tp_chat_member_removed_cb (EmpathyTpGroup *group, + EmpathyContact *contact, + EmpathyContact *actor, + guint reason, + const gchar *message, + EmpathyTpChat *chat) +{ + g_signal_emit_by_name (chat, "members-changed", + contact, actor, reason, message, + FALSE); +} +static void +tp_chat_local_pending_cb (EmpathyTpGroup *group, + EmpathyContact *contact, + EmpathyContact *actor, + guint reason, + const gchar *message, + EmpathyTpChat *chat) +{ + g_signal_emit_by_name (chat, "pendings-changed", + contact, actor, reason, message, + TRUE); +} + +static void +tp_chat_add (EmpathyContactList *list, + EmpathyContact *contact, + const gchar *message) +{ + EmpathyTpChatPriv *priv = GET_PRIV (list); + + g_return_if_fail (EMPATHY_IS_TP_CHAT (list)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + if (priv->group) { + empathy_tp_group_add_member (priv->group, contact, message); + } +} + +static void +tp_chat_remove (EmpathyContactList *list, + EmpathyContact *contact, + const gchar *message) +{ + EmpathyTpChatPriv *priv = GET_PRIV (list); + + g_return_if_fail (EMPATHY_IS_TP_CHAT (list)); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + if (priv->group) { + empathy_tp_group_remove_member (priv->group, contact, message); + } +} + +static GList * +tp_chat_get_members (EmpathyContactList *list) +{ + EmpathyTpChatPriv *priv = GET_PRIV (list); + GList *members = NULL; + + g_return_val_if_fail (EMPATHY_IS_TP_CHAT (list), NULL); + + if (priv->group) { + members = empathy_tp_group_get_members (priv->group); + } else { + members = g_list_prepend (members, g_object_ref (priv->user)); + members = g_list_prepend (members, g_object_ref (priv->initiator)); + } + + return members; +} + static EmpathyMessage * tp_chat_build_message (EmpathyTpChat *chat, guint type, @@ -697,15 +789,32 @@ tp_chat_constructor (GType type, g_object_get (priv->channel, "channel-ready", &channel_ready, NULL); if (channel_ready) { - /* FIXME: We do that in a cb to let time to set the acknowledge - * property, this property should be required for construct. */ - g_idle_add ((GSourceFunc) tp_chat_channel_ready_cb, chat); + tp_chat_channel_ready_cb (EMPATHY_TP_CHAT (chat)); } else { g_signal_connect_swapped (priv->channel, "notify::channel-ready", G_CALLBACK (tp_chat_channel_ready_cb), chat); } + if (tp_proxy_has_interface_by_id (priv->channel, + TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) { + priv->group = empathy_tp_group_new (priv->account, priv->tp_chan); + + g_signal_connect (priv->group, "member-added", + G_CALLBACK (tp_chat_member_added_cb), + chat); + g_signal_connect (priv->group, "member-removed", + G_CALLBACK (tp_chat_member_removed_cb), + chat); + g_signal_connect (priv->group, "local-pending", + G_CALLBACK (tp_chat_local_pending_cb), + chat); + } else { + priv->initiator = empathy_contact_factory_get_from_handle (priv->factory, + priv->account, + priv->tp_chan->handle); + } + return chat; } @@ -755,8 +864,7 @@ tp_chat_set_property (GObject *object, priv->channel = g_object_ref (g_value_get_object (value)); break; case PROP_ACKNOWLEDGE: - empathy_tp_chat_set_acknowledge (EMPATHY_TP_CHAT (object), - g_value_get_boolean (value)); + priv->acknowledge = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -808,7 +916,7 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass) "Wheter or not received messages should be acknowledged", FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + G_PARAM_CONSTRUCT_ONLY)); /* Signals */ signals[MESSAGE_RECEIVED] = @@ -869,9 +977,18 @@ empathy_tp_chat_init (EmpathyTpChat *chat) { } +static void +tp_chat_iface_init (EmpathyContactListIface *iface) +{ + iface->add = tp_chat_add; + iface->remove = tp_chat_remove; + iface->get_members = tp_chat_get_members; +} + EmpathyTpChat * empathy_tp_chat_new (McAccount *account, - TpChan *tp_chan) + TpChan *tp_chan, + gboolean acknowledge) { EmpathyTpChat *chat; TpChannel *channel; @@ -888,6 +1005,7 @@ empathy_tp_chat_new (McAccount *account, "account", account, "channel", channel, "tp-chan", tp_chan, + "acknowledge", acknowledge, NULL); g_object_unref (channel); @@ -932,7 +1050,7 @@ empathy_tp_chat_new_with_contact (EmpathyContact *contact) handle, TRUE); - chat = empathy_tp_chat_new (account, text_chan); + chat = empathy_tp_chat_new (account, text_chan, TRUE); g_object_unref (tp_conn); g_object_unref (text_chan); @@ -941,32 +1059,6 @@ empathy_tp_chat_new_with_contact (EmpathyContact *contact) return chat; } -gboolean -empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat) -{ - EmpathyTpChatPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), FALSE); - - priv = GET_PRIV (chat); - - return priv->acknowledge; -} - -void -empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat, - gboolean acknowledge) -{ - EmpathyTpChatPriv *priv; - - g_return_if_fail (EMPATHY_IS_TP_CHAT (chat)); - - priv = GET_PRIV (chat); - - priv->acknowledge = acknowledge; - g_object_notify (G_OBJECT (chat), "acknowledge"); -} - TpChan * empathy_tp_chat_get_channel (EmpathyTpChat *chat) { diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h index 4fb7f3997..72c0c0122 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -56,11 +56,9 @@ struct _EmpathyTpChatClass { GType empathy_tp_chat_get_type (void) G_GNUC_CONST; EmpathyTpChat *empathy_tp_chat_new (McAccount *account, - TpChan *tp_chan); -EmpathyTpChat *empathy_tp_chat_new_with_contact (EmpathyContact *contact); -gboolean empathy_tp_chat_get_acknowledge (EmpathyTpChat *chat); -void empathy_tp_chat_set_acknowledge (EmpathyTpChat *chat, + TpChan *tp_chan, gboolean acknowledge); +EmpathyTpChat *empathy_tp_chat_new_with_contact (EmpathyContact *contact); McAccount * empathy_tp_chat_get_account (EmpathyTpChat *chat); TpChan * empathy_tp_chat_get_channel (EmpathyTpChat *chat); void empathy_tp_chat_send (EmpathyTpChat *chat, diff --git a/libempathy/empathy-tp-chatroom.c b/libempathy/empathy-tp-chatroom.c deleted file mode 100644 index de0a684c0..000000000 --- a/libempathy/empathy-tp-chatroom.c +++ /dev/null @@ -1,279 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2007-2008 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens <xclaesse@gmail.com> - */ - -#include <config.h> - -#include "empathy-tp-chatroom.h" -#include "empathy-contact-list.h" -#include "empathy-tp-group.h" -#include "empathy-utils.h" -#include "empathy-debug.h" - -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroomPriv)) - -#define DEBUG_DOMAIN "TpChatroom" - -struct _EmpathyTpChatroomPriv { - EmpathyTpGroup *group; - - gboolean is_invited; - EmpathyContact *invitor; - gchar *invit_message; -}; - -static void empathy_tp_chatroom_class_init (EmpathyTpChatroomClass *klass); -static void tp_chatroom_iface_init (EmpathyContactListIface *iface); -static void empathy_tp_chatroom_init (EmpathyTpChatroom *chatroom); - -G_DEFINE_TYPE_WITH_CODE (EmpathyTpChatroom, empathy_tp_chatroom, EMPATHY_TYPE_TP_CHAT, - G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CONTACT_LIST, - tp_chatroom_iface_init)); - -static void -tp_chatroom_member_added_cb (EmpathyTpGroup *group, - EmpathyContact *contact, - EmpathyContact *actor, - guint reason, - const gchar *message, - EmpathyTpChatroom *chatroom) -{ - g_signal_emit_by_name (chatroom, "members-changed", - contact, actor, reason, message, - TRUE); -} - -static void -tp_chatroom_member_removed_cb (EmpathyTpGroup *group, - EmpathyContact *contact, - EmpathyContact *actor, - guint reason, - const gchar *message, - EmpathyTpChatroom *chatroom) -{ - g_signal_emit_by_name (chatroom, "members-changed", - contact, actor, reason, message, - FALSE); -} -static void -tp_chatroom_local_pending_cb (EmpathyTpGroup *group, - EmpathyContact *contact, - EmpathyContact *actor, - guint reason, - const gchar *message, - EmpathyTpChatroom *chatroom) -{ - EmpathyTpChatroomPriv *priv = GET_PRIV (chatroom); - - if (empathy_contact_is_user (contact)) { - priv->invitor = g_object_ref (actor); - priv->invit_message = g_strdup (message); - priv->is_invited = TRUE; - - empathy_debug (DEBUG_DOMAIN, "We are invited to join by %s (%d): %s", - empathy_contact_get_id (priv->invitor), - empathy_contact_get_handle (priv->invitor), - priv->invit_message); - } -} - -static void -tp_chatroom_add (EmpathyContactList *list, - EmpathyContact *contact, - const gchar *message) -{ - EmpathyTpChatroomPriv *priv; - - g_return_if_fail (EMPATHY_IS_TP_CHATROOM (list)); - g_return_if_fail (EMPATHY_IS_CONTACT (contact)); - - priv = GET_PRIV (list); - - empathy_tp_group_add_member (priv->group, contact, message); -} - -static void -tp_chatroom_remove (EmpathyContactList *list, - EmpathyContact *contact, - const gchar *message) -{ - EmpathyTpChatroomPriv *priv; - - g_return_if_fail (EMPATHY_IS_TP_CHATROOM (list)); - g_return_if_fail (EMPATHY_IS_CONTACT (contact)); - - priv = GET_PRIV (list); - - empathy_tp_group_remove_member (priv->group, contact, message); -} - -static GList * -tp_chatroom_get_members (EmpathyContactList *list) -{ - EmpathyTpChatroomPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_TP_CHATROOM (list), NULL); - - priv = GET_PRIV (list); - - return empathy_tp_group_get_members (priv->group); -} - -static void -tp_chatroom_finalize (GObject *object) -{ - EmpathyTpChatroomPriv *priv; - EmpathyTpChatroom *chatroom; - - chatroom = EMPATHY_TP_CHATROOM (object); - priv = GET_PRIV (chatroom); - - g_object_unref (priv->group); - - if (priv->invitor) { - g_object_unref (priv->invitor); - } - - g_free (priv->invit_message); - - G_OBJECT_CLASS (empathy_tp_chatroom_parent_class)->finalize (object); -} - -static void -empathy_tp_chatroom_class_init (EmpathyTpChatroomClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = tp_chatroom_finalize; - - g_type_class_add_private (object_class, sizeof (EmpathyTpChatroomPriv)); -} - -static void -tp_chatroom_iface_init (EmpathyContactListIface *iface) -{ - iface->add = tp_chatroom_add; - iface->remove = tp_chatroom_remove; - iface->get_members = tp_chatroom_get_members; -} - -static void -empathy_tp_chatroom_init (EmpathyTpChatroom *chatroom) -{ -} - -EmpathyTpChatroom * -empathy_tp_chatroom_new (McAccount *account, - TpChan *tp_chan) -{ - EmpathyTpChatroomPriv *priv; - EmpathyTpChatroom *chatroom; - TpChannel *channel; - TpConnection *connection; - MissionControl *mc; - TpConn *tp_conn; - - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); - - mc = empathy_mission_control_new (); - tp_conn = mission_control_get_connection (mc, account, NULL); - connection = tp_conn_dup_connection (tp_conn); - channel = tp_chan_dup_channel (tp_chan, connection, NULL); - - chatroom = g_object_new (EMPATHY_TYPE_TP_CHATROOM, - "account", account, - "channel", channel, - "tp-chan", tp_chan, - NULL); - - priv = GET_PRIV (chatroom); - - priv->group = empathy_tp_group_new (account, tp_chan); - - g_signal_connect (priv->group, "member-added", - G_CALLBACK (tp_chatroom_member_added_cb), - chatroom); - g_signal_connect (priv->group, "member-removed", - G_CALLBACK (tp_chatroom_member_removed_cb), - chatroom); - g_signal_connect (priv->group, "local-pending", - G_CALLBACK (tp_chatroom_local_pending_cb), - chatroom); - - g_object_unref (channel); - g_object_unref (tp_conn); - g_object_unref (connection); - g_object_unref (mc); - - return chatroom; -} - -gboolean -empathy_tp_chatroom_get_invitation (EmpathyTpChatroom *chatroom, - EmpathyContact **contact, - const gchar **message) -{ - EmpathyTpChatroomPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_TP_CHATROOM (chatroom), FALSE); - - priv = GET_PRIV (chatroom); - - if (contact) { - *contact = priv->invitor; - } - if (message) { - *message = priv->invit_message; - } - - return priv->is_invited; -} - -void -empathy_tp_chatroom_accept_invitation (EmpathyTpChatroom *chatroom) -{ - EmpathyTpChatroomPriv *priv; - EmpathyContact *user; - - g_return_if_fail (EMPATHY_IS_TP_CHATROOM (chatroom)); - - priv = GET_PRIV (chatroom); - - if (!priv->is_invited) { - return; - } - - /* Clear invitation data */ - priv->is_invited = FALSE; - if (priv->invitor) { - g_object_unref (priv->invitor); - priv->invitor = NULL; - } - g_free (priv->invit_message); - priv->invit_message = NULL; - - /* Add ourself in the members of the room */ - user = empathy_tp_group_get_self_contact (priv->group); - empathy_tp_group_add_member (priv->group, user, ""); - g_object_unref (user); -} - diff --git a/libempathy/empathy-tp-chatroom.h b/libempathy/empathy-tp-chatroom.h deleted file mode 100644 index 85bcf6f81..000000000 --- a/libempathy/empathy-tp-chatroom.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2007 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens <xclaesse@gmail.com> - */ - -#ifndef __EMPATHY_TP_CHATROOM_H__ -#define __EMPATHY_TP_CHATROOM_H__ - -#include <glib.h> - -#include <libtelepathy/tp-chan.h> - -#include <libmissioncontrol/mc-account.h> - -#include "empathy-tp-chat.h" - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_TP_CHATROOM (empathy_tp_chatroom_get_type ()) -#define EMPATHY_TP_CHATROOM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroom)) -#define EMPATHY_TP_CHATROOM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroomClass)) -#define EMPATHY_IS_TP_CHATROOM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_TP_CHATROOM)) -#define EMPATHY_IS_TP_CHATROOM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_TP_CHATROOM)) -#define EMPATHY_TP_CHATROOM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_TP_CHATROOM, EmpathyTpChatroomClass)) - -typedef struct _EmpathyTpChatroom EmpathyTpChatroom; -typedef struct _EmpathyTpChatroomClass EmpathyTpChatroomClass; -typedef struct _EmpathyTpChatroomPriv EmpathyTpChatroomPriv; - -struct _EmpathyTpChatroom { - EmpathyTpChat parent; -}; - -struct _EmpathyTpChatroomClass { - EmpathyTpChatClass parent_class; -}; - -GType empathy_tp_chatroom_get_type (void) G_GNUC_CONST; -EmpathyTpChatroom *empathy_tp_chatroom_new (McAccount *account, - TpChan *tp_chan); -gboolean empathy_tp_chatroom_get_invitation (EmpathyTpChatroom *chatroom, - EmpathyContact **contact, - const gchar **message); -void empathy_tp_chatroom_accept_invitation (EmpathyTpChatroom *chatroom); -G_END_DECLS - -#endif /* __EMPATHY_TP_CHATROOM_H__ */ |