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
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
24 #include "sound-theme.h"
26 #define PURPLE_SOUND_THEME_GET_PRIVATE(Gobject) \
27 ((PurpleSoundThemePrivate *) ((PURPLE_SOUND_THEME(Gobject))->priv))
29 /******************************************************************************
31 *****************************************************************************/
34 /* used to store filenames of diffrent sounds */
35 GHashTable
*sound_files
;
36 } PurpleSoundThemePrivate
;
38 /******************************************************************************
40 *****************************************************************************/
42 static GObjectClass
*parent_class
= NULL
;
44 /******************************************************************************
46 *****************************************************************************/
48 /******************************************************************************
50 *****************************************************************************/
53 purple_sound_theme_init(GTypeInstance
*instance
,
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
);
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
);
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
;
89 purple_sound_theme_get_type(void)
91 static GType type
= 0;
93 static const GTypeInfo info
= {
94 sizeof(PurpleSoundThemeClass
),
96 NULL
, /* base_finalize */
97 (GClassInitFunc
)purple_sound_theme_class_init
, /* class_init */
98 NULL
, /* class_finalize */
99 NULL
, /* class_data */
100 sizeof(PurpleSoundTheme
),
102 purple_sound_theme_init
, /* instance_init */
103 NULL
, /* value table */
105 type
= g_type_register_static(PURPLE_TYPE_THEME
,
106 "PurpleSoundTheme", &info
, 0);
111 /*****************************************************************************
112 * Public API functions
113 *****************************************************************************/
116 purple_sound_theme_get_file(PurpleSoundTheme
*theme
,
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
);
129 purple_sound_theme_get_file_full(PurpleSoundTheme
*theme
,
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
);
144 purple_sound_theme_set_file(PurpleSoundTheme
*theme
,
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
));
157 g_hash_table_remove(priv
->sound_files
, event
);