rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / pidgin / gtkicon-theme-loader.c
blobd6ef1c3e60875b3b96be0417372e6bce631a31ee
1 /*
2 * PidginIconThemeLoader for Pidgin
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 "gtkicon-theme-loader.h"
24 #include "gtkstatus-icon-theme.h"
26 #include "xmlnode.h"
27 #include "debug.h"
29 /**
30 * PidginIconThemeLoader:
32 * A pidgin icon theme loader. Extends PurpleThemeLoader (theme-loader.h)
33 * This is a class designed to build icon themes
35 struct _PidginIconThemeLoader
37 PurpleThemeLoader parent;
40 /*****************************************************************************
41 * Icon Theme Builder
42 *****************************************************************************/
44 static PurpleTheme *
45 pidgin_icon_loader_build(const gchar *theme_dir)
47 PurpleXmlNode *root_node = NULL, *sub_node;
48 gchar *dir, *filename_full, *data = NULL;
49 PidginIconTheme *theme = NULL;
50 const gchar *name;
52 /* Find the theme file */
53 g_return_val_if_fail(theme_dir != NULL, NULL);
54 dir = g_build_filename(theme_dir, "purple", "status-icon", NULL);
55 filename_full = g_build_filename(dir, "theme.xml", NULL);
57 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR))
58 root_node = purple_xmlnode_from_file(dir, "theme.xml", "icon themes", "icon-theme-loader");
60 g_free(filename_full);
61 if (root_node == NULL) {
62 g_free(dir);
63 return NULL;
66 name = purple_xmlnode_get_attrib(root_node, "name");
68 if (name) {
69 /* Parse the tree */
70 sub_node = purple_xmlnode_get_child(root_node, "description");
71 data = purple_xmlnode_get_data(sub_node);
73 if (purple_xmlnode_get_attrib(root_node, "name") != NULL) {
74 theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME,
75 "type", "status-icon",
76 "name", name,
77 "author", purple_xmlnode_get_attrib(root_node, "author"),
78 "image", purple_xmlnode_get_attrib(root_node, "image"),
79 "directory", dir,
80 "description", data, NULL);
82 sub_node = purple_xmlnode_get_child(root_node, "icon");
84 while (sub_node) {
85 pidgin_icon_theme_set_icon(theme,
86 purple_xmlnode_get_attrib(sub_node, "id"),
87 purple_xmlnode_get_attrib(sub_node, "file"));
88 sub_node = purple_xmlnode_get_next_twin(sub_node);
93 purple_xmlnode_free(root_node);
94 g_free(data);
95 g_free(dir);
96 return PURPLE_THEME(theme);
99 /******************************************************************************
100 * GObject Stuff
101 *****************************************************************************/
103 static void
104 pidgin_icon_theme_loader_class_init (PidginIconThemeLoaderClass *klass)
106 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass);
108 loader_klass->purple_theme_loader_build = pidgin_icon_loader_build;
112 GType
113 pidgin_icon_theme_loader_get_type (void)
115 static GType type = 0;
116 if (type == 0) {
117 static const GTypeInfo info = {
118 sizeof(PidginIconThemeLoaderClass),
119 NULL, /* base_init */
120 NULL, /* base_finalize */
121 (GClassInitFunc)pidgin_icon_theme_loader_class_init, /* class_init */
122 NULL, /* class_finalize */
123 NULL, /* class_data */
124 sizeof (PidginIconThemeLoader),
125 0, /* n_preallocs */
126 NULL, /* instance_init */
127 NULL, /* value table */
129 type = g_type_register_static (PURPLE_TYPE_THEME_LOADER,
130 "PidginIconThemeLoader", &info, 0);
132 return type;