[gnome-bluetooth] lib: Store Properties proxy in GtkTree too



commit c8da744037ce2892ad776ed843f1ca84c696f741
Author: Gustavo Padovan <gustavo padovan collabora co uk>
Date:   Fri Jun 14 16:29:18 2013 +0100

    lib: Store Properties proxy in GtkTree too
    
    Since it is used more than once in the code we store it to easier access.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701399

 lib/bluetooth-client.c |   45 +++++++++++++++++++++++++++++++++++----------
 lib/bluetooth-enums.h  |    2 ++
 2 files changed, 37 insertions(+), 10 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index 9df530b..6adb604 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -313,6 +313,7 @@ device_added (ObjectManager   *manager,
        BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
        GDBusProxy *adapter;
        Device1 *device;
+       Properties *properties;
        GVariant *v, *dict;
        const char *adapter_path, *address, *alias, *name, *icon;
        char **uuids;
@@ -330,6 +331,13 @@ device_added (ObjectManager   *manager,
        if (device == NULL)
                return;
 
+       properties = properties_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | 
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                                       BLUEZ_SERVICE,
+                                                       path,
+                                                       NULL,
+                                                       NULL);
+
        dict = g_variant_lookup_value (variant, BLUEZ_DEVICE_INTERFACE,
                                       G_VARIANT_TYPE_DICTIONARY);
 
@@ -389,12 +397,14 @@ device_added (ObjectManager   *manager,
                           BLUETOOTH_COLUMN_CONNECTED, connected,
                           BLUETOOTH_COLUMN_TRUSTED, trusted,
                           BLUETOOTH_COLUMN_PROXY, device,
+                          BLUETOOTH_COLUMN_PROPERTIES, properties,
                           -1);
        g_strfreev (uuids);
 
        g_signal_connect (G_OBJECT (device), "g-properties-changed",
                          G_CALLBACK (device_g_properties_changed), client);
 
+       g_object_unref (properties);
        g_object_unref (device);
        g_object_unref (adapter);
 }
@@ -539,6 +549,7 @@ adapter_added (ObjectManager   *manager,
        BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
        GtkTreeIter iter;
        Adapter1 *adapter;
+       Properties *properties;
        const gchar *address, *name;
        GVariant *v, *dict;
        gboolean discovering, discoverable, powered;
@@ -550,6 +561,13 @@ adapter_added (ObjectManager   *manager,
                                                   NULL,
                                                   NULL);
 
+       properties = properties_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | 
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                                       BLUEZ_SERVICE,
+                                                       path,
+                                                       NULL,
+                                                       NULL);
+
        dict = g_variant_lookup_value (variant, BLUEZ_ADAPTER_INTERFACE,
                               G_VARIANT_TYPE_DICTIONARY);
 
@@ -570,6 +588,7 @@ adapter_added (ObjectManager   *manager,
 
        gtk_tree_store_insert_with_values(priv->store, &iter, NULL, -1,
                                          BLUETOOTH_COLUMN_PROXY, adapter,
+                                         BLUETOOTH_COLUMN_PROPERTIES, properties,
                                          BLUETOOTH_COLUMN_ADDRESS, address,
                                          BLUETOOTH_COLUMN_NAME, name,
                                          BLUETOOTH_COLUMN_DISCOVERING, discovering,
@@ -582,6 +601,7 @@ adapter_added (ObjectManager   *manager,
 
        default_adapter_changed (manager, path, client);
 
+       g_object_unref (properties);
        g_object_unref (adapter);
 }
 
@@ -756,7 +776,8 @@ static void bluetooth_client_init(BluetoothClient *client)
        BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
 
        priv->store = gtk_tree_store_new(_BLUETOOTH_NUM_COLUMNS, G_TYPE_OBJECT,
-                                        G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+                                        G_TYPE_OBJECT, G_TYPE_STRING,
+                                        G_TYPE_STRING, G_TYPE_STRING,
                                         G_TYPE_UINT, G_TYPE_STRING,
                                         G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
                                         G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_INT,
@@ -888,11 +909,12 @@ _bluetooth_client_set_discoverable (BluetoothClient *client,
                                    gboolean discoverable,
                                    guint timeout)
 {
+       BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE (client);
        GError *error = NULL;
        GDBusProxy *adapter;
        Properties *properties;
-       const char *path;
        gboolean ret;
+       GtkTreeIter iter;
 
        g_return_val_if_fail (BLUETOOTH_IS_CLIENT (client), FALSE);
 
@@ -900,11 +922,9 @@ _bluetooth_client_set_discoverable (BluetoothClient *client,
        if (adapter == NULL)
                return FALSE;
 
-       path = g_dbus_proxy_get_object_path (adapter);
-
-       properties = properties_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
-                                                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | 
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
-                                                       BLUEZ_SERVICE, path, NULL, NULL);
+       get_iter_from_proxy (priv->store, &iter, adapter);
+       gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
+                           BLUETOOTH_COLUMN_PROPERTIES, &properties, -1);
 
        if (properties == NULL)
                return FALSE;
@@ -920,6 +940,7 @@ _bluetooth_client_set_discoverable (BluetoothClient *client,
                g_error_free (error);
        }
 
+       g_object_unref (properties);
        g_object_unref(adapter);
 
        return ret;
@@ -1338,16 +1359,20 @@ bluetooth_client_set_trusted (BluetoothClient *client,
                              const char      *device,
                              gboolean         trusted)
 {
+       BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
        Properties *properties;
        GError     *error = NULL;
+       GtkTreeIter iter;
        gboolean   ret;
 
        g_return_val_if_fail (BLUETOOTH_IS_CLIENT (client), FALSE);
        g_return_val_if_fail (device != NULL, FALSE);
 
-       properties = properties_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
-                                                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | 
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
-                                                       BLUEZ_SERVICE, device, NULL, NULL);
+       if (get_iter_from_path (priv->store, &iter, device) == FALSE)
+               return FALSE;
+
+       gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
+                           BLUETOOTH_COLUMN_PROPERTIES, &properties, -1);
 
        if (properties == NULL)
                return FALSE;
diff --git a/lib/bluetooth-enums.h b/lib/bluetooth-enums.h
index 5874037..65403ec 100644
--- a/lib/bluetooth-enums.h
+++ b/lib/bluetooth-enums.h
@@ -113,6 +113,7 @@ typedef enum {
 /**
  * BluetoothColumn:
  * @BLUETOOTH_COLUMN_PROXY: a #GDBusProxy object
+ * @BLUETOOTH_COLUMN_PROPERTIES: a #GDBusProxy object for DBus.Properties
  * @BLUETOOTH_COLUMN_ADDRESS: a string representing a Bluetooth address
  * @BLUETOOTH_COLUMN_ALIAS: a string to use for display (the name of the device, or its address if the name 
is not known). Only available for devices.
  * @BLUETOOTH_COLUMN_NAME: a string representing the device or adapter's name
@@ -133,6 +134,7 @@ typedef enum {
  **/
 typedef enum {
        BLUETOOTH_COLUMN_PROXY,
+       BLUETOOTH_COLUMN_PROPERTIES,
        BLUETOOTH_COLUMN_ADDRESS,
        BLUETOOTH_COLUMN_ALIAS,
        BLUETOOTH_COLUMN_NAME,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]