aboutsummaryrefslogtreecommitdiffstats
path: root/meta-gnome/recipes-extended/polkit-gnome/polkit-gnome/0003-Get-user-icon-from-accountsservice-instead-of-lookin.patch
blob: a3759c4dcf52e1a0f61422007e2c040c0b06371b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
From: Marc Deslauriers <marc.deslauriers@canonical.com>
Date: Mon, 30 Apr 2018 18:03:22 +0000
Subject: Get user icon from accountsservice instead of looking in ~/.face

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=669857
Bug-Ubuntu: https://launchpad.net/bugs/928249

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/polkitgnomeauthenticationdialog.c | 107 ++++++++++++++++++++++++++++++----
 1 file changed, 97 insertions(+), 10 deletions(-)

diff --git a/src/polkitgnomeauthenticationdialog.c b/src/polkitgnomeauthenticationdialog.c
index efd4185..565da87 100644
--- a/src/polkitgnomeauthenticationdialog.c
+++ b/src/polkitgnomeauthenticationdialog.c
@@ -135,6 +135,102 @@ user_combobox_changed (GtkComboBox *widget,
     }
 }
 
+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
+    {
+      /* TODO: we probably shouldn't hard-code the size to 16x16 */
+      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
 create_user_combobox (PolkitGnomeAuthenticationDialog *dialog)
 {
@@ -197,16 +293,7 @@ create_user_combobox (PolkitGnomeAuthenticationDialog *dialog)
       g_free (gecos);
 
       /* Load users face */
-      pixbuf = NULL;
-      if (passwd->pw_dir != NULL)
-        {
-          gchar *path;
-          path = g_strdup_printf ("%s/.face", passwd->pw_dir);
-          /* TODO: we probably shouldn't hard-code the size to 16x16 */
-          pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 16, 16, TRUE, NULL);
-          g_free (path);
-        }
-
+      pixbuf = get_user_icon (dialog->priv->users[n]);
       /* fall back to avatar-default icon */
       if (pixbuf == NULL)
         {