2
* Copyright 2014 Canonical Ltd.
2
* Copyright 2014-2016 Canonical Ltd.
4
4
* This program is free software: you can redistribute it and/or modify it
5
5
* under the terms of the GNU General Public License version 3, as published
17
17
* Charles Kerr <charles.kerr@canonical.com>
20
#include "datafiles.h"
21
#include "dbus-accounts-sound.h"
20
22
#include "dbus-battery.h"
21
23
#include "dbus-shared.h"
22
24
#include "notifier.h"
25
#include "sound-player.h"
24
27
#include <url-dispatcher.h>
78
83
gboolean caps_queried;
79
84
gboolean actions_supported;
86
IndicatorPowerSoundPlayer * sound_player;
88
GCancellable * cancellable;
89
DbusAccountsServiceSound * accounts_service_sound_proxy;
90
gboolean accounts_service_sound_proxy_pending;
81
92
IndicatorPowerNotifierPrivate;
149
on_sound_proxy_ready (GObject * source_object G_GNUC_UNUSED,
154
DbusAccountsServiceSound * proxy;
157
proxy = dbus_accounts_service_sound_proxy_new_for_bus_finish (res, &error);
160
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
162
get_priv(gself)->accounts_service_sound_proxy_pending = FALSE;
163
g_debug("%s Couldn't find accounts service sound proxy: %s", G_STRLOC, error->message);
166
g_clear_error(&error);
170
IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(gself);
171
priv_t * const p = get_priv (self);
172
g_clear_object (&p->accounts_service_sound_proxy);
173
p->accounts_service_sound_proxy = proxy;
174
p->accounts_service_sound_proxy_pending = FALSE;
179
silent_mode (IndicatorPowerNotifier * self)
181
priv_t * const p = get_priv (self);
183
/* if we don't have a proxy yet, assume we're in silent mode
184
as a "do no harm" level of response */
185
if (p->accounts_service_sound_proxy_pending)
188
return (p->accounts_service_sound_proxy != NULL)
189
&& dbus_accounts_service_sound_get_silent_mode(p->accounts_service_sound_proxy);
193
play_low_battery_sound (IndicatorPowerNotifier * self)
195
const gchar * const key = LOW_BATTERY_SOUND;
197
priv_t * const p = get_priv(self);
200
g_return_if_fail (p->sound_player != NULL);
203
if (silent_mode(self))
206
filename = datafile_find(DATAFILE_TYPE_SOUND, key);
207
if (filename != NULL)
209
gchar * uri = g_filename_to_uri(filename, NULL, NULL);
210
indicator_power_sound_player_play_uri (p->sound_player, uri);
216
g_warning("Unable to find '%s' in XDG data dirs", key);
134
221
**** Notifications
330
418
g_value_set_object (value, p->battery);
421
case PROP_SOUND_PLAYER:
422
g_value_set_object (value, p->sound_player);
334
426
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
349
441
indicator_power_notifier_set_battery (self, g_value_get_object(value));
444
case PROP_SOUND_PLAYER:
445
indicator_power_notifier_set_sound_player (self, g_value_get_object(value));
353
449
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
360
456
IndicatorPowerNotifier * const self = INDICATOR_POWER_NOTIFIER(o);
361
457
priv_t * const p = get_priv (self);
459
if (p->cancellable != NULL)
461
g_cancellable_cancel(p->cancellable);
462
g_clear_object(&p->cancellable);
363
465
indicator_power_notifier_set_bus (self, NULL);
466
indicator_power_notifier_set_sound_player (self, NULL);
364
467
notification_clear (self);
365
468
indicator_power_notifier_set_battery (self, NULL);
366
469
g_clear_object (&p->dbus_battery);
470
g_clear_object (&p->accounts_service_sound_proxy);
368
472
G_OBJECT_CLASS (indicator_power_notifier_parent_class)->dispose (o);
395
498
p->power_level = POWER_LEVEL_OK;
500
p->cancellable = g_cancellable_new();
397
502
if (!instance_count++ && !notify_init("indicator-power-service"))
398
503
g_critical("Unable to initialize libnotify! Notifications might not be shown.");
505
p->accounts_service_sound_proxy_pending = TRUE;
506
gchar* object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid());
507
dbus_accounts_service_sound_proxy_new_for_bus(
509
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
510
"org.freedesktop.Accounts",
513
on_sound_proxy_ready,
515
g_clear_pointer(&object_path, g_free);
416
533
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
535
properties[PROP_SOUND_PLAYER] = g_param_spec_object (
536
PROP_SOUND_PLAYER_NAME,
538
"The current sound player",
540
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
418
542
g_object_class_install_properties (object_class, LAST_PROP, properties);
425
549
IndicatorPowerNotifier *
426
indicator_power_notifier_new (void)
550
indicator_power_notifier_new (IndicatorPowerSoundPlayer * sound_player)
428
GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER, NULL);
552
GObject * o = g_object_new (INDICATOR_TYPE_POWER_NOTIFIER,
553
PROP_SOUND_PLAYER_NAME, sound_player,
430
556
return INDICATOR_POWER_NOTIFIER (o);
594
indicator_power_notifier_set_sound_player (IndicatorPowerNotifier * self,
595
IndicatorPowerSoundPlayer * sound_player)
599
g_return_if_fail(INDICATOR_IS_POWER_NOTIFIER(self));
600
g_return_if_fail((sound_player == NULL) || INDICATOR_IS_POWER_SOUND_PLAYER(sound_player));
604
if (p->sound_player == sound_player)
607
g_clear_object(&p->sound_player);
609
if (sound_player != NULL)
610
p->sound_player = g_object_ref(sound_player);
468
614
indicator_power_notifier_set_bus (IndicatorPowerNotifier * self,
469
615
GDBusConnection * bus)