From 4fc7a4e4d0346e1aad32057536301620e138bf30 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 12:34:41 -0600 Subject: add logic to call sound_play_file() when the low battery notification is shown --- src/notifier.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 123ee6f..47690ca 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -17,10 +17,16 @@ * Charles Kerr */ +#include "datafiles.h" #include "dbus-battery.h" #include "dbus-shared.h" #include "notifier.h" #include "utils.h" +#include "sound.h" + +#ifdef HAS_URLDISPATCHER +# include +#endif #include @@ -129,6 +135,29 @@ get_battery_power_level (IndicatorPowerDevice * battery) return ret; } +/*** +**** Sounds +***/ + +static void +play_low_battery_sound (void) +{ + const gchar * key; + gchar * filename; + + key = "Low battery.ogg"; + filename = datafile_find(DATAFILE_TYPE_SOUND, key); + if (filename != NULL) + { + sound_play_file(filename); + g_free(filename); + } + else + { + g_warning("Unable to find '%s' in XDG data dirs", key); + } +} + /*** **** Notifications ***/ @@ -299,6 +328,7 @@ on_battery_property_changed (IndicatorPowerNotifier * self) ((new_power_level != POWER_LEVEL_OK) && new_discharging && !old_discharging)) { notification_show (self); + play_low_battery_sound(); } else if (!new_discharging || (new_power_level == POWER_LEVEL_OK)) { -- cgit v1.2.3 From 2b939453598cc1fd8f1c40e5d6cbfd63cb852fb4 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 13:53:48 -0600 Subject: use gstreamer to play the sound --- src/notifier.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 47690ca..63e7c89 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -149,7 +149,9 @@ play_low_battery_sound (void) filename = datafile_find(DATAFILE_TYPE_SOUND, key); if (filename != NULL) { - sound_play_file(filename); + gchar * uri = g_filename_to_uri(filename, NULL, NULL); + sound_play_uri(uri); + g_free(uri); g_free(filename); } else -- cgit v1.2.3 From a8fd3f49bf6509bd4545aec3292d2fc022d847ca Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 15:58:55 -0600 Subject: make a SoundPlayer interface so we can mock it in the tests this requires an annoying amount of scaffolding: 1. implement gst and mock classes to implement the SoundPlayer interface 2. modify notifier to take a SoundPlayer argument in its ctor 3. modify service to take a Notifier argument in its ctor instead of instantiating it on its own 4. change main to update the startup steps for player/notifier/service --- src/notifier.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 9 deletions(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 63e7c89..b50f48c 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -22,10 +22,10 @@ #include "dbus-shared.h" #include "notifier.h" #include "utils.h" -#include "sound.h" +#include "sound-player.h" #ifdef HAS_URLDISPATCHER -# include +#include #endif #include @@ -51,10 +51,12 @@ enum { PROP_0, PROP_BATTERY, + PROP_SOUND_PLAYER, LAST_PROP }; #define PROP_BATTERY_NAME "battery" +#define PROP_SOUND_PLAYER_NAME "sound-player" static GParamSpec * properties[LAST_PROP]; @@ -82,6 +84,8 @@ typedef struct gboolean caps_queried; gboolean actions_supported; + + IndicatorPowerSoundPlayer * sound_player; } IndicatorPowerNotifierPrivate; @@ -140,17 +144,19 @@ get_battery_power_level (IndicatorPowerDevice * battery) ***/ static void -play_low_battery_sound (void) +play_low_battery_sound (IndicatorPowerNotifier * self) { - const gchar * key; + const gchar * const key = "Low battery.ogg"; gchar * filename; + priv_t * const p = get_priv(self); + + g_return_if_fail (p->sound_player != NULL); - key = "Low battery.ogg"; filename = datafile_find(DATAFILE_TYPE_SOUND, key); if (filename != NULL) { gchar * uri = g_filename_to_uri(filename, NULL, NULL); - sound_play_uri(uri); + indicator_power_sound_player_play_uri (p->sound_player, uri); g_free(uri); g_free(filename); } @@ -330,7 +336,7 @@ on_battery_property_changed (IndicatorPowerNotifier * self) ((new_power_level != POWER_LEVEL_OK) && new_discharging && !old_discharging)) { notification_show (self); - play_low_battery_sound(); + play_low_battery_sound (self); } else if (!new_discharging || (new_power_level == POWER_LEVEL_OK)) { @@ -361,6 +367,10 @@ my_get_property (GObject * o, g_value_set_object (value, p->battery); break; + case PROP_SOUND_PLAYER: + g_value_set_object (value, p->sound_player); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); } @@ -380,6 +390,10 @@ my_set_property (GObject * o, indicator_power_notifier_set_battery (self, g_value_get_object(value)); break; + case PROP_SOUND_PLAYER: + indicator_power_notifier_set_sound_player (self, g_value_get_object(value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); } @@ -446,6 +460,13 @@ indicator_power_notifier_class_init (IndicatorPowerNotifierClass * klass) G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + properties[PROP_SOUND_PLAYER] = g_param_spec_object ( + PROP_SOUND_PLAYER_NAME, + "Sound Player", + "The current battery", + G_TYPE_OBJECT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, LAST_PROP, properties); } @@ -454,9 +475,11 @@ indicator_power_notifier_class_init (IndicatorPowerNotifierClass * klass) ***/ IndicatorPowerNotifier * -indicator_power_notifier_new (void) +indicator_power_notifier_new (IndicatorPowerSoundPlayer * sound_player) { - GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, NULL); + GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, + PROP_SOUND_PLAYER_NAME, sound_player, + NULL); return INDICATOR_POWER_NOTIFIER (o); } @@ -495,6 +518,26 @@ indicator_power_notifier_set_battery (IndicatorPowerNotifier * self, } } +void +indicator_power_notifier_set_sound_player (IndicatorPowerNotifier * self, + IndicatorPowerSoundPlayer * sound_player) +{ + priv_t * p; + + g_return_if_fail(INDICATOR_IS_POWER_NOTIFIER(self)); + g_return_if_fail((sound_player == NULL) || INDICATOR_IS_POWER_SOUND_PLAYER(sound_player)); + + p = get_priv (self); + + if (p->sound_player == sound_player) + return; + + g_clear_object(&p->sound_player); + + if (sound_player != NULL) + p->sound_player = g_object_ref(sound_player); +} + void indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, GDBusConnection * bus) -- cgit v1.2.3 From bdc03e1cddb8811651f22e0bb423bf3385cbc793 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 16:12:16 -0600 Subject: update copyright years on changed/new files --- src/notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index b50f48c..0907a14 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -1,5 +1,5 @@ /* - * Copyright 2014 Canonical Ltd. + * Copyright 2014-2016 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published -- cgit v1.2.3 From 46efcd909dc04f6474f275071aadf41e7547f6d8 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 16:17:52 -0600 Subject: in Notifier's destructor, unref its SoundPlayer field --- src/notifier.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 0907a14..d5e8b5d 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -406,6 +406,7 @@ my_dispose (GObject * o) priv_t * const p = get_priv (self); indicator_power_notifier_set_bus (self, NULL); + indicator_power_notifier_set_sound_player (self, NULL); notification_clear (self); indicator_power_notifier_set_battery (self, NULL); g_clear_object (&p->dbus_battery); -- cgit v1.2.3 From 460f1464709a4c5e2c1594045961be9108ae2afd Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 19:37:51 -0600 Subject: use a symbolic constant for the low battery sound's filename --- src/notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index d5e8b5d..7d81f3a 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -146,7 +146,7 @@ get_battery_power_level (IndicatorPowerDevice * battery) static void play_low_battery_sound (IndicatorPowerNotifier * self) { - const gchar * const key = "Low battery.ogg"; + const gchar * const key = LOW_BATTERY_SOUND; gchar * filename; priv_t * const p = get_priv(self); -- cgit v1.2.3 From 97130ad08300c3ec6ab2165ff7506cd7f25af0d6 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Fri, 1 Jan 2016 20:08:05 -0600 Subject: honor com.ubuntu.touch.AccountsService.Sound.SilentMode --- src/notifier.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 7d81f3a..ad7efb0 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -18,6 +18,7 @@ */ #include "datafiles.h" +#include "dbus-accounts-sound.h" #include "dbus-battery.h" #include "dbus-shared.h" #include "notifier.h" @@ -86,6 +87,9 @@ typedef struct gboolean actions_supported; IndicatorPowerSoundPlayer * sound_player; + + GCancellable * cancellable; + DbusAccountsServiceSound * accounts_service_sound_proxy; } IndicatorPowerNotifierPrivate; @@ -143,6 +147,40 @@ get_battery_power_level (IndicatorPowerDevice * battery) **** Sounds ***/ +static void +on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, + GAsyncResult * res, + gpointer gself) +{ + GError * error; + DbusAccountsServiceSound * proxy; + + error = NULL; + proxy = dbus_accounts_service_sound_proxy_new_for_bus_finish (res, &error); + if (error != NULL) + { + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); + + g_clear_error(&error); + } + else + { + IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(gself); + priv_t * const p = get_priv (self); + p->accounts_service_sound_proxy = proxy; + } +} + +static gboolean +silent_mode (IndicatorPowerNotifier * self) +{ + priv_t * const p = get_priv (self); + + return (p->accounts_service_sound_proxy != NULL) + && (dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy)); +} + static void play_low_battery_sound (IndicatorPowerNotifier * self) { @@ -150,8 +188,13 @@ play_low_battery_sound (IndicatorPowerNotifier * self) gchar * filename; priv_t * const p = get_priv(self); + /* can't play? */ g_return_if_fail (p->sound_player != NULL); + /* won't play? */ + if (silent_mode(self)) + return; + filename = datafile_find(DATAFILE_TYPE_SOUND, key); if (filename != NULL) { @@ -405,11 +448,18 @@ my_dispose (GObject * o) IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(o); priv_t * const p = get_priv (self); + if (p->cancellable != NULL) + { + g_cancellable_cancel(p->cancellable); + g_clear_object(&p->cancellable); + } + indicator_power_notifier_set_bus (self, NULL); indicator_power_notifier_set_sound_player (self, NULL); notification_clear (self); indicator_power_notifier_set_battery (self, NULL); g_clear_object (&p->dbus_battery); + g_clear_object (&p->accounts_service_sound_proxy); G_OBJECT_CLASS (indicator_power_notifier_parent_class)->dispose (o); } @@ -428,7 +478,6 @@ my_finalize (GObject * o G_GNUC_UNUSED) **** Instantiation ***/ - static void indicator_power_notifier_init (IndicatorPowerNotifier * self) { @@ -440,8 +489,21 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) p->power_level = POWER_LEVEL_OK; + p->cancellable = g_cancellable_new(); + if (!instance_count++ && !notify_init("ayatana-indicator-power-service")) g_critical("Unable to initialize libnotify! Notifications might not be shown."); + + gchar* object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); + dbus_accounts_service_sound_proxy_new_for_bus( + G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, + "org.freedesktop.Accounts", + object_path, + p->cancellable, + on_sound_proxy_ready, + self); + g_clear_pointer(&object_path, g_free); } static void -- cgit v1.2.3 From 1182c7fb79942c14f2a713063182778e6af94cd1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Jan 2016 09:38:01 -0600 Subject: add build-dep to accountsservice-ubuntu-schemas instead of bundling com.ubuntu.touch.AccountsService.Sound.xml into our source tree --- src/notifier.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index ad7efb0..487f889 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -18,7 +18,11 @@ */ #include "datafiles.h" + +#ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS #include "dbus-accounts-sound.h" +#endif + #include "dbus-battery.h" #include "dbus-shared.h" #include "notifier.h" @@ -89,7 +93,9 @@ typedef struct IndicatorPowerSoundPlayer * sound_player; GCancellable * cancellable; + #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS DbusAccountsServiceSound * accounts_service_sound_proxy; + #endif } IndicatorPowerNotifierPrivate; @@ -147,16 +153,18 @@ get_battery_power_level (IndicatorPowerDevice * battery) **** Sounds ***/ +#ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS static void on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, GAsyncResult * res, gpointer gself) { GError * error; - DbusAccountsServiceSound * proxy; - error = NULL; + + DbusAccountsServiceSound * proxy; proxy = dbus_accounts_service_sound_proxy_new_for_bus_finish (res, &error); + if (error != NULL) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -172,6 +180,7 @@ on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, } } + static gboolean silent_mode (IndicatorPowerNotifier * self) { @@ -180,6 +189,7 @@ silent_mode (IndicatorPowerNotifier * self) return (p->accounts_service_sound_proxy != NULL) && (dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy)); } +#endif static void play_low_battery_sound (IndicatorPowerNotifier * self) @@ -191,9 +201,11 @@ play_low_battery_sound (IndicatorPowerNotifier * self) /* can't play? */ g_return_if_fail (p->sound_player != NULL); + #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS /* won't play? */ if (silent_mode(self)) return; + #endif filename = datafile_find(DATAFILE_TYPE_SOUND, key); if (filename != NULL) @@ -459,7 +471,10 @@ my_dispose (GObject * o) notification_clear (self); indicator_power_notifier_set_battery (self, NULL); g_clear_object (&p->dbus_battery); + + #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS g_clear_object (&p->accounts_service_sound_proxy); + #endif G_OBJECT_CLASS (indicator_power_notifier_parent_class)->dispose (o); } @@ -467,7 +482,7 @@ my_dispose (GObject * o) static void my_finalize (GObject * o G_GNUC_UNUSED) { - /* FIXME: This is an awkward place to put this. + /* FIXME: This is an awkward place to put this. Ordinarily something like this would go in main(), but we need libnotify to clean itself up before shutting down the bus in the unit tests as well. */ if (!--instance_count) @@ -494,6 +509,7 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) if (!instance_count++ && !notify_init("ayatana-indicator-power-service")) g_critical("Unable to initialize libnotify! Notifications might not be shown."); + #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS gchar* object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); dbus_accounts_service_sound_proxy_new_for_bus( G_BUS_TYPE_SYSTEM, @@ -504,6 +520,7 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) on_sound_proxy_ready, self); g_clear_pointer(&object_path, g_free); + #endif } static void -- cgit v1.2.3 From afc091939635eb46f2947cfe1aaadcb408de2835 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Jan 2016 10:08:39 -0600 Subject: add a leak safeguard to accounts_service_sound_proxy --- src/notifier.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 487f889..696556a 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -176,6 +176,7 @@ on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, { IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(gself); priv_t * const p = get_priv (self); + g_clear_object (&p->accounts_service_sound_proxy); p->accounts_service_sound_proxy = proxy; } } -- cgit v1.2.3 From 27122e92856bbe4efcdfc4975b46a0c6dee67cb9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Jan 2016 10:10:25 -0600 Subject: assume we're in silent mode if we can't get an accounts-service proxy --- src/notifier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 696556a..4b7aede 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -187,8 +187,12 @@ silent_mode (IndicatorPowerNotifier * self) { priv_t * const p = get_priv (self); - return (p->accounts_service_sound_proxy != NULL) - && (dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy)); + /* if we don't have a proxy yet, assume we're in silent mode + as a "do no harm" level of response */ + if (p->accounts_service_sound_proxy == NULL) + return TRUE; + + return dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy); } #endif -- cgit v1.2.3 From 1d9e1e532b6e52c974a6889706e02a500290ea51 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Jan 2016 10:11:18 -0600 Subject: fix copy-paste typo --- src/notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 4b7aede..93ab461 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -548,7 +548,7 @@ indicator_power_notifier_class_init (IndicatorPowerNotifierClass * klass) properties[PROP_SOUND_PLAYER] = g_param_spec_object ( PROP_SOUND_PLAYER_NAME, "Sound Player", - "The current battery", + "The current sound player", G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); -- cgit v1.2.3 From d2e654d53f5dbe89cce2fe08a7e6dbcae4a6d835 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Jan 2016 12:52:04 -0600 Subject: don't disable the warning sound when AccountServices is completely unavailable --- src/notifier.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 93ab461..e6c511f 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -95,6 +95,7 @@ typedef struct GCancellable * cancellable; #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS DbusAccountsServiceSound * accounts_service_sound_proxy; + gboolean accounts_service_sound_proxy_pending; #endif } IndicatorPowerNotifierPrivate; @@ -168,7 +169,10 @@ on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, if (error != NULL) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); + { + get_priv(gself)->accounts_service_sound_proxy_pending = FALSE; + g_warning("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); + } g_clear_error(&error); } @@ -178,6 +182,7 @@ on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, priv_t * const p = get_priv (self); g_clear_object (&p->accounts_service_sound_proxy); p->accounts_service_sound_proxy = proxy; + p->accounts_service_sound_proxy_pending = FALSE; } } @@ -189,10 +194,11 @@ silent_mode (IndicatorPowerNotifier * self) /* if we don't have a proxy yet, assume we're in silent mode as a "do no harm" level of response */ - if (p->accounts_service_sound_proxy == NULL) + if (p->accounts_service_sound_proxy_pending) return TRUE; - return dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy); + return (p->accounts_service_sound_proxy != NULL) + && dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy); } #endif @@ -515,6 +521,7 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) g_critical("Unable to initialize libnotify! Notifications might not be shown."); #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS + p->accounts_service_sound_proxy_pending = TRUE; gchar* object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); dbus_accounts_service_sound_proxy_new_for_bus( G_BUS_TYPE_SYSTEM, -- cgit v1.2.3 From b9068926a006bfcae447d3d14ef9ef50af2388ee Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Jan 2016 14:25:56 -0600 Subject: demote a spurious warning to a debug message --- src/notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index e6c511f..b481fdf 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -171,7 +171,7 @@ on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED, if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { get_priv(gself)->accounts_service_sound_proxy_pending = FALSE; - g_warning("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); + g_debug("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message); } g_clear_error(&error); -- cgit v1.2.3 From f4d66118c3a845892b32495efec3d6473e17baca Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 10:53:07 -0600 Subject: for low power notifications, use libnotify's 'sound-file' property instead of indicator-power calling the sound player directly --- src/notifier.c | 94 +++++++++++----------------------------------------------- 1 file changed, 17 insertions(+), 77 deletions(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index b481fdf..00a00e5 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -27,7 +27,6 @@ #include "dbus-shared.h" #include "notifier.h" #include "utils.h" -#include "sound-player.h" #ifdef HAS_URLDISPATCHER #include @@ -56,12 +55,10 @@ enum { PROP_0, PROP_BATTERY, - PROP_SOUND_PLAYER, LAST_PROP }; #define PROP_BATTERY_NAME "battery" -#define PROP_SOUND_PLAYER_NAME "sound-player" static GParamSpec * properties[LAST_PROP]; @@ -90,8 +87,6 @@ typedef struct gboolean caps_queried; gboolean actions_supported; - IndicatorPowerSoundPlayer * sound_player; - GCancellable * cancellable; #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS DbusAccountsServiceSound * accounts_service_sound_proxy; @@ -202,36 +197,6 @@ silent_mode (IndicatorPowerNotifier * self) } #endif -static void -play_low_battery_sound (IndicatorPowerNotifier * self) -{ - const gchar * const key = LOW_BATTERY_SOUND; - gchar * filename; - priv_t * const p = get_priv(self); - - /* can't play? */ - g_return_if_fail (p->sound_player != NULL); - - #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS - /* won't play? */ - if (silent_mode(self)) - return; - #endif - - filename = datafile_find(DATAFILE_TYPE_SOUND, key); - if (filename != NULL) - { - gchar * uri = g_filename_to_uri(filename, NULL, NULL); - indicator_power_sound_player_play_uri (p->sound_player, uri); - g_free(uri); - g_free(filename); - } - else - { - g_warning("Unable to find '%s' in XDG data dirs", key); - } -} - /*** **** Notifications ***/ @@ -346,6 +311,21 @@ notification_show(IndicatorPowerNotifier * self) if (are_actions_supported(self)) { + if (!silent_mode(self)) + { + gchar* filename = datafile_find(DATAFILE_TYPE_SOUND, LOW_BATTERY_SOUND); + if (filename != NULL) + { + gchar * uri = g_filename_to_uri(filename, NULL, NULL); + notify_notification_set_hint(nn, "sound-file", g_variant_new_take_string(uri)); + g_clear_pointer(&filename, g_free); + } + else + { + g_warning("Unable to find '%s' in XDG data dirs", LOW_BATTERY_SOUND); + } + } + notify_notification_set_hint(nn, "x-canonical-snap-decisions", g_variant_new_string("true")); notify_notification_set_hint(nn, "x-canonical-non-shaped-icon", g_variant_new_string("true")); notify_notification_set_hint(nn, "x-canonical-private-affirmative-tint", g_variant_new_string("true")); @@ -402,7 +382,6 @@ on_battery_property_changed (IndicatorPowerNotifier * self) ((new_power_level != POWER_LEVEL_OK) && new_discharging && !old_discharging)) { notification_show (self); - play_low_battery_sound (self); } else if (!new_discharging || (new_power_level == POWER_LEVEL_OK)) { @@ -433,10 +412,6 @@ my_get_property (GObject * o, g_value_set_object (value, p->battery); break; - case PROP_SOUND_PLAYER: - g_value_set_object (value, p->sound_player); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); } @@ -456,10 +431,6 @@ my_set_property (GObject * o, indicator_power_notifier_set_battery (self, g_value_get_object(value)); break; - case PROP_SOUND_PLAYER: - indicator_power_notifier_set_sound_player (self, g_value_get_object(value)); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); } @@ -478,7 +449,6 @@ my_dispose (GObject * o) } indicator_power_notifier_set_bus (self, NULL); - indicator_power_notifier_set_sound_player (self, NULL); notification_clear (self); indicator_power_notifier_set_battery (self, NULL); g_clear_object (&p->dbus_battery); @@ -552,13 +522,6 @@ indicator_power_notifier_class_init (IndicatorPowerNotifierClass * klass) G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - properties[PROP_SOUND_PLAYER] = g_param_spec_object ( - PROP_SOUND_PLAYER_NAME, - "Sound Player", - "The current sound player", - G_TYPE_OBJECT, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, LAST_PROP, properties); } @@ -567,12 +530,9 @@ indicator_power_notifier_class_init (IndicatorPowerNotifierClass * klass) ***/ IndicatorPowerNotifier * -indicator_power_notifier_new (IndicatorPowerSoundPlayer * sound_player) +indicator_power_notifier_new (void) { - GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, - PROP_SOUND_PLAYER_NAME, sound_player, - NULL); - + GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, NULL); return INDICATOR_POWER_NOTIFIER (o); } @@ -610,26 +570,6 @@ indicator_power_notifier_set_battery (IndicatorPowerNotifier * self, } } -void -indicator_power_notifier_set_sound_player (IndicatorPowerNotifier * self, - IndicatorPowerSoundPlayer * sound_player) -{ - priv_t * p; - - g_return_if_fail(INDICATOR_IS_POWER_NOTIFIER(self)); - g_return_if_fail((sound_player == NULL) || INDICATOR_IS_POWER_SOUND_PLAYER(sound_player)); - - p = get_priv (self); - - if (p->sound_player == sound_player) - return; - - g_clear_object(&p->sound_player); - - if (sound_player != NULL) - p->sound_player = g_object_ref(sound_player); -} - void indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, GDBusConnection * bus) -- cgit v1.2.3 From 557e10a031b886dc670bdf5918c3984edbace5ac Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 12:24:34 -0600 Subject: remove dead code --- src/notifier.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index 00a00e5..da5c5d5 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -311,7 +311,9 @@ notification_show(IndicatorPowerNotifier * self) if (are_actions_supported(self)) { + #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS if (!silent_mode(self)) + #endif { gchar* filename = datafile_find(DATAFILE_TYPE_SOUND, LOW_BATTERY_SOUND); if (filename != NULL) -- cgit v1.2.3 From 39571b0e05c78627d233b2f77250de459d73f4a6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 16 May 2016 12:59:03 -0500 Subject: fix cmake warning of the test apps' dependency on the service library --- src/notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/notifier.c') diff --git a/src/notifier.c b/src/notifier.c index da5c5d5..d982ac2 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -489,7 +489,7 @@ indicator_power_notifier_init (IndicatorPowerNotifier * self) p->cancellable = g_cancellable_new(); - if (!instance_count++ && !notify_init("ayatana-indicator-power-service")) + if (!instance_count++ && !notify_init(SERVICE_EXEC)) g_critical("Unable to initialize libnotify! Notifications might not be shown."); #ifdef HAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS -- cgit v1.2.3