After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 683744 - have a way to get the generic icon name for a mime type
have a way to get the generic icon name for a mime type
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 683722
 
 
Reported: 2012-09-10 19:15 UTC by William Jon McCann
Modified: 2012-09-13 16:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add api to get the generic icon name for a mime type (5.39 KB, patch)
2012-09-10 19:17 UTC, William Jon McCann
needs-work Details | Review
Add api to get the generic icon name for a mime type (5.61 KB, patch)
2012-09-10 22:10 UTC, William Jon McCann
committed Details | Review

Description William Jon McCann 2012-09-10 19:15:09 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.
Comment 1 William Jon McCann 2012-09-10 19:17:34 UTC
Created attachment 223948 [details] [review]
Add api to get the generic icon name for a mime type
Comment 2 Cosimo Cecchi 2012-09-10 21:32:30 UTC
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.
Comment 3 William Jon McCann 2012-09-10 22:10:54 UTC
Created attachment 223963 [details] [review]
Add api to get the generic icon name for a mime type
Comment 4 Cosimo Cecchi 2012-09-10 22:22:15 UTC
Review of attachment 223963 [details] [review]:

Patch looks good to me now.
Comment 5 Matthias Clasen 2012-09-11 02:46:49 UTC
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
Comment 6 William Jon McCann 2012-09-13 16:50:59 UTC
Attachment 223963 [details] pushed as cc3238a - Add api to get the generic icon name for a mime type