~ubuntu-multiseat/ubuntu/saucy/unity-greeter/bug1201122

« back to all changes in this revision

Viewing changes to src/unity-greeter.vala

Tags: upstream-12.10.3
ImportĀ upstreamĀ versionĀ 12.10.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
public class UnityGreeter
23
23
{
24
 
    static bool show_version = false;
25
 
    public static bool test_mode = false;
26
 
    public static const OptionEntry[] options =
27
 
    {
28
 
        { "version", 'v', 0, OptionArg.NONE, ref show_version,
29
 
          /* Help string for command line --version flag */
30
 
          N_("Show release version"), null },
31
 
        { "test-mode", 0, 0, OptionArg.NONE, ref test_mode,
32
 
          /* Help string for command line --test-mode flag */
33
 
          N_("Run in test mode"), null },
34
 
        { null }
35
 
    };
36
 
 
37
 
    private static Timer log_timer;
38
 
 
39
 
    private static string state_file;
40
 
    private static KeyFile state;
41
 
 
42
 
    private static Cairo.XlibSurface background_surface;
 
24
    public static UnityGreeter singleton;
 
25
 
 
26
    public signal void show_message (string text, LightDM.MessageType type);
 
27
    public signal void show_prompt (string text, LightDM.PromptType type);
 
28
    public signal void authentication_complete ();
 
29
 
 
30
    public bool test_mode = false;
 
31
 
 
32
    private string state_file;
 
33
    private KeyFile state;
 
34
 
 
35
    private Cairo.XlibSurface background_surface;
43
36
 
44
37
    private SettingsDaemon settings_daemon;
45
38
 
46
 
    private static MainWindow main_window;
 
39
    private MainWindow main_window;
47
40
 
48
 
    public static LightDM.Greeter greeter;
 
41
    private LightDM.Greeter greeter;
49
42
 
50
43
    private Canberra.Context canberra_context;
51
44
 
52
 
    public UnityGreeter ()
 
45
    private static Timer log_timer;
 
46
 
 
47
    private UnityGreeter (bool test_mode_)
53
48
    {
 
49
        singleton = this;
 
50
        test_mode = test_mode_;
 
51
 
 
52
        /* Prepare to set the background */
 
53
        debug ("Creating background surface");
 
54
        background_surface = create_root_surface (Gdk.Screen.get_default ());
 
55
 
54
56
        greeter = new LightDM.Greeter ();
 
57
        greeter.show_message.connect ((text, type) => { show_message (text, type); });
 
58
        greeter.show_prompt.connect ((text, type) => { show_prompt (text, type); });
 
59
        greeter.authentication_complete.connect (() => { authentication_complete (); });
55
60
        var connected = false;
56
61
        try
57
62
        {
67
72
        if (!test_mode)
68
73
        {
69
74
            settings_daemon = new SettingsDaemon ();
70
 
            settings_daemon.start ();
 
75
            settings_daemon.start.begin ();
71
76
        }
72
77
 
73
78
        var state_dir = Path.build_filename (Environment.get_user_cache_dir (), "unity-greeter");
91
96
        Gdk.threads_add_idle (ready_cb);
92
97
    }
93
98
 
94
 
    public static string? get_state (string key)
 
99
    public string? get_state (string key)
95
100
    {
96
101
        try
97
102
        {
103
108
        }
104
109
    }
105
110
 
106
 
    public static void set_state (string key, string value)
 
111
    public void set_state (string key, string value)
107
112
    {
108
113
        state.set_value ("greeter", key, value);
109
114
        var data = state.to_data ();
117
122
        }
118
123
    }
119
124
 
120
 
    public static void push_list (GreeterList widget)
 
125
    public void push_list (GreeterList widget)
121
126
    {
122
127
        main_window.push_list (widget);
123
128
    }
124
129
 
125
 
    public static void pop_list ()
 
130
    public void pop_list ()
126
131
    {
127
132
        main_window.pop_list ();
128
133
    }
144
149
        return null;
145
150
    }
146
151
 
147
 
    public static void start_session (string? session)
 
152
    public void start_session (string? session)
148
153
    {
149
154
        /* Set the background */
150
155
        refresh_background (Gdk.Screen.get_default (), background_surface);
151
156
 
152
 
        if (UnityGreeter.test_mode)
 
157
        if (test_mode)
153
158
        {
154
159
                debug ("Successfully logged in!  Quitting...");
155
160
                Gtk.main_quit ();
158
163
        {
159
164
            try
160
165
            {
161
 
                UnityGreeter.greeter.start_session_sync (session);
 
166
                greeter.start_session_sync (session);
162
167
            }
163
168
            catch (Error e)
164
169
            {
192
197
        main_window.set_keyboard_state ();
193
198
    }
194
199
 
195
 
    private static Gdk.FilterReturn focus_upon_map (Gdk.XEvent gxevent, Gdk.Event event)
 
200
    public bool is_authenticated ()
 
201
    {
 
202
        return greeter.is_authenticated;
 
203
    }
 
204
 
 
205
    public void authenticate (string? userid = null)
 
206
    {
 
207
        greeter.authenticate (userid);
 
208
    }
 
209
 
 
210
    public void authenticate_as_guest ()
 
211
    {
 
212
        greeter.authenticate_as_guest ();
 
213
    }
 
214
 
 
215
    public void authenticate_remote (string? session, string? userid)
 
216
    {
 
217
        UnityGreeter.singleton.greeter.authenticate_remote (session, userid);
 
218
    }
 
219
 
 
220
    public void cancel_authentication ()
 
221
    {
 
222
        greeter.cancel_authentication ();
 
223
    }
 
224
 
 
225
    public void respond (string response)
 
226
    {
 
227
        greeter.respond (response);
 
228
    }
 
229
 
 
230
    public string authentication_user ()
 
231
    {
 
232
        return greeter.authentication_user;
 
233
    }
 
234
 
 
235
    public string default_session_hint ()
 
236
    {
 
237
        return greeter.default_session_hint;
 
238
    }
 
239
 
 
240
    public string select_user_hint ()
 
241
    {
 
242
        return greeter.select_user_hint;
 
243
    }
 
244
 
 
245
    public bool show_manual_login_hint ()
 
246
    {
 
247
        return greeter.show_manual_login_hint;
 
248
    }
 
249
 
 
250
    public bool hide_users_hint ()
 
251
    {
 
252
        return greeter.hide_users_hint;
 
253
    }
 
254
 
 
255
    public bool has_guest_account_hint ()
 
256
    {
 
257
        return greeter.has_guest_account_hint;
 
258
    }
 
259
 
 
260
    private Gdk.FilterReturn focus_upon_map (Gdk.XEvent gxevent, Gdk.Event event)
196
261
    {
197
262
        var xevent = (X.Event*)gxevent;
198
263
        if (xevent.type == X.EventType.MapNotify)
237
302
 
238
303
        var pixmap = X.CreatePixmap (display,
239
304
                                     Gdk.X11Window.get_xid (screen.get_root_window ()),
240
 
                                     screen.width (),
241
 
                                     screen.height (),
 
305
                                     screen.get_width (),
 
306
                                     screen.get_height (),
242
307
                                     visual.get_depth ());
243
308
 
244
309
        /* Convert into a Cairo surface */
245
310
        var surface = new Cairo.XlibSurface (display,
246
311
                                             pixmap,
247
312
                                             Gdk.X11Visual.get_xvisual (visual),
248
 
                                             screen.width (), screen.height ());
 
313
                                             screen.get_width (), screen.get_height ());
249
314
 
250
315
        return surface;
251
316
    }
344
409
        debug ("Setting cursor");
345
410
        Gdk.get_default_root_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.LEFT_PTR));
346
411
 
347
 
        /* Prepare to set the background */
348
 
        debug ("Creating background surface");
349
 
        background_surface = create_root_surface (Gdk.Screen.get_default ());
 
412
        bool do_show_version = false;
 
413
        bool do_test_mode = false;
 
414
        OptionEntry versionOption = { "version", 'v', 0, OptionArg.NONE, ref do_show_version,
 
415
                /* Help string for command line --version flag */
 
416
                N_("Show release version"), null };
 
417
        OptionEntry testOption =  { "test-mode", 0, 0, OptionArg.NONE, ref do_test_mode,
 
418
                /* Help string for command line --test-mode flag */
 
419
                N_("Run in test mode"), null };
 
420
        OptionEntry nullOption = { null };
 
421
        OptionEntry[] options = { versionOption, testOption, nullOption };
350
422
 
351
423
        debug ("Loading command line options");
352
424
        var c = new OptionContext (/* Arguments and description for --help text */
365
437
            stderr.printf ("\n");
366
438
            return Posix.EXIT_FAILURE;
367
439
        }
368
 
        if (show_version)
 
440
        if (do_show_version)
369
441
        {
370
442
            /* Note, not translated so can be easily parsed */
371
443
            stderr.printf ("unity-greeter %s\n", Config.VERSION);
372
444
            return Posix.EXIT_SUCCESS;
373
445
        }
374
446
 
375
 
        if (test_mode)
 
447
        if (do_test_mode)
376
448
            debug ("Running in test mode");
377
449
 
378
 
        if (!test_mode)
 
450
        if (!do_test_mode)
379
451
        {
380
452
            /* Make nm-applet hide items the user does not have permissions to interact with */
381
453
            Environment.set_variable ("NM_APPLET_HIDE_POLICY_ITEMS", "1", true);
415
487
            settings.set ("gtk-xft-rgba", value, null);
416
488
 
417
489
        debug ("Creating Unity Greeter");
418
 
        var greeter = new UnityGreeter ();
 
490
        var greeter = new UnityGreeter (do_test_mode);
419
491
 
420
492
        debug ("Showing greeter");
421
493
        greeter.show ();