[gnome-bluetooth] lib: Override icons for some phone brands



commit 00284e21a1dbce2d7fd579535cd4b51e39019b48
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Dec 10 00:29:58 2013 +0100

    lib: Override icons for some phone brands
    
    Apple, Google and Samsung phones get some fancy icons instead
    of the generic one.
    
    Fixes krh's bug:
    http://www.hadess.net/2013/12/bluetooth-panel-redesign.html?showComment=1386622940545#c2299335627471329746

 lib/bluetooth-client.c |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index 6356489..e79b012 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -47,6 +47,7 @@
 #include "bluetooth-fdo-glue.h"
 #include "bluetooth-utils.h"
 #include "gnome-bluetooth-enum-types.h"
+#include "pin.h"
 
 #define BLUEZ_SERVICE                  "org.bluez"
 #define BLUEZ_MANAGER_PATH             "/"
@@ -249,7 +250,29 @@ bluetooth_client_get_connectable(const char **uuids)
 }
 
 static const char *
-audio_icon_override (BluetoothType type)
+phone_oui_to_icon_name (const char *bdaddr)
+{
+       char *vendor;
+       const char *ret = NULL;
+
+       vendor = oui_to_vendor (bdaddr);
+       if (vendor == NULL)
+               return NULL;
+
+       if (strstr (vendor, "Apple") != NULL)
+               ret = "phone-apple-iphone";
+       else if (strstr (vendor, "Samsung") != NULL)
+               ret = "phone-samsung-galaxy-s";
+       else if (strstr (vendor, "Google") != NULL)
+               ret = "phone-google-nexus-one";
+       g_free (vendor);
+
+       return ret;
+}
+
+static const char *
+icon_override (const char    *bdaddr,
+              BluetoothType  type)
 {
        /* audio-card, you're ugly */
        switch (type) {
@@ -259,6 +282,8 @@ audio_icon_override (BluetoothType type)
                return "audio-headphones";
        case BLUETOOTH_TYPE_OTHER_AUDIO:
                return "audio-speakers";
+       case BLUETOOTH_TYPE_PHONE:
+               return phone_oui_to_icon_name (bdaddr);
        default:
                return NULL;
        }
@@ -332,9 +357,16 @@ device_g_properties_changed (GDBusProxy      *device,
                } else if (g_str_equal (property, "Class") == TRUE) {
                        BluetoothType type;
                        const char *icon = NULL;
+                       char *bdaddr;
+
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
+                                           BLUETOOTH_COLUMN_ADDRESS, &bdaddr,
+                                           -1);
 
                        type = v ? bluetooth_class_to_type (g_variant_get_uint32 (v)) : BLUETOOTH_TYPE_ANY;
-                       icon = audio_icon_override (type);
+                       icon = icon_override (bdaddr, type);
+
+                       g_free (bdaddr);
 
                        if (icon) {
                                gtk_tree_store_set (priv->store, &iter,
@@ -405,7 +437,7 @@ device_added (ObjectManager   *manager,
 
        v = g_variant_lookup_value (dict, "Class", G_VARIANT_TYPE_UINT32);
        type = v ? bluetooth_class_to_type (g_variant_get_uint32 (v)) : BLUETOOTH_TYPE_ANY;
-       icon = audio_icon_override (type);
+       icon = icon_override (address, type);
 
        if (icon == NULL) {
                v = g_variant_lookup_value (dict, "Icon", G_VARIANT_TYPE_STRING);


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