return g_strdup (type);
}
-/**
- * g_content_type_get_icon:
- * @type: a content type string
- *
- * Gets the icon for a content type.
- *
- * Returns: (transfer full): #GIcon corresponding to the content type. Free the returned
- * object with g_object_unref()
- */
-GIcon *
-g_content_type_get_icon (const gchar *type)
+
+static GIcon *
+g_content_type_get_icon_internal (const gchar *type,
+ gboolean symbolic)
{
- char *mimetype_icon, *generic_mimetype_icon, *q;
- char *xdg_mimetype_icon, *legacy_mimetype_icon;
+ char *mimetype_icon;
+ char *generic_mimetype_icon;
+ 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 (xdg_mime_get_icon (type));
- xdg_mimetype_generic_icon = g_strdup (xdg_mime_get_generic_icon (type));
+ 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);
- mimetype_icon = g_strdup (type);
+ mimetype_icon = g_strdup_printf (file_template, type);
while ((q = strchr (mimetype_icon, '/')) != NULL)
*q = '-';
/* 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 ("-x-generic") + 1);
+ generic_mimetype_icon = g_malloc (p - type + strlen (generic_suffix) + 1);
memcpy (generic_mimetype_icon, type, p - type);
- memcpy (generic_mimetype_icon + (p - type), "-x-generic", strlen ("-x-generic"));
- generic_mimetype_icon[(p - type) + strlen ("-x-generic")] = 0;
+ 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;
}
/**
+ * g_content_type_get_icon:
+ * @type: a content type string
+ *
+ * Gets the icon for a content type.
+ *
+ * Returns: (transfer full): #GIcon corresponding to the content type. Free the returned
+ * object with g_object_unref()
+ */
+GIcon *
+g_content_type_get_icon (const gchar *type)
+{
+ return g_content_type_get_icon_internal (type, FALSE);
+}
+
+/**
+ * g_content_type_get_symbolic_icon:
+ * @type: a content type string
+ *
+ * Gets the symbolic icon for a content type.
+ *
+ * Returns: (transfer full): symbolic #GIcon corresponding to the content type.
+ * Free the returned object with g_object_unref()
+ *
+ * Since: 2.34
+ */
+GIcon *
+g_content_type_get_symbolic_icon (const gchar *type)
+{
+ return g_content_type_get_icon_internal (type, TRUE);
+}
+
+/**
* g_content_type_can_be_executable:
* @type: a content type string
*
return name;
}
+static GIcon *
+get_icon (const char *path,
+ const char *content_type,
+ gboolean is_folder,
+ gboolean use_symbolic)
+{
+ GIcon *icon = NULL;
+ const char *icon_name;
+ gboolean with_fallbacks;
+
+ icon_name = get_icon_name (path, use_symbolic, &with_fallbacks);
+ if (icon_name != NULL)
+ {
+ if (with_fallbacks)
+ icon = g_themed_icon_new_with_default_fallbacks (icon_name);
+ else
+ icon = g_themed_icon_new (icon_name);
+ }
+ else
+ {
+ if (use_symbolic)
+ icon = g_content_type_get_symbolic_icon (content_type);
+ else
+ icon = g_content_type_get_icon (content_type);
+
+ if (G_IS_THEMED_ICON (icon) && is_folder)
+ {
+ g_themed_icon_append_name (G_THEMED_ICON (icon), use_symbolic ? "folder-symbolic" : "folder");
+ }
+ }
+
+ return icon;
+}
+
GFileInfo *
_g_local_file_info_get (const char *basename,
const char *path,
if (content_type)
{
- gboolean use_symbolics = FALSE;
-
g_file_info_set_content_type (info, content_type);
- use_symbolics = _g_file_attribute_matcher_matches_id (attribute_matcher,
- G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON);
- if (use_symbolics ||
- _g_file_attribute_matcher_matches_id (attribute_matcher,
- G_FILE_ATTRIBUTE_ID_STANDARD_ICON))
+ if (_g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_STANDARD_ICON)
+ || _g_file_attribute_matcher_matches_id (attribute_matcher,
+ G_FILE_ATTRIBUTE_ID_STANDARD_SYMBOLIC_ICON))
{
GIcon *icon;
- gboolean with_fallbacks = TRUE;
- const char *icon_name = get_icon_name (path, use_symbolics, &with_fallbacks);
- if (icon_name != NULL)
- {
- if (with_fallbacks)
- icon = g_themed_icon_new_with_default_fallbacks (icon_name);
- else
- icon = g_themed_icon_new (icon_name);
- }
- else
+ /* non symbolic icon */
+ icon = get_icon (path, content_type, S_ISDIR (statbuf.st_mode), FALSE);
+ if (icon != NULL)
{
- icon = g_content_type_get_icon (content_type);
- if (G_IS_THEMED_ICON (icon))
- {
- const char *type_icon = NULL;
-
- if (S_ISDIR (statbuf.st_mode))
- type_icon = "folder";
- if (type_icon)
- g_themed_icon_append_name (G_THEMED_ICON (icon), type_icon);
- }
+ g_file_info_set_icon (info, icon);
+ g_object_unref (icon);
}
+ /* symbolic icon */
+ icon = get_icon (path, content_type, S_ISDIR (statbuf.st_mode), TRUE);
if (icon != NULL)
{
- g_file_info_set_icon (info, icon);
+ g_file_info_set_symbolic_icon (info, icon);
g_object_unref (icon);
}
+
}
g_free (content_type);