[gnome-panel/wip/3.0-freeze-break] panel, libpanel-applet: Send per-instance GSettings path to the applets



commit 49a59ec3493de8f019d6e9e6a7c3eebd2e698c01
Author: Vincent Untz <vuntz gnome org>
Date:   Sat Mar 26 07:10:03 2011 +0100

    panel, libpanel-applet: Send per-instance GSettings path to the applets
    
    We add a new "settings-path" property.
    
    This will enable applets to use GSettings for per-instance
    configuration.

 .../panel-applet-container.c                       |   15 +++---
 .../panel-applet-frame-dbus.c                      |    6 ++
 gnome-panel/panel-applet-frame.c                   |   15 ++++++
 gnome-panel/panel-applet-frame.h                   |    1 +
 libpanel-applet/panel-applet.c                     |   52 +++++++++++++++++++-
 5 files changed, 80 insertions(+), 9 deletions(-)
---
diff --git a/gnome-panel/libpanel-applet-private/panel-applet-container.c b/gnome-panel/libpanel-applet-private/panel-applet-container.c
index ce80cba..b228479 100644
--- a/gnome-panel/libpanel-applet-private/panel-applet-container.c
+++ b/gnome-panel/libpanel-applet-private/panel-applet-container.c
@@ -53,13 +53,14 @@ typedef struct {
 } AppletPropertyInfo;
 
 static const AppletPropertyInfo applet_properties [] = {
-	{ "prefs-key",   "PrefsKey" },
-	{ "orient",      "Orient" },
-	{ "size",        "Size" },
-	{ "size-hints",  "SizeHints" },
-	{ "background",  "Background" },
-	{ "flags",       "Flags" },
-	{ "locked-down", "LockedDown" }
+	{ "settings-path", "SettingsPath" },
+	{ "prefs-key",     "PrefsKey" },
+	{ "orient",        "Orient" },
+	{ "size",          "Size" },
+	{ "size-hints",    "SizeHints" },
+	{ "background",    "Background" },
+	{ "flags",         "Flags" },
+	{ "locked-down",   "LockedDown" }
 };
 
 #define PANEL_APPLET_CONTAINER_GET_PRIVATE(o) \
diff --git a/gnome-panel/libpanel-applet-private/panel-applet-frame-dbus.c b/gnome-panel/libpanel-applet-private/panel-applet-frame-dbus.c
index 83afc26..78c3e50 100644
--- a/gnome-panel/libpanel-applet-private/panel-applet-frame-dbus.c
+++ b/gnome-panel/libpanel-applet-private/panel-applet-frame-dbus.c
@@ -409,6 +409,7 @@ panel_applet_frame_dbus_load (const gchar                 *iid,
 	PanelAppletFrame     *frame;
 	GVariantBuilder       builder;
 	GdkScreen            *screen;
+	gchar                *settings_path;
 	gchar                *conf_path;
 	gchar                *background;
 	guint                 orient;
@@ -425,6 +426,7 @@ panel_applet_frame_dbus_load (const gchar                 *iid,
 
 	screen = panel_applet_frame_activating_get_screen (frame_act);
 	orient = get_panel_applet_orient (panel_applet_frame_activating_get_orientation (frame_act));
+	settings_path = panel_applet_frame_activating_get_settings_path (frame_act);
 	conf_path = panel_applet_frame_activating_get_conf_path (frame_act);
 	/* we can't really get a background string at this point since we don't
 	 * know the position of the applet */
@@ -432,6 +434,9 @@ panel_applet_frame_dbus_load (const gchar                 *iid,
 
 	g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
 	g_variant_builder_add (&builder, "{sv}",
+			       "settings-path",
+			       g_variant_new_string (settings_path));
+	g_variant_builder_add (&builder, "{sv}",
 			       "prefs-key",
 			       g_variant_new_string (conf_path));
 	g_variant_builder_add (&builder, "{sv}",
@@ -458,6 +463,7 @@ panel_applet_frame_dbus_load (const gchar                 *iid,
 				    g_variant_builder_end (&builder));
 
 	g_free (conf_path);
+	g_free (settings_path);
 	g_free (background);
 
 	return TRUE;
diff --git a/gnome-panel/panel-applet-frame.c b/gnome-panel/panel-applet-frame.c
index 29fa427..659c6ea 100644
--- a/gnome-panel/panel-applet-frame.c
+++ b/gnome-panel/panel-applet-frame.c
@@ -41,6 +41,7 @@
 #include "panel-layout.h"
 #include "panel-lockdown.h"
 #include "panel-object-loader.h"
+#include "panel-schemas.h"
 #include "panel-stock-icons.h"
 #include "xstuff.h"
 #include "panel-compatibility.h"
@@ -843,6 +844,20 @@ panel_applet_frame_activating_get_locked_down (PanelAppletFrameActivating *frame
 }
 
 gchar *
+panel_applet_frame_activating_get_settings_path (PanelAppletFrameActivating *frame_act)
+{
+        char *path;
+        char *path_instance;
+
+        g_object_get (frame_act->settings, "path", &path, NULL);
+        path_instance = g_strdup_printf ("%s%s", path,
+                                         PANEL_LAYOUT_OBJECT_CONFIG_SUFFIX);
+        g_free (path);
+
+	return path_instance;
+}
+
+gchar *
 panel_applet_frame_activating_get_conf_path (PanelAppletFrameActivating *frame_act)
 {
 	char *ret;
diff --git a/gnome-panel/panel-applet-frame.h b/gnome-panel/panel-applet-frame.h
index 33567a0..2ef72c3 100644
--- a/gnome-panel/panel-applet-frame.h
+++ b/gnome-panel/panel-applet-frame.h
@@ -108,6 +108,7 @@ GdkScreen        *panel_applet_frame_activating_get_screen      (PanelAppletFram
 PanelOrientation  panel_applet_frame_activating_get_orientation (PanelAppletFrameActivating *frame_act);
 guint32           panel_applet_frame_activating_get_size        (PanelAppletFrameActivating *frame_act);
 gboolean          panel_applet_frame_activating_get_locked_down (PanelAppletFrameActivating *frame_act);
+gchar            *panel_applet_frame_activating_get_settings_path (PanelAppletFrameActivating *frame_act);
 gchar            *panel_applet_frame_activating_get_conf_path   (PanelAppletFrameActivating *frame_act);
 
 void  _panel_applet_frame_set_iid               (PanelAppletFrame           *frame,
diff --git a/libpanel-applet/panel-applet.c b/libpanel-applet/panel-applet.c
index bda9bcc..f656752 100644
--- a/libpanel-applet/panel-applet.c
+++ b/libpanel-applet/panel-applet.c
@@ -89,6 +89,7 @@ struct _PanelAppletPrivate {
 	GClosure          *closure;
 	char              *object_path;
 	guint              object_id;
+	char              *settings_path;
 	char              *prefs_key;
 
 	GtkUIManager      *ui_manager;
@@ -127,6 +128,7 @@ enum {
 	PROP_ID,
 	PROP_CLOSURE,
 	PROP_CONNECTION,
+	PROP_SETTINGS_PATH,
 	PROP_PREFS_KEY,
 	PROP_ORIENT,
 	PROP_SIZE,
@@ -368,6 +370,25 @@ panel_applet_set_preferences_key (PanelApplet *applet,
 	g_object_notify (G_OBJECT (applet), "prefs-key");
 }
 
+static void
+panel_applet_set_settings_path (PanelApplet *applet,
+				const char  *settings_path)
+{
+	if (applet->priv->settings_path == settings_path)
+		return;
+
+	if (g_strcmp0 (applet->priv->settings_path, settings_path) == 0)
+		return;
+
+	g_free (applet->priv->settings_path);
+	applet->priv->settings_path = NULL;
+
+	if (settings_path)
+		applet->priv->settings_path = g_strdup (settings_path);
+
+	g_object_notify (G_OBJECT (applet), "settings-path");
+}
+
 /**
  * panel_applet_get_flags:
  * @applet: a #PanelApplet.
@@ -976,6 +997,7 @@ panel_applet_finalize (GObject *object)
 
 	g_free (applet->priv->size_hints);
 	g_free (applet->priv->prefs_key);
+	g_free (applet->priv->settings_path);
 	g_free (applet->priv->background);
 	g_free (applet->priv->id);
 
@@ -1766,6 +1788,9 @@ panel_applet_get_property (GObject    *object,
 	case PROP_CONNECTION:
 		g_value_set_object (value, applet->priv->connection);
 		break;
+	case PROP_SETTINGS_PATH:
+		g_value_set_string (value, applet->priv->settings_path);
+		break;
 	case PROP_PREFS_KEY:
 		g_value_set_string (value, applet->priv->prefs_key);
 		break;
@@ -1827,6 +1852,9 @@ panel_applet_set_property (GObject      *object,
 	case PROP_CONNECTION:
 		applet->priv->connection = g_value_dup_object (value);
 		break;
+	case PROP_SETTINGS_PATH:
+		panel_applet_set_settings_path (applet, g_value_get_string (value));
+		break;
 	case PROP_PREFS_KEY:
 		panel_applet_set_preferences_key (applet, g_value_get_string (value));
 		break;
@@ -2035,6 +2063,20 @@ panel_applet_class_init (PanelAppletClass *klass)
 							      G_PARAM_CONSTRUCT_ONLY |
 							      G_PARAM_READWRITE));
 	/**
+	 * PanelApplet:settings-path:
+	 *
+	 * The GSettings path to the per-instance settings of the applet.
+	 *
+	 * This property gets set when the applet gets embedded.
+	 **/
+	g_object_class_install_property (gobject_class,
+					 PROP_SETTINGS_PATH,
+					 g_param_spec_string ("settings-path",
+							      "SettingsPath",
+							      "GSettings path to per-instance settings",
+							      NULL,
+							      G_PARAM_READWRITE));
+	/**
 	 * PanelApplet:prefs-key:
 	 *
 	 * The GConf path to the per-instance settings of the applet.
@@ -2264,7 +2306,10 @@ get_property_cb (GDBusConnection *connection,
 	PanelApplet *applet = PANEL_APPLET (user_data);
 	GVariant    *retval = NULL;
 
-	if (g_strcmp0 (property_name, "PrefsKey") == 0) {
+	if (g_strcmp0 (property_name, "SettingsPath") == 0) {
+		retval = g_variant_new_string (applet->priv->settings_path ?
+					       applet->priv->settings_path : "");
+	} else if (g_strcmp0 (property_name, "PrefsKey") == 0) {
 		retval = g_variant_new_string (applet->priv->prefs_key ?
 					       applet->priv->prefs_key : "");
 	} else if (g_strcmp0 (property_name, "Orient") == 0) {
@@ -2305,7 +2350,9 @@ set_property_cb (GDBusConnection *connection,
 {
 	PanelApplet *applet = PANEL_APPLET (user_data);
 
-	if (g_strcmp0 (property_name, "PrefsKey") == 0) {
+	if (g_strcmp0 (property_name, "SettingsPath") == 0) {
+		panel_applet_set_settings_path (applet, g_variant_get_string (value, NULL));
+	} else if (g_strcmp0 (property_name, "PrefsKey") == 0) {
 		panel_applet_set_preferences_key (applet, g_variant_get_string (value, NULL));
 	} else if (g_strcmp0 (property_name, "Orient") == 0) {
 		panel_applet_set_orient (applet, g_variant_get_uint32 (value));
@@ -2339,6 +2386,7 @@ static const gchar introspection_xml[] =
 	      "<arg name='button' type='u' direction='in'/>"
 	      "<arg name='time' type='u' direction='in'/>"
 	    "</method>"
+	    "<property name='SettingsPath' type='s' access='readwrite'/>"
 	    "<property name='PrefsKey' type='s' access='readwrite'/>"
 	    "<property name='Orient' type='u' access='readwrite' />"
 	    "<property name='Size' type='u' access='readwrite'/>"



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