mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 18:52:09 +01:00
gio: Show icons based on file's mime type on OS X
The patch basically just grabs the implementation of g_content_type_get_icon_internal() from gcontenttype.c - the only difference is that it first converts UTI to MIME using g_content_type_get_mime_type() and at the end frees this temporary MIME type. https://bugzilla.gnome.org/show_bug.cgi?id=788936
This commit is contained in:
parent
9cb584dd98
commit
656e614da5
@ -192,25 +192,59 @@ g_content_type_get_description (const gchar *type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GIcon *
|
static GIcon *
|
||||||
g_content_type_get_icon_internal (const gchar *type,
|
g_content_type_get_icon_internal (const gchar *uti,
|
||||||
gboolean symbolic)
|
gboolean symbolic)
|
||||||
{
|
{
|
||||||
GIcon *icon = NULL;
|
char *mimetype_icon;
|
||||||
gchar *name;
|
char *type;
|
||||||
|
char *generic_mimetype_icon = NULL;
|
||||||
|
char *q;
|
||||||
|
char *icon_names[6];
|
||||||
|
int n = 0;
|
||||||
|
GIcon *themed_icon;
|
||||||
|
const char *xdg_icon;
|
||||||
|
int i;
|
||||||
|
|
||||||
g_return_val_if_fail (type != NULL, NULL);
|
g_return_val_if_fail (uti != NULL, NULL);
|
||||||
|
|
||||||
/* TODO: Show mimetype icons. */
|
type = g_content_type_get_mime_type (uti);
|
||||||
if (g_content_type_can_be_executable (type))
|
|
||||||
name = "gtk-execute";
|
|
||||||
else if (g_content_type_is_a (type, "public.directory"))
|
|
||||||
name = symbolic ? "inode-directory-symbolic" : "inode-directory";
|
|
||||||
else
|
|
||||||
name = "gtk-file";
|
|
||||||
|
|
||||||
icon = g_themed_icon_new_with_default_fallbacks (name);
|
G_LOCK (gio_xdgmime);
|
||||||
|
xdg_icon = xdg_mime_get_icon (type);
|
||||||
|
G_UNLOCK (gio_xdgmime);
|
||||||
|
|
||||||
return icon;
|
if (xdg_icon)
|
||||||
|
icon_names[n++] = g_strdup (xdg_icon);
|
||||||
|
|
||||||
|
mimetype_icon = g_strdup (type);
|
||||||
|
while ((q = strchr (mimetype_icon, '/')) != NULL)
|
||||||
|
*q = '-';
|
||||||
|
|
||||||
|
icon_names[n++] = mimetype_icon;
|
||||||
|
|
||||||
|
generic_mimetype_icon = g_content_type_get_generic_icon_name (type);
|
||||||
|
if (generic_mimetype_icon)
|
||||||
|
icon_names[n++] = generic_mimetype_icon;
|
||||||
|
|
||||||
|
if (symbolic)
|
||||||
|
{
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
icon_names[n + i] = icon_names[i];
|
||||||
|
icon_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
n += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
themed_icon = g_themed_icon_new_from_names (icon_names, n);
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
g_free (icon_names[i]);
|
||||||
|
|
||||||
|
g_free(type);
|
||||||
|
|
||||||
|
return themed_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
GIcon *
|
GIcon *
|
||||||
|
@ -233,8 +233,12 @@ test_icon (void)
|
|||||||
const gchar *const *names;
|
const gchar *const *names;
|
||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
|
#ifdef __APPLE__
|
||||||
|
g_assert (g_strv_contains (names, "text-*"));
|
||||||
|
#else
|
||||||
g_assert (g_strv_contains (names, "text-plain"));
|
g_assert (g_strv_contains (names, "text-plain"));
|
||||||
g_assert (g_strv_contains (names, "text-x-generic"));
|
g_assert (g_strv_contains (names, "text-x-generic"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
@ -248,7 +252,9 @@ test_icon (void)
|
|||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
g_assert (g_strv_contains (names, "application-rtf"));
|
g_assert (g_strv_contains (names, "application-rtf"));
|
||||||
|
#ifndef __APPLE__
|
||||||
g_assert (g_strv_contains (names, "x-office-document"));
|
g_assert (g_strv_contains (names, "x-office-document"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
@ -269,10 +275,15 @@ test_symbolic_icon (void)
|
|||||||
const gchar *const *names;
|
const gchar *const *names;
|
||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
|
#ifdef __APPLE__
|
||||||
|
g_assert (g_strv_contains (names, "text-*-symbolic"));
|
||||||
|
g_assert (g_strv_contains (names, "text-*"));
|
||||||
|
#else
|
||||||
g_assert (g_strv_contains (names, "text-plain-symbolic"));
|
g_assert (g_strv_contains (names, "text-plain-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "text-x-generic-symbolic"));
|
g_assert (g_strv_contains (names, "text-x-generic-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "text-plain"));
|
g_assert (g_strv_contains (names, "text-plain"));
|
||||||
g_assert (g_strv_contains (names, "text-x-generic"));
|
g_assert (g_strv_contains (names, "text-x-generic"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
@ -286,9 +297,11 @@ test_symbolic_icon (void)
|
|||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
g_assert (g_strv_contains (names, "application-rtf-symbolic"));
|
g_assert (g_strv_contains (names, "application-rtf-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "x-office-document-symbolic"));
|
|
||||||
g_assert (g_strv_contains (names, "application-rtf"));
|
g_assert (g_strv_contains (names, "application-rtf"));
|
||||||
|
#ifndef __APPLE__
|
||||||
|
g_assert (g_strv_contains (names, "x-office-document-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "x-office-document"));
|
g_assert (g_strv_contains (names, "x-office-document"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
@ -334,8 +347,10 @@ test_type_is_a_special_case (void)
|
|||||||
/* Everything but the inode type is application/octet-stream */
|
/* Everything but the inode type is application/octet-stream */
|
||||||
res = g_content_type_is_a ("inode/directory", "application/octet-stream");
|
res = g_content_type_is_a ("inode/directory", "application/octet-stream");
|
||||||
g_assert_false (res);
|
g_assert_false (res);
|
||||||
|
#ifndef __APPLE__
|
||||||
res = g_content_type_is_a ("anything", "application/octet-stream");
|
res = g_content_type_is_a ("anything", "application/octet-stream");
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user