comparison libpurple/sound-loader.c @ 25122:9525fb966efb

theme loader cleanup, and remove a few warnings
author Justin Rodriguez <ffdragon@soc.pidgin.im>
date Tue, 26 Aug 2008 08:28:25 +0000
parents b37ccfd1697b
children
comparison
equal deleted inserted replaced
25121:b37ccfd1697b 25122:9525fb966efb
24 #include "sound-loader.h" 24 #include "sound-loader.h"
25 #include "sound-theme.h" 25 #include "sound-theme.h"
26 #include "util.h" 26 #include "util.h"
27 #include "xmlnode.h" 27 #include "xmlnode.h"
28 28
29 /******************************************************************************
30 * Globals
31 *****************************************************************************/
32 /***************************************************************************** 29 /*****************************************************************************
33 * Sound Theme Builder 30 * Sound Theme Builder
34 *****************************************************************************/ 31 *****************************************************************************/
35 32
36 static PurpleTheme * 33 static PurpleTheme *
37 purple_sound_loader_build(const gchar *dir) 34 purple_sound_loader_build(const gchar *dir)
38 { 35 {
39 xmlnode *root_node, *sub_node; 36 xmlnode *root_node = NULL, *sub_node;
40 gchar *filename, *filename_full, *data; 37 gchar *filename_full, *data;
41 GDir *gdir;
42 PurpleSoundTheme *theme = NULL; 38 PurpleSoundTheme *theme = NULL;
43 39
44 /* Find the theme file */ 40 /* Find the theme file */
45 gdir = g_dir_open(dir, 0, NULL); 41 g_return_val_if_fail(dir != NULL, NULL);
46 g_return_val_if_fail(gdir != NULL, NULL); 42 filename_full = g_build_filename(dir, "theme.xml", NULL);
47 43
48 while ((filename = g_strdup(g_dir_read_name(gdir))) != NULL && ! g_str_has_suffix(filename, ".xml")) 44 if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR))
49 g_free(filename); 45 root_node = xmlnode_from_file(dir, "theme.xml", "sound themes", "sound-loader");
50
51 g_return_val_if_fail(filename != NULL, NULL);
52
53 /* Build the xml tree */
54 filename_full = g_build_filename(dir, filename, NULL);
55 46
56 root_node = xmlnode_from_file(dir, filename, "sound themes", "sound-loader"); 47 g_free(filename_full);
57 g_return_val_if_fail(root_node != NULL, NULL); 48 g_return_val_if_fail(root_node != NULL, NULL);
58 49
59 /* Parse the tree */ 50 /* Parse the tree */
60 sub_node = xmlnode_get_child(root_node, "description"); 51 sub_node = xmlnode_get_child(root_node, "description");
61 data = xmlnode_get_data(sub_node); 52 data = xmlnode_get_data(sub_node);
66 "name", xmlnode_get_attrib(root_node, "name"), 57 "name", xmlnode_get_attrib(root_node, "name"),
67 "author", xmlnode_get_attrib(root_node, "author"), 58 "author", xmlnode_get_attrib(root_node, "author"),
68 "image", xmlnode_get_attrib(root_node, "image"), 59 "image", xmlnode_get_attrib(root_node, "image"),
69 "directory", dir, 60 "directory", dir,
70 "description", data, NULL); 61 "description", data, NULL);
71
72 xmlnode_free(sub_node);
73 62
74 while ((sub_node = xmlnode_get_child(root_node, "event")) != NULL){ 63 sub_node = xmlnode_get_child(root_node, "event");
64
65 while (sub_node) {
75 purple_sound_theme_set_file(theme, 66 purple_sound_theme_set_file(theme,
76 xmlnode_get_attrib(sub_node, "name"), 67 xmlnode_get_attrib(sub_node, "name"),
77 xmlnode_get_attrib(sub_node, "file")); 68 xmlnode_get_attrib(sub_node, "file"));
78 xmlnode_free(sub_node); 69 sub_node = xmlnode_get_next_twin(sub_node);
79 } 70 }
80 } 71 }
81 72
82 xmlnode_free(root_node); 73 xmlnode_free(root_node);
83 g_dir_close(gdir);
84 g_free(filename_full);
85 g_free(data); 74 g_free(data);
86 return PURPLE_THEME(theme); 75 return PURPLE_THEME(theme);
87 } 76 }
88 77
89 /****************************************************************************** 78 /******************************************************************************
90 * GObject Stuff 79 * GObject Stuff
91 *****************************************************************************/ 80 *****************************************************************************/
92 81
93 static void 82 static void
94 purple_sound_theme_loader_class_init (PurpleSoundThemeLoaderClass *klass) 83 purple_sound_theme_loader_class_init(PurpleSoundThemeLoaderClass *klass)
95 { 84 {
96 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass); 85 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass);
97 86
98 loader_klass->purple_theme_loader_build = purple_sound_loader_build; 87 loader_klass->purple_theme_loader_build = purple_sound_loader_build;
99 } 88 }
100 89
101 90
102 GType 91 GType
103 purple_sound_theme_loader_get_type (void) 92 purple_sound_theme_loader_get_type(void)
104 { 93 {
105 static GType type = 0; 94 static GType type = 0;
106 if (type == 0) { 95 if (type == 0) {
107 static const GTypeInfo info = { 96 static const GTypeInfo info = {
108 sizeof (PurpleSoundThemeLoaderClass), 97 sizeof (PurpleSoundThemeLoaderClass),
114 sizeof (PurpleSoundThemeLoader), 103 sizeof (PurpleSoundThemeLoader),
115 0, /* n_preallocs */ 104 0, /* n_preallocs */
116 NULL, /* instance_init */ 105 NULL, /* instance_init */
117 NULL, /* value table */ 106 NULL, /* value table */
118 }; 107 };
119 type = g_type_register_static (PURPLE_TYPE_THEME_LOADER, 108 type = g_type_register_static(PURPLE_TYPE_THEME_LOADER,
120 "PurpleSoundThemeLoader", 109 "PurpleSoundThemeLoader",
121 &info, 0); 110 &info, 0);
122 } 111 }
123 return type; 112 return type;
124 } 113 }