[gnome-initial-setup/wip/port-to-gtk4: 5/9] driver, page-header: Use GdkPaintable APIs
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/wip/port-to-gtk4: 5/9] driver, page-header: Use GdkPaintable APIs
- Date: Thu, 21 Jul 2022 19:59:53 +0000 (UTC)
commit b597cf5bb68f58673b9211a639137d704be133aa
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Jul 16 10:21:53 2022 -0300
driver, page-header: Use GdkPaintable APIs
Instead of exposing and expecting GdkPixbufs, use GdkPaintable
for the properties and GisDriver APIs. This not only fixes a
warning - GtkImage does not have a "pixbuf" property anymore -
but it also paves the way for potential future improvements.
gnome-initial-setup/gis-driver.c | 12 ++++++------
gnome-initial-setup/gis-driver.h | 6 +++---
gnome-initial-setup/gis-page-header.c | 16 ++++++++--------
.../pages/account/gis-account-page-local.c | 16 ++++++++++++----
.../pages/parental-controls/gis-parental-controls-page.c | 10 +++++-----
gnome-initial-setup/pages/password/gis-password-page.c | 16 ++++++++--------
6 files changed, 42 insertions(+), 34 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 4d9c4b86..1fbf636c 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -91,7 +91,7 @@ struct _GisDriver {
gchar *username;
gchar *full_name; /* (owned) (nullable) */
- GdkPixbuf *avatar; /* (owned) (nullable) */
+ GdkPaintable *avatar; /* (owned) (nullable) */
GisDriverMode mode;
UmAccountMode account_mode;
@@ -299,11 +299,11 @@ gis_driver_get_full_name (GisDriver *driver)
* Since: 3.36
*/
void
-gis_driver_set_avatar (GisDriver *driver,
- GdkPixbuf *avatar)
+gis_driver_set_avatar (GisDriver *driver,
+ GdkPaintable *avatar)
{
g_return_if_fail (GIS_IS_DRIVER (driver));
- g_return_if_fail (avatar == NULL || GDK_IS_PIXBUF (avatar));
+ g_return_if_fail (avatar == NULL || GDK_IS_PAINTABLE (avatar));
if (g_set_object (&driver->avatar, avatar))
g_object_notify_by_pspec (G_OBJECT (driver), obj_props[PROP_AVATAR]);
@@ -318,7 +318,7 @@ gis_driver_set_avatar (GisDriver *driver,
* Returns: (nullable) (transfer none): avatar of the main user, or %NULL if not known
* Since: 3.36
*/
-GdkPixbuf *
+GdkPaintable *
gis_driver_get_avatar (GisDriver *driver)
{
g_return_val_if_fail (GIS_IS_DRIVER (driver), NULL);
@@ -902,7 +902,7 @@ gis_driver_class_init (GisDriverClass *klass)
g_param_spec_object ("avatar",
"Avatar",
"Avatar of the main user.",
- GDK_TYPE_PIXBUF,
+ GDK_TYPE_PAINTABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, G_N_ELEMENTS (obj_props), obj_props);
diff --git a/gnome-initial-setup/gis-driver.h b/gnome-initial-setup/gis-driver.h
index 3af51a8f..9b935e24 100644
--- a/gnome-initial-setup/gis-driver.h
+++ b/gnome-initial-setup/gis-driver.h
@@ -87,9 +87,9 @@ void gis_driver_set_full_name (GisDriver *driver,
const gchar *full_name);
const gchar *gis_driver_get_full_name (GisDriver *driver);
-void gis_driver_set_avatar (GisDriver *driver,
- GdkPixbuf *avatar);
-GdkPixbuf *gis_driver_get_avatar (GisDriver *driver);
+void gis_driver_set_avatar (GisDriver *driver,
+ GdkPaintable *avatar);
+GdkPaintable *gis_driver_get_avatar (GisDriver *driver);
gboolean gis_driver_get_gdm_objects (GisDriver *driver,
GdmGreeter **greeter,
diff --git a/gnome-initial-setup/gis-page-header.c b/gnome-initial-setup/gis-page-header.c
index 3cea4fde..9b84a0ba 100644
--- a/gnome-initial-setup/gis-page-header.c
+++ b/gnome-initial-setup/gis-page-header.c
@@ -31,7 +31,7 @@ enum {
PROP_TITLE,
PROP_SUBTITLE,
PROP_ICON_NAME,
- PROP_PIXBUF,
+ PROP_PAINTABLE,
PROP_SHOW_ICON,
PROP_LAST,
};
@@ -96,8 +96,8 @@ gis_page_header_get_property (GObject *object,
g_object_get_property (G_OBJECT (header->icon), "icon-name", value);
break;
- case PROP_PIXBUF:
- g_object_get_property (G_OBJECT (header->icon), "pixbuf", value);
+ case PROP_PAINTABLE:
+ g_object_get_property (G_OBJECT (header->icon), "paintable", value);
break;
case PROP_SHOW_ICON:
@@ -134,8 +134,8 @@ gis_page_header_set_property (GObject *object,
g_object_set_property (G_OBJECT (header->icon), "icon-name", value);
break;
- case PROP_PIXBUF:
- g_object_set_property (G_OBJECT (header->icon), "pixbuf", value);
+ case PROP_PAINTABLE:
+ g_object_set_property (G_OBJECT (header->icon), "paintable", value);
break;
case PROP_SHOW_ICON:
@@ -181,10 +181,10 @@ gis_page_header_class_init (GisPageHeaderClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- obj_props[PROP_PIXBUF] =
- g_param_spec_object ("pixbuf",
+ obj_props[PROP_PAINTABLE] =
+ g_param_spec_object ("paintable",
"", "",
- GDK_TYPE_PIXBUF,
+ GDK_TYPE_PAINTABLE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_SHOW_ICON] =
diff --git a/gnome-initial-setup/pages/account/gis-account-page-local.c
b/gnome-initial-setup/pages/account/gis-account-page-local.c
index 1b2f498c..82d4bd1b 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.c
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.c
@@ -698,14 +698,22 @@ gis_account_page_local_apply (GisAccountPageLocal *local, GisPage *page)
if (priv->avatar_pixbuf != NULL)
{
- gis_driver_set_avatar (GIS_PAGE (page)->driver, priv->avatar_pixbuf);
+ g_autoptr(GdkTexture) texture = NULL;
+
+ texture = gdk_texture_new_for_pixbuf (priv->avatar_pixbuf);
+ gis_driver_set_avatar (GIS_PAGE (page)->driver, GDK_PAINTABLE (texture));
}
else if (priv->avatar_filename != NULL)
{
- g_autoptr(GdkPixbuf) pixbuf = NULL;
+ g_autoptr(GdkTexture) texture = NULL;
+ g_autoptr(GError) error = NULL;
+
+ texture = gdk_texture_new_from_filename (priv->avatar_filename, &error);
- pixbuf = gdk_pixbuf_new_from_file_at_size (priv->avatar_filename, 96, 96, NULL);
- gis_driver_set_avatar (GIS_PAGE (page)->driver, pixbuf);
+ if (!error)
+ gis_driver_set_avatar (GIS_PAGE (page)->driver, GDK_PAINTABLE (texture));
+ else
+ g_warning ("Error loading avatar: %s", error->message);
}
#ifdef HAVE_PARENTAL_CONTROLS
diff --git a/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
b/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
index 89f3e34a..736194d3 100644
--- a/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
+++ b/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
@@ -96,21 +96,21 @@ update_header (GisParentalControlsPage *page)
{
g_autofree gchar *title = NULL;
const gchar *subtitle, *icon_name;
- GdkPixbuf *pixbuf;
+ GdkPaintable *paintable;
/* Translators: The placeholder is the user’s full name. */
title = g_strdup_printf (_("Parental Controls for %s"),
gis_driver_get_full_name (GIS_PAGE (page)->driver));
subtitle = _("Set restrictions on what this user can run or install.");
- pixbuf = gis_driver_get_avatar (GIS_PAGE (page)->driver);
- icon_name = (pixbuf != NULL) ? NULL : "dialog-password-symbolic";
+ paintable = gis_driver_get_avatar (GIS_PAGE (page)->driver);
+ icon_name = (paintable != NULL) ? NULL : "dialog-password-symbolic";
g_object_set (G_OBJECT (page->header),
"title", title,
"subtitle", subtitle,
NULL);
- if (pixbuf != NULL)
- g_object_set (G_OBJECT (page->header), "pixbuf", pixbuf, NULL);
+ if (paintable != NULL)
+ g_object_set (G_OBJECT (page->header), "paintable", paintable, NULL);
else if (icon_name != NULL)
g_object_set (G_OBJECT (page->header), "icon-name", icon_name, NULL);
}
diff --git a/gnome-initial-setup/pages/password/gis-password-page.c
b/gnome-initial-setup/pages/password/gis-password-page.c
index 269cf940..700d80a0 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.c
+++ b/gnome-initial-setup/pages/password/gis-password-page.c
@@ -83,13 +83,13 @@ update_header (GisPasswordPage *page)
g_autofree gchar *title = NULL;
g_autofree gchar *subtitle = NULL;
const gchar *icon_name;
- GdkPixbuf *pixbuf;
+ GdkPaintable *paintable;
#ifndef HAVE_PARENTAL_CONTROLS
/* Don’t break UI compatibility if parental controls are disabled. */
title = g_strdup (_("Set a Password"));
subtitle = g_strdup (_("Be careful not to lose your password."));
- pixbuf = NULL;
+ paintable = NULL;
icon_name = "dialog-password-symbolic";
#else
if (!priv->parent_mode)
@@ -98,8 +98,8 @@ update_header (GisPasswordPage *page)
title = g_strdup_printf (_("Set a Password for %s"),
gis_driver_get_full_name (GIS_PAGE (page)->driver));
subtitle = g_strdup (_("Be careful not to lose your password."));
- pixbuf = gis_driver_get_avatar (GIS_PAGE (page)->driver);
- icon_name = (pixbuf != NULL) ? NULL : "dialog-password-symbolic";
+ paintable = gis_driver_get_avatar (GIS_PAGE (page)->driver);
+ icon_name = (paintable != NULL) ? NULL : "dialog-password-symbolic";
}
else
{
@@ -108,19 +108,19 @@ update_header (GisPasswordPage *page)
subtitle = g_strdup_printf (_("This password will control access to the parental controls for %s."),
gis_driver_get_full_name (GIS_PAGE (page)->driver));
icon_name = "org.freedesktop.MalcontentControl-symbolic";
- pixbuf = NULL;
+ paintable = NULL;
}
#endif
/* Doesn’t make sense to set both. */
- g_assert (icon_name == NULL || pixbuf == NULL);
+ g_assert (icon_name == NULL || paintable == NULL);
g_object_set (G_OBJECT (priv->header),
"title", title,
"subtitle", subtitle,
NULL);
- if (pixbuf != NULL)
- g_object_set (G_OBJECT (priv->header), "pixbuf", pixbuf, NULL);
+ if (paintable != NULL)
+ g_object_set (G_OBJECT (priv->header), "paintable", paintable, NULL);
else if (icon_name != NULL)
g_object_set (G_OBJECT (priv->header), "icon-name", icon_name, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]