From 1711049123981c79400b06ccd46d4e010925e33b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 10 Feb 2014 09:51:57 -0600 Subject: CMake stuff to the ignore file --- .bzrignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.bzrignore b/.bzrignore index 166a1ca..d010156 100644 --- a/.bzrignore +++ b/.bzrignore @@ -13,3 +13,13 @@ /src/service.c /src/volume-control.c /src/freedesktop-interfaces.c + +# CMake Generated Files +CMakeFiles/ +Makefile +cmake_install.cmake +CMakeCache.txt +CTestTestfile.cmake +config.h + + -- cgit v1.2.3 From 9660d0b5c1cee59d7b34e989fc2da19b67167619 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 10 Feb 2014 11:54:07 -0600 Subject: Trying to put together all our account service pieces --- ....canonical.indicator.sound.AccountsService.pkla | 6 ++++ data/CMakeLists.txt | 32 ++++++++++++++++++++++ ...anonical.indicator.sound.AccountsService.policy | 23 ++++++++++++++++ ...m.canonical.indicator.sound.AccountsService.xml | 20 ++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 data/50-com.canonical.indicator.sound.AccountsService.pkla create mode 100644 data/com.canonical.indicator.sound.AccountsService.policy create mode 100644 data/com.canonical.indicator.sound.AccountsService.xml diff --git a/data/50-com.canonical.indicator.sound.AccountsService.pkla b/data/50-com.canonical.indicator.sound.AccountsService.pkla new file mode 100644 index 0000000..bbcca1e --- /dev/null +++ b/data/50-com.canonical.indicator.sound.AccountsService.pkla @@ -0,0 +1,6 @@ +[Allow LightDM to set Unity AccountsService fields] +Identity=unix-user:lightdm +Action=com.canonical.indicator.sound.AccountsService.ModifyAnyUser +ResultActive=yes +ResultInactive=yes +ResultAny=yes diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 565e652..9694a9e 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -61,3 +61,35 @@ install( ########################### add_schema ("com.canonical.indicator.sound.gschema.xml") + +########################### +# Accounts Service +########################### + + +set(POLKIT_LIB_DIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/polkit-1") +set(POLKIT_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/polkit-1") +set(DBUS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces") +set(ACCOUNTS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/accountsservice/interfaces") + +install(FILES com.canonical.indicator.sound.AccountsService.xml + DESTINATION "${DBUS_IFACE_DIR}" +) + +# Create accountsservice symlink for above dbus interface +install(CODE " + execute_process(COMMAND mkdir -p \"\$ENV{DESTDIR}${ACCOUNTS_IFACE_DIR}\") + execute_process(COMMAND ln -sf ../../dbus-1/interfaces/com.canonical.indicator.sound.AccountsService.xml \"\$ENV{DESTDIR}${ACCOUNTS_IFACE_DIR}\") +") + +install(FILES com.canonical.indicator.sound.AccountsService.policy +DESTINATION "${POLKIT_DATA_DIR}/actions" +) + +install(FILES 50-com.canonical.indicator.sound.AccountsService.pkla +DESTINATION "${POLKIT_LIB_DIR}/localauthority/10-vendor.d" +) + + + + diff --git a/data/com.canonical.indicator.sound.AccountsService.policy b/data/com.canonical.indicator.sound.AccountsService.policy new file mode 100644 index 0000000..4d0ee75 --- /dev/null +++ b/data/com.canonical.indicator.sound.AccountsService.policy @@ -0,0 +1,23 @@ + + + + + Set properties of own user + Authentication is required to set one's own indicator sound properties. + + yes + yes + yes + + + + + Set properties of any user + Authentication is required to set another user's indicator sound properties. + + no + no + no + + + diff --git a/data/com.canonical.indicator.sound.AccountsService.xml b/data/com.canonical.indicator.sound.AccountsService.xml new file mode 100644 index 0000000..bb73efd --- /dev/null +++ b/data/com.canonical.indicator.sound.AccountsService.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + -- cgit v1.2.3 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 --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 11 ++++++++++- src/service.vala | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecd2f12..87c0e3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,10 @@ pkg_check_modules( gee-1.0 gio-2.0>=${GIO_2_0_REQUIRED_VERSION} gio-unix-2.0 + gthread-2.0 libxml-2.0 libnotify + accountsservice ) include_directories(${SOUNDSERVICE_INCLUDE_DIRS}) 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(-) 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 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(-) 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(+) 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(-) 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 --- ...m.canonical.indicator.sound.AccountsService.xml | 23 +++++++++- src/accounts-service-user.vala | 53 ++++++++++++++++++---- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/data/com.canonical.indicator.sound.AccountsService.xml b/data/com.canonical.indicator.sound.AccountsService.xml index bb73efd..1651a43 100644 --- a/data/com.canonical.indicator.sound.AccountsService.xml +++ b/data/com.canonical.indicator.sound.AccountsService.xml @@ -12,8 +12,27 @@ - - + + + + + + + + + + + + + + + + + + + + + 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(-) 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 eca0a6a44fce6efe86905940c3ce2562e18d3502 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 20:00:36 -0600 Subject: Add dbustest library --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87c0e3c..8c8d69c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,12 @@ pkg_check_modules( ) include_directories(${SOUNDSERVICE_INCLUDE_DIRS}) +pkg_check_modules( + TEST REQUIRED + dbustest-1 +) +include_directories(${TEST_INCLUDE_DIRS}) + find_package(Vala 0.20) find_package(GObjectIntrospection 0.9.12) -- cgit v1.2.3 From 7da8553896b1967d44292e211e9573e2d2d18e74 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 20:27:19 -0600 Subject: Adding in an accounts service base test --- tests/CMakeLists.txt | 9 +++++ tests/accounts-service-user.cc | 85 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/accounts-service-user.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8e79fd0..e6a5f34 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,3 +20,12 @@ add_executable (name-watch-test name-watch-test.cc ${CMAKE_SOURCE_DIR}/src/bus-w target_link_libraries (name-watch-test gtest ${SOUNDSERVICE_LIBRARIES}) add_test(name-watch-test name-watch-test) +########################### +# Accounts Service User +########################### + +include_directories(${CMAKE_SOURCE_DIR}/src) +add_executable (accounts-service-user-test accounts-service-user.cc) +target_link_libraries (accounts-service-user-test gtest ${SOUNDSERVICE_LIBRARIES} ${TEST_LIBRARIES}) +add_test(accounts-service-user-test accounts-service-user-test) + diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc new file mode 100644 index 0000000..db79d14 --- /dev/null +++ b/tests/accounts-service-user.cc @@ -0,0 +1,85 @@ +/* + * 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 + */ + +#include +#include +#include + +extern "C" { +#include "indicator-sound-service.h" +} + +class AccountsServiceUserTest : public ::testing::Test +{ + + protected: + DbusTestService * service = NULL; + + GDBusConnection * session = NULL; + GDBusConnection * system = NULL; + + virtual void SetUp() { + service = dbus_test_service_new(NULL); + dbus_test_service_start_tasks(service); + + g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); + + session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); + g_dbus_connection_set_exit_on_close(session, FALSE); + g_object_add_weak_pointer(G_OBJECT(session), (gpointer *)&session); + + system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); + g_dbus_connection_set_exit_on_close(system, FALSE); + g_object_add_weak_pointer(G_OBJECT(system), (gpointer *)&system); + } + + virtual void TearDown() { + g_clear_object(&service); + + g_object_unref(session); + g_object_unref(system); + + unsigned int cleartry = 0; + while (session != NULL && system != NULL && cleartry < 100) { + loop(100); + cleartry++; + } + + ASSERT_EQ(nullptr, session); + ASSERT_EQ(nullptr, system); + } + + static gboolean timeout_cb (gpointer user_data) { + GMainLoop * loop = static_cast(user_data); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + void loop (unsigned int ms) { + GMainLoop * loop = g_main_loop_new(NULL, FALSE); + g_timeout_add(ms, timeout_cb, loop); + g_main_loop_run(loop); + g_main_loop_unref(loop); + } +}; + +TEST_F(AccountsServiceUserTest, BasicObject) { + + +} -- 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 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 3dceea54230f478ca188b4987ef352e13ea09f69 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 21:29:30 -0600 Subject: Allocating an object and working around libaccountsservice0 --- tests/CMakeLists.txt | 8 +++++++- tests/accounts-service-user.cc | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e6a5f34..b25b20a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,12 @@ add_test(name-watch-test name-watch-test) include_directories(${CMAKE_SOURCE_DIR}/src) add_executable (accounts-service-user-test accounts-service-user.cc) -target_link_libraries (accounts-service-user-test gtest ${SOUNDSERVICE_LIBRARIES} ${TEST_LIBRARIES}) +target_link_libraries ( + accounts-service-user-test + indicator-sound-service-lib + gtest + ${SOUNDSERVICE_LIBRARIES} + ${TEST_LIBRARIES} +) add_test(accounts-service-user-test accounts-service-user-test) diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index db79d14..ff1debc 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -20,6 +20,7 @@ #include #include #include +#include extern "C" { #include "indicator-sound-service.h" @@ -50,13 +51,20 @@ class AccountsServiceUserTest : public ::testing::Test } virtual void TearDown() { + /* These are the things that libaccountservice0 doesn't clean up :-( */ + g_object_unref(act_user_manager_get_default()); + g_object_unref(system); + g_object_unref(system); + g_object_unref(system); + /* End shitty untested library cleanup */ + g_clear_object(&service); g_object_unref(session); g_object_unref(system); unsigned int cleartry = 0; - while (session != NULL && system != NULL && cleartry < 100) { + while ((session != NULL || system != NULL) && cleartry < 100) { loop(100); cleartry++; } @@ -80,6 +88,7 @@ class AccountsServiceUserTest : public ::testing::Test }; TEST_F(AccountsServiceUserTest, BasicObject) { - - + AccountsServiceUser * srv = accounts_service_user_new(); + loop(50); + g_object_unref(srv); } -- cgit v1.2.3 From 073c7cefb2ae5aaae12e2251523732034e3b2f4b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Feb 2014 22:19:03 -0600 Subject: Drop a dbus mock on this problem --- tests/accounts-service-user.cc | 61 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index ff1debc..2a83ee5 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -31,12 +31,66 @@ class AccountsServiceUserTest : public ::testing::Test protected: DbusTestService * service = NULL; + DbusTestDbusMock * mock = NULL; GDBusConnection * session = NULL; GDBusConnection * system = NULL; virtual void SetUp() { service = dbus_test_service_new(NULL); + + mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts"); + + DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL); + + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "CacheUser", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, + "ret = dbus.ObjectPath('/user')\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "FindUserById", G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_OBJECT_PATH, + "ret = dbus.ObjectPath('/user')\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "FindUserByName", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, + "ret = dbus.ObjectPath('/user')\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "ListCachedUsers", NULL, G_VARIANT_TYPE_OBJECT_PATH_ARRAY, + "ret = [ dbus.ObjectPath('/user') ]\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "UncacheUser", G_VARIANT_TYPE_STRING, NULL, + "", NULL); + + DbusTestDbusMockObject * userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL); + dbus_test_dbus_mock_object_add_property(mock, userobj, + "UserName", G_VARIANT_TYPE_STRING, + g_variant_new_string(g_get_user_name()), NULL); + + DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "PlayerName", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "PlayerIcon", G_VARIANT_TYPE_VARIANT, + g_variant_new_variant(g_variant_new_string("")), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Running", G_VARIANT_TYPE_BOOLEAN, + g_variant_new_boolean(FALSE), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "State", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Title", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Artist", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Album", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "ArtUrl", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + + dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); dbus_test_service_start_tasks(service); g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); @@ -53,11 +107,12 @@ class AccountsServiceUserTest : public ::testing::Test virtual void TearDown() { /* These are the things that libaccountservice0 doesn't clean up :-( */ g_object_unref(act_user_manager_get_default()); - g_object_unref(system); - g_object_unref(system); - g_object_unref(system); + for (int i = 0; i < 11; i++) { + g_object_unref(system); + } /* End shitty untested library cleanup */ + g_clear_object(&mock); g_clear_object(&service); g_object_unref(session); -- 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 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 ++ tests/CMakeLists.txt | 71 ++++++++++++++++++++++++++++++++++++++++++++ tests/media-player-mock.vala | 51 +++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 tests/media-player-mock.vala 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( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b25b20a..09073b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,76 @@ add_library (gtest STATIC ${GTEST_SOURCE_DIR}/gtest_main.cc) target_link_libraries(gtest ${GTEST_LIBS}) +########################### +# Vala Mocks +########################### + +set(VALA_MOCKS_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/vala-mocks.h") +set(VALA_MOCKS_SYMBOLS_PATH "${CMAKE_CURRENT_BINARY_DIR}/vala-mocks.def") + +vala_init(vala-mocks + DEPENDS + indicator-sound-service-lib + PACKAGES + config + gio-2.0 + gio-unix-2.0 + libxml-2.0 + libpulse + libpulse-mainloop-glib + libnotify + accounts-service + indicator-sound-service + OPTIONS + --ccode + --thread + --vapidir=${CMAKE_BINARY_DIR}/src/ + --vapidir=${CMAKE_SOURCE_DIR}/vapi/ + --vapidir=. +) + +vala_add(vala-mocks + media-player-mock.vala +) + +vala_finish(vala-mocks + SOURCES + vala_mocks_VALA_SOURCES + OUTPUTS + vala_mocks_VALA_C + GENERATE_HEADER + ${VALA_MOCKS_HEADER_PATH} + GENERATE_SYMBOLS + ${VALA_MOCKS_SYMBOLS_PATH} +) + +set_source_files_properties( + ${vala_mocks_VALA_SOURCES} + PROPERTIES + HEADER_FILE_ONLY TRUE +) + +set( + VALA_MOCKS_SOURCES + ${vala_mocks_VALA_SOURCES} + ${vala_mocks_VALA_C} + ${VALA_MOCKS_SYMBOLS_PATH} +) + +add_definitions( + -Wno-unused-but-set-variable +) + +add_library( + vala-mocks-lib STATIC + ${VALA_MOCKS_SOURCES} +) + +target_link_libraries( + vala-mocks-lib + indicator-sound-service-lib +) + ########################### # Name Watch Test @@ -29,6 +99,7 @@ add_executable (accounts-service-user-test accounts-service-user.cc) target_link_libraries ( accounts-service-user-test indicator-sound-service-lib + vala-mocks-lib gtest ${SOUNDSERVICE_LIBRARIES} ${TEST_LIBRARIES} diff --git a/tests/media-player-mock.vala b/tests/media-player-mock.vala new file mode 100644 index 0000000..8a4a6cf --- /dev/null +++ b/tests/media-player-mock.vala @@ -0,0 +1,51 @@ +/* + * 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 MediaPlayerMock: MediaPlayer { + + public override void activate () { + debug("Mock activate"); + } + public override void play_pause () { + debug("Mock play_pause"); + } + public override void next () { + debug("Mock next"); + } + public override void previous () { + debug("Mock previous"); + } + + public override uint get_n_playlists() { + debug("Mock get_n_playlists"); + return 0; + } + public override string get_playlist_id (int index) { + debug("Mock get_playlist_id"); + return ""; + } + public override string get_playlist_name (int index) { + debug("Mock get_playlist_name"); + return ""; + } + public override void activate_playlist_by_name (string playlist) { + debug("Mock activate_playlist_by_name"); + } + +} -- cgit v1.2.3 From 691f7056cc888444b55ad1a6a6949926162cffe4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 13:39:53 -0600 Subject: Ensuring we can allocate the player, add it to an object, and woot! --- tests/accounts-service-user.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index 2a83ee5..e36686b 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -24,6 +24,7 @@ extern "C" { #include "indicator-sound-service.h" +#include "vala-mocks.h" } class AccountsServiceUserTest : public ::testing::Test @@ -107,7 +108,7 @@ class AccountsServiceUserTest : public ::testing::Test virtual void TearDown() { /* These are the things that libaccountservice0 doesn't clean up :-( */ g_object_unref(act_user_manager_get_default()); - for (int i = 0; i < 11; i++) { + for (int i = 0; i < 11 && system != NULL; i++) { g_object_unref(system); } /* End shitty untested library cleanup */ @@ -116,7 +117,8 @@ class AccountsServiceUserTest : public ::testing::Test g_clear_object(&service); g_object_unref(session); - g_object_unref(system); + if (system != NULL) + g_object_unref(system); unsigned int cleartry = 0; while ((session != NULL || system != NULL) && cleartry < 100) { @@ -147,3 +149,15 @@ TEST_F(AccountsServiceUserTest, BasicObject) { loop(50); g_object_unref(srv); } + +TEST_F(AccountsServiceUserTest, SetMediaPlayer) { + AccountsServiceUser * srv = accounts_service_user_new(); + MediaPlayerMock * media = media_player_mock_new(); + + accounts_service_user_set_player(srv, MEDIA_PLAYER(media)); + + loop(50); + + g_object_unref(media); + g_object_unref(srv); +} -- cgit v1.2.3 From f71a5f1208e38b670c2895cdd38b082a26210f75 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 13:54:59 -0600 Subject: Adding mock values to fill out mock media player --- tests/media-player-mock.vala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/media-player-mock.vala b/tests/media-player-mock.vala index 8a4a6cf..14028f5 100644 --- a/tests/media-player-mock.vala +++ b/tests/media-player-mock.vala @@ -19,6 +19,31 @@ public class MediaPlayerMock: MediaPlayer { + /* Superclass variables */ + public override string id { get { return mock_id; } } + public override string name { get { return mock_name; } } + public override string state { get { return mock_state; } set { this.mock_state = value; }} + public override Icon? icon { get { return mock_icon; } } + public override string dbus_name { get { return mock_dbus_name; } } + + public override bool is_running { get { return mock_is_running; } } + public override bool can_raise { get { return mock_can_raise; } } + + public override MediaPlayer.Track? current_track { get { return mock_current_track; } set { this.mock_current_track = value; } } + + /* Mock values */ + public string mock_id { get; set; } + public string mock_name { get; set; } + public string mock_state { get; set; } + public Icon? mock_icon { get; set; } + public string mock_dbus_name { get; set; } + + public bool mock_is_running { get; set; } + public bool mock_can_raise { get; set; } + + public MediaPlayer.Track? mock_current_track { get; set; } + + /* Virtual functions */ public override void activate () { debug("Mock activate"); } -- 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(-) 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 c2a9d0e2995ea7d32e0f3d82886ac34517694698 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 15:13:11 -0600 Subject: Get the player test put together --- tests/CMakeLists.txt | 9 +++- tests/accounts-service-user.cc | 107 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 09073b9..a703d24 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -104,5 +104,12 @@ target_link_libraries ( ${SOUNDSERVICE_LIBRARIES} ${TEST_LIBRARIES} ) -add_test(accounts-service-user-test accounts-service-user-test) +# Split tests to work around libaccountservice sucking +add_test(accounts-service-user-test-basic + accounts-service-user-test --gtest_filter=AccountsServiceUserTest.BasicObject +) + +add_test(accounts-service-user-test-player + accounts-service-user-test --gtest_filter=AccountsServiceUserTest.SetMediaPlayer +) diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index e36686b..65806e3 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -36,6 +36,7 @@ class AccountsServiceUserTest : public ::testing::Test GDBusConnection * session = NULL; GDBusConnection * system = NULL; + GDBusProxy * proxy = NULL; virtual void SetUp() { service = dbus_test_service_new(NULL); @@ -97,29 +98,36 @@ class AccountsServiceUserTest : public ::testing::Test g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); + ASSERT_NE(nullptr, session); g_dbus_connection_set_exit_on_close(session, FALSE); g_object_add_weak_pointer(G_OBJECT(session), (gpointer *)&session); system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); + ASSERT_NE(nullptr, system); g_dbus_connection_set_exit_on_close(system, FALSE); g_object_add_weak_pointer(G_OBJECT(system), (gpointer *)&system); + + proxy = g_dbus_proxy_new_sync(session, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.Accounts", + "/user", + "org.freedesktop.DBus.Properties", + NULL, NULL); + ASSERT_NE(nullptr, proxy); } virtual void TearDown() { - /* These are the things that libaccountservice0 doesn't clean up :-( */ - g_object_unref(act_user_manager_get_default()); - for (int i = 0; i < 11 && system != NULL; i++) { - g_object_unref(system); - } - /* End shitty untested library cleanup */ - + g_clear_object(&proxy); g_clear_object(&mock); g_clear_object(&service); g_object_unref(session); - if (system != NULL) - g_object_unref(system); + g_object_unref(system); + #if 0 + /* Accounts Service keeps a bunch of references around so we + have to split the tests and can't check this :-( */ unsigned int cleartry = 0; while ((session != NULL || system != NULL) && cleartry < 100) { loop(100); @@ -128,6 +136,7 @@ class AccountsServiceUserTest : public ::testing::Test ASSERT_EQ(nullptr, session); ASSERT_EQ(nullptr, system); + #endif } static gboolean timeout_cb (gpointer user_data) { @@ -142,6 +151,38 @@ class AccountsServiceUserTest : public ::testing::Test g_main_loop_run(loop); g_main_loop_unref(loop); } + + static int unref_idle (gpointer user_data) { + g_variant_unref(static_cast(user_data)); + return G_SOURCE_REMOVE; + } + + const gchar * get_property_string (const gchar * name) { + GVariant * propval = g_dbus_proxy_call_sync(proxy, + "Get", + g_variant_new("(ss)", "com.canonical.indicator.sound.AccountsService", name), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL + ); + + if (propval == nullptr) { + return nullptr; + } + + /* NOTE: This is a bit of a hack, basically if main gets + called the returned string becomes invalid. But it + makes the test much easier to read :-/ */ + g_idle_add(unref_idle, propval); + + const gchar * ret = NULL; + GVariant * child = g_variant_get_child_value(propval, 0); + GVariant * vstr = g_variant_get_variant(child); + ret = g_variant_get_string(vstr, NULL); + g_variant_unref(vstr); + g_variant_unref(child); + + return ret; + } }; TEST_F(AccountsServiceUserTest, BasicObject) { @@ -151,12 +192,56 @@ TEST_F(AccountsServiceUserTest, BasicObject) { } TEST_F(AccountsServiceUserTest, SetMediaPlayer) { + MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url"); + + MediaPlayerMock * media = MEDIA_PLAYER_MOCK( + g_object_new(TYPE_MEDIA_PLAYER_MOCK, + "mock-id", "player-id", + "mock-name", "Test Player", + "mock-state", "Playing", + "mock-is-running", TRUE, + "mock-can-raise", FALSE, + "mock-current-track", track, + NULL) + ); + g_clear_object(&track); + AccountsServiceUser * srv = accounts_service_user_new(); - MediaPlayerMock * media = media_player_mock_new(); accounts_service_user_set_player(srv, MEDIA_PLAYER(media)); - loop(50); + loop(500); + + /* Verify the values are on the other side of the bus */ + EXPECT_STREQ("Test Player", get_property_string("PlayerName")); + EXPECT_STREQ("Playing", get_property_string("State")); + EXPECT_STREQ("Title", get_property_string("Title")); + EXPECT_STREQ("Artist", get_property_string("Artist")); + EXPECT_STREQ("Album", get_property_string("Album")); + EXPECT_STREQ("http://art.url", get_property_string("ArtUrl")); + + /* Check changing the track info */ + track = media_player_track_new("Artist-ish", "Title-like", "Psuedo Album", "http://fake.art.url"); + media_player_mock_set_mock_current_track(media, track); + g_clear_object(&track); + accounts_service_user_set_player(srv, MEDIA_PLAYER(media)); + + loop(500); + + EXPECT_STREQ("Test Player", get_property_string("PlayerName")); + EXPECT_STREQ("Playing", get_property_string("State")); + EXPECT_STREQ("Title-like", get_property_string("Title")); + EXPECT_STREQ("Artist-ish", get_property_string("Artist")); + EXPECT_STREQ("Psuedo Album", get_property_string("Album")); + EXPECT_STREQ("http://fake.art.url", get_property_string("ArtUrl")); + + /* Check to ensure the state can be updated */ + media_player_set_state(MEDIA_PLAYER(media), "Paused"); + accounts_service_user_set_player(srv, MEDIA_PLAYER(media)); + + loop(500); + + EXPECT_STREQ("Paused", get_property_string("State")); g_object_unref(media); g_object_unref(srv); -- cgit v1.2.3 From bfb2375fbd1647c5be63ee67e91b099b3faac05d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 15:34:24 -0600 Subject: Grab the generated header --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a703d24..1556fc7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,6 +80,7 @@ target_link_libraries( indicator-sound-service-lib ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) ########################### # Name Watch Test -- cgit v1.2.3 From 3ddbdeeaab92406fc9fc67e5925368f53b45d592 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 15:38:35 -0600 Subject: Grabbing build deps for our new library friends --- debian/control | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debian/control b/debian/control index 55aae86..06acb09 100644 --- a/debian/control +++ b/debian/control @@ -6,10 +6,13 @@ XSBC-Original-Maintainer: Conor Curran Build-Depends: debhelper (>= 9.0), cmake, dbus, + dbus-test-runner, dh-translations, gnome-common, autotools-dev, valac (>= 0.20), + libaccountsservice-dev, + libdbustest1-dev, libglib2.0-dev (>= 2.22.3), libgtest-dev, liburl-dispatcher1-dev, -- cgit v1.2.3 From 89a949038a591fae3b55b2a7865a5d93057accf8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 16:17:32 -0600 Subject: Need the accounts service GIR file --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index 06acb09..eb0dad6 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,7 @@ Build-Depends: debhelper (>= 9.0), dbus, dbus-test-runner, dh-translations, + gir1.2-accountsservice-1.0, gnome-common, autotools-dev, valac (>= 0.20), -- cgit v1.2.3 From 3c019c7c7593ed3c7f1050b1499c53f590cc0e5e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 12 Feb 2014 17:03:33 -0600 Subject: Would have thought that was implied --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index eb0dad6..f9b535a 100644 --- a/debian/control +++ b/debian/control @@ -14,6 +14,7 @@ Build-Depends: debhelper (>= 9.0), valac (>= 0.20), libaccountsservice-dev, libdbustest1-dev, + libgirepository1.0-dev, libglib2.0-dev (>= 2.22.3), libgtest-dev, liburl-dispatcher1-dev, -- cgit v1.2.3 From 10757562302a8b757d10d3106513e440914a0a84 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Feb 2014 09:58:21 -0600 Subject: The mocker of choice --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index f9b535a..84d3727 100644 --- a/debian/control +++ b/debian/control @@ -23,6 +23,7 @@ Build-Depends: debhelper (>= 9.0), libnotify-dev, libgee-dev, libxml2-dev, + python3-dbusmock, Standards-Version: 3.9.4 Homepage: https://launchpad.net/indicator-sound # If you aren't a member of ~indicator-applet-developers but need to upload -- 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 --- data/com.canonical.indicator.sound.AccountsService.xml | 3 +++ src/accounts-service-user.vala | 3 +++ 2 files changed, 6 insertions(+) diff --git a/data/com.canonical.indicator.sound.AccountsService.xml b/data/com.canonical.indicator.sound.AccountsService.xml index 1651a43..fb7e96f 100644 --- a/data/com.canonical.indicator.sound.AccountsService.xml +++ b/data/com.canonical.indicator.sound.AccountsService.xml @@ -12,6 +12,9 @@ + + + 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(+) 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 bc01d6ceef3dbc5119a0ac7b2fba1583f62c3d48 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Feb 2014 13:00:34 -0600 Subject: Adding the timeout to the mock --- tests/accounts-service-user.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index 65806e3..a52b3a0 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -67,6 +67,9 @@ class AccountsServiceUserTest : public ::testing::Test g_variant_new_string(g_get_user_name()), NULL); DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Timeout", G_VARIANT_TYPE_UINT64, + g_variant_new_uint64(0), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "PlayerName", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); -- cgit v1.2.3 From 129467f4faccdfd852584bb26da4011d01955239 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Feb 2014 13:06:24 -0600 Subject: Can't watch hockey and type --- tests/accounts-service-user.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index a52b3a0..522bec9 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -68,7 +68,7 @@ class AccountsServiceUserTest : public ::testing::Test DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, - "Timeout", G_VARIANT_TYPE_UINT64, + "Timestamp", G_VARIANT_TYPE_UINT64, g_variant_new_uint64(0), NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "PlayerName", G_VARIANT_TYPE_STRING, -- 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 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(-) 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 69231381cb7656b551d860c441b8d9750f9f5bc2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Feb 2014 15:44:34 -0600 Subject: Set localstate dir --- debian/rules | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/debian/rules b/debian/rules index 9a276dc..3f1dfeb 100755 --- a/debian/rules +++ b/debian/rules @@ -5,3 +5,8 @@ export DPKG_GENSYMBOLS_CHECK_LEVEL=4 %: dh $@ --parallel --fail-missing --with translations +override_dh_auto_configure: + # Debian defines CMAKE_INSTALL_LOCALSTATEDIR as /usr/var, which is wrong. + # So until Debian bug 719148 is fixed, do it ourselves. + dh_auto_configure -- -DCMAKE_INSTALL_LOCALSTATEDIR="/var" + -- cgit v1.2.3 From 88dbefac5c013ed65619ed37b991f35535ef85ee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 3 Mar 2014 14:50:52 -0600 Subject: Put the accounts service mock into a class --- tests/accounts-service-mock.h | 90 ++++++++++++++++++++++++++++++++++++++++++ tests/accounts-service-user.cc | 60 +++------------------------- 2 files changed, 95 insertions(+), 55 deletions(-) create mode 100644 tests/accounts-service-mock.h diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h new file mode 100644 index 0000000..225d7b5 --- /dev/null +++ b/tests/accounts-service-mock.h @@ -0,0 +1,90 @@ +/* + * 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 + */ + +#include + +class AccountsServiceMock +{ + DbusTestDbusMock * mock = nullptr; + + public: + AccountsServiceMock () { + mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts"); + + DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL); + + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "CacheUser", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, + "ret = dbus.ObjectPath('/user')\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "FindUserById", G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_OBJECT_PATH, + "ret = dbus.ObjectPath('/user')\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "FindUserByName", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, + "ret = dbus.ObjectPath('/user')\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "ListCachedUsers", NULL, G_VARIANT_TYPE_OBJECT_PATH_ARRAY, + "ret = [ dbus.ObjectPath('/user') ]\n", NULL); + dbus_test_dbus_mock_object_add_method(mock, baseobj, + "UncacheUser", G_VARIANT_TYPE_STRING, NULL, + "", NULL); + + DbusTestDbusMockObject * userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL); + dbus_test_dbus_mock_object_add_property(mock, userobj, + "UserName", G_VARIANT_TYPE_STRING, + g_variant_new_string(g_get_user_name()), NULL); + + DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Timestamp", G_VARIANT_TYPE_UINT64, + g_variant_new_uint64(0), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "PlayerName", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "PlayerIcon", G_VARIANT_TYPE_VARIANT, + g_variant_new_variant(g_variant_new_string("")), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Running", G_VARIANT_TYPE_BOOLEAN, + g_variant_new_boolean(FALSE), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "State", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Title", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Artist", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "Album", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + dbus_test_dbus_mock_object_add_property(mock, soundobj, + "ArtUrl", G_VARIANT_TYPE_STRING, + g_variant_new_string(""), NULL); + } + + ~AccountsServiceMock () { + g_clear_object(&mock); + } + + operator DbusTestTask* () { + return DBUS_TEST_TASK(mock); + } +}; diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index 522bec9..b39b546 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -22,6 +22,8 @@ #include #include +#include "accounts-service-mock.h" + extern "C" { #include "indicator-sound-service.h" #include "vala-mocks.h" @@ -41,61 +43,9 @@ class AccountsServiceUserTest : public ::testing::Test virtual void SetUp() { service = dbus_test_service_new(NULL); - mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts"); - - DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL); - - dbus_test_dbus_mock_object_add_method(mock, baseobj, - "CacheUser", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, - "ret = dbus.ObjectPath('/user')\n", NULL); - dbus_test_dbus_mock_object_add_method(mock, baseobj, - "FindUserById", G_VARIANT_TYPE_INT64, G_VARIANT_TYPE_OBJECT_PATH, - "ret = dbus.ObjectPath('/user')\n", NULL); - dbus_test_dbus_mock_object_add_method(mock, baseobj, - "FindUserByName", G_VARIANT_TYPE_STRING, G_VARIANT_TYPE_OBJECT_PATH, - "ret = dbus.ObjectPath('/user')\n", NULL); - dbus_test_dbus_mock_object_add_method(mock, baseobj, - "ListCachedUsers", NULL, G_VARIANT_TYPE_OBJECT_PATH_ARRAY, - "ret = [ dbus.ObjectPath('/user') ]\n", NULL); - dbus_test_dbus_mock_object_add_method(mock, baseobj, - "UncacheUser", G_VARIANT_TYPE_STRING, NULL, - "", NULL); - - DbusTestDbusMockObject * userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL); - dbus_test_dbus_mock_object_add_property(mock, userobj, - "UserName", G_VARIANT_TYPE_STRING, - g_variant_new_string(g_get_user_name()), NULL); - - DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "Timestamp", G_VARIANT_TYPE_UINT64, - g_variant_new_uint64(0), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "PlayerName", G_VARIANT_TYPE_STRING, - g_variant_new_string(""), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "PlayerIcon", G_VARIANT_TYPE_VARIANT, - g_variant_new_variant(g_variant_new_string("")), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "Running", G_VARIANT_TYPE_BOOLEAN, - g_variant_new_boolean(FALSE), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "State", G_VARIANT_TYPE_STRING, - g_variant_new_string(""), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "Title", G_VARIANT_TYPE_STRING, - g_variant_new_string(""), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "Artist", G_VARIANT_TYPE_STRING, - g_variant_new_string(""), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "Album", G_VARIANT_TYPE_STRING, - g_variant_new_string(""), NULL); - dbus_test_dbus_mock_object_add_property(mock, soundobj, - "ArtUrl", G_VARIANT_TYPE_STRING, - g_variant_new_string(""), NULL); - - dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); + AccountsServiceMock service_mock; + + dbus_test_service_add_task(service, (DbusTestTask*)service_mock); dbus_test_service_start_tasks(service); g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); -- cgit v1.2.3 From 5857ca8b2f70630a298ac19aaf8a60668badbb53 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Mar 2014 23:19:09 -0600 Subject: Make sure we have a new dbus-test-runner --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index f026240..4278f7a 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ XSBC-Original-Maintainer: Conor Curran Build-Depends: debhelper (>= 9.0), cmake, dbus, - dbus-test-runner, + dbus-test-runner (>= 14.04.0+14.04.20140226), dh-translations, gir1.2-accountsservice-1.0, gnome-common, -- cgit v1.2.3 From bef0abe544ecbb9e020b7d9f99255acefa5073ed Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Mar 2014 16:00:43 -0500 Subject: Adding a setting for greeter exporting --- data/com.canonical.indicator.sound.gschema.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/data/com.canonical.indicator.sound.gschema.xml b/data/com.canonical.indicator.sound.gschema.xml index 102a1db..c34dfd6 100644 --- a/data/com.canonical.indicator.sound.gschema.xml +++ b/data/com.canonical.indicator.sound.gschema.xml @@ -48,5 +48,14 @@ Whether or not to show the sound indicator in the menu bar. + + true + Whether or not to export the currently playing song to the greeter. + + If enabled the sound indicator will export the current player and + song to the greeter so that it can be shown if the user is selected + and the sound menu is shown. + + -- 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(-) 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(+) 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(+) 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(+) 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(-) 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(+) 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(+) 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(+) 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(+) 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(+) 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(-) 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(+) 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(-) 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