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