[gnome-flashback] polkit: use accountsservice to fetch user icon



commit d28752176ef618799603208761ab6daae037ad60
Author: Marc Deslauriers <marc deslauriers ubuntu com>
Date:   Sat Feb 11 00:35:48 2012 -0500

    polkit: use accountsservice to fetch user icon
    
    Use accountsservice to obtain the user's face icon instead of
    attempting to get it from ~/.face, which is no longer the right
    location.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669857

 .../libpolkit/flashback-polkit-dialog.c            |  103 ++++++++++++++++++--
 1 files changed, 93 insertions(+), 10 deletions(-)
---
diff --git a/gnome-flashback/libpolkit/flashback-polkit-dialog.c 
b/gnome-flashback/libpolkit/flashback-polkit-dialog.c
index 9434b05..24a2911 100644
--- a/gnome-flashback/libpolkit/flashback-polkit-dialog.c
+++ b/gnome-flashback/libpolkit/flashback-polkit-dialog.c
@@ -268,6 +268,98 @@ users_combobox_changed_cb (GtkComboBox *combobox,
   gtk_widget_set_sensitive (dialog->auth_button, TRUE);
 }
 
+static GdkPixbuf *
+get_user_icon (char *username)
+{
+  GError *error;
+  GDBusConnection *connection;
+  GVariant *find_user_result;
+  GVariant *get_icon_result;
+  GVariant *icon_result_variant;
+  const gchar *user_path;
+  const gchar *icon_filename;
+  GdkPixbuf *pixbuf;
+
+  error = NULL;
+  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+
+  if (connection == NULL)
+    {
+      g_warning ("Unable to connect to system bus: %s", error->message);
+      g_error_free (error);
+      return NULL;
+    }
+
+  find_user_result = g_dbus_connection_call_sync (connection,
+                                          "org.freedesktop.Accounts",
+                                          "/org/freedesktop/Accounts",
+                                          "org.freedesktop.Accounts",
+                                          "FindUserByName",
+                                          g_variant_new ("(s)",
+                                          username),
+                                          G_VARIANT_TYPE ("(o)"),
+                                          G_DBUS_CALL_FLAGS_NONE,
+                                          -1,
+                                          NULL,
+                                          &error);
+
+  if (find_user_result == NULL)
+    {
+      g_warning ("Accounts couldn't find user: %s", error->message);
+      g_error_free (error);
+      return NULL;
+    }
+
+  user_path = g_variant_get_string (g_variant_get_child_value (find_user_result, 0),
+                                    NULL);
+
+  get_icon_result = g_dbus_connection_call_sync (connection,
+                                                 "org.freedesktop.Accounts",
+                                                 user_path,
+                                                 "org.freedesktop.DBus.Properties",
+                                                 "Get",
+                                                 g_variant_new ("(ss)",
+                                                                "org.freedesktop.Accounts.User",
+                                                                "IconFile"),
+                                                 G_VARIANT_TYPE ("(v)"),
+                                                 G_DBUS_CALL_FLAGS_NONE,
+                                                 -1,
+                                                 NULL,
+                                                 &error);
+
+  g_variant_unref (find_user_result);
+
+  if (get_icon_result == NULL)
+    {
+      g_warning ("Accounts couldn't find user icon: %s", error->message);
+      g_error_free (error);
+      return NULL;
+    }
+
+  g_variant_get_child (get_icon_result, 0, "v", &icon_result_variant);
+  icon_filename = g_variant_get_string (icon_result_variant, NULL);
+
+  if (icon_filename == NULL)
+    {
+      g_warning ("Accounts didn't return a valid filename for user icon");
+      pixbuf = NULL;
+    }
+  else
+    {
+      pixbuf = gdk_pixbuf_new_from_file_at_size (icon_filename, 16, 16, &error);
+      if (pixbuf == NULL)
+        {
+          g_warning ("Couldn't open user icon: %s", error->message);
+          g_error_free (error);
+        }
+    }
+
+  g_variant_unref (icon_result_variant);
+  g_variant_unref (get_icon_result);
+
+  return pixbuf;
+}
+
 static void
 setup_users_store (FlashbackPolkitDialog *dialog)
 {
@@ -332,16 +424,7 @@ setup_users_store (FlashbackPolkitDialog *dialog)
 
       g_free (gecos);
 
-      pixbuf = NULL;
-      if (passwd->pw_dir != NULL)
-        {
-          gchar *path;
-
-          path = g_strdup_printf ("%s/.face", passwd->pw_dir);
-          pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 16, 16, TRUE, NULL);
-
-          g_free (path);
-        }
+      pixbuf = get_user_icon (dialog->users[i]);
 
       if (pixbuf == NULL)
         {


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