Re: [Nautilus-list] preferences



Darin Adler wrote:
> 
> There's definitely no good reason to store the visibilities in GConf. That'
> s a bit of weirdness that crept in that I should have prevented when
> talking with Ramiro about this design in the first place. I can't even
> make a strong argument for having the visibilities in a data file rather
> than a table inside Nautilus code. In effect, they're already in a table,
> just a table that's used to populate GConf settings that are then never
> changed.
> 
>      -- Darin
> 

Yep Darin, I already fessed up to screwing this up previously on this
thread.

I just checked in the attatched patch to both eel1 and eel2 that removes
this whacky scheme of using gconf itself to store visibilities and user
level specific defaults.

It simplified the preferences code a significant amount I think.

I havent changed any of the user level system behavior or features.  Its
just a cleanup to remove the "gross innefeciencies" as I said before in
this thread.

We can now continue to debate whether to simplify that system more by
dropping per user level defaults and about moving the visibilitiy
feature to gconf proper.

Havoc: this should kill the startup time hit you were talking
about before, since it completely avoids the dumb gconf daemon traffic
at init
time.  The info for visiblities and default values is now stored in the
eel preferences table which has to be initialized and maintained by each
nautilus process that wants to use preferences.  A possible improvement
to this would be to use schemas somehow.  Im not planning to hack on
that, though.

This change causes no binary or source compat problems for Nautilus.

-re
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/eel/ChangeLog,v
retrieving revision 1.113.2.23
diff -u -u -r1.113.2.23 ChangeLog
--- ChangeLog	2001/08/22 09:21:02	1.113.2.23
+++ ChangeLog	2001/08/22 17:00:44
@@ -1,3 +1,60 @@
+2001-08-22  Ramiro Estrugo  <ramiro fateware com>
+
+	* eel/eel-gconf-extensions.h:
+	* eel/eel-gconf-extensions.c: (eel_gconf_is_default): Use value
+	free cover that does its own not NULL checking.
+	(eel_gconf_value_get_string_list),
+	(eel_gconf_value_set_string_list): New function to deal with
+	GConfValue lists of GNONF_VALUE_STRING type.
+
+	* eel/eel-preferences.c: (preferences_gconf_value_get_int),
+	(preferences_gconf_value_get_bool),
+	(preferences_gconf_value_get_string),
+	(preferences_gconf_value_get_string_list), (preferences_get_value),
+	(preferences_preference_is_gconf_key), (preferences_key_make),
+	(preferences_find_first_non_null_default_value),
+	(eel_preferences_get_visible_user_level),
+	(eel_preferences_set_visible_user_level),
+	(eel_preferences_set_is_invisible), (eel_preferences_set_boolean),
+	(eel_preferences_get_boolean), (eel_preferences_set_integer),
+	(eel_preferences_get_integer), (eel_preferences_set),
+	(eel_preferences_get), (eel_preferences_set_string_list),
+	(eel_preferences_get_string_list),
+	(eel_preferences_default_set_integer),
+	(eel_preferences_default_get_integer),
+	(eel_preferences_default_set_boolean),
+	(eel_preferences_default_get_boolean),
+	(eel_preferences_default_set_string),
+	(eel_preferences_default_get_string),
+	(eel_preferences_default_set_string_list),
+	(eel_preferences_default_get_string_list),
+	(preferences_entry_invoke_callbacks_if_needed),
+	(preferences_entry_update_cached_value),
+	(preferences_entry_ensure_gconf_connection),
+	(preferences_entry_free), (preferences_global_table_free),
+	(eel_preferences_add_callback), (eel_preferences_add_auto_string),
+	(eel_preferences_add_auto_string_list),
+	(eel_preferences_add_auto_integer),
+	(eel_preferences_add_auto_boolean),
+	(eel_preferences_remove_auto_string),
+	(eel_preferences_remove_auto_string_list),
+	(eel_preferences_remove_auto_integer),
+	(eel_preferences_remove_auto_boolean),
+	(preferences_while_alive_disconnector),
+	(eel_preferences_add_callback_while_alive),
+	(eel_preferences_remove_callback),
+	(eel_preferences_set_description),
+	(eel_preferences_set_enumeration_id),
+	(eel_preferences_visible_in_current_user_level),
+	(eel_preferences_initialize):
+	Cleanup whacky system where preference visibilities and default
+	values were stored using gconf.  Instead, store the visibilities
+	and defaults values in the already existing table of preferences.
+	The changes make this code a bit simpler.  In particular, the code
+	to create the right keys is now gone.  Add some covers for getting
+	values out of GConfValue safely and with some extra checking the
+	the types are right.
+	
 2001-08-20  Maciej Stachowiak  <mjs noisehavoc org>
 
 	* configure.in: Change the way we generate libtool's dependency
Index: eel/eel-gconf-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gconf-extensions.c,v
retrieving revision 1.1
diff -u -u -r1.1 eel-gconf-extensions.c
--- eel/eel-gconf-extensions.c	2001/05/04 09:50:59	1.1
+++ eel/eel-gconf-extensions.c	2001/08/22 17:00:44
@@ -270,12 +270,7 @@
 	}
 
 	result = (value == NULL);
-
-	if (value != NULL) {
-		gconf_value_free (value);
-	}
-
-	
+	eel_gconf_value_free (value);
 	return result;
 }
 
@@ -512,4 +507,53 @@
 	g_return_if_fail (client != NULL);
 
 	gconf_client_notify_remove (client, notification_id);
+}
+
+GSList *
+eel_gconf_value_get_string_list (const GConfValue *value)
+{
+ 	GSList *result;
+ 	const GSList *slist;
+ 	const GSList *node;
+	const char *string;
+	const GConfValue *next_value;
+
+	if (value == NULL) {
+		return NULL;
+	}
+
+	g_return_val_if_fail (value->type == GCONF_VALUE_LIST, NULL);
+	g_return_val_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING, NULL);
+
+	slist = gconf_value_get_list (value);
+	result = NULL;
+	for (node = slist; node != NULL; node = node->next) {
+		next_value = node->data;
+		g_return_val_if_fail (next_value != NULL, NULL);
+		g_return_val_if_fail (next_value->type == GCONF_VALUE_STRING, NULL);
+		string = gconf_value_get_string (next_value);
+		result = g_slist_append (result, g_strdup (string));
+	}
+	return result;
+}
+
+void
+eel_gconf_value_set_string_list (GConfValue *value,
+				 const GSList *string_list)
+{
+ 	const GSList *node;
+	GConfValue *next_value;
+ 	GSList *value_list;
+
+	g_return_if_fail (value->type == GCONF_VALUE_LIST);
+	g_return_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING);
+
+	value_list = NULL;
+	for (node = string_list; node != NULL; node = node->next) {
+		next_value = gconf_value_new (GCONF_VALUE_STRING);
+		gconf_value_set_string (next_value, node->data);
+		value_list = g_slist_append (value_list, next_value);
+	}
+
+	gconf_value_set_list (value, value_list);
 }
Index: eel/eel-gconf-extensions.h
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gconf-extensions.h,v
retrieving revision 1.1
diff -u -u -r1.1 eel-gconf-extensions.h
--- eel/eel-gconf-extensions.h	2001/05/04 09:50:59	1.1
+++ eel/eel-gconf-extensions.h	2001/08/22 17:00:44
@@ -33,32 +33,35 @@
 
 #define EEL_GCONF_UNDEFINED_CONNECTION 0
 
-GConfClient *eel_gconf_client_get_global   (void);
-gboolean     eel_gconf_handle_error        (GError                **error);
-void         eel_gconf_set_boolean         (const char             *key,
-					    gboolean                boolean_value);
-gboolean     eel_gconf_get_boolean         (const char             *key);
-int          eel_gconf_get_integer         (const char             *key);
-void         eel_gconf_set_integer         (const char             *key,
-					    int                     int_value);
-char *       eel_gconf_get_string          (const char             *key);
-void         eel_gconf_set_string          (const char             *key,
-					    const char             *string_value);
-GSList *     eel_gconf_get_string_list     (const char             *key);
-void         eel_gconf_set_string_list     (const char             *key,
-					    const GSList           *string_list_value);
-gboolean     eel_gconf_is_default          (const char             *key);
-gboolean     eel_gconf_monitor_add         (const char             *directory);
-gboolean     eel_gconf_monitor_remove      (const char             *directory);
-void         eel_gconf_suggest_sync        (void);
-GConfValue*  eel_gconf_get_value           (const char             *key);
-gboolean     eel_gconf_value_is_equal      (const GConfValue       *a,
-					    const GConfValue       *b);
-void         eel_gconf_value_free          (GConfValue             *value);
-guint        eel_gconf_notification_add    (const char             *key,
-					    GConfClientNotifyFunc   notification_callback,
-					    gpointer                callback_data);
-void         eel_gconf_notification_remove (guint                   notification_id);
+GConfClient *eel_gconf_client_get_global     (void);
+gboolean     eel_gconf_handle_error          (GError                **error);
+void         eel_gconf_set_boolean           (const char             *key,
+					      gboolean                boolean_value);
+gboolean     eel_gconf_get_boolean           (const char             *key);
+int          eel_gconf_get_integer           (const char             *key);
+void         eel_gconf_set_integer           (const char             *key,
+					      int                     int_value);
+char *       eel_gconf_get_string            (const char             *key);
+void         eel_gconf_set_string            (const char             *key,
+					      const char             *string_value);
+GSList *     eel_gconf_get_string_list       (const char             *key);
+void         eel_gconf_set_string_list       (const char             *key,
+					      const GSList           *string_list_value);
+gboolean     eel_gconf_is_default            (const char             *key);
+gboolean     eel_gconf_monitor_add           (const char             *directory);
+gboolean     eel_gconf_monitor_remove        (const char             *directory);
+void         eel_gconf_suggest_sync          (void);
+GConfValue*  eel_gconf_get_value             (const char             *key);
+gboolean     eel_gconf_value_is_equal        (const GConfValue       *a,
+					      const GConfValue       *b);
+void         eel_gconf_value_free            (GConfValue             *value);
+guint        eel_gconf_notification_add      (const char             *key,
+					      GConfClientNotifyFunc   notification_callback,
+					      gpointer                callback_data);
+void         eel_gconf_notification_remove   (guint                   notification_id);
+GSList *     eel_gconf_value_get_string_list (const GConfValue       *value);
+void         eel_gconf_value_set_string_list (GConfValue             *value,
+					      const GSList           *string_list);
 
 END_GNOME_DECLS
 
Index: eel/eel-preferences.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-preferences.c,v
retrieving revision 1.1
diff -u -u -r1.1 eel-preferences.c
--- eel/eel-preferences.c	2001/05/04 09:50:59	1.1
+++ eel/eel-preferences.c	2001/08/22 17:00:45
@@ -46,8 +46,7 @@
  * FIXME: there is another enumeration like this in eel-global-preferences.c,
  * used for different purposes but in a related way. Should we combine them?
  */
-typedef enum
-{
+typedef enum {
 	PREFERENCE_BOOLEAN = 1,
 	PREFERENCE_INTEGER,
 	PREFERENCE_STRING,
@@ -72,6 +71,8 @@
 	int gconf_connection_id;
 	char *enumeration_id;
 	GConfValue *cached_value;
+	int visible_user_level;
+	GConfValue *default_values[3];
 } PreferencesEntry;
 
 /*
@@ -86,58 +87,96 @@
 	gpointer callback_data;
 } PreferencesCallbackEntry;
 
-static const char *user_level_names_for_display[] =
-{
+static const char *user_level_names_for_display[] = {
 	N_("Beginner"),
 	N_("Intermediate"),
 	N_("Advanced")
 };
 
-static const char *user_level_names_for_storage[] =
-{
+static const char *user_level_names_for_storage[] = {
 	"novice",
 	"intermediate",
 	"advanced"
 };
 
-static const char * preferences_peek_storage_path                   (void);
-static const char * preferences_peek_defaults_path                  (void);
-static const char * preferences_peek_visibility_path                (void);
-static gboolean     preferences_preference_is_internal              (const char               *name);
-static gboolean     preferences_preference_is_user_level            (const char               *name);
-static gboolean     preferences_preference_is_default               (const char               *name);
-static char *       preferences_key_make                            (const char               *name);
-static char *       preferences_key_make_for_getter                 (const char               *name);
-static char *       preferences_key_make_for_default                (const char               *name,
-								     int                       user_level);
-static char *       preferences_key_make_for_default_getter         (const char               *name,
-								     int                       user_level);
-static char *       preferences_key_make_for_visibility             (const char               *name);
-static void         preferences_user_level_changed_notice           (GConfClient              *client,
-								     guint                     connection_id,
-								     GConfEntry               *gconf_entry,
-								     gpointer                  user_data);
-static void         preferences_something_changed_notice            (GConfClient              *client,
-								     guint                     connection_id,
-								     GConfEntry               *gconf_entry,
-								     gpointer                  user_data);
-static void         preferences_global_table_check_changes_function (gpointer                  key,
-								     gpointer                  value,
-								     gpointer                  callback_data);
-static GHashTable  *preferences_global_table_get_global             (void);
-static void         preferences_callback_entry_free                 (PreferencesCallbackEntry *callback_entry);
-static void         preferences_entry_update_auto_storage           (PreferencesEntry         *entry);
-static void         preferences_global_table_free                   (void);
-static const char * preferences_peek_user_level_name_for_storage    (int                       user_level);
-static PreferencesEntry * preferences_global_table_lookup_or_insert (const char *name);
+static const char *      preferences_peek_storage_path                   (void);
+static gboolean          preferences_preference_is_gconf_key             (const char               *name);
+static gboolean          preferences_preference_is_user_level            (const char               *name);
+static gboolean          preferences_preference_is_default               (const char               *name);
+static char *            preferences_key_make                            (const char               *name);
+static void              preferences_user_level_changed_notice           (GConfClient              *client,
+									  guint                     connection_id,
+									  GConfEntry               *gconf_entry,
+									  gpointer                  user_data);
+static void              preferences_something_changed_notice            (GConfClient              *client,
+									  guint                     connection_id,
+									  GConfEntry               *gconf_entry,
+									  gpointer                  user_data);
+static void              preferences_global_table_check_changes_function (gpointer                  key,
+									  gpointer                  value,
+									  gpointer                  callback_data);
+static GHashTable  *     preferences_global_table_get_global             (void);
+static void              preferences_callback_entry_free                 (PreferencesCallbackEntry *callback_entry);
+static void              preferences_entry_update_auto_storage           (PreferencesEntry         *entry);
+static void              preferences_global_table_free                   (void);
+static const char *      preferences_peek_user_level_name_for_storage    (int                       user_level);
+static PreferencesEntry *preferences_global_table_lookup_or_insert       (const char               *name);
+static const GConfValue *preferences_find_first_non_null_default_value   (const char               *name,
+									  int                       user_level);
 
 static guint user_level_changed_connection_id = EEL_GCONF_UNDEFINED_CONNECTION;
 static GHashTable *global_table = NULL;
 static char *storage_path = NULL;
-static char *defaults_path = NULL;
-static char *visiblity_path = NULL;
 static gboolean initialized = FALSE;
 
+static int
+preferences_gconf_value_get_int (const GConfValue *value)
+{
+	if (value == NULL) {
+		return 0;
+	}
+	g_return_val_if_fail (value->type == GCONF_VALUE_INT, 0);
+	return gconf_value_get_int (value);
+}
+
+static gboolean
+preferences_gconf_value_get_bool (const GConfValue *value)
+{
+	if (value == NULL) {
+		return FALSE;
+	}
+	g_return_val_if_fail (value->type == GCONF_VALUE_BOOL, FALSE);
+	return gconf_value_get_bool (value);
+}
+
+static char *
+preferences_gconf_value_get_string (const GConfValue *value)
+{
+	if (value == NULL) {
+		return g_strdup ("");
+	}
+	g_return_val_if_fail (value->type == GCONF_VALUE_STRING, g_strdup (""));
+	return g_strdup (gconf_value_get_string (value));
+}
+
+static EelStringList *
+preferences_gconf_value_get_string_list (const GConfValue *value)
+{
+	GSList *slist;
+	EelStringList *result;
+
+	if (value == NULL) {
+		return eel_string_list_new (TRUE);
+	}
+	g_return_val_if_fail (value->type == GCONF_VALUE_LIST, eel_string_list_new (TRUE));
+	g_return_val_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING, eel_string_list_new (TRUE));
+
+	slist = eel_gconf_value_get_string_list (value);
+	result = eel_string_list_new_from_g_slist (slist, TRUE);
+	eel_g_slist_free_deep (slist);
+ 	return result;
+}
+
 static const char *
 preferences_peek_storage_path (void)
 {
@@ -175,24 +214,32 @@
 	return initialized;
 }
 
-static const char *
-preferences_peek_defaults_path (void)
+static GConfValue *
+preferences_get_value (const char *name)
 {
-	if (defaults_path == NULL) {
-		defaults_path = g_strdup_printf ("%s/defaults", preferences_peek_storage_path ());
-	}
+	GConfValue *result;
+	char *key;
+	const GConfValue *default_value;
 
-	return defaults_path;
-}
+	g_return_val_if_fail (name != NULL, 0);
+	g_return_val_if_fail (preferences_is_initialized (), 0);
 
-static const char *
-preferences_peek_visibility_path (void)
-{
-	if (visiblity_path == NULL) {
-		visiblity_path = g_strdup_printf ("%s/visibility", preferences_peek_storage_path ());
+	/* If the preference is default (no value is stored for it) or
+	 * it is not visible in the current user level, return the
+	 * default_value */
+	if (preferences_preference_is_default (name)
+	    || !eel_preferences_visible_in_current_user_level (name)) {
+		default_value = preferences_find_first_non_null_default_value (name, eel_preferences_get_user_level ());
+		return (default_value != NULL)
+			? gconf_value_copy ((GConfValue *) default_value)
+			: NULL;
 	}
+
+	key = preferences_key_make (name);
+	result = eel_gconf_get_value (key);
+	g_free (key);
 
-	return visiblity_path;
+	return result;
 }
 
 static const char *
@@ -206,7 +253,7 @@
 /* If the preference name begind with a "/", we interpret 
  * it as a straight gconf key. */
 static gboolean
-preferences_preference_is_internal (const char *name)
+preferences_preference_is_gconf_key (const char *name)
 {
 	g_return_val_if_fail (name != NULL, FALSE);
 	
@@ -231,73 +278,41 @@
 {
 	g_return_val_if_fail (name != NULL, NULL);
 	
-	if (!preferences_preference_is_internal (name)) {
+	if (!preferences_preference_is_gconf_key (name)) {
 		return g_strdup (name);
 	}
 
 	/* Otherwise, we prefix it with the path */
 	return g_strdup_printf ("%s/%s", preferences_peek_storage_path (), name);
 }
-
-static char *
-preferences_key_make_for_default (const char *name,
-				  int user_level)
-{
-	char *key;
-	char *default_key = NULL;
-
-	g_return_val_if_fail (name != NULL, NULL);
-
-	user_level = eel_preferences_user_level_clamp (user_level);
-	key = preferences_key_make (name);
-	default_key = g_strdup_printf ("%s/%s%s",
-				       preferences_peek_defaults_path (),
-				       preferences_peek_user_level_name_for_storage (user_level),
-				       key);
-	g_free (key);
-	
-	return default_key;
-}
 
-static char *
-preferences_key_make_for_default_getter (const char *name,
-					 int user_level)
+/* Find the first non NULL default_value that is less than or 
+ * equal to the given user level */
+static const GConfValue *
+preferences_find_first_non_null_default_value (const char *name,
+					       int user_level)
 {
-	char *default_key_for_getter = NULL;
+	const GConfValue *result;
+	PreferencesEntry *entry;
 	gboolean done;
 
 	g_return_val_if_fail (name != NULL, NULL);
 
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
+
 	user_level = eel_preferences_user_level_clamp (user_level);
 
 	done = FALSE;
 	while (!done) {
-		default_key_for_getter = preferences_key_make_for_default (name, user_level);
-		
-		done = (user_level == 0) || (!eel_gconf_is_default (default_key_for_getter));
-		
+		result = entry->default_values[user_level];
+		done = (user_level == 0) || (result != NULL);
 		if (!done) {
-			g_free (default_key_for_getter);
 			user_level--;
 		}
 	}
-
-	return default_key_for_getter;
-}
-
-static char *
-preferences_key_make_for_visibility (const char *name)
-{
-	char *default_key;
-	char *key;
 
-	g_return_val_if_fail (name != NULL, NULL);
-
-	key = preferences_key_make (name);
-	default_key = g_strdup_printf ("%s%s", preferences_peek_visibility_path (), key);
-	g_free (key);
-	
-	return default_key;
+	return result;
 }
 
 static gboolean
@@ -315,22 +330,6 @@
 	return result;
 }
 
-static char *
-preferences_make_user_level_filtered_key (const char *name)
-{
-	char *key;
-	
-	g_return_val_if_fail (name != NULL, NULL);
-
-	if (eel_preferences_visible_in_current_user_level (name)) {
-		key = preferences_key_make (name);
-	} else {
-		key = preferences_key_make_for_default (name, eel_preferences_get_user_level ());
-	}
-
-	return key;
-}
-
 static void
 preferences_block_callbacks (const char *name)
 {
@@ -363,31 +362,21 @@
 int
 eel_preferences_get_visible_user_level (const char *name)
 {
-  	int result;
-	char *visible_key;
-	
 	g_return_val_if_fail (name != NULL, FALSE);
 	g_return_val_if_fail (preferences_is_initialized (), FALSE);
-	
-	visible_key = preferences_key_make_for_visibility (name);
-	result = eel_gconf_get_integer (visible_key);
-	g_free (visible_key);
 
-	return result;
+	return preferences_global_table_lookup_or_insert (name)->visible_user_level;
 }
 
 void
 eel_preferences_set_visible_user_level (const char *name,
-					     int visible_user_level)
+					int visible_user_level)
 {
-	char *visible_key;
-	
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (preferences_is_initialized ());
-	
-	visible_key = preferences_key_make_for_visibility (name);
-	eel_gconf_set_integer (visible_key, visible_user_level);
-	g_free (visible_key);
+
+	preferences_global_table_lookup_or_insert (name)->visible_user_level =
+		eel_preferences_user_level_clamp (visible_user_level);
 }
 
 gboolean
@@ -401,7 +390,7 @@
 
 void
 eel_preferences_set_is_invisible (const char *name,
-				       gboolean is_invisible)
+				  gboolean is_invisible)
 {
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (preferences_is_initialized ());
@@ -411,7 +400,7 @@
 
 void
 eel_preferences_set_boolean (const char *name,
-				  gboolean boolean_value)
+			     gboolean boolean_value)
 {
 	char *key;
 
@@ -425,42 +414,25 @@
 	eel_gconf_suggest_sync ();
 }
 
-static char *
-preferences_key_make_for_getter (const char *name)
-{
-	char *key;
-
-	g_return_val_if_fail (name != NULL, NULL);
-	g_return_val_if_fail (preferences_is_initialized (), NULL);
-
-	if (preferences_preference_is_default (name) || !eel_preferences_visible_in_current_user_level (name)) {
-		key = preferences_key_make_for_default_getter (name, eel_preferences_get_user_level ());
-	} else {
-		key = preferences_make_user_level_filtered_key (name);
-	}
-	
-	return key;
-}
-
 gboolean
 eel_preferences_get_boolean (const char *name)
 {
  	gboolean result;
-	char *key;
-	
-	g_return_val_if_fail (name != NULL, FALSE);
-	g_return_val_if_fail (preferences_is_initialized (), FALSE);
+	GConfValue *value;
 
-	key = preferences_key_make_for_getter (name);
-	result = eel_gconf_get_boolean (key);
-	g_free (key);
+	g_return_val_if_fail (name != NULL, 0);
+	g_return_val_if_fail (preferences_is_initialized (), 0);
 
+	value = preferences_get_value (name);
+	result = preferences_gconf_value_get_bool (value);
+	eel_gconf_value_free (value);
+	
 	return result;
 }
 
 void
 eel_preferences_set_integer (const char *name,
-				  int int_value)
+			     int int_value)
 {
 	char *key;
 	int old_value;
@@ -482,21 +454,21 @@
 eel_preferences_get_integer (const char *name)
 {
  	int result;
-	char *key;
+	GConfValue *value;
 
 	g_return_val_if_fail (name != NULL, 0);
 	g_return_val_if_fail (preferences_is_initialized (), 0);
 
-	key = preferences_key_make_for_getter (name);
-	result = eel_gconf_get_integer (key);
-	g_free (key);
+	value = preferences_get_value (name);
+	result = preferences_gconf_value_get_int (value);
+	eel_gconf_value_free (value);
 
 	return result;
 }
 
 void
 eel_preferences_set (const char *name,
-			  const char *string_value)
+		     const char *string_value)
 {
 	char *key;
 	char *old_value;
@@ -519,25 +491,21 @@
 eel_preferences_get (const char *name)
 {
  	char *result;
-	char *key;
-
-	g_return_val_if_fail (name != NULL, NULL);
-	g_return_val_if_fail (preferences_is_initialized (), NULL);
+	GConfValue *value;
 
-	key = preferences_key_make_for_getter (name);
-	result = eel_gconf_get_string (key);
-	g_free (key);
-
-	if (result == NULL) {
-		result = g_strdup ("");
-	}
+	g_return_val_if_fail (name != NULL, 0);
+	g_return_val_if_fail (preferences_is_initialized (), 0);
 
+	value = preferences_get_value (name);
+	result = preferences_gconf_value_get_string (value);
+	eel_gconf_value_free (value);
+	
 	return result;
 }
 
 void
 eel_preferences_set_string_list (const char *name,
-				      const EelStringList *string_list_value)
+				 const EelStringList *string_list_value)
 {
 	char *key;
 	GSList *slist;
@@ -546,7 +514,6 @@
 	g_return_if_fail (preferences_is_initialized ());
 
 	slist = eel_string_list_as_g_slist (string_list_value);
-
 	key = preferences_key_make (name);
 	eel_gconf_set_string_list (key, slist);
 	g_free (key);
@@ -581,21 +548,17 @@
 eel_preferences_get_string_list (const char *name)
 {
  	EelStringList *result;
-	char *key;
-	GSList *slist;
+	GConfValue *value;
 	PreferencesEntry *entry;
-	char *default_key;
-	
-	g_return_val_if_fail (name != NULL, NULL);
-	g_return_val_if_fail (preferences_is_initialized (), NULL);
-	
-	key = preferences_key_make_for_getter (name);
-	slist = eel_gconf_get_string_list (key);
-	g_free (key);
+	const GConfValue *default_value;
 
-	result = eel_string_list_new_from_g_slist (slist, TRUE);
-	eel_g_slist_free_deep (slist);
+	g_return_val_if_fail (name != NULL, 0);
+	g_return_val_if_fail (preferences_is_initialized (), 0);
 
+	value = preferences_get_value (name);
+	result = preferences_gconf_value_get_string_list (value);
+	eel_gconf_value_free (value);
+	
 	entry = preferences_global_table_lookup_or_insert (name);
 	g_assert (entry != NULL);
 
@@ -611,13 +574,9 @@
 
 	/* Forget the bad value and use the default instead */
 	eel_string_list_free (result);
-	default_key = preferences_key_make_for_default_getter (name,
-							       eel_preferences_get_user_level ());
-	slist = eel_gconf_get_string_list (default_key);
-	g_free (default_key);
-	
-	result = eel_string_list_new_from_g_slist (slist, TRUE);
-	eel_g_slist_free_deep (slist);
+
+	default_value = preferences_find_first_non_null_default_value (name, eel_preferences_get_user_level ());
+	result = preferences_gconf_value_get_string_list (default_value);
 	
  	/* Go the extra mile and fix the problem for the user */
 	preferences_block_callbacks (name);
@@ -666,139 +625,151 @@
 
 void
 eel_preferences_default_set_integer (const char *name,
-					  int user_level,
-					  int int_value)
+				     int user_level,
+				     int int_value)
 {
-	char *default_key;
+	PreferencesEntry *entry;
 
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (preferences_is_initialized ());
-	
-	default_key = preferences_key_make_for_default (name, user_level);
-	eel_gconf_set_integer (default_key, int_value);
-	g_free (default_key);
+	g_return_if_fail (eel_preferences_user_level_is_valid (user_level));
+
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
+
+	if (entry->default_values[user_level] == NULL) {
+		entry->default_values[user_level] = gconf_value_new (GCONF_VALUE_INT);
+	}
+	gconf_value_set_int (entry->default_values[user_level], int_value);
 }
 
 int
 eel_preferences_default_get_integer (const char *name,
-					  int user_level)
+				     int user_level)
 {
- 	int result;
-	char *default_key;
+	PreferencesEntry *entry;
 
 	g_return_val_if_fail (name != NULL, 0);
 	g_return_val_if_fail (preferences_is_initialized (), 0);
+	g_return_val_if_fail (eel_preferences_user_level_is_valid (user_level), 0);
 	
-	default_key = preferences_key_make_for_default (name, user_level);
-	result = eel_gconf_get_integer (default_key);
-	g_free (default_key);
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
 
-	return result;
+	return preferences_gconf_value_get_int (entry->default_values[user_level]);
 }
 
 void
 eel_preferences_default_set_boolean (const char *name,
-					  int user_level,
-					  gboolean boolean_value)
+				     int user_level,
+				     gboolean boolean_value)
 {
-	char *default_key;
-	
+	PreferencesEntry *entry;
+
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (preferences_is_initialized ());
-	
-	default_key = preferences_key_make_for_default (name, user_level);
-	eel_gconf_set_boolean (default_key, boolean_value);
-	g_free (default_key);
+	g_return_if_fail (eel_preferences_user_level_is_valid (user_level));
+
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
+
+	if (entry->default_values[user_level] == NULL) {
+		entry->default_values[user_level] = gconf_value_new (GCONF_VALUE_BOOL);
+	}
+	gconf_value_set_bool (entry->default_values[user_level], boolean_value);
 }
 
 gboolean
 eel_preferences_default_get_boolean (const char *name,
-					  int user_level)
+				     int user_level)
 {
- 	gboolean result;
-	char *default_key;
+	PreferencesEntry *entry;
 
 	g_return_val_if_fail (name != NULL, FALSE);
 	g_return_val_if_fail (preferences_is_initialized (), FALSE);
+	g_return_val_if_fail (eel_preferences_user_level_is_valid (user_level), FALSE);
 	
-	default_key = preferences_key_make_for_default (name, user_level);
-	result = eel_gconf_get_boolean (default_key);
-	g_free (default_key);
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
 
-	return result;
+	return preferences_gconf_value_get_bool (entry->default_values[user_level]);
 }
 
 void
 eel_preferences_default_set_string (const char *name,
-					 int user_level,
-					 const char *string_value)
+				    int user_level,
+				    const char *string_value)
 {
-	char *default_key;
-	
+	PreferencesEntry *entry;
+
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (preferences_is_initialized ());
-	
-	default_key = preferences_key_make_for_default (name, user_level);
-	eel_gconf_set_string (default_key, string_value);
-	g_free (default_key);
+	g_return_if_fail (eel_preferences_user_level_is_valid (user_level));
+
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
+
+	if (entry->default_values[user_level] == NULL) {
+		entry->default_values[user_level] = gconf_value_new (GCONF_VALUE_STRING);
+	}
+	gconf_value_set_string (entry->default_values[user_level], string_value);
 }
 
 char *
 eel_preferences_default_get_string (const char *name,
-					 int user_level)
+				    int user_level)
 {
- 	char *result;
-	char *default_key;
+	PreferencesEntry *entry;
 
-	g_return_val_if_fail (name != NULL, NULL);
-	g_return_val_if_fail (preferences_is_initialized (), NULL);
+	g_return_val_if_fail (name != NULL, FALSE);
+	g_return_val_if_fail (preferences_is_initialized (), FALSE);
+	g_return_val_if_fail (eel_preferences_user_level_is_valid (user_level), FALSE);
 	
-	default_key = preferences_key_make_for_default (name, user_level);
-	result = eel_gconf_get_string (default_key);
-	g_free (default_key);
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
 
-	return result;
+	return preferences_gconf_value_get_string (entry->default_values[user_level]);
 }
 
 void
 eel_preferences_default_set_string_list (const char *name,
-					      int user_level,
-					      const EelStringList *string_list_value)
+					 int user_level,
+					 const EelStringList *string_list_value)
 {
-	char *default_key;
+	PreferencesEntry *entry;
 	GSList *slist;
-	
+
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (preferences_is_initialized ());
+	g_return_if_fail (eel_preferences_user_level_is_valid (user_level));
 
-	slist = eel_string_list_as_g_slist (string_list_value);
-	
-	default_key = preferences_key_make_for_default (name, user_level);
-	eel_gconf_set_string_list (default_key, slist);
-	g_free (default_key);
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
 
+	if (entry->default_values[user_level] == NULL) {
+		entry->default_values[user_level] = gconf_value_new (GCONF_VALUE_LIST);
+		gconf_value_set_list_type (entry->default_values[user_level], GCONF_VALUE_STRING);
+	}
+	
+	slist = eel_string_list_as_g_slist (string_list_value);
+	eel_gconf_value_set_string_list (entry->default_values[user_level], slist);
 	eel_g_slist_free_deep (slist);
 }
 
 EelStringList *
 eel_preferences_default_get_string_list (const char *name,
-					      int user_level)
+					 int user_level)
 {
- 	EelStringList *result;
-	char *default_key;
-	GSList *slist;
-	
-	g_return_val_if_fail (name != NULL, NULL);
-	g_return_val_if_fail (preferences_is_initialized (), NULL);
-	
-	default_key = preferences_key_make_for_default (name, user_level);
-	slist = eel_gconf_get_string_list (default_key);
-	g_free (default_key);
+	PreferencesEntry *entry;
 
-	result = eel_string_list_new_from_g_slist (slist, TRUE);
-	eel_g_slist_free_deep (slist);
+	g_return_val_if_fail (name != NULL, FALSE);
+	g_return_val_if_fail (preferences_is_initialized (), FALSE);
+	g_return_val_if_fail (eel_preferences_user_level_is_valid (user_level), FALSE);
+	
+	entry = preferences_global_table_lookup_or_insert (name);
+	g_assert (entry != NULL);
 
-	return result;
+	return preferences_gconf_value_get_string_list (entry->default_values[user_level]);
 }
 
 /**
@@ -841,13 +812,10 @@
 preferences_entry_invoke_callbacks_if_needed (PreferencesEntry *entry)
 {
 	GConfValue *new_value;
-	char *getter_key;
 	
 	g_return_if_fail (entry != NULL);
 
-	getter_key = preferences_key_make_for_getter (entry->name);
-	new_value = eel_gconf_get_value (getter_key);
-	g_free (getter_key);
+	new_value = preferences_get_value (entry->name);
 
 	/* If the values are the same, then we dont need to invoke any callbacks */
 	if (eel_gconf_value_is_equal (entry->cached_value, new_value)) {
@@ -995,15 +963,11 @@
 static void
 preferences_entry_update_cached_value (PreferencesEntry *entry)
 {
-	char *getter_key;
-
 	g_return_if_fail (entry != NULL);
 
 	eel_gconf_value_free (entry->cached_value);
 
-	getter_key = preferences_key_make_for_getter (entry->name);
-	entry->cached_value = eel_gconf_get_value (getter_key);
-	g_free (getter_key);
+	entry->cached_value = preferences_get_value (entry->name);
 }
 
 static void
@@ -1040,8 +1004,8 @@
 	key = preferences_key_make (entry->name);
 
 	entry->gconf_connection_id = eel_gconf_notification_add (key,
-								      preferences_something_changed_notice,
-								      entry);
+								 preferences_something_changed_notice,
+								 entry);
 	g_free (key);
 
 	g_return_if_fail (entry->gconf_connection_id != EEL_GCONF_UNDEFINED_CONNECTION);
@@ -1283,6 +1247,9 @@
 	g_free (entry->enumeration_id);
 
 	eel_gconf_value_free (entry->cached_value);
+	eel_gconf_value_free (entry->default_values[0]);
+	eel_gconf_value_free (entry->default_values[1]);
+	eel_gconf_value_free (entry->default_values[2]);
 
 	g_free (entry);
 }
@@ -1319,10 +1286,6 @@
 
 	g_free (storage_path);
 	storage_path = NULL;
-	g_free (defaults_path);
-	defaults_path = NULL;
-	g_free (visiblity_path);
-	visiblity_path = NULL;
 }
 
 static GHashTable *
@@ -1403,8 +1366,8 @@
 
 void
 eel_preferences_add_callback (const char *name,
-				   EelPreferencesCallback callback,
-				   gpointer callback_data)
+			      EelPreferencesCallback callback,
+			      gpointer callback_data)
 {
 	PreferencesEntry *entry;
 
@@ -1420,7 +1383,7 @@
 
 void
 eel_preferences_add_auto_string (const char *name,
-				      const char **storage)
+				 const char **storage)
 {
 	PreferencesEntry *entry;
 	char *value;
@@ -1441,7 +1404,7 @@
 
 void
 eel_preferences_add_auto_string_list (const char *name,
-					   const EelStringList **storage)
+				      const EelStringList **storage)
 {
 	PreferencesEntry *entry;
 	EelStringList *value;
@@ -1462,7 +1425,7 @@
 
 void
 eel_preferences_add_auto_integer (const char *name,
-				       int *storage)
+				  int *storage)
 {
 	PreferencesEntry *entry;
 	int value;
@@ -1482,7 +1445,7 @@
 
 void
 eel_preferences_add_auto_boolean (const char *name,
-				       gboolean *storage)
+				  gboolean *storage)
 {
 	PreferencesEntry *entry;
 	gboolean value;
@@ -1502,7 +1465,7 @@
 
 void
 eel_preferences_remove_auto_string (const char *name,
-				         const char **storage)
+				    const char **storage)
 {
 	PreferencesEntry *entry;
 
@@ -1521,7 +1484,7 @@
 
 void
 eel_preferences_remove_auto_string_list (const char *name,
-					      const EelStringList **storage)
+					 const EelStringList **storage)
 {
 	PreferencesEntry *entry;
 
@@ -1540,7 +1503,7 @@
 
 void
 eel_preferences_remove_auto_integer (const char *name,
-				          int *storage)
+				     int *storage)
 {
 	PreferencesEntry *entry;
 
@@ -1559,7 +1522,7 @@
 
 void
 eel_preferences_remove_auto_boolean (const char *name,
-				          gboolean *storage)
+				     gboolean *storage)
 {
 	PreferencesEntry *entry;
 
@@ -1594,8 +1557,8 @@
 	data = callback_data;
 
 	eel_preferences_remove_callback (data->name,
-					      data->callback,
-					      data->callback_data);
+					 data->callback,
+					 data->callback_data);
 
 	g_free (data->name);
 	g_free (data);
@@ -1603,9 +1566,9 @@
 
 void
 eel_preferences_add_callback_while_alive (const char *name,
-					       EelPreferencesCallback callback,
-					       gpointer callback_data,
-					       GtkObject *alive_object)
+					  EelPreferencesCallback callback,
+					  gpointer callback_data,
+					  GtkObject *alive_object)
 {
 	WhileAliveData *data;
 
@@ -1629,8 +1592,8 @@
 
 void
 eel_preferences_remove_callback (const char *name,
-				      EelPreferencesCallback callback,
-				      gpointer callback_data)
+				 EelPreferencesCallback callback,
+				 gpointer callback_data)
 {
 	PreferencesEntry *entry;
 
@@ -1650,7 +1613,7 @@
 
 void
 eel_preferences_set_description (const char *name,
-				      const char *description)
+				 const char *description)
 {
 	PreferencesEntry *entry;
 
@@ -1680,7 +1643,7 @@
 
 void
 eel_preferences_set_enumeration_id (const char *name,
-					 const char *enumeration_id)
+				    const char *enumeration_id)
 {
 	PreferencesEntry *entry;
 
@@ -1753,16 +1716,11 @@
 gboolean
 eel_preferences_visible_in_current_user_level (const char *name)
 {
-	int user_level;
-	int visible_user_level;
-
 	g_return_val_if_fail (name != NULL, FALSE);
 	g_return_val_if_fail (preferences_is_initialized (), FALSE);
-
-	user_level = eel_preferences_get_user_level ();
-	visible_user_level = eel_preferences_get_visible_user_level (name);
 
-	return visible_user_level <= user_level;
+	return eel_preferences_get_visible_user_level (name)
+		<= eel_preferences_get_user_level ();
 }
 
 gboolean
@@ -1797,8 +1755,8 @@
 	initialized = TRUE;
 
 	user_level_changed_connection_id = eel_gconf_notification_add (USER_LEVEL_KEY,
-									    preferences_user_level_changed_notice,
-									    NULL);
+								       preferences_user_level_changed_notice,
+								       NULL);
 
 	g_atexit (preferences_remove_user_level_notice);
 


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