Deprecate GEmblemedIcon and GEmblem

Reasons for deprecating them:
 - Not many consumers
 - GTK4 dropped support for it
 - It's easy enough to implement the same feature without this special GIcon
 - Any place that accepts a GIcon is supposed to also support GEmblemedIcon
   e.g GNotification::set_icon(), but none of the backends supports it.

See the attached issue for more details.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3544
This commit is contained in:
Julian Sparber 2024-12-05 15:47:12 +01:00
parent b6da230b8f
commit 3d31d99c45
7 changed files with 67 additions and 16 deletions

View File

@ -39,6 +39,8 @@
*
* Currently, only metainformation about the emblem's origin is
* supported. More may be added in the future.
*
* Deprecated: 2.84
*/
static void g_emblem_iface_init (GIconIface *iface);
@ -48,7 +50,10 @@ struct _GEmblem
GObject parent_instance;
GIcon *icon;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
GEmblemOrigin origin;
G_GNUC_END_IGNORE_DEPRECATIONS
};
struct _GEmblemClass
@ -140,13 +145,14 @@ g_emblem_class_init (GEmblemClass *klass)
* The origin the emblem is derived from.
*
* Since: 2.18
* Deprecated: 2.84
*/
g_object_class_install_property (gobject_class,
PROP_ORIGIN,
g_param_spec_enum ("origin", NULL, NULL,
G_TYPE_EMBLEM_ORIGIN,
G_EMBLEM_ORIGIN_UNKNOWN,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
/**
* GEmblem:icon:
@ -154,12 +160,13 @@ g_emblem_class_init (GEmblemClass *klass)
* The actual icon of the emblem.
*
* Since: 2.18
* Deprecated: 2.84
*/
g_object_class_install_property (gobject_class,
PROP_ICON,
g_param_spec_object ("icon", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
}
@ -177,6 +184,7 @@ g_emblem_init (GEmblem *emblem)
* Returns: a new #GEmblem.
*
* Since: 2.18
* Deprecated: 2.84
*/
GEmblem *
g_emblem_new (GIcon *icon)
@ -194,6 +202,7 @@ g_emblem_new (GIcon *icon)
return emblem;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* g_emblem_new_with_origin:
* @icon: a GIcon containing the icon.
@ -204,6 +213,7 @@ g_emblem_new (GIcon *icon)
* Returns: a new #GEmblem.
*
* Since: 2.18
* Deprecated: 2.84
*/
GEmblem *
g_emblem_new_with_origin (GIcon *icon,
@ -221,6 +231,7 @@ g_emblem_new_with_origin (GIcon *icon,
return emblem;
}
G_GNUC_END_IGNORE_DEPRECATIONS
/**
* g_emblem_get_icon:
@ -232,6 +243,7 @@ g_emblem_new_with_origin (GIcon *icon,
* the emblem and should not be modified or freed.
*
* Since: 2.18
* Deprecated: 2.84
*/
GIcon *
g_emblem_get_icon (GEmblem *emblem)
@ -241,7 +253,7 @@ g_emblem_get_icon (GEmblem *emblem)
return emblem->icon;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* g_emblem_get_origin:
* @emblem: a #GEmblem
@ -251,6 +263,7 @@ g_emblem_get_icon (GEmblem *emblem)
* Returns: (transfer none): the origin of the emblem
*
* Since: 2.18
* Deprecated: 2.84
*/
GEmblemOrigin
g_emblem_get_origin (GEmblem *emblem)
@ -259,6 +272,7 @@ g_emblem_get_origin (GEmblem *emblem)
return emblem->origin;
}
G_GNUC_END_IGNORE_DEPRECATIONS
static guint
g_emblem_hash (GIcon *icon)
@ -266,7 +280,9 @@ g_emblem_hash (GIcon *icon)
GEmblem *emblem = G_EMBLEM (icon);
guint hash;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
hash = g_icon_hash (g_emblem_get_icon (emblem));
G_GNUC_END_IGNORE_DEPRECATIONS
hash ^= emblem->origin;
return hash;
@ -320,6 +336,7 @@ g_emblem_from_tokens (gchar **tokens,
{
GEmblem *emblem;
GIcon *icon;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
GEmblemOrigin origin;
emblem = NULL;
@ -352,6 +369,7 @@ g_emblem_from_tokens (gchar **tokens,
origin = atoi (tokens[1]);
emblem = g_emblem_new_with_origin (icon, origin);
G_GNUC_END_IGNORE_DEPRECATIONS
g_object_unref (icon);
return G_ICON (emblem);

View File

@ -43,16 +43,20 @@ typedef struct _GEmblemClass GEmblemClass;
GIO_AVAILABLE_IN_ALL
GType g_emblem_get_type (void) G_GNUC_CONST;
GIO_AVAILABLE_IN_ALL
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
GIO_DEPRECATED_IN_2_84
GEmblem *g_emblem_new (GIcon *icon);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
GEmblem *g_emblem_new_with_origin (GIcon *icon,
GEmblemOrigin origin);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
GIcon *g_emblem_get_icon (GEmblem *emblem);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
GEmblemOrigin g_emblem_get_origin (GEmblem *emblem);
G_GNUC_END_IGNORE_DEPRECATIONS
G_END_DECLS
#endif /* __G_EMBLEM_H__ */

View File

@ -41,6 +41,8 @@
*
* Note that `GEmblemedIcon` allows no control over the position
* of the emblems. See also [class@Gio.Emblem] for more information.
*
* Deprecated: 2.84
**/
enum {
@ -129,11 +131,12 @@ g_emblemed_icon_class_init (GEmblemedIconClass *klass)
* The [iface@Gio.Icon] to attach emblems to.
*
* Since: 2.18
* Deprecated: 2.84
*/
properties[PROP_GICON] =
g_param_spec_object ("gicon", NULL, NULL,
G_TYPE_ICON,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -154,6 +157,7 @@ g_emblemed_icon_init (GEmblemedIcon *emblemed)
* Returns: (transfer full) (type GEmblemedIcon): a new #GIcon
*
* Since: 2.18
* Deprecated: 2.84
**/
GIcon *
g_emblemed_icon_new (GIcon *icon,
@ -168,13 +172,14 @@ g_emblemed_icon_new (GIcon *icon,
"gicon", icon,
NULL));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (emblem != NULL)
g_emblemed_icon_add_emblem (emblemed, emblem);
G_GNUC_END_IGNORE_DEPRECATIONS
return G_ICON (emblemed);
}
/**
* g_emblemed_icon_get_icon:
* @emblemed: a #GEmblemedIcon
@ -184,6 +189,7 @@ g_emblemed_icon_new (GIcon *icon,
* Returns: (transfer none): a #GIcon that is owned by @emblemed
*
* Since: 2.18
* Deprecated: 2.84
**/
GIcon *
g_emblemed_icon_get_icon (GEmblemedIcon *emblemed)
@ -203,6 +209,7 @@ g_emblemed_icon_get_icon (GEmblemedIcon *emblemed)
* #GEmblems that is owned by @emblemed
*
* Since: 2.18
* Deprecated: 2.84
**/
GList *
@ -220,6 +227,7 @@ g_emblemed_icon_get_emblems (GEmblemedIcon *emblemed)
* Removes all the emblems from @icon.
*
* Since: 2.28
* Deprecated: 2.84
**/
void
g_emblemed_icon_clear_emblems (GEmblemedIcon *emblemed)
@ -257,6 +265,7 @@ g_emblem_comp (GEmblem *a,
* Adds @emblem to the #GList of #GEmblems.
*
* Since: 2.18
* Deprecated: 2.84
**/
void
g_emblemed_icon_add_emblem (GEmblemedIcon *emblemed,

View File

@ -60,19 +60,23 @@ struct _GEmblemedIconClass
GIO_AVAILABLE_IN_ALL
GType g_emblemed_icon_get_type (void) G_GNUC_CONST;
GIO_AVAILABLE_IN_ALL
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
GIO_DEPRECATED_IN_2_84
GIcon *g_emblemed_icon_new (GIcon *icon,
GEmblem *emblem);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
GIcon *g_emblemed_icon_get_icon (GEmblemedIcon *emblemed);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
GList *g_emblemed_icon_get_emblems (GEmblemedIcon *emblemed);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
void g_emblemed_icon_add_emblem (GEmblemedIcon *emblemed,
GEmblem *emblem);
GIO_AVAILABLE_IN_ALL
GIO_DEPRECATED_IN_2_84
void g_emblemed_icon_clear_emblems (GEmblemedIcon *emblemed);
G_GNUC_END_IGNORE_DEPRECATIONS
G_END_DECLS
#endif /* __G_EMBLEMED_ICON_H__ */

View File

@ -61,7 +61,7 @@
*
* If you want to consume `GIcon` (for example, in a toolkit) you must
* be prepared to handle at least the three following cases:
* [iface@Gio.LoadableIcon], [class@Gio.ThemedIcon] and [class@Gio.EmblemedIcon].
* [iface@Gio.LoadableIcon], [class@Gio.ThemedIcon] and [class@Gio.EmblemedIcon] (deprecated since 2.84).
* It may also make sense to have fast-paths for other cases (like handling
* [`GdkPixbuf`](https://docs.gtk.org/gdk-pixbuf/class.Pixbuf.html) directly,
* for example) but all compliant `GIcon` implementations outside of GIO must
@ -471,6 +471,7 @@ g_icon_new_for_string (const gchar *str,
return icon;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GEmblem *
g_icon_deserialize_emblem (GVariant *value)
{
@ -555,6 +556,7 @@ g_icon_deserialize_emblemed (GVariant *value)
return icon;
}
G_GNUC_END_IGNORE_DEPRECATIONS
/**
* g_icon_deserialize:

View File

@ -701,13 +701,14 @@ typedef enum {
* to #GEmblem.
*
* Since: 2.18
* Deprecated: 2.84
*/
typedef enum {
G_EMBLEM_ORIGIN_UNKNOWN,
G_EMBLEM_ORIGIN_DEVICE,
G_EMBLEM_ORIGIN_LIVEMETADATA,
G_EMBLEM_ORIGIN_TAG
} GEmblemOrigin;
} GEmblemOrigin GIO_DEPRECATED_TYPE_IN_2_84;
/**
* GResolverError:

View File

@ -244,17 +244,21 @@ test_g_icon_to_string (void)
location = g_file_new_for_uri ("file:///some/path/somewhere.png");
icon3 = g_file_icon_new (location);
g_object_unref (location);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
emblem1 = g_emblem_new_with_origin (icon2, G_EMBLEM_ORIGIN_DEVICE);
emblem2 = g_emblem_new_with_origin (icon3, G_EMBLEM_ORIGIN_LIVEMETADATA);
icon4 = g_emblemed_icon_new (icon, emblem1);
g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon4), emblem2);
G_GNUC_END_IGNORE_DEPRECATIONS
data = g_icon_to_string (icon4);
icon5 = g_icon_new_for_string (data, &error);
g_assert_no_error (error);
g_assert (g_icon_equal (icon4, icon5));
g_object_get (emblem1, "origin", &origin, "icon", &i, NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert (origin == G_EMBLEM_ORIGIN_DEVICE);
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert (i == icon2);
g_object_unref (i);
@ -364,10 +368,12 @@ test_g_icon_serialize (void)
location = g_file_new_for_uri ("file:///some/path/somewhere.png");
icon3 = g_file_icon_new (location);
g_object_unref (location);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
emblem1 = g_emblem_new_with_origin (icon2, G_EMBLEM_ORIGIN_DEVICE);
emblem2 = g_emblem_new_with_origin (icon3, G_EMBLEM_ORIGIN_LIVEMETADATA);
icon4 = g_emblemed_icon_new (icon, emblem1);
g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon4), emblem2);
G_GNUC_END_IGNORE_DEPRECATIONS
data = g_icon_serialize (icon4);
icon5 = g_icon_deserialize (data);
g_assert (g_icon_equal (icon4, icon5));
@ -450,6 +456,7 @@ test_emblemed_icon (void)
icon1 = g_themed_icon_new ("testicon");
icon2 = g_themed_icon_new ("testemblem");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
emblem1 = g_emblem_new (icon2);
emblem2 = g_emblem_new_with_origin (icon2, G_EMBLEM_ORIGIN_TAG);
@ -461,6 +468,7 @@ test_emblemed_icon (void)
icon4 = g_emblemed_icon_new (icon1, emblem1);
g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon4), emblem2);
emblems = g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon4));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_cmpint (g_list_length (emblems), ==, 2);
g_assert (!g_icon_equal (icon3, icon4));
@ -472,6 +480,7 @@ test_emblemed_icon (void)
g_variant_unref (variant);
emblem = emblems->data;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert (g_emblem_get_icon (emblem) == icon2);
g_assert (g_emblem_get_origin (emblem) == G_EMBLEM_ORIGIN_UNKNOWN);
@ -481,6 +490,7 @@ test_emblemed_icon (void)
g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (icon4));
g_assert (g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon4)) == NULL);
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert (g_icon_hash (icon4) != g_icon_hash (icon2));
g_object_get (icon4, "gicon", &icon, NULL);
@ -611,6 +621,9 @@ int
main (int argc,
char *argv[])
{
/* Disable deprecation warnings because GEmblemedIcon is deprecated and has deprecated properties */
g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE);
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/icons/to-string", test_g_icon_to_string);