1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
2 | * |
---|
3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
4 | * Copyright (C) 2007 Ray Strode <rstrode@redhat.com> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include "config.h" |
---|
23 | |
---|
24 | #include <stdlib.h> |
---|
25 | #include <stdio.h> |
---|
26 | #include <unistd.h> |
---|
27 | #include <string.h> |
---|
28 | #include <errno.h> |
---|
29 | #include <dirent.h> |
---|
30 | #include <sys/stat.h> |
---|
31 | |
---|
32 | #include <glib.h> |
---|
33 | #include <glib/gi18n.h> |
---|
34 | #include <glib/gstdio.h> |
---|
35 | #include <gtk/gtk.h> |
---|
36 | |
---|
37 | #include <gconf/gconf-client.h> |
---|
38 | |
---|
39 | #include "gdm-user-manager.h" |
---|
40 | #include "gdm-user-chooser-widget.h" |
---|
41 | |
---|
42 | |
---|
43 | #define KEY_DISABLE_USER_LIST "/apps/gdm/simple-greeter/disable_user_list" |
---|
44 | |
---|
45 | enum { |
---|
46 | USER_NO_DISPLAY = 1 << 0, |
---|
47 | USER_ACCOUNT_DISABLED = 1 << 1, |
---|
48 | }; |
---|
49 | |
---|
50 | #define DEFAULT_USER_ICON "stock_person" |
---|
51 | |
---|
52 | #define GDM_USER_CHOOSER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_USER_CHOOSER_WIDGET, GdmUserChooserWidgetPrivate)) |
---|
53 | |
---|
54 | #define MAX_ICON_SIZE 128 |
---|
55 | |
---|
56 | struct GdmUserChooserWidgetPrivate |
---|
57 | { |
---|
58 | GdmUserManager *manager; |
---|
59 | GtkIconTheme *icon_theme; |
---|
60 | |
---|
61 | GdkPixbuf *logged_in_pixbuf; |
---|
62 | GdkPixbuf *stock_person_pixbuf; |
---|
63 | |
---|
64 | guint loaded : 1; |
---|
65 | guint show_user_other : 1; |
---|
66 | guint show_user_guest : 1; |
---|
67 | guint show_user_auto : 1; |
---|
68 | guint show_normal_users : 1; |
---|
69 | |
---|
70 | guint has_user_other : 1; |
---|
71 | |
---|
72 | guint load_idle_id; |
---|
73 | }; |
---|
74 | |
---|
75 | enum { |
---|
76 | PROP_0, |
---|
77 | PROP_SHOW_USER_GUEST, |
---|
78 | PROP_SHOW_USER_AUTO, |
---|
79 | PROP_SHOW_USER_OTHER, |
---|
80 | }; |
---|
81 | |
---|
82 | static void gdm_user_chooser_widget_class_init (GdmUserChooserWidgetClass *klass); |
---|
83 | static void gdm_user_chooser_widget_init (GdmUserChooserWidget *user_chooser_widget); |
---|
84 | static void gdm_user_chooser_widget_finalize (GObject *object); |
---|
85 | |
---|
86 | G_DEFINE_TYPE (GdmUserChooserWidget, gdm_user_chooser_widget, GDM_TYPE_CHOOSER_WIDGET) |
---|
87 | |
---|
88 | static void add_user_other (GdmUserChooserWidget *widget); |
---|
89 | static void remove_user_other (GdmUserChooserWidget *widget); |
---|
90 | |
---|
91 | static int |
---|
92 | get_font_height_for_widget (GtkWidget *widget) |
---|
93 | { |
---|
94 | PangoFontMetrics *metrics; |
---|
95 | PangoContext *context; |
---|
96 | int ascent; |
---|
97 | int descent; |
---|
98 | int height; |
---|
99 | |
---|
100 | gtk_widget_ensure_style (widget); |
---|
101 | context = gtk_widget_get_pango_context (widget); |
---|
102 | metrics = pango_context_get_metrics (context, |
---|
103 | widget->style->font_desc, |
---|
104 | pango_context_get_language (context)); |
---|
105 | |
---|
106 | ascent = pango_font_metrics_get_ascent (metrics); |
---|
107 | descent = pango_font_metrics_get_descent (metrics); |
---|
108 | height = PANGO_PIXELS (ascent + descent); |
---|
109 | pango_font_metrics_unref (metrics); |
---|
110 | return height; |
---|
111 | } |
---|
112 | |
---|
113 | static int |
---|
114 | get_icon_height_for_widget (GtkWidget *widget) |
---|
115 | { |
---|
116 | int font_height; |
---|
117 | int height; |
---|
118 | |
---|
119 | font_height = get_font_height_for_widget (widget); |
---|
120 | height = 3 * font_height; |
---|
121 | if (height > MAX_ICON_SIZE) { |
---|
122 | height = MAX_ICON_SIZE; |
---|
123 | } |
---|
124 | |
---|
125 | g_debug ("GdmUserChooserWidget: font height %d; using icon size %d", font_height, height); |
---|
126 | |
---|
127 | return height; |
---|
128 | } |
---|
129 | |
---|
130 | static void |
---|
131 | update_other_user_visibility (GdmUserChooserWidget *widget) |
---|
132 | { |
---|
133 | int number_of_users; |
---|
134 | |
---|
135 | if (!widget->priv->show_user_other) { |
---|
136 | if (widget->priv->has_user_other) { |
---|
137 | remove_user_other (widget); |
---|
138 | } |
---|
139 | |
---|
140 | return; |
---|
141 | } |
---|
142 | |
---|
143 | number_of_users = gdm_chooser_widget_get_number_of_items (GDM_CHOOSER_WIDGET (widget)); |
---|
144 | |
---|
145 | /* we hide the Other user if it's the last one, and we show it |
---|
146 | * if there's another user */ |
---|
147 | if (number_of_users == 1 && widget->priv->has_user_other) { |
---|
148 | remove_user_other (widget); |
---|
149 | } if (number_of_users >= 1 && !widget->priv->has_user_other) { |
---|
150 | add_user_other (widget); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | static void |
---|
155 | add_user_other (GdmUserChooserWidget *widget) |
---|
156 | { |
---|
157 | widget->priv->has_user_other = TRUE; |
---|
158 | gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget), |
---|
159 | GDM_USER_CHOOSER_USER_OTHER, |
---|
160 | NULL, |
---|
161 | /* translators: This option prompts |
---|
162 | * the user to type in a username |
---|
163 | * manually instead of choosing from |
---|
164 | * a list. |
---|
165 | */ |
---|
166 | C_("user", "Other..."), |
---|
167 | _("Choose a different account"), |
---|
168 | 0, |
---|
169 | FALSE, |
---|
170 | TRUE); |
---|
171 | } |
---|
172 | |
---|
173 | static void |
---|
174 | add_user_guest (GdmUserChooserWidget *widget) |
---|
175 | { |
---|
176 | gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget), |
---|
177 | GDM_USER_CHOOSER_USER_GUEST, |
---|
178 | widget->priv->stock_person_pixbuf, |
---|
179 | _("Guest"), |
---|
180 | _("Login as a temporary guest"), |
---|
181 | 0, |
---|
182 | FALSE, |
---|
183 | TRUE); |
---|
184 | update_other_user_visibility (widget); |
---|
185 | } |
---|
186 | |
---|
187 | static void |
---|
188 | add_user_auto (GdmUserChooserWidget *widget) |
---|
189 | { |
---|
190 | gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget), |
---|
191 | GDM_USER_CHOOSER_USER_AUTO, |
---|
192 | NULL, |
---|
193 | _("Automatic Login"), |
---|
194 | _("Automatically login to the system after selecting options"), |
---|
195 | 0, |
---|
196 | FALSE, |
---|
197 | TRUE); |
---|
198 | update_other_user_visibility (widget); |
---|
199 | } |
---|
200 | |
---|
201 | static void |
---|
202 | remove_user_other (GdmUserChooserWidget *widget) |
---|
203 | { |
---|
204 | widget->priv->has_user_other = FALSE; |
---|
205 | gdm_chooser_widget_remove_item (GDM_CHOOSER_WIDGET (widget), |
---|
206 | GDM_USER_CHOOSER_USER_OTHER); |
---|
207 | } |
---|
208 | |
---|
209 | static void |
---|
210 | remove_user_guest (GdmUserChooserWidget *widget) |
---|
211 | { |
---|
212 | gdm_chooser_widget_remove_item (GDM_CHOOSER_WIDGET (widget), |
---|
213 | GDM_USER_CHOOSER_USER_GUEST); |
---|
214 | update_other_user_visibility (widget); |
---|
215 | } |
---|
216 | |
---|
217 | static void |
---|
218 | remove_user_auto (GdmUserChooserWidget *widget) |
---|
219 | { |
---|
220 | gdm_chooser_widget_remove_item (GDM_CHOOSER_WIDGET (widget), |
---|
221 | GDM_USER_CHOOSER_USER_AUTO); |
---|
222 | update_other_user_visibility (widget); |
---|
223 | } |
---|
224 | |
---|
225 | void |
---|
226 | gdm_user_chooser_widget_set_show_user_other (GdmUserChooserWidget *widget, |
---|
227 | gboolean show_user) |
---|
228 | { |
---|
229 | g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (widget)); |
---|
230 | |
---|
231 | if (widget->priv->show_user_other != show_user) { |
---|
232 | widget->priv->show_user_other = show_user; |
---|
233 | update_other_user_visibility (widget); |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | void |
---|
238 | gdm_user_chooser_widget_set_show_user_guest (GdmUserChooserWidget *widget, |
---|
239 | gboolean show_user) |
---|
240 | { |
---|
241 | g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (widget)); |
---|
242 | |
---|
243 | if (widget->priv->show_user_guest != show_user) { |
---|
244 | widget->priv->show_user_guest = show_user; |
---|
245 | if (show_user) { |
---|
246 | add_user_guest (widget); |
---|
247 | } else { |
---|
248 | remove_user_guest (widget); |
---|
249 | } |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | void |
---|
254 | gdm_user_chooser_widget_set_show_user_auto (GdmUserChooserWidget *widget, |
---|
255 | gboolean show_user) |
---|
256 | { |
---|
257 | g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (widget)); |
---|
258 | |
---|
259 | if (widget->priv->show_user_auto != show_user) { |
---|
260 | widget->priv->show_user_auto = show_user; |
---|
261 | if (show_user) { |
---|
262 | add_user_auto (widget); |
---|
263 | } else { |
---|
264 | remove_user_auto (widget); |
---|
265 | } |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | char * |
---|
270 | gdm_user_chooser_widget_get_chosen_user_name (GdmUserChooserWidget *widget) |
---|
271 | { |
---|
272 | g_return_val_if_fail (GDM_IS_USER_CHOOSER_WIDGET (widget), NULL); |
---|
273 | |
---|
274 | return gdm_chooser_widget_get_active_item (GDM_CHOOSER_WIDGET (widget)); |
---|
275 | } |
---|
276 | |
---|
277 | void |
---|
278 | gdm_user_chooser_widget_set_chosen_user_name (GdmUserChooserWidget *widget, |
---|
279 | const char *name) |
---|
280 | { |
---|
281 | g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (widget)); |
---|
282 | |
---|
283 | gdm_chooser_widget_set_active_item (GDM_CHOOSER_WIDGET (widget), name); |
---|
284 | } |
---|
285 | |
---|
286 | void |
---|
287 | gdm_user_chooser_widget_set_show_only_chosen (GdmUserChooserWidget *widget, |
---|
288 | gboolean show_only) { |
---|
289 | g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (widget)); |
---|
290 | |
---|
291 | gdm_chooser_widget_set_hide_inactive_items (GDM_CHOOSER_WIDGET (widget), |
---|
292 | show_only); |
---|
293 | |
---|
294 | } |
---|
295 | static void |
---|
296 | gdm_user_chooser_widget_set_property (GObject *object, |
---|
297 | guint prop_id, |
---|
298 | const GValue *value, |
---|
299 | GParamSpec *pspec) |
---|
300 | { |
---|
301 | GdmUserChooserWidget *self; |
---|
302 | |
---|
303 | self = GDM_USER_CHOOSER_WIDGET (object); |
---|
304 | |
---|
305 | switch (prop_id) { |
---|
306 | case PROP_SHOW_USER_AUTO: |
---|
307 | gdm_user_chooser_widget_set_show_user_auto (self, g_value_get_boolean (value)); |
---|
308 | break; |
---|
309 | case PROP_SHOW_USER_GUEST: |
---|
310 | gdm_user_chooser_widget_set_show_user_guest (self, g_value_get_boolean (value)); |
---|
311 | break; |
---|
312 | case PROP_SHOW_USER_OTHER: |
---|
313 | gdm_user_chooser_widget_set_show_user_other (self, g_value_get_boolean (value)); |
---|
314 | break; |
---|
315 | default: |
---|
316 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
317 | break; |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | static void |
---|
322 | gdm_user_chooser_widget_get_property (GObject *object, |
---|
323 | guint prop_id, |
---|
324 | GValue *value, |
---|
325 | GParamSpec *pspec) |
---|
326 | { |
---|
327 | GdmUserChooserWidget *self; |
---|
328 | |
---|
329 | self = GDM_USER_CHOOSER_WIDGET (object); |
---|
330 | |
---|
331 | switch (prop_id) { |
---|
332 | case PROP_SHOW_USER_AUTO: |
---|
333 | g_value_set_boolean (value, self->priv->show_user_auto); |
---|
334 | break; |
---|
335 | case PROP_SHOW_USER_GUEST: |
---|
336 | g_value_set_boolean (value, self->priv->show_user_guest); |
---|
337 | break; |
---|
338 | case PROP_SHOW_USER_OTHER: |
---|
339 | g_value_set_boolean (value, self->priv->show_user_other); |
---|
340 | break; |
---|
341 | default: |
---|
342 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
343 | break; |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | static gboolean |
---|
348 | is_user_list_disabled (GdmUserChooserWidget *widget) |
---|
349 | { |
---|
350 | GConfClient *client; |
---|
351 | GError *error; |
---|
352 | gboolean result; |
---|
353 | |
---|
354 | client = gconf_client_get_default (); |
---|
355 | error = NULL; |
---|
356 | result = gconf_client_get_bool (client, KEY_DISABLE_USER_LIST, &error); |
---|
357 | if (error != NULL) { |
---|
358 | g_debug ("GdmUserChooserWidget: unable to get disable-user-list configuration: %s", error->message); |
---|
359 | g_error_free (error); |
---|
360 | } |
---|
361 | g_object_unref (client); |
---|
362 | |
---|
363 | return result; |
---|
364 | } |
---|
365 | |
---|
366 | static void |
---|
367 | add_user (GdmUserChooserWidget *widget, |
---|
368 | GdmUser *user) |
---|
369 | { |
---|
370 | GdkPixbuf *pixbuf; |
---|
371 | char *tooltip; |
---|
372 | gboolean is_logged_in; |
---|
373 | int size; |
---|
374 | |
---|
375 | if (!widget->priv->show_normal_users) { |
---|
376 | return; |
---|
377 | } |
---|
378 | |
---|
379 | size = get_icon_height_for_widget (GTK_WIDGET (widget)); |
---|
380 | pixbuf = gdm_user_render_icon (user, size); |
---|
381 | if (pixbuf == NULL && widget->priv->stock_person_pixbuf != NULL) { |
---|
382 | pixbuf = g_object_ref (widget->priv->stock_person_pixbuf); |
---|
383 | } |
---|
384 | |
---|
385 | tooltip = g_strdup_printf (_("Log in as %s"), |
---|
386 | gdm_user_get_user_name (user)); |
---|
387 | |
---|
388 | is_logged_in = gdm_user_get_num_sessions (user) > 0; |
---|
389 | |
---|
390 | g_debug ("GdmUserChooserWidget: User added name:%s logged-in:%d pixbuf:%p", |
---|
391 | gdm_user_get_user_name (user), |
---|
392 | is_logged_in, |
---|
393 | pixbuf); |
---|
394 | |
---|
395 | gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget), |
---|
396 | gdm_user_get_user_name (user), |
---|
397 | pixbuf, |
---|
398 | gdm_user_get_display_name (user), |
---|
399 | tooltip, |
---|
400 | gdm_user_get_login_frequency (user), |
---|
401 | is_logged_in, |
---|
402 | FALSE); |
---|
403 | g_free (tooltip); |
---|
404 | |
---|
405 | if (pixbuf != NULL) { |
---|
406 | g_object_unref (pixbuf); |
---|
407 | } |
---|
408 | |
---|
409 | update_other_user_visibility (widget); |
---|
410 | } |
---|
411 | |
---|
412 | static void |
---|
413 | on_user_added (GdmUserManager *manager, |
---|
414 | GdmUser *user, |
---|
415 | GdmUserChooserWidget *widget) |
---|
416 | { |
---|
417 | /* wait for all users to be loaded */ |
---|
418 | if (! widget->priv->loaded) { |
---|
419 | return; |
---|
420 | } |
---|
421 | add_user (widget, user); |
---|
422 | } |
---|
423 | |
---|
424 | static void |
---|
425 | on_user_removed (GdmUserManager *manager, |
---|
426 | GdmUser *user, |
---|
427 | GdmUserChooserWidget *widget) |
---|
428 | { |
---|
429 | const char *user_name; |
---|
430 | |
---|
431 | g_debug ("GdmUserChooserWidget: User removed: %s", gdm_user_get_user_name (user)); |
---|
432 | /* wait for all users to be loaded */ |
---|
433 | if (! widget->priv->loaded) { |
---|
434 | return; |
---|
435 | } |
---|
436 | |
---|
437 | user_name = gdm_user_get_user_name (user); |
---|
438 | |
---|
439 | gdm_chooser_widget_remove_item (GDM_CHOOSER_WIDGET (widget), |
---|
440 | user_name); |
---|
441 | |
---|
442 | update_other_user_visibility (widget); |
---|
443 | } |
---|
444 | |
---|
445 | static void |
---|
446 | on_user_is_logged_in_changed (GdmUserManager *manager, |
---|
447 | GdmUser *user, |
---|
448 | GdmUserChooserWidget *widget) |
---|
449 | { |
---|
450 | const char *user_name; |
---|
451 | gboolean is_logged_in; |
---|
452 | |
---|
453 | g_debug ("GdmUserChooserWidget: User logged in changed: %s", gdm_user_get_user_name (user)); |
---|
454 | |
---|
455 | user_name = gdm_user_get_user_name (user); |
---|
456 | is_logged_in = gdm_user_get_num_sessions (user) > 0; |
---|
457 | |
---|
458 | gdm_chooser_widget_set_item_in_use (GDM_CHOOSER_WIDGET (widget), |
---|
459 | user_name, |
---|
460 | is_logged_in); |
---|
461 | } |
---|
462 | |
---|
463 | static void |
---|
464 | on_user_login_frequency_changed (GdmUserManager *manager, |
---|
465 | GdmUser *user, |
---|
466 | GdmUserChooserWidget *widget) |
---|
467 | { |
---|
468 | const char *user_name; |
---|
469 | gulong freq; |
---|
470 | |
---|
471 | g_debug ("GdmUserChooserWidget: User login frequency changed: %s", gdm_user_get_user_name (user)); |
---|
472 | |
---|
473 | user_name = gdm_user_get_user_name (user); |
---|
474 | freq = gdm_user_get_login_frequency (user); |
---|
475 | |
---|
476 | gdm_chooser_widget_set_item_priority (GDM_CHOOSER_WIDGET (widget), |
---|
477 | user_name, |
---|
478 | freq); |
---|
479 | } |
---|
480 | |
---|
481 | static void |
---|
482 | on_users_loaded (GdmUserManager *manager, |
---|
483 | GdmUserChooserWidget *widget) |
---|
484 | { |
---|
485 | GSList *users; |
---|
486 | gboolean list_visible; |
---|
487 | |
---|
488 | g_debug ("GdmUserChooserWidget: Users loaded"); |
---|
489 | |
---|
490 | users = gdm_user_manager_list_users (manager); |
---|
491 | while (users != NULL) { |
---|
492 | add_user (widget, users->data); |
---|
493 | users = g_slist_delete_link (users, users); |
---|
494 | } |
---|
495 | |
---|
496 | g_object_get (G_OBJECT (widget), "list-visible", &list_visible, NULL); |
---|
497 | |
---|
498 | if (list_visible) { |
---|
499 | gtk_widget_grab_focus (GTK_WIDGET (widget)); |
---|
500 | } |
---|
501 | widget->priv->loaded = TRUE; |
---|
502 | |
---|
503 | gdm_chooser_widget_loaded (GDM_CHOOSER_WIDGET (widget)); |
---|
504 | } |
---|
505 | |
---|
506 | static gboolean |
---|
507 | load_users (GdmUserChooserWidget *widget) |
---|
508 | { |
---|
509 | |
---|
510 | if (widget->priv->show_normal_users) { |
---|
511 | widget->priv->manager = gdm_user_manager_ref_default (); |
---|
512 | g_signal_connect (widget->priv->manager, |
---|
513 | "user-added", |
---|
514 | G_CALLBACK (on_user_added), |
---|
515 | widget); |
---|
516 | g_signal_connect (widget->priv->manager, |
---|
517 | "user-removed", |
---|
518 | G_CALLBACK (on_user_removed), |
---|
519 | widget); |
---|
520 | g_signal_connect (widget->priv->manager, |
---|
521 | "users-loaded", |
---|
522 | G_CALLBACK (on_users_loaded), |
---|
523 | widget); |
---|
524 | g_signal_connect (widget->priv->manager, |
---|
525 | "user-is-logged-in-changed", |
---|
526 | G_CALLBACK (on_user_is_logged_in_changed), |
---|
527 | widget); |
---|
528 | g_signal_connect (widget->priv->manager, |
---|
529 | "user-login-frequency-changed", |
---|
530 | G_CALLBACK (on_user_login_frequency_changed), |
---|
531 | widget); |
---|
532 | } else { |
---|
533 | gdm_chooser_widget_loaded (GDM_CHOOSER_WIDGET (widget)); |
---|
534 | } |
---|
535 | |
---|
536 | widget->priv->load_idle_id = 0; |
---|
537 | |
---|
538 | return FALSE; |
---|
539 | } |
---|
540 | |
---|
541 | static GObject * |
---|
542 | gdm_user_chooser_widget_constructor (GType type, |
---|
543 | guint n_construct_properties, |
---|
544 | GObjectConstructParam *construct_properties) |
---|
545 | { |
---|
546 | GdmUserChooserWidget *widget; |
---|
547 | |
---|
548 | widget = GDM_USER_CHOOSER_WIDGET (G_OBJECT_CLASS (gdm_user_chooser_widget_parent_class)->constructor (type, |
---|
549 | n_construct_properties, |
---|
550 | construct_properties)); |
---|
551 | |
---|
552 | widget->priv->has_user_other = FALSE; |
---|
553 | widget->priv->show_normal_users = !is_user_list_disabled (widget); |
---|
554 | |
---|
555 | widget->priv->load_idle_id = g_idle_add ((GSourceFunc)load_users, widget); |
---|
556 | |
---|
557 | return G_OBJECT (widget); |
---|
558 | } |
---|
559 | |
---|
560 | static void |
---|
561 | gdm_user_chooser_widget_dispose (GObject *object) |
---|
562 | { |
---|
563 | GdmUserChooserWidget *widget; |
---|
564 | |
---|
565 | widget = GDM_USER_CHOOSER_WIDGET (object); |
---|
566 | |
---|
567 | G_OBJECT_CLASS (gdm_user_chooser_widget_parent_class)->dispose (object); |
---|
568 | |
---|
569 | if (widget->priv->load_idle_id > 0) { |
---|
570 | g_source_remove (widget->priv->load_idle_id); |
---|
571 | widget->priv->load_idle_id = 0; |
---|
572 | } |
---|
573 | |
---|
574 | if (widget->priv->logged_in_pixbuf != NULL) { |
---|
575 | g_object_unref (widget->priv->logged_in_pixbuf); |
---|
576 | widget->priv->logged_in_pixbuf = NULL; |
---|
577 | } |
---|
578 | |
---|
579 | if (widget->priv->stock_person_pixbuf != NULL) { |
---|
580 | g_object_unref (widget->priv->stock_person_pixbuf); |
---|
581 | widget->priv->stock_person_pixbuf = NULL; |
---|
582 | } |
---|
583 | } |
---|
584 | |
---|
585 | static void |
---|
586 | gdm_user_chooser_widget_class_init (GdmUserChooserWidgetClass *klass) |
---|
587 | { |
---|
588 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
589 | |
---|
590 | object_class->get_property = gdm_user_chooser_widget_get_property; |
---|
591 | object_class->set_property = gdm_user_chooser_widget_set_property; |
---|
592 | object_class->constructor = gdm_user_chooser_widget_constructor; |
---|
593 | object_class->dispose = gdm_user_chooser_widget_dispose; |
---|
594 | object_class->finalize = gdm_user_chooser_widget_finalize; |
---|
595 | |
---|
596 | |
---|
597 | g_object_class_install_property (object_class, |
---|
598 | PROP_SHOW_USER_AUTO, |
---|
599 | g_param_spec_boolean ("show-user-auto", |
---|
600 | "show user auto", |
---|
601 | "show user auto", |
---|
602 | FALSE, |
---|
603 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
604 | g_object_class_install_property (object_class, |
---|
605 | PROP_SHOW_USER_GUEST, |
---|
606 | g_param_spec_boolean ("show-user-guest", |
---|
607 | "show user guest", |
---|
608 | "show user guest", |
---|
609 | FALSE, |
---|
610 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
611 | g_object_class_install_property (object_class, |
---|
612 | PROP_SHOW_USER_OTHER, |
---|
613 | g_param_spec_boolean ("show-user-other", |
---|
614 | "show user other", |
---|
615 | "show user other", |
---|
616 | TRUE, |
---|
617 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
618 | |
---|
619 | g_type_class_add_private (klass, sizeof (GdmUserChooserWidgetPrivate)); |
---|
620 | } |
---|
621 | |
---|
622 | static GdkPixbuf * |
---|
623 | get_stock_person_pixbuf (GdmUserChooserWidget *widget) |
---|
624 | { |
---|
625 | GdkPixbuf *pixbuf; |
---|
626 | int size; |
---|
627 | |
---|
628 | size = get_icon_height_for_widget (GTK_WIDGET (widget)); |
---|
629 | |
---|
630 | pixbuf = gtk_icon_theme_load_icon (widget->priv->icon_theme, |
---|
631 | DEFAULT_USER_ICON, |
---|
632 | size, |
---|
633 | 0, |
---|
634 | NULL); |
---|
635 | |
---|
636 | return pixbuf; |
---|
637 | } |
---|
638 | |
---|
639 | static GdkPixbuf * |
---|
640 | get_logged_in_pixbuf (GdmUserChooserWidget *widget) |
---|
641 | { |
---|
642 | GdkPixbuf *pixbuf; |
---|
643 | int size; |
---|
644 | |
---|
645 | size = get_icon_height_for_widget (GTK_WIDGET (widget)); |
---|
646 | |
---|
647 | pixbuf = gtk_icon_theme_load_icon (widget->priv->icon_theme, |
---|
648 | "emblem-default", |
---|
649 | size / 3, |
---|
650 | 0, |
---|
651 | NULL); |
---|
652 | |
---|
653 | return pixbuf; |
---|
654 | } |
---|
655 | |
---|
656 | typedef struct { |
---|
657 | GdkPixbuf *old_icon; |
---|
658 | GdkPixbuf *new_icon; |
---|
659 | } IconUpdateData; |
---|
660 | |
---|
661 | static gboolean |
---|
662 | update_icons (GdmChooserWidget *widget, |
---|
663 | const char *id, |
---|
664 | GdkPixbuf **image, |
---|
665 | char **name, |
---|
666 | char **comment, |
---|
667 | gulong *priority, |
---|
668 | gboolean *is_in_use, |
---|
669 | gboolean *is_separate, |
---|
670 | IconUpdateData *data) |
---|
671 | { |
---|
672 | if (data->old_icon == *image) { |
---|
673 | *image = data->new_icon; |
---|
674 | return TRUE; |
---|
675 | } |
---|
676 | |
---|
677 | return FALSE; |
---|
678 | } |
---|
679 | |
---|
680 | static void |
---|
681 | load_icons (GdmUserChooserWidget *widget) |
---|
682 | { |
---|
683 | GdkPixbuf *old_pixbuf; |
---|
684 | IconUpdateData data; |
---|
685 | |
---|
686 | if (widget->priv->logged_in_pixbuf != NULL) { |
---|
687 | g_object_unref (widget->priv->logged_in_pixbuf); |
---|
688 | } |
---|
689 | widget->priv->logged_in_pixbuf = get_logged_in_pixbuf (widget); |
---|
690 | |
---|
691 | old_pixbuf = widget->priv->stock_person_pixbuf; |
---|
692 | widget->priv->stock_person_pixbuf = get_stock_person_pixbuf (widget); |
---|
693 | /* update the icons in the model */ |
---|
694 | data.old_icon = old_pixbuf; |
---|
695 | data.new_icon = widget->priv->stock_person_pixbuf; |
---|
696 | gdm_chooser_widget_update_foreach_item (GDM_CHOOSER_WIDGET (widget), |
---|
697 | (GdmChooserUpdateForeachFunc)update_icons, |
---|
698 | &data); |
---|
699 | if (old_pixbuf != NULL) { |
---|
700 | g_object_unref (old_pixbuf); |
---|
701 | } |
---|
702 | } |
---|
703 | |
---|
704 | static void |
---|
705 | on_icon_theme_changed (GtkIconTheme *icon_theme, |
---|
706 | GdmUserChooserWidget *widget) |
---|
707 | { |
---|
708 | g_debug ("GdmUserChooserWidget: icon theme changed"); |
---|
709 | load_icons (widget); |
---|
710 | } |
---|
711 | |
---|
712 | static void |
---|
713 | setup_icons (GdmUserChooserWidget *widget) |
---|
714 | { |
---|
715 | if (gtk_widget_has_screen (GTK_WIDGET (widget))) { |
---|
716 | widget->priv->icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (widget))); |
---|
717 | } else { |
---|
718 | widget->priv->icon_theme = gtk_icon_theme_get_default (); |
---|
719 | } |
---|
720 | |
---|
721 | if (widget->priv->icon_theme != NULL) { |
---|
722 | g_signal_connect (widget->priv->icon_theme, |
---|
723 | "changed", |
---|
724 | G_CALLBACK (on_icon_theme_changed), |
---|
725 | widget); |
---|
726 | } |
---|
727 | |
---|
728 | load_icons (widget); |
---|
729 | } |
---|
730 | |
---|
731 | static void |
---|
732 | gdm_user_chooser_widget_init (GdmUserChooserWidget *widget) |
---|
733 | { |
---|
734 | widget->priv = GDM_USER_CHOOSER_WIDGET_GET_PRIVATE (widget); |
---|
735 | |
---|
736 | gdm_chooser_widget_set_separator_position (GDM_CHOOSER_WIDGET (widget), |
---|
737 | GDM_CHOOSER_WIDGET_POSITION_BOTTOM); |
---|
738 | gdm_chooser_widget_set_in_use_message (GDM_CHOOSER_WIDGET (widget), |
---|
739 | _("Currently logged in")); |
---|
740 | |
---|
741 | setup_icons (widget); |
---|
742 | } |
---|
743 | |
---|
744 | static void |
---|
745 | gdm_user_chooser_widget_finalize (GObject *object) |
---|
746 | { |
---|
747 | GdmUserChooserWidget *widget; |
---|
748 | |
---|
749 | g_return_if_fail (object != NULL); |
---|
750 | g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (object)); |
---|
751 | |
---|
752 | widget = GDM_USER_CHOOSER_WIDGET (object); |
---|
753 | |
---|
754 | g_return_if_fail (widget->priv != NULL); |
---|
755 | |
---|
756 | G_OBJECT_CLASS (gdm_user_chooser_widget_parent_class)->finalize (object); |
---|
757 | } |
---|
758 | |
---|
759 | GtkWidget * |
---|
760 | gdm_user_chooser_widget_new (void) |
---|
761 | { |
---|
762 | GObject *object; |
---|
763 | |
---|
764 | object = g_object_new (GDM_TYPE_USER_CHOOSER_WIDGET, |
---|
765 | NULL); |
---|
766 | |
---|
767 | return GTK_WIDGET (object); |
---|
768 | } |
---|