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 /******************************************************************************
28 *****************************************************************************/
33 * A purple sound theme.
34 * This is an object for Purple to represent a sound theme.
36 struct _PurpleSoundTheme
43 /* used to store filenames of diffrent sounds */
44 GHashTable
*sound_files
;
45 } PurpleSoundThemePrivate
;
47 /******************************************************************************
49 *****************************************************************************/
51 G_DEFINE_TYPE_WITH_PRIVATE(PurpleSoundTheme
, purple_sound_theme
,
54 /******************************************************************************
56 *****************************************************************************/
58 /******************************************************************************
60 *****************************************************************************/
63 purple_sound_theme_init(PurpleSoundTheme
*theme
)
65 PurpleSoundThemePrivate
*priv
;
67 priv
= purple_sound_theme_get_instance_private(theme
);
69 priv
->sound_files
= g_hash_table_new_full(g_str_hash
,
70 g_str_equal
, g_free
, g_free
);
74 purple_sound_theme_finalize(GObject
*obj
)
76 PurpleSoundThemePrivate
*priv
;
78 priv
= purple_sound_theme_get_instance_private(PURPLE_SOUND_THEME(obj
));
80 g_hash_table_destroy(priv
->sound_files
);
82 G_OBJECT_CLASS(purple_sound_theme_parent_class
)->finalize(obj
);
86 purple_sound_theme_class_init(PurpleSoundThemeClass
*klass
)
88 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
90 obj_class
->finalize
= purple_sound_theme_finalize
;
93 /*****************************************************************************
94 * Public API functions
95 *****************************************************************************/
98 purple_sound_theme_get_file(PurpleSoundTheme
*theme
,
101 PurpleSoundThemePrivate
*priv
;
103 g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme
), NULL
);
105 priv
= purple_sound_theme_get_instance_private(theme
);
107 return g_hash_table_lookup(priv
->sound_files
, event
);
111 purple_sound_theme_get_file_full(PurpleSoundTheme
*theme
,
114 const gchar
*filename
;
116 g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme
), NULL
);
118 filename
= purple_sound_theme_get_file(theme
, event
);
120 g_return_val_if_fail(filename
, NULL
);
122 return g_build_filename(purple_theme_get_dir(PURPLE_THEME(theme
)), filename
, NULL
);
126 purple_sound_theme_set_file(PurpleSoundTheme
*theme
,
128 const gchar
*filename
)
130 PurpleSoundThemePrivate
*priv
;
131 g_return_if_fail(PURPLE_IS_SOUND_THEME(theme
));
133 priv
= purple_sound_theme_get_instance_private(theme
);
135 if (filename
!= NULL
)
136 g_hash_table_replace(priv
->sound_files
,
137 g_strdup(event
), g_strdup(filename
));
139 g_hash_table_remove(priv
->sound_files
, event
);