pidgin/gtkicon-theme-loader.c

changeset 26378
e85d894af8a5
parent 25875
a98b16817658
child 27328
0e1d3c207948
equal deleted inserted replaced
26377:9124a345ed3a 26378:e85d894af8a5
1 /*
2 * PidginIconThemeLoader for Pidgin
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 #include "gtkicon-theme-loader.h"
24 #include "gtkstatus-icon-theme.h"
25
26 #include "xmlnode.h"
27
28 /*****************************************************************************
29 * Icon Theme Builder
30 *****************************************************************************/
31
32 static PurpleTheme *
33 pidgin_icon_loader_build(const gchar *dir)
34 {
35 xmlnode *root_node = NULL, *sub_node;
36 gchar *filename_full, *data;
37 PidginIconTheme *theme = NULL;
38
39 /* Find the theme file */
40 g_return_val_if_fail(dir != NULL, NULL);
41 filename_full = g_build_filename(dir, "theme.xml", NULL);
42
43 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR))
44 root_node = xmlnode_from_file(dir, "theme.xml", "sound themes", "sound-theme-loader");
45
46 g_free(filename_full);
47 g_return_val_if_fail(root_node != NULL, NULL);
48
49 /* Parse the tree */
50 sub_node = xmlnode_get_child(root_node, "description");
51 data = xmlnode_get_data(sub_node);
52
53 if (xmlnode_get_attrib(root_node, "name") != NULL) {
54 theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME,
55 "type", "status-icon",
56 "name", xmlnode_get_attrib(root_node, "name"),
57 "author", xmlnode_get_attrib(root_node, "author"),
58 "image", xmlnode_get_attrib(root_node, "image"),
59 "directory", dir,
60 "description", data, NULL);
61
62 sub_node = xmlnode_get_child(root_node, "icon");
63
64 while (sub_node) {
65 pidgin_icon_theme_set_icon(theme,
66 xmlnode_get_attrib(sub_node, "id"),
67 xmlnode_get_attrib(sub_node, "file"));
68 sub_node = xmlnode_get_next_twin(sub_node);
69 }
70 }
71
72 xmlnode_free(root_node);
73 g_free(data);
74 return PURPLE_THEME(theme);
75 }
76
77 /******************************************************************************
78 * GObject Stuff
79 *****************************************************************************/
80
81 static void
82 pidgin_icon_theme_loader_class_init (PidginIconThemeLoaderClass *klass)
83 {
84 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass);
85
86 loader_klass->purple_theme_loader_build = pidgin_icon_loader_build;
87 }
88
89
90 GType
91 pidgin_icon_theme_loader_get_type (void)
92 {
93 static GType type = 0;
94 if (type == 0) {
95 static const GTypeInfo info = {
96 sizeof(PidginIconThemeLoaderClass),
97 NULL, /* base_init */
98 NULL, /* base_finalize */
99 (GClassInitFunc)pidgin_icon_theme_loader_class_init, /* class_init */
100 NULL, /* class_finalize */
101 NULL, /* class_data */
102 sizeof (PidginIconThemeLoader),
103 0, /* n_preallocs */
104 NULL, /* instance_init */
105 NULL, /* value table */
106 };
107 type = g_type_register_static (PURPLE_TYPE_THEME_LOADER,
108 "PidginIconThemeLoader", &info, 0);
109 }
110 return type;
111 }

mercurial