~ubuntu-branches/ubuntu/maverick/gdm/maverick-backports

« back to all changes in this revision

Viewing changes to .pc/95_git_name_escaping.patch/gui/simple-greeter/gdm-user-chooser-widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-07-21 11:43:52 UTC
  • Revision ID: james.westby@ubuntu.com-20100721114352-j791f5c06356aebe
Tags: 2.30.2.is.2.30.2-0ubuntu3
* debian/patches/95_git_name_escaping.patch:
  - updated to the current git version to fix escaping issues in the 
    language selector list due the previous change
    (lp: #603097)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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->show_normal_users = !is_user_list_disabled (widget);
 
553
 
 
554
        widget->priv->load_idle_id = g_idle_add ((GSourceFunc)load_users, widget);
 
555
 
 
556
        return G_OBJECT (widget);
 
557
}
 
558
 
 
559
static void
 
560
gdm_user_chooser_widget_dispose (GObject *object)
 
561
{
 
562
        GdmUserChooserWidget *widget;
 
563
 
 
564
        widget = GDM_USER_CHOOSER_WIDGET (object);
 
565
 
 
566
        G_OBJECT_CLASS (gdm_user_chooser_widget_parent_class)->dispose (object);
 
567
 
 
568
        if (widget->priv->load_idle_id > 0) {
 
569
                g_source_remove (widget->priv->load_idle_id);
 
570
                widget->priv->load_idle_id = 0;
 
571
        }
 
572
 
 
573
        if (widget->priv->logged_in_pixbuf != NULL) {
 
574
                g_object_unref (widget->priv->logged_in_pixbuf);
 
575
                widget->priv->logged_in_pixbuf = NULL;
 
576
        }
 
577
 
 
578
        if (widget->priv->stock_person_pixbuf != NULL) {
 
579
                g_object_unref (widget->priv->stock_person_pixbuf);
 
580
                widget->priv->stock_person_pixbuf = NULL;
 
581
        }
 
582
}
 
583
 
 
584
static void
 
585
gdm_user_chooser_widget_class_init (GdmUserChooserWidgetClass *klass)
 
586
{
 
587
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
588
 
 
589
        object_class->get_property = gdm_user_chooser_widget_get_property;
 
590
        object_class->set_property = gdm_user_chooser_widget_set_property;
 
591
        object_class->constructor = gdm_user_chooser_widget_constructor;
 
592
        object_class->dispose = gdm_user_chooser_widget_dispose;
 
593
        object_class->finalize = gdm_user_chooser_widget_finalize;
 
594
 
 
595
 
 
596
        g_object_class_install_property (object_class,
 
597
                                         PROP_SHOW_USER_AUTO,
 
598
                                         g_param_spec_boolean ("show-user-auto",
 
599
                                                               "show user auto",
 
600
                                                               "show user auto",
 
601
                                                               FALSE,
 
602
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
603
        g_object_class_install_property (object_class,
 
604
                                         PROP_SHOW_USER_GUEST,
 
605
                                         g_param_spec_boolean ("show-user-guest",
 
606
                                                               "show user guest",
 
607
                                                               "show user guest",
 
608
                                                               FALSE,
 
609
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
610
        g_object_class_install_property (object_class,
 
611
                                         PROP_SHOW_USER_OTHER,
 
612
                                         g_param_spec_boolean ("show-user-other",
 
613
                                                               "show user other",
 
614
                                                               "show user other",
 
615
                                                               TRUE,
 
616
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
617
 
 
618
        g_type_class_add_private (klass, sizeof (GdmUserChooserWidgetPrivate));
 
619
}
 
620
 
 
621
static GdkPixbuf *
 
622
get_stock_person_pixbuf (GdmUserChooserWidget *widget)
 
623
{
 
624
        GdkPixbuf *pixbuf;
 
625
        int        size;
 
626
 
 
627
        size = get_icon_height_for_widget (GTK_WIDGET (widget));
 
628
 
 
629
        pixbuf = gtk_icon_theme_load_icon (widget->priv->icon_theme,
 
630
                                           DEFAULT_USER_ICON,
 
631
                                           size,
 
632
                                           0,
 
633
                                           NULL);
 
634
 
 
635
        return pixbuf;
 
636
}
 
637
 
 
638
static GdkPixbuf *
 
639
get_logged_in_pixbuf (GdmUserChooserWidget *widget)
 
640
{
 
641
        GdkPixbuf *pixbuf;
 
642
        int        size;
 
643
 
 
644
        size = get_icon_height_for_widget (GTK_WIDGET (widget));
 
645
 
 
646
        pixbuf = gtk_icon_theme_load_icon (widget->priv->icon_theme,
 
647
                                           "emblem-default",
 
648
                                           size / 3,
 
649
                                           0,
 
650
                                           NULL);
 
651
 
 
652
        return pixbuf;
 
653
}
 
654
 
 
655
typedef struct {
 
656
        GdkPixbuf *old_icon;
 
657
        GdkPixbuf *new_icon;
 
658
} IconUpdateData;
 
659
 
 
660
static gboolean
 
661
update_icons (GdmChooserWidget *widget,
 
662
              const char       *id,
 
663
              GdkPixbuf       **image,
 
664
              char            **name,
 
665
              char            **comment,
 
666
              gulong           *priority,
 
667
              gboolean         *is_in_use,
 
668
              gboolean         *is_separate,
 
669
              IconUpdateData   *data)
 
670
{
 
671
        if (data->old_icon == *image) {
 
672
                *image = data->new_icon;
 
673
                return TRUE;
 
674
        }
 
675
 
 
676
        return FALSE;
 
677
}
 
678
 
 
679
static void
 
680
load_icons (GdmUserChooserWidget *widget)
 
681
{
 
682
        GdkPixbuf     *old_pixbuf;
 
683
        IconUpdateData data;
 
684
 
 
685
        if (widget->priv->logged_in_pixbuf != NULL) {
 
686
                g_object_unref (widget->priv->logged_in_pixbuf);
 
687
        }
 
688
        widget->priv->logged_in_pixbuf = get_logged_in_pixbuf (widget);
 
689
 
 
690
        old_pixbuf = widget->priv->stock_person_pixbuf;
 
691
        widget->priv->stock_person_pixbuf = get_stock_person_pixbuf (widget);
 
692
        /* update the icons in the model */
 
693
        data.old_icon = old_pixbuf;
 
694
        data.new_icon = widget->priv->stock_person_pixbuf;
 
695
        gdm_chooser_widget_update_foreach_item (GDM_CHOOSER_WIDGET (widget),
 
696
                                                (GdmChooserUpdateForeachFunc)update_icons,
 
697
                                                &data);
 
698
        if (old_pixbuf != NULL) {
 
699
                g_object_unref (old_pixbuf);
 
700
        }
 
701
}
 
702
 
 
703
static void
 
704
on_icon_theme_changed (GtkIconTheme         *icon_theme,
 
705
                       GdmUserChooserWidget *widget)
 
706
{
 
707
        g_debug ("GdmUserChooserWidget: icon theme changed");
 
708
        load_icons (widget);
 
709
}
 
710
 
 
711
static void
 
712
setup_icons (GdmUserChooserWidget *widget)
 
713
{
 
714
        if (gtk_widget_has_screen (GTK_WIDGET (widget))) {
 
715
                widget->priv->icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (widget)));
 
716
        } else {
 
717
                widget->priv->icon_theme = gtk_icon_theme_get_default ();
 
718
        }
 
719
 
 
720
        if (widget->priv->icon_theme != NULL) {
 
721
                g_signal_connect (widget->priv->icon_theme,
 
722
                                  "changed",
 
723
                                  G_CALLBACK (on_icon_theme_changed),
 
724
                                  widget);
 
725
        }
 
726
 
 
727
        load_icons (widget);
 
728
}
 
729
 
 
730
static void
 
731
gdm_user_chooser_widget_init (GdmUserChooserWidget *widget)
 
732
{
 
733
        widget->priv = GDM_USER_CHOOSER_WIDGET_GET_PRIVATE (widget);
 
734
 
 
735
        gdm_chooser_widget_set_separator_position (GDM_CHOOSER_WIDGET (widget),
 
736
                                                   GDM_CHOOSER_WIDGET_POSITION_BOTTOM);
 
737
        gdm_chooser_widget_set_in_use_message (GDM_CHOOSER_WIDGET (widget),
 
738
                                               _("Currently logged in"));
 
739
 
 
740
        setup_icons (widget);
 
741
}
 
742
 
 
743
static void
 
744
gdm_user_chooser_widget_finalize (GObject *object)
 
745
{
 
746
        GdmUserChooserWidget *widget;
 
747
 
 
748
        g_return_if_fail (object != NULL);
 
749
        g_return_if_fail (GDM_IS_USER_CHOOSER_WIDGET (object));
 
750
 
 
751
        widget = GDM_USER_CHOOSER_WIDGET (object);
 
752
 
 
753
        g_return_if_fail (widget->priv != NULL);
 
754
 
 
755
        G_OBJECT_CLASS (gdm_user_chooser_widget_parent_class)->finalize (object);
 
756
}
 
757
 
 
758
GtkWidget *
 
759
gdm_user_chooser_widget_new (void)
 
760
{
 
761
        GObject *object;
 
762
 
 
763
        object = g_object_new (GDM_TYPE_USER_CHOOSER_WIDGET,
 
764
                               NULL);
 
765
 
 
766
        return GTK_WIDGET (object);
 
767
}