From 47b8809e176f4bc7f22768cb45fec47280c4242f Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 9 Jan 2008 15:20:49 +0000 Subject: [PATCH] Add g_themed_icon_new_with_default_fallbacks 2008-01-09 Alexander Larsson * gio.symbols: * gthemedicon.[ch]: Add g_themed_icon_new_with_default_fallbacks * gunixmounts.c: Use default fallbacks for icons svn path=/trunk/; revision=6284 --- gio/ChangeLog | 9 +++++++++ gio/gio.symbols | 7 ++++--- gio/gthemedicon.c | 37 +++++++++++++++++++++++++++++++++++++ gio/gthemedicon.h | 1 + gio/gunixmounts.c | 4 ++-- 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/gio/ChangeLog b/gio/ChangeLog index 4a67e8d5c..48c8ac6a3 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,12 @@ +2008-01-09 Alexander Larsson + + * gio.symbols: + * gthemedicon.[ch]: + Add g_themed_icon_new_with_default_fallbacks + + * gunixmounts.c: + Use default fallbacks for icons + 2008-01-09 Alexander Larsson * gio-marshal.list: diff --git a/gio/gio.symbols b/gio/gio.symbols index 20defabf3..5d93b5264 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -609,9 +609,10 @@ g_simple_async_report_gerror_in_idle #if IN_HEADER(__G_THEMED_ICON_H__) #if IN_FILE(__G_THEMED_ICON_C__) g_themed_icon_get_type G_GNUC_CONST -g_themed_icon_new -g_themed_icon_new_from_names -g_themed_icon_get_names +g_themed_icon_new +g_themed_icon_new_with_default_fallbacks +g_themed_icon_new_from_names +g_themed_icon_get_names #endif #endif diff --git a/gio/gthemedicon.c b/gio/gthemedicon.c index 909bc6e3a..fdfbd4347 100644 --- a/gio/gthemedicon.c +++ b/gio/gthemedicon.c @@ -22,6 +22,8 @@ #include +#include + #include "gthemedicon.h" #include "gioalias.h" @@ -141,6 +143,41 @@ g_themed_icon_new_from_names (char **iconnames, return G_ICON (themed); } +GIcon * +g_themed_icon_new_with_default_fallbacks (const char *iconname) +{ + GThemedIcon *themed; + int i, dashes; + const char *p; + char *dashp; + char *last; + + g_return_val_if_fail (iconname != NULL, NULL); + + themed = g_object_new (G_TYPE_THEMED_ICON, NULL); + + dashes = 0; + p = iconname; + while (*p) + { + if (*p == '-') + dashes++; + p++; + } + + themed->names = g_new (char *, dashes + 1 + 1); + i = 0; + themed->names[i++] = last = g_strdup (iconname); + + while ((dashp = strrchr (last, '-')) != NULL) + themed->names[i++] = last = g_strndup (last, dashp - last); + + themed->names[i++] = NULL; + + return G_ICON (themed); +} + + /** * g_themed_icon_get_names: * @icon: a #GThemedIcon. diff --git a/gio/gthemedicon.h b/gio/gthemedicon.h index 7c3a204dd..f649e2d9e 100644 --- a/gio/gthemedicon.h +++ b/gio/gthemedicon.h @@ -49,6 +49,7 @@ typedef struct _GThemedIconClass GThemedIconClass; GType g_themed_icon_get_type (void) G_GNUC_CONST; GIcon *g_themed_icon_new (const char *iconname); +GIcon *g_themed_icon_new_with_default_fallbacks (const char *iconname); GIcon *g_themed_icon_new_from_names (char **iconnames, int len); const char * const *g_themed_icon_get_names (GThemedIcon *icon); diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index 4b26c2b9a..361c0318b 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -1769,7 +1769,7 @@ g_unix_mount_guess_name (GUnixMountEntry *mount_entry) GIcon * g_unix_mount_guess_icon (GUnixMountEntry *mount_entry) { - return g_themed_icon_new (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE)); + return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE)); } /** @@ -1806,7 +1806,7 @@ g_unix_mount_point_guess_name (GUnixMountPoint *mount_point) GIcon * g_unix_mount_point_guess_icon (GUnixMountPoint *mount_point) { - return g_themed_icon_new (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE)); + return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE)); } /**