[Telepathy-commits] [telepathy-glib/master] channelspecific example room: implement TpExportableChannel

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Jan 7 07:23:57 PST 2009


Also accept 'initiator-handle' as a construct-time property.
---
 examples/cm/channelspecific/room.c |   50 +++++++++++++++++++++++++++++++-----
 1 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/examples/cm/channelspecific/room.c b/examples/cm/channelspecific/room.c
index 8e4a287..2eaa846 100644
--- a/examples/cm/channelspecific/room.c
+++ b/examples/cm/channelspecific/room.c
@@ -30,6 +30,7 @@ G_DEFINE_TYPE_WITH_CODE (ExampleCSHRoomChannel,
       tp_group_mixin_iface_init);
     G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
       tp_dbus_properties_mixin_iface_init);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL);
     G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL))
 
 /* type definition stuff */
@@ -46,6 +47,8 @@ enum
   PROP_INITIATOR_ID,
   PROP_CONNECTION,
   PROP_INTERFACES,
+  PROP_CHANNEL_DESTROYED,
+  PROP_CHANNEL_PROPERTIES,
   N_PROPS
 };
 
@@ -54,6 +57,7 @@ struct _ExampleCSHRoomChannelPrivate
   TpBaseConnection *conn;
   gchar *object_path;
   TpHandle handle;
+  TpHandle initiator;
 
   /* These are really booleans, but gboolean is signed. Thanks, GLib */
   unsigned closed:1;
@@ -254,6 +258,9 @@ constructor (GType type,
 
   tp_handle_ref (room_repo, self->priv->handle);
 
+  if (self->priv->initiator != 0)
+    tp_handle_ref (contact_repo, self->priv->initiator);
+
   bus = tp_get_bus ();
   dbus_g_connection_register_g_object (bus, self->priv->object_path, object);
 
@@ -324,19 +331,17 @@ get_property (GObject *object,
       g_value_set_boolean (value, TRUE);
       break;
     case PROP_INITIATOR_HANDLE:
-      /* this example CM doesn't yet support being invited into a chatroom,
-       * so the only way a channel can exist is if the user asked for it */
-      g_value_set_uint (value, self->priv->conn->self_handle);
+      g_value_set_uint (value, self->priv->initiator);
       break;
     case PROP_INITIATOR_ID:
         {
-          /* this example CM doesn't yet support being invited into a chatroom,
-           * so the only way a channel can exist is if the user asked for it */
           TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
               self->priv->conn, TP_HANDLE_TYPE_CONTACT);
 
           g_value_set_string (value,
-              tp_handle_inspect (contact_repo, self->priv->conn->self_handle));
+              self->priv->initiator == 0
+                  ? ""
+                  : tp_handle_inspect (contact_repo, self->priv->initiator));
         }
       break;
     case PROP_CONNECTION:
@@ -345,6 +350,22 @@ get_property (GObject *object,
     case PROP_INTERFACES:
       g_value_set_boxed (value, example_csh_room_channel_interfaces);
       break;
+    case PROP_CHANNEL_DESTROYED:
+      g_value_set_boolean (value, self->priv->closed);
+      break;
+    case PROP_CHANNEL_PROPERTIES:
+      g_value_take_boxed (value,
+          tp_dbus_properties_mixin_make_properties_hash (object,
+              TP_IFACE_CHANNEL, "ChannelType",
+              TP_IFACE_CHANNEL, "TargetHandleType",
+              TP_IFACE_CHANNEL, "TargetHandle",
+              TP_IFACE_CHANNEL, "TargetID",
+              TP_IFACE_CHANNEL, "InitiatorHandle",
+              TP_IFACE_CHANNEL, "InitiatorID",
+              TP_IFACE_CHANNEL, "Requested",
+              TP_IFACE_CHANNEL, "Interfaces",
+              NULL));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -371,6 +392,10 @@ set_property (GObject *object,
        */
       self->priv->handle = g_value_get_uint (value);
       break;
+    case PROP_INITIATOR_HANDLE:
+      /* similarly, we don't yet have the contact repo */
+      self->priv->initiator = g_value_get_uint (value);
+      break;
     case PROP_HANDLE_TYPE:
     case PROP_CHANNEL_TYPE:
       /* these properties are writable in the interface, but not actually
@@ -397,6 +422,7 @@ dispose (GObject *object)
 
   if (!self->priv->closed)
     {
+      self->priv->closed = TRUE;
       tp_svc_channel_emit_closed (self);
     }
 
@@ -407,9 +433,14 @@ static void
 finalize (GObject *object)
 {
   ExampleCSHRoomChannel *self = EXAMPLE_CSH_ROOM_CHANNEL (object);
+  TpHandleRepoIface *contact_handles = tp_base_connection_get_handles
+      (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
   TpHandleRepoIface *room_handles = tp_base_connection_get_handles
       (self->priv->conn, TP_HANDLE_TYPE_ROOM);
 
+  if (self->priv->initiator != 0)
+    tp_handle_unref (contact_handles, self->priv->initiator);
+
   tp_handle_unref (room_handles, self->priv->handle);
   g_free (self->priv->object_path);
 
@@ -473,6 +504,11 @@ example_csh_room_channel_class_init (ExampleCSHRoomChannelClass *klass)
       "handle-type");
   g_object_class_override_property (object_class, PROP_HANDLE, "handle");
 
+  g_object_class_override_property (object_class, PROP_CHANNEL_DESTROYED,
+      "channel-destroyed");
+  g_object_class_override_property (object_class, PROP_CHANNEL_PROPERTIES,
+      "channel-properties");
+
   param_spec = g_param_spec_object ("connection", "TpBaseConnection object",
       "Connection object that owns this channel",
       TP_TYPE_BASE_CONNECTION,
@@ -494,7 +530,7 @@ example_csh_room_channel_class_init (ExampleCSHRoomChannelClass *klass)
   param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
       "The contact who initiated the channel",
       0, G_MAXUINT32, 0,
-      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
       param_spec);
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list