Make sure that all timeouts in HildonBanner are removed
[hildon] / hildon / hildon-sound.c
1 /*
2  * This file is a part of libhildon
3  *
4  * Copyright (C) 2005-2008 Nokia Corporation. All rights reserved.
5  *
6  * Contact: Kimmo Hämäläinen <kimmo.hamalainen@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, or (at your option) any later version.
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: libcanberra-based utility function for playing a sound.
28  *
29  * Please note that this method is only provided for backwards compatibility,
30  * but we highly recommend you to use canberra-gtk directly instead.
31  * 
32  */
33
34 #include <unistd.h>
35 #include <gconf/gconf-client.h>
36 #include <canberra.h>
37
38 #include "hildon-sound.h"
39
40 #define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
41
42 static ca_context *hildon_ca_context_get (void);
43
44 /*
45  * hildon_ca_context_get:
46  *
47  * hildon maintains a single application-global ca_context object.
48  *
49  * This functions is based on ca_gtk_context_get
50  *
51  * Returns: a ca_context object
52  */
53 static ca_context *
54 hildon_ca_context_get (void)
55 {
56     static GStaticPrivate context_private = G_STATIC_PRIVATE_INIT;
57     ca_context *c = NULL;
58     const gchar *name = NULL;
59     gint ret;
60
61     if ((c = g_static_private_get(&context_private)))
62         return c;
63
64     if ((ret = ca_context_create(&c)) != CA_SUCCESS) {
65         g_warning("ca_context_create: %s\n", ca_strerror(ret));
66         return NULL;
67     }
68     if ((ret = ca_context_open(c)) != CA_SUCCESS) {
69         g_warning("ca_context_open: %s\n", ca_strerror(ret));
70         ca_context_destroy(c);
71         return NULL;
72     }
73
74     if ((name = g_get_application_name()))
75         ca_context_change_props(c, CA_PROP_APPLICATION_NAME, name, NULL);
76
77     g_static_private_set(&context_private, c, (GDestroyNotify) ca_context_destroy);
78
79     return c;
80 }
81
82 /**
83  * hildon_play_system_sound:
84  * @sample: sound file to play
85  * 
86  * Plays the given sample using libcanberra.
87  * Volume level is received from gconf.
88  *
89  * This method sets the "dialog-information" role for the sound played,
90  * so you need to keep this into account when using it. For any purpose, it
91  * is highly recommended that you use canberra-gtk instead of this method.
92  */
93 void 
94 hildon_play_system_sound(const gchar *sample)
95 {
96     int ret;
97     ca_context *ca_con = NULL;
98     ca_proplist *pl = NULL;
99
100     ca_con = hildon_ca_context_get ();
101
102     ca_proplist_create(&pl);
103     ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, sample);
104     ca_proplist_sets(pl, CA_PROP_MEDIA_ROLE, "dialog-information");
105     ca_proplist_sets(pl, "module-stream-restore.id", "x-maemo-system-sound");
106
107     ret = ca_context_play_full(ca_con, 0, pl, NULL, NULL);
108     g_debug("ca_context_play_full %s\n", ca_strerror(ret));
109
110     ca_proplist_destroy(pl);
111 }