Adding an example test program to check icon-lookup functionality. Doc updates.
[hildon] / src / hildon-sound.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 /**
26  * SECTION:hildon-sound
27  * @short_description: An esd-based utility function for playing a sound.
28  * 
29  */
30
31 #include                                        "hildon-sound.h"
32 #include                                        <gconf/gconf-client.h>
33 #include                                        <esd.h>
34 #include                                        <unistd.h>
35
36 #define                                         ALARM_GCONF_PATH \
37                                                 "/apps/osso/sound/system_alert_volume"
38
39 /**
40  * hildon_play_system_sound:
41  * @sample: sound file to play
42  * 
43  * Plays the given sample using esd sound daemon.
44  * Volume level is received from gconf. 
45  */
46 void 
47 hildon_play_system_sound                        (const gchar *sample)
48 {
49     GConfClient *client;
50     GConfValue *value;
51     gint volume, scale, sock, sample_id;
52
53     client = gconf_client_get_default ();
54     value = gconf_client_get (client, ALARM_GCONF_PATH, NULL);
55
56     /* We want error cases to match full volume, not silence, so
57        we do not want to use gconf_client_get_int */
58     if (!value || value->type != GCONF_VALUE_INT)
59         volume = 2;
60     else
61         volume = gconf_value_get_int(value);
62
63     if (value)
64         gconf_value_free(value);
65     g_object_unref (client);
66
67     switch (volume)
68     {
69         case 0:
70             return;
71         case 1:
72             scale = 0x80;
73             break;
74         case 2:
75         default:
76             scale = 0xff;
77             break;
78     };
79
80     sock = esd_open_sound (NULL);
81     if (sock <= 0)
82         return;
83
84     sample_id = esd_file_cache (sock, g_get_prgname(), sample);
85     if (sample_id < 0) {
86         close(sock);
87         return;
88     }
89
90     esd_set_default_sample_pan (sock, sample_id, scale, scale);
91     esd_sample_play(sock, sample_id);
92     esd_sample_free(sock, sample_id);
93     close (sock);
94 }