[glib] Add ability to get symbolic icon for content type
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add ability to get symbolic icon for content type
- Date: Thu, 30 Aug 2012 15:05:16 +0000 (UTC)
commit 40b4fae42e8c8ad306a1fab93a1e263354fef3d5
Author: William Jon McCann <jmccann redhat com>
Date: Tue Aug 28 19:22:01 2012 -0400
Add ability to get symbolic icon for content type
https://bugzilla.gnome.org/show_bug.cgi?id=682101
docs/reference/gio/gio-sections.txt | 1 +
gio/gcontenttype.c | 79 ++++++++++++++++++++++++++--------
gio/gcontenttype.h | 1 +
gio/gio.symbols | 1 +
gio/glocalfileinfo.c | 75 +++++++++++++++++++++------------
5 files changed, 110 insertions(+), 47 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index dfc79d3..ee72a68 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -1291,6 +1291,7 @@ g_content_type_is_unknown
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_can_be_executable
g_content_type_from_mime_type
g_content_type_guess
diff --git a/gio/gcontenttype.c b/gio/gcontenttype.c
index 2fd9ea8..3ada6f0 100644
--- a/gio/gcontenttype.c
+++ b/gio/gcontenttype.c
@@ -393,34 +393,43 @@ g_content_type_get_mime_type (const char *type)
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 = '-';
@@ -432,10 +441,10 @@ g_content_type_get_icon (const gchar *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 ("-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;
@@ -460,6 +469,38 @@ g_content_type_get_icon (const gchar *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)
+{
+ 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
*
diff --git a/gio/gcontenttype.h b/gio/gcontenttype.h
index 959e170..5e3d3ce 100644
--- a/gio/gcontenttype.h
+++ b/gio/gcontenttype.h
@@ -39,6 +39,7 @@ gboolean g_content_type_is_unknown (const gchar *type);
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);
gboolean g_content_type_can_be_executable (const gchar *type);
gchar * g_content_type_from_mime_type (const gchar *mime_type);
diff --git a/gio/gio.symbols b/gio/gio.symbols
index e366d9c..9b90a36 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -161,6 +161,7 @@ g_content_type_is_unknown
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_can_be_executable
g_content_type_from_mime_type
g_content_type_guess
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 0d4c1b7..ec1b936 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -1505,6 +1505,40 @@ get_icon_name (const char *path,
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,
@@ -1666,46 +1700,31 @@ _g_local_file_info_get (const char *basename,
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]