aboutsummaryrefslogtreecommitdiff
path: root/src/notifier.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/notifier.c')
-rw-r--r--src/notifier.c61
1 files changed, 52 insertions, 9 deletions
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 <lomiri-url-dispatcher.h>
+#include <lomiri-url-dispatcher.h>
#endif
#include <libnotify/notify.h>
@@ -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);
}
@@ -496,6 +519,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)
{