pidgin/gtkblist-theme-loader.c

branch
next.minor
changeset 25863
b724badf6cd2
parent 24377
8d0bfda8402d
child 25875
a98b16817658
equal deleted inserted replaced
25862:57228df2541f 25863:b724badf6cd2
40 pidgin_blist_loader_build(const gchar *dir) 40 pidgin_blist_loader_build(const gchar *dir)
41 { 41 {
42 xmlnode *root_node = NULL, *sub_node, *sub_sub_node; 42 xmlnode *root_node = NULL, *sub_node, *sub_sub_node;
43 gchar *filename_full, *data; 43 gchar *filename_full, *data;
44 const gchar *temp; 44 const gchar *temp;
45 gboolean sucess = TRUE; 45 gboolean success = TRUE;
46 GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *contact_color; 46 GdkColor *bgcolor, *expanded_bgcolor, *collapsed_bgcolor, *contact_color;
47 GdkColor color; 47 GdkColor color;
48 FontColorPair *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *status; 48 FontColorPair *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status;
49 PidginBlistLayout *layout; 49 PidginBlistLayout *layout;
50 PidginBlistTheme *theme; 50 PidginBlistTheme *theme;
51 51
52 /* Find the theme file */ 52 /* Find the theme file */
53 g_return_val_if_fail(dir != NULL, NULL); 53 g_return_val_if_fail(dir != NULL, NULL);
77 online = g_new0(FontColorPair, 1); 77 online = g_new0(FontColorPair, 1);
78 away = g_new0(FontColorPair, 1); 78 away = g_new0(FontColorPair, 1);
79 offline = g_new0(FontColorPair, 1); 79 offline = g_new0(FontColorPair, 1);
80 idle = g_new0(FontColorPair, 1); 80 idle = g_new0(FontColorPair, 1);
81 message = g_new0(FontColorPair, 1); 81 message = g_new0(FontColorPair, 1);
82 message_nick_said = g_new0(FontColorPair, 1);
82 status = g_new0(FontColorPair, 1); 83 status = g_new0(FontColorPair, 1);
83 84
84 /* <blist> */ 85 /* <blist> */
85 if ((sucess = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) { 86 if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) {
86 if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, bgcolor)) 87 if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, bgcolor))
87 gdk_colormap_alloc_color(gdk_colormap_get_system(), bgcolor, FALSE, TRUE); 88 gdk_colormap_alloc_color(gdk_colormap_get_system(), bgcolor, FALSE, TRUE);
88 else { 89 else {
89 g_free(bgcolor); 90 g_free(bgcolor);
90 bgcolor = NULL; 91 bgcolor = NULL;
91 } 92 }
92 } 93 }
93 94
94 /* <groups> */ 95 /* <groups> */
95 if ((sucess = sucess && (sub_node = xmlnode_get_child(root_node, "groups")) != NULL 96 if ((success = (success && (sub_node = xmlnode_get_child(root_node, "groups")) != NULL
96 && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)) { 97 && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL))) {
97 98
98 expanded->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 99 expanded->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
99 100
100 if ((temp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(temp, &color)) 101 if ((temp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(temp, &color))
101 expanded->color = g_strdup(temp); 102 expanded->color = g_strdup(temp);
108 g_free(expanded_bgcolor); 109 g_free(expanded_bgcolor);
109 expanded_bgcolor = NULL; 110 expanded_bgcolor = NULL;
110 } 111 }
111 } 112 }
112 113
113 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) { 114 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL))) {
114 115
115 collapsed->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 116 collapsed->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
116 117
117 if((temp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(temp, &color)) 118 if((temp = xmlnode_get_attrib(sub_sub_node, "text_color")) != NULL && gdk_color_parse(temp, &color))
118 collapsed->color = g_strdup(temp); 119 collapsed->color = g_strdup(temp);
125 collapsed_bgcolor = NULL; 126 collapsed_bgcolor = NULL;
126 } 127 }
127 } 128 }
128 129
129 /* <buddys> */ 130 /* <buddys> */
130 if ((sucess = sucess && (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL && 131 if ((success = (success && (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL &&
131 (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)) { 132 (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL))) {
132 133
133 layout->status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0; 134 layout->status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0;
134 layout->text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1; 135 layout->text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1;
135 layout->emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2; 136 layout->emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2;
136 layout->protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3; 137 layout->protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3;
137 layout->buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4; 138 layout->buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4;
138 layout->show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1; 139 layout->show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1;
139 } 140 }
140 141
141 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL)) { 142 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) {
142 if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), contact_color)) 143 if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), contact_color))
143 gdk_colormap_alloc_color(gdk_colormap_get_system(), contact_color, FALSE, TRUE); 144 gdk_colormap_alloc_color(gdk_colormap_get_system(), contact_color, FALSE, TRUE);
144 else { 145 else {
145 g_free(contact_color); 146 g_free(contact_color);
146 contact_color = NULL; 147 contact_color = NULL;
147 } 148 }
148 } 149 }
149 150
150 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "contact_text")) != NULL)) { 151 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "contact_text")) != NULL))) {
151 contact->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 152 contact->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
152 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 153 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
153 contact->color = g_strdup(temp); 154 contact->color = g_strdup(temp);
154 else contact->color = g_strdup(DEFAULT_TEXT_COLOR); 155 else contact->color = g_strdup(DEFAULT_TEXT_COLOR);
155 } 156 }
156 157
157 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "online_text")) != NULL)) { 158 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "online_text")) != NULL))) {
158 online->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 159 online->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
159 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 160 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
160 online->color = g_strdup(temp); 161 online->color = g_strdup(temp);
161 else online->color = g_strdup(DEFAULT_TEXT_COLOR); 162 else online->color = g_strdup(DEFAULT_TEXT_COLOR);
162 } 163 }
163 164
164 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "away_text")) != NULL)) { 165 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "away_text")) != NULL))) {
165 away->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 166 away->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
166 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 167 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
167 away->color = g_strdup(temp); 168 away->color = g_strdup(temp);
168 else away->color = g_strdup(DEFAULT_TEXT_COLOR); 169 else away->color = g_strdup(DEFAULT_TEXT_COLOR);
169 } 170 }
170 171
171 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "offline_text")) != NULL)) { 172 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "offline_text")) != NULL))) {
172 offline->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 173 offline->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
173 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 174 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
174 online->color = g_strdup(temp); 175 online->color = g_strdup(temp);
175 else online->color = g_strdup(DEFAULT_TEXT_COLOR); 176 else online->color = g_strdup(DEFAULT_TEXT_COLOR);
176 } 177 }
177 178
178 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "idle_text")) != NULL)) { 179 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "idle_text")) != NULL))) {
179 idle->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 180 idle->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
180 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 181 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
181 idle->color = g_strdup(temp); 182 idle->color = g_strdup(temp);
182 else online->color = g_strdup(DEFAULT_TEXT_COLOR); 183 else online->color = g_strdup(DEFAULT_TEXT_COLOR);
183 } 184 }
184 185
185 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "message_text")) != NULL)) { 186 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "message_text")) != NULL))) {
186 message->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 187 message->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
187 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 188 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
188 message->color = g_strdup(temp); 189 message->color = g_strdup(temp);
189 else message->color = g_strdup(DEFAULT_TEXT_COLOR); 190 else message->color = g_strdup(DEFAULT_TEXT_COLOR);
190 } 191 }
191 192
192 if ((sucess = sucess && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "status_text")) != NULL)) { 193 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "message_nick_said_text")) != NULL))) {
194 message_nick_said->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
195 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
196 message_nick_said->color = g_strdup(temp);
197 else message_nick_said->color = g_strdup(DEFAULT_TEXT_COLOR);
198 }
199
200 if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "status_text")) != NULL))) {
193 status->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font")); 201 status->font = g_strdup(xmlnode_get_attrib(sub_sub_node, "font"));
194 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color)) 202 if(gdk_color_parse(temp = xmlnode_get_attrib(sub_sub_node, "color"), &color))
195 status->color = g_strdup(temp); 203 status->color = g_strdup(temp);
196 else status->color = g_strdup(DEFAULT_TEXT_COLOR); 204 else status->color = g_strdup(DEFAULT_TEXT_COLOR);
197 } 205 }
198 206
199 /* name is required for theme manager */ 207 /* name is required for theme manager */
200 sucess = sucess && xmlnode_get_attrib(root_node, "name") != NULL; 208 success = (success && xmlnode_get_attrib(root_node, "name") != NULL);
201 209
202 /* the new theme */ 210 /* the new theme */
203 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME, 211 theme = g_object_new(PIDGIN_TYPE_BLIST_THEME,
204 "type", "blist", 212 "type", "blist",
205 "name", xmlnode_get_attrib(root_node, "name"), 213 "name", xmlnode_get_attrib(root_node, "name"),
218 "online", online, 226 "online", online,
219 "away", away, 227 "away", away,
220 "offline", offline, 228 "offline", offline,
221 "idle", idle, 229 "idle", idle,
222 "message", message, 230 "message", message,
231 "message_nick_said", message_nick_said,
223 "status", status, NULL); 232 "status", status, NULL);
224 233
225 xmlnode_free(root_node); 234 xmlnode_free(root_node);
226 g_free(data); 235 g_free(data);
227 236
228 /* malformed xml file - also frees all partial data*/ 237 /* malformed xml file - also frees all partial data*/
229 if (!sucess) { 238 if (!success) {
230 g_object_unref(theme); 239 g_object_unref(theme);
231 theme = NULL; 240 theme = NULL;
232 } 241 }
233 242
234 return PURPLE_THEME(theme); 243 return PURPLE_THEME(theme);

mercurial