#include <config.h>
-#include <libtelepathy/tp-helpers.h>
+#include <string.h>
+
#include <libtelepathy/tp-chan-type-text-gen.h>
#include <libtelepathy/tp-chan-iface-chat-state-gen.h>
#include <libtelepathy/tp-conn.h>
+#include <libtelepathy/tp-helpers.h>
#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))
#define DEBUG_DOMAIN "TpChat"
struct _EmpathyTpChatPriv {
- EmpathyContactList *list;
+ EmpathyTpContactList *list;
EmpathyContactManager *manager;
McAccount *account;
gchar *id;
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,
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",
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",
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)
{
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) {
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);
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)) {
}
/* 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
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),
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);