diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-01-20 12:29:21 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-01-20 15:14:51 +0100 |
commit | 6f611a6776bb27c7c2019ee596750f327a85092e (patch) | |
tree | 3d967414308ae44800c50a955fedf8a04d940e15 /lib | |
parent | d1cb796fd6bdbbf5ea07dd179a0869e5fe5f831b (diff) | |
download | gnome-bluetooth-6f611a6776bb27c7c2019ee596750f327a85092e.tar.gz |
lib: Add connectable property to BluetoothDevice
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bluetooth-device.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/bluetooth-device.c b/lib/bluetooth-device.c index a49d8a83..9dc8d5a5 100644 --- a/lib/bluetooth-device.c +++ b/lib/bluetooth-device.c @@ -24,6 +24,7 @@ enum { PROP_CONNECTED, PROP_LEGACYPAIRING, PROP_UUIDS, + PROP_CONNECTABLE, }; struct _BluetoothDevice { @@ -40,11 +41,47 @@ struct _BluetoothDevice { gboolean connected; gboolean legacy_pairing; char **uuids; + gboolean connectable; +}; + +static const char *connectable_uuids[] = { + "HSP", + "AudioSource", + "AudioSink", + "A/V_RemoteControlTarget", + "A/V_RemoteControl", + "Headset_-_AG", + "Handsfree", + "HandsfreeAudioGateway", + "HumanInterfaceDeviceService", + "Human Interface Device", }; G_DEFINE_TYPE(BluetoothDevice, bluetooth_device, G_TYPE_OBJECT) static void +update_connectable (BluetoothDevice *device) +{ + gboolean new_connectable = FALSE; + + if (device->uuids) { + guint i; + + for (i = 0; i < G_N_ELEMENTS (connectable_uuids); i++) { + if (g_strv_contains ((const char * const*) device->uuids, connectable_uuids[i])) { + new_connectable = TRUE; + break; + } + } + } + + if (new_connectable != device->connectable) { + device->connectable = new_connectable; + g_object_notify (G_OBJECT (device), "connectable"); + } +} + +static void bluetooth_device_get_property (GObject *object, guint property_id, GValue *value, @@ -139,6 +176,7 @@ bluetooth_device_set_property (GObject *object, case PROP_UUIDS: g_clear_pointer (&device->uuids, g_strfreev); device->uuids = g_value_dup_boxed (value); + update_connectable (device); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); @@ -201,6 +239,9 @@ static void bluetooth_device_class_init(BluetoothDeviceClass *klass) g_object_class_install_property (object_class, PROP_UUIDS, g_param_spec_boxed ("uuids", NULL, "UUIDs", G_TYPE_STRV, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_CONNECTABLE, + g_param_spec_boolean ("connectable", NULL, "Connectable", + FALSE, G_PARAM_READABLE)); } static void |