4
* Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/>
6
* Copying and distribution of this file, with or without modification,
7
* are permitted in any medium without royalty provided the copyright
8
* notice and this notice are preserved.
14
#include <telepathy-glib/telepathy-glib.h>
15
#include <telepathy-glib/debug.h>
16
#include <telepathy-glib/simple-approver.h>
18
GMainLoop *mainloop = NULL;
21
cdo_finished_cb (TpProxy *self,
27
g_print ("ChannelDispatchOperation has been invalidated\n");
29
g_object_unref (self);
30
g_main_loop_quit (mainloop);
34
handle_with_cb (GObject *source,
38
TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
41
if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error))
43
g_print ("HandleWith() failed: %s\n", error->message);
48
g_print ("HandleWith() succeeded\n");
52
claim_cb (GObject *source,
57
TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
62
if (!tp_channel_dispatch_operation_claim_finish (cdo, result, &error))
64
g_print ("Claim() failed: %s\n", error->message);
69
g_print ("Claim() succeeded, close channels\n");
71
channels = tp_channel_dispatch_operation_borrow_channels (cdo);
72
for (i = 0; i < channels->len; i++)
74
TpChannel *channel = g_ptr_array_index (channels, i);
76
tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
82
add_dispatch_operation_cb (TpSimpleApprover *self,
84
TpConnection *connection,
86
TpChannelDispatchOperation *cdo,
87
TpAddDispatchOperationContext *context,
91
GStrv possible_handlers;
94
g_print ("Approving this batch of channels:\n");
96
g_signal_connect (cdo, "invalidated", G_CALLBACK (cdo_finished_cb), NULL);
98
for (l = channels; l != NULL; l = g_list_next (l))
100
TpChannel *channel = l->data;
102
g_print ("%s channel with %s\n", tp_channel_get_channel_type (channel),
103
tp_channel_get_identifier (channel));
106
possible_handlers = tp_channel_dispatch_operation_borrow_possible_handlers (
108
if (possible_handlers[0] == NULL)
110
g_print ("\nNo possible handler suggested\n");
116
g_print ("\npossible handlers:\n");
117
for (i = 0; possible_handlers[i] != NULL; i++)
118
g_print (" %s\n", possible_handlers[i]);
123
tp_add_dispatch_operation_context_accept (context);
125
g_print ("Approve? [y/n]\n");
129
if (c == 'y' || c == 'Y')
131
g_print ("Approve channels\n");
133
tp_channel_dispatch_operation_handle_with_async (cdo, NULL,
134
handle_with_cb, NULL);
136
else if (c == 'n' || c == 'N')
138
g_print ("Dissaprove channels\n");
140
tp_channel_dispatch_operation_claim_async (cdo, claim_cb, NULL);
144
g_print ("Ignore channels\n");
152
TpDBusDaemon *bus_daemon;
153
GError *error = NULL;
154
TpBaseClient *approver;
157
tp_debug_set_flags (g_getenv ("EXAMPLE_DEBUG"));
159
bus_daemon = tp_dbus_daemon_dup (&error);
161
if (bus_daemon == NULL)
163
g_warning ("%s", error->message);
164
g_error_free (error);
168
approver = tp_simple_approver_new (bus_daemon, "ExampleApprover",
169
FALSE, add_dispatch_operation_cb, NULL, NULL);
171
/* contact text chat */
172
tp_base_client_take_approver_filter (approver, tp_asv_new (
173
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
174
TP_IFACE_CHANNEL_TYPE_TEXT,
175
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
176
TP_HANDLE_TYPE_CONTACT,
180
tp_base_client_take_approver_filter (approver, tp_asv_new (
181
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
182
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
183
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
184
TP_HANDLE_TYPE_CONTACT,
188
tp_base_client_take_approver_filter (approver, tp_asv_new (
189
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
190
TP_IFACE_CHANNEL_TYPE_TEXT,
191
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
196
tp_base_client_take_approver_filter (approver, tp_asv_new (
197
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
198
TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
199
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
200
TP_HANDLE_TYPE_CONTACT,
203
if (!tp_base_client_register (approver, &error))
205
g_warning ("Failed to register Approver: %s\n", error->message);
206
g_error_free (error);
210
g_print ("Start approving\n");
212
mainloop = g_main_loop_new (NULL, FALSE);
213
g_main_loop_run (mainloop);
215
if (mainloop != NULL)
216
g_main_loop_unref (mainloop);
219
g_object_unref (bus_daemon);
220
g_object_unref (approver);