summaryrefslogtreecommitdiff
path: root/gui/simple-greeter/test-greeter-login-window.c
blob: 347bbde32b80ce5b644e50df18aaba96f3ca6520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdlib.h>
#include <libintl.h>
#include <locale.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>

#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "gdm-settings-client.h"

#include "gdm-greeter-login-window.h"

static guint cancel_idle_id = 0;

static gboolean     timed_login   = FALSE;
static GOptionEntry entries []   = {
        { "timed-login", 0, 0, G_OPTION_ARG_NONE, &timed_login, "Test timed login", NULL },
        { NULL }
};

static gboolean
do_cancel (GdmGreeterLoginWindow *login_window)
{
        gdm_greeter_login_window_reset (GDM_GREETER_LOGIN_WINDOW (login_window));
        cancel_idle_id = 0;
        return FALSE;
}

static void
on_select_user (GdmGreeterLoginWindow *login_window,
                const char            *text,
                gpointer               data)
{
        g_debug ("user selected: %s", text);
        if (cancel_idle_id != 0) {
                return;
        }
        cancel_idle_id = g_timeout_add_seconds (5, (GSourceFunc) do_cancel, login_window);
}

static void
on_cancelled (GdmGreeterLoginWindow *login_window,
              gpointer               data)
{
        g_debug ("login cancelled");
        if (cancel_idle_id != 0) {
                g_source_remove (cancel_idle_id);
                cancel_idle_id = 0;
        }
}

int
main (int argc, char *argv[])
{
        GtkWidget        *login_window;

        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        setlocale (LC_ALL, "");

        gtk_init_with_args (&argc,
                            &argv,
                            "",
                            entries,
                            NULL,
                            NULL);

        if (! gdm_settings_client_init (GDMCONFDIR "/gdm.schemas", "/")) {
                g_critical ("Unable to initialize settings client");
                exit (1);
        }

        login_window = gdm_greeter_login_window_new (TRUE);
        g_signal_connect (login_window,
                          "user-selected",
                          G_CALLBACK (on_select_user),
                          NULL);
        g_signal_connect (login_window,
                          "cancelled",
                          G_CALLBACK (on_cancelled),
                          NULL);
        if (timed_login) {
                gdm_greeter_login_window_request_timed_login (GDM_GREETER_LOGIN_WINDOW (login_window),
                                                              g_get_user_name (),
                                                              60);
        }

        gtk_widget_show (login_window);

        gtk_main ();

        return 0;
}