1
/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
3
* Copyright (C) 2012 Canonical Ltd
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.
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.
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/>.
17
* Authors: Michael Terry <michael.terry@canonical.com>
20
public class SessionPrompt : PromptBox
22
public string session { get; construct; }
23
public string default_session { get; construct; }
25
private Gtk.Widget active;
27
public SessionPrompt (string id, string? session, string? default_session)
29
Object (id: id, session: session, default_session: default_session);
34
label = _("Select desktop environment");
36
if (UnityGreeter.test_mode)
38
add_session ("gnome", "GNOME");
39
add_session ("kde", "KDE");
40
add_session ("ubuntu", "Ubuntu");
44
foreach (var session in LightDM.get_sessions ())
46
debug ("Adding session %s (%s)", session.key, session.name);
47
add_session (session.key, session.name);
51
var ok = new DashButton (_("OK"));
52
ok.clicked.connect (() =>
55
respond ({ active.get_data<string> ("session-list-key") });
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;
67
private void add_session (string key, string name_in)
69
var item = new Gtk.Button ();
70
item.clicked.connect (button_clicked_cb);
71
UnityGreeter.add_style_class (item);
73
var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
75
var pixbuf = SessionList.get_badge (key);
78
var image = new CachedImage (pixbuf);
79
hbox.pack_start (image, false, false, 0);
83
if (key == default_session)
85
/* Translators: %s is a session name like KDE or Ubuntu */
86
name = _("%s (Default)").printf (name);
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);
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);
107
debug ("Internal error loading session chooser style: %s", e.message);
110
item.set_data<string> ("session-list-key", key);
114
private void button_clicked_cb (Gtk.Widget button)
116
foreach_prompt_widget ((w) =>
119
w.override_background_color (Gtk.StateFlags.NORMAL, { 0.5f, 0.5f, 0.5f, 0.4f });
121
w.override_background_color (Gtk.StateFlags.NORMAL, null);
126
public override void grab_focus ()
129
Gtk.Widget best = null;
130
foreach_prompt_widget ((w) =>
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))
147
button_clicked_cb (best);
152
public class SessionList : GreeterList
154
public signal void session_clicked (string session);
155
public string session { get; construct; }
156
public string default_session { get; construct; }
158
private SessionPrompt prompt;
160
public SessionList (Background bg, MenuBar mb, string? session, string? default_session)
162
Object (background: bg, menubar: mb, session: session, default_session: default_session);
167
prompt = add_session_prompt ("session");
170
private SessionPrompt add_session_prompt (string id)
172
var e = new SessionPrompt (id, session, default_session);
173
e.respond.connect ((responses) => { session_clicked (responses[0]); });
178
protected override void add_manual_entry () {}
179
public override void show_authenticated (bool successful = true) {}
181
private static string? get_badge_name (string session)
187
return "ubuntu_badge.png";
188
case "gnome-classic":
189
case "gnome-fallback":
192
return "gnome_badge.png";
195
return "kde_badge.png";
197
return "recovery_console_badge.png";
199
return "unknown_badge.png"; //"remote_login_help.png";
205
private static HashTable<string, Gdk.Pixbuf> badges; /* cache of badges */
206
public static Gdk.Pixbuf? get_badge (string session)
208
var name = get_badge_name (session);
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))
219
name = "unknown_badge.png";
223
badges = new HashTable<string, Gdk.Pixbuf> (str_hash, str_equal);
225
var pixbuf = badges.lookup (name);
230
pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (Config.PKGDATADIR, name, null));
231
badges.insert (name, pixbuf);
235
debug ("Error loading badge %s: %s", name, e.message);