aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcharles kerr <charlesk@canonical.com>2016-01-01 20:08:05 -0600
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2021-08-28 10:17:14 +0200
commit97130ad08300c3ec6ab2165ff7506cd7f25af0d6 (patch)
tree58a988880a81563e1cdc4fadcd74c2e50a59d63a /src
parent460f1464709a4c5e2c1594045961be9108ae2afd (diff)
downloadayatana-indicator-power-97130ad08300c3ec6ab2165ff7506cd7f25af0d6.tar.gz
ayatana-indicator-power-97130ad08300c3ec6ab2165ff7506cd7f25af0d6.tar.bz2
ayatana-indicator-power-97130ad08300c3ec6ab2165ff7506cd7f25af0d6.zip
honor com.ubuntu.touch.AccountsService.Sound.SilentMode
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/com.ubuntu.touch.AccountsService.Sound.xml47
-rw-r--r--src/notifier.c64
3 files changed, 115 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c99ce46..01a0558 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -39,6 +39,11 @@ add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-testing
org.ayatana.indicator.power
Dbus
${CMAKE_SOURCE_DIR}/data/org.ayatana.indicator.power.Testing.xml)
+add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-accounts-sound
+ com.ubuntu.touch
+ Dbus
+ ${CMAKE_SOURCE_DIR}/src/com.ubuntu.touch.AccountsService.Sound.xml)
+
# add the bin dir to our include path so the code can find the generated header files
include_directories(${CMAKE_CURRENT_BINARY_DIR})
diff --git a/src/com.ubuntu.touch.AccountsService.Sound.xml b/src/com.ubuntu.touch.AccountsService.Sound.xml
new file mode 100644
index 0000000..6e2ca5f
--- /dev/null
+++ b/src/com.ubuntu.touch.AccountsService.Sound.xml
@@ -0,0 +1,47 @@
+<node>
+ <interface name="com.ubuntu.touch.AccountsService.Sound">
+
+ <annotation name="org.freedesktop.Accounts.VendorExtension" value="true"/>
+
+ <!-- Muted is all sound, SilentMode is only non-user-initiated sounds -->
+ <property name="SilentMode" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/>
+ </property>
+
+ <property name="IncomingCallSound" type="s" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue.String"
+ value="/usr/share/sounds/ubuntu/ringtones/Ubuntu.ogg"/>
+ </property>
+
+ <property name="IncomingMessageSound" type="s" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue.String"
+ value="/usr/share/sounds/ubuntu/notifications/Xylo.ogg"/>
+ </property>
+
+ <property name="IncomingCallVibrate" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
+ </property>
+
+ <property name="IncomingCallVibrateSilentMode" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
+ </property>
+
+ <property name="IncomingMessageVibrate" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
+ </property>
+
+ <property name="IncomingMessageVibrateSilentMode" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
+ </property>
+
+ <!-- "Other vibrations" should cover all vibrations except for those relating to phone calls and messages -->
+ <property name="OtherVibrate" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
+ </property>
+
+ <property name="DialpadSoundsEnabled" type="b" access="readwrite">
+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
+ </property>
+
+ </interface>
+</node>
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;
@@ -144,14 +148,53 @@ get_battery_power_level (IndicatorPowerDevice * battery)
***/
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)
{
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);
+ /* 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