blob: a3759c4dcf52e1a0f61422007e2c040c0b06371b [file] [log] [blame]
Patrick Williams8e7b46e2023-05-01 14:19:06 -05001From: Marc Deslauriers <marc.deslauriers@canonical.com>
2Date: Mon, 30 Apr 2018 18:03:22 +0000
3Subject: Get user icon from accountsservice instead of looking in ~/.face
4
5Bug: https://bugzilla.gnome.org/show_bug.cgi?id=669857
6Bug-Ubuntu: https://launchpad.net/bugs/928249
7
8Upstream-Status: Pending
9Signed-off-by: Khem Raj <raj.khem@gmail.com>
10---
11 src/polkitgnomeauthenticationdialog.c | 107 ++++++++++++++++++++++++++++++----
12 1 file changed, 97 insertions(+), 10 deletions(-)
13
14diff --git a/src/polkitgnomeauthenticationdialog.c b/src/polkitgnomeauthenticationdialog.c
15index efd4185..565da87 100644
16--- a/src/polkitgnomeauthenticationdialog.c
17+++ b/src/polkitgnomeauthenticationdialog.c
18@@ -135,6 +135,102 @@ user_combobox_changed (GtkComboBox *widget,
19 }
20 }
21
22+static GdkPixbuf *
23+get_user_icon (char *username)
24+{
25+ GError *error;
26+ GDBusConnection *connection;
27+ GVariant *find_user_result;
28+ GVariant *get_icon_result;
29+ GVariant *icon_result_variant;
30+ const gchar *user_path;
31+ const gchar *icon_filename;
32+ GdkPixbuf *pixbuf;
33+
34+ error = NULL;
35+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
36+
37+ if (connection == NULL)
38+ {
39+ g_warning ("Unable to connect to system bus: %s", error->message);
40+ g_error_free (error);
41+ return NULL;
42+ }
43+
44+ find_user_result = g_dbus_connection_call_sync (connection,
45+ "org.freedesktop.Accounts",
46+ "/org/freedesktop/Accounts",
47+ "org.freedesktop.Accounts",
48+ "FindUserByName",
49+ g_variant_new ("(s)",
50+ username),
51+ G_VARIANT_TYPE ("(o)"),
52+ G_DBUS_CALL_FLAGS_NONE,
53+ -1,
54+ NULL,
55+ &error);
56+
57+ if (find_user_result == NULL)
58+ {
59+ g_warning ("Accounts couldn't find user: %s", error->message);
60+ g_error_free (error);
61+ return NULL;
62+ }
63+
64+ user_path = g_variant_get_string (g_variant_get_child_value (find_user_result, 0),
65+ NULL);
66+
67+ get_icon_result = g_dbus_connection_call_sync (connection,
68+ "org.freedesktop.Accounts",
69+ user_path,
70+ "org.freedesktop.DBus.Properties",
71+ "Get",
72+ g_variant_new ("(ss)",
73+ "org.freedesktop.Accounts.User",
74+ "IconFile"),
75+ G_VARIANT_TYPE ("(v)"),
76+ G_DBUS_CALL_FLAGS_NONE,
77+ -1,
78+ NULL,
79+ &error);
80+
81+ g_variant_unref (find_user_result);
82+
83+ if (get_icon_result == NULL)
84+ {
85+ g_warning ("Accounts couldn't find user icon: %s", error->message);
86+ g_error_free (error);
87+ return NULL;
88+ }
89+
90+ g_variant_get_child (get_icon_result, 0, "v", &icon_result_variant);
91+ icon_filename = g_variant_get_string (icon_result_variant, NULL);
92+
93+ if (icon_filename == NULL)
94+ {
95+ g_warning ("Accounts didn't return a valid filename for user icon");
96+ pixbuf = NULL;
97+ }
98+ else
99+ {
100+ /* TODO: we probably shouldn't hard-code the size to 16x16 */
101+ pixbuf = gdk_pixbuf_new_from_file_at_size (icon_filename,
102+ 16,
103+ 16,
104+ &error);
105+ if (pixbuf == NULL)
106+ {
107+ g_warning ("Couldn't open user icon: %s", error->message);
108+ g_error_free (error);
109+ }
110+ }
111+
112+ g_variant_unref (icon_result_variant);
113+ g_variant_unref (get_icon_result);
114+
115+ return pixbuf;
116+}
117+
118 static void
119 create_user_combobox (PolkitGnomeAuthenticationDialog *dialog)
120 {
121@@ -197,16 +293,7 @@ create_user_combobox (PolkitGnomeAuthenticationDialog *dialog)
122 g_free (gecos);
123
124 /* Load users face */
125- pixbuf = NULL;
126- if (passwd->pw_dir != NULL)
127- {
128- gchar *path;
129- path = g_strdup_printf ("%s/.face", passwd->pw_dir);
130- /* TODO: we probably shouldn't hard-code the size to 16x16 */
131- pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 16, 16, TRUE, NULL);
132- g_free (path);
133- }
134-
135+ pixbuf = get_user_icon (dialog->priv->users[n]);
136 /* fall back to avatar-default icon */
137 if (pixbuf == NULL)
138 {