diff options
Diffstat (limited to 'examples/cm/call/conn.c')
-rw-r--r-- | examples/cm/call/conn.c | 88 |
1 files changed, 65 insertions, 23 deletions
diff --git a/examples/cm/call/conn.c b/examples/cm/call/conn.c index 3dd0e0a40..eb95cc2cc 100644 --- a/examples/cm/call/conn.c +++ b/examples/cm/call/conn.c @@ -59,16 +59,47 @@ struct _ExampleCallConnectionPrivate guint simulation_delay; gboolean away; gchar *presence_message; + GPtrArray *statuses; +}; + +/* Must be kept in sync with ExampleCallPresence enum in header */ +static const struct { + const gchar *name; + TpConnectionPresenceType type; + gboolean on_self; + gboolean has_message; +} presence_statuses[] = { + { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, FALSE }, + { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, FALSE }, + { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, FALSE }, + { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, TRUE }, + { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, TRUE }, + { NULL } }; static void example_call_connection_init (ExampleCallConnection *self) { + guint i; + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EXAMPLE_TYPE_CALL_CONNECTION, ExampleCallConnectionPrivate); self->priv->away = FALSE; self->priv->presence_message = g_strdup (""); + + self->priv->statuses = g_ptr_array_new_full (N_EXAMPLE_CALL_PRESENCES, + (GDestroyNotify) tp_presence_status_spec_unref); + + for (i = 0; i < N_EXAMPLE_CALL_PRESENCES; i++) + { + g_ptr_array_add (self->priv->statuses, + tp_presence_status_spec_new (presence_statuses[i].name, + presence_statuses[i].type, presence_statuses[i].on_self, + presence_statuses[i].has_message, i)); + } + + g_assert (presence_statuses[N_EXAMPLE_CALL_PRESENCES].name == NULL); } static void @@ -137,6 +168,7 @@ finalize (GObject *object) g_free (self->priv->account); g_free (self->priv->presence_message); + g_ptr_array_unref (self->priv->statuses); G_OBJECT_CLASS (example_call_connection_parent_class)->finalize (object); } @@ -224,13 +256,13 @@ shut_down (TpBaseConnection *conn) static gboolean status_available (TpPresenceMixin *mixin, - guint index_) + TpPresenceStatusSpec *spec) { return tp_base_connection_check_connected (TP_BASE_CONNECTION (mixin), NULL); } static TpPresenceStatus * -get_contact_status (TpPresenceMixin *mixin, +dup_contact_status (TpPresenceMixin *mixin, TpHandle contact) { ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (mixin); @@ -252,21 +284,24 @@ get_contact_status (TpPresenceMixin *mixin, message = NULL; } - return tp_presence_status_new (presence, message); + return tp_presence_status_new (g_ptr_array_index ( + self->priv->statuses, presence), message); } static gboolean set_own_status (TpPresenceMixin *mixin, - const TpPresenceStatus *status, + TpPresenceStatus *status, GError **error) { ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (mixin); TpBaseConnection *base = TP_BASE_CONNECTION (mixin); GHashTable *presences; + const gchar *message = tp_presence_status_get_message (status); - if (status->index == EXAMPLE_CALL_PRESENCE_AWAY) + if (tp_presence_status_spec_get_id (tp_presence_status_get_spec (status)) + == EXAMPLE_CALL_PRESENCE_AWAY) { - if (self->priv->away && !tp_strdiff (status->message, + if (self->priv->away && !tp_strdiff (message, self->priv->presence_message)) return TRUE; @@ -274,7 +309,7 @@ set_own_status (TpPresenceMixin *mixin, } else { - if (!self->priv->away && !tp_strdiff (status->message, + if (!self->priv->away && !tp_strdiff (message, self->priv->presence_message)) return TRUE; @@ -282,34 +317,26 @@ set_own_status (TpPresenceMixin *mixin, } g_free (self->priv->presence_message); - self->priv->presence_message = g_strdup (status->message); + self->priv->presence_message = g_strdup (message); presences = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); g_hash_table_insert (presences, GUINT_TO_POINTER (tp_base_connection_get_self_handle (base)), - (gpointer) status); - tp_presence_mixin_emit_presence_update (TP_PRESENCE_MIXIN (self), presences); + status); + tp_presence_mixin_emit_presence_update (TP_PRESENCE_MIXIN (self), + presences); g_hash_table_unref (presences); if (!self->priv->away) { - g_signal_emit (self, signals[SIGNAL_AVAILABLE], 0, status->message); + g_signal_emit (self, signals[SIGNAL_AVAILABLE], 0, + message); } return TRUE; } -/* Must be kept in sync with ExampleCallPresence enum in header */ -static const TpPresenceStatusSpec presence_statuses[] = { - { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, FALSE }, - { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, FALSE }, - { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, FALSE }, - { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, TRUE }, - { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, TRUE }, - { NULL } -}; - static const gchar *interfaces_always_present[] = { TP_IFACE_CONNECTION_INTERFACE_PRESENCE1, NULL }; @@ -336,6 +363,21 @@ fill_contact_attributes (TpBaseConnection *conn, fill_contact_attributes (conn, dbus_interface, contact, attributes); } +static GList * +dup_statuses (TpPresenceMixin *mixin) +{ + ExampleCallConnection *self = EXAMPLE_CALL_CONNECTION (mixin); + GList *them = NULL; + guint i; + + for (i = 0; i < N_EXAMPLE_CALL_PRESENCES; i++) + them = g_list_prepend (them, + tp_presence_status_spec_ref ( + g_ptr_array_index (self->priv->statuses, i))); + + return them; +} + static void init_presence (gpointer g_iface, gpointer iface_data) @@ -343,9 +385,9 @@ init_presence (gpointer g_iface, TpPresenceMixinInterface *iface = g_iface; iface->status_available = status_available; - iface->get_contact_status = get_contact_status; + iface->dup_contact_status = dup_contact_status; iface->set_own_status = set_own_status; - iface->statuses = presence_statuses; + iface->dup_statuses = dup_statuses; } static void |