GNOME Bugzilla – Bug 683744
have a way to get the generic icon name for a mime type
Last modified: 2012-09-13 16:51:02 UTC
We currently compute generic icon names for mime types during the icon generation but in some cases it would be useful to get this information without making an icon.
Created attachment 223948 [details] [review] Add api to get the generic icon name for a mime type
Review of attachment 223948 [details] [review]: ::: gio/gcontenttype.c @@ +423,3 @@ G_LOCK (gio_xdgmime); xdg_mimetype_icon = g_strdup_printf (file_template, xdg_mime_get_icon (type)); + xdg_mimetype_generic_icon = g_content_type_get_generic_icon_name (type); I think the new function should be changed to take the gio_xdgmime lock like we do here (and so it should be called either before taking this lock or after we unlock it). @@ +443,3 @@ + if (generic_mimetype_icon) + icon_names[n++] = generic_mimetype_icon; AFAICS there is a little difference between the previous implementation and your version, which is previously, if a generic-icon was specified in the XDG shared mime info, we would append both that and the generic suffix version, whereas now we only append the latter if there's no generic-icon coming from XDG. I think the change is fine, since the spec says this [1], but I wonder if we should try to keep the old behavior here. [1] "If this element is not specified then the mimetype is used to generate the generic icon by using the top-level media type (e.g. "video" in "video/ogg") and appending "-x-generic" (i.e. "video-x-generic" in the previous example). Only one generic-icon element is allowed." @@ +492,3 @@ + * @type: a content type string + * + * Gets the generic icon name for a content type. I think it'd be nice to have a brief description here of what a generic icon for a content type is, maybe with a link to the shared-mime-info specification. @@ +503,3 @@ + gchar *icon_name; + + * or %NULL if unknown. This should take the gio_xdgmime lock.
Created attachment 223963 [details] [review] Add api to get the generic icon name for a mime type
Review of attachment 223963 [details] [review]: Patch looks good to me now.
Review of attachment 223963 [details] [review]: Good to commit with the two changes below. ::: gio/gcontenttype.c @@ +498,3 @@ + * + * Returns: (allow-none): the registered generic icon name for the given @type, + * or %NULL if unknown. Would be good to say 'Free with g_free()' for the return value Also add: Since: 2.34 ::: gio/gcontenttype.h @@ +41,3 @@ GIcon * g_content_type_get_icon (const gchar *type); GIcon * g_content_type_get_symbolic_icon (const gchar *type); +gchar * g_content_type_get_generic_icon_name (const gchar *type); Prepend GLIB_AVAILABLE_IN_2_34 here
Attachment 223963 [details] pushed as cc3238a - Add api to get the generic icon name for a mime type