diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/notifier.c | 94 | ||||
-rw-r--r-- | src/notifier.h | 6 | ||||
-rw-r--r-- | src/sound-player-gst.c | 173 | ||||
-rw-r--r-- | src/sound-player-gst.h | 70 | ||||
-rw-r--r-- | src/sound-player.c | 45 | ||||
-rw-r--r-- | src/sound-player.h | 72 |
8 files changed, 20 insertions, 450 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8eac086..a5e6c57 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,9 +19,7 @@ set(SERVICE_MANUAL_SOURCES notifier.c testing.c service.c - utils.c - sound-player.c - sound-player-gst.c) + utils.c) # generated sources include(GdbusCodegen) @@ -25,7 +25,6 @@ #include "device.h" #include "notifier.h" #include "service.h" -#include "sound-player-gst.h" #include "testing.h" /*** @@ -42,7 +41,6 @@ on_name_lost (gpointer instance G_GNUC_UNUSED, gpointer loop) int main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) { - IndicatorPowerSoundPlayer * sound_player; IndicatorPowerNotifier * notifier; IndicatorPowerService * service; IndicatorPowerTesting * testing; @@ -54,8 +52,7 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) textdomain (GETTEXT_PACKAGE); /* run */ - sound_player = indicator_power_sound_player_gst_new (); - notifier = indicator_power_notifier_new (sound_player); + notifier = indicator_power_notifier_new(); service = indicator_power_service_new(NULL, notifier); testing = indicator_power_testing_new (service); loop = g_main_loop_new (NULL, FALSE); @@ -68,6 +65,5 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED) g_clear_object (&testing); g_clear_object (&service); g_clear_object (¬ifier); - g_clear_object (&sound_player); return 0; } 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 <lomiri-url-dispatcher.h> @@ -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); } @@ -611,26 +571,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) { diff --git a/src/notifier.h b/src/notifier.h index 602f6e5..1b04943 100644 --- a/src/notifier.h +++ b/src/notifier.h @@ -23,7 +23,6 @@ #include <gio/gio.h> #include "device.h" -#include "sound-player.h" G_BEGIN_DECLS @@ -56,7 +55,7 @@ struct _IndicatorPowerNotifierClass GType indicator_power_notifier_get_type (void); -IndicatorPowerNotifier * indicator_power_notifier_new (IndicatorPowerSoundPlayer * sound_player); +IndicatorPowerNotifier * indicator_power_notifier_new (void); void indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, GDBusConnection * connection); @@ -64,9 +63,6 @@ void indicator_power_notifier_set_bus (IndicatorPowerNotifier * self, void indicator_power_notifier_set_battery (IndicatorPowerNotifier * self, IndicatorPowerDevice * battery); -void indicator_power_notifier_set_sound_player (IndicatorPowerNotifier * self, - IndicatorPowerSoundPlayer * battery); - #define POWER_LEVEL_STR_OK "ok" #define POWER_LEVEL_STR_LOW "low" #define POWER_LEVEL_STR_VERY_LOW "very_low" diff --git a/src/sound-player-gst.c b/src/sound-player-gst.c deleted file mode 100644 index 25c3884..0000000 --- a/src/sound-player-gst.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright 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 - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, 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 <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include "sound-player.h" -#include "sound-player-gst.h" - -#include <gst/gst.h> - - -/*** -**** private struct -***/ - -typedef struct -{ - int unused; -} -IndicatorPowerSoundPlayerGSTPrivate; - -typedef IndicatorPowerSoundPlayerGSTPrivate priv_t; - -#define get_priv(o) ((priv_t*)indicator_power_sound_player_gst_get_instance_private(o)) - - -/*** -**** GObject boilerplate -***/ - -static void indicator_power_device_provider_interface_init ( - IndicatorPowerSoundPlayerInterface * iface); - -G_DEFINE_TYPE_WITH_CODE ( - IndicatorPowerSoundPlayerGST, - indicator_power_sound_player_gst, - G_TYPE_OBJECT, - G_ADD_PRIVATE(IndicatorPowerSoundPlayerGST) - G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_SOUND_PLAYER, - indicator_power_device_provider_interface_init)) - -/*** -**** GSTREAMER -***/ - -static void -gst_init_once(void) -{ - static gboolean gst_init_checked = FALSE; - - if (G_UNLIKELY(!gst_init_checked)) - { - GError* error = NULL; - if (!gst_init_check(NULL, NULL, &error)) - { - g_critical("Unable to play alarm sound: %s", error->message); - g_error_free(error); - } - gst_init_checked = TRUE; - } -} - -static gboolean bus_callback(GstBus* bus G_GNUC_UNUSED, GstMessage* msg, gpointer gelement) -{ - const GstMessageType message_type = GST_MESSAGE_TYPE(msg); - - if (GST_MESSAGE_SRC(msg) != gelement) - return G_SOURCE_CONTINUE; - - /* on eos, cleanup the element and cancel our gst bus subscription */ - if (message_type == GST_MESSAGE_EOS) - { - g_debug("got GST_MESSAGE_EOS on sound play"); - gst_element_set_state(GST_ELEMENT(gelement), GST_STATE_NULL); - gst_object_unref(gelement); - return G_SOURCE_REMOVE; - } - - /* on stream start, set the media role to 'alert' if we're using pulsesink */ - if (message_type == GST_MESSAGE_STREAM_START) - { - GstElement* audio_sink = NULL; - g_debug("got GST_MESSAGE_STREAM_START on sound play"); - g_object_get(gelement, "audio-sink", &audio_sink, NULL); - if (audio_sink != NULL) - { - GstPluginFeature* feature; - feature = GST_PLUGIN_FEATURE_CAST(GST_ELEMENT_GET_CLASS(audio_sink)->elementfactory); - if (feature && g_strcmp0(gst_plugin_feature_get_name(feature), "pulsesink") == 0) - { - const gchar* const props_str = "props,media.role=alert"; - GstStructure* props = gst_structure_from_string(props_str, NULL); - g_debug("setting audio sink properties to '%s'", props_str); - g_object_set(audio_sink, "stream-properties", props, NULL); - g_clear_pointer(&props, gst_structure_free); - } - gst_object_unref(audio_sink); - } - } - - return G_SOURCE_CONTINUE; -} - -/*** -**** IndicatorPowerSoundPlayer virtual functions -***/ - -static void -my_play_uri (IndicatorPowerSoundPlayer * self G_GNUC_UNUSED, const gchar * uri) -{ - GstElement * element; - GstBus * bus; - - /* create the element */ - element = gst_element_factory_make("playbin", NULL); - - /* start listening for gst events */ - bus = gst_pipeline_get_bus(GST_PIPELINE(element)); - gst_bus_add_watch(bus, bus_callback, element); - gst_object_unref(bus); - - /* play the sound */ - g_debug("Playing '%s'", uri); - g_object_set(element, "uri", uri, NULL); - gst_element_set_state(element, GST_STATE_PLAYING); -} - -/*** -**** Instantiation -***/ - -static void -indicator_power_sound_player_gst_class_init (IndicatorPowerSoundPlayerGSTClass * klass) -{ - gst_init_once(); -} - -static void -indicator_power_device_provider_interface_init (IndicatorPowerSoundPlayerInterface * iface) -{ - iface->play_uri = my_play_uri; -} - -static void -indicator_power_sound_player_gst_init (IndicatorPowerSoundPlayerGST * self G_GNUC_UNUSED) -{ -} - -/*** -**** Public API -***/ - -IndicatorPowerSoundPlayer * -indicator_power_sound_player_gst_new(void) -{ - gpointer o = g_object_new (INDICATOR_TYPE_POWER_SOUND_PLAYER_GST, NULL); - - return INDICATOR_POWER_SOUND_PLAYER (o); -} diff --git a/src/sound-player-gst.h b/src/sound-player-gst.h deleted file mode 100644 index 3075738..0000000 --- a/src/sound-player-gst.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 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 - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, 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 <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#ifndef __INDICATOR_POWER_SOUND_PLAYER_GST__H__ -#define __INDICATOR_POWER_SOUND_PLAYER_GST__H__ - -#include <glib-object.h> /* parent class */ - -#include "device-provider.h" - -G_BEGIN_DECLS - -#define INDICATOR_TYPE_POWER_SOUND_PLAYER_GST \ - (indicator_power_sound_player_gst_get_type()) - -#define INDICATOR_POWER_SOUND_PLAYER_GST(o) \ - (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - INDICATOR_TYPE_POWER_SOUND_PLAYER_GST, \ - IndicatorPowerSoundPlayerGST)) - -#define INDICATOR_POWER_SOUND_PLAYER_GST_GET_CLASS(o) \ - (G_TYPE_INSTANCE_GET_CLASS ((o), \ - INDICATOR_TYPE_POWER_SOUND_PLAYER_GST, \ - IndicatorPowerSoundPlayerGSTClass)) - -#define INDICATOR_IS_POWER_SOUND_PLAYER_GST(o) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - INDICATOR_TYPE_POWER_SOUND_PLAYER_GST)) - -typedef struct _IndicatorPowerSoundPlayerGST - IndicatorPowerSoundPlayerGST; -typedef struct _IndicatorPowerSoundPlayerGSTClass - IndicatorPowerSoundPlayerGSTClass; - -/** - * An IndicatorPowerSoundPlayer which gets its devices from GST. - */ -struct _IndicatorPowerSoundPlayerGST -{ - GObject parent_instance; -}; - -struct _IndicatorPowerSoundPlayerGSTClass -{ - GObjectClass parent_class; -}; - -GType indicator_power_sound_player_gst_get_type (void); - -IndicatorPowerSoundPlayer * indicator_power_sound_player_gst_new (void); - -G_END_DECLS - -#endif /* __INDICATOR_POWER_SOUND_PLAYER_GST__H__ */ diff --git a/src/sound-player.c b/src/sound-player.c deleted file mode 100644 index dcbb27b..0000000 --- a/src/sound-player.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 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 - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, 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 <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include "sound-player.h" - -G_DEFINE_INTERFACE (IndicatorPowerSoundPlayer, - indicator_power_sound_player, - 0) - -static void -indicator_power_sound_player_default_init (IndicatorPowerSoundPlayerInterface * klass G_GNUC_UNUSED) -{ -} - -/*** -**** PUBLIC API -***/ - -void -indicator_power_sound_player_play_uri (IndicatorPowerSoundPlayer * self, - const gchar * uri) -{ - IndicatorPowerSoundPlayerInterface * iface; - - g_return_if_fail (INDICATOR_IS_POWER_SOUND_PLAYER (self)); - iface = INDICATOR_POWER_SOUND_PLAYER_GET_INTERFACE (self); - g_return_if_fail (iface->play_uri != NULL); - iface->play_uri (self, uri); -} diff --git a/src/sound-player.h b/src/sound-player.h deleted file mode 100644 index adff924..0000000 --- a/src/sound-player.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 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 - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, 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 <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#ifndef __INDICATOR_POWER_SOUND_PLAYER__H__ -#define __INDICATOR_POWER_SOUND_PLAYER__H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define INDICATOR_TYPE_POWER_SOUND_PLAYER \ - (indicator_power_sound_player_get_type ()) - -#define INDICATOR_POWER_SOUND_PLAYER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - INDICATOR_TYPE_POWER_SOUND_PLAYER, \ - IndicatorPowerSoundPlayer)) - -#define INDICATOR_IS_POWER_SOUND_PLAYER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_TYPE_POWER_SOUND_PLAYER)) - -#define INDICATOR_POWER_SOUND_PLAYER_GET_INTERFACE(inst) \ - (G_TYPE_INSTANCE_GET_INTERFACE ((inst), \ - INDICATOR_TYPE_POWER_SOUND_PLAYER, \ - IndicatorPowerSoundPlayerInterface)) - -typedef struct _IndicatorPowerSoundPlayer - IndicatorPowerSoundPlayer; - -typedef struct _IndicatorPowerSoundPlayerInterface - IndicatorPowerSoundPlayerInterface; - -/** - * An interface class for an object that plays sounds. - */ -struct _IndicatorPowerSoundPlayerInterface -{ - GTypeInterface parent_iface; - - /* virtual functions */ - void (*play_uri) (IndicatorPowerSoundPlayer * self, - const gchar * uri); -}; - -GType indicator_power_sound_player_get_type (void); - -/*** -**** -***/ - -void indicator_power_sound_player_play_uri (IndicatorPowerSoundPlayer * self, - const gchar * uri); - -G_END_DECLS - -#endif /* __INDICATOR_POWER_SOUND_PLAYER__H__ */ |