[Telepathy] Accessing the ContactList for a connection.
Robert McQueen
robert.mcqueen at collabora.co.uk
Thu Feb 14 19:37:43 PST 2008
Hi Michael,
Michael R. Head wrote:
> Hi, I'm trying to find my way around the telepathy API (for a maemo
> project) and what I'd like to do right now is use mission control to
> access a Connected account's contact list and print out the first
> contact in the list. (after that, I'd like to send a message to that
> contact, but I'll work on that later).
OK.
> I'm having a little trouble figuring out which calls to make. It seems
> like I should be getting a ContactList channel and storing the result in
> a TP_HANDLE_TYPE_LIST, but I'm not sure what the handle int should be
> set to... actually I'm not sure how these handles work yet, and I'm
> having trouble translating between the telepathy spec and the
> appropriate libtelepathy/telepathy-glib calls I should be making.
As you may have spotted, recent tp-glib releases include a full
client-side API which unlike libtp has full gtkdoc-ification, and should
help a great deal with mapping between the specs and the binding APIs.
For list handles, because they only appear on contact list channels, the
appropriate documention pointer is here:
http://telepathy.freedesktop.org/spec.html#org.freedesktop.Telepathy.Channel.Type.ContactList
In brief, the list type handles (if present) correspond to string values
like "subscribe" for the list of people whose presence you're subscribed
to, "publish" for the list of people who are subscribed to your
presence, "deny" for the list of people who may not see you or send
messages to you, and as a special hidden feature (ahem...) on gabble,
"known" corresponds to every member of the XMPP roster regardless of
subscription state (people can be on the roster with subscription=none).
> Anyway, here's my snippet, which of course fails because I'm not putting
> in a good value for handle:
>
> TpConn* tp_connection = mission_control_get_connection(mc, account, &error);
> if (tp_connection == NULL) {
> g_assert(error != NULL);
> g_error("Connection was not created: \"%s\" (code: %i)\n", error->message, error->code);
> g_error_free(error);
> } else {
> /* We have a connection! */
> guint handle = 0;
const gchar **lists = { "subscribe", NULL };
GArray *handles = NULL;
if (!tp_conn_request_handles (conn, TP_HANDLE_TYPE_LIST, lists,
&handles, &error)
{
// this connection may legitimately not have a subscribe list, or
// even not any contact lists at all
...
}
else
{
g_assert (handles != NULL);
handle = g_array_index (handles, guint, 0);
g_array_free (handles);
}
> const gchar* bus_name = dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_connection));
> TpChan * contact_list_channel = tp_conn_new_channel (dbus_conn, tp_connection, bus_name, TP_IFACE_CHANNEL_TYPE_CONTACT_LIST, TP_HANDLE_TYPE_LIST, handle, TRUE);
> }
>
> And the output:
> ...
> mission-control-test[3723]: GLIB WARNING ** default - RequestChannel() failed: invalid handle 0 (org.freedesktop.Telepathy.Error.InvalidHandle)
The above should work better. :)
Regards,
Rob
More information about the Telepathy
mailing list