~ubuntu-branches/ubuntu/utopic/unity-greeter/utopic

« back to all changes in this revision

Viewing changes to src/session-list.vala

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2013-01-04 10:37:29 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: package-import@ubuntu.com-20130104103729-ydal31wfuhirb8zb
Tags: upstream-13.04.0
ImportĀ upstreamĀ versionĀ 13.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    public string session { get; construct; }
23
23
    public string default_session { get; construct; }
24
24
 
25
 
    private Gtk.Widget active;
26
 
 
27
25
    public SessionPrompt (string id, string? session, string? default_session)
28
26
    {
29
27
        Object (id: id, session: session, default_session: default_session);
30
28
    }
31
29
 
 
30
    private ToggleBox box;
 
31
 
32
32
    construct
33
33
    {
34
34
        label = _("Select desktop environment");
 
35
        name_label.vexpand = false;
 
36
 
 
37
        box = new ToggleBox (default_session, session);
35
38
 
36
39
        if (UnityGreeter.singleton.test_mode)
37
40
        {
38
 
            add_session ("gnome", "GNOME");
39
 
            add_session ("kde", "KDE");
40
 
            add_session ("ubuntu", "Ubuntu");
 
41
            box.add_item ("gnome", "GNOME", SessionList.get_badge ("gnome"));
 
42
            box.add_item ("kde", "KDE", SessionList.get_badge ("kde"));
 
43
            box.add_item ("ubuntu", "Ubuntu", SessionList.get_badge ("ubuntu"));
41
44
        }
42
45
        else
43
46
        {
44
47
            foreach (var session in LightDM.get_sessions ())
45
48
            {
46
49
                debug ("Adding session %s (%s)", session.key, session.name);
47
 
                add_session (session.key, session.name);
48
 
            }
49
 
        }
50
 
 
51
 
        var ok = new DashButton (_("OK"));
52
 
        ok.clicked.connect (() =>
53
 
        {
54
 
            if (active != null)
55
 
                respond ({ active.get_data<string> ("session-list-key") });
56
 
            else
57
 
                respond ({ null });
58
 
        });
59
 
        attach_item (ok);
60
 
 
61
 
        /* Only have the OK button be end-aligned.  The rest of them are near the top. */
62
 
        name_label.vexpand = false;
63
 
        ok.valign = Gtk.Align.END;
64
 
        ok.vexpand = true;
65
 
    }
66
 
 
67
 
    private void add_session (string key, string name_in)
68
 
    {
69
 
        var item = new Gtk.Button ();
70
 
        item.clicked.connect (button_clicked_cb);
71
 
        UnityGreeter.add_style_class (item);
72
 
 
73
 
        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
74
 
 
75
 
        var pixbuf = SessionList.get_badge (key);
76
 
        if (pixbuf != null)
77
 
        {
78
 
            var image = new CachedImage (pixbuf);
79
 
            hbox.pack_start (image, false, false, 0);
80
 
        }
81
 
 
82
 
        var name = name_in;
83
 
        if (key == default_session)
84
 
        {
85
 
            /* Translators: %s is a session name like KDE or Ubuntu */
86
 
            name = _("%s (Default)").printf (name);
87
 
        }
88
 
 
89
 
        var label = new Gtk.Label (null);
90
 
        label.set_markup ("<span font=\"Ubuntu 13\">%s</span>".printf (name));
91
 
        label.halign = Gtk.Align.START;
92
 
        hbox.pack_start (label, true, true, 0);
93
 
 
94
 
        item.hexpand = true;
95
 
        item.add (hbox);
96
 
        hbox.show_all ();
97
 
 
98
 
        try
99
 
        {
100
 
            /* Tighten padding on buttons to not be so large */
101
 
            var style = new Gtk.CssProvider ();
102
 
            style.load_from_data ("* {padding: 8px;}", -1);
103
 
            item.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
104
 
        }
105
 
        catch (Error e)
106
 
        {
107
 
            debug ("Internal error loading session chooser style: %s", e.message);
108
 
        }
109
 
 
110
 
        item.set_data<string> ("session-list-key", key);
111
 
        attach_item (item);
112
 
    }
113
 
 
114
 
    private void button_clicked_cb (Gtk.Widget button)
115
 
    {
116
 
        foreach_prompt_widget ((w) =>
117
 
        {
118
 
            if (w == button)
119
 
                w.override_background_color (Gtk.StateFlags.NORMAL, { 0.5f, 0.5f, 0.5f, 0.4f });
120
 
            else
121
 
                w.override_background_color (Gtk.StateFlags.NORMAL, null);
122
 
        });
123
 
        active = button;
124
 
    }
125
 
 
126
 
    public override void grab_focus ()
127
 
    {
128
 
        var done = false;
129
 
        Gtk.Widget best = null;
130
 
        foreach_prompt_widget ((w) =>
131
 
        {
132
 
            if (done)
133
 
                return;
134
 
            if (best == null)
135
 
                best = w; /* first button wins, all else considered */
136
 
            var key = w.get_data<string> ("session-list-key");
137
 
            if (session == key || (session == null && default_session == key))
138
 
            {
139
 
                best = w;
140
 
                done = true;
141
 
            }
142
 
        });
143
 
 
144
 
        if (best != null)
145
 
        {
146
 
            best.grab_focus ();
147
 
            button_clicked_cb (best);
148
 
        }
 
50
                box.add_item (session.key, session.name, SessionList.get_badge (session.key));
 
51
            }
 
52
        }
 
53
 
 
54
        box.notify["selected-key"].connect (selected_cb);
 
55
        box.show ();
 
56
 
 
57
        attach_item (box);
 
58
    }
 
59
 
 
60
    private void selected_cb ()
 
61
    {
 
62
        respond ({ box.selected_key });
149
63
    }
150
64
}
151
65