From 3ce0b11814352483761e693d50364b1b43694d26 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 10 Feb 2014 16:42:39 -0600 Subject: Getting accounts service into the service --- src/CMakeLists.txt | 11 ++++++++++- src/service.vala | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c11ec51..7efb2a5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,15 @@ set(HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/indicator-sound-service.h") set(SYMBOLS_PATH "${CMAKE_CURRENT_BINARY_DIR}/indicator-sound-service.def") +vapi_gen(accounts-service + LIBRARY + accounts-service + PACKAGES + gio-2.0 + INPUT + /usr/share/gir-1.0/AccountsService-1.0.gir +) + vala_init(indicator-sound-service PACKAGES config @@ -20,9 +29,9 @@ vala_init(indicator-sound-service --thread --vapidir=${CMAKE_SOURCE_DIR}/vapi/ --vapidir=. - --target-glib=2.36 --pkg=url-dispatcher --pkg=bus-watcher + --pkg=accounts-service ) vala_add(indicator-sound-service diff --git a/src/service.vala b/src/service.vala index f7d86bb..a246758 100644 --- a/src/service.vala +++ b/src/service.vala @@ -87,6 +87,7 @@ public class IndicatorSound.Service { uint player_action_update_id; Notify.Notification notification; bool syncing_preferred_players = false; + Act.UserManager account_manager = Act.UserManager.get_default(); const double volume_step_percentage = 0.06; -- cgit v1.2.3 From e826a1e7d8d21d21cddeb797cd7f8eb6aee08c79 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 10 Feb 2014 16:46:16 -0600 Subject: Making parallel build work again --- src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7efb2a5..1994989 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,8 @@ vapi_gen(accounts-service ) vala_init(indicator-sound-service + DEPENDS + accounts-service PACKAGES config gio-2.0 @@ -24,6 +26,7 @@ vala_init(indicator-sound-service libpulse libpulse-mainloop-glib libnotify + accounts-service OPTIONS --ccode --thread @@ -31,7 +34,6 @@ vala_init(indicator-sound-service --vapidir=. --pkg=url-dispatcher --pkg=bus-watcher - --pkg=accounts-service ) vala_add(indicator-sound-service -- cgit v1.2.3 From 6e67bf9139adfbd9bfd8b7a32ec061d63514efe9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 10:01:10 -0600 Subject: Making an object to hold our accounts service stuff --- src/CMakeLists.txt | 4 ++++ src/accounts-service-user.vala | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/accounts-service-user.vala (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1994989..9ff68ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,6 +44,7 @@ vala_add(indicator-sound-service media-player media-player-list mpris2-interfaces + accounts-service-user ) vala_add(indicator-sound-service main.vala @@ -76,6 +77,9 @@ vala_add(indicator-sound-service media-player mpris2-interfaces ) +vala_add(indicator-sound-service + accounts-service-user.vala +) vala_finish(indicator-sound-service SOURCES diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala new file mode 100644 index 0000000..56d981d --- /dev/null +++ b/src/accounts-service-user.vala @@ -0,0 +1,31 @@ +/* + * Copyright 2014 © Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: + * Ted Gould + */ + + +public class AccountServiceUser : Object { + + + + + + + + + +} -- cgit v1.2.3 From a38509fd4b0023456c48fcb014f6ba0063b16f23 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 15:18:18 -0600 Subject: Building the service over in the new object --- src/accounts-service-user.vala | 9 ++++++++- src/service.vala | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 56d981d..7639b2e 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -18,7 +18,14 @@ */ -public class AccountServiceUser : Object { +public class AccountsServiceUser : Object { + Act.UserManager accounts_manager = Act.UserManager.get_default(); + Act.User? user = null; + + public AccountsServiceUser () { + user = accounts_manager.get_user(GLib.Environment.get_user_name()); + + } diff --git a/src/service.vala b/src/service.vala index a246758..b6ed0a5 100644 --- a/src/service.vala +++ b/src/service.vala @@ -42,6 +42,10 @@ public class IndicatorSound.Service { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); }); + if (GLib.Environment.get_user_name() != "lightdm") { + accounts_service = new AccountsServiceUser(); + } + this.sync_preferred_players (); this.settings.changed["interested-media-players"].connect ( () => { this.sync_preferred_players (); @@ -87,7 +91,7 @@ public class IndicatorSound.Service { uint player_action_update_id; Notify.Notification notification; bool syncing_preferred_players = false; - Act.UserManager account_manager = Act.UserManager.get_default(); + AccountsServiceUser? accounts_service = null; const double volume_step_percentage = 0.06; -- cgit v1.2.3 From eb1dc0ff1ae607763635ad220b7b914ec9235417 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 15:34:24 -0600 Subject: Update the player based on which one is running --- src/CMakeLists.txt | 3 +++ src/accounts-service-user.vala | 2 ++ src/service.vala | 12 ++++++++++++ 3 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ff68ca..3ee6a65 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,6 +79,9 @@ vala_add(indicator-sound-service ) vala_add(indicator-sound-service accounts-service-user.vala + DEPENDS + media-player + mpris2-interfaces ) vala_finish(indicator-sound-service diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 7639b2e..33fb6e9 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -22,6 +22,8 @@ public class AccountsServiceUser : Object { Act.UserManager accounts_manager = Act.UserManager.get_default(); Act.User? user = null; + public MediaPlayer? player = null; + public AccountsServiceUser () { user = accounts_manager.get_user(GLib.Environment.get_user_name()); diff --git a/src/service.vala b/src/service.vala index b6ed0a5..25f3011 100644 --- a/src/service.vala +++ b/src/service.vala @@ -275,12 +275,24 @@ public class IndicatorSound.Service { } bool update_player_actions () { + bool clear_accounts_player = true; + foreach (var player in this.players) { SimpleAction? action = this.actions.lookup_action (player.id) as SimpleAction; if (action != null) { action.set_state (this.action_state_for_player (player)); action.set_enabled (player.can_raise); } + + /* If we're playing then put that data in accounts service */ + if (player.is_running && accounts_service != null) { + accounts_service.player = player; + clear_accounts_player = false; + } + } + + if (clear_accounts_player && accounts_service != null) { + accounts_service.player = null; } this.player_action_update_id = 0; -- cgit v1.2.3 From b96572e7933c03fdd51529e6dd71e87c72bd062a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 16:29:54 -0600 Subject: Build up to getting our settings proxy in the account manager --- src/accounts-service-user.vala | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 33fb6e9..c476033 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -17,16 +17,53 @@ * Ted Gould */ +[DBus (name = "com.canonical.indicator.sound.AccountsService")] +public interface AccountsServiceSoundSettings : Object { + // properties + public abstract bool playing{owned get; set;} +} public class AccountsServiceUser : Object { Act.UserManager accounts_manager = Act.UserManager.get_default(); Act.User? user = null; + AccountsServiceSoundSettings? proxy = null; + MediaPlayer? _player = null; - public MediaPlayer? player = null; + public MediaPlayer? player { + set { + this._player = value; + } + get { + return this._player; + } + } public AccountsServiceUser () { user = accounts_manager.get_user(GLib.Environment.get_user_name()); + user.notify["is-loaded"].connect(() => { + debug("User loaded"); + + this.proxy = null; + + Bus.get_proxy.begin ( + BusType.SYSTEM, + "org.freedesktop.AccountsService", + user.get_object_path(), + DBusProxyFlags.GET_INVALIDATED_PROPERTIES, + null, + new_proxy); + }); + + } + void new_proxy (GLib.Object? obj, AsyncResult res) { + try { + this.proxy = Bus.get_proxy.end (res); + //this.player = _player; + } catch (Error e) { + this.proxy = null; + warning("Unable to get proxy to user sound settings: %s", e.message); + } } -- cgit v1.2.3 From 28e3a8eff7e1305c93c5c7b8283bb7aedfce56b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 17:33:42 -0600 Subject: All the properties we need --- src/accounts-service-user.vala | 53 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index c476033..c5465ca 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -20,7 +20,14 @@ [DBus (name = "com.canonical.indicator.sound.AccountsService")] public interface AccountsServiceSoundSettings : Object { // properties - public abstract bool playing{owned get; set;} + public abstract string player_name {owned get; set;} + public abstract Variant player_icon {owned get; set;} + public abstract bool running {owned get; set;} + public abstract string state {owned get; set;} + public abstract string title {owned get; set;} + public abstract string artist {owned get; set;} + public abstract string album {owned get; set;} + public abstract string art_url {owned get; set;} } public class AccountsServiceUser : Object { @@ -32,6 +39,38 @@ public class AccountsServiceUser : Object { public MediaPlayer? player { set { this._player = value; + + /* No proxy, no settings to set */ + if (this.proxy == null) + return; + + if (this._player == null) { + /* Clear it */ + this.proxy.player_name = ""; + } else { + this.proxy.player_name = this._player.name; + if (this._player.icon == null) { + var icon = new ThemedIcon.with_default_fallbacks ("application-default-icon"); + this.proxy.player_icon = icon.serialize(); + } else { + this.proxy.player_icon = this._player.icon.serialize(); + } + + this.proxy.running = this._player.is_running; + this.proxy.state = this._player.state; + + if (this._player.current_track != null) { + this.proxy.title = this._player.current_track.title; + this.proxy.artist = this._player.current_track.artist; + this.proxy.album = this._player.current_track.album; + this.proxy.art_url = this._player.current_track.art_url; + } else { + this.proxy.title = ""; + this.proxy.artist = ""; + this.proxy.album = ""; + this.proxy.art_url = ""; + } + } } get { return this._player; @@ -53,7 +92,10 @@ public class AccountsServiceUser : Object { null, new_proxy); }); + } + ~AccountsServiceUser () { + this.player = null; } void new_proxy (GLib.Object? obj, AsyncResult res) { @@ -65,13 +107,4 @@ public class AccountsServiceUser : Object { warning("Unable to get proxy to user sound settings: %s", e.message); } } - - - - - - - - - } -- cgit v1.2.3 From a933b3a40d32453c096029b9d47dd198f49bda98 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 17:36:37 -0600 Subject: oops --- src/accounts-service-user.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index c5465ca..927a270 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -86,7 +86,7 @@ public class AccountsServiceUser : Object { Bus.get_proxy.begin ( BusType.SYSTEM, - "org.freedesktop.AccountsService", + "org.freedesktop.Accounts", user.get_object_path(), DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, -- cgit v1.2.3 From 66edc177867c09e696552a73862c29485194e704 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 20:52:49 -0600 Subject: Switch the build to have a library of all the vala components --- src/CMakeLists.txt | 29 ++++++++++++++++++++--------- src/main.c | 32 ++++++++++++++++++++++++++++++++ src/main.vala | 14 -------------- 3 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 src/main.c delete mode 100644 src/main.vala (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ee6a65..ca1eb82 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,11 +46,6 @@ vala_add(indicator-sound-service mpris2-interfaces accounts-service-user ) -vala_add(indicator-sound-service - main.vala - DEPENDS - service -) vala_add(indicator-sound-service volume-control.vala ) @@ -110,16 +105,33 @@ set( ) ########################### -# Executable +# Lib ########################### add_definitions( -w ) +add_library( + indicator-sound-service-lib STATIC + ${INDICATOR_SOUND_SOURCES} +) + +target_link_libraries( + indicator-sound-service-lib + ${PULSEAUDIO_LIBRARIES} + ${SOUNDSERVICE_LIBRARIES} +) + +########################### +# Executable +########################### + +include_directories(${CMAKE_BINARY_DIR}) + add_executable( indicator-sound-service-bin - ${INDICATOR_SOUND_SOURCES} + main.c ) set_target_properties( @@ -130,8 +142,7 @@ set_target_properties( target_link_libraries( indicator-sound-service-bin - ${PULSEAUDIO_LIBRARIES} - ${SOUNDSERVICE_LIBRARIES} + indicator-sound-service-lib ) ########################### diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f8635c8 --- /dev/null +++ b/src/main.c @@ -0,0 +1,32 @@ +/* main.c generated by valac 0.22.1, the Vala compiler + * generated from main.vala, do not modify */ + + +#include +#include +#include + +#include "indicator-sound-service.h" +#include "config.h" + +int +main (int argc, char ** argv) { + gint result = 0; + IndicatorSoundService* service = NULL; + + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + setlocale (LC_ALL, ""); + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + + /* Initialize libnotify */ + notify_init ("indicator-sound"); + + + service = indicator_sound_service_new (); + result = indicator_sound_service_run (service); + g_object_unref(service); + + return result; +} + + diff --git a/src/main.vala b/src/main.vala deleted file mode 100644 index 4da9e58..0000000 --- a/src/main.vala +++ /dev/null @@ -1,14 +0,0 @@ - -[CCode (cheader_filename="libintl.h", type="char *")] -extern unowned string bind_textdomain_codeset (string domainname, string codeset); - -static int main (string[] args) { - bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8"); - Intl.setlocale (LocaleCategory.ALL, ""); - Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.GNOMELOCALEDIR); - - Notify.init ("indicator-sound"); - - var service = new IndicatorSound.Service (); - return service.run (); -} -- cgit v1.2.3 From 23482084db3c4b94ad019639507a5891d2199560 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 10:21:32 -0600 Subject: Throwing an abstraction in front of the player --- src/CMakeLists.txt | 5 + src/media-player-list.vala | 20 +-- src/media-player-mpris.vala | 299 ++++++++++++++++++++++++++++++++++++++++++++ src/media-player.vala | 297 ++++--------------------------------------- 4 files changed, 337 insertions(+), 284 deletions(-) create mode 100644 src/media-player-mpris.vala (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca1eb82..d548c66 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,13 +51,18 @@ vala_add(indicator-sound-service ) vala_add(indicator-sound-service media-player.vala +) +vala_add(indicator-sound-service + media-player-mpris.vala DEPENDS + media-player mpris2-interfaces ) vala_add(indicator-sound-service media-player-list.vala DEPENDS media-player + media-player-mpris mpris2-interfaces ) vala_add(indicator-sound-service diff --git a/src/media-player-list.vala b/src/media-player-list.vala index 5a12e32..87ca1f0 100644 --- a/src/media-player-list.vala +++ b/src/media-player-list.vala @@ -24,24 +24,24 @@ public class MediaPlayerList { public MediaPlayerList () { - this._players = new HashTable (str_hash, str_equal); + this._players = new HashTable (str_hash, str_equal); BusWatcher.watch_namespace (BusType.SESSION, "org.mpris.MediaPlayer2", this.player_appeared, this.player_disappeared); } /* only valid while the list is not changed */ public class Iterator { - HashTableIter iter; + HashTableIter iter; public Iterator (MediaPlayerList list) { - this.iter = HashTableIter (list._players); + this.iter = HashTableIter (list._players); } public MediaPlayer? next_value () { - MediaPlayer? player; + MediaPlayerMpris? player; if (this.iter.next (null, out player)) - return player; + return player as MediaPlayer; else return null; } @@ -54,9 +54,9 @@ public class MediaPlayerList { /** * Adds the player associated with @desktop_id. Does nothing if such a player already exists. */ - MediaPlayer? insert (string desktop_id) { + MediaPlayerMpris? insert (string desktop_id) { var id = desktop_id.has_suffix (".desktop") ? desktop_id : desktop_id + ".desktop"; - MediaPlayer? player = this._players.lookup (id); + MediaPlayerMpris? player = this._players.lookup (id); if (player == null) { var appinfo = new DesktopAppInfo (id); @@ -65,7 +65,7 @@ public class MediaPlayerList { return null; } - player = new MediaPlayer (appinfo); + player = new MediaPlayerMpris (appinfo); this._players.insert (player.id, player); this.player_added (player); } @@ -110,7 +110,7 @@ public class MediaPlayerList { public signal void player_added (MediaPlayer player); public signal void player_removed (MediaPlayer player); - HashTable _players; + HashTable _players; void player_appeared (DBusConnection connection, string name, string owner) { try { @@ -126,7 +126,7 @@ public class MediaPlayerList { } void player_disappeared (DBusConnection connection, string dbus_name) { - MediaPlayer? player = this._players.find ( (name, player) => { + MediaPlayerMpris? player = this._players.find ( (name, player) => { return player.dbus_name == dbus_name; }); diff --git a/src/media-player-mpris.vala b/src/media-player-mpris.vala new file mode 100644 index 0000000..25ddac4 --- /dev/null +++ b/src/media-player-mpris.vala @@ -0,0 +1,299 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +/** + * MediaPlayerMpris represents an MRPIS-capable media player. + */ +public class MediaPlayerMpris: MediaPlayer { + + public MediaPlayerMpris (DesktopAppInfo appinfo) { + this.appinfo = appinfo; + } + + /** Desktop id of the player */ + public override string id { + get { + return this.appinfo.get_id (); + } + } + + /** Display name of the player */ + public override string name { + get { + return this.appinfo.get_name (); + } + } + + /** Application icon of the player */ + public override Icon? icon { + get { + return this.appinfo.get_icon (); + } + } + + /** + * True if an instance of the player is currently running. + * + * See also: attach(), detach() + */ + public override bool is_running { + get { + return this.proxy != null; + } + } + + /** Name of the player on the bus, if an instance is currently running */ + public override string dbus_name { + get { + return this._dbus_name; + } + } + + public override string state { + get; private set; default = "Paused"; + } + + public override MediaPlayer.Track? current_track { + get; set; + } + + public override bool can_raise { + get { + return this.root != null ? this.root.CanRaise : true; + } + } + + /** + * Attach this object to a process of the associated media player. The player must own @dbus_name and + * implement the org.mpris.MediaPlayer2.Player interface. + * + * Only one player can be attached at any given time. Use detach() to detach a player. + * + * This method does not block. If it is successful, "is-running" will be set to %TRUE. + */ + public void attach (MprisRoot root, string dbus_name) { + return_if_fail (this._dbus_name == null && this.proxy == null); + + this.root = root; + this.notify_property ("can-raise"); + + this._dbus_name = dbus_name; + Bus.get_proxy.begin (BusType.SESSION, dbus_name, "/org/mpris/MediaPlayer2", + DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, got_proxy); + Bus.get_proxy.begin (BusType.SESSION, dbus_name, "/org/mpris/MediaPlayer2", + DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, got_playlists_proxy); + } + + /** + * Detach this object from a process running the associated media player. + * + * See also: attach() + */ + public void detach () { + this.root = null; + this.proxy = null; + this._dbus_name = null; + this.notify_property ("is-running"); + this.notify_property ("can-raise"); + this.state = "Paused"; + this.current_track = null; + } + + /** + * Activate the associated media player. + * + * Note: this will _not_ call attach(), because it doesn't know on which dbus-name the player will appear. + * Use attach() to attach this object to a running instance of the player. + */ + public override void activate () { + try { + if (this.proxy == null) { + this.appinfo.launch (null, null); + this.state = "Launching"; + } + else if (this.root != null && this.root.CanRaise) { + this.root.Raise (); + } + } + catch (Error e) { + warning ("unable to activate %s: %s", appinfo.get_name (), e.message); + } + } + + /** + * Toggles playing status. + */ + public override void play_pause () { + if (this.proxy != null) { + this.proxy.PlayPause.begin (); + } + else if (this.state != "Launching") { + this.play_when_attached = true; + this.activate (); + } + } + + /** + * Skips to the next track. + */ + public override void next () { + if (this.proxy != null) + this.proxy.Next.begin (); + } + + /** + * Skips to the previous track. + */ + public override void previous () { + if (this.proxy != null) + this.proxy.Previous.begin (); + } + + public override uint get_n_playlists () { + return this.playlists != null ? this.playlists.length : 0; + } + + public override string get_playlist_id (int index) { + return_val_if_fail (index < this.playlists.length, ""); + return this.playlists[index].path; + } + + public override string get_playlist_name (int index) { + return_val_if_fail (index < this.playlists.length, ""); + return this.playlists[index].name; + } + + public override void activate_playlist_by_name (string name) { + if (this.playlists_proxy != null) + this.playlists_proxy.ActivatePlaylist.begin (new ObjectPath (name)); + } + + DesktopAppInfo appinfo; + MprisPlayer? proxy; + MprisPlaylists ?playlists_proxy; + string _dbus_name; + bool play_when_attached = false; + MprisRoot root; + PlaylistDetails[] playlists = null; + + void got_proxy (Object? obj, AsyncResult res) { + try { + this.proxy = Bus.get_proxy.end (res); + + /* Connecting to GDBusProxy's "g-properties-changed" signal here, because vala's dbus objects don't + * emit notify signals */ + var gproxy = this.proxy as DBusProxy; + gproxy.g_properties_changed.connect (this.proxy_properties_changed); + + this.notify_property ("is-running"); + this.state = this.proxy.PlaybackStatus; + this.update_current_track (gproxy.get_cached_property ("Metadata")); + + if (this.play_when_attached) { + /* wait a little before calling PlayPause, some players need some time to + set themselves up */ + Timeout.add (1000, () => { proxy.PlayPause.begin (); return false; } ); + this.play_when_attached = false; + } + } + catch (Error e) { + this._dbus_name = null; + warning ("unable to attach to media player: %s", e.message); + } + } + + void fetch_playlists () { + /* The proxy is created even when the interface is not supported. GDBusProxy will + return 0 for the PlaylistCount property in that case. */ + if (this.playlists_proxy != null && this.playlists_proxy.PlaylistCount > 0) { + this.playlists_proxy.GetPlaylists.begin (0, 100, "Alphabetical", false, (obj, res) => { + try { + this.playlists = playlists_proxy.GetPlaylists.end (res); + this.playlists_changed (); + } + catch (Error e) { + warning ("could not fetch playlists: %s", e.message); + this.playlists = null; + } + }); + } + else { + this.playlists = null; + this.playlists_changed (); + } + } + + void got_playlists_proxy (Object? obj, AsyncResult res) { + try { + this.playlists_proxy = Bus.get_proxy.end (res); + + var gproxy = this.proxy as DBusProxy; + gproxy.g_properties_changed.connect (this.playlists_proxy_properties_changed); + } + catch (Error e) { + warning ("unable to create mpris plalists proxy: %s", e.message); + return; + } + + Timeout.add (500, () => { this.fetch_playlists (); return false; } ); + } + + /* some players (e.g. Spotify) don't follow the spec closely and pass single strings in metadata fields + * where an array of string is expected */ + static string sanitize_metadata_value (Variant? v) { + if (v == null) + return ""; + else if (v.is_of_type (VariantType.STRING)) + return v.get_string (); + else if (v.is_of_type (VariantType.STRING_ARRAY)) + return string.joinv (",", v.get_strv ()); + + warn_if_reached (); + return ""; + } + + void proxy_properties_changed (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) { + if (changed_properties.lookup ("PlaybackStatus", "s", null)) { + this.state = this.proxy.PlaybackStatus; + } + + var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}")); + if (metadata != null) + this.update_current_track (metadata); + } + + void playlists_proxy_properties_changed (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) { + if (changed_properties.lookup ("PlaylistCount", "u", null)) + this.fetch_playlists (); + } + + void update_current_track (Variant metadata) { + if (metadata != null) { + this.current_track = new Track ( + sanitize_metadata_value (metadata.lookup_value ("xesam:artist", null)), + sanitize_metadata_value (metadata.lookup_value ("xesam:title", null)), + sanitize_metadata_value (metadata.lookup_value ("xesam:album", null)), + sanitize_metadata_value (metadata.lookup_value ("mpris:artUrl", null)) + ); + } + else { + this.current_track = null; + } + } +} diff --git a/src/media-player.vala b/src/media-player.vala index da68ac1..4d4aef3 100644 --- a/src/media-player.vala +++ b/src/media-player.vala @@ -1,5 +1,5 @@ /* - * Copyright 2013 Canonical Ltd. + * Copyright © 2014 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,60 +14,18 @@ * along with this program. If not, see . * * Authors: - * Lars Uebernickel + * Ted Gould */ -/** - * MediaPlayer represents an MRPIS-capable media player. - */ -public class MediaPlayer: Object { - - public MediaPlayer (DesktopAppInfo appinfo) { - this.appinfo = appinfo; - } - - /** Desktop id of the player */ - public string id { - get { - return this.appinfo.get_id (); - } - } +public abstract class MediaPlayer : Object { + public virtual string id { get { not_implemented(); return ""; } } + public virtual string name { get { not_implemented(); return ""; } } + public virtual string state { get { not_implemented(); return ""; } set { }} + public virtual Icon? icon { get { not_implemented(); return null; } } + public virtual string dbus_name { get { not_implemented(); return ""; } } - /** Display name of the player */ - public string name { - get { - return this.appinfo.get_name (); - } - } - - /** Application icon of the player */ - public Icon icon { - get { - return this.appinfo.get_icon (); - } - } - - /** - * True if an instance of the player is currently running. - * - * See also: attach(), detach() - */ - public bool is_running { - get { - return this.proxy != null; - } - } - - /** Name of the player on the bus, if an instance is currently running */ - public string dbus_name { - get { - return this._dbus_name; - } - } - - public string state { - get; private set; default = "Paused"; - } + public virtual bool is_running { get { not_implemented(); return false; } } + public virtual bool can_raise { get { not_implemented(); return false; } } public class Track : Object { public string artist { get; construct; } @@ -80,233 +38,24 @@ public class MediaPlayer: Object { } } - public Track current_track { - get; set; - } - - public bool can_raise { - get { - return this.root != null ? this.root.CanRaise : true; - } + public virtual Track? current_track { + get { not_implemented(); return null; } + set { not_implemented(); } } public signal void playlists_changed (); - /** - * Attach this object to a process of the associated media player. The player must own @dbus_name and - * implement the org.mpris.MediaPlayer2.Player interface. - * - * Only one player can be attached at any given time. Use detach() to detach a player. - * - * This method does not block. If it is successful, "is-running" will be set to %TRUE. - */ - public void attach (MprisRoot root, string dbus_name) { - return_if_fail (this._dbus_name == null && this.proxy == null); - - this.root = root; - this.notify_property ("can-raise"); - - this._dbus_name = dbus_name; - Bus.get_proxy.begin (BusType.SESSION, dbus_name, "/org/mpris/MediaPlayer2", - DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, got_proxy); - Bus.get_proxy.begin (BusType.SESSION, dbus_name, "/org/mpris/MediaPlayer2", - DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, got_playlists_proxy); - } - - /** - * Detach this object from a process running the associated media player. - * - * See also: attach() - */ - public void detach () { - this.root = null; - this.proxy = null; - this._dbus_name = null; - this.notify_property ("is-running"); - this.notify_property ("can-raise"); - this.state = "Paused"; - this.current_track = null; - } + public abstract void activate (); + public abstract void play_pause (); + public abstract void next (); + public abstract void previous (); - /** - * Activate the associated media player. - * - * Note: this will _not_ call attach(), because it doesn't know on which dbus-name the player will appear. - * Use attach() to attach this object to a running instance of the player. - */ - public void activate () { - try { - if (this.proxy == null) { - this.appinfo.launch (null, null); - this.state = "Launching"; - } - else if (this.root != null && this.root.CanRaise) { - this.root.Raise (); - } - } - catch (Error e) { - warning ("unable to activate %s: %s", appinfo.get_name (), e.message); - } - } - - /** - * Toggles playing status. - */ - public void play_pause () { - if (this.proxy != null) { - this.proxy.PlayPause.begin (); - } - else if (this.state != "Launching") { - this.play_when_attached = true; - this.activate (); - } - } - - /** - * Skips to the next track. - */ - public void next () { - if (this.proxy != null) - this.proxy.Next.begin (); - } - - /** - * Skips to the previous track. - */ - public void previous () { - if (this.proxy != null) - this.proxy.Previous.begin (); - } + public abstract uint get_n_playlists(); + public abstract string get_playlist_id (int index); + public abstract string get_playlist_name (int index); + public abstract void activate_playlist_by_name (string playlist); - public uint get_n_playlists () { - return this.playlists != null ? this.playlists.length : 0; - } - - public string get_playlist_id (int index) { - return_val_if_fail (index < this.playlists.length, ""); - return this.playlists[index].path; - } - - public string get_playlist_name (int index) { - return_val_if_fail (index < this.playlists.length, ""); - return this.playlists[index].name; - } - - public void activate_playlist_by_name (string name) { - if (this.playlists_proxy != null) - this.playlists_proxy.ActivatePlaylist.begin (new ObjectPath (name)); - } - - DesktopAppInfo appinfo; - MprisPlayer? proxy; - MprisPlaylists ?playlists_proxy; - string _dbus_name; - bool play_when_attached = false; - MprisRoot root; - PlaylistDetails[] playlists = null; - - void got_proxy (Object? obj, AsyncResult res) { - try { - this.proxy = Bus.get_proxy.end (res); - - /* Connecting to GDBusProxy's "g-properties-changed" signal here, because vala's dbus objects don't - * emit notify signals */ - var gproxy = this.proxy as DBusProxy; - gproxy.g_properties_changed.connect (this.proxy_properties_changed); - - this.notify_property ("is-running"); - this.state = this.proxy.PlaybackStatus; - this.update_current_track (gproxy.get_cached_property ("Metadata")); - - if (this.play_when_attached) { - /* wait a little before calling PlayPause, some players need some time to - set themselves up */ - Timeout.add (1000, () => { proxy.PlayPause.begin (); return false; } ); - this.play_when_attached = false; - } - } - catch (Error e) { - this._dbus_name = null; - warning ("unable to attach to media player: %s", e.message); - } - } - - void fetch_playlists () { - /* The proxy is created even when the interface is not supported. GDBusProxy will - return 0 for the PlaylistCount property in that case. */ - if (this.playlists_proxy != null && this.playlists_proxy.PlaylistCount > 0) { - this.playlists_proxy.GetPlaylists.begin (0, 100, "Alphabetical", false, (obj, res) => { - try { - this.playlists = playlists_proxy.GetPlaylists.end (res); - this.playlists_changed (); - } - catch (Error e) { - warning ("could not fetch playlists: %s", e.message); - this.playlists = null; - } - }); - } - else { - this.playlists = null; - this.playlists_changed (); - } - } - - void got_playlists_proxy (Object? obj, AsyncResult res) { - try { - this.playlists_proxy = Bus.get_proxy.end (res); - - var gproxy = this.proxy as DBusProxy; - gproxy.g_properties_changed.connect (this.playlists_proxy_properties_changed); - } - catch (Error e) { - warning ("unable to create mpris plalists proxy: %s", e.message); - return; - } - - Timeout.add (500, () => { this.fetch_playlists (); return false; } ); - } - - /* some players (e.g. Spotify) don't follow the spec closely and pass single strings in metadata fields - * where an array of string is expected */ - static string sanitize_metadata_value (Variant? v) { - if (v == null) - return ""; - else if (v.is_of_type (VariantType.STRING)) - return v.get_string (); - else if (v.is_of_type (VariantType.STRING_ARRAY)) - return string.joinv (",", v.get_strv ()); - - warn_if_reached (); - return ""; - } - - void proxy_properties_changed (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) { - if (changed_properties.lookup ("PlaybackStatus", "s", null)) { - this.state = this.proxy.PlaybackStatus; - } - - var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}")); - if (metadata != null) - this.update_current_track (metadata); - } - - void playlists_proxy_properties_changed (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) { - if (changed_properties.lookup ("PlaylistCount", "u", null)) - this.fetch_playlists (); - } - - void update_current_track (Variant metadata) { - if (metadata != null) { - this.current_track = new Track ( - sanitize_metadata_value (metadata.lookup_value ("xesam:artist", null)), - sanitize_metadata_value (metadata.lookup_value ("xesam:title", null)), - sanitize_metadata_value (metadata.lookup_value ("xesam:album", null)), - sanitize_metadata_value (metadata.lookup_value ("mpris:artUrl", null)) - ); - } - else { - this.current_track = null; - } + private void not_implemented () { + warning("Property not implemented"); } } -- cgit v1.2.3 From 7035341609179f1d646b3c48df79c15d4fa5a72f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 11:22:32 -0600 Subject: Setting up the build so we can have Vala mocks --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d548c66..7d58afb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,7 @@ set(HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/indicator-sound-service.h") set(SYMBOLS_PATH "${CMAKE_CURRENT_BINARY_DIR}/indicator-sound-service.def") +set(VAPI_PATH "${CMAKE_CURRENT_BINARY_DIR}/indicator-sound-service.vapi") vapi_gen(accounts-service LIBRARY @@ -93,6 +94,8 @@ vala_finish(indicator-sound-service ${HEADER_PATH} GENERATE_SYMBOLS ${SYMBOLS_PATH} + GENERATE_VAPI + ${VAPI_PATH} ) set_source_files_properties( -- cgit v1.2.3 From 18121baa3297e11eb064b4f0ad0c02ff5316ea95 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 15:03:26 -0600 Subject: Hmm, really should uncomment this. --- src/accounts-service-user.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 927a270..19ca774 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -101,7 +101,7 @@ public class AccountsServiceUser : Object { void new_proxy (GLib.Object? obj, AsyncResult res) { try { this.proxy = Bus.get_proxy.end (res); - //this.player = _player; + this.player = _player; } catch (Error e) { this.proxy = null; warning("Unable to get proxy to user sound settings: %s", e.message); -- cgit v1.2.3 From 6974a81bd969f97fb685ea021af4d1406fa13679 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Feb 2014 12:11:02 -0600 Subject: Make sure to timestamp our updates --- src/accounts-service-user.vala | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 19ca774..2062dc8 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -20,6 +20,7 @@ [DBus (name = "com.canonical.indicator.sound.AccountsService")] public interface AccountsServiceSoundSettings : Object { // properties + public abstract uint64 timestamp {owned get; set;} public abstract string player_name {owned get; set;} public abstract Variant player_icon {owned get; set;} public abstract bool running {owned get; set;} @@ -47,7 +48,9 @@ public class AccountsServiceUser : Object { if (this._player == null) { /* Clear it */ this.proxy.player_name = ""; + this.proxy.timestamp = 0; } else { + this.proxy.timestamp = GLib.get_monotonic_time(); this.proxy.player_name = this._player.name; if (this._player.icon == null) { var icon = new ThemedIcon.with_default_fallbacks ("application-default-icon"); -- cgit v1.2.3 From b8c9c3690d44e20e5cf2fb1322644d1bfdcf9084 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Feb 2014 12:19:12 -0600 Subject: Keep our timestamp up-to-date if we have a player --- src/accounts-service-user.vala | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 2062dc8..47189a5 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -35,6 +35,7 @@ public class AccountsServiceUser : Object { Act.UserManager accounts_manager = Act.UserManager.get_default(); Act.User? user = null; AccountsServiceSoundSettings? proxy = null; + uint timer = 0; MediaPlayer? _player = null; public MediaPlayer? player { @@ -45,6 +46,12 @@ public class AccountsServiceUser : Object { if (this.proxy == null) return; + /* Always reset the timer */ + if (this.timer != 0) { + GLib.Source.remove(this.timer); + this.timer = 0; + } + if (this._player == null) { /* Clear it */ this.proxy.player_name = ""; @@ -73,6 +80,11 @@ public class AccountsServiceUser : Object { this.proxy.album = ""; this.proxy.art_url = ""; } + + this.timer = GLib.Timeout.add_seconds(5 * 60, () => { + this.proxy.timestamp = GLib.get_monotonic_time(); + return true; + }); } } get { -- cgit v1.2.3 From b00962daf23fe43c7409dbcc735b19d7f74e7241 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Feb 2014 15:39:32 -0600 Subject: Split out the sound settings interface --- src/CMakeLists.txt | 4 ++++ src/accounts-service-sound-settings.vala | 33 ++++++++++++++++++++++++++++++++ src/accounts-service-user.vala | 14 -------------- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 src/accounts-service-sound-settings.vala (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7d58afb..280e89a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,6 +83,10 @@ vala_add(indicator-sound-service DEPENDS media-player mpris2-interfaces + accounts-service-sound-settings +) +vala_add(indicator-sound-service + accounts-service-sound-settings.vala ) vala_finish(indicator-sound-service diff --git a/src/accounts-service-sound-settings.vala b/src/accounts-service-sound-settings.vala new file mode 100644 index 0000000..7e27bd5 --- /dev/null +++ b/src/accounts-service-sound-settings.vala @@ -0,0 +1,33 @@ +/* + * Copyright 2014 © Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: + * Ted Gould + */ + +[DBus (name = "com.canonical.indicator.sound.AccountsService")] +public interface AccountsServiceSoundSettings : Object { + // properties + public abstract uint64 timestamp {owned get; set;} + public abstract string player_name {owned get; set;} + public abstract Variant player_icon {owned get; set;} + public abstract bool running {owned get; set;} + public abstract string state {owned get; set;} + public abstract string title {owned get; set;} + public abstract string artist {owned get; set;} + public abstract string album {owned get; set;} + public abstract string art_url {owned get; set;} +} + diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 47189a5..03aeb25 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -17,20 +17,6 @@ * Ted Gould */ -[DBus (name = "com.canonical.indicator.sound.AccountsService")] -public interface AccountsServiceSoundSettings : Object { - // properties - public abstract uint64 timestamp {owned get; set;} - public abstract string player_name {owned get; set;} - public abstract Variant player_icon {owned get; set;} - public abstract bool running {owned get; set;} - public abstract string state {owned get; set;} - public abstract string title {owned get; set;} - public abstract string artist {owned get; set;} - public abstract string album {owned get; set;} - public abstract string art_url {owned get; set;} -} - public class AccountsServiceUser : Object { Act.UserManager accounts_manager = Act.UserManager.get_default(); Act.User? user = null; -- cgit v1.2.3 From c5dd9403344fdab2e8db6dd794f56a679d063bf9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Feb 2014 15:38:11 -0600 Subject: Debug messages --- src/accounts-service-user.vala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 03aeb25..f021764 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -27,10 +27,13 @@ public class AccountsServiceUser : Object { public MediaPlayer? player { set { this._player = value; + debug("New player: %s", this._player != null ? this._player.name : "Cleared"); /* No proxy, no settings to set */ - if (this.proxy == null) + if (this.proxy == null) { + debug("Nothing written to Accounts Service, waiting on proxy"); return; + } /* Always reset the timer */ if (this.timer != 0) { @@ -68,6 +71,7 @@ public class AccountsServiceUser : Object { } this.timer = GLib.Timeout.add_seconds(5 * 60, () => { + debug("Writing timestamp"); this.proxy.timestamp = GLib.get_monotonic_time(); return true; }); -- cgit v1.2.3 From 006c044b3063c905a5c7aa8c31e91a4545acedae Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 11:35:45 -0500 Subject: Connect to the setting for exporting to the greeter to the creation of the accounts service user --- src/service.vala | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 6835896..7f4982f 100644 --- a/src/service.vala +++ b/src/service.vala @@ -46,9 +46,9 @@ public class IndicatorSound.Service: Object { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); }); - if (GLib.Environment.get_user_name() != "lightdm") { - accounts_service = new AccountsServiceUser(); - } + /* Setup handling for the greeter-export setting */ + this.settings.changed["greeter-export"].connect( () => this.build_accountsservice() ); + build_accountsservice(); this.sync_preferred_players (); this.settings.changed["interested-media-players"].connect ( () => { @@ -66,6 +66,22 @@ public class IndicatorSound.Service: Object { sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET); } + void build_accountsservice () { + this.accounts_service = null; + + /* If we're not exporting, don't build anything */ + if (!this.settings.get_boolean("greeter-export")) { + return; + } + + /* If we're on the greeter, don't export */ + if (GLib.Environment.get_user_name() == "lightdm") { + return; + } + + this.accounts_service = new AccountsServiceUser(); + } + public int run () { if (this.loop != null) { warning ("service is already running"); -- cgit v1.2.3 From e4bb3237e72b10941b22beac5c2c0a630f6666c5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 15:27:17 -0500 Subject: Make sure to update the player if needed --- src/service.vala | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index d94aa18..8863a16 100644 --- a/src/service.vala +++ b/src/service.vala @@ -80,6 +80,8 @@ public class IndicatorSound.Service: Object { } this.accounts_service = new AccountsServiceUser(); + + this.eventually_update_player_actions(); } public int run () { -- cgit v1.2.3 From 6be3d4e79f6121a56ae458c18af010768d73a2dc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 15:28:59 -0500 Subject: Clear everything --- src/accounts-service-user.vala | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index f021764..8797fb9 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -45,6 +45,13 @@ public class AccountsServiceUser : Object { /* Clear it */ this.proxy.player_name = ""; this.proxy.timestamp = 0; + this.proxy.title = ""; + this.proxy.artist = ""; + this.proxy.album = ""; + this.proxy.art_url = ""; + + var icon = new ThemedIcon.with_default_fallbacks ("application-default-icon"); + this.proxy.player_icon = icon.serialize(); } else { this.proxy.timestamp = GLib.get_monotonic_time(); this.proxy.player_name = this._player.name; -- cgit v1.2.3 From cdfa2afeb95b1067bde7412b6cee744a1ab0e0b9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 15:40:39 -0500 Subject: Debug messages --- src/accounts-service-user.vala | 2 ++ src/service.vala | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 8797fb9..77dc9d4 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -42,6 +42,8 @@ public class AccountsServiceUser : Object { } if (this._player == null) { + debug("Clearing player data in accounts service"); + /* Clear it */ this.proxy.player_name = ""; this.proxy.timestamp = 0; diff --git a/src/service.vala b/src/service.vala index 8863a16..de03296 100644 --- a/src/service.vala +++ b/src/service.vala @@ -71,11 +71,13 @@ public class IndicatorSound.Service: Object { /* If we're not exporting, don't build anything */ if (!this.settings.get_boolean("greeter-export")) { + debug("Accounts service export disabled due to user setting"); return; } /* If we're on the greeter, don't export */ if (GLib.Environment.get_user_name() == "lightdm") { + debug("Accounts service export disabled due to being used on the greeter"); return; } -- cgit v1.2.3 From 61d3328c1a41b3704db9e96c8f9a27b42e649aca Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 15:48:03 -0500 Subject: If the user is already loaded don't wait on it. --- src/accounts-service-user.vala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 77dc9d4..e18e20f 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -93,11 +93,16 @@ public class AccountsServiceUser : Object { public AccountsServiceUser () { user = accounts_manager.get_user(GLib.Environment.get_user_name()); - user.notify["is-loaded"].connect(() => { - debug("User loaded"); + user.notify["is-loaded"].connect(() => user_loaded_changed()); + user_loaded_changed(); + } - this.proxy = null; + void user_loaded_changed () { + debug("User loaded changed"); + this.proxy = null; + + if (this.user.is_loaded) { Bus.get_proxy.begin ( BusType.SYSTEM, "org.freedesktop.Accounts", @@ -105,7 +110,7 @@ public class AccountsServiceUser : Object { DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, new_proxy); - }); + } } ~AccountsServiceUser () { -- cgit v1.2.3 From 6ebc8b959ae45538e04d6831c94779b5c0c3d58e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 15:58:44 -0500 Subject: Backport the timer patch --- src/accounts-service-user.vala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index e18e20f..92c972d 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -115,6 +115,11 @@ public class AccountsServiceUser : Object { ~AccountsServiceUser () { this.player = null; + + if (this.timer != 0) { + GLib.Source.remove(this.timer); + this.timer = 0; + } } void new_proxy (GLib.Object? obj, AsyncResult res) { -- cgit v1.2.3 From f444eecaec57ab4966f2ebcfce0aefc0f8fbb6ba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 16:13:14 -0500 Subject: Debug message --- src/accounts-service-user.vala | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/accounts-service-user.vala b/src/accounts-service-user.vala index 92c972d..c29842a 100644 --- a/src/accounts-service-user.vala +++ b/src/accounts-service-user.vala @@ -114,6 +114,7 @@ public class AccountsServiceUser : Object { } ~AccountsServiceUser () { + debug("Account Service Object Finalizing"); this.player = null; if (this.timer != 0) { -- cgit v1.2.3 From 9d458fd02cc5180b9728186690026fd296edd9d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 17:06:07 -0500 Subject: Clear the player to ensure we don't get into a ref loop --- src/service.vala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index de03296..df33a62 100644 --- a/src/service.vala +++ b/src/service.vala @@ -67,6 +67,11 @@ public class IndicatorSound.Service: Object { } void build_accountsservice () { + /* NOTE: This is a bit of a hack to ensure that accounts service doesn't + continue to export the player by keeping a ref in the timer */ + if (this.accounts_service != null) + this.accounts_service.player = null; + this.accounts_service = null; /* If we're not exporting, don't build anything */ -- cgit v1.2.3 From c04df47dc6e092e843532c602d367ef315a5d79d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 17:07:27 -0500 Subject: Handle sigterm --- src/service.vala | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index df33a62..c8a57ac 100644 --- a/src/service.vala +++ b/src/service.vala @@ -101,6 +101,13 @@ public class IndicatorSound.Service: Object { this.bus_acquired, null, this.name_lost); this.loop = new MainLoop (null, false); + + GLib.Unix.signal_add(GLib.ProcessSignal.TERM, () => { + debug("SIGTERM recieved, stopping our mainloop"); + this.loop.quit(); + return false; + }); + this.loop.run (); return 0; -- cgit v1.2.3 From 0ef1cba5e195c4d92b7dd5753cb88f072aa9f297 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Mar 2014 17:13:05 -0500 Subject: Make sure to clear the player on exit --- src/service.vala | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index c8a57ac..8b83082 100644 --- a/src/service.vala +++ b/src/service.vala @@ -110,6 +110,10 @@ public class IndicatorSound.Service: Object { this.loop.run (); + /* Ensure we clear the player right after the mainloop quits */ + if (this.accounts_service != null) + this.accounts_service.player = null; + return 0; } -- cgit v1.2.3 From 0f18af8fd8c22b756436a5d7ff8c93e6d9a489a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Mar 2014 14:26:43 -0500 Subject: Move all the clearing of the player into one place --- src/service.vala | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 8b83082..bfd4115 100644 --- a/src/service.vala +++ b/src/service.vala @@ -67,11 +67,7 @@ public class IndicatorSound.Service: Object { } void build_accountsservice () { - /* NOTE: This is a bit of a hack to ensure that accounts service doesn't - continue to export the player by keeping a ref in the timer */ - if (this.accounts_service != null) - this.accounts_service.player = null; - + clear_acts_player(); this.accounts_service = null; /* If we're not exporting, don't build anything */ @@ -91,6 +87,13 @@ public class IndicatorSound.Service: Object { this.eventually_update_player_actions(); } + void clear_acts_player () { + /* NOTE: This is a bit of a hack to ensure that accounts service doesn't + continue to export the player by keeping a ref in the timer */ + if (this.accounts_service != null) + this.accounts_service.player = null; + } + public int run () { if (this.loop != null) { warning ("service is already running"); @@ -110,9 +113,7 @@ public class IndicatorSound.Service: Object { this.loop.run (); - /* Ensure we clear the player right after the mainloop quits */ - if (this.accounts_service != null) - this.accounts_service.player = null; + clear_acts_player(); return 0; } @@ -400,9 +401,8 @@ public class IndicatorSound.Service: Object { } } - if (clear_accounts_player && accounts_service != null) { - accounts_service.player = null; - } + if (clear_accounts_player) + clear_acts_player(); this.player_action_update_id = 0; return false; -- cgit v1.2.3 From 929d65e2b0df330cc3995b9ea1c6ba36732407b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Mar 2014 14:30:09 -0500 Subject: Remove sound blocked timer when the service is shutdown --- src/service.vala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index bfd4115..3bda52f 100644 --- a/src/service.vala +++ b/src/service.vala @@ -66,6 +66,11 @@ public class IndicatorSound.Service: Object { sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET); } + ~Service() { + if (this.sound_was_blocked_timeout_id > 0) + Source.remove (this.sound_was_blocked_timeout_id); + } + void build_accountsservice () { clear_acts_player(); this.accounts_service = null; -- cgit v1.2.3 From aee881c058971adcbe676d0d24d4924a0f38ef67 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Mar 2014 14:31:40 -0500 Subject: Make sure to clear values after removing the source --- src/service.vala | 4 +++- src/volume-control.vala | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 3bda52f..f6c5f01 100644 --- a/src/service.vala +++ b/src/service.vala @@ -67,8 +67,10 @@ public class IndicatorSound.Service: Object { } ~Service() { - if (this.sound_was_blocked_timeout_id > 0) + if (this.sound_was_blocked_timeout_id > 0) { Source.remove (this.sound_was_blocked_timeout_id); + this.sound_was_blocked_timeout_id = 0; + } } void build_accountsservice () { diff --git a/src/volume-control.vala b/src/volume-control.vala index 8f21b60..03cac0b 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -56,6 +56,7 @@ public class VolumeControl : Object { if (_reconnect_timer != 0) { Source.remove (_reconnect_timer); + _reconnect_timer = 0; } } -- cgit v1.2.3