comparison libpurple/sound-theme.c @ 23458:1cf10adc9b32

Added minimal sound theme class (only get/set api)
author Justin Rodriguez <ffdragon@soc.pidgin.im>
date Thu, 12 Jun 2008 07:34:43 +0000
parents
children fecc8e2612c4
comparison
equal deleted inserted replaced
23457:8793058bc318 23458:1cf10adc9b32
1 /*
2 * Sound Themes for LibPurple
3 *
4 * Pidgin is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 *
22 */
23
24 #include "sound-theme.h"
25
26 #define PURPLE_SOUND_THEME_GET_PRIVATE(Gobject) \
27 ((PurpleSoundThemePrivate *) ((PURPLE_SOUND_THEME(Gobject))->priv))
28
29
30 /******************************************************************************
31 * Structs
32 *****************************************************************************/
33 typedef struct {
34 /* used to store filenames of diffrent sounds */
35 GHashTable *sound_files;
36 } PurpleSoundThemePrivate;
37
38 /******************************************************************************
39 * Globals
40 *****************************************************************************/
41
42 /******************************************************************************
43 * Enums
44 *****************************************************************************/
45
46 /******************************************************************************
47 * GObject Stuff
48 *****************************************************************************/
49
50 static void
51 purple_sound_theme_finalize (GObject *obj)
52 {
53 PurpleSoundThemePrivate *priv;
54
55 priv = PURPLE_SOUND_THEME_GET_PRIVATE(obj);
56
57 g_hash_table_destroy(priv->sound_files);
58 }
59
60 static void
61 purple_sound_theme_class_init (PurpleSoundThemeClass *klass)
62 {
63 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
64
65 obj_class->finalize = purple_sound_theme_finalize;
66 }
67
68 GType
69 purple_sound_theme_get_type (void)
70 {
71 static GType type = 0;
72 if (type == 0) {
73 static const GTypeInfo info = {
74 sizeof (PurpleSoundThemeClass),
75 NULL, /* base_init */
76 NULL, /* base_finalize */
77 (GClassInitFunc)purple_sound_theme_class_init, /* class_init */
78 NULL, /* class_finalize */
79 NULL, /* class_data */
80 sizeof (PurpleSoundTheme),
81 0, /* n_preallocs */
82 NULL, /* instance_init */
83 NULL, /* value table */
84 };
85 type = g_type_register_static (G_TYPE_OBJECT,
86 "PurpleSoundThemeType",
87 &info, 0);
88 }
89 return type;
90 }
91
92
93 /*****************************************************************************
94 * Public API functions
95 *****************************************************************************/
96
97 PurpleSoundTheme *
98 purple_sound_theme_new()
99 {
100 PurpleSoundTheme *theme;
101 PurpleSoundThemePrivate *priv;
102
103 theme = g_object_new(PURPLE_TYPE_SOUND_THEME, NULL);
104 priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme);
105
106 priv->sound_files = g_hash_table_new_full (g_str_hash,
107 g_str_equal,
108 g_free,
109 g_free);
110
111 return theme;
112 }
113
114 gchar *
115 purple_sound_theme_get_file(PurpleSoundTheme *theme,
116 const gchar *event)
117 {
118 PurpleSoundThemePrivate *priv;
119
120 g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme), NULL);
121
122 priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme);
123
124 return g_hash_table_lookup(priv->sound_files, event);
125 }
126
127 gchar *
128 purple_sound_theme_get_file_full(PurpleSoundTheme *theme,
129 const gchar *event)
130 {
131 gchar *dir, *fname, *full;
132
133 g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme), NULL);
134
135 dir = purple_theme_get_dir(theme->parent);
136 fname = purple_sound_theme_get_file(theme, event);
137 full = g_strconcat (dir, '/',fname, NULL);
138
139 g_free(dir);
140 g_free(fname);
141
142 return full;
143 }
144
145 void
146 purple_sound_theme_set_file(PurpleSoundTheme *theme,
147 const gchar *event,
148 const gchar *fname)
149 {
150 PurpleSoundThemePrivate *priv;
151 g_return_if_fail(PURPLE_IS_SOUND_THEME(theme));
152
153 priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme);
154
155 if (fname)g_hash_table_replace(priv->sound_files,
156 g_strdup(event),
157 g_strdup(fname));
158 else g_hash_table_remove(priv->sound_files, event);
159 }
160
161