Increment version number
[pidgin-git.git] / libpurple / sound-theme.c
blob4918f4075824fab1f518c89989f351f688f1cf14
1 /*
2 * Sound Themes for libpurple
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.
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.
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.
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
23 #include "internal.h"
24 #include "sound-theme.h"
26 #define PURPLE_SOUND_THEME_GET_PRIVATE(Gobject) \
27 ((PurpleSoundThemePrivate *) ((PURPLE_SOUND_THEME(Gobject))->priv))
29 /******************************************************************************
30 * Structs
31 *****************************************************************************/
33 typedef struct {
34 /* used to store filenames of diffrent sounds */
35 GHashTable *sound_files;
36 } PurpleSoundThemePrivate;
38 /******************************************************************************
39 * Globals
40 *****************************************************************************/
42 static GObjectClass *parent_class = NULL;
44 /******************************************************************************
45 * Enums
46 *****************************************************************************/
48 /******************************************************************************
49 * GObject Stuff
50 *****************************************************************************/
52 static void
53 purple_sound_theme_init(GTypeInstance *instance,
54 gpointer klass)
56 PurpleSoundThemePrivate *priv;
58 (PURPLE_SOUND_THEME(instance))->priv = g_new0(PurpleSoundThemePrivate, 1);
60 priv = PURPLE_SOUND_THEME_GET_PRIVATE(instance);
62 priv->sound_files = g_hash_table_new_full(g_str_hash,
63 g_str_equal, g_free, g_free);
66 static void
67 purple_sound_theme_finalize(GObject *obj)
69 PurpleSoundThemePrivate *priv;
71 priv = PURPLE_SOUND_THEME_GET_PRIVATE(obj);
73 g_hash_table_destroy(priv->sound_files);
75 parent_class->finalize(obj);
78 static void
79 purple_sound_theme_class_init(PurpleSoundThemeClass *klass)
81 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
83 parent_class = g_type_class_peek_parent(klass);
85 obj_class->finalize = purple_sound_theme_finalize;
88 GType
89 purple_sound_theme_get_type(void)
91 static GType type = 0;
92 if (type == 0) {
93 static const GTypeInfo info = {
94 sizeof(PurpleSoundThemeClass),
95 NULL, /* base_init */
96 NULL, /* base_finalize */
97 (GClassInitFunc)purple_sound_theme_class_init, /* class_init */
98 NULL, /* class_finalize */
99 NULL, /* class_data */
100 sizeof(PurpleSoundTheme),
101 0, /* n_preallocs */
102 purple_sound_theme_init, /* instance_init */
103 NULL, /* value table */
105 type = g_type_register_static(PURPLE_TYPE_THEME,
106 "PurpleSoundTheme", &info, 0);
108 return type;
111 /*****************************************************************************
112 * Public API functions
113 *****************************************************************************/
115 const gchar *
116 purple_sound_theme_get_file(PurpleSoundTheme *theme,
117 const gchar *event)
119 PurpleSoundThemePrivate *priv;
121 g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme), NULL);
123 priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme);
125 return g_hash_table_lookup(priv->sound_files, event);
128 gchar *
129 purple_sound_theme_get_file_full(PurpleSoundTheme *theme,
130 const gchar *event)
132 const gchar *filename;
134 g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme), NULL);
136 filename = purple_sound_theme_get_file(theme, event);
138 g_return_val_if_fail(filename, NULL);
140 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme)), filename, NULL);
143 void
144 purple_sound_theme_set_file(PurpleSoundTheme *theme,
145 const gchar *event,
146 const gchar *filename)
148 PurpleSoundThemePrivate *priv;
149 g_return_if_fail(PURPLE_IS_SOUND_THEME(theme));
151 priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme);
153 if (filename != NULL)
154 g_hash_table_replace(priv->sound_files,
155 g_strdup(event), g_strdup(filename));
156 else
157 g_hash_table_remove(priv->sound_files, event);