2 * This file is a part of libhildon
4 * Copyright (C) 2005-2008 Nokia Corporation. All rights reserved.
6 * Contact: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-sound
27 * @short_description: libcanberra-based utility function for playing a sound.
32 #include <gconf/gconf-client.h>
34 #include <canberra-gtk.h>
36 #include "hildon-sound.h"
38 #define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
41 * hildon_play_system_sound:
42 * @sample: sound file to play
44 * Plays the given sample using libcanberra.
45 * Volume level is received from gconf.
48 hildon_play_system_sound(const gchar *sample)
52 ca_context *ca_con = NULL;
53 ca_proplist *pl = NULL;
55 #if 0 /* FIXME: Check volume handling. Would be great not to use Gconf... */
61 * The volume is from -0dB to -6dB,
62 The full volume is marked as 2 in gconf */
63 client = gconf_client_get_default ();
64 value = gconf_client_get (client, ALARM_GCONF_PATH, NULL);
66 /* We want error cases to match full volume, not silence, so
67 we do not want to use gconf_client_get_int */
68 if (!value || value->type != GCONF_VALUE_INT)
71 gconf_vol = gconf_value_get_int(value);
74 gconf_value_free(value);
75 g_object_unref (client);
77 volume = ((1.0 - (float)gconf_vol / 2.0)) * (-6.0);
80 ca_con = ca_gtk_context_get ();
83 g_warning ("ca_gtk_context_get doesn't return a proper context \n");
87 ca_proplist_create(&pl);
88 ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, sample);
89 ca_proplist_setf(pl, CA_PROP_CANBERRA_VOLUME, "%f", volume);
91 ret = ca_context_play_full(ca_con, 0, pl, NULL, NULL);
92 g_debug("ca_context_play_full (vol %f): %s\n", volume, ca_strerror(ret));
94 ca_proplist_destroy(pl);