~ubuntu-branches/ubuntu/raring/gnome-bluetooth/raring-proposed

« back to all changes in this revision

Viewing changes to applet/agent.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort, Laurent Bigonville, Emilio Pozuelo Monfort
  • Date: 2011-02-27 15:45:22 UTC
  • mfrom: (1.4.1 upstream) (2.1.11 sid)
  • mto: (2.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20110227154522-p2nrmq4sxbrl3j4b
Tags: 2.91.5-1
[ Laurent Bigonville ]
* New upstream release
  - Bump libgnome-bluetooth soname
  - Update .symbols file
  - Japanese translation updated (Closes: #601518)
* debian/control.in:
  - Bump build-dependencies
  - Drop not needed build-dependencies
  - Add libgnome-control-center-dev build-dependency
  - Add gobject-introspection, libgirepository1.0-dev, gir1.2-atk-1.0,
    gir1.2-freedesktop, gir1.2-gtk-3.0 and libatk1.0-dev for introspection
  - Bump Standards-Version to 3.9.1 (no further changes)
  - Bump debhelper compatibility to 8
  - Remove duplicate Section to please lintian
  - Make gnome-bluetooth depends against ${gir:Depends} and libdconf0
  - Add gir1.2-gnomebluetooth-1.0 package
* Switch to dpkg-source 3.0 (quilt) format
* debian/libgnome-bluetooth-dev.install: Install .gir file
* debian/rules:
  - Add --enable-introspection
  - Add parameters for dh_girepository for gnome-bluetooth package
* debian/gnome-bluetooth.install:
  - Remove debian/tmp/etc
  - Add debian/tmp/usr/lib/control-center-1/panels/*.so,
    debian/tmp/usr/lib/gnome-bluetooth/*.so*,
    debian/tmp/usr/lib/gnome-bluetooth/*.typelib,
    debian/tmp/usr/share/GConf/gsettings/,
    debian/tmp/usr/share/glib-2.0/schemas/

[ Emilio Pozuelo Monfort ]
* debian/control.in:
  + Bump gobject-introspection build dependency to get a
    dh_girepository that can cope with private libraries.
  + Update gtk+ 3 package names.
* New upstream release.
* debian/rules:
  + Don't run dh_makeshlibs on gnome-bluetooth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <glib/gi18n.h>
32
32
#include <gtk/gtk.h>
33
33
 
34
 
#include <dbus/dbus-glib.h>
35
 
 
36
 
#include <bluetooth-client.h>
37
 
#include <bluetooth-agent.h>
38
 
 
 
34
#include "bluetooth-applet.h"
39
35
#include "notify.h"
40
36
#include "agent.h"
41
37
 
42
 
static BluetoothClient *client;
43
 
static BluetoothAgent *agent = NULL;
44
 
 
45
38
static GList *input_list = NULL;
46
39
 
47
40
typedef struct input_data input_data;
48
41
struct input_data {
 
42
        BluetoothApplet *applet;
49
43
        char *path;
50
44
        char *uuid;
51
45
        gboolean numeric;
52
 
        DBusGProxy *device;
53
 
        DBusGMethodInvocation *context;
54
46
        GtkWidget *dialog;
55
47
        GtkWidget *button;
56
48
        GtkWidget *entry;
57
49
};
58
50
 
59
 
static gint input_compare(gconstpointer a, gconstpointer b)
60
 
{
61
 
        input_data *a_data = (input_data *) a;
62
 
        input_data *b_data = (input_data *) b;
63
 
 
64
 
        return g_ascii_strcasecmp(a_data->path, b_data->path);
65
 
}
66
 
 
67
51
static void input_free(input_data *input)
68
52
{
69
53
        gtk_widget_destroy(input->dialog);
70
54
 
 
55
        g_object_unref (G_OBJECT (input->applet));
 
56
        g_free(input->uuid);
 
57
        g_free(input->path);
 
58
 
71
59
        input_list = g_list_remove(input_list, input);
72
60
 
73
 
        if (input->device != NULL)
74
 
                g_object_unref(input->device);
75
 
 
76
 
        g_free(input->uuid);
77
 
        g_free(input->path);
78
61
        g_free(input);
79
62
 
80
 
        if (g_list_length(input_list) == 0)
81
 
                disable_blinking();
82
63
}
83
64
 
84
65
static void pin_callback(GtkWidget *dialog,
93
74
 
94
75
                if (input->numeric == TRUE) {
95
76
                        guint pin = atoi(text);
96
 
                        dbus_g_method_return(input->context, pin);
97
 
                } else {
98
 
                        dbus_g_method_return(input->context, text);
99
 
                }
 
77
                        bluetooth_applet_agent_reply_passkey (input->applet, input->path, pin);
 
78
                } else
 
79
                        bluetooth_applet_agent_reply_pincode (input->applet, input->path, text);
100
80
        } else {
101
 
                GError *error;
102
 
                error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
103
 
                                                "Pairing request rejected");
104
 
                dbus_g_method_return_error(input->context, error);
 
81
                if (input->numeric == TRUE)
 
82
                        bluetooth_applet_agent_reply_passkey (input->applet, input->path, -1);
 
83
                else
 
84
                        bluetooth_applet_agent_reply_pincode (input->applet, input->path, NULL);
105
85
        }
106
86
 
107
87
        input_free(input);
114
94
{
115
95
        input_data *input = user_data;
116
96
 
117
 
        if (response != GTK_RESPONSE_ACCEPT) {
118
 
                GError *error;
119
 
                error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
120
 
                                        "Confirmation request rejected");
121
 
                dbus_g_method_return_error(input->context, error);
122
 
        } else
123
 
                dbus_g_method_return(input->context);
 
97
        bluetooth_applet_agent_reply_confirm (input->applet, input->path, response == GTK_RESPONSE_ACCEPT);
124
98
 
125
99
        input_free(input);
126
100
}
127
101
 
128
 
static void set_trusted(input_data *input)
129
 
{
130
 
        GValue value = { 0 };
131
 
        gboolean active;
132
 
 
133
 
        if (input->device == NULL)
134
 
                return;
135
 
 
136
 
        active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (input->button));
137
 
        if (active == FALSE)
138
 
                return;
139
 
 
140
 
        g_value_init (&value, G_TYPE_BOOLEAN);
141
 
        g_value_set_boolean (&value, TRUE);
142
 
 
143
 
        dbus_g_proxy_call (input->device, "SetProperty", NULL,
144
 
                           G_TYPE_STRING, "Trusted",
145
 
                           G_TYPE_VALUE, &value, G_TYPE_INVALID,
146
 
                           G_TYPE_INVALID);
147
 
 
148
 
        g_value_unset (&value);
149
 
}
150
 
 
151
102
static void
152
103
auth_callback (GtkWidget *dialog,
153
 
               gint response,
154
 
               gpointer user_data)
 
104
               gint response,
 
105
               gpointer user_data)
155
106
{
156
107
        input_data *input = user_data;
157
108
 
158
109
        if (response == GTK_RESPONSE_ACCEPT) {
159
 
                set_trusted (input);
160
 
                dbus_g_method_return(input->context);
161
 
        } else {
162
 
                GError *error;
163
 
                error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
164
 
                                     "Authorization request rejected");
165
 
                dbus_g_method_return_error (input->context, error);
166
 
        }
 
110
                gboolean trusted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (input->button));
 
111
                bluetooth_applet_agent_reply_auth (input->applet, input->path, TRUE, trusted);
 
112
        } else
 
113
                bluetooth_applet_agent_reply_auth (input->applet, input->path, FALSE, FALSE);
167
114
 
168
115
        input_free(input);
169
116
}
208
155
}
209
156
 
210
157
static void
211
 
pin_dialog (DBusGProxy *adapter,
212
 
                DBusGProxy *device,
213
 
                const char *name,
214
 
                const char *long_name,
215
 
                gboolean numeric,
216
 
                DBusGMethodInvocation *context)
 
158
pin_dialog (BluetoothApplet *applet,
 
159
            const char *path,
 
160
            const char *name,
 
161
            const char *long_name,
 
162
            gboolean numeric)
217
163
{
218
164
        GtkWidget *dialog;
219
165
        GtkWidget *button;
227
173
                gtk_builder_add_from_file (xml, PKGDATADIR "/passkey-dialogue.ui", NULL);
228
174
 
229
175
        input = g_new0 (input_data, 1);
230
 
        input->path = g_strdup (dbus_g_proxy_get_path(adapter));
 
176
        input->applet = g_object_ref (G_OBJECT (applet));
 
177
        input->path = g_strdup (path);
231
178
        input->numeric = numeric;
232
 
        input->context = context;
233
 
        input->device = g_object_ref (device);
234
179
 
235
180
        dialog = GTK_WIDGET (gtk_builder_get_object (xml, "dialog"));
236
181
 
286
231
 
287
232
        g_signal_connect (G_OBJECT (dialog), "response",
288
233
                          G_CALLBACK (pin_callback), input);
289
 
 
290
 
        enable_blinking();
291
 
}
292
 
 
293
 
#if 0
294
 
static void display_dialog(DBusGProxy *adapter, DBusGProxy *device,
295
 
                const char *address, const char *name, const char *value,
296
 
                                guint entered, DBusGMethodInvocation *context)
297
 
{
298
 
}
299
 
#endif
 
234
}
300
235
 
301
236
static void
302
 
confirm_dialog (DBusGProxy *adapter,
303
 
                DBusGProxy *device,
304
 
                const char *name,
305
 
                const char *long_name,
306
 
                const char *value,
307
 
                DBusGMethodInvocation *context)
 
237
confirm_dialog (BluetoothApplet *applet,
 
238
                const char *path,
 
239
                const char *name,
 
240
                const char *long_name,
 
241
                const char *value)
308
242
{
309
243
        GtkWidget *dialog;
310
244
        GtkBuilder *xml;
312
246
        input_data *input;
313
247
 
314
248
        input = g_new0 (input_data, 1);
315
 
        input->path = g_strdup (dbus_g_proxy_get_path(adapter));
316
 
        input->device = g_object_ref (device);
317
 
        input->context = context;
 
249
        input->applet = g_object_ref (G_OBJECT (applet));
 
250
        input->path = g_strdup (path);
318
251
 
319
252
        xml = gtk_builder_new ();
320
253
        if (gtk_builder_add_from_file (xml, "confirm-dialogue.ui", NULL) == 0)
344
277
 
345
278
        g_signal_connect (G_OBJECT (dialog), "response",
346
279
                          G_CALLBACK (confirm_callback), input);
347
 
 
348
 
        enable_blinking ();
349
280
}
350
281
 
351
282
static void
352
 
auth_dialog (DBusGProxy *adapter,
353
 
             DBusGProxy *device,
354
 
             const char *name,
355
 
             const char *long_name,
356
 
             const char *uuid,
357
 
             DBusGMethodInvocation *context)
 
283
auth_dialog (BluetoothApplet *applet,
 
284
             const char *path,
 
285
             const char *name,
 
286
             const char *long_name,
 
287
             const char *uuid)
358
288
{
359
289
        GtkBuilder *xml;
360
290
        GtkWidget *dialog;
363
293
        input_data *input;
364
294
 
365
295
        input = g_new0 (input_data, 1);
366
 
        input->path = g_strdup (dbus_g_proxy_get_path (adapter));
 
296
        input->applet = g_object_ref (G_OBJECT (applet));
 
297
        input->path = g_strdup (path);
367
298
        input->uuid = g_strdup (uuid);
368
 
        input->device = g_object_ref (device);
369
 
        input->context = context;
370
299
 
371
300
        xml = gtk_builder_new ();
372
301
        if (gtk_builder_add_from_file (xml, "authorisation-dialogue.ui", NULL) == 0)
397
326
 
398
327
        g_signal_connect (G_OBJECT (dialog), "response",
399
328
                          G_CALLBACK (auth_callback), input);
400
 
 
401
 
        enable_blinking ();
402
329
}
403
330
 
404
331
static void show_dialog(gpointer data, gpointer user_data)
413
340
static void present_notification_dialogs (void)
414
341
{
415
342
        g_list_foreach(input_list, show_dialog, NULL);
416
 
 
417
 
        disable_blinking();
418
343
}
419
344
 
420
345
static void notification_closed(GObject *object, gpointer user_data)
422
347
        present_notification_dialogs ();
423
348
}
424
349
 
425
 
#ifndef DBUS_TYPE_G_DICTIONARY
426
 
#define DBUS_TYPE_G_DICTIONARY \
427
 
        (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
428
 
#endif
429
 
 
430
 
static char *
431
 
device_get_name(DBusGProxy *proxy, char **long_name)
432
 
{
433
 
        GHashTable *hash;
434
 
        GValue *value;
435
 
        char *alias, *address;
436
 
 
437
 
        if (long_name != NULL)
438
 
                *long_name = NULL;
439
 
 
440
 
        if (dbus_g_proxy_call (proxy, "GetProperties",  NULL,
441
 
                               G_TYPE_INVALID,
442
 
                               DBUS_TYPE_G_DICTIONARY, &hash,
443
 
                               G_TYPE_INVALID) == FALSE) {
444
 
                return NULL;
445
 
        }
446
 
 
447
 
        value = g_hash_table_lookup(hash, "Address");
448
 
        if (value == NULL) {
449
 
                g_hash_table_destroy (hash);
450
 
                return NULL;
451
 
        }
452
 
        address = g_value_dup_string(value);
453
 
 
454
 
        value = g_hash_table_lookup(hash, "Alias");
455
 
        alias = value ? g_value_dup_string(value) : NULL;
456
 
 
457
 
        g_hash_table_destroy (hash);
458
 
 
459
 
        if (g_strcmp0 (alias, address) == 0) {
460
 
                g_free (alias);
461
 
                if (long_name != NULL)
462
 
                        *long_name = g_strdup_printf ("'%s'", address);
463
 
                return address;
464
 
        }
465
 
 
466
 
        if (long_name != NULL)
467
 
                *long_name = g_strdup_printf ("'%s' (%s)", alias, address);
468
 
 
469
 
        g_free (address);
470
 
 
471
 
        return alias;
472
 
}
473
 
 
474
 
static gboolean pincode_request(DBusGMethodInvocation *context,
475
 
                                        DBusGProxy *device, gpointer user_data)
476
 
{
477
 
        DBusGProxy *adapter = user_data;
478
 
        char *name, *long_name, *line;
479
 
 
480
 
        name = device_get_name (device, &long_name);
481
 
        if (name == NULL)
482
 
                return FALSE;
483
 
 
484
 
        pin_dialog(adapter, device, name, long_name, FALSE, context);
485
 
 
486
 
        g_free (long_name);
487
 
 
488
 
        if (notification_supports_actions () == FALSE) {
489
 
                g_free (name);
490
 
                present_notification_dialogs ();
491
 
                return TRUE;
492
 
        }
493
 
 
494
 
        /* translators: this is a popup telling you a particular device
495
 
         * has asked for pairing */
496
 
        line = g_strdup_printf(_("Pairing request for '%s'"), name);
497
 
 
498
 
        g_free(name);
499
 
 
500
 
        show_notification(_("Bluetooth device"),
501
 
                          line, _("Enter PIN"), 0,
502
 
                          G_CALLBACK(notification_closed));
503
 
 
504
 
        g_free(line);
505
 
 
506
 
        return TRUE;
507
 
}
508
 
 
509
 
static gboolean pin_request(DBusGMethodInvocation *context,
510
 
                                        DBusGProxy *device, gpointer user_data)
511
 
{
512
 
        DBusGProxy *adapter = user_data;
513
 
        char *name, *long_name, *line;
514
 
 
515
 
        name = device_get_name (device, &long_name);
516
 
        if (name == NULL)
517
 
                return FALSE;
518
 
 
519
 
        pin_dialog(adapter, device, name, long_name, TRUE, context);
520
 
 
521
 
        g_free (long_name);
522
 
 
523
 
        if (notification_supports_actions () == FALSE) {
524
 
                g_free (name);
525
 
                present_notification_dialogs ();
526
 
                return TRUE;
527
 
        }
528
 
 
529
 
        /* translators: this is a popup telling you a particular device
530
 
         * has asked for pairing */
531
 
        line = g_strdup_printf(_("Pairing request for '%s'"), name);
532
 
 
533
 
        g_free(name);
534
 
 
535
 
        show_notification(_("Bluetooth device"),
536
 
                          line, _("Enter PIN"), 0,
537
 
                          G_CALLBACK(notification_closed));
538
 
 
539
 
        g_free(line);
540
 
 
541
 
        return TRUE;
542
 
}
543
 
 
544
 
static gboolean
545
 
display_request (DBusGMethodInvocation *context,
546
 
                 DBusGProxy *device,
547
 
                 guint pin,
548
 
                 guint entered,
549
 
                 gpointer user_data)
550
 
{
551
 
        g_warning ("Not implemented, please file a bug at how this happened");
552
 
        return FALSE;
553
 
#if 0
554
 
        DBusGProxy *adapter = user_data;
555
 
        char *name, *text;
556
 
 
557
 
        name = get_name_for_display (device);
558
 
        if (name == NULL)
559
 
                return FALSE;
560
 
 
561
 
        text = g_strdup_printf("%d", pin);
562
 
        display_dialog(adapter, device, address, name, text, entered, context);
563
 
        g_free(text);
564
 
 
565
 
        if (notification_supports_actions () == FALSE) {
566
 
                g_free (name);
567
 
                present_notification_dialogs ();
568
 
                return TRUE;
569
 
        }
570
 
 
571
 
        /* translators: this is a popup telling you a particular device
572
 
         * has asked for pairing */
573
 
        line = g_strdup_printf(_("Pairing request for '%s'"), name);
574
 
 
575
 
        g_free(name);
576
 
 
577
 
        show_notification(_("Bluetooth device"),
578
 
                          line, _("Enter PIN"), 0,
579
 
                          G_CALLBACK(notification_closed));
580
 
 
581
 
        g_free(line);
582
 
 
583
 
        return TRUE;
584
 
#endif
585
 
}
586
 
 
587
 
static gboolean
588
 
confirm_request (DBusGMethodInvocation *context,
589
 
                 DBusGProxy *device,
590
 
                 guint pin,
591
 
                 gpointer user_data)
592
 
{
593
 
        DBusGProxy *adapter = user_data;
594
 
        char *name, *long_name, *line, *text;
595
 
 
596
 
        name = device_get_name (device, &long_name);
597
 
        if (name == NULL)
598
 
                return FALSE;
599
 
 
600
 
        text = g_strdup_printf("%d", pin);
601
 
        confirm_dialog(adapter, device, name, long_name, text, context);
602
 
        g_free(text);
603
 
 
604
 
        g_free (long_name);
 
350
static gboolean
 
351
pin_request(BluetoothApplet *applet,
 
352
            char *path,
 
353
            char *name,
 
354
            char *long_name,
 
355
            gboolean numeric,
 
356
            gpointer user_data)
 
357
{
 
358
        char *line;
 
359
 
 
360
        pin_dialog(applet, path, name, long_name, numeric);
 
361
 
 
362
        if (notification_supports_actions () == FALSE) {
 
363
                present_notification_dialogs ();
 
364
                return TRUE;
 
365
        }
 
366
 
 
367
        /* translators: this is a popup telling you a particular device
 
368
         * has asked for pairing */
 
369
        line = g_strdup_printf(_("Pairing request for '%s'"), name);
 
370
 
 
371
        show_notification(_("Bluetooth device"),
 
372
                          line, _("Enter PIN"), 0,
 
373
                          G_CALLBACK(notification_closed));
 
374
 
 
375
        g_free(line);
 
376
 
 
377
        return TRUE;
 
378
}
 
379
 
 
380
static gboolean
 
381
confirm_request (BluetoothApplet *applet,
 
382
                 char *path,
 
383
                 char *name,
 
384
                 char *long_name,
 
385
                 guint pin,
 
386
                 gpointer user_data)
 
387
{
 
388
        char *text, *line;
 
389
 
 
390
        text = g_strdup_printf("%d", pin);
 
391
        confirm_dialog(applet, path, name, long_name, text);
 
392
        g_free(text);
605
393
 
606
394
        /* translators: this is a popup telling you a particular device
607
395
         * has asked for pairing */
608
396
        line = g_strdup_printf(_("Pairing confirmation for '%s'"), name);
609
397
 
610
 
        g_free(name);
611
 
 
612
398
        /* translators:
613
399
         * This message is for Bluetooth 2.1 support, when the
614
400
         * action is clicked in the notification popup, the user
627
413
}
628
414
 
629
415
static gboolean
630
 
authorize_request (DBusGMethodInvocation *context,
631
 
                   DBusGProxy *device,
632
 
                   const char *uuid,
633
 
                   gpointer user_data)
 
416
authorize_request (BluetoothApplet *applet,
 
417
                   char *path,
 
418
                   char *name,
 
419
                   char *long_name,
 
420
                   char *uuid,
 
421
                   gpointer user_data)
634
422
{
635
 
        DBusGProxy *adapter = user_data;
636
 
        char *name, *long_name, *line;
637
 
 
638
 
        name = device_get_name (device, &long_name);
639
 
        if (name == NULL)
640
 
                return FALSE;
641
 
 
642
 
        auth_dialog (adapter, device, name, long_name, uuid, context);
643
 
 
644
 
        g_free (long_name);
 
423
        char *line;
 
424
 
 
425
        auth_dialog (applet, path, name, long_name, uuid);
645
426
 
646
427
        if (notification_supports_actions () == FALSE) {
647
 
                g_free (name);
648
428
                present_notification_dialogs ();
649
429
                return TRUE;
650
430
        }
651
431
 
652
432
        line = g_strdup_printf (_("Authorization request from '%s'"), name);
653
433
 
654
 
        g_free (name);
655
 
 
656
434
        show_notification (_("Bluetooth device"),
657
435
                           line, _("Check authorization"), 0,
658
436
                           G_CALLBACK (notification_closed));
662
440
        return TRUE;
663
441
}
664
442
 
665
 
static gboolean cancel_request(DBusGMethodInvocation *context,
 
443
static void input_free_list (gpointer data, gpointer user_data) {
 
444
        input_data *input = data;
 
445
 
 
446
        gtk_widget_destroy(input->dialog);
 
447
 
 
448
        g_object_unref (G_OBJECT (input->applet));
 
449
        g_free(input->uuid);
 
450
        g_free(input->path);
 
451
        g_free(input);
 
452
}
 
453
 
 
454
static void cancel_request(BluetoothApplet *applet,
666
455
                                                        gpointer user_data)
667
456
{
668
 
        DBusGProxy *adapter = user_data;
669
 
        GList *list;
670
 
        GError *result;
671
 
        input_data *input;
672
 
 
673
 
        input = g_new0(input_data, 1);
674
 
        input->path = g_strdup(dbus_g_proxy_get_path(adapter));
675
 
 
676
 
        list = g_list_find_custom(input_list, input, input_compare);
677
 
 
678
 
        g_free(input->path);
679
 
        g_free(input);
680
 
 
681
 
        if (!list || !list->data)
682
 
                return FALSE;
683
 
 
684
 
        input = list->data;
685
 
 
686
 
        close_notification();
687
 
 
688
 
        result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
689
 
                                                "Agent callback cancelled");
690
 
 
691
 
        dbus_g_method_return_error(input->context, result);
692
 
 
693
 
        input_free(input);
694
 
 
695
 
        return TRUE;
696
 
}
697
 
 
698
 
static void
699
 
default_adapter_changed (GObject    *gobject,
700
 
                         GParamSpec *pspec,
701
 
                         gpointer    user_data)
702
 
{
703
 
        char *adapter_str;
704
 
 
705
 
        g_object_get (G_OBJECT (gobject), "default-adapter", &adapter_str, NULL);
706
 
        if (agent != NULL) {
707
 
                bluetooth_agent_unregister (agent);
708
 
                g_object_unref (agent);
709
 
                agent = NULL;
710
 
        }
711
 
        if (adapter_str != NULL) {
712
 
                DBusGConnection *connection;
713
 
                DBusGProxy *adapter;
714
 
 
715
 
                connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
716
 
                adapter = dbus_g_proxy_new_for_name (connection,
717
 
                                                     "org.bluez",
718
 
                                                     adapter_str,
719
 
                                                     "org.bluez.Adapter");
720
 
                dbus_g_connection_unref (connection);
721
 
 
722
 
                agent = bluetooth_agent_new();
723
 
 
724
 
                bluetooth_agent_set_pincode_func(agent, pincode_request, adapter);
725
 
                bluetooth_agent_set_passkey_func(agent, pin_request, adapter);
726
 
                bluetooth_agent_set_display_func(agent, display_request, adapter);
727
 
                bluetooth_agent_set_confirm_func(agent, confirm_request, adapter);
728
 
                bluetooth_agent_set_authorize_func(agent, authorize_request, adapter);
729
 
                bluetooth_agent_set_cancel_func(agent, cancel_request, adapter);
730
 
 
731
 
                bluetooth_agent_register(agent, adapter);
732
 
 
733
 
                g_object_unref (adapter);
734
 
        }
735
 
        g_free (adapter_str);
736
 
}
737
 
 
738
 
int setup_agents(void)
739
 
{
740
 
        dbus_g_error_domain_register(AGENT_ERROR, "org.bluez.Error",
741
 
                                                        AGENT_ERROR_TYPE);
742
 
 
743
 
        client = bluetooth_client_new();
744
 
        g_signal_connect (G_OBJECT (client), "notify::default-adapter",
745
 
                          G_CALLBACK (default_adapter_changed), NULL);
746
 
        default_adapter_changed (G_OBJECT (client), NULL, NULL);
 
457
        g_list_foreach (input_list, input_free_list, NULL);
 
458
        g_list_free (input_list);
 
459
        input_list = NULL;
 
460
}
 
461
 
 
462
int setup_agents(BluetoothApplet *applet)
 
463
{
 
464
        g_signal_connect (applet, "pincode-request",
 
465
                        G_CALLBACK (pin_request), NULL);
 
466
        g_signal_connect (applet, "confirm-request",
 
467
                        G_CALLBACK (confirm_request), NULL);
 
468
        g_signal_connect (applet, "auth-request",
 
469
                        G_CALLBACK (authorize_request), NULL);
 
470
        g_signal_connect (applet, "cancel-request",
 
471
                        G_CALLBACK (cancel_request), NULL);
747
472
 
748
473
        return 0;
749
474
}
750
475
 
751
 
void cleanup_agents(void)
752
 
{
753
 
        if (agent != NULL) {
754
 
                bluetooth_agent_unregister (agent);
755
 
                g_object_unref (agent);
756
 
        }
757
 
        g_object_unref (client);
758
 
}
759
 
 
760
476
void show_agents(void)
761
477
{
762
478
        close_notification();
763
479
 
764
480
        g_list_foreach(input_list, show_dialog, NULL);
765
 
 
766
 
        disable_blinking();
767
481
}