[gnome-panel] libgnome-panel: add support for initial settings



commit 2b3a16ba84ef83da200ba0acca4d6e5513089452
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Sep 15 17:47:26 2018 +0300

    libgnome-panel: add support for initial settings

 .../libpanel-applet-private/gp-applet-manager.c    |  8 +++++-
 libgnome-panel/gp-applet.c                         | 29 ++++++++++++++++++++++
 libgnome-panel/gp-applet.h                         |  4 +++
 libgnome-panel/gp-module-private.h                 |  1 +
 libgnome-panel/gp-module.c                         |  3 +++
 5 files changed, 44 insertions(+), 1 deletion(-)
---
diff --git a/gnome-panel/libpanel-applet-private/gp-applet-manager.c 
b/gnome-panel/libpanel-applet-private/gp-applet-manager.c
index 5d4470091..2ae6bfcd1 100644
--- a/gnome-panel/libpanel-applet-private/gp-applet-manager.c
+++ b/gnome-panel/libpanel-applet-private/gp-applet-manager.c
@@ -190,6 +190,7 @@ gp_applet_manager_load_applet (PanelAppletsManager        *manager,
   PanelOrientation panel_orientation;
   GtkOrientation orientation;
   GtkPositionType position;
+  GVariant *initial_settings;
   GError *error;
   GpApplet *applet;
   GpAppletFrame *frame;
@@ -238,8 +239,13 @@ gp_applet_manager_load_applet (PanelAppletsManager        *manager,
         break;
     }
 
+  initial_settings = NULL;
+
   error = NULL;
-  applet = gp_module_applet_new (module, applet_id, settings_path, &error);
+  applet = gp_module_applet_new (module, applet_id, settings_path,
+                                 initial_settings, &error);
+
+  g_clear_pointer (&initial_settings, g_variant_unref);
   g_free (settings_path);
 
   if (!applet)
diff --git a/libgnome-panel/gp-applet.c b/libgnome-panel/gp-applet.c
index 78b31d6f4..9aa4bd894 100644
--- a/libgnome-panel/gp-applet.c
+++ b/libgnome-panel/gp-applet.c
@@ -62,6 +62,7 @@ typedef struct
 
   gchar              *id;
   gchar              *settings_path;
+  GVariant           *initial_settings;
   gchar              *gettext_domain;
   gboolean            locked_down;
   GtkOrientation      orientation;
@@ -86,6 +87,7 @@ enum
 
   PROP_ID,
   PROP_SETTINGS_PATH,
+  PROP_INITIAL_SETTINGS,
   PROP_GETTEXT_DOMAIN,
   PROP_LOCKED_DOWN,
   PROP_ORIENTATION,
@@ -291,6 +293,7 @@ static void
 gp_applet_constructed (GObject *object)
 {
   GpApplet *applet;
+  GpAppletClass *applet_class;
   GpAppletPrivate *priv;
   GActionGroup *group;
   GtkStyleContext *context;
@@ -298,8 +301,13 @@ gp_applet_constructed (GObject *object)
   G_OBJECT_CLASS (gp_applet_parent_class)->constructed (object);
 
   applet = GP_APPLET (object);
+  applet_class = GP_APPLET_GET_CLASS (applet);
   priv = gp_applet_get_instance_private (applet);
 
+  if (applet_class->initial_setup != NULL && priv->initial_settings != NULL)
+    applet_class->initial_setup (applet, priv->initial_settings);
+  g_clear_pointer (&priv->initial_settings, g_variant_unref);
+
   gtk_builder_set_translation_domain (priv->builder, priv->gettext_domain);
 
   group = G_ACTION_GROUP (priv->action_group);
@@ -327,6 +335,7 @@ gp_applet_dispose (GObject *object)
       priv->size_hints_idle = 0;
     }
 
+  g_clear_pointer (&priv->initial_settings, g_variant_unref);
   g_clear_object (&priv->general_settings);
 
   G_OBJECT_CLASS (gp_applet_parent_class)->dispose (object);
@@ -371,6 +380,10 @@ gp_applet_get_property (GObject    *object,
         g_value_set_string (value, priv->settings_path);
         break;
 
+      case PROP_INITIAL_SETTINGS:
+        g_value_set_variant (value, priv->initial_settings);
+        break;
+
       case PROP_GETTEXT_DOMAIN:
         g_value_set_string (value, priv->gettext_domain);
         break;
@@ -429,6 +442,11 @@ gp_applet_set_property (GObject      *object,
         priv->settings_path = g_value_dup_string (value);
         break;
 
+      case PROP_INITIAL_SETTINGS:
+        g_assert (priv->initial_settings == NULL);
+        priv->initial_settings = g_value_dup_variant (value);
+        break;
+
       case PROP_GETTEXT_DOMAIN:
         g_assert (priv->gettext_domain == NULL);
         priv->gettext_domain = g_value_dup_string (value);
@@ -572,6 +590,17 @@ install_properties (GObjectClass *object_class)
                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
                          G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GpApplet:initial-settings:
+   *
+   * The GVariant with initial settings.
+   */
+  properties[PROP_INITIAL_SETTINGS] =
+    g_param_spec_variant ("initial-settings", "Initial Settings", "Initial Settings",
+                          G_VARIANT_TYPE ("a{sv}"), NULL,
+                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
+                          G_PARAM_STATIC_STRINGS);
+
   /**
    * GpApplet:gettext-domain:
    *
diff --git a/libgnome-panel/gp-applet.h b/libgnome-panel/gp-applet.h
index f21d86aff..6712161c2 100644
--- a/libgnome-panel/gp-applet.h
+++ b/libgnome-panel/gp-applet.h
@@ -59,6 +59,7 @@ typedef enum
 /**
  * GpAppletClass:
  * @parent_class: The parent class.
+ * @initial_setup: virtual method called when applet has initial settings
  * @placement_changed: Signal is emitted when the orientation or position
  *     properties of applet has changed.
  *
@@ -68,6 +69,9 @@ struct _GpAppletClass
 {
   GtkEventBoxClass parent_class;
 
+  void (* initial_setup)       (GpApplet        *applet,
+                                GVariant        *initial_settings);
+
   void (* placement_changed)   (GpApplet        *applet,
                                 GtkOrientation   orientation,
                                 GtkPositionType  position);
diff --git a/libgnome-panel/gp-module-private.h b/libgnome-panel/gp-module-private.h
index 8c8575219..200290e63 100644
--- a/libgnome-panel/gp-module-private.h
+++ b/libgnome-panel/gp-module-private.h
@@ -51,6 +51,7 @@ const gchar         *gp_module_get_applet_id_from_iid (GpModule     *module,
 GpApplet            *gp_module_applet_new             (GpModule     *module,
                                                        const gchar  *applet,
                                                        const gchar  *settings_path,
+                                                       GVariant     *initial_settings,
                                                        GError      **error);
 
 G_END_DECLS
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index 91e879a4e..f915ecbdd 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -560,6 +560,7 @@ gp_module_get_applet_id_from_iid (GpModule    *module,
  * @module: a #GpModule
  * @applet: the applet id
  * @settings_path: the #GSettings path to the per-instance settings
+ * @initial_settings: initial settings
  * @error: return location for a #GError, or %NULL
  *
  * Returns a newly allocated applet.
@@ -570,6 +571,7 @@ GpApplet *
 gp_module_applet_new (GpModule     *module,
                       const gchar  *applet,
                       const gchar  *settings_path,
+                      GVariant     *initial_settings,
                       GError      **error)
 {
   GpAppletInfo *info;
@@ -606,6 +608,7 @@ gp_module_applet_new (GpModule     *module,
   return g_object_new (type,
                        "id", applet,
                        "settings-path", settings_path,
+                       "initial-settings", initial_settings,
                        "gettext-domain", module->gettext_domain,
                        NULL);
 }


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