2 * SoundThemeLoader 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-loader.h"
25 #include "sound-theme.h"
31 * PurpleSoundThemeLoader:
33 * A purple sound theme loader. extends PurpleThemeLoader (theme-loader.h)
34 * This is a class designed to build sound themes
36 struct _PurpleSoundThemeLoader
38 PurpleThemeLoader parent
;
41 /*****************************************************************************
43 *****************************************************************************/
46 purple_sound_loader_build(const gchar
*theme_dir
)
48 PurpleXmlNode
*root_node
= NULL
, *sub_node
;
49 gchar
*dir
, *filename_full
, *data
= NULL
;
50 PurpleSoundTheme
*theme
= NULL
;
53 /* Find the theme file */
54 g_return_val_if_fail(theme_dir
!= NULL
, NULL
);
55 dir
= g_build_filename(theme_dir
, "purple", "sound", NULL
);
56 filename_full
= g_build_filename(dir
, "theme.xml", NULL
);
58 if (g_file_test(filename_full
, G_FILE_TEST_IS_REGULAR
))
59 root_node
= purple_xmlnode_from_file(dir
, "theme.xml", "sound themes", "sound-theme-loader");
61 g_free(filename_full
);
62 if (root_node
== NULL
) {
67 name
= purple_xmlnode_get_attrib(root_node
, "name");
69 if (name
&& purple_strequal(purple_xmlnode_get_attrib(root_node
, "type"), "sound")) {
71 sub_node
= purple_xmlnode_get_child(root_node
, "description");
72 data
= purple_xmlnode_get_data(sub_node
);
74 if (purple_xmlnode_get_attrib(root_node
, "name") != NULL
) {
75 theme
= g_object_new(PURPLE_TYPE_SOUND_THEME
,
78 "author", purple_xmlnode_get_attrib(root_node
, "author"),
79 "image", purple_xmlnode_get_attrib(root_node
, "image"),
81 "description", data
, NULL
);
83 sub_node
= purple_xmlnode_get_child(root_node
, "event");
86 purple_sound_theme_set_file(theme
,
87 purple_xmlnode_get_attrib(sub_node
, "name"),
88 purple_xmlnode_get_attrib(sub_node
, "file"));
89 sub_node
= purple_xmlnode_get_next_twin(sub_node
);
92 } else purple_debug_warning("sound-theme-loader", "Missing attribute or problem with the root element\n");
94 purple_xmlnode_free(root_node
);
97 return PURPLE_THEME(theme
);
100 /******************************************************************************
102 *****************************************************************************/
105 purple_sound_theme_loader_class_init(PurpleSoundThemeLoaderClass
*klass
)
107 PurpleThemeLoaderClass
*loader_klass
= PURPLE_THEME_LOADER_CLASS(klass
);
109 loader_klass
->purple_theme_loader_build
= purple_sound_loader_build
;
113 purple_sound_theme_loader_get_type(void)
115 static GType type
= 0;
117 static const GTypeInfo info
= {
118 sizeof(PurpleSoundThemeLoaderClass
),
119 NULL
, /* base_init */
120 NULL
, /* base_finalize */
121 (GClassInitFunc
)purple_sound_theme_loader_class_init
, /* class_init */
122 NULL
, /* class_finalize */
123 NULL
, /* class_data */
124 sizeof(PurpleSoundThemeLoader
),
126 NULL
, /* instance_init */
127 NULL
, /* value table */
129 type
= g_type_register_static(PURPLE_TYPE_THEME_LOADER
,
130 "PurpleSoundThemeLoader", &info
, 0);