[Telepathy-commits] [telepathy-haze/master] HazeIMChannel: implement InitiatorHandle, InitiatorID, Requested
Simon McVittie
"http://smcv.pseudorandom.co.uk/" at dhansak.collabora.co.uk
Thu Oct 16 03:31:48 PDT 2008
Also use G_PARAM_STATIC_STRINGS.
---
src/im-channel-factory.c | 24 +++++++++------
src/im-channel.c | 70 ++++++++++++++++++++++++++++++++++++++--------
2 files changed, 72 insertions(+), 22 deletions(-)
diff --git a/src/im-channel-factory.c b/src/im-channel-factory.c
index 1d9b207..a06ecbd 100644
--- a/src/im-channel-factory.c
+++ b/src/im-channel-factory.c
@@ -57,10 +57,8 @@ enum {
LAST_PROPERTY
};
-static HazeIMChannel *
-get_im_channel (HazeImChannelFactory *self,
- TpHandle handle,
- gboolean *created);
+static HazeIMChannel *get_im_channel (HazeImChannelFactory *self,
+ TpHandle handle, TpHandle initiator, gboolean *created);
static void
conversation_updated_cb (PurpleConversation *conv,
@@ -103,7 +101,8 @@ conversation_updated_cb (PurpleConversation *conv,
g_assert_not_reached ();
}
- chan = get_im_channel (im_factory, ui_data->contact_handle, NULL);
+ chan = get_im_channel (im_factory, ui_data->contact_handle,
+ ui_data->contact_handle, NULL);
tp_svc_channel_interface_chat_state_emit_chat_state_changed (
(TpSvcChannelInterfaceChatState*)chan, ui_data->contact_handle, state);
@@ -229,7 +228,8 @@ im_channel_closed_cb (HazeIMChannel *chan, gpointer user_data)
static HazeIMChannel *
new_im_channel (HazeImChannelFactory *self,
- guint handle)
+ TpHandle handle,
+ TpHandle initiator)
{
HazeImChannelFactoryPrivate *priv;
TpBaseConnection *conn;
@@ -249,6 +249,7 @@ new_im_channel (HazeImChannelFactory *self,
"connection", priv->conn,
"object-path", object_path,
"handle", handle,
+ "initiator-handle", initiator,
NULL);
DEBUG ("Created IM channel with object path %s", object_path);
@@ -268,6 +269,7 @@ new_im_channel (HazeImChannelFactory *self,
static HazeIMChannel *
get_im_channel (HazeImChannelFactory *self,
TpHandle handle,
+ TpHandle initiator,
gboolean *created)
{
HazeImChannelFactoryPrivate *priv =
@@ -282,7 +284,7 @@ get_im_channel (HazeImChannelFactory *self,
}
else
{
- chan = new_im_channel (self, handle);
+ chan = new_im_channel (self, handle, initiator);
if (created)
*created = TRUE;
}
@@ -363,8 +365,9 @@ haze_im_channel_factory_iface_request (TpChannelFactoryIface *iface,
HazeImChannelFactory *self = HAZE_IM_CHANNEL_FACTORY (iface);
HazeImChannelFactoryPrivate *priv =
HAZE_IM_CHANNEL_FACTORY_GET_PRIVATE (self);
+ TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
- (TpBaseConnection *)priv->conn, TP_HANDLE_TYPE_CONTACT);
+ base_conn, TP_HANDLE_TYPE_CONTACT);
HazeIMChannel *chan;
TpChannelFactoryRequestStatus status;
gboolean created;
@@ -378,7 +381,7 @@ haze_im_channel_factory_iface_request (TpChannelFactoryIface *iface,
if (!tp_handle_is_valid (contact_repo, handle, error))
return TP_CHANNEL_FACTORY_REQUEST_STATUS_ERROR;
- chan = get_im_channel (self, handle, &created);
+ chan = get_im_channel (self, handle, base_conn->self_handle, &created);
if (created)
{
status = TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED;
@@ -435,7 +438,8 @@ haze_write_im (PurpleConversation *conv,
else if (purple_message_meify(message, -1))
type = TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION;
- chan = get_im_channel (im_factory, ui_data->contact_handle, NULL);
+ chan = get_im_channel (im_factory, ui_data->contact_handle,
+ ui_data->contact_handle, NULL);
if (flags & PURPLE_MESSAGE_RECV)
tp_text_mixin_receive (G_OBJECT (chan), type, ui_data->contact_handle,
diff --git a/src/im-channel.c b/src/im-channel.c
index 518f807..5cdb499 100644
--- a/src/im-channel.c
+++ b/src/im-channel.c
@@ -38,6 +38,9 @@ enum
PROP_HANDLE,
PROP_TARGET_ID,
PROP_INTERFACES,
+ PROP_INITIATOR_HANDLE,
+ PROP_INITIATOR_ID,
+ PROP_REQUESTED,
LAST_PROPERTY
};
@@ -46,7 +49,8 @@ typedef struct _HazeIMChannelPrivate
{
HazeConnection *conn;
char *object_path;
- guint handle;
+ TpHandle handle;
+ TpHandle initiator;
PurpleConversation *conv;
@@ -371,6 +375,21 @@ haze_im_channel_get_property (GObject *object,
g_value_set_string (value, tp_handle_inspect (repo, priv->handle));
break;
}
+ case PROP_INITIATOR_HANDLE:
+ g_value_set_uint (value, priv->initiator);
+ break;
+ case PROP_INITIATOR_ID:
+ {
+ TpHandleRepoIface *repo = tp_base_connection_get_handles (base_conn,
+ TP_HANDLE_TYPE_CONTACT);
+
+ g_value_set_string (value, tp_handle_inspect (repo, priv->initiator));
+ break;
+ }
+ case PROP_REQUESTED:
+ g_value_set_boolean (value,
+ (priv->initiator == base_conn->self_handle));
+ break;
case PROP_CONNECTION:
g_value_set_object (value, priv->conn);
break;
@@ -403,6 +422,10 @@ haze_im_channel_set_property (GObject *object,
*/
priv->handle = g_value_get_uint (value);
break;
+ case PROP_INITIATOR_HANDLE:
+ /* similarly we can't ref this yet */
+ priv->initiator = g_value_get_uint (value);
+ break;
case PROP_CHANNEL_TYPE:
case PROP_HANDLE_TYPE:
/* this property is writable in the interface, but not actually
@@ -437,6 +460,9 @@ haze_im_channel_constructor (GType type, guint n_props,
contact_handles = tp_base_connection_get_handles (conn,
TP_HANDLE_TYPE_CONTACT);
tp_handle_ref (contact_handles, priv->handle);
+ g_assert (priv->initiator != 0);
+ tp_handle_ref (contact_handles, priv->initiator);
+
tp_text_mixin_init (obj, G_STRUCT_OFFSET (HazeIMChannel, text),
contact_handles);
@@ -469,6 +495,9 @@ haze_im_channel_dispose (GObject *obj)
if (priv->handle != 0)
tp_handle_unref (contact_handles, priv->handle);
+ if (priv->initiator != 0)
+ tp_handle_unref (contact_handles, priv->initiator);
+
if (!priv->closed)
{
purple_conversation_destroy (priv->conv);
@@ -493,6 +522,9 @@ haze_im_channel_class_init (HazeIMChannelClass *klass)
{ "TargetID", "target-id", NULL },
{ "ChannelType", "channel-type", NULL },
{ "Interfaces", "interfaces", NULL },
+ { "Requested", "requested", NULL },
+ { "InitiatorHandle", "initiator-handle", NULL },
+ { "InitiatorID", "initiator-id", NULL },
{ NULL }
};
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
@@ -522,29 +554,43 @@ haze_im_channel_class_init (HazeIMChannelClass *klass)
"handle");
param_spec = g_param_spec_object ("connection", "HazeConnection object",
- "Haze connection object that owns this "
- "IM channel object.",
- HAZE_TYPE_CONNECTION,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB);
+ "Haze connection object that owns this IM channel object.",
+ HAZE_TYPE_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
"Additional Channel.Interface.* interfaces",
G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
param_spec = g_param_spec_string ("target-id", "Other person's username",
"The username of the other person in the conversation",
NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_TARGET_ID, param_spec);
+ param_spec = g_param_spec_boolean ("requested", "Requested?",
+ "True if this channel was requested by the local user",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_REQUESTED, param_spec);
+
+ param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
+ "The contact who initiated the channel",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
+ param_spec);
+
+ param_spec = g_param_spec_string ("initiator-id", "Initiator's bare JID",
+ "The string obtained by inspecting the initiator-handle",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INITIATOR_ID,
+ param_spec);
+
tp_text_mixin_class_init (object_class,
G_STRUCT_OFFSET(HazeIMChannelClass, text_class));
--
1.5.6.5
More information about the Telepathy-commits
mailing list