pidgin/gtkutils.c

changeset 41067
3d135d1f8b6e
parent 41058
18f3ea2e7e6d
child 41080
e315e317c2de
equal deleted inserted replaced
41066:00e6bda3ef95 41067:3d135d1f8b6e
225 GdkPixbuf * 225 GdkPixbuf *
226 pidgin_create_icon_from_protocol(PurpleProtocol *protocol, 226 pidgin_create_icon_from_protocol(PurpleProtocol *protocol,
227 PidginProtocolIconSize size, 227 PidginProtocolIconSize size,
228 PurpleAccount *account) 228 PurpleAccount *account)
229 { 229 {
230 GInputStream *stream = NULL;
231 GdkPixbuf *pixbuf; 230 GdkPixbuf *pixbuf;
232 const char *protoname = NULL; 231 const char *protoname = NULL;
233 const gchar *icon_name = NULL; 232 const gchar *icon_name = NULL;
234 char *tmp; 233 char *tmp;
235 char *filename = NULL; 234 GtkIconTheme *theme = NULL;
235 gint dimensions = 0;
236
237 theme = gtk_icon_theme_get_default();
238 if(size == PIDGIN_PROTOCOL_ICON_SMALL) {
239 dimensions = 16;
240 } else if(size == PIDGIN_PROTOCOL_ICON_MEDIUM) {
241 dimensions = 22;
242 } else {
243 dimensions = 48;
244 }
236 245
237 /* If the protocol specified an icon-name try to load it from the icon 246 /* If the protocol specified an icon-name try to load it from the icon
238 * theme. 247 * theme.
239 */ 248 */
240 icon_name = purple_protocol_get_icon_name(protocol); 249 icon_name = purple_protocol_get_icon_name(protocol);
241 if(icon_name != NULL) { 250 if(icon_name != NULL) {
242 GtkIconTheme *theme = gtk_icon_theme_get_default();
243 gint dimensions = 48;
244
245 if(size == PIDGIN_PROTOCOL_ICON_SMALL) {
246 dimensions = 16;
247 } else if(size == PIDGIN_PROTOCOL_ICON_MEDIUM) {
248 dimensions = 22;
249 }
250
251 pixbuf = gtk_icon_theme_load_icon(theme, icon_name, dimensions, 251 pixbuf = gtk_icon_theme_load_icon(theme, icon_name, dimensions,
252 GTK_ICON_LOOKUP_FORCE_SIZE, NULL); 252 GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
253 253
254 if(GDK_IS_PIXBUF(pixbuf)) { 254 if(GDK_IS_PIXBUF(pixbuf)) {
255 return pixbuf; 255 return pixbuf;
256 } 256 }
257 257
258 } 258 }
259 259
260 protoname = purple_protocol_get_list_icon(protocol, account, NULL); 260 protoname = purple_protocol_get_list_icon(protocol, account, NULL);
261 if (protoname == NULL) 261 if (protoname == NULL) {
262 return NULL; 262 return NULL;
263 }
263 264
264 /* 265 /*
265 * Status icons will be themeable too, and then it will look up 266 * Status icons will be themeable too, and then it will look up
266 * protoname from the theme 267 * protoname from the theme
267 */ 268 */
268 tmp = g_strconcat("im-", protoname, ".png", NULL); 269 tmp = g_strconcat("im-", protoname, NULL);
269 270 pixbuf = gtk_icon_theme_load_icon(theme, tmp, dimensions,
270 filename = g_build_filename(PURPLE_DATADIR, 271 GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
271 "pidgin", "icons", "hicolor",
272 (size == PIDGIN_PROTOCOL_ICON_SMALL) ? "16x16" :
273 ((size == PIDGIN_PROTOCOL_ICON_MEDIUM) ? "22x22" :
274 "48x48"),
275 "apps", tmp, NULL);
276 g_free(tmp); 272 g_free(tmp);
277
278 pixbuf = pidgin_pixbuf_new_from_file(filename);
279 g_free(filename);
280 273
281 return pixbuf; 274 return pixbuf;
282 } 275 }
283 276
284 static void 277 static void

mercurial