2
* telepathy-example-inspect-contact - inspect a contact on a connection
4
* Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
5
* Copyright (C) 2007-2008 Nokia Corporation
7
* Copying and distribution of this file, with or without modification,
8
* are permitted in any medium without royalty provided the copyright
9
* notice and this notice are preserved.
14
#include <telepathy-glib/contact.h>
15
#include <telepathy-glib/dbus.h>
16
#include <telepathy-glib/debug.h>
19
display_contact (TpContact *contact)
21
const gchar *avatar_token;
23
g_message ("Handle %u, \"%s\":", tp_contact_get_handle (contact),
24
tp_contact_get_identifier (contact));
25
g_message ("\tAlias: \"%s\"", tp_contact_get_alias (contact));
27
avatar_token = tp_contact_get_avatar_token (contact);
29
if (avatar_token == NULL)
30
g_message ("\tAvatar token not known");
32
g_message ("\tAvatar token: \"%s\"", avatar_token);
34
g_message ("\tPresence: type #%i \"%s\": \"%s\"",
35
tp_contact_get_presence_type (contact),
36
tp_contact_get_presence_status (contact),
37
tp_contact_get_presence_message (contact));
41
got_contacts_by_handle (TpConnection *connection,
43
TpContact * const *contacts,
45
const TpHandle *invalid,
50
GMainLoop *mainloop = user_data;
56
for (i = 0; i < n_contacts; i++)
58
display_contact (contacts[i]);
61
for (i = 0; i < n_invalid; i++)
63
g_warning ("Invalid handle %u", invalid[i]);
68
g_warning ("Error getting contacts: %s", error->message);
71
g_main_loop_quit (mainloop);
75
got_contacts_by_id (TpConnection *connection,
77
TpContact * const *contacts,
78
const gchar * const *good_ids,
84
GMainLoop *mainloop = user_data;
89
GHashTableIter hash_iter;
92
for (i = 0; i < n_contacts; i++)
94
display_contact (contacts[i]);
97
g_hash_table_iter_init (&hash_iter, bad_ids);
99
while (g_hash_table_iter_next (&hash_iter, &key, &value))
104
g_warning ("Invalid ID \"%s\": %s", id, e->message);
109
g_warning ("Error getting contacts: %s", error->message);
112
g_main_loop_quit (mainloop);
119
const gchar *bus_name, *object_path;
120
TpConnection *connection = NULL;
121
GMainLoop *mainloop = NULL;
122
TpDBusDaemon *daemon = NULL;
123
GError *error = NULL;
124
static TpContactFeature features[] = {
125
TP_CONTACT_FEATURE_ALIAS,
126
TP_CONTACT_FEATURE_AVATAR_TOKEN,
127
TP_CONTACT_FEATURE_PRESENCE
132
tp_debug_set_flags (g_getenv ("EXAMPLE_DEBUG"));
137
" telepathy-example-inspect-connection OBJECT_PATH [CONTACT_ID]\n"
139
" telepathy-example-inspect-connection BUS_NAME [CONTACT_ID]\n",
144
/* Cope with the first argument being a bus name or an object path */
145
if (argv[1][0] == '/')
147
object_path = argv[1];
156
daemon = tp_dbus_daemon_dup (&error);
160
g_warning ("%s", error->message);
164
connection = tp_connection_new (daemon, bus_name, object_path, &error);
166
if (connection == NULL ||
167
!tp_connection_run_until_ready (connection, FALSE, &error, NULL))
169
g_warning ("%s", error->message);
173
g_message ("Connection ready\n");
175
mainloop = g_main_loop_new (NULL, FALSE);
181
if (!tp_cli_connection_run_get_self_handle (connection, -1,
182
&self_handle, &error, NULL))
184
g_warning ("%s", error->message);
188
tp_connection_get_contacts_by_handle (connection,
190
sizeof (features) / sizeof (features[0]), features,
191
got_contacts_by_handle,
192
g_main_loop_ref (mainloop),
193
(GDestroyNotify) g_main_loop_unref, NULL);
197
const gchar *contacts[] = { argv[2], NULL };
199
tp_connection_get_contacts_by_id (connection,
201
sizeof (features) / sizeof (features[0]), features,
203
g_main_loop_ref (mainloop),
204
(GDestroyNotify) g_main_loop_unref, NULL);
207
g_main_loop_run (mainloop);
212
g_error_free (error);
214
if (mainloop != NULL)
215
g_main_loop_unref (mainloop);
217
if (connection != NULL)
218
g_object_unref (connection);
221
g_object_unref (daemon);