StIcon: deprecate StIcon:icon-name and StIcon:icon-type

Reroute setting those properties to a GIcon. API users are expected
to create GIcon directly now.
The advantage is that from a StIcon you can now create a similar one
by accessing :gicon.

https://bugzilla.gnome.org/show_bug.cgi?id=682540
This commit is contained in:
Giovanni Campagna 2012-08-26 15:36:45 +02:00
parent f96dcaccbe
commit d3b0d23d8f
4 changed files with 80 additions and 95 deletions

View File

@ -53,7 +53,6 @@ struct _StIconPrivate
guint opacity_handler_id;
GIcon *gicon;
gchar *icon_name;
StIconType icon_type;
gint prop_icon_size; /* icon size set as property */
gint theme_icon_size; /* icon size from theme node */
@ -174,20 +173,6 @@ st_icon_dispose (GObject *gobject)
G_OBJECT_CLASS (st_icon_parent_class)->dispose (gobject);
}
static void
st_icon_finalize (GObject *gobject)
{
StIconPrivate *priv = ST_ICON (gobject)->priv;
if (priv->icon_name)
{
g_free (priv->icon_name);
priv->icon_name = NULL;
}
G_OBJECT_CLASS (st_icon_parent_class)->finalize (gobject);
}
static void
st_icon_get_preferred_height (ClutterActor *actor,
gfloat for_width,
@ -337,7 +322,6 @@ st_icon_class_init (StIconClass *klass)
object_class->get_property = st_icon_get_property;
object_class->set_property = st_icon_set_property;
object_class->dispose = st_icon_dispose;
object_class->finalize = st_icon_finalize;
actor_class->get_preferred_height = st_icon_get_preferred_height;
actor_class->get_preferred_width = st_icon_get_preferred_width;
@ -348,7 +332,7 @@ st_icon_class_init (StIconClass *klass)
pspec = g_param_spec_object ("gicon",
"GIcon",
"A GIcon to override :icon-name",
"The GIcon shown by this icon actor",
G_TYPE_ICON,
ST_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_GICON, pspec);
@ -356,7 +340,7 @@ st_icon_class_init (StIconClass *klass)
pspec = g_param_spec_string ("icon-name",
"Icon name",
"An icon name",
NULL, ST_PARAM_READWRITE);
NULL, ST_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (object_class, PROP_ICON_NAME, pspec);
pspec = g_param_spec_enum ("icon-type",
@ -364,7 +348,7 @@ st_icon_class_init (StIconClass *klass)
"The type of icon that should be used",
ST_TYPE_ICON_TYPE,
DEFAULT_ICON_TYPE,
ST_PARAM_READWRITE);
ST_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (object_class, PROP_ICON_TYPE, pspec);
pspec = g_param_spec_int ("icon-size",
@ -492,14 +476,6 @@ st_icon_update (StIcon *icon)
priv->gicon,
priv->icon_size);
}
else if (priv->icon_name)
{
priv->pending_texture = st_texture_cache_load_icon_name (cache,
theme_node,
priv->icon_name,
priv->icon_type,
priv->icon_size);
}
if (priv->pending_texture)
{
@ -562,9 +538,16 @@ st_icon_new (void)
const gchar *
st_icon_get_icon_name (StIcon *icon)
{
StIconPrivate *priv;
g_return_val_if_fail (ST_IS_ICON (icon), NULL);
return icon->priv->icon_name;
priv = icon->priv;
if (priv->gicon && G_IS_THEMED_ICON (priv->gicon))
return g_themed_icon_get_names (G_THEMED_ICON (priv->gicon)) [0];
else
return NULL;
}
void
@ -577,20 +560,20 @@ st_icon_set_icon_name (StIcon *icon,
priv = icon->priv;
/* Check if there's no change */
if (g_strcmp0 (priv->icon_name, icon_name) == 0)
return;
g_free (priv->icon_name);
priv->icon_name = g_strdup (icon_name);
if (priv->gicon)
{
g_object_unref (priv->gicon);
priv->gicon = NULL;
g_object_notify (G_OBJECT (icon), "gicon");
}
g_object_unref (priv->gicon);
if (icon_name)
{
if (priv->icon_type == ST_ICON_SYMBOLIC)
priv->gicon = _st_make_symbolic_themed_icon (icon_name);
else
priv->gicon = g_themed_icon_new_with_default_fallbacks (icon_name);
}
else
priv->gicon = NULL;
g_object_notify (G_OBJECT (icon), "gicon");
g_object_notify (G_OBJECT (icon), "icon-name");
st_icon_update (icon);
@ -665,7 +648,7 @@ void
st_icon_set_gicon (StIcon *icon, GIcon *gicon)
{
g_return_if_fail (ST_IS_ICON (icon));
g_return_if_fail (G_IS_ICON (gicon));
g_return_if_fail (gicon == NULL || G_IS_ICON (gicon));
if (icon->priv->gicon == gicon) /* do nothing */
return;
@ -679,13 +662,6 @@ st_icon_set_gicon (StIcon *icon, GIcon *gicon)
if (gicon)
icon->priv->gicon = g_object_ref (gicon);
if (icon->priv->icon_name)
{
g_free (icon->priv->icon_name);
icon->priv->icon_name = NULL;
g_object_notify (G_OBJECT (icon), "icon-name");
}
g_object_notify (G_OBJECT (icon), "gicon");
st_icon_update (icon);

View File

@ -691,3 +691,55 @@ _st_paint_shadow_with_opacity (StShadow *shadow_spec,
shadow_box.x2, shadow_box.y2,
0, 0, 1, 1);
}
/* generates names like g_themed_icon_new_with_default_fallbacks(),
* but *only* symbolic names
*/
static char **
symbolic_names_for_icon (const char *name)
{
char **parts, **names;
int i, numnames;
parts = g_strsplit (name, "-", -1);
numnames = g_strv_length (parts);
names = g_new (char *, numnames + 1);
for (i = 0; parts[i]; i++)
{
if (i == 0)
{
names[i] = g_strdup_printf ("%s-symbolic", parts[i]);
}
else
{
names[i] = g_strdup_printf ("%.*s-%s-symbolic",
(int) (strlen (names[i - 1]) - strlen ("-symbolic")),
names[i - 1], parts[i]);
}
}
names[i] = NULL;
g_strfreev (parts);
/* need to reverse here, because longest (most specific)
name has to come first */
for (i = 0; i < (numnames / 2); i++) {
char *tmp = names[i];
names[i] = names[numnames - i - 1];
names[numnames - i - 1] = tmp;
}
return names;
}
GIcon *
_st_make_symbolic_themed_icon (const char *icon_name)
{
char **names;
GIcon *themed;
names = symbolic_names_for_icon (icon_name);
themed = g_themed_icon_new_from_names (names, -1);
g_strfreev (names);
return themed;
}

View File

@ -79,4 +79,6 @@ void _st_paint_shadow_with_opacity (StShadow *shadow_spec,
ClutterActorBox *box,
guint8 paint_opacity);
GIcon *_st_make_symbolic_themed_icon (const char *icon_name);
#endif /* __ST_PRIVATE_H__ */

View File

@ -22,6 +22,7 @@
#include "config.h"
#include "st-texture-cache.h"
#include "st-private.h"
#include <gtk/gtk.h>
#include <string.h>
#include <glib.h>
@ -967,9 +968,6 @@ load_gicon_with_colors (StTextureCache *cache,
* icon isn't loaded already, the texture will be filled
* asynchronously.
*
* This will load @icon as a full-color icon; if you want a symbolic
* icon, you must use st_texture_cache_load_icon_name().
*
* Return Value: (transfer none): A new #ClutterActor for the icon, or %NULL if not found
*/
ClutterActor *
@ -1135,46 +1133,6 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
* full-color icon.
*/
/* generates names like g_themed_icon_new_with_default_fallbacks(),
* but *only* symbolic names
*/
static char **
symbolic_names_for_icon (const char *name)
{
char **parts, **names;
int i, numnames;
parts = g_strsplit (name, "-", -1);
numnames = g_strv_length (parts);
names = g_new (char *, numnames + 1);
for (i = 0; parts[i]; i++)
{
if (i == 0)
{
names[i] = g_strdup_printf ("%s-symbolic", parts[i]);
}
else
{
names[i] = g_strdup_printf ("%.*s-%s-symbolic",
(int) (strlen (names[i - 1]) - strlen ("-symbolic")),
names[i - 1], parts[i]);
}
}
names[i] = NULL;
g_strfreev (parts);
/* need to reverse here, because longest (most specific)
name has to come first */
for (i = 0; i < (numnames / 2); i++) {
char *tmp = names[i];
names[i] = names[numnames - i - 1];
names[numnames - i - 1] = tmp;
}
return names;
}
/**
* st_texture_cache_load_icon_name:
* @cache: The texture cache instance
@ -1198,16 +1156,13 @@ st_texture_cache_load_icon_name (StTextureCache *cache,
{
ClutterActor *texture;
GIcon *themed;
char **names;
g_return_val_if_fail (!(icon_type == ST_ICON_SYMBOLIC && theme_node == NULL), NULL);
switch (icon_type)
{
case ST_ICON_SYMBOLIC:
names = symbolic_names_for_icon (name);
themed = g_themed_icon_new_from_names (names, -1);
g_strfreev (names);
themed = _st_make_symbolic_themed_icon (name);
texture = load_gicon_with_colors (cache, themed, size,
st_theme_node_get_icon_colors (theme_node));
g_object_unref (themed);