~ubuntu-branches/ubuntu/oneiric/gdm/oneiric

« back to all changes in this revision

Viewing changes to gui/gdmsetup/gdmsetup.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt, Sebastien Bacher, Gunnar Hjalmarsson, Robert Ancell, Martin Pitt
  • Date: 2011-06-29 12:05:47 UTC
  • mfrom: (1.4.49 upstream)
  • Revision ID: james.westby@ubuntu.com-20110629120547-j5yvrc0jec43j9f4
Tags: 3.0.4-0ubuntu1
[ Sebastien Bacher ]
* New upstream version 3.0.0
* Start cleaning for the GNOME3 update
* debian/patches/00git_passwordless_login_crash.patch,
  debian/patches/17_use_timed_login_after_autologin.patch,
  debian/patches/19_no_greeter_for_autologin.patch,
  debian/patches/37_disable_resize_grip.patch,
  debian/patches/38_user_chooser_focus.patch,
  debian/patches/43_translate_cancel_button.patch:
  - those are fixed is in the new version
* debian/patches/08_use_polkit_for_settings.patch,
  debian/patches/09_gdmsetup.patch:
  - drop gdmsetup, the options should be integrated in gnome-control-center 
    (the autologin one is in the user account configuration for example)
* debian/patches/09_gdmserver_gconf_settings.patch:
  - the gconf hack to turn on and off login sounds, that should be
    rewritten use gsettings if wanted, lightdm should also make that easier
* debian/patches/10_xsplash.patch:
  - xsplash was a one cycle hack and has been deprecated since
* debian/patches/24_respect_system_minuid.patch:
  - deprecated with the accountsservice use
* debian/patches/25_update_gconf_directories.patch:
  - the new version use gsettings and that was useful for the
    gdmsetup configuration only
* debian/patches/34_disable_a11y_default.patch:
  - the change was not appropriate for a sru but is fine early 
    during the cycle
* debian/%gconf-tree.xml:
  - tweaks to the default layout, those will need to be revisited with the
    new ui and gsettings if needed (no needed if lightdm is the default?)
* Resynchronize some of the files on Debian to lower the difference

[ Gunnar Hjalmarsson ]
* debian/patches/36_language_environment_settings.patch:
  Set LC_CTYPE and LC_COLLATE to the same locale name as LC_MESSAGES
  (LP: #786986).
* Patches adapted to gdm-3.0.0:
  - 15_default_session.patch
  - 30_don_t_save_failsafe_session.patch
  - 32-hide-mouse-cursor.patch
  - 45_time_display_on_greeter.patch
  - 90_register-bin-true-as-URI-scheme-handler-for-several-schemes.patch
* debian/patches/45_time_display_on_greeter.patch:
  Display time on the greeter in a proper format also when
  /etc/default/locale assigns different locales to LANG respective
  LC_MESSAGES (LP: #777264).
* debian/gdm.upstart:
  Export LC_MESSAGES so the weekday gets displayed in the system
  language on the greeter.
* debian/patches/41_pt_time_format.patch:
  Patch deleted (superseded by 45_time_display_on_greeter.patch).

[ Robert Ancell ]
* debian/patches/42_no_ecryptfs_autologin.patch:
  - Only stop autologin if full home directory encryption is used
    (LP: #753707)

[ Martin Pitt ]
* New upstream version 3.0.4.
* debian/control.in: Require accountsservice 0.6.12.
* Drop 90_register-bin-true-as-URI-scheme-handler-for-several-schemes.patch:
  Fixed upstream in a different way.
* debian/gdm.install: install the dummy desktop handler and the
  mimeapps.list to /usr/share/gdm/applications.
* debian/rules: Drop installation of bonobo .server for FUSA, this is all
  obsolete.
* debian/rules: Drop installation of debian/%gconf-tree.xml, which was
  removed above.
* Drop 35_langlist_and_lsmess_dmrc_fields.patch: This now needs to be
  reimplemented in accountsservice.
* 42_no_ecryptfs_autologin.patch: Update to gdm 3.0.
* Synchronize patches with Debian:
  - Drop 04_fix_external_program_directories.patch, replace with
    07_libexec-paths.patch.
  - Add 93_xdg_data_dirs.patch.
  - Add 01_language.patch.
  - Drop 02_x_server_location.patch, replace with 16_xserver_path.patch. Set
    $X_PATH and friends in debian/rules.
  - Rename 05_initial_server_on_vt7.patch to 06_first_vt.patch. They have
    the same purpose, but ours is two magnitudes simpler.
  - Add 08_frequent-users_greeter.patch.
  - Rename 06_run_xsession.d.patch to ubuntu_run_xsession.d.patch; we don't
    use Debian's Xsession script, but upstream's.
  - Rename 11_crash_for_apport.patch to ubuntu_dont_catch_sigsegv.patch.
  - Rename 14_guest_session.patch to ubuntu_guest_session.patch.
  - Rename 20_upstart.patch to ubuntu_upstart_event.patch.
  - Rename 26_no_debug.patch to ubuntu_no_debug.patch.
  - Rename 39_grep_path.patch to 29_grep_path.patch just as Debian did.
* Merge 27_save_root_window.patch and 28_plymouth_transition.patch into
  ubuntu_plymouth.patch, to correspond better with its origin at
  http://pkgs.fedoraproject.org/gitweb/?p=gdm.git;a=blob;f=plymouth.patch;hb=HEAD
* Drop 16_gdmserver_user_manager.patch, this info is now provided by
  accountsservice.
* Drop 32-hide-mouse-cursor.patch. It never really looked that much better,
  and is unimportant now that gdm isn't even the default DM any more.
* Drop 40_one_lang_option_per_translation.patch: gdm does not show a
  language list any more, thus obsolete.
* 44_xsession-errors_symlink.patch: Fix case of .xsession-errors pointing to
  non-files such as /dev/null. Also rename to
  00git_xsession-errors_symlink.patch, as the patch was also committed
  upstream now. (LP: #771661)
* debian/watch: Look for .bz2 tarballs; upstream stopped publishing .gz
  ones.
* debian/control.in: Add missing gnome-pkg-tools dependency.
* debian/control.in: Bump Standards-Vesion to 3.9.2.
* debian/gdm.preinst: Add missing debhelper token.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include "config.h"
3
 
#endif
4
 
 
5
 
#include <string.h>
6
 
#include <stdlib.h>
7
 
#include <gtk/gtk.h>
8
 
#include <gdk/gdkkeysyms.h>
9
 
#include <dbus/dbus-glib.h>
10
 
#include <glib/gi18n.h>
11
 
 
12
 
#include "gdm-user-manager.h"
13
 
#include "gdm-sessions.h"
14
 
 
15
 
#define MAX_USERS_IN_COMBO_BOX 20
16
 
 
17
 
/* User interface */
18
 
static GtkBuilder *ui;
19
 
static GtkWidget *dialog, *unlock_button, *option_vbox;
20
 
static GtkWidget *user_combo, *user_entry, *delay_spin;
21
 
static GtkWidget *session_combo;
22
 
static GtkWidget *auto_login_radio, *login_delay_box, *login_delay_check, *sound_enable_check, *face_browser_enable_check;
23
 
 
24
 
/* Timer to delay application of configuration */
25
 
static guint apply_timeout = 0;
26
 
 
27
 
/* Flag to show when information is user_login_loaded */
28
 
static gboolean user_login_loaded = FALSE;
29
 
static gboolean session_loaded = FALSE;
30
 
 
31
 
/* Flag to show when information is loaded */
32
 
static gboolean locked = TRUE;
33
 
 
34
 
/* True if the user selection method is a combo box, False if an entry */
35
 
static gboolean user_list_is_combo = TRUE;
36
 
 
37
 
/* User information */
38
 
static GdmUserManager *user_manager;
39
 
 
40
 
/* Proxy to GDM settings */
41
 
static DBusGProxy *proxy = NULL;
42
 
 
43
 
 
44
 
static gboolean
45
 
get_sound_enabled ()
46
 
{
47
 
    gboolean value;
48
 
    GError *error = NULL;
49
 
    
50
 
    if (!dbus_g_proxy_call (proxy, "GetSoundEnabled", &error,
51
 
                            G_TYPE_INVALID,
52
 
                            G_TYPE_BOOLEAN, &value, G_TYPE_INVALID)) {
53
 
        g_warning ("Error calling GetSoundEnabled(): %s", error->message);
54
 
        return FALSE;
55
 
    }
56
 
  
57
 
    return value;
58
 
}
59
 
 
60
 
 
61
 
static gboolean
62
 
set_sound_enabled (gboolean enabled)
63
 
{
64
 
    GError *error = NULL;
65
 
    
66
 
    dbus_g_proxy_call (proxy, "SetSoundEnabled", &error,
67
 
                       G_TYPE_BOOLEAN, enabled, G_TYPE_INVALID,
68
 
                       G_TYPE_INVALID);
69
 
    if (error) {
70
 
        g_warning ("Error calling SetSoundEnabled(%s): %s", enabled ? "TRUE" : "FALSE", error->message);
71
 
        return FALSE;
72
 
    }
73
 
    
74
 
    return TRUE;
75
 
}
76
 
 
77
 
 
78
 
static gboolean
79
 
get_face_browser_enabled ()
80
 
{
81
 
    gboolean value;
82
 
    GError *error = NULL;
83
 
    
84
 
    if (!dbus_g_proxy_call (proxy, "GetFaceBrowserEnabled", &error,
85
 
                            G_TYPE_INVALID,
86
 
                            G_TYPE_BOOLEAN, &value, G_TYPE_INVALID)) {
87
 
        g_warning ("Error calling GetFaceBrowserEnabled(): %s", error->message);
88
 
        return FALSE;
89
 
    }
90
 
  
91
 
    return value;
92
 
}
93
 
 
94
 
 
95
 
static gboolean
96
 
set_face_browser_enabled (gboolean enabled)
97
 
{
98
 
    GError *error = NULL;
99
 
    
100
 
    dbus_g_proxy_call (proxy, "SetFaceBrowserEnabled", &error,
101
 
                       G_TYPE_BOOLEAN, enabled, G_TYPE_INVALID,
102
 
                       G_TYPE_INVALID);
103
 
    if (error) {
104
 
        g_warning ("Error calling SetFaceBrowserEnabled(%s): %s", enabled ? "TRUE" : "FALSE", error->message);
105
 
        return FALSE;
106
 
    }
107
 
    
108
 
    return TRUE;
109
 
}
110
 
 
111
 
 
112
 
static gchar *
113
 
get_value (const gchar *key, gchar *def)
114
 
{
115
 
    gchar *value;
116
 
    GError *error = NULL;
117
 
    
118
 
    if (!dbus_g_proxy_call (proxy, "GetValue", &error,
119
 
                            G_TYPE_STRING, key, G_TYPE_INVALID,
120
 
                            G_TYPE_STRING, &value, G_TYPE_INVALID)) {
121
 
        g_warning ("Error calling GetValue('%s'): %s", key, error->message);
122
 
        return def;
123
 
    }
124
 
    
125
 
    return value;
126
 
}
127
 
 
128
 
 
129
 
static gboolean
130
 
set_value (const gchar *key, const gchar *value)
131
 
{
132
 
    GError *error = NULL;
133
 
    
134
 
    dbus_g_proxy_call (proxy, "SetValue", &error,
135
 
                       G_TYPE_STRING, key,
136
 
                       G_TYPE_STRING, value, G_TYPE_INVALID, G_TYPE_INVALID);
137
 
    if (error) {
138
 
        g_warning ("Error calling SetValue('%s', '%s'): %s", key, value, error->message);
139
 
        return FALSE;
140
 
    }
141
 
    
142
 
    return TRUE;
143
 
}
144
 
 
145
 
 
146
 
static gboolean
147
 
get_boolean_value (const gchar *key, gboolean def)
148
 
{
149
 
    gchar *value;
150
 
    gboolean result;
151
 
    
152
 
    value = get_value (key, NULL);
153
 
    if (!value)
154
 
        return def;
155
 
    result = strcmp (value, "true") == 0;
156
 
    g_free (value);
157
 
    return result;
158
 
}
159
 
 
160
 
 
161
 
static gint
162
 
get_integer_value (const gchar *key, gint def)
163
 
{
164
 
    gchar *value;
165
 
    gint result;
166
 
    char *end;
167
 
    
168
 
    value = get_value (key, NULL);
169
 
    if (!value || value[0] == '\0')
170
 
        result = def;
171
 
    else {
172
 
        result = strtol (value, &end, 10);
173
 
        if (*end != '\0')
174
 
            result = def;
175
 
    }
176
 
 
177
 
    if (value)
178
 
        g_free (value);
179
 
    return result;
180
 
}
181
 
 
182
 
 
183
 
static gboolean
184
 
set_boolean_value (const gchar *key, gboolean value)
185
 
{
186
 
    return set_value (key, value ? "true" : "false");
187
 
}
188
 
 
189
 
 
190
 
static gboolean
191
 
set_integer_value (const gchar *key, gint value)
192
 
{
193
 
    char value_string[1024];
194
 
    snprintf(value_string, 1024, "%d", value);
195
 
    return set_value (key, value_string);
196
 
}
197
 
 
198
 
 
199
 
static void
200
 
update_config ()
201
 
{
202
 
    GtkTreeModel *model;
203
 
    GtkTreeIter iter;
204
 
    gchar *user = NULL;
205
 
    gint delay = 0;
206
 
    gboolean auto_login = FALSE, timed_login = FALSE, error = FALSE;
207
 
    gchar *default_session = NULL;
208
 
    
209
 
    if (apply_timeout != 0) {
210
 
        g_source_remove (apply_timeout);
211
 
        apply_timeout = 0;
212
 
    }
213
 
 
214
 
    if (user_list_is_combo) {
215
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (user_combo));
216
 
        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (user_combo), &iter))
217
 
            gtk_tree_model_get (model, &iter, 1, &user, -1);
218
 
    }
219
 
    else
220
 
        user = g_strdup (gtk_entry_get_text (GTK_ENTRY (user_entry)));
221
 
 
222
 
    model = gtk_combo_box_get_model (GTK_COMBO_BOX (session_combo));
223
 
    if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (session_combo), &iter))
224
 
        gtk_tree_model_get (model, &iter, 1, &default_session, -1);
225
 
 
226
 
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (auto_login_radio))) {
227
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (login_delay_check)))
228
 
            timed_login = TRUE;
229
 
        else
230
 
            auto_login = TRUE;
231
 
    }
232
 
    
233
 
    delay = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (delay_spin));
234
 
 
235
 
    g_debug ("set user='%s', auto=%s, timed=%s, delay=%d, default_session=%s",
236
 
             user,
237
 
             auto_login ? "True" : "False",
238
 
             timed_login ? "True" : "False", delay,
239
 
             default_session);
240
 
    
241
 
    if (!set_boolean_value ("daemon/TimedLoginEnable", timed_login) ||
242
 
        !set_boolean_value ("daemon/AutomaticLoginEnable", auto_login) ||
243
 
        !set_value ("daemon/TimedLogin", user) ||
244
 
        !set_value ("daemon/AutomaticLogin", user) ||    
245
 
        !set_integer_value ("daemon/TimedLoginDelay", delay) ||
246
 
        !set_value ("daemon/DefaultSession", default_session))
247
 
        error = TRUE;
248
 
 
249
 
    if (user)
250
 
        g_free (user);
251
 
}
252
 
 
253
 
 
254
 
G_MODULE_EXPORT
255
 
void
256
 
gdm_capplet_response_cb (GtkWidget *widget, gint response_id)
257
 
{
258
 
    if (response_id != 1)
259
 
        gtk_main_quit ();
260
 
}
261
 
 
262
 
 
263
 
static void
264
 
unlock_response_cb (DBusGProxy     *proxy,
265
 
                    DBusGProxyCall *call_id,
266
 
                    void           *user_data)
267
 
{
268
 
    gboolean is_unlocked;
269
 
    GError *error = NULL;
270
 
    
271
 
    dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_BOOLEAN, &is_unlocked, G_TYPE_INVALID);
272
 
    if (error) {
273
 
        g_warning ("Failed to unlock: %s", error->message);
274
 
        g_error_free (error);
275
 
        return;
276
 
    }
277
 
    
278
 
    if (!is_unlocked)
279
 
        return;
280
 
    
281
 
    locked = FALSE;
282
 
    gtk_widget_set_sensitive (unlock_button, FALSE);
283
 
    gtk_widget_set_sensitive (option_vbox, user_login_loaded && !locked);
284
 
}
285
 
 
286
 
 
287
 
G_MODULE_EXPORT
288
 
void
289
 
unlock_button_clicked_cb (GtkWidget *widget)
290
 
{
291
 
    dbus_g_proxy_begin_call (proxy, "Unlock", unlock_response_cb, NULL, NULL, G_TYPE_INVALID);
292
 
}
293
 
 
294
 
 
295
 
G_MODULE_EXPORT
296
 
void
297
 
login_delay_check_toggled_cb (GtkWidget *widget)
298
 
{
299
 
    gtk_widget_set_sensitive (delay_spin,
300
 
                              gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (login_delay_check)));
301
 
    
302
 
    if (session_loaded && user_login_loaded)
303
 
        update_config ();
304
 
}
305
 
 
306
 
 
307
 
G_MODULE_EXPORT
308
 
void
309
 
sound_enable_check_toggled_cb (GtkWidget *widget)
310
 
{
311
 
   set_sound_enabled (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
312
 
}
313
 
 
314
 
 
315
 
G_MODULE_EXPORT
316
 
void
317
 
face_browser_enable_check_toggled_cb (GtkWidget *widget)
318
 
{
319
 
   set_face_browser_enabled (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
320
 
}
321
 
 
322
 
 
323
 
static gboolean
324
 
delayed_apply_cb ()
325
 
{
326
 
    update_config ();
327
 
    return FALSE;
328
 
}
329
 
 
330
 
 
331
 
G_MODULE_EXPORT
332
 
void
333
 
apply_config_cb (GtkWidget *widget)
334
 
{
335
 
    if (session_loaded && user_login_loaded) {
336
 
        if (apply_timeout != 0)
337
 
            g_source_remove (apply_timeout);
338
 
        apply_timeout = g_timeout_add (200, (GSourceFunc)delayed_apply_cb, NULL);
339
 
    }
340
 
}
341
 
 
342
 
 
343
 
static void
344
 
init_login_delay ()
345
 
{
346
 
    gint delay;
347
 
    
348
 
    if (get_boolean_value ("daemon/TimedLoginEnable", FALSE))
349
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (login_delay_check), TRUE);
350
 
    
351
 
    delay = get_integer_value ("daemon/TimedLoginDelay", 30);
352
 
 
353
 
    g_debug ("init delay=%d", delay);
354
 
 
355
 
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (delay_spin), delay);
356
 
}
357
 
 
358
 
 
359
 
G_MODULE_EXPORT
360
 
void
361
 
automatic_login_toggle_cb (GtkWidget *automatic_login_toggle)    
362
 
{
363
 
    gboolean automatic_login;
364
 
 
365
 
    automatic_login = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (automatic_login_toggle));
366
 
    gtk_widget_set_sensitive (login_delay_box, automatic_login);
367
 
    gtk_widget_set_sensitive (user_combo, automatic_login);
368
 
    gtk_widget_set_sensitive (user_entry, automatic_login);
369
 
    gtk_widget_set_sensitive (face_browser_enable_check, !automatic_login);
370
 
 
371
 
    if (session_loaded && user_login_loaded)
372
 
        update_config ();
373
 
}
374
 
 
375
 
 
376
 
G_MODULE_EXPORT
377
 
void
378
 
default_user_combo_box_changed_cb (void)
379
 
{
380
 
    if (session_loaded && user_login_loaded) {
381
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (auto_login_radio), TRUE);
382
 
        update_config ();
383
 
    }
384
 
}
385
 
 
386
 
G_MODULE_EXPORT
387
 
void
388
 
default_session_combo_box_changed_cb (void)
389
 
{
390
 
    if (session_loaded && user_login_loaded)
391
 
        update_config ();
392
 
}
393
 
 
394
 
 
395
 
static void
396
 
init_default_user (void)
397
 
{
398
 
    GtkTreeModel *model;
399
 
    GtkTreeIter iter;
400
 
    gboolean auto_login, timed_login, active;
401
 
    gchar *user = NULL;
402
 
    
403
 
    auto_login = get_boolean_value ("daemon/AutomaticLoginEnable", FALSE);
404
 
    timed_login = get_boolean_value ("daemon/TimedLoginEnable", FALSE);
405
 
    
406
 
    if (auto_login)
407
 
        user = get_value ("daemon/AutomaticLogin", NULL);
408
 
    if (user == NULL)
409
 
        user = get_value ("daemon/TimedLogin", NULL);
410
 
 
411
 
    g_debug ("init user='%s' auto=%s", user, auto_login || timed_login ? "True" : "False");
412
 
 
413
 
    if (auto_login || timed_login)
414
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (auto_login_radio), TRUE);
415
 
    
416
 
    if (!user_list_is_combo) {
417
 
        if (user != NULL)
418
 
            gtk_entry_set_text (GTK_ENTRY (user_entry), user);
419
 
    }
420
 
    else {
421
 
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (user_combo));
422
 
        active = gtk_tree_model_get_iter_first (model, &iter);
423
 
        
424
 
        /* If no user then use first available */
425
 
        if (user == NULL) {
426
 
            if (active)
427
 
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (user_combo), &iter);
428
 
        }
429
 
        else {
430
 
            while (user != NULL && active) {
431
 
                gchar *u;
432
 
                gboolean matched;
433
 
            
434
 
                gtk_tree_model_get (model, &iter, 1, &u, -1);
435
 
                matched = strcmp (user, u) == 0;
436
 
                g_free (u);
437
 
                if (matched) {
438
 
                    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (user_combo), &iter);
439
 
                    break;
440
 
                }
441
 
            
442
 
                active = gtk_tree_model_iter_next (model, &iter);
443
 
            }
444
 
        }
445
 
    }
446
 
    
447
 
    g_free (user);
448
 
}
449
 
 
450
 
 
451
 
static void
452
 
init_default_session (void)
453
 
{
454
 
    GtkTreeModel *model;
455
 
    GtkTreeIter iter;
456
 
    gboolean active;
457
 
    gchar *default_session = NULL;
458
 
 
459
 
    default_session = get_value ("daemon/DefaultSession", NULL);
460
 
    g_debug ("Init default session found:'%s'", default_session);
461
 
 
462
 
    model = gtk_combo_box_get_model (GTK_COMBO_BOX (session_combo));
463
 
    active = gtk_tree_model_get_iter_first (model, &iter);
464
 
 
465
 
    /* If no default session then use gnome one */
466
 
    if (default_session == NULL || strlen(default_session) == 0)
467
 
        default_session = g_strdup("gnome");
468
 
 
469
 
    while (active) {
470
 
        gchar *u;
471
 
        gboolean matched;
472
 
 
473
 
        gtk_tree_model_get (model, &iter, 1, &u, -1);
474
 
        matched = strcmp (default_session, u) == 0;
475
 
        g_free (u);
476
 
        if (matched) {
477
 
            gtk_combo_box_set_active_iter (GTK_COMBO_BOX (session_combo), &iter);
478
 
            break;
479
 
        }
480
 
 
481
 
        active = gtk_tree_model_iter_next (model, &iter);
482
 
    }
483
 
    session_loaded = TRUE;
484
 
 
485
 
    g_free (default_session);
486
 
}
487
 
 
488
 
 
489
 
static void add_user (GdmUser *user)
490
 
{
491
 
    GtkListStore *model;
492
 
    GtkTreeIter iter;
493
 
    GString *label;
494
 
    const gchar *home_user_dir;
495
 
    gchar *encryption_path;
496
 
    gchar *encryption_content;
497
 
    GFile *encryption_file;
498
 
    GString *encryption_mount;
499
 
    gboolean using_encryption = FALSE;
500
 
 
501
 
    /* don't enable autologin for user having encrypted home dir
502
 
       there are some corner case if gdmsetup isn't run as root and another user
503
 
       than the current one is using encrypted dir: you can't check for them if
504
 
       they access to it. The solution is the server to refuse the change then
505
 
       (too late in the cycle for such changes). */
506
 
    home_user_dir = gdm_user_get_home_directory (user);
507
 
    encryption_path = g_build_filename (home_user_dir, ".ecryptfs", "Private.mnt", NULL);
508
 
    encryption_file = g_file_new_for_path (encryption_path);
509
 
    if (g_file_load_contents (encryption_file, NULL, &encryption_content, NULL, NULL, NULL)) {
510
 
        if (g_str_has_suffix (encryption_content, "\n"))
511
 
            encryption_content[strlen(encryption_content)-1] = '\0';
512
 
        encryption_mount = g_string_new(encryption_content);
513
 
        if (strcmp (encryption_mount->str, home_user_dir) == 0)
514
 
            using_encryption = TRUE;
515
 
        g_string_free (encryption_mount, TRUE);
516
 
    }
517
 
    if (encryption_file)
518
 
        g_object_unref (encryption_file);
519
 
    g_free (encryption_path);
520
 
 
521
 
    if (using_encryption) {
522
 
        g_debug ("%s is using an encrypted home, not listing him for autologin", gdm_user_get_real_name (user));
523
 
        return;
524
 
    }
525
 
 
526
 
    model = GTK_LIST_STORE (gtk_builder_get_object (ui, "login_user_model"));
527
 
    gtk_list_store_append (model, &iter);
528
 
    label = g_string_new("");
529
 
    g_string_printf (label, "%s (%s)", gdm_user_get_real_name (user), gdm_user_get_user_name (user));
530
 
    gtk_list_store_set (model, &iter,
531
 
                        0, label->str,
532
 
                        1, gdm_user_get_user_name (user),
533
 
                        -1);
534
 
    g_string_free (label, TRUE);
535
 
}
536
 
 
537
 
 
538
 
static void add_session (gchar *session_id, gchar *name, gchar *comment)
539
 
{
540
 
    GtkListStore *model;
541
 
    GtkTreeIter iter;
542
 
    GString *label;    
543
 
 
544
 
    model = GTK_LIST_STORE (gtk_builder_get_object (ui, "session_model"));
545
 
    gtk_list_store_append (model, &iter);
546
 
    label = g_string_new("");
547
 
    g_string_printf (label, "%s", name);
548
 
    gtk_list_store_set (model, &iter,
549
 
                        0, label->str,
550
 
                        1, session_id,
551
 
                        -1);
552
 
    g_string_free (label, TRUE);
553
 
}
554
 
 
555
 
 
556
 
static void
557
 
users_loaded_cb(GdmUserManager *manager)
558
 
{
559
 
    GSList *users, *item;
560
 
 
561
 
    users = gdm_user_manager_list_users (user_manager);
562
 
    
563
 
    if (g_slist_length (users) > MAX_USERS_IN_COMBO_BOX) {
564
 
        user_list_is_combo = FALSE;
565
 
        gtk_widget_hide (user_combo);
566
 
        gtk_widget_show (user_entry);
567
 
    }
568
 
    else {
569
 
        for (item = users; item; item = item->next)
570
 
            add_user ((GdmUser *) item->data);
571
 
    }
572
 
 
573
 
    init_default_user ();
574
 
 
575
 
    user_login_loaded = TRUE;
576
 
    gtk_widget_set_sensitive (option_vbox, user_login_loaded && !locked);
577
 
}
578
 
 
579
 
 
580
 
static void
581
 
user_added_cb (GdmUserManager *manager, GdmUser *user)
582
 
{
583
 
    if (session_loaded && user_login_loaded)
584
 
        add_user (user);
585
 
}
586
 
 
587
 
 
588
 
static void
589
 
load_sessions_cb(void)
590
 
{
591
 
    gchar     **session_ids;
592
 
    int        i;
593
 
 
594
 
    session_ids = gdm_get_all_sessions ();
595
 
 
596
 
    for (i = 0; session_ids[i] != NULL; i++) {
597
 
        gchar *name;
598
 
        gchar *comment;
599
 
        if (!gdm_get_details_for_session (session_ids[i],
600
 
                                          &name, &comment)) {
601
 
            continue;
602
 
        }
603
 
        add_session (session_ids[i], name, comment);
604
 
            g_free (name);
605
 
            g_free (comment);
606
 
    }
607
 
    g_strfreev (session_ids);
608
 
 
609
 
    init_default_session();
610
 
}
611
 
 
612
 
 
613
 
static void
614
 
split_text (const gchar *text, const gchar *prefix_label_name, const gchar *suffix_label_name)
615
 
{
616
 
    gchar **tokens;
617
 
    GtkWidget *prefix_label, *suffix_label;
618
 
    
619
 
    prefix_label = GTK_WIDGET (gtk_builder_get_object (ui, prefix_label_name));
620
 
    suffix_label = GTK_WIDGET (gtk_builder_get_object (ui, suffix_label_name));
621
 
    
622
 
    tokens = g_strsplit (text, "%s", 2);
623
 
    if (tokens[0] != NULL && tokens[1] != NULL) {
624
 
        if (tokens[0][0] != '\0')
625
 
            gtk_label_set_text (GTK_LABEL (prefix_label), g_strstrip (tokens[0]));
626
 
        else
627
 
            gtk_widget_hide (prefix_label);
628
 
        if (tokens[1][0] != '\0')
629
 
            gtk_label_set_text (GTK_LABEL (suffix_label), g_strstrip (tokens[1]));
630
 
        else
631
 
            gtk_widget_hide (suffix_label);
632
 
    }
633
 
    g_strfreev (tokens);
634
 
}
635
 
 
636
 
 
637
 
int main (int argc, char **argv)
638
 
{
639
 
    GtkCellRenderer *renderer;
640
 
    DBusGConnection *connection;
641
 
    GError *error = NULL;
642
 
    
643
 
    bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
644
 
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
645
 
    textdomain (GETTEXT_PACKAGE);
646
 
 
647
 
    gtk_init (&argc, &argv);
648
 
    
649
 
    connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
650
 
    if (error) {
651
 
        g_warning ("Failed to get system bus: %s", error->message);
652
 
        return 1;
653
 
    }
654
 
    proxy = dbus_g_proxy_new_for_name (connection,
655
 
                                       "org.gnome.DisplayManager",
656
 
                                       "/org/gnome/DisplayManager/Settings",
657
 
                                       "org.gnome.DisplayManager.Settings");
658
 
 
659
 
    ui = gtk_builder_new ();
660
 
    gtk_builder_add_from_file (ui, UIDIR "/gdmsetup.ui", &error);
661
 
    if (error) {
662
 
        g_warning ("Failed to load UI: %s", error->message);
663
 
        return 1;
664
 
    }
665
 
    dialog = GTK_WIDGET (gtk_builder_get_object (ui, "gdm_capplet"));
666
 
    unlock_button = GTK_WIDGET (gtk_builder_get_object (ui, "unlock_button"));
667
 
    option_vbox = GTK_WIDGET (gtk_builder_get_object (ui, "gdm_capplet_vbox"));
668
 
    user_combo = GTK_WIDGET (gtk_builder_get_object (ui, "default_user_combo_box"));
669
 
    session_combo = GTK_WIDGET (gtk_builder_get_object (ui, "default_session_combo_box"));
670
 
    user_entry = GTK_WIDGET (gtk_builder_get_object (ui, "default_user_entry"));
671
 
    delay_spin = GTK_WIDGET (gtk_builder_get_object (ui, "login_delay_spin"));
672
 
    auto_login_radio = GTK_WIDGET (gtk_builder_get_object (ui, "automatic_login_radio"));
673
 
    login_delay_box = GTK_WIDGET (gtk_builder_get_object (ui, "login_delay_box"));
674
 
    login_delay_check = GTK_WIDGET (gtk_builder_get_object (ui, "login_delay_check"));
675
 
    sound_enable_check = GTK_WIDGET (gtk_builder_get_object (ui, "sound_enable_check"));
676
 
    face_browser_enable_check = GTK_WIDGET (gtk_builder_get_object (ui, "face_browser_enable_check"));
677
 
 
678
 
    if (g_file_test ("/usr/share/gdm/autostart/LoginWindow/libcanberra-ready-sound.desktop", G_FILE_TEST_EXISTS))
679
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_enable_check), get_sound_enabled ());
680
 
    else
681
 
        gtk_widget_hide (GTK_WIDGET (sound_enable_check));
682
 
 
683
 
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (face_browser_enable_check), get_face_browser_enabled ());
684
 
  
685
 
    gtk_builder_connect_signals (ui, NULL);
686
 
 
687
 
    /* Translators: Label for choosing which user to log in as. '%s' is replaced with an input field. */
688
 
    split_text (_("Log in as %s automatically"), "user_prefix_label", "user_suffix_label");
689
 
    /* Translators: Label for choosing the login delay. '%s' is replaced with an input field. */
690
 
    split_text (_("Allow %s seconds for anyone else to log in first"), "delay_prefix_label", "delay_suffix_label");
691
 
    /* Translators: Label for choosing the default session. '%s' is replaced with an input field. */
692
 
    split_text (_("Select %s as default session"), "session_prefix_label", "session_suffix_label");
693
 
    
694
 
    init_login_delay ();
695
 
    load_sessions_cb();
696
 
 
697
 
    renderer = gtk_cell_renderer_text_new ();
698
 
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (user_combo), renderer, TRUE);
699
 
    gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (user_combo), renderer, "text", 0);
700
 
 
701
 
    renderer = gtk_cell_renderer_text_new ();
702
 
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (session_combo), renderer, TRUE);
703
 
    gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (session_combo), renderer, "text", 0);
704
 
 
705
 
    user_manager = gdm_user_manager_ref_default ();
706
 
    g_signal_connect (user_manager, "users-loaded", G_CALLBACK (users_loaded_cb), NULL);
707
 
    g_signal_connect (user_manager, "user-added", G_CALLBACK (user_added_cb), NULL);
708
 
    
709
 
    gtk_widget_hide (user_entry);
710
 
 
711
 
    gtk_widget_set_sensitive (option_vbox, FALSE);
712
 
    gtk_widget_show (dialog);
713
 
 
714
 
    gtk_main ();
715
 
    
716
 
    return 0;
717
 
}