1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* This file is a part of libhildon
*
* Copyright (C) 2005-2008 Nokia Corporation. All rights reserved.
*
* Contact: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**
* SECTION:hildon-sound
* @short_description: libcanberra-based utility function for playing a sound.
*
* Please note that this method is only provided for backwards compatibility,
* but we highly recommend you to use canberra-gtk directly instead.
*
*/
#include <unistd.h>
#include <gconf/gconf-client.h>
#include <canberra.h>
#include "hildon-sound.h"
#define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
static ca_context *hildon_ca_context_get (void);
/*
* hildon_ca_context_get:
*
* hildon maintains a single application-global ca_context object.
*
* This functions is based on ca_gtk_context_get
*
* Returns: a ca_context object
*/
static ca_context *
hildon_ca_context_get (void)
{
static GStaticPrivate context_private = G_STATIC_PRIVATE_INIT;
ca_context *c = NULL;
const gchar *name = NULL;
gint ret;
if ((c = g_static_private_get(&context_private)))
return c;
if ((ret = ca_context_create(&c)) != CA_SUCCESS) {
g_warning("ca_context_create: %s\n", ca_strerror(ret));
return NULL;
}
if ((ret = ca_context_open(c)) != CA_SUCCESS) {
g_warning("ca_context_open: %s\n", ca_strerror(ret));
ca_context_destroy(c);
return NULL;
}
if ((name = g_get_application_name()))
ca_context_change_props(c, CA_PROP_APPLICATION_NAME, name, NULL);
g_static_private_set(&context_private, c, (GDestroyNotify) ca_context_destroy);
return c;
}
/**
* hildon_play_system_sound:
* @sample: sound file to play
*
* Plays the given sample using libcanberra.
* Volume level is received from gconf.
*
* This method sets the "dialog-information" role for the sound played,
* so you need to keep this into account when using it. For any purpose, it
* is highly recommended that you use canberra-gtk instead of this method.
*/
void
hildon_play_system_sound(const gchar *sample)
{
ca_context *ca_con = NULL;
ca_proplist *pl = NULL;
ca_con = hildon_ca_context_get ();
ca_proplist_create(&pl);
ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, sample);
ca_proplist_sets(pl, CA_PROP_MEDIA_ROLE, "dialog-information");
ca_proplist_sets(pl, "module-stream-restore.id", "x-maemo-system-sound");
ca_context_play_full(ca_con, 0, pl, NULL, NULL);
ca_proplist_destroy(pl);
}
|