Add purple_util_write_data_to_*_file declarations
[pidgin-git.git] / pidgin / gtkicon-theme-loader.c
bloba7c64104be98acc8a3a0f2a03752866f99a7b7db
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 * Icon Theme Builder
31 *****************************************************************************/
33 static PurpleTheme *
34 pidgin_icon_loader_build(const gchar *theme_dir)
36 PurpleXmlNode *root_node = NULL, *sub_node;
37 gchar *dir, *filename_full, *data = NULL;
38 PidginIconTheme *theme = NULL;
39 const gchar *name;
41 /* Find the theme file */
42 g_return_val_if_fail(theme_dir != NULL, NULL);
43 dir = g_build_filename(theme_dir, "purple", "status-icon", NULL);
44 filename_full = g_build_filename(dir, "theme.xml", NULL);
46 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR))
47 root_node = purple_xmlnode_from_file(dir, "theme.xml", "icon themes", "icon-theme-loader");
49 g_free(filename_full);
50 if (root_node == NULL) {
51 g_free(dir);
52 return NULL;
55 name = purple_xmlnode_get_attrib(root_node, "name");
57 if (name) {
58 /* Parse the tree */
59 sub_node = purple_xmlnode_get_child(root_node, "description");
60 data = purple_xmlnode_get_data(sub_node);
62 if (purple_xmlnode_get_attrib(root_node, "name") != NULL) {
63 theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME,
64 "type", "status-icon",
65 "name", name,
66 "author", purple_xmlnode_get_attrib(root_node, "author"),
67 "image", purple_xmlnode_get_attrib(root_node, "image"),
68 "directory", dir,
69 "description", data, NULL);
71 sub_node = purple_xmlnode_get_child(root_node, "icon");
73 while (sub_node) {
74 pidgin_icon_theme_set_icon(theme,
75 purple_xmlnode_get_attrib(sub_node, "id"),
76 purple_xmlnode_get_attrib(sub_node, "file"));
77 sub_node = purple_xmlnode_get_next_twin(sub_node);
82 purple_xmlnode_free(root_node);
83 g_free(data);
84 return PURPLE_THEME(theme);
87 /******************************************************************************
88 * GObject Stuff
89 *****************************************************************************/
91 static void
92 pidgin_icon_theme_loader_class_init (PidginIconThemeLoaderClass *klass)
94 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass);
96 loader_klass->purple_theme_loader_build = pidgin_icon_loader_build;
100 GType
101 pidgin_icon_theme_loader_get_type (void)
103 static GType type = 0;
104 if (type == 0) {
105 static const GTypeInfo info = {
106 sizeof(PidginIconThemeLoaderClass),
107 NULL, /* base_init */
108 NULL, /* base_finalize */
109 (GClassInitFunc)pidgin_icon_theme_loader_class_init, /* class_init */
110 NULL, /* class_finalize */
111 NULL, /* class_data */
112 sizeof (PidginIconThemeLoader),
113 0, /* n_preallocs */
114 NULL, /* instance_init */
115 NULL, /* value table */
117 type = g_type_register_static (PURPLE_TYPE_THEME_LOADER,
118 "PidginIconThemeLoader", &info, 0);
120 return type;