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

« back to all changes in this revision

Viewing changes to .pc/01_add_remote_login_help_icon.patch/src/session-list.vala

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-09-17 13:31:13 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20120917133113-sdfw9yiutq0omdgf
Tags: 12.10.3-0ubuntu1
* New upstream release
  - Rearrange some UI bits (LP: #1049231, LP: #1049235, LP: #1049236,
    LP: #1049239)
  - After a remote login error, do not use cache when trying same user
    again
  - When no users and no manual entry, force manual entry to appear
    (LP: #1044251)
  - When switching between monitors, re-adjust user names (LP: #1043604)
  - Center remote login help dialog
  - Use the xsettings plugin to apply icons-in-menus gsetting
    (LP: #927236)
* debian/unity-greeter.pkla:
  - Fix policykit file to not be order-dependent and spell out the
    NetworkManager permissions instead of using a wildcard.
    LP: #1048522
* debian/control:
  - Add some Build-Depends for new test suite
* debian/patches/01_add_remote_login_help_icon.patch:
  - Drop, remote login help icon is included upstream
* debian/patches/02_use_remote_login_hint.patch:
  - Update to apply again

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
 *
3
 
 * Copyright (C) 2012 Canonical Ltd
4
 
 *
5
 
 * This program is free software: you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 3 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 *
17
 
 * Authors: Michael Terry <michael.terry@canonical.com>
18
 
 */
19
 
 
20
 
public class SessionPrompt : PromptBox
21
 
{
22
 
    public string session { get; construct; }
23
 
    public string default_session { get; construct; }
24
 
 
25
 
    private Gtk.Widget active;
26
 
 
27
 
    public SessionPrompt (string id, string? session, string? default_session)
28
 
    {
29
 
        Object (id: id, session: session, default_session: default_session);
30
 
    }
31
 
 
32
 
    construct
33
 
    {
34
 
        label = _("Select desktop environment");
35
 
 
36
 
        if (UnityGreeter.test_mode)
37
 
        {
38
 
            add_session ("gnome", "GNOME");
39
 
            add_session ("kde", "KDE");
40
 
            add_session ("ubuntu", "Ubuntu");
41
 
        }
42
 
        else
43
 
        {
44
 
            foreach (var session in LightDM.get_sessions ())
45
 
            {
46
 
                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
 
        }
149
 
    }
150
 
}
151
 
 
152
 
public class SessionList : GreeterList
153
 
{
154
 
    public signal void session_clicked (string session);
155
 
    public string session { get; construct; }
156
 
    public string default_session { get; construct; }
157
 
 
158
 
    private SessionPrompt prompt;
159
 
 
160
 
    public SessionList (Background bg, MenuBar mb, string? session, string? default_session)
161
 
    {
162
 
        Object (background: bg, menubar: mb, session: session, default_session: default_session);
163
 
    }
164
 
 
165
 
    construct
166
 
    {
167
 
        prompt = add_session_prompt ("session");
168
 
    }
169
 
 
170
 
    private SessionPrompt add_session_prompt (string id)
171
 
    {
172
 
        var e = new SessionPrompt (id, session, default_session);
173
 
        e.respond.connect ((responses) => { session_clicked (responses[0]); });
174
 
        add_entry (e);
175
 
        return e;
176
 
    }
177
 
 
178
 
    protected override void add_manual_entry () {}
179
 
    public override void show_authenticated (bool successful = true) {}
180
 
 
181
 
    private static string? get_badge_name (string session)
182
 
    {
183
 
        switch (session)
184
 
        {
185
 
        case "ubuntu":
186
 
        case "ubuntu-2d":
187
 
            return "ubuntu_badge.png";
188
 
        case "gnome-classic":
189
 
        case "gnome-fallback":
190
 
        case "gnome-shell":
191
 
        case "gnome":
192
 
            return "gnome_badge.png";
193
 
        case "kde":
194
 
        case "kde-plasma":
195
 
            return "kde_badge.png";
196
 
        case "xterm":
197
 
            return "recovery_console_badge.png";
198
 
        case "remote-login":
199
 
            return "unknown_badge.png"; //"remote_login_help.png";
200
 
        default:
201
 
            return null;
202
 
        }
203
 
    }
204
 
 
205
 
    private static HashTable<string, Gdk.Pixbuf> badges; /* cache of badges */
206
 
    public static Gdk.Pixbuf? get_badge (string session)
207
 
    {
208
 
        var name = get_badge_name (session);
209
 
 
210
 
        if (name == null)
211
 
        {
212
 
            /* Not a known name, but let's see if we have a custom badge before
213
 
               giving up entirely and using the unknown badget. */
214
 
            var maybe_name = "custom_%s_badge.png".printf (session);
215
 
            var maybe_path = Path.build_filename (Config.PKGDATADIR, maybe_name, null);
216
 
            if (FileUtils.test (maybe_path, FileTest.EXISTS))
217
 
                name = maybe_name;
218
 
            else
219
 
                name = "unknown_badge.png";
220
 
        }
221
 
 
222
 
        if (badges == null)
223
 
            badges = new HashTable<string, Gdk.Pixbuf> (str_hash, str_equal);
224
 
 
225
 
        var pixbuf = badges.lookup (name);
226
 
        if (pixbuf == null)
227
 
        {
228
 
            try
229
 
            {
230
 
                pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (Config.PKGDATADIR, name, null));
231
 
                badges.insert (name, pixbuf);
232
 
            }
233
 
            catch (Error e)
234
 
            {
235
 
                debug ("Error loading badge %s: %s", name, e.message);
236
 
            }
237
 
        }
238
 
 
239
 
        return pixbuf;
240
 
    }
241
 
}