183
180
const char *request_key,
184
181
const char *pincode)
186
DBusGMethodInvocation* context;
183
GDBusMethodInvocation* invocation;
188
185
g_return_if_fail (BLUETOOTH_IS_APPLET (self));
189
186
g_return_if_fail (request_key != NULL);
191
context = g_hash_table_lookup (self->pending_requests, request_key);
188
invocation = g_hash_table_lookup (self->pending_requests, request_key);
193
190
if (pincode != NULL) {
194
dbus_g_method_return (context, pincode);
191
g_dbus_method_invocation_return_value (invocation,
192
g_variant_new ("(s)", pincode));
197
195
error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
198
196
"Pairing request rejected");
199
dbus_g_method_return_error (context, error);
197
g_dbus_method_invocation_return_gerror (invocation, error);
198
g_error_free (error);
202
201
g_hash_table_remove (self->pending_requests, request_key);
214
213
const char *request_key,
217
DBusGMethodInvocation* context;
216
GDBusMethodInvocation* invocation;
219
218
g_return_if_fail (BLUETOOTH_IS_APPLET (self));
220
219
g_return_if_fail (request_key != NULL);
222
context = g_hash_table_lookup (self->pending_requests, request_key);
221
invocation = g_hash_table_lookup (self->pending_requests, request_key);
224
223
if (passkey != -1) {
225
dbus_g_method_return (context, passkey);
224
g_dbus_method_invocation_return_value (invocation,
225
g_variant_new ("(u)", passkey));
228
228
error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
229
229
"Pairing request rejected");
230
dbus_g_method_return_error (context, error);
230
g_dbus_method_invocation_return_gerror (invocation, error);
231
g_error_free (error);
233
234
g_hash_table_remove (self->pending_requests, request_key);
245
246
const char *request_key,
246
247
gboolean confirm)
248
DBusGMethodInvocation* context;
249
GDBusMethodInvocation* invocation;
250
251
g_return_if_fail (BLUETOOTH_IS_APPLET (self));
251
252
g_return_if_fail (request_key != NULL);
253
context = g_hash_table_lookup (self->pending_requests, request_key);
254
invocation = g_hash_table_lookup (self->pending_requests, request_key);
256
dbus_g_method_return (context);
257
g_dbus_method_invocation_return_value (invocation, NULL);
259
260
error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
260
261
"Confirmation request rejected");
261
dbus_g_method_return_error (context, error);
262
g_dbus_method_invocation_return_gerror (invocation, error);
263
g_error_free (error);
264
266
g_hash_table_remove (self->pending_requests, request_key);
279
281
gboolean trusted)
281
DBusGMethodInvocation* context;
283
GDBusMethodInvocation* invocation;
283
285
g_return_if_fail (BLUETOOTH_IS_APPLET (self));
284
286
g_return_if_fail (request_key != NULL);
286
context = g_hash_table_lookup (self->pending_requests, request_key);
288
invocation = g_hash_table_lookup (self->pending_requests, request_key);
290
292
bluetooth_client_set_trusted (self->client, request_key, TRUE);
292
dbus_g_method_return (context);
294
g_dbus_method_invocation_return_value (invocation, NULL);
295
297
error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
296
298
"Confirmation request rejected");
297
dbus_g_method_return_error (context, error);
299
g_dbus_method_invocation_return_gerror (invocation, error);
300
g_error_free (error);
300
303
g_hash_table_remove (self->pending_requests, request_key);
303
#ifndef DBUS_TYPE_G_DICTIONARY
304
#define DBUS_TYPE_G_DICTIONARY \
305
(dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
309
device_get_name (DBusGProxy *proxy, char **long_name)
307
device_get_name (GDBusProxy *proxy, char **long_name)
313
311
char *alias, *address;
315
313
g_return_val_if_fail (long_name != NULL, NULL);
317
if (dbus_g_proxy_call (proxy, "GetProperties", NULL,
319
DBUS_TYPE_G_DICTIONARY, &hash,
320
G_TYPE_INVALID) == FALSE) {
315
result = g_dbus_proxy_call_sync (proxy, "GetProperties", NULL,
316
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
324
value = g_hash_table_lookup (hash, "Address");
320
value = g_variant_lookup_value (result, "Address", G_VARIANT_TYPE_STRING);
325
321
if (value == NULL) {
326
g_hash_table_destroy (hash);
322
g_variant_unref (result);
329
address = g_value_dup_string (value);
331
value = g_hash_table_lookup (hash, "Name");
332
alias = value ? g_value_dup_string (value) : address;
334
g_hash_table_destroy (hash);
325
address = g_strdup (g_variant_get_string (value, NULL));
327
value = g_variant_lookup_value (result, "Name", G_VARIANT_TYPE_STRING);
328
alias = value ? g_strdup (g_variant_get_string (value, NULL)) : g_strdup (address);
330
g_variant_unref (result);
337
333
*long_name = g_strdup_printf ("'%s' (%s)", alias, address);
339
335
*long_name = g_strdup_printf ("'%s'", address);
341
if (alias != address)
347
pincode_request (DBusGMethodInvocation *context,
342
pincode_request (GDBusMethodInvocation *invocation,
349
344
gpointer user_data)
351
346
BluetoothApplet* self = BLUETOOTH_APPLET (user_data);
354
349
const char *path;
356
351
name = device_get_name (device, &long_name);
357
path = dbus_g_proxy_get_path (device);
358
g_hash_table_insert (self->pending_requests, g_strdup (path), context);
352
path = g_dbus_proxy_get_object_path (device);
353
g_hash_table_insert (self->pending_requests, g_strdup (path), invocation);
360
355
g_signal_emit (self, signals[SIGNAL_PINCODE_REQUEST], 0, path, name, long_name, FALSE);
376
371
const char *path;
378
373
name = device_get_name (device, &long_name);
379
path = dbus_g_proxy_get_path (device);
380
g_hash_table_insert (self->pending_requests, g_strdup (path), context);
374
path = g_dbus_proxy_get_object_path (device);
375
g_hash_table_insert (self->pending_requests, g_strdup (path), invocation);
382
377
g_signal_emit (self, signals[SIGNAL_PINCODE_REQUEST], 0, path, name, long_name, TRUE);
399
394
const char *path;
401
396
name = device_get_name (device, &long_name);
402
path = dbus_g_proxy_get_path (device);
403
g_hash_table_insert (self->pending_requests, g_strdup (path), context);
397
path = g_dbus_proxy_get_object_path (device);
398
g_hash_table_insert (self->pending_requests, g_strdup (path), invocation);
405
400
g_signal_emit (self, signals[SIGNAL_CONFIRM_REQUEST], 0, path, name, long_name, pin);
422
417
const char *path;
424
419
name = device_get_name (device, &long_name);
425
path = dbus_g_proxy_get_path (device);
426
g_hash_table_insert (self->pending_requests, g_strdup (path), context);
420
path = g_dbus_proxy_get_object_path (device);
421
g_hash_table_insert (self->pending_requests, g_strdup (path), invocation);
428
423
g_signal_emit (self, signals[SIGNAL_AUTHORIZE_REQUEST], 0, path, name, long_name, uuid);
437
432
cancel_request_single (gpointer key, gpointer value, gpointer user_data)
439
DBusGMethodInvocation* request_context = value;
434
GDBusMethodInvocation* request_invocation = value;
443
result = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT, "Agent callback cancelled");
444
dbus_g_method_return_error (request_context, result);
438
error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT, "Agent callback cancelled");
439
g_dbus_method_invocation_return_gerror (request_invocation, error);
440
g_error_free (error);
449
cancel_request(DBusGMethodInvocation *context,
445
cancel_request(GDBusMethodInvocation *invocation,
450
446
gpointer user_data)
452
448
BluetoothApplet* self = BLUETOOTH_APPLET (user_data);
504
500
BluetoothApplet* self = BLUETOOTH_APPLET (data);
505
501
GtkTreeModel *child_model;
507
if (self->default_adapter)
508
g_object_unref (self->default_adapter);
509
self->default_adapter = bluetooth_client_get_default_adapter (self->client);
503
if (self->default_adapter) {
504
g_free (self->default_adapter);
505
self->default_adapter = NULL;
507
g_object_get (G_OBJECT (self->client), "default-adapter", &self->default_adapter, NULL);
511
509
/* The old model */
512
510
child_model = get_child_model (self->device_model);
580
575
GtkTreeIter *iter,
583
DBusGProxy *proxy = NULL;
584
GValue value = { 0, };
578
GDBusProxy *proxy = NULL;
586
580
gtk_tree_model_get (model, iter,
587
581
BLUETOOTH_COLUMN_PROXY, &proxy, -1);
588
583
if (proxy == NULL)
591
g_value_init (&value, G_TYPE_BOOLEAN);
592
g_value_set_boolean (&value, TRUE);
594
dbus_g_proxy_call_no_reply (proxy, "SetProperty",
595
G_TYPE_STRING, "Powered",
596
G_TYPE_VALUE, &value,
600
g_value_unset (&value);
586
g_dbus_proxy_call (proxy,
588
g_variant_new ("sv", "Powered", g_variant_new_boolean (TRUE)),
589
G_DBUS_CALL_FLAGS_NO_AUTO_START,
601
595
g_object_unref (proxy);
644
638
} ConnectionClosure;
647
connection_callback (BluetoothClient* client, gboolean success, gpointer data)
642
connection_callback (GObject *source_object,
649
ConnectionClosure *closure = (ConnectionClosure*) data;
646
ConnectionClosure *closure = (ConnectionClosure*) user_data;
649
success = bluetooth_client_connect_service_finish (BLUETOOTH_CLIENT (source_object), res, NULL);
651
651
(*(closure->func)) (closure->self, success, closure->user_data);
961
967
g_signal_connect (self->killswitch_manager, "state-changed", G_CALLBACK(killswitch_state_change), self);
963
969
self->pending_requests = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
964
dbus_g_error_domain_register (AGENT_ERROR, "org.bluez.Error", AGENT_ERROR_TYPE);
970
g_dbus_error_register_error (AGENT_ERROR, AGENT_ERROR_REJECT, "org.bluez.Error.Rejected");
966
972
/* Make sure all the unblocked adapters are powered,
967
973
* so as to avoid seeing unpowered, but unblocked
1031
1037
g_object_class_install_property (gobject_class, PROP_FULL_MENU, properties[PROP_FULL_MENU]);
1033
1039
signals[SIGNAL_DEVICES_CHANGED] = g_signal_new ("devices-changed", G_TYPE_FROM_CLASS (gobject_class),
1034
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
1040
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE, 0, NULL, NULL, NULL,
1035
1041
G_TYPE_NONE, 0);
1037
1043
signals[SIGNAL_PINCODE_REQUEST] = g_signal_new ("pincode-request", G_TYPE_FROM_CLASS (gobject_class),
1038
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, marshal_VOID__STRING_STRING_STRING_BOOLEAN,
1044
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
1039
1045
G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
1041
1047
signals[SIGNAL_CONFIRM_REQUEST] = g_signal_new ("confirm-request", G_TYPE_FROM_CLASS (gobject_class),
1042
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, marshal_VOID__STRING_STRING_STRING_UINT,
1048
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
1043
1049
G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
1045
1051
signals[SIGNAL_AUTHORIZE_REQUEST] = g_signal_new ("auth-request", G_TYPE_FROM_CLASS (gobject_class),
1046
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, marshal_VOID__STRING_STRING_STRING_STRING,
1052
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
1047
1053
G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
1049
1055
signals[SIGNAL_CANCEL_REQUEST] = g_signal_new ("cancel-request", G_TYPE_FROM_CLASS (gobject_class),
1050
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
1056
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
1051
1057
G_TYPE_NONE, 0);