aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2014-02-24 15:36:48 -0600
committerTed Gould <ted@gould.cx>2014-02-24 15:36:48 -0600
commita758202c3799256ddded7ee790744d6fe3c1c4a7 (patch)
tree4355914be83bfa0dbbba37b4648a9ab5e869fd14
parentd42cb160a6823f34b478aab7c50a8b2247be0cf4 (diff)
downloadayatana-indicator-sound-a758202c3799256ddded7ee790744d6fe3c1c4a7.tar.gz
ayatana-indicator-sound-a758202c3799256ddded7ee790744d6fe3c1c4a7.tar.bz2
ayatana-indicator-sound-a758202c3799256ddded7ee790744d6fe3c1c4a7.zip
Build up our list of media players from the greeter list
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/media-player-list-greeter.vala62
-rw-r--r--src/media-player-user.vala4
3 files changed, 65 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f134954..436a154 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -82,6 +82,7 @@ vala_add(indicator-sound-service
media-player-list-greeter.vala
DEPENDS
media-player-list
+ media-player-user
media-player
)
vala_add(indicator-sound-service
diff --git a/src/media-player-list-greeter.vala b/src/media-player-list-greeter.vala
index 6bcf270..c07663a 100644
--- a/src/media-player-list-greeter.vala
+++ b/src/media-player-list-greeter.vala
@@ -17,7 +17,69 @@
* Ted Gould <ted@canonical.com>
*/
+[DBus (name="com.canonical.UnityGreeter.List")]
+public interface UnityGreeterList : Object {
+ public abstract async string get_active_entry () throws IOError;
+ public signal void entry_selected (string entry_name);
+}
+
public class MediaPlayerListGreeter : MediaPlayerList {
+ string? selected_user = null;
+ UnityGreeterList? proxy = null;
+ HashTable<string, MediaPlayerUser> players = new HashTable<string, MediaPlayerUser>(str_hash, str_equal);
+
+ public MediaPlayerListGreeter () {
+ Bus.get_proxy.begin<UnityGreeterList> (
+ BusType.SESSION,
+ "com.canonical.Unity",
+ "/list",
+ DBusProxyFlags.NONE,
+ null,
+ new_proxy);
+ }
+
+ void new_proxy (GLib.Object? obj, AsyncResult res) {
+ try {
+ this.proxy = Bus.get_proxy.end(res);
+
+ this.proxy.entry_selected.connect(active_user_changed);
+ this.proxy.get_active_entry.begin ((obj, res) => {
+ try {
+ var value = (obj as UnityGreeterList).get_active_entry.end(res);
+ active_user_changed(value);
+ } catch (Error e) {
+ warning("Unable to get active entry: %s", e.message);
+ }
+ });
+ } catch (Error e) {
+ this.proxy = null;
+ warning("Unable to create proxy to the greeter: %s", e.message);
+ }
+ }
+
+ void active_user_changed (string active_user) {
+ /* No change, move along */
+ if (selected_user == active_user) {
+ return;
+ }
+
+ var old_user = selected_user;
+ selected_user = active_user;
+
+ if (selected_user != null && !players.contains(selected_user)) {
+ players.insert(selected_user, new MediaPlayerUser(selected_user));
+ }
+
+ if (old_user != null) {
+ var old_player = players.lookup(old_user);
+ player_removed(old_player);
+ }
+
+ if (selected_user != null) {
+ var new_player = players.lookup(selected_user);
+ player_added(new_player);
+ }
+ }
}
diff --git a/src/media-player-user.vala b/src/media-player-user.vala
index 6c948ad..bd9bc92 100644
--- a/src/media-player-user.vala
+++ b/src/media-player-user.vala
@@ -17,13 +17,13 @@
* Ted Gould <ted@canonical.com>
*/
-public abstract class MediaPlayerUser : MediaPlayer {
+public class MediaPlayerUser : MediaPlayer {
Act.UserManager accounts_manager = Act.UserManager.get_default();
string username;
Act.User? actuser = null;
AccountsServiceSoundSettings? proxy = null;
- MediaPlayerUser(string user) {
+ public MediaPlayerUser(string user) {
username = user;
actuser = accounts_manager.get_user(user);