mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-23 22:16:16 +01:00
Add api to get the generic icon name for a mime type
https://bugzilla.gnome.org/show_bug.cgi?id=683744
This commit is contained in:
parent
8d362a14e4
commit
cc3238a9c9
@ -1292,6 +1292,7 @@ g_content_type_get_description
|
||||
g_content_type_get_mime_type
|
||||
g_content_type_get_icon
|
||||
g_content_type_get_symbolic_icon
|
||||
g_content_type_get_generic_icon_name
|
||||
g_content_type_can_be_executable
|
||||
g_content_type_from_mime_type
|
||||
g_content_type_guess
|
||||
|
@ -399,63 +399,50 @@ g_content_type_get_icon_internal (const gchar *type,
|
||||
gboolean symbolic)
|
||||
{
|
||||
char *mimetype_icon;
|
||||
char *generic_mimetype_icon;
|
||||
char *generic_mimetype_icon = NULL;
|
||||
char *q;
|
||||
char *xdg_mimetype_icon;
|
||||
char *legacy_mimetype_icon;
|
||||
char *xdg_mimetype_generic_icon;
|
||||
char *icon_names[5];
|
||||
int n = 0;
|
||||
const char *p;
|
||||
GIcon *themed_icon;
|
||||
const char *file_template;
|
||||
const char *generic_suffix;
|
||||
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
if (symbolic)
|
||||
{
|
||||
file_template = "%s-symbolic";
|
||||
generic_suffix = "-x-generic-symbolic";
|
||||
}
|
||||
else
|
||||
{
|
||||
file_template = "%s";
|
||||
generic_suffix = "-x-generic";
|
||||
}
|
||||
|
||||
G_LOCK (gio_xdgmime);
|
||||
xdg_mimetype_icon = g_strdup_printf (file_template, xdg_mime_get_icon (type));
|
||||
xdg_mimetype_generic_icon = g_strdup_printf (file_template, xdg_mime_get_generic_icon (type));
|
||||
G_UNLOCK (gio_xdgmime);
|
||||
xdg_mimetype_generic_icon = g_content_type_get_generic_icon_name (type);
|
||||
|
||||
mimetype_icon = g_strdup_printf (file_template, type);
|
||||
if (xdg_mimetype_generic_icon)
|
||||
generic_mimetype_icon = g_strdup_printf (file_template, xdg_mimetype_generic_icon);
|
||||
|
||||
while ((q = strchr (mimetype_icon, '/')) != NULL)
|
||||
*q = '-';
|
||||
|
||||
p = strchr (type, '/');
|
||||
if (p == NULL)
|
||||
p = type + strlen (type);
|
||||
|
||||
/* Not all icons have migrated to the new icon theme spec, look for old names too */
|
||||
legacy_mimetype_icon = g_strconcat ("gnome-mime-", mimetype_icon, NULL);
|
||||
|
||||
generic_mimetype_icon = g_malloc (p - type + strlen (generic_suffix) + 1);
|
||||
memcpy (generic_mimetype_icon, type, p - type);
|
||||
memcpy (generic_mimetype_icon + (p - type), generic_suffix, strlen (generic_suffix));
|
||||
generic_mimetype_icon[(p - type) + strlen (generic_suffix)] = 0;
|
||||
|
||||
if (xdg_mimetype_icon)
|
||||
icon_names[n++] = xdg_mimetype_icon;
|
||||
|
||||
icon_names[n++] = mimetype_icon;
|
||||
icon_names[n++] = legacy_mimetype_icon;
|
||||
|
||||
if (xdg_mimetype_generic_icon)
|
||||
icon_names[n++] = xdg_mimetype_generic_icon;
|
||||
|
||||
icon_names[n++] = generic_mimetype_icon;
|
||||
if (generic_mimetype_icon)
|
||||
icon_names[n++] = generic_mimetype_icon;
|
||||
|
||||
themed_icon = g_themed_icon_new_from_names (icon_names, n);
|
||||
|
||||
@ -500,6 +487,52 @@ g_content_type_get_symbolic_icon (const gchar *type)
|
||||
return g_content_type_get_icon_internal (type, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_generic_icon_name:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the generic icon name for a content type.
|
||||
*
|
||||
* See the <ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</ulink>
|
||||
* specification for more on the generic icon name.
|
||||
*
|
||||
* Returns: (allow-none): the registered generic icon name for the given @type,
|
||||
* or %NULL if unknown. Free with g_free()
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_get_generic_icon_name (const gchar *type)
|
||||
{
|
||||
const gchar *xdg_icon_name;
|
||||
gchar *icon_name;
|
||||
|
||||
G_LOCK (gio_xdgmime);
|
||||
xdg_icon_name = xdg_mime_get_generic_icon (type);
|
||||
G_UNLOCK (gio_xdgmime);
|
||||
|
||||
if (!xdg_icon_name)
|
||||
{
|
||||
const char *p;
|
||||
const char *suffix = "-x-generic";
|
||||
|
||||
p = strchr (type, '/');
|
||||
if (p == NULL)
|
||||
p = type + strlen (type);
|
||||
|
||||
icon_name = g_malloc (p - type + strlen (suffix) + 1);
|
||||
memcpy (icon_name, type, p - type);
|
||||
memcpy (icon_name + (p - type), suffix, strlen (suffix));
|
||||
icon_name[(p - type) + strlen (suffix)] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon_name = g_strdup (xdg_icon_name);
|
||||
}
|
||||
|
||||
return icon_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_can_be_executable:
|
||||
* @type: a content type string
|
||||
|
@ -40,6 +40,9 @@ gchar * g_content_type_get_description (const gchar *type);
|
||||
gchar * g_content_type_get_mime_type (const gchar *type);
|
||||
GIcon * g_content_type_get_icon (const gchar *type);
|
||||
GIcon * g_content_type_get_symbolic_icon (const gchar *type);
|
||||
GLIB_AVAILABLE_IN_2_34
|
||||
gchar * g_content_type_get_generic_icon_name (const gchar *type);
|
||||
|
||||
gboolean g_content_type_can_be_executable (const gchar *type);
|
||||
|
||||
gchar * g_content_type_from_mime_type (const gchar *mime_type);
|
||||
|
@ -162,6 +162,7 @@ g_content_type_get_description
|
||||
g_content_type_get_mime_type
|
||||
g_content_type_get_icon
|
||||
g_content_type_get_symbolic_icon
|
||||
g_content_type_get_generic_icon_name
|
||||
g_content_type_can_be_executable
|
||||
g_content_type_from_mime_type
|
||||
g_content_type_guess
|
||||
|
Loading…
Reference in New Issue
Block a user