From 3639e65c41630247c4910e1679fd9d40b7f9311d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 23 Jun 2008 18:14:54 +0200 Subject: add new property CA_PROP_CANBERRA_ENABLE for disabling/enabling event sounds --- src/canberra.h | 16 +++++++++++++++- src/common.c | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/canberra.h b/src/canberra.h index fc9ef0a..3a3b88f 100644 --- a/src/canberra.h +++ b/src/canberra.h @@ -352,6 +352,19 @@ extern "C" { */ #define CA_PROP_CANBERRA_XDG_THEME_OUTPUT_PROFILE "canberra.xdg-theme.output-profile" +/** + * CA_PROP_CANBERRA_ENABLE: + * + * A special property that can be used to control whether any sounds + * are played at all. If this property is "1" or unset sounds are + * played as normal. However, if it is "0" all calls to + * ca_context_play() will fail with CA_ERROR_DISABLED. + * + * If the list of properties is handed on to the sound server this + * property is stripped from it. + */ +#define CA_PROP_CANBERRA_ENABLE "canberra.enable" + /** * ca_context: * @@ -399,7 +412,8 @@ enum { CA_ERROR_ACCESS = -13, CA_ERROR_IO = -14, CA_ERROR_INTERNAL = -15, - _CA_ERROR_MAX = -16 + CA_ERROR_DISABLED = -16, + _CA_ERROR_MAX = -17 }; /** diff --git a/src/common.c b/src/common.c index b285514..71b887a 100644 --- a/src/common.c +++ b/src/common.c @@ -518,6 +518,8 @@ int ca_context_play(ca_context *c, uint32_t id, ...) { int ca_context_play_full(ca_context *c, uint32_t id, ca_proplist *p, ca_finish_callback_t cb, void *userdata) { int ret; + const char *t; + ca_bool_t enabled = TRUE; ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_return_val_if_fail(p, CA_ERROR_INVALID); @@ -528,6 +530,18 @@ int ca_context_play_full(ca_context *c, uint32_t id, ca_proplist *p, ca_finish_c ca_return_val_if_fail_unlock(ca_proplist_contains(p, CA_PROP_EVENT_ID) || ca_proplist_contains(c->props, CA_PROP_EVENT_ID), CA_ERROR_INVALID, c->mutex); + ca_mutex_lock(c->props->mutex); + if ((t = ca_proplist_gets_unlocked(c->props, CA_PROP_CANBERRA_ENABLE))) + enabled = !streq(t, "0"); + ca_mutex_unlock(c->props->mutex); + + ca_mutex_lock(p->mutex); + if ((t = ca_proplist_gets_unlocked(p, CA_PROP_CANBERRA_ENABLE))) + enabled = !streq(t, "0"); + ca_mutex_unlock(p->mutex); + + ca_return_val_if_fail_unlock(enabled, CA_ERROR_DISABLED, c->mutex); + if ((ret = context_open_unlocked(c)) < 0) goto finish; @@ -674,7 +688,8 @@ const char *ca_strerror(int code) { [-CA_ERROR_NOTAVAILABLE] = "Not available", [-CA_ERROR_ACCESS] = "Access forbidden", [-CA_ERROR_IO] = "IO error", - [-CA_ERROR_INTERNAL] = "Internal error" + [-CA_ERROR_INTERNAL] = "Internal error", + [-CA_ERROR_DISABLED] = "Sounds disabled" }; ca_return_val_if_fail(code <= 0, NULL); -- cgit