2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Ted Gould <ted@canonical.com>
20
[DBus (name="com.canonical.UnityGreeter.List")]
21
public interface UnityGreeterList : Object {
22
public abstract async string get_active_entry () throws IOError;
23
public signal void entry_selected (string entry_name);
26
public class MediaPlayerListGreeter : MediaPlayerList {
27
string? selected_user = null;
28
UnityGreeterList? proxy = null;
29
HashTable<string, MediaPlayerUser> players = new HashTable<string, MediaPlayerUser>(str_hash, str_equal);
31
public MediaPlayerListGreeter () {
32
Bus.get_proxy.begin<UnityGreeterList> (
34
"com.canonical.UnityGreeter",
41
void new_proxy (GLib.Object? obj, AsyncResult res) {
43
this.proxy = Bus.get_proxy.end(res);
45
this.proxy.entry_selected.connect(active_user_changed);
46
this.proxy.get_active_entry.begin ((obj, res) => {
48
var value = (obj as UnityGreeterList).get_active_entry.end(res);
49
active_user_changed(value);
51
warning("Unable to get active entry: %s", e.message);
56
warning("Unable to create proxy to the greeter: %s", e.message);
60
void active_user_changed (string active_user) {
61
/* No change, move along */
62
if (selected_user == active_user) {
66
debug(@"Active user changed to: $active_user");
68
var old_user = selected_user;
70
/* Protect against a null user */
71
if (active_user != "" && active_user[0] != '*') {
72
selected_user = active_user;
74
debug(@"Blocking active user change for '$active_user'");
78
if (selected_user != null && !players.contains(selected_user)) {
79
players.insert(selected_user, new MediaPlayerUser(selected_user));
82
if (old_user != null) {
83
var old_player = players.lookup(old_user);
84
debug("Removing player for user: %s", old_user);
85
player_removed(old_player);
88
if (selected_user != null) {
89
var new_player = players.lookup(selected_user);
91
if (new_player != null) {
92
debug("Adding player for user: %s", selected_user);
93
player_added(new_player);
98
/* We need to have an iterator for the interface, but eh, we can
99
only ever have one player for the current user */
100
public class Iterator : MediaPlayerList.Iterator {
102
MediaPlayerListGreeter list;
104
public Iterator (MediaPlayerListGreeter in_list) {
108
public override MediaPlayer? next_value () {
109
MediaPlayer? retval = null;
111
if (i == 0 && list.selected_user != null) {
112
retval = list.players.lookup(list.selected_user);
120
public override MediaPlayerList.Iterator iterator() {
121
return new Iterator(this) as MediaPlayerList.Iterator;