~dobey/indicator-sound/drop-greeeter

« back to all changes in this revision

Viewing changes to src/media-player-list-greeter.vala

  • Committer: Rodney Dawes
  • Date: 2017-03-23 19:23:42 UTC
  • Revision ID: rodney.dawes@canonical.com-20170323192342-v3didhhuoec0nv5p
Strip out the complicated non-working greeter support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2014 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authors:
17
 
 *      Ted Gould <ted@canonical.com>
18
 
 */
19
 
 
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);
24
 
}
25
 
 
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);
30
 
 
31
 
        public MediaPlayerListGreeter () {
32
 
                Bus.get_proxy.begin<UnityGreeterList> (
33
 
                        BusType.SESSION,
34
 
                        "com.canonical.UnityGreeter",
35
 
                        "/list",
36
 
                        DBusProxyFlags.NONE,
37
 
                        null,
38
 
                        new_proxy);
39
 
        }
40
 
 
41
 
        void new_proxy (GLib.Object? obj, AsyncResult res) {
42
 
                try {
43
 
                        this.proxy = Bus.get_proxy.end(res);
44
 
 
45
 
                        this.proxy.entry_selected.connect(active_user_changed);
46
 
                        this.proxy.get_active_entry.begin ((obj, res) => {
47
 
                                try {
48
 
                                        var value = (obj as UnityGreeterList).get_active_entry.end(res);
49
 
                                        active_user_changed(value);
50
 
                                } catch (Error e) {
51
 
                                        warning("Unable to get active entry: %s", e.message);
52
 
                                }
53
 
                        });
54
 
                } catch (Error e) {
55
 
                        this.proxy = null;
56
 
                        warning("Unable to create proxy to the greeter: %s", e.message);
57
 
                }
58
 
        }
59
 
 
60
 
        void active_user_changed (string active_user) {
61
 
                /* No change, move along */
62
 
                if (selected_user == active_user) {
63
 
                        return;
64
 
                }
65
 
 
66
 
                debug(@"Active user changed to: $active_user");
67
 
 
68
 
                var old_user = selected_user;
69
 
 
70
 
                /* Protect against a null user */
71
 
                if (active_user != "" && active_user[0] != '*') {
72
 
                        selected_user = active_user;
73
 
                } else {
74
 
                        debug(@"Blocking active user change for '$active_user'");
75
 
                        selected_user = null;
76
 
                }
77
 
 
78
 
                if (selected_user != null && !players.contains(selected_user)) {
79
 
                        players.insert(selected_user, new MediaPlayerUser(selected_user));
80
 
                }
81
 
 
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);
86
 
                }
87
 
 
88
 
                if (selected_user != null) {
89
 
                        var new_player = players.lookup(selected_user);
90
 
 
91
 
                        if (new_player != null) {
92
 
                                debug("Adding player for user: %s", selected_user);
93
 
                                player_added(new_player);
94
 
                        }
95
 
                }
96
 
        }
97
 
 
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 {
101
 
                int i = 0;
102
 
                MediaPlayerListGreeter list;
103
 
 
104
 
                public Iterator (MediaPlayerListGreeter in_list) {
105
 
                        list = in_list;
106
 
                }
107
 
 
108
 
                public override MediaPlayer? next_value () {
109
 
                        MediaPlayer? retval = null;
110
 
 
111
 
                        if (i == 0 && list.selected_user != null) {
112
 
                                retval = list.players.lookup(list.selected_user);
113
 
                        }
114
 
                        i++;
115
 
 
116
 
                        return retval;
117
 
                }
118
 
        }
119
 
 
120
 
        public override MediaPlayerList.Iterator iterator() {
121
 
                return new Iterator(this) as MediaPlayerList.Iterator;
122
 
        }
123
 
}