Add shell_texture_cache_load_from_name

Utility function to load a texture for a themed icon from a
string name.
This commit is contained in:
Colin Walters 2009-07-30 00:17:25 -04:00
parent 4495f98dce
commit 5064d873bb
2 changed files with 38 additions and 6 deletions

View File

@ -8,12 +8,12 @@ typedef struct
{ {
ShellTextureCachePolicy policy; ShellTextureCachePolicy policy;
/* These 3 are exclusive */ /* These are exclusive */
GIcon *icon; GIcon *icon;
gchar *uri; gchar *uri;
gchar *thumbnail_uri; gchar *thumbnail_uri;
/* This one is common to all 3 */ /* This one is common to all */
guint size; guint size;
} CacheKey; } CacheKey;
@ -32,14 +32,17 @@ static guint
cache_key_hash (gconstpointer a) cache_key_hash (gconstpointer a)
{ {
CacheKey *akey = (CacheKey *)a; CacheKey *akey = (CacheKey *)a;
guint base_hash;
if (akey->icon) if (akey->icon)
return g_icon_hash (akey->icon) + 31*akey->size; base_hash = g_icon_hash (akey->icon);
else if (akey->uri) else if (akey->uri)
return g_str_hash (akey->uri) + 31*akey->size; base_hash = g_str_hash (akey->uri);
else if (akey->thumbnail_uri) else if (akey->thumbnail_uri)
return g_str_hash (akey->thumbnail_uri) + 31*akey->size; base_hash = g_str_hash (akey->thumbnail_uri);
else
g_assert_not_reached (); g_assert_not_reached ();
return base_hash + 31*akey->size;
} }
static gboolean static gboolean
@ -772,6 +775,31 @@ shell_texture_cache_load_gicon (ShellTextureCache *cache,
return CLUTTER_ACTOR (texture); return CLUTTER_ACTOR (texture);
} }
/**
* shell_texture_cache_load_icon_name:
* @cache: The texture cache instance
* @name: Name of a themed icon
* @size: Size of themed
*
* Load a themed icon into a texture.
*
* Return Value: (transfer none): A new #ClutterTexture for the icon
*/
ClutterActor *
shell_texture_cache_load_icon_name (ShellTextureCache *cache,
const char *name,
gint size)
{
ClutterActor *texture;
GIcon *themed;
themed = g_themed_icon_new (name);
texture = shell_texture_cache_load_gicon (cache, themed, size);
g_object_unref (themed);
return CLUTTER_ACTOR (texture);
}
/** /**
* shell_texture_cache_load_uri: * shell_texture_cache_load_uri:
* *

View File

@ -40,6 +40,10 @@ GType shell_texture_cache_get_type (void) G_GNUC_CONST;
ShellTextureCache* shell_texture_cache_get_default (void); ShellTextureCache* shell_texture_cache_get_default (void);
ClutterActor *shell_texture_cache_load_icon_name (ShellTextureCache *cache,
const char *name,
gint size);
ClutterActor *shell_texture_cache_load_gicon (ShellTextureCache *cache, ClutterActor *shell_texture_cache_load_gicon (ShellTextureCache *cache,
GIcon *icon, GIcon *icon,
gint size); gint size);