[gnome-initial-setup: 9/20] gis-driver: Add avatar property



commit fc2f8d0aa5a56399521223636bc79329f1bcb814
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Feb 6 13:52:59 2020 +0000

    gis-driver: Add avatar property
    
    This will be used in upcoming commits for sharing the main user’s avatar
    between pages in the setup process.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 gnome-initial-setup/gis-driver.c | 66 +++++++++++++++++++++++++++++++++++++++-
 gnome-initial-setup/gis-driver.h |  4 +++
 2 files changed, 69 insertions(+), 1 deletion(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 496f435..af7508d 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -63,9 +63,10 @@ typedef enum {
   PROP_SMALL_SCREEN,
   PROP_PARENTAL_CONTROLS_ENABLED,
   PROP_FULL_NAME,
+  PROP_AVATAR,
 } GisDriverProperty;
 
-static GParamSpec *obj_props[PROP_FULL_NAME + 1];
+static GParamSpec *obj_props[PROP_AVATAR + 1];
 
 struct _GisDriverPrivate {
   GtkWindow *main_window;
@@ -87,6 +88,8 @@ struct _GisDriverPrivate {
   gchar *username;
   gchar *full_name;  /* (owned) (nullable) */
 
+  GdkPixbuf *avatar;  /* (owned) (nullable) */
+
   GisDriverMode mode;
   UmAccountMode account_mode;
   gboolean small_screen;
@@ -123,6 +126,8 @@ gis_driver_finalize (GObject *object)
   g_free (priv->full_name);
   g_free (priv->user_password);
 
+  g_clear_object (&priv->avatar);
+
   g_clear_object (&priv->user_account);
   g_clear_pointer (&priv->vendor_conf_file, g_key_file_free);
 
@@ -296,6 +301,45 @@ gis_driver_get_full_name (GisDriver *driver)
   return priv->full_name;
 }
 
+/**
+ * gis_driver_set_avatar:
+ * @driver: a #GisDriver
+ * @avatar: (nullable) (transfer none): avatar of the main user, or %NULL if not known
+ *
+ * Set the #GisDriver:avatar property.
+ *
+ * Since: 3.36
+ */
+void
+gis_driver_set_avatar (GisDriver *driver,
+                       GdkPixbuf *avatar)
+{
+  GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+  g_return_if_fail (GIS_IS_DRIVER (driver));
+  g_return_if_fail (avatar == NULL || GDK_IS_PIXBUF (avatar));
+
+  if (g_set_object (&priv->avatar, avatar))
+    g_object_notify_by_pspec (G_OBJECT (driver), obj_props[PROP_AVATAR]);
+}
+
+/**
+ * gis_driver_get_avatar:
+ * @driver: a #GisDriver
+ *
+ * Get the #GisDriver:avatar property.
+ *
+ * Returns: (nullable) (transfer none): avatar of the main user, or %NULL if not known
+ * Since: 3.36
+ */
+GdkPixbuf *
+gis_driver_get_avatar (GisDriver *driver)
+{
+  GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+  g_return_val_if_fail (GIS_IS_DRIVER (driver), NULL);
+
+  return priv->avatar;
+}
+
 void
 gis_driver_set_user_permissions (GisDriver   *driver,
                                  ActUser     *user,
@@ -595,6 +639,9 @@ gis_driver_get_property (GObject      *object,
     case PROP_FULL_NAME:
       g_value_set_string (value, priv->full_name);
       break;
+    case PROP_AVATAR:
+      g_value_set_object (value, priv->avatar);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -624,6 +671,9 @@ gis_driver_set_property (GObject      *object,
     case PROP_FULL_NAME:
       gis_driver_set_full_name (driver, g_value_get_string (value));
       break;
+    case PROP_AVATAR:
+      gis_driver_set_avatar (driver, g_value_get_object (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -923,6 +973,20 @@ gis_driver_class_init (GisDriverClass *klass)
                          NULL,
                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GisDriver:avatar: (nullable)
+   *
+   * Avatar of the main user. May be %NULL if unknown or not set yet.
+   *
+   * Since: 3.36
+   */
+  obj_props[PROP_AVATAR] =
+    g_param_spec_object ("avatar",
+                         "Avatar",
+                         "Avatar of the main user.",
+                         GDK_TYPE_PIXBUF,
+                         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 6571a1d..aace51d 100644
--- a/gnome-initial-setup/gis-driver.h
+++ b/gnome-initial-setup/gis-driver.h
@@ -107,6 +107,10 @@ 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);
+
 gboolean gis_driver_get_gdm_objects (GisDriver        *driver,
                                      GdmGreeter      **greeter,
                                      GdmUserVerifier **user_verifier);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]