[Xfce4-commits] <xfce4-panel:devel> Drop internal xfconf cache.
Nick Schermer
nick at xfce.org
Thu Sep 3 21:30:05 CEST 2009
Updating branch refs/heads/devel
to ebd3413db8a17862eae7f9674f388daa65b6dd00 (commit)
from 356a39f9b587b5e8674c9742d2584fd0f1eed073 (commit)
commit ebd3413db8a17862eae7f9674f388daa65b6dd00
Author: Nick Schermer <nick at xfce.org>
Date: Thu Sep 3 20:49:51 2009 +0200
Drop internal xfconf cache.
This is implemented in xfconf now, so we don't need it
anymore.
common/panel-xfconf.c | 260 +++-----------------------------------------
common/panel-xfconf.h | 2 -
panel/panel-application.c | 101 ++++++------------
3 files changed, 53 insertions(+), 310 deletions(-)
diff --git a/common/panel-xfconf.c b/common/panel-xfconf.c
index 4ecd05f..559473d 100644
--- a/common/panel-xfconf.c
+++ b/common/panel-xfconf.c
@@ -25,174 +25,24 @@
#include <libxfce4panel/xfce-panel-macros.h>
-typedef struct
-{
- XfconfChannel *channel;
- gchar *channel_prop;
-
- GObject *object;
- gchar *object_prop;
-} PropertyBinding;
-
-
-
-static void panel_properties_object_notify (GObject *object,
- GParamSpec *pspec,
- gpointer user_data);
-static void panel_properties_object_disconnect (gpointer user_data,
- GClosure *closure);
-static void panel_properties_channel_notify (XfconfChannel *channel,
- const gchar *property,
- const GValue *value,
- gpointer user_data);
-static void panel_properties_channel_destroyed (gpointer user_data,
- GObject *where_the_channel_was);
-
-
-
-/* shared table which is used to speed up the panel startup */
-static GHashTable *shared_hash_table = NULL;
-
-
-
-static void
-panel_properties_object_notify (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- GValue value = { 0, };
- PropertyBinding *binding = user_data;
-
- panel_return_if_fail (G_IS_OBJECT (object));
- panel_return_if_fail (binding->object == object);
- panel_return_if_fail (XFCONF_IS_CHANNEL (binding->channel));
-
- /* get the property from the object */
- g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
- g_object_get_property (object, g_param_spec_get_name (pspec), &value);
-
- /* set the xfconf property, unfortunately function blocking is
- * pointless there because dbus is async. so we will receive
- * a property-changed from the channel. */
- xfconf_channel_set_property (binding->channel, binding->channel_prop,
- &value);
-
- /* cleanup */
- g_value_unset (&value);
-}
-
-
-
-static void
-panel_properties_object_disconnect (gpointer user_data,
- GClosure *closure)
-{
- PropertyBinding *binding = user_data;
-
- panel_return_if_fail (XFCONF_IS_CHANNEL (binding->channel));
-
- /* disconnect from the channel */
- if (g_signal_handlers_disconnect_by_func (G_OBJECT (binding->channel),
- panel_properties_channel_notify, binding) > 0)
- {
- g_object_weak_unref (G_OBJECT (binding->channel),
- panel_properties_channel_destroyed, binding);
- }
-
- /* cleanup */
- g_free (binding->channel_prop);
- g_free (binding->object_prop);
- g_slice_free (PropertyBinding, binding);
-}
-
-
-
-static void
-panel_properties_channel_notify (XfconfChannel *channel,
- const gchar *property,
- const GValue *value,
- gpointer user_data)
-{
- PropertyBinding *binding = user_data;
- GParamSpec *pspec;
- GValue def_value = { 0, };
-
- panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
- panel_return_if_fail (binding->channel == channel);
- panel_return_if_fail (G_IS_OBJECT (binding->object));
-
- /* for a property reset, set the default value */
- if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
- {
- pspec = g_object_class_find_property(G_OBJECT_GET_CLASS (binding->object),
- binding->object_prop);
- panel_return_if_fail (pspec == NULL);
- if (G_UNLIKELY (pspec == NULL))
- return;
-
- g_param_value_set_default (pspec, &def_value);
- value = &def_value;
- }
-
- /* block property notify */
- g_signal_handlers_block_by_func (G_OBJECT (binding->object),
- G_CALLBACK (panel_properties_object_notify), binding);
-
- /* set the property */
- g_object_set_property (binding->object, binding->object_prop, value);
-
- /* unblock property notify */
- g_signal_handlers_unblock_by_func (G_OBJECT (binding->object),
- G_CALLBACK (panel_properties_object_notify), binding);
-
- /* cleanup */
- if (G_UNLIKELY (value == &def_value))
- g_value_unset (&def_value);
-}
-
-
-
-static void
-panel_properties_channel_destroyed (gpointer user_data,
- GObject *where_the_channel_was)
-{
- PropertyBinding *binding = user_data;
-
- panel_return_if_fail (binding->channel == (XfconfChannel *) where_the_channel_was);
- panel_return_if_fail (G_IS_OBJECT (binding->object));
-
- /* disconnect from the object, which will take
- * care of freeing everything else */
- g_signal_handlers_disconnect_by_func (G_OBJECT (binding->object),
- panel_properties_object_notify, binding);
-}
-
-
XfconfChannel *
panel_properties_get_channel (void)
{
- static XfconfChannel *channel = NULL;
- GError *error = NULL;
+ GError *error = NULL;
+ XfconfChannel *channel;
- if (G_UNLIKELY (channel == NULL))
+ if (!xfconf_init (&error))
{
- if (!xfconf_init (&error))
- {
- g_critical ("Failed to initialize Xfconf: %s", error->message);
- g_error_free (error);
- }
-
- channel = xfconf_channel_new (XFCE_PANEL_PLUGIN_CHANNEL_NAME);
- g_object_add_weak_pointer (G_OBJECT (channel), (gpointer) &channel);
-
- g_object_weak_ref (G_OBJECT (channel), (GWeakNotify) xfconf_shutdown, NULL);
- }
- else
- {
- g_object_ref (G_OBJECT (channel));
+ g_critical ("Failed to initialize Xfconf: %s", error->message);
+ g_error_free (error);
+ return NULL;
}
+ channel = xfconf_channel_get (XFCE_PANEL_PLUGIN_CHANNEL_NAME);
+ /* TODO enable this again when Brian fixed his code
+ * _object_weak_ref (G_OBJECT (channel), (GWeakNotify) xfconf_shutdown, NULL); */
+
return channel;
}
@@ -206,10 +56,7 @@ panel_properties_bind (XfconfChannel *channel,
gboolean save_properties)
{
const PanelProperty *prop;
- const GValue *value;
- gchar buf[512];
- PropertyBinding *binding;
- GHashTable *hash_table;
+ gchar *property;
panel_return_if_fail (channel == NULL || XFCONF_IS_CHANNEL (channel));
panel_return_if_fail (G_IS_OBJECT (object));
@@ -218,69 +65,19 @@ panel_properties_bind (XfconfChannel *channel,
if (G_LIKELY (channel == NULL))
{
- /* use the default channel if none is set by the user and take
- * care of refcounting */
- channel = panel_properties_get_channel ();
- panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
+ channel = xfconf_channel_get (XFCE_PANEL_PLUGIN_CHANNEL_NAME);
+ if (G_UNLIKELY (channel == NULL))
+ return;
g_object_weak_ref (G_OBJECT (object), (GWeakNotify) g_object_unref, channel);
}
- /* get or ref the hash table */
- if (save_properties)
- hash_table = NULL;
- else if (shared_hash_table != NULL)
- hash_table = g_hash_table_ref (shared_hash_table);
- else if (channel != NULL)
- hash_table = xfconf_channel_get_properties (channel, property_base);
- else
- panel_assert_not_reached ();
-
/* walk the properties array */
for (prop = properties; prop->property != NULL; prop++)
{
- /* create a new binding */
- binding = g_slice_new (PropertyBinding);
- binding->channel = channel;
- binding->channel_prop = g_strconcat (property_base, "/", prop->property, NULL);
- binding->object = object;
- binding->object_prop = g_strdup (prop->property);
-
- /* lookup the property value */
- if (hash_table != NULL)
- {
- value = g_hash_table_lookup (hash_table, binding->channel_prop);
- if (G_IS_VALUE (value))
- {
- if (G_LIKELY (G_VALUE_TYPE (value) == prop->type))
- g_object_set_property (object, prop->property, value);
- else
- g_message ("Value types of property \"%s\" do not "
- "match: channel = %s, property = %s", buf,
- G_VALUE_TYPE_NAME (value),
- g_type_name (prop->type));
- }
- }
-
- /* monitor object property changes */
- g_snprintf (buf, sizeof (buf), "notify::%s", prop->property);
- g_signal_connect_data (G_OBJECT (object), buf,
- G_CALLBACK (panel_properties_object_notify), binding,
- panel_properties_object_disconnect, 0);
-
- /* emit the property so it gets saved */
- if (save_properties)
- g_object_notify (G_OBJECT (object), prop->property);
-
- /* monitor channel changes */
- g_snprintf (buf, sizeof (buf), "property-changed::%s", binding->channel_prop);
- g_object_weak_ref (G_OBJECT (channel), panel_properties_channel_destroyed, binding);
- g_signal_connect (G_OBJECT (channel), buf,
- G_CALLBACK (panel_properties_channel_notify), binding);
+ property = g_strconcat (property_base, "/", prop->property, NULL);
+ xfconf_g_property_bind (channel, property, prop->type, object, prop->property);
+ g_free (property);
}
-
- /* cleanup */
- if (G_LIKELY (hash_table != NULL))
- g_hash_table_unref (hash_table);
}
@@ -288,26 +85,5 @@ panel_properties_bind (XfconfChannel *channel,
void
panel_properties_unbind (GObject *object)
{
- panel_return_if_fail (G_IS_OBJECT (object));
- panel_return_if_fail (!XFCONF_IS_CHANNEL (object));
-
- /* disconnect the notify functions */
- g_signal_handlers_disconnect_matched (object, G_SIGNAL_MATCH_FUNC,
- 0, 0, NULL, G_CALLBACK (panel_properties_object_notify), NULL);
-}
-
-
-
-void
-panel_properties_shared_hash_table (GHashTable *hash_table)
-{
- /* release previous table */
- if (shared_hash_table != NULL)
- g_hash_table_unref (shared_hash_table);
-
- /* set new table */
- if (hash_table != NULL)
- shared_hash_table = g_hash_table_ref (hash_table);
- else
- shared_hash_table = NULL;
+ xfconf_g_property_unbind_all (object);
}
diff --git a/common/panel-xfconf.h b/common/panel-xfconf.h
index 5c5f32b..0551c05 100644
--- a/common/panel-xfconf.h
+++ b/common/panel-xfconf.h
@@ -43,6 +43,4 @@ void panel_properties_bind (XfconfChannel *channel,
void panel_properties_unbind (GObject *object);
-void panel_properties_shared_hash_table (GHashTable *hash_table);
-
#endif /* !__PANEL_XFCONF_H__ */
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 7d69b47..ad8ce36 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -50,8 +50,7 @@
static void panel_application_finalize (GObject *object);
-static void panel_application_load (PanelApplication *application,
- GHashTable *hash_table);
+static void panel_application_load (PanelApplication *application);
static void panel_application_plugin_move (GtkWidget *item,
PanelApplication *application);
static gboolean panel_application_plugin_insert (PanelApplication *application,
@@ -139,17 +138,17 @@ enum
static const GtkTargetEntry drag_targets[] =
{
- { (gchar *) "xfce-panel/plugin-widget",
+ { "xfce-panel/plugin-widget",
GTK_TARGET_SAME_APP, TARGET_PLUGIN_WIDGET }
};
static const GtkTargetEntry drop_targets[] =
{
- { (gchar *) "xfce-panel/plugin-name",
+ { "xfce-panel/plugin-name",
GTK_TARGET_SAME_APP, TARGET_PLUGIN_NAME },
- { (gchar *) "xfce-panel/plugin-widget",
+ { "xfce-panel/plugin-widget",
GTK_TARGET_SAME_APP, TARGET_PLUGIN_WIDGET },
- { (gchar *) "text/uri-list",
+ { "text/uri-list",
GTK_TARGET_OTHER_APP, TARGET_TEXT_URI_LIST }
};
@@ -173,9 +172,7 @@ panel_application_class_init (PanelApplicationClass *klass)
static void
panel_application_init (PanelApplication *application)
{
- PanelWindow *window;
- GHashTable *hash_table;
- const GValue *value;
+ PanelWindow *window;
/* initialize */
application->windows = NULL;
@@ -188,26 +185,15 @@ panel_application_init (PanelApplication *application)
/* get the xfconf channel */
application->xfconf = panel_properties_get_channel ();
- /* get all the panel properties */
- hash_table = xfconf_channel_get_properties (application->xfconf, NULL);
-
- if (G_LIKELY (hash_table != NULL))
- {
- /* check if we need to force all plugins to run external */
- value = g_hash_table_lookup (hash_table, "/force-all-external");
- if (value != NULL && g_value_get_boolean (value))
- panel_module_factory_force_all_external ();
-
- /* set the shared hash table */
- panel_properties_shared_hash_table (hash_table);
- }
+ /* check if we need to force all plugins to run external */
+ if (xfconf_channel_get_bool (application->xfconf, "/force-all-external", FALSE))
+ panel_module_factory_force_all_external ();
/* get a factory reference so it never unloads */
application->factory = panel_module_factory_get ();
/* load setup */
- if (G_LIKELY (hash_table != NULL))
- panel_application_load (application, hash_table);
+ panel_application_load (application);
/* start the autosave timeout */
panel_application_save_reschedule (application);
@@ -215,15 +201,6 @@ panel_application_init (PanelApplication *application)
/* create empty window */
if (G_UNLIKELY (application->windows == NULL))
window = panel_application_new_window (application, NULL, TRUE);
-
- if (G_LIKELY (hash_table != NULL))
- {
- /* unset the shared hash table */
- panel_properties_shared_hash_table (NULL);
-
- /* cleanup */
- g_hash_table_destroy (hash_table);
- }
}
@@ -302,25 +279,22 @@ panel_application_xfconf_window_bindings (PanelApplication *application,
static void
-panel_application_load (PanelApplication *application,
- GHashTable *hash_table)
+panel_application_load (PanelApplication *application)
{
- const GValue *value;
PanelWindow *window;
guint i, j, n_panels;
gchar buf[50];
- const gchar *name;
+ gchar *name;
gint unique_id;
GdkScreen *screen;
GPtrArray *array;
+ const GValue *value;
panel_return_if_fail (PANEL_IS_APPLICATION (application));
panel_return_if_fail (XFCONF_IS_CHANNEL (application->xfconf));
- panel_return_if_fail (hash_table != NULL);
/* walk all the panel in the configuration */
- value = g_hash_table_lookup (hash_table, "/panels");
- n_panels = value != NULL ? g_value_get_uint (value) : 0;
+ n_panels = xfconf_channel_get_uint (application->xfconf, "/panels", 0);
for (i = 0; i < n_panels; i++)
{
/* create a new window */
@@ -328,30 +302,27 @@ panel_application_load (PanelApplication *application,
screen = gtk_window_get_screen (GTK_WINDOW (window));
/* walk all the plugins on the panel */
- g_snprintf (buf, sizeof (buf), "/panels/panel-%u/plugins", i);
- value = g_hash_table_lookup (hash_table, buf);
- array = value ? g_value_get_boxed (value) : NULL;
- if (value == NULL || array->len % 2 != 0)
+ g_snprintf (buf, sizeof (buf), "/panels/panel-%u/plugin-ids", i);
+ array = xfconf_channel_get_arrayv (application->xfconf, buf);
+ if (array == NULL)
continue;
/* walk the array in pairs of two */
- for (j = 0; j < array->len; j += 2)
+ for (j = 0; j < array->len; j++)
{
- /* get the plugin module name */
+ /* get the plugin id */
value = g_ptr_array_index (array, j);
- name = value != NULL ? g_value_get_string (value) : NULL;
- if (G_UNLIKELY (name == NULL))
- continue;
+ panel_assert (value != NULL);
+ unique_id = g_value_get_int (value);
- /* get the plugin id */
- value = g_ptr_array_index (array, j + 1);
- unique_id = value != NULL ? g_value_get_int (value) : -1;
- if (G_UNLIKELY (unique_id < 1))
- continue;
+ /* get the plugin name */
+ g_snprintf (buf, sizeof (buf), "/plugins/plugin-%d", unique_id);
+ name = xfconf_channel_get_string (application->xfconf, buf, NULL);
/* append the plugin to the panel */
- if (!panel_application_plugin_insert (application, window, screen,
- name, unique_id, NULL, -1))
+ if (unique_id < 1 || name == NULL
+ || !panel_application_plugin_insert (application, window, screen,
+ name, unique_id, NULL, -1))
{
/* plugin could not be loaded, remove it from the channel */
g_snprintf (buf, sizeof (buf), "/panels/plugin-%d", unique_id);
@@ -361,6 +332,8 @@ panel_application_load (PanelApplication *application,
g_critical (_("Plugin \"%s-%d\" was not found and has been "
"removed from the configuration"), name, unique_id);
}
+
+ g_free (name);
}
}
}
@@ -1037,12 +1010,10 @@ panel_application_save (PanelApplication *application,
itembar = gtk_bin_get_child (GTK_BIN (li->data));
children = gtk_container_get_children (GTK_CONTAINER (itembar));
- /* create property name */
- g_snprintf (buf, sizeof (buf), "/panels/panel-%u/plugins", i);
-
/* only cleanup and continue if there are no children */
if (G_UNLIKELY (children == NULL))
{
+ g_snprintf (buf, sizeof (buf), "/panels/panel-%u/plugin-ids", i);
xfconf_channel_reset_property (channel, buf, FALSE);
continue;
}
@@ -1055,13 +1026,6 @@ panel_application_save (PanelApplication *application,
{
provider = XFCE_PANEL_PLUGIN_PROVIDER (lp->data);
- /* add plugin name to the array */
- value = g_new0 (GValue, 1);
- g_value_init (value, G_TYPE_STRING);
- g_value_set_static_string (value,
- xfce_panel_plugin_provider_get_name (provider));
- g_ptr_array_add (array, value);
-
/* add plugin id to the array */
value = g_new0 (GValue, 1);
g_value_init (value, G_TYPE_INT);
@@ -1069,12 +1033,17 @@ panel_application_save (PanelApplication *application,
xfce_panel_plugin_provider_get_unique_id (provider));
g_ptr_array_add (array, value);
+ /* make sure the plugin type is store in the plugin item */
+ g_snprintf (buf, sizeof (buf), "/plugins/plugin-%d", g_value_get_int (value));
+ xfconf_channel_set_string (channel, buf, xfce_panel_plugin_provider_get_name (provider));
+
/* ask the plugin to save */
if (save_plugin_providers)
xfce_panel_plugin_provider_save (provider);
}
/* store the plugins for this panel */
+ g_snprintf (buf, sizeof (buf), "/panels/panel-%u/plugin-ids", i);
xfconf_channel_set_arrayv (channel, buf, array);
/* cleanup */
More information about the Xfce4-commits
mailing list