This is a sample implementation to demonstrate how to load the icon for a given MIME-type using various fallbacks (using both new standard icon names, as used by ROX currently, and old-style gnome icon names). The implementation is easy and very straight-forward.
Add KDE icon name support (most probably using a simple hash table
based translation)?
static FilerIconCacheEntry* filer_mime_icon_load (FilerIcon *icon, FilerIconSize size) { FilerIconCacheEntry *entry; FilerMimeIcon *mime_icon = FILER_MIME_ICON (icon); const gchar *sp; gchar name[256]; gchar *tp; /* try full qualified icon name first (standard) */ for (sp = "mime-", tp = name; *sp != '\0'; *tp++ = *sp++); for (sp = mime_icon->name; *sp != '\0' && tp < name + 255; ++sp, ++tp) *tp = (G_UNLIKELY (*sp == '/')) ? ':' : *sp; *tp = '\0'; entry = filer_mime_icon_tryload (mime_icon, size, name); if (entry == NULL) { /* retry with only the media icon name (standard) */ for (tp = name + 6; *tp != '\0'; ++tp) if (*tp == ':') { *tp = '\0'; break; } entry = filer_mime_icon_tryload (mime_icon, size, name); if (entry == NULL) { /* try full qualified icon name (gnome) */ for (sp = "gnome-mime-", tp = name; *sp != '\0'; *tp++ = *sp++); for (sp = mime_icon->name; *sp != '\0' && tp < name + 255; ++sp, ++tp) *tp = (G_UNLIKELY (*sp == '/')) ? '-' : *sp; *tp = '\0'; entry = filer_mime_icon_tryload (mime_icon, size, name); if (entry == NULL) { /* retry with only the media icon name (gnome) */ for (sp = mime_icon->name, tp = name + 11; *sp != '\0' && tp < name + 255; ++sp, ++tp) if (G_UNLIKELY (*sp == '/')) break; else *tp = *sp; *tp = '\0'; entry = filer_mime_icon_tryload (mime_icon, size, name); if (entry == NULL) { /* retry with application/octect-stream (standard) */ entry = filer_mime_icon_tryload (mime_icon, size, "mime-application:octet-stream"); if (entry == NULL) { /* ...and the gnome application/octect-stream */ entry = filer_mime_icon_tryload (mime_icon, size, "gnome-mime-application-octet-stream"); } } } } } #ifdef FILER_DEBUG_INTERNALS g_assert (FILER_IS_ICON_CACHE_ENTRY (entry)); #endif return entry; } static FilerIconCacheEntry* filer_mime_icon_tryload (FilerMimeIcon *mime_icon, FilerIconSize size, const gchar *name) { FilerIconCacheEntry *entry; GdkPixbuf *pixbuf; entry = filer_icon_cache_lookup (FILER_ICON (mime_icon)->cache, size, FILER_ICON_THEMED, name); if (entry == NULL) { pixbuf = gtk_icon_theme_load_icon (mime_icon->theme, name, filer_icon_sizes[size], 0, NULL); if (pixbuf == NULL) return NULL; entry = filer_icon_cache_insert (FILER_ICON (mime_icon)->cache, size, FILER_ICON_THEMED, name, pixbuf); } return entry; }