X-Git-Url: https://git.0d.be/?p=empathy.git;a=blobdiff_plain;f=libempathy%2Fempathy-tp-chat.c;h=8e8a52acad2219f5bde44bbde78aba34f4ab6b18;hp=4729cc267ca8c1052c6e1cd4be03e6865a62e73b;hb=1ff555e581a89646fa252706d41ae822d1e023e4;hpb=ae195f5e93d0f92e0c7714b5b27be8d1740803aa diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 4729cc26..8e8a52ac 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -22,17 +22,20 @@ #include -#include +#include + #include #include #include +#include #include "empathy-tp-chat.h" #include "empathy-contact-manager.h" -#include "empathy-contact-list.h" +#include "empathy-tp-contact-list.h" #include "empathy-marshal.h" #include "gossip-debug.h" #include "gossip-time.h" +#include "gossip-utils.h" #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_TP_CHAT, EmpathyTpChatPriv)) @@ -40,7 +43,7 @@ #define DEBUG_DOMAIN "TpChat" struct _EmpathyTpChatPriv { - EmpathyContactList *list; + EmpathyTpContactList *list; EmpathyContactManager *manager; McAccount *account; gchar *id; @@ -51,35 +54,51 @@ struct _EmpathyTpChatPriv { DBusGProxy *chat_state_iface; }; -static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass); -static void empathy_tp_chat_init (EmpathyTpChat *chat); -static void tp_chat_finalize (GObject *object); -static void tp_chat_destroy_cb (TpChan *text_chan, - EmpathyTpChat *chat); -static void tp_chat_closed_cb (TpChan *text_chan, - EmpathyTpChat *chat); -static void tp_chat_received_cb (DBusGProxy *text_iface, - guint message_id, - guint timestamp, - guint from_handle, - guint message_type, - guint message_flags, - gchar *message_body, - EmpathyTpChat *chat); -static void tp_chat_sent_cb (DBusGProxy *text_iface, - guint timestamp, - guint message_type, - gchar *message_body, - EmpathyTpChat *chat); -static void tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, - guint handle, - TelepathyChannelChatState state, - EmpathyTpChat *chat); -static void tp_chat_emit_message (EmpathyTpChat *chat, - guint type, - guint timestamp, - guint from_handle, - const gchar *message_body); +static void empathy_tp_chat_class_init (EmpathyTpChatClass *klass); +static void empathy_tp_chat_init (EmpathyTpChat *chat); +static void tp_chat_finalize (GObject *object); +static GObject * tp_chat_constructor (GType type, + guint n_props, + GObjectConstructParam *props); +static void tp_chat_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void tp_chat_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); +static void tp_chat_destroy_cb (TpChan *text_chan, + EmpathyTpChat *chat); +static void tp_chat_closed_cb (TpChan *text_chan, + EmpathyTpChat *chat); +static void tp_chat_received_cb (DBusGProxy *text_iface, + guint message_id, + guint timestamp, + guint from_handle, + guint message_type, + guint message_flags, + gchar *message_body, + EmpathyTpChat *chat); +static void tp_chat_sent_cb (DBusGProxy *text_iface, + guint timestamp, + guint message_type, + gchar *message_body, + EmpathyTpChat *chat); +static void tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, + guint handle, + TelepathyChannelChatState state, + EmpathyTpChat *chat); +static void tp_chat_emit_message (EmpathyTpChat *chat, + guint type, + guint timestamp, + guint from_handle, + const gchar *message_body); +enum { + PROP_0, + PROP_ACCOUNT, + PROP_TP_CHAN +}; enum { MESSAGE_RECEIVED, @@ -98,6 +117,27 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = tp_chat_finalize; + object_class->constructor = tp_chat_constructor; + object_class->get_property = tp_chat_get_property; + object_class->set_property = tp_chat_set_property; + + g_object_class_install_property (object_class, + PROP_ACCOUNT, + g_param_spec_object ("account", + "channel Account", + "The account associated with the channel", + MC_TYPE_ACCOUNT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_TP_CHAN, + g_param_spec_object ("tp-chan", + "telepathy channel", + "The text channel for the chat", + TELEPATHY_CHAN_TYPE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); signals[MESSAGE_RECEIVED] = g_signal_new ("message-received", @@ -181,29 +221,26 @@ tp_chat_finalize (GObject *object) G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object); } -EmpathyTpChat * -empathy_tp_chat_new (McAccount *account, - TpChan *tp_chan) +static GObject * +tp_chat_constructor (GType type, + guint n_props, + GObjectConstructParam *props) { - EmpathyTpChatPriv *priv; - EmpathyTpChat *chat; + GObject *chat; + EmpathyTpChatPriv *priv; - g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); + chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props); - chat = g_object_new (EMPATHY_TYPE_TP_CHAT, NULL); priv = GET_PRIV (chat); priv->manager = empathy_contact_manager_new (); - priv->list = empathy_contact_manager_get_list (priv->manager, account); - priv->tp_chan = g_object_ref (tp_chan); - priv->account = g_object_ref (account); - priv->mc = mission_control_new (tp_get_bus ()); + priv->list = empathy_contact_manager_get_list (priv->manager, priv->account); + priv->mc = gossip_mission_control_new (); g_object_ref (priv->list); - priv->text_iface = tp_chan_get_interface (tp_chan, + priv->text_iface = tp_chan_get_interface (priv->tp_chan, TELEPATHY_CHAN_IFACE_TEXT_QUARK); - priv->chat_state_iface = tp_chan_get_interface (tp_chan, + priv->chat_state_iface = tp_chan_get_interface (priv->tp_chan, TELEPATHY_CHAN_IFACE_CHAT_STATE_QUARK); g_signal_connect (priv->tp_chan, "destroy", @@ -229,6 +266,62 @@ empathy_tp_chat_new (McAccount *account, return chat; } +static void +tp_chat_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyTpChatPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ACCOUNT: + g_value_set_object (value, priv->account); + break; + case PROP_TP_CHAN: + g_value_set_object (value, priv->tp_chan); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +tp_chat_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyTpChatPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ACCOUNT: + priv->account = g_object_ref (g_value_get_object (value)); + break; + case PROP_TP_CHAN: + priv->tp_chan = g_object_ref (g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +EmpathyTpChat * +empathy_tp_chat_new (McAccount *account, + TpChan *tp_chan) +{ + return g_object_new (EMPATHY_TYPE_TP_CHAT, + "account", account, + "tp-chan", tp_chan, + NULL); +} + EmpathyTpChat * empathy_tp_chat_new_with_contact (GossipContact *contact) { @@ -242,7 +335,7 @@ empathy_tp_chat_new_with_contact (GossipContact *contact) g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL); - mc = mission_control_new (tp_get_bus ()); + mc = gossip_mission_control_new (); account = gossip_contact_get_account (contact); if (mission_control_get_connection_status (mc, account, NULL) != 0) { @@ -385,11 +478,7 @@ empathy_tp_chat_set_state (EmpathyTpChat *chat, const gchar * empathy_tp_chat_get_id (EmpathyTpChat *chat) { - EmpathyTpChatPriv *priv; - TpConn *tp_conn; - GArray *handles; - gchar **names; - GError *error = NULL; + EmpathyTpChatPriv *priv; g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL); @@ -399,12 +488,33 @@ empathy_tp_chat_get_id (EmpathyTpChat *chat) return priv->id; } - tp_conn = mission_control_get_connection (priv->mc, priv->account, NULL); - handles = g_array_new (FALSE, FALSE, sizeof (guint)); - g_array_append_val (handles, priv->tp_chan->handle); + priv->id = empathy_tp_chat_build_id (priv->account, priv->tp_chan); + + return priv->id; +} +gchar * +empathy_tp_chat_build_id (McAccount *account, + TpChan *tp_chan) +{ + MissionControl *mc; + TpConn *tp_conn; + GArray *handles; + gchar **names; + gchar *id; + GError *error = NULL; + + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL); + + mc = gossip_mission_control_new (); + tp_conn = mission_control_get_connection (mc, account, NULL); + g_object_unref (mc); + + handles = g_array_new (FALSE, FALSE, sizeof (guint)); + g_array_append_val (handles, tp_chan->handle); if (!tp_conn_inspect_handles (DBUS_G_PROXY (tp_conn), - priv->tp_chan->handle_type, + tp_chan->handle_type, handles, &names, &error)) { @@ -419,14 +529,14 @@ empathy_tp_chat_get_id (EmpathyTpChat *chat) } /* A handle name is unique only for a specific account */ - priv->id = g_strdup_printf ("%s/%s", - mc_account_get_unique_name (priv->account), - *names); + id = g_strdup_printf ("%s/%s", + mc_account_get_unique_name (account), + *names); g_strfreev (names); g_object_unref (tp_conn); - return priv->id; + return id; } static void @@ -520,7 +630,7 @@ tp_chat_state_changed_cb (DBusGProxy *chat_state_iface, priv = GET_PRIV (chat); - contact = empathy_contact_list_get_from_handle (priv->list, handle); + contact = empathy_tp_contact_list_get_from_handle (priv->list, handle); gossip_debug (DEBUG_DOMAIN, "Chat state changed for %s (%d): %d", gossip_contact_get_name (contact), @@ -546,11 +656,11 @@ tp_chat_emit_message (EmpathyTpChat *chat, priv = GET_PRIV (chat); if (from_handle == 0) { - sender = empathy_contact_list_get_own (priv->list); + sender = empathy_tp_contact_list_get_user (priv->list); g_object_ref (sender); } else { - sender = empathy_contact_list_get_from_handle (priv->list, - from_handle); + sender = empathy_tp_contact_list_get_from_handle (priv->list, + from_handle); } message = gossip_message_new (message_body);