diff options
author | Ramiro Estrugo <ramiro@src.gnome.org> | 2000-04-05 15:13:44 +0000 |
---|---|---|
committer | Ramiro Estrugo <ramiro@src.gnome.org> | 2000-04-05 15:13:44 +0000 |
commit | ee95ca88c438bc23222643c3b1ee40a3365a6fb2 (patch) | |
tree | 93eeb6f20d989a843f2d4b0440cc0a033f1b172b | |
parent | c34c6f30cf1887408c9d721840217a2e846a7c13 (diff) | |
download | nautilus-ee95ca88c438bc23222643c3b1ee40a3365a6fb2.tar.gz |
Preferences work. Make preference registration implicit. Update code that
required preferences to be explicitly registered before using them.
24 files changed, 1458 insertions, 1035 deletions
diff --git a/ChangeLog-20000414 b/ChangeLog-20000414 index 48dbc98a9..46e17c34f 100644 --- a/ChangeLog-20000414 +++ b/ChangeLog-20000414 @@ -1,3 +1,93 @@ +2000-04-05 Ramiro Estrugo <ramiro@eazel.com> + + Preferences work. Make preference registration implicit. + + * nautilus-widgets/nautilus-preferences.c, + nautilus-widgets/nautilus-preferences.h: + (prefs_hash_lookup_with_implicit_registration): New function to do + preference lookup with implicit registration. If the pref is not + found at first, it will be automatically added. + + (preference_get): Replace the old badly named prefs_get_pref with + something simpler. + + (preference_set): Same here. + + (nautilus_preferences_set_info): Add a function that allows + tweaking the default values and other info for a pref. + + (nautilus_preferences_add_enum_callback): + (nautilus_preferences_add_boolean_callback): + (nautilus_preferences_add_string_callback): New callback adding + functions that work with implicit registration. The caller needs + to know the type of preference they want to munge beforehand for + the implicit registration to work. + + Also cleanup a bunch bucnhsome of style issues. + + * nautilus-widgets/test-nautilus-widgets.c: + Update for all the pref changes. + + * libnautilus/nautilus-global-preferences.c, + libnautilus/nautilus-global-preferences.h: + (global_preferences_register_for_ui): Add a new private function + to register only preferences used in the pref dialog ui. + + (global_preferences_static_info): Remove + NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES and + NAUTILUS_PREFERENCES_ICON_THEME since they dont have a ui and can + be used implicitly. + + (nautilus_global_preferences_initialize): Removed. + + * libnautilus/nautilus-icon-factory.c: + (icon_theme_changed_callback): Doesnt take a type paramater no + more. + + (nautilus_get_current_icon_factory): Remove the global preferences + initialization code and blurb. Not needed since prefs are + registered implicitly as needed. Use + nautilus_preferences_add_string_callback instead of obsolete + nautilus_preferences_add_callback. + + (nautilus_icon_factory_initialize_class): Add a preferences call + to set the default value for the ICON_THEME string. + We might want to change things such that no default has to be installed + for this preference. If so, then the code that fetches the preference + would have to deal with either a NULL return value (or ""). + + * src/ntl-app.c: + (nautilus_app_startup): Remove global preferences initialization + call. + + * src/file-manager/fm-directory-view.c: + (user_level_changed_callback): + (use_new_window_changed_callback): Callbacks dont take a + preference type argument no more. + + (fm_directory_view_initialize): Use + nautilus_preferences_add_{enum,boolean}_callback instead of obsolete + nautilus_preferences_add_callback. + + * src/file-manager/fm-icon-text-window.c: + (preference_changed_callback): Doesnt take a type paramater no + more. + + (create_icon_text_window): Use + nautilus_preferences_add_string_callback instead of obsolete + nautilus_preferences_add_callback. + + * src/file-manager/fm-icon-view.c: + (text_attribute_names_changed_callback): Doesnt take a type paramater no + more. + + (fm_icon_view_initialize_class): Add a preferences call + to set the default value for the ICON_VIEW_TEXT_ATTRIBUTE_NAMES string. + We might want to change things such that no default has to be installed + for this preference. If so, then the code that fetches the preference + would have to deal with either a NULL return value (or ""). + + 2000-04-05 Andy Hertzfeld <andy@eazel.com> * components/services/startup/nautilus-service-startup-view.c: diff --git a/libnautilus-extensions/nautilus-global-preferences.c b/libnautilus-extensions/nautilus-global-preferences.c index 65ce157d8..7aa66c6d6 100644 --- a/libnautilus-extensions/nautilus-global-preferences.c +++ b/libnautilus-extensions/nautilus-global-preferences.c @@ -45,6 +45,7 @@ static GtkWidget *global_preferences_create_check_group (GtkWidget *pa const char * const pref_names[], guint num_prefs); static GtkWidget *global_preferences_get_dialog (void); +static void global_preferences_register_for_ui (void); static void global_preferences_register_static (NautilusPreferences *prefs); static void global_preferences_register_dynamic (NautilusPreferences *prefs); @@ -116,20 +117,6 @@ static const NautilusPreferencesInfo global_preferences_static_info[] = FALSE, NULL }, - { - NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, - "", /* No caption since not currently displayed in preferences dialog */ - NAUTILUS_PREFERENCE_STRING, - "name|size|date_modified|type", - NULL - }, - { - NAUTILUS_PREFERENCES_ICON_THEME, - "", /* No caption since not currently displayed in preferences dialog */ - NAUTILUS_PREFERENCE_STRING, - "default", - NULL - } }; /* @@ -142,6 +129,8 @@ global_preferences_create_dialog (void) GtkWidget *prefs_dialog; NautilusPreferencesBox *prefs_box; + global_preferences_register_for_ui (); + prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE); prefs_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog))); @@ -241,9 +230,13 @@ global_preferences_register_static (NautilusPreferences *prefs) g_assert (prefs != NULL); /* Register the static prefs */ - for (i = 0; i < NAUTILUS_N_ELEMENTS (global_preferences_static_info); i++) - { - nautilus_preferences_register_from_info (prefs, &global_preferences_static_info[i]); + for (i = 0; i < NAUTILUS_N_ELEMENTS (global_preferences_static_info); i++) { + nautilus_preferences_set_info (prefs, + global_preferences_static_info[i].name, + global_preferences_static_info[i].description, + global_preferences_static_info[i].type, + global_preferences_static_info[i].default_value, + global_preferences_static_info[i].data); } } @@ -280,47 +273,47 @@ global_preferences_register_dynamic (NautilusPreferences *prefs) { g_assert (prefs != NULL); - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HISTORY, - "History View", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HISTORY, + "History View", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_WEB_SEARCH, - "Web Search View", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_ANNOTATIONS, - "Annotations", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_CONTENTS, - "Help Contents", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_INDEX, - "Help Index", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) FALSE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_SEARCH, - "Help Search", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) FALSE, - NULL); + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_WEB_SEARCH, + "Web Search View", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_ANNOTATIONS, + "Annotations", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_CONTENTS, + "Help Contents", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_INDEX, + "Help Index", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) FALSE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_SEARCH, + "Help Search", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) FALSE, + NULL); } static GtkWidget * @@ -345,6 +338,20 @@ global_preferences_get_dialog (void) return global_prefs_dialog; } +static void +global_preferences_register_for_ui (void) +{ + static gboolean initialized = FALSE; + + if (!initialized) + { + initialized = TRUE; + + global_preferences_register_static (nautilus_preferences_get_global_preferences ()); + global_preferences_register_dynamic (nautilus_preferences_get_global_preferences ()); + } +} + /* * Public functions */ @@ -373,16 +380,3 @@ nautilus_global_preferences_shutdown (void) gtk_object_unref (global_prefs); } -void -nautilus_global_preferences_initialize (void) -{ - static gboolean initialized = FALSE; - - if (!initialized) - { - initialized = TRUE; - - global_preferences_register_static (nautilus_preferences_get_global_preferences ()); - global_preferences_register_dynamic (nautilus_preferences_get_global_preferences ()); - } -} diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h index accb6879a..72855b7d6 100644 --- a/libnautilus-extensions/nautilus-global-preferences.h +++ b/libnautilus-extensions/nautilus-global-preferences.h @@ -58,7 +58,6 @@ enum }; void nautilus_global_preferences_shutdown (void); -void nautilus_global_preferences_initialize (void); void nautilus_global_preferences_show_dialog (void); const NautilusStringList *nautilus_global_preferences_get_meta_view_iids (void); diff --git a/libnautilus-extensions/nautilus-icon-factory.c b/libnautilus-extensions/nautilus-icon-factory.c index 9b66c7ecc..8d942c9f5 100644 --- a/libnautilus-extensions/nautilus-icon-factory.c +++ b/libnautilus-extensions/nautilus-icon-factory.c @@ -180,7 +180,6 @@ typedef struct { static void icon_theme_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); static GtkType nautilus_icon_factory_get_type (void); @@ -219,22 +218,20 @@ nautilus_get_current_icon_factory (void) if (global_icon_factory == NULL) { char *theme_preference; - /* No guarantee that nautilus preferences have been set - * up properly, so we have to initialize them all here just - * to be sure that the icon_theme preference will work. - */ - nautilus_global_preferences_initialize (); theme_preference = nautilus_preferences_get_string (nautilus_preferences_get_global_preferences (), NAUTILUS_PREFERENCES_ICON_THEME); + + g_assert (theme_preference != NULL); + global_icon_factory = nautilus_icon_factory_new (theme_preference); g_free (theme_preference); - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_ICON_THEME, - icon_theme_changed_callback, - NULL); - + nautilus_preferences_add_string_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_THEME, + icon_theme_changed_callback, + NULL); + } return global_icon_factory; } @@ -287,6 +284,19 @@ nautilus_icon_factory_initialize_class (NautilusIconFactoryClass *class) GTK_TYPE_NONE, 0); gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + + /* Set the default icon theme. + * + * We might want to change things such that no default has to be installed + * for this preference. If so, then the code that fetches the preference + * would have to deal with either a NULL return value (or ""). + */ + nautilus_preferences_set_info (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_THEME, + NULL, + NAUTILUS_PREFERENCE_STRING, + "default", + NULL); } /* Destroy one image in the cache. */ @@ -599,13 +609,11 @@ get_icon_file_path (const char *name, guint size_in_pixels, ArtIRect *text_rect) static void icon_theme_changed_callback (NautilusPreferences *preferences, const char *name, - GtkFundamentalType type, gconstpointer value, gpointer user_data) { g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_ICON_THEME) == 0); - g_assert (type == NAUTILUS_PREFERENCE_STRING); g_assert (value != NULL); g_assert (user_data == NULL); diff --git a/libnautilus-extensions/nautilus-preferences.c b/libnautilus-extensions/nautilus-preferences.c index b125e7fa9..7729ecf22 100644 --- a/libnautilus-extensions/nautilus-preferences.c +++ b/libnautilus-extensions/nautilus-preferences.c @@ -63,50 +63,65 @@ typedef struct { */ struct NautilusPreferencesDetails { char *domain; - GHashTable *prefs_hash_table; + GHashTable *preference_hash_table; }; /* NautilusPreferencesClass methods */ -static void nautilus_preferences_initialize_class (NautilusPreferencesClass *klass); -static void nautilus_preferences_initialize (NautilusPreferences *prefs); +static void nautilus_preferences_initialize_class (NautilusPreferencesClass *klass); +static void nautilus_preferences_initialize (NautilusPreferences *preferences); /* GtkObjectClass methods */ -static void nautilus_preferences_destroy (GtkObject *object); +static void nautilus_preferences_destroy (GtkObject *object); /* PrefHashNode functions */ -static PrefHashNode * pref_hash_node_alloc (const NautilusPreferencesInfo *info); -static void pref_hash_node_free (PrefHashNode *pref_hash_node); -static void pref_hash_node_free_func (gpointer key, - gpointer value, - gpointer user_data); +static PrefHashNode * pref_hash_node_alloc (char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); +static void pref_hash_node_free (PrefHashNode *pref_hash_node); +static void pref_hash_node_free_func (gpointer key, + gpointer value, + gpointer user_data); /* PrefCallbackInfo functions */ -static PrefCallbackInfo *pref_callback_info_alloc (NautilusPreferencesCallback callback_proc, - gpointer user_data, - const PrefHashNode *hash_node); -static void pref_callback_info_free (PrefCallbackInfo *pref_hash_node); -static void pref_callback_info_free_func (gpointer data, - gpointer user_data); -static void pref_callback_info_invoke_func (gpointer data, - gpointer user_data); -static void pref_hash_node_add_callback (PrefHashNode *pref_hash_node, - NautilusPreferencesCallback callback_proc, - gpointer user_data); -static void pref_hash_node_remove_callback (PrefHashNode *pref_hash_node, - NautilusPreferencesCallback callback_proc, - gpointer user_data); - +static PrefCallbackInfo *pref_callback_info_alloc (NautilusPreferencesCallback callback_proc, + gpointer user_data, + const PrefHashNode *hash_node); +static void pref_callback_info_free (PrefCallbackInfo *pref_hash_node); +static void pref_callback_info_free_func (gpointer data, + gpointer user_data); +static void pref_callback_info_invoke_func (gpointer data, + gpointer user_data); +static void pref_hash_node_add_callback (PrefHashNode *pref_hash_node, + NautilusPreferencesCallback callback_proc, + gpointer user_data); +static void pref_hash_node_remove_callback (PrefHashNode *pref_hash_node, + NautilusPreferencesCallback callback_proc, + gpointer user_data); /* Private stuff */ -static void prefs_set_pref (NautilusPreferences *prefs, - const char *name, - gconstpointer value); -static gboolean prefs_get_pref (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesType *type_out, - gconstpointer *value_out); -PrefHashNode * prefs_hash_lookup (NautilusPreferences *prefs, - const char *name); -static char * make_gnome_config_string (const NautilusPreferencesInfo *info); +static void preference_set (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer value); +static void preference_get (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer *value_out); +PrefHashNode * prefs_hash_lookup (NautilusPreferences *preferences, + const char *name); +PrefHashNode * prefs_hash_lookup_with_implicit_registration (NautilusPreferences *preferences, + const char *pref_name, + NautilusPreferencesType pref_type); +static char * gnome_config_make_string (char *name, + NautilusPreferencesType type, + gconstpointer default_value); +static void preferences_register (NautilusPreferences *preferences, + char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferences, nautilus_preferences, GTK_TYPE_OBJECT) @@ -138,14 +153,14 @@ nautilus_preferences_initialize_class (NautilusPreferencesClass *preferences_cla * **/ static void -nautilus_preferences_initialize (NautilusPreferences *prefs) +nautilus_preferences_initialize (NautilusPreferences *preferences) { - prefs->details = g_new (NautilusPreferencesDetails, 1); + preferences->details = g_new (NautilusPreferencesDetails, 1); - prefs->details->domain = NULL; + preferences->details->domain = NULL; - prefs->details->prefs_hash_table = g_hash_table_new (g_str_hash, - g_str_equal); + preferences->details->preference_hash_table = g_hash_table_new (g_str_hash, + g_str_equal); } /** @@ -158,23 +173,23 @@ nautilus_preferences_initialize (NautilusPreferences *prefs) static void nautilus_preferences_destroy (GtkObject *object) { - NautilusPreferences * prefs; + NautilusPreferences *preferences; - prefs = NAUTILUS_PREFERENCES (object); - - g_free (prefs->details->domain); + preferences = NAUTILUS_PREFERENCES (object); - if (prefs->details->prefs_hash_table != NULL) { - g_hash_table_foreach (prefs->details->prefs_hash_table, + g_free (preferences->details->domain); + + if (preferences->details->preference_hash_table != NULL) { + g_hash_table_foreach (preferences->details->preference_hash_table, pref_hash_node_free_func, NULL); - g_hash_table_destroy (prefs->details->prefs_hash_table); - - prefs->details->prefs_hash_table = NULL; + g_hash_table_destroy (preferences->details->preference_hash_table); + + preferences->details->preference_hash_table = NULL; } - - g_free (prefs->details); + + g_free (preferences->details); /* Chain */ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); @@ -189,24 +204,25 @@ nautilus_preferences_destroy (GtkObject *object) * Return value: A newly allocated node. **/ static PrefHashNode * -pref_hash_node_alloc (const NautilusPreferencesInfo *info) +pref_hash_node_alloc (char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { PrefHashNode * pref_hash_node; - g_assert (info != NULL); - - g_assert (info->name != NULL); - g_assert (info->description != NULL); + g_assert (name != NULL); pref_hash_node = g_new (PrefHashNode, 1); - pref_hash_node->info.name = g_strdup (info->name); - pref_hash_node->info.description = g_strdup (info->description); - pref_hash_node->info.type = info->type; - pref_hash_node->info.default_value = info->default_value; - pref_hash_node->info.data = info->data; + pref_hash_node->info.name = g_strdup (name); + pref_hash_node->info.description = description ? g_strdup (description) : NULL; + pref_hash_node->info.type = type; + pref_hash_node->info.default_value = default_value; + pref_hash_node->info.data = data; - pref_hash_node->value = (gpointer) info->default_value; + pref_hash_node->value = (gpointer) default_value; pref_hash_node->callback_list = NULL; return pref_hash_node; @@ -231,7 +247,9 @@ pref_hash_node_free (PrefHashNode *pref_hash_node) NULL); g_free (pref_hash_node->info.name); - g_free (pref_hash_node->info.description); + + if (pref_hash_node->info.description) + g_free (pref_hash_node->info.description); pref_hash_node->info.name = NULL; pref_hash_node->info.type = GTK_TYPE_INVALID; @@ -270,9 +288,8 @@ pref_hash_node_add_callback (PrefHashNode *pref_hash_node, g_assert (pref_callback_info != NULL); - pref_hash_node->callback_list = - g_list_append (pref_hash_node->callback_list, - (gpointer) pref_callback_info); + pref_hash_node->callback_list = g_list_append (pref_hash_node->callback_list, + (gpointer) pref_callback_info); } /** @@ -420,7 +437,7 @@ static void pref_callback_info_invoke_func (gpointer data, gpointer user_data) { - NautilusPreferences *prefs; + NautilusPreferences *preferences; PrefCallbackInfo *pref_callback_info; pref_callback_info = (PrefCallbackInfo *) data; @@ -429,30 +446,28 @@ pref_callback_info_invoke_func (gpointer data, g_assert (pref_callback_info->callback_proc != NULL); - prefs = (NautilusPreferences *) user_data; + preferences = (NautilusPreferences *) user_data; - (* pref_callback_info->callback_proc) (prefs, + (* pref_callback_info->callback_proc) (preferences, pref_callback_info->hash_node->info.name, - pref_callback_info->hash_node->info.type, pref_callback_info->hash_node->value, pref_callback_info->user_data); } static void -prefs_set_pref (NautilusPreferences *prefs, - const char *name, - gconstpointer value) +preference_set (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer value) { PrefHashNode * pref_hash_node; - g_assert (NAUTILUS_IS_PREFERENCES (prefs)); + g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (name != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); - if (!pref_hash_node) { - g_warning ("tried to set an unregistered preference '%s'", name); - return; - } + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); + + g_assert (pref_hash_node != NULL); /* gnome-config for now ; in the future gconf */ switch (pref_hash_node->info.type) { @@ -468,45 +483,41 @@ prefs_set_pref (NautilusPreferences *prefs, break; case NAUTILUS_PREFERENCE_STRING: + if (pref_hash_node->value) + g_free (pref_hash_node->value); pref_hash_node->value = g_strdup (value); gnome_config_set_string (name, pref_hash_node->value); break; - - } /* Sync all the damn time. Yes it sucks. it will be better with gconf */ gnome_config_sync (); + /* Invoke callbacks for this node */ if (pref_hash_node->callback_list) { g_list_foreach (pref_hash_node->callback_list, pref_callback_info_invoke_func, - (gpointer) prefs); + (gpointer) preferences); } } -static gboolean -prefs_get_pref (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesType *type_out, - gconstpointer *value_out) +static void +preference_get (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer *value_out) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (type_out != NULL, FALSE); - g_return_val_if_fail (value_out != NULL, FALSE); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); + g_return_if_fail (name != NULL); + g_return_if_fail (value_out != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); - if (pref_hash_node == NULL) { - return FALSE; - } + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); - *type_out = pref_hash_node->info.type; - *value_out = pref_hash_node->value; + g_assert (pref_hash_node != NULL); - return TRUE; + *value_out = pref_hash_node->value; } /* @@ -515,48 +526,50 @@ prefs_get_pref (NautilusPreferences *prefs, GtkObject * nautilus_preferences_new (const char *domain) { - NautilusPreferences *prefs; + NautilusPreferences *preferences; g_return_val_if_fail (domain != NULL, NULL); - prefs = gtk_type_new (nautilus_preferences_get_type ()); + preferences = gtk_type_new (nautilus_preferences_get_type ()); - return GTK_OBJECT (prefs); + return GTK_OBJECT (preferences); } -void -nautilus_preferences_register_from_info (NautilusPreferences *prefs, - const NautilusPreferencesInfo *info) +static void +preferences_register (NautilusPreferences *preferences, + char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { char *gnome_config_string; PrefHashNode *pref_hash_node; - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); - g_return_if_fail (info != NULL); - - g_return_if_fail (info->name != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (description != NULL); - pref_hash_node = prefs_hash_lookup (prefs, info->name); + pref_hash_node = prefs_hash_lookup (preferences, name); if (pref_hash_node) { - g_warning ("the '%s' preference is already registered", info->name); + g_warning ("the '%s' preference is already registered", name); return; } - pref_hash_node = pref_hash_node_alloc (info); + pref_hash_node = pref_hash_node_alloc (name, description, type, default_value, data); - g_hash_table_insert (prefs->details->prefs_hash_table, - (gpointer) info->name, + g_hash_table_insert (preferences->details->preference_hash_table, + (gpointer) name, (gpointer) pref_hash_node); - gnome_config_string = make_gnome_config_string (info); + gnome_config_string = gnome_config_make_string (name, type, default_value); g_assert (gnome_config_string != NULL); /* gnome-config for now; in the future gconf */ switch (pref_hash_node->info.type) { - case NAUTILUS_PREFERENCE_BOOLEAN: pref_hash_node->value = GINT_TO_POINTER (gnome_config_get_bool (gnome_config_string)); break; @@ -577,7 +590,7 @@ nautilus_preferences_register_from_info (NautilusPreferences *prefs, } /** - * make_gnome_config_string + * gnome_config_make_string * * Make a gnome_config conformant string out of NautilusPreferencesInfo. The 'path' * for the config string is the same for both gnome_config and nautilus preferences. @@ -590,21 +603,22 @@ nautilus_preferences_register_from_info (NautilusPreferences *prefs, * Return value: A newly allocated string with the gnome_config conformant string. **/ static char * -make_gnome_config_string (const NautilusPreferencesInfo *info) +gnome_config_make_string (char *name, + NautilusPreferencesType type, + gconstpointer default_value) { char * rv = NULL; GString * tmp = NULL; - g_assert (info != NULL); + g_assert (name != NULL); - tmp = g_string_new (info->name); + tmp = g_string_new (name); - g_string_append (tmp, "="); - - switch (info->type) { - + switch (type) { case NAUTILUS_PREFERENCE_BOOLEAN: - if (GPOINTER_TO_INT (info->default_value)) { + g_string_append (tmp, "="); + + if (GPOINTER_TO_INT (default_value)) { g_string_append (tmp, "true"); } else { g_string_append (tmp, "false"); @@ -612,11 +626,17 @@ make_gnome_config_string (const NautilusPreferencesInfo *info) break; case NAUTILUS_PREFERENCE_ENUM: - g_string_sprintfa (tmp, "%d", GPOINTER_TO_INT (info->default_value)); + g_string_append (tmp, "="); + + g_string_sprintfa (tmp, "%d", GPOINTER_TO_INT (default_value)); break; case NAUTILUS_PREFERENCE_STRING: - g_string_append (tmp, info->default_value); + if (default_value != NULL) + { + g_string_append (tmp, "="); + g_string_append (tmp, (char *) default_value); + } break; } @@ -630,74 +650,164 @@ make_gnome_config_string (const NautilusPreferencesInfo *info) return rv; } -void -nautilus_preferences_register_from_values (NautilusPreferences *prefs, - char *name, - char *description, - NautilusPreferencesType type, - gconstpointer default_value, - gpointer data) +const NautilusPreferencesInfo * +nautilus_preferences_get_info (NautilusPreferences *preferences, + const char *name) { - NautilusPreferencesInfo info; - - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + PrefHashNode * pref_hash_node; - g_return_if_fail (name != NULL); - g_return_if_fail (description != NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), NULL); + g_return_val_if_fail (name != NULL, NULL); - info.name = name; - info.description = description; - info.type = type; - info.default_value = default_value; - info.data = data; + pref_hash_node = prefs_hash_lookup (preferences, name); + + g_assert (pref_hash_node != NULL); - nautilus_preferences_register_from_info (prefs, &info); + return &pref_hash_node->info; } -const NautilusPreferencesInfo * -nautilus_preferences_get_info (NautilusPreferences *prefs, - const char *name) +void +nautilus_preferences_set_info (NautilusPreferences *preferences, + const char *name, + const char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { - PrefHashNode * pref_hash_node; + PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), NULL); - g_return_val_if_fail (name != NULL, NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); + g_return_if_fail (name != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); g_assert (pref_hash_node != NULL); - return &pref_hash_node->info; + pref_hash_node->info.default_value = default_value; + + if (pref_hash_node->info.description) + g_free (pref_hash_node->info.description); + + pref_hash_node->info.description = g_strdup (description); + + pref_hash_node->info.data = data; + + if (!pref_hash_node->value) + preference_set (preferences, + name, + type, + default_value); } PrefHashNode * -prefs_hash_lookup (NautilusPreferences *prefs, +prefs_hash_lookup (NautilusPreferences *preferences, const char *name) { gpointer hash_value; - g_assert (prefs != NULL); + g_assert (preferences != NULL); g_assert (name != NULL); - hash_value = g_hash_table_lookup (prefs->details->prefs_hash_table, + hash_value = g_hash_table_lookup (preferences->details->preference_hash_table, (gconstpointer) name); return (PrefHashNode *) hash_value; } +PrefHashNode * +prefs_hash_lookup_with_implicit_registration (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type) +{ + PrefHashNode * hash_node; + + g_assert (preferences != NULL); + g_assert (name != NULL); + + hash_node = prefs_hash_lookup (preferences, name); + + if (!hash_node) { + preferences_register (preferences, + (char *) name, + "Unspecified Description", + type, + (gconstpointer) 0, + (gpointer) NULL); + + hash_node = prefs_hash_lookup (preferences, name); + } + + g_assert (hash_node != NULL); + + return hash_node; +} + +gboolean +nautilus_preferences_add_boolean_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) +{ + PrefHashNode *pref_hash_node; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_BOOLEAN); + + if (pref_hash_node == NULL) { + g_warning ("trying to add a callback for an unregistered preference"); + return FALSE; + } + + pref_hash_node_add_callback (pref_hash_node, + callback_proc, + user_data); + + return TRUE; +} + +gboolean +nautilus_preferences_add_enum_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) +{ + PrefHashNode *pref_hash_node; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_ENUM); + + if (pref_hash_node == NULL) { + g_warning ("trying to add a callback for an unregistered preference"); + return FALSE; + } + + pref_hash_node_add_callback (pref_hash_node, + callback_proc, + user_data); + + return TRUE; +} + gboolean -nautilus_preferences_add_callback (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesCallback callback_proc, - gpointer user_data) +nautilus_preferences_add_string_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (callback_proc != NULL, FALSE); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_STRING); + if (pref_hash_node == NULL) { g_warning ("trying to add a callback for an unregistered preference"); return FALSE; @@ -711,18 +821,18 @@ nautilus_preferences_add_callback (NautilusPreferences *prefs, } gboolean -nautilus_preferences_remove_callback (NautilusPreferences *prefs, +nautilus_preferences_remove_callback (NautilusPreferences *preferences, const char *name, NautilusPreferencesCallback callback_proc, gpointer user_data) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (callback_proc != NULL, FALSE); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup (preferences, name); if (pref_hash_node == NULL) { g_warning ("trying to remove a callback for an unregistered preference"); return FALSE; @@ -736,102 +846,96 @@ nautilus_preferences_remove_callback (NautilusPreferences *prefs, } void -nautilus_preferences_set_boolean (NautilusPreferences *prefs, +nautilus_preferences_set_boolean (NautilusPreferences *preferences, const char *name, gboolean boolean_value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); - prefs_set_pref (prefs, name, GINT_TO_POINTER (boolean_value)); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_BOOLEAN, + GINT_TO_POINTER (boolean_value)); } gboolean -nautilus_preferences_get_boolean (NautilusPreferences *prefs, +nautilus_preferences_get_boolean (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered boolean preference '%s'", name); - return FALSE; - } - - g_assert (type == NAUTILUS_PREFERENCE_BOOLEAN); + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_BOOLEAN, + &value); return GPOINTER_TO_INT (value); } void -nautilus_preferences_set_enum (NautilusPreferences *prefs, +nautilus_preferences_set_enum (NautilusPreferences *preferences, const char *name, int enum_value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); - prefs_set_pref (prefs, name, GINT_TO_POINTER (enum_value)); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_ENUM, + GINT_TO_POINTER (enum_value)); } int -nautilus_preferences_get_enum (NautilusPreferences *prefs, +nautilus_preferences_get_enum (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered enum preference '%s'", name); - return 0; - } - - g_assert (type == NAUTILUS_PREFERENCE_ENUM); - + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_ENUM, + &value); + return GPOINTER_TO_INT (value); } void -nautilus_preferences_set_string (NautilusPreferences *prefs, +nautilus_preferences_set_string (NautilusPreferences *preferences, const char *name, const char *value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); g_return_if_fail (value != NULL); - prefs_set_pref (prefs, name, value); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_STRING, + value); } char * -nautilus_preferences_get_string (NautilusPreferences *prefs, +nautilus_preferences_get_string (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered string preference '%s'", name); - return NULL; - } - - g_assert (type == NAUTILUS_PREFERENCE_STRING); - + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_STRING, + &value); + return g_strdup (value); } diff --git a/libnautilus-extensions/nautilus-preferences.h b/libnautilus-extensions/nautilus-preferences.h index ba23fdcbf..88e36e74f 100644 --- a/libnautilus-extensions/nautilus-preferences.h +++ b/libnautilus-extensions/nautilus-preferences.h @@ -64,7 +64,6 @@ typedef enum */ typedef void (*NautilusPreferencesCallback) (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); @@ -91,43 +90,48 @@ typedef struct } NautilusPreferencesEnumData; GtkType nautilus_preferences_get_type (void); -GtkObject * nautilus_preferences_new (const char *domain); -void nautilus_preferences_register_from_info (NautilusPreferences *preferences, - const NautilusPreferencesInfo *pref_info); -void nautilus_preferences_register_from_values (NautilusPreferences *preferences, - char *name, - char *description, - NautilusPreferencesType type, - gconstpointer default_value, - gpointer data); -const NautilusPreferencesInfo *nautilus_preferences_get_info (NautilusPreferences *preferences, - const char *name); -gboolean nautilus_preferences_add_callback (NautilusPreferences *preferences, - const char *name, - NautilusPreferencesCallback callback, - gpointer user_data); -gboolean nautilus_preferences_remove_callback (NautilusPreferences *preferences, - const char *name, - NautilusPreferencesCallback callback, - gpointer user_data); -void nautilus_preferences_set_boolean (NautilusPreferences *preferences, - const char *name, - gboolean value); -gboolean nautilus_preferences_get_boolean (NautilusPreferences *preferences, - const char *name); -void nautilus_preferences_set_enum (NautilusPreferences *preferences, - const char *name, - int value); -int nautilus_preferences_get_enum (NautilusPreferences *preferences, - const char *name); -void nautilus_preferences_set_string (NautilusPreferences *preferences, - const char *name, - const char *value); -char * nautilus_preferences_get_string (NautilusPreferences *preferences, - const char *name); +GtkObject * nautilus_preferences_new (const char *domain); +const NautilusPreferencesInfo *nautilus_preferences_get_info (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_info (NautilusPreferences *preferences, + const char *name, + const char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); +gboolean nautilus_preferences_add_enum_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_add_boolean_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_add_string_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_remove_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +void nautilus_preferences_set_boolean (NautilusPreferences *preferences, + const char *name, + gboolean value); +gboolean nautilus_preferences_get_boolean (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_enum (NautilusPreferences *preferences, + const char *name, + int value); +int nautilus_preferences_get_enum (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_string (NautilusPreferences *preferences, + const char *name, + const char *value); +char * nautilus_preferences_get_string (NautilusPreferences *preferences, + const char *name); NautilusPreferences * nautilus_preferences_get_global_preferences (void); - BEGIN_GNOME_DECLS #endif /* NAUTILUS_PREFERENCES_H */ diff --git a/libnautilus-extensions/test-nautilus-widgets.c b/libnautilus-extensions/test-nautilus-widgets.c index d09acd1e5..01be23f50 100644 --- a/libnautilus-extensions/test-nautilus-widgets.c +++ b/libnautilus-extensions/test-nautilus-widgets.c @@ -145,7 +145,6 @@ create_bool_item (void) return item; } - static const gchar * prefs_global_user_level_names[] = { "novice", @@ -213,11 +212,14 @@ create_dummy_prefs (void) /* Register the static prefs */ for (i = 0; i < 3; i++) { - nautilus_preferences_register_from_info (NAUTILUS_PREFERENCES (dummy_prefs), - &prefs_global_static_pref_info[i]); + nautilus_preferences_set_info (NAUTILUS_PREFERENCES (dummy_prefs), + prefs_global_static_pref_info[i].name, + prefs_global_static_pref_info[i].description, + prefs_global_static_pref_info[i].type, + prefs_global_static_pref_info[i].default_value, + prefs_global_static_pref_info[i].data); } - - + nautilus_preferences_set_enum (NAUTILUS_PREFERENCES (dummy_prefs), "user_level", 2); diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c index 65ce157d8..7aa66c6d6 100644 --- a/libnautilus-private/nautilus-global-preferences.c +++ b/libnautilus-private/nautilus-global-preferences.c @@ -45,6 +45,7 @@ static GtkWidget *global_preferences_create_check_group (GtkWidget *pa const char * const pref_names[], guint num_prefs); static GtkWidget *global_preferences_get_dialog (void); +static void global_preferences_register_for_ui (void); static void global_preferences_register_static (NautilusPreferences *prefs); static void global_preferences_register_dynamic (NautilusPreferences *prefs); @@ -116,20 +117,6 @@ static const NautilusPreferencesInfo global_preferences_static_info[] = FALSE, NULL }, - { - NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, - "", /* No caption since not currently displayed in preferences dialog */ - NAUTILUS_PREFERENCE_STRING, - "name|size|date_modified|type", - NULL - }, - { - NAUTILUS_PREFERENCES_ICON_THEME, - "", /* No caption since not currently displayed in preferences dialog */ - NAUTILUS_PREFERENCE_STRING, - "default", - NULL - } }; /* @@ -142,6 +129,8 @@ global_preferences_create_dialog (void) GtkWidget *prefs_dialog; NautilusPreferencesBox *prefs_box; + global_preferences_register_for_ui (); + prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE); prefs_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog))); @@ -241,9 +230,13 @@ global_preferences_register_static (NautilusPreferences *prefs) g_assert (prefs != NULL); /* Register the static prefs */ - for (i = 0; i < NAUTILUS_N_ELEMENTS (global_preferences_static_info); i++) - { - nautilus_preferences_register_from_info (prefs, &global_preferences_static_info[i]); + for (i = 0; i < NAUTILUS_N_ELEMENTS (global_preferences_static_info); i++) { + nautilus_preferences_set_info (prefs, + global_preferences_static_info[i].name, + global_preferences_static_info[i].description, + global_preferences_static_info[i].type, + global_preferences_static_info[i].default_value, + global_preferences_static_info[i].data); } } @@ -280,47 +273,47 @@ global_preferences_register_dynamic (NautilusPreferences *prefs) { g_assert (prefs != NULL); - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HISTORY, - "History View", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HISTORY, + "History View", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_WEB_SEARCH, - "Web Search View", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_ANNOTATIONS, - "Annotations", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_CONTENTS, - "Help Contents", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_INDEX, - "Help Index", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) FALSE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_SEARCH, - "Help Search", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) FALSE, - NULL); + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_WEB_SEARCH, + "Web Search View", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_ANNOTATIONS, + "Annotations", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_CONTENTS, + "Help Contents", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_INDEX, + "Help Index", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) FALSE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_SEARCH, + "Help Search", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) FALSE, + NULL); } static GtkWidget * @@ -345,6 +338,20 @@ global_preferences_get_dialog (void) return global_prefs_dialog; } +static void +global_preferences_register_for_ui (void) +{ + static gboolean initialized = FALSE; + + if (!initialized) + { + initialized = TRUE; + + global_preferences_register_static (nautilus_preferences_get_global_preferences ()); + global_preferences_register_dynamic (nautilus_preferences_get_global_preferences ()); + } +} + /* * Public functions */ @@ -373,16 +380,3 @@ nautilus_global_preferences_shutdown (void) gtk_object_unref (global_prefs); } -void -nautilus_global_preferences_initialize (void) -{ - static gboolean initialized = FALSE; - - if (!initialized) - { - initialized = TRUE; - - global_preferences_register_static (nautilus_preferences_get_global_preferences ()); - global_preferences_register_dynamic (nautilus_preferences_get_global_preferences ()); - } -} diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h index accb6879a..72855b7d6 100644 --- a/libnautilus-private/nautilus-global-preferences.h +++ b/libnautilus-private/nautilus-global-preferences.h @@ -58,7 +58,6 @@ enum }; void nautilus_global_preferences_shutdown (void); -void nautilus_global_preferences_initialize (void); void nautilus_global_preferences_show_dialog (void); const NautilusStringList *nautilus_global_preferences_get_meta_view_iids (void); diff --git a/libnautilus-private/nautilus-icon-factory.c b/libnautilus-private/nautilus-icon-factory.c index 9b66c7ecc..8d942c9f5 100644 --- a/libnautilus-private/nautilus-icon-factory.c +++ b/libnautilus-private/nautilus-icon-factory.c @@ -180,7 +180,6 @@ typedef struct { static void icon_theme_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); static GtkType nautilus_icon_factory_get_type (void); @@ -219,22 +218,20 @@ nautilus_get_current_icon_factory (void) if (global_icon_factory == NULL) { char *theme_preference; - /* No guarantee that nautilus preferences have been set - * up properly, so we have to initialize them all here just - * to be sure that the icon_theme preference will work. - */ - nautilus_global_preferences_initialize (); theme_preference = nautilus_preferences_get_string (nautilus_preferences_get_global_preferences (), NAUTILUS_PREFERENCES_ICON_THEME); + + g_assert (theme_preference != NULL); + global_icon_factory = nautilus_icon_factory_new (theme_preference); g_free (theme_preference); - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_ICON_THEME, - icon_theme_changed_callback, - NULL); - + nautilus_preferences_add_string_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_THEME, + icon_theme_changed_callback, + NULL); + } return global_icon_factory; } @@ -287,6 +284,19 @@ nautilus_icon_factory_initialize_class (NautilusIconFactoryClass *class) GTK_TYPE_NONE, 0); gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + + /* Set the default icon theme. + * + * We might want to change things such that no default has to be installed + * for this preference. If so, then the code that fetches the preference + * would have to deal with either a NULL return value (or ""). + */ + nautilus_preferences_set_info (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_THEME, + NULL, + NAUTILUS_PREFERENCE_STRING, + "default", + NULL); } /* Destroy one image in the cache. */ @@ -599,13 +609,11 @@ get_icon_file_path (const char *name, guint size_in_pixels, ArtIRect *text_rect) static void icon_theme_changed_callback (NautilusPreferences *preferences, const char *name, - GtkFundamentalType type, gconstpointer value, gpointer user_data) { g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_ICON_THEME) == 0); - g_assert (type == NAUTILUS_PREFERENCE_STRING); g_assert (value != NULL); g_assert (user_data == NULL); diff --git a/libnautilus-private/nautilus-preferences.c b/libnautilus-private/nautilus-preferences.c index b125e7fa9..7729ecf22 100644 --- a/libnautilus-private/nautilus-preferences.c +++ b/libnautilus-private/nautilus-preferences.c @@ -63,50 +63,65 @@ typedef struct { */ struct NautilusPreferencesDetails { char *domain; - GHashTable *prefs_hash_table; + GHashTable *preference_hash_table; }; /* NautilusPreferencesClass methods */ -static void nautilus_preferences_initialize_class (NautilusPreferencesClass *klass); -static void nautilus_preferences_initialize (NautilusPreferences *prefs); +static void nautilus_preferences_initialize_class (NautilusPreferencesClass *klass); +static void nautilus_preferences_initialize (NautilusPreferences *preferences); /* GtkObjectClass methods */ -static void nautilus_preferences_destroy (GtkObject *object); +static void nautilus_preferences_destroy (GtkObject *object); /* PrefHashNode functions */ -static PrefHashNode * pref_hash_node_alloc (const NautilusPreferencesInfo *info); -static void pref_hash_node_free (PrefHashNode *pref_hash_node); -static void pref_hash_node_free_func (gpointer key, - gpointer value, - gpointer user_data); +static PrefHashNode * pref_hash_node_alloc (char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); +static void pref_hash_node_free (PrefHashNode *pref_hash_node); +static void pref_hash_node_free_func (gpointer key, + gpointer value, + gpointer user_data); /* PrefCallbackInfo functions */ -static PrefCallbackInfo *pref_callback_info_alloc (NautilusPreferencesCallback callback_proc, - gpointer user_data, - const PrefHashNode *hash_node); -static void pref_callback_info_free (PrefCallbackInfo *pref_hash_node); -static void pref_callback_info_free_func (gpointer data, - gpointer user_data); -static void pref_callback_info_invoke_func (gpointer data, - gpointer user_data); -static void pref_hash_node_add_callback (PrefHashNode *pref_hash_node, - NautilusPreferencesCallback callback_proc, - gpointer user_data); -static void pref_hash_node_remove_callback (PrefHashNode *pref_hash_node, - NautilusPreferencesCallback callback_proc, - gpointer user_data); - +static PrefCallbackInfo *pref_callback_info_alloc (NautilusPreferencesCallback callback_proc, + gpointer user_data, + const PrefHashNode *hash_node); +static void pref_callback_info_free (PrefCallbackInfo *pref_hash_node); +static void pref_callback_info_free_func (gpointer data, + gpointer user_data); +static void pref_callback_info_invoke_func (gpointer data, + gpointer user_data); +static void pref_hash_node_add_callback (PrefHashNode *pref_hash_node, + NautilusPreferencesCallback callback_proc, + gpointer user_data); +static void pref_hash_node_remove_callback (PrefHashNode *pref_hash_node, + NautilusPreferencesCallback callback_proc, + gpointer user_data); /* Private stuff */ -static void prefs_set_pref (NautilusPreferences *prefs, - const char *name, - gconstpointer value); -static gboolean prefs_get_pref (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesType *type_out, - gconstpointer *value_out); -PrefHashNode * prefs_hash_lookup (NautilusPreferences *prefs, - const char *name); -static char * make_gnome_config_string (const NautilusPreferencesInfo *info); +static void preference_set (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer value); +static void preference_get (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer *value_out); +PrefHashNode * prefs_hash_lookup (NautilusPreferences *preferences, + const char *name); +PrefHashNode * prefs_hash_lookup_with_implicit_registration (NautilusPreferences *preferences, + const char *pref_name, + NautilusPreferencesType pref_type); +static char * gnome_config_make_string (char *name, + NautilusPreferencesType type, + gconstpointer default_value); +static void preferences_register (NautilusPreferences *preferences, + char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferences, nautilus_preferences, GTK_TYPE_OBJECT) @@ -138,14 +153,14 @@ nautilus_preferences_initialize_class (NautilusPreferencesClass *preferences_cla * **/ static void -nautilus_preferences_initialize (NautilusPreferences *prefs) +nautilus_preferences_initialize (NautilusPreferences *preferences) { - prefs->details = g_new (NautilusPreferencesDetails, 1); + preferences->details = g_new (NautilusPreferencesDetails, 1); - prefs->details->domain = NULL; + preferences->details->domain = NULL; - prefs->details->prefs_hash_table = g_hash_table_new (g_str_hash, - g_str_equal); + preferences->details->preference_hash_table = g_hash_table_new (g_str_hash, + g_str_equal); } /** @@ -158,23 +173,23 @@ nautilus_preferences_initialize (NautilusPreferences *prefs) static void nautilus_preferences_destroy (GtkObject *object) { - NautilusPreferences * prefs; + NautilusPreferences *preferences; - prefs = NAUTILUS_PREFERENCES (object); - - g_free (prefs->details->domain); + preferences = NAUTILUS_PREFERENCES (object); - if (prefs->details->prefs_hash_table != NULL) { - g_hash_table_foreach (prefs->details->prefs_hash_table, + g_free (preferences->details->domain); + + if (preferences->details->preference_hash_table != NULL) { + g_hash_table_foreach (preferences->details->preference_hash_table, pref_hash_node_free_func, NULL); - g_hash_table_destroy (prefs->details->prefs_hash_table); - - prefs->details->prefs_hash_table = NULL; + g_hash_table_destroy (preferences->details->preference_hash_table); + + preferences->details->preference_hash_table = NULL; } - - g_free (prefs->details); + + g_free (preferences->details); /* Chain */ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); @@ -189,24 +204,25 @@ nautilus_preferences_destroy (GtkObject *object) * Return value: A newly allocated node. **/ static PrefHashNode * -pref_hash_node_alloc (const NautilusPreferencesInfo *info) +pref_hash_node_alloc (char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { PrefHashNode * pref_hash_node; - g_assert (info != NULL); - - g_assert (info->name != NULL); - g_assert (info->description != NULL); + g_assert (name != NULL); pref_hash_node = g_new (PrefHashNode, 1); - pref_hash_node->info.name = g_strdup (info->name); - pref_hash_node->info.description = g_strdup (info->description); - pref_hash_node->info.type = info->type; - pref_hash_node->info.default_value = info->default_value; - pref_hash_node->info.data = info->data; + pref_hash_node->info.name = g_strdup (name); + pref_hash_node->info.description = description ? g_strdup (description) : NULL; + pref_hash_node->info.type = type; + pref_hash_node->info.default_value = default_value; + pref_hash_node->info.data = data; - pref_hash_node->value = (gpointer) info->default_value; + pref_hash_node->value = (gpointer) default_value; pref_hash_node->callback_list = NULL; return pref_hash_node; @@ -231,7 +247,9 @@ pref_hash_node_free (PrefHashNode *pref_hash_node) NULL); g_free (pref_hash_node->info.name); - g_free (pref_hash_node->info.description); + + if (pref_hash_node->info.description) + g_free (pref_hash_node->info.description); pref_hash_node->info.name = NULL; pref_hash_node->info.type = GTK_TYPE_INVALID; @@ -270,9 +288,8 @@ pref_hash_node_add_callback (PrefHashNode *pref_hash_node, g_assert (pref_callback_info != NULL); - pref_hash_node->callback_list = - g_list_append (pref_hash_node->callback_list, - (gpointer) pref_callback_info); + pref_hash_node->callback_list = g_list_append (pref_hash_node->callback_list, + (gpointer) pref_callback_info); } /** @@ -420,7 +437,7 @@ static void pref_callback_info_invoke_func (gpointer data, gpointer user_data) { - NautilusPreferences *prefs; + NautilusPreferences *preferences; PrefCallbackInfo *pref_callback_info; pref_callback_info = (PrefCallbackInfo *) data; @@ -429,30 +446,28 @@ pref_callback_info_invoke_func (gpointer data, g_assert (pref_callback_info->callback_proc != NULL); - prefs = (NautilusPreferences *) user_data; + preferences = (NautilusPreferences *) user_data; - (* pref_callback_info->callback_proc) (prefs, + (* pref_callback_info->callback_proc) (preferences, pref_callback_info->hash_node->info.name, - pref_callback_info->hash_node->info.type, pref_callback_info->hash_node->value, pref_callback_info->user_data); } static void -prefs_set_pref (NautilusPreferences *prefs, - const char *name, - gconstpointer value) +preference_set (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer value) { PrefHashNode * pref_hash_node; - g_assert (NAUTILUS_IS_PREFERENCES (prefs)); + g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (name != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); - if (!pref_hash_node) { - g_warning ("tried to set an unregistered preference '%s'", name); - return; - } + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); + + g_assert (pref_hash_node != NULL); /* gnome-config for now ; in the future gconf */ switch (pref_hash_node->info.type) { @@ -468,45 +483,41 @@ prefs_set_pref (NautilusPreferences *prefs, break; case NAUTILUS_PREFERENCE_STRING: + if (pref_hash_node->value) + g_free (pref_hash_node->value); pref_hash_node->value = g_strdup (value); gnome_config_set_string (name, pref_hash_node->value); break; - - } /* Sync all the damn time. Yes it sucks. it will be better with gconf */ gnome_config_sync (); + /* Invoke callbacks for this node */ if (pref_hash_node->callback_list) { g_list_foreach (pref_hash_node->callback_list, pref_callback_info_invoke_func, - (gpointer) prefs); + (gpointer) preferences); } } -static gboolean -prefs_get_pref (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesType *type_out, - gconstpointer *value_out) +static void +preference_get (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer *value_out) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (type_out != NULL, FALSE); - g_return_val_if_fail (value_out != NULL, FALSE); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); + g_return_if_fail (name != NULL); + g_return_if_fail (value_out != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); - if (pref_hash_node == NULL) { - return FALSE; - } + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); - *type_out = pref_hash_node->info.type; - *value_out = pref_hash_node->value; + g_assert (pref_hash_node != NULL); - return TRUE; + *value_out = pref_hash_node->value; } /* @@ -515,48 +526,50 @@ prefs_get_pref (NautilusPreferences *prefs, GtkObject * nautilus_preferences_new (const char *domain) { - NautilusPreferences *prefs; + NautilusPreferences *preferences; g_return_val_if_fail (domain != NULL, NULL); - prefs = gtk_type_new (nautilus_preferences_get_type ()); + preferences = gtk_type_new (nautilus_preferences_get_type ()); - return GTK_OBJECT (prefs); + return GTK_OBJECT (preferences); } -void -nautilus_preferences_register_from_info (NautilusPreferences *prefs, - const NautilusPreferencesInfo *info) +static void +preferences_register (NautilusPreferences *preferences, + char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { char *gnome_config_string; PrefHashNode *pref_hash_node; - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); - g_return_if_fail (info != NULL); - - g_return_if_fail (info->name != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (description != NULL); - pref_hash_node = prefs_hash_lookup (prefs, info->name); + pref_hash_node = prefs_hash_lookup (preferences, name); if (pref_hash_node) { - g_warning ("the '%s' preference is already registered", info->name); + g_warning ("the '%s' preference is already registered", name); return; } - pref_hash_node = pref_hash_node_alloc (info); + pref_hash_node = pref_hash_node_alloc (name, description, type, default_value, data); - g_hash_table_insert (prefs->details->prefs_hash_table, - (gpointer) info->name, + g_hash_table_insert (preferences->details->preference_hash_table, + (gpointer) name, (gpointer) pref_hash_node); - gnome_config_string = make_gnome_config_string (info); + gnome_config_string = gnome_config_make_string (name, type, default_value); g_assert (gnome_config_string != NULL); /* gnome-config for now; in the future gconf */ switch (pref_hash_node->info.type) { - case NAUTILUS_PREFERENCE_BOOLEAN: pref_hash_node->value = GINT_TO_POINTER (gnome_config_get_bool (gnome_config_string)); break; @@ -577,7 +590,7 @@ nautilus_preferences_register_from_info (NautilusPreferences *prefs, } /** - * make_gnome_config_string + * gnome_config_make_string * * Make a gnome_config conformant string out of NautilusPreferencesInfo. The 'path' * for the config string is the same for both gnome_config and nautilus preferences. @@ -590,21 +603,22 @@ nautilus_preferences_register_from_info (NautilusPreferences *prefs, * Return value: A newly allocated string with the gnome_config conformant string. **/ static char * -make_gnome_config_string (const NautilusPreferencesInfo *info) +gnome_config_make_string (char *name, + NautilusPreferencesType type, + gconstpointer default_value) { char * rv = NULL; GString * tmp = NULL; - g_assert (info != NULL); + g_assert (name != NULL); - tmp = g_string_new (info->name); + tmp = g_string_new (name); - g_string_append (tmp, "="); - - switch (info->type) { - + switch (type) { case NAUTILUS_PREFERENCE_BOOLEAN: - if (GPOINTER_TO_INT (info->default_value)) { + g_string_append (tmp, "="); + + if (GPOINTER_TO_INT (default_value)) { g_string_append (tmp, "true"); } else { g_string_append (tmp, "false"); @@ -612,11 +626,17 @@ make_gnome_config_string (const NautilusPreferencesInfo *info) break; case NAUTILUS_PREFERENCE_ENUM: - g_string_sprintfa (tmp, "%d", GPOINTER_TO_INT (info->default_value)); + g_string_append (tmp, "="); + + g_string_sprintfa (tmp, "%d", GPOINTER_TO_INT (default_value)); break; case NAUTILUS_PREFERENCE_STRING: - g_string_append (tmp, info->default_value); + if (default_value != NULL) + { + g_string_append (tmp, "="); + g_string_append (tmp, (char *) default_value); + } break; } @@ -630,74 +650,164 @@ make_gnome_config_string (const NautilusPreferencesInfo *info) return rv; } -void -nautilus_preferences_register_from_values (NautilusPreferences *prefs, - char *name, - char *description, - NautilusPreferencesType type, - gconstpointer default_value, - gpointer data) +const NautilusPreferencesInfo * +nautilus_preferences_get_info (NautilusPreferences *preferences, + const char *name) { - NautilusPreferencesInfo info; - - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + PrefHashNode * pref_hash_node; - g_return_if_fail (name != NULL); - g_return_if_fail (description != NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), NULL); + g_return_val_if_fail (name != NULL, NULL); - info.name = name; - info.description = description; - info.type = type; - info.default_value = default_value; - info.data = data; + pref_hash_node = prefs_hash_lookup (preferences, name); + + g_assert (pref_hash_node != NULL); - nautilus_preferences_register_from_info (prefs, &info); + return &pref_hash_node->info; } -const NautilusPreferencesInfo * -nautilus_preferences_get_info (NautilusPreferences *prefs, - const char *name) +void +nautilus_preferences_set_info (NautilusPreferences *preferences, + const char *name, + const char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { - PrefHashNode * pref_hash_node; + PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), NULL); - g_return_val_if_fail (name != NULL, NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); + g_return_if_fail (name != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); g_assert (pref_hash_node != NULL); - return &pref_hash_node->info; + pref_hash_node->info.default_value = default_value; + + if (pref_hash_node->info.description) + g_free (pref_hash_node->info.description); + + pref_hash_node->info.description = g_strdup (description); + + pref_hash_node->info.data = data; + + if (!pref_hash_node->value) + preference_set (preferences, + name, + type, + default_value); } PrefHashNode * -prefs_hash_lookup (NautilusPreferences *prefs, +prefs_hash_lookup (NautilusPreferences *preferences, const char *name) { gpointer hash_value; - g_assert (prefs != NULL); + g_assert (preferences != NULL); g_assert (name != NULL); - hash_value = g_hash_table_lookup (prefs->details->prefs_hash_table, + hash_value = g_hash_table_lookup (preferences->details->preference_hash_table, (gconstpointer) name); return (PrefHashNode *) hash_value; } +PrefHashNode * +prefs_hash_lookup_with_implicit_registration (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type) +{ + PrefHashNode * hash_node; + + g_assert (preferences != NULL); + g_assert (name != NULL); + + hash_node = prefs_hash_lookup (preferences, name); + + if (!hash_node) { + preferences_register (preferences, + (char *) name, + "Unspecified Description", + type, + (gconstpointer) 0, + (gpointer) NULL); + + hash_node = prefs_hash_lookup (preferences, name); + } + + g_assert (hash_node != NULL); + + return hash_node; +} + +gboolean +nautilus_preferences_add_boolean_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) +{ + PrefHashNode *pref_hash_node; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_BOOLEAN); + + if (pref_hash_node == NULL) { + g_warning ("trying to add a callback for an unregistered preference"); + return FALSE; + } + + pref_hash_node_add_callback (pref_hash_node, + callback_proc, + user_data); + + return TRUE; +} + +gboolean +nautilus_preferences_add_enum_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) +{ + PrefHashNode *pref_hash_node; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_ENUM); + + if (pref_hash_node == NULL) { + g_warning ("trying to add a callback for an unregistered preference"); + return FALSE; + } + + pref_hash_node_add_callback (pref_hash_node, + callback_proc, + user_data); + + return TRUE; +} + gboolean -nautilus_preferences_add_callback (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesCallback callback_proc, - gpointer user_data) +nautilus_preferences_add_string_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (callback_proc != NULL, FALSE); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_STRING); + if (pref_hash_node == NULL) { g_warning ("trying to add a callback for an unregistered preference"); return FALSE; @@ -711,18 +821,18 @@ nautilus_preferences_add_callback (NautilusPreferences *prefs, } gboolean -nautilus_preferences_remove_callback (NautilusPreferences *prefs, +nautilus_preferences_remove_callback (NautilusPreferences *preferences, const char *name, NautilusPreferencesCallback callback_proc, gpointer user_data) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (callback_proc != NULL, FALSE); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup (preferences, name); if (pref_hash_node == NULL) { g_warning ("trying to remove a callback for an unregistered preference"); return FALSE; @@ -736,102 +846,96 @@ nautilus_preferences_remove_callback (NautilusPreferences *prefs, } void -nautilus_preferences_set_boolean (NautilusPreferences *prefs, +nautilus_preferences_set_boolean (NautilusPreferences *preferences, const char *name, gboolean boolean_value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); - prefs_set_pref (prefs, name, GINT_TO_POINTER (boolean_value)); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_BOOLEAN, + GINT_TO_POINTER (boolean_value)); } gboolean -nautilus_preferences_get_boolean (NautilusPreferences *prefs, +nautilus_preferences_get_boolean (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered boolean preference '%s'", name); - return FALSE; - } - - g_assert (type == NAUTILUS_PREFERENCE_BOOLEAN); + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_BOOLEAN, + &value); return GPOINTER_TO_INT (value); } void -nautilus_preferences_set_enum (NautilusPreferences *prefs, +nautilus_preferences_set_enum (NautilusPreferences *preferences, const char *name, int enum_value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); - prefs_set_pref (prefs, name, GINT_TO_POINTER (enum_value)); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_ENUM, + GINT_TO_POINTER (enum_value)); } int -nautilus_preferences_get_enum (NautilusPreferences *prefs, +nautilus_preferences_get_enum (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered enum preference '%s'", name); - return 0; - } - - g_assert (type == NAUTILUS_PREFERENCE_ENUM); - + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_ENUM, + &value); + return GPOINTER_TO_INT (value); } void -nautilus_preferences_set_string (NautilusPreferences *prefs, +nautilus_preferences_set_string (NautilusPreferences *preferences, const char *name, const char *value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); g_return_if_fail (value != NULL); - prefs_set_pref (prefs, name, value); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_STRING, + value); } char * -nautilus_preferences_get_string (NautilusPreferences *prefs, +nautilus_preferences_get_string (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered string preference '%s'", name); - return NULL; - } - - g_assert (type == NAUTILUS_PREFERENCE_STRING); - + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_STRING, + &value); + return g_strdup (value); } diff --git a/libnautilus-private/nautilus-preferences.h b/libnautilus-private/nautilus-preferences.h index ba23fdcbf..88e36e74f 100644 --- a/libnautilus-private/nautilus-preferences.h +++ b/libnautilus-private/nautilus-preferences.h @@ -64,7 +64,6 @@ typedef enum */ typedef void (*NautilusPreferencesCallback) (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); @@ -91,43 +90,48 @@ typedef struct } NautilusPreferencesEnumData; GtkType nautilus_preferences_get_type (void); -GtkObject * nautilus_preferences_new (const char *domain); -void nautilus_preferences_register_from_info (NautilusPreferences *preferences, - const NautilusPreferencesInfo *pref_info); -void nautilus_preferences_register_from_values (NautilusPreferences *preferences, - char *name, - char *description, - NautilusPreferencesType type, - gconstpointer default_value, - gpointer data); -const NautilusPreferencesInfo *nautilus_preferences_get_info (NautilusPreferences *preferences, - const char *name); -gboolean nautilus_preferences_add_callback (NautilusPreferences *preferences, - const char *name, - NautilusPreferencesCallback callback, - gpointer user_data); -gboolean nautilus_preferences_remove_callback (NautilusPreferences *preferences, - const char *name, - NautilusPreferencesCallback callback, - gpointer user_data); -void nautilus_preferences_set_boolean (NautilusPreferences *preferences, - const char *name, - gboolean value); -gboolean nautilus_preferences_get_boolean (NautilusPreferences *preferences, - const char *name); -void nautilus_preferences_set_enum (NautilusPreferences *preferences, - const char *name, - int value); -int nautilus_preferences_get_enum (NautilusPreferences *preferences, - const char *name); -void nautilus_preferences_set_string (NautilusPreferences *preferences, - const char *name, - const char *value); -char * nautilus_preferences_get_string (NautilusPreferences *preferences, - const char *name); +GtkObject * nautilus_preferences_new (const char *domain); +const NautilusPreferencesInfo *nautilus_preferences_get_info (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_info (NautilusPreferences *preferences, + const char *name, + const char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); +gboolean nautilus_preferences_add_enum_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_add_boolean_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_add_string_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_remove_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +void nautilus_preferences_set_boolean (NautilusPreferences *preferences, + const char *name, + gboolean value); +gboolean nautilus_preferences_get_boolean (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_enum (NautilusPreferences *preferences, + const char *name, + int value); +int nautilus_preferences_get_enum (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_string (NautilusPreferences *preferences, + const char *name, + const char *value); +char * nautilus_preferences_get_string (NautilusPreferences *preferences, + const char *name); NautilusPreferences * nautilus_preferences_get_global_preferences (void); - BEGIN_GNOME_DECLS #endif /* NAUTILUS_PREFERENCES_H */ diff --git a/libnautilus-private/test-nautilus-widgets.c b/libnautilus-private/test-nautilus-widgets.c index d09acd1e5..01be23f50 100644 --- a/libnautilus-private/test-nautilus-widgets.c +++ b/libnautilus-private/test-nautilus-widgets.c @@ -145,7 +145,6 @@ create_bool_item (void) return item; } - static const gchar * prefs_global_user_level_names[] = { "novice", @@ -213,11 +212,14 @@ create_dummy_prefs (void) /* Register the static prefs */ for (i = 0; i < 3; i++) { - nautilus_preferences_register_from_info (NAUTILUS_PREFERENCES (dummy_prefs), - &prefs_global_static_pref_info[i]); + nautilus_preferences_set_info (NAUTILUS_PREFERENCES (dummy_prefs), + prefs_global_static_pref_info[i].name, + prefs_global_static_pref_info[i].description, + prefs_global_static_pref_info[i].type, + prefs_global_static_pref_info[i].default_value, + prefs_global_static_pref_info[i].data); } - - + nautilus_preferences_set_enum (NAUTILUS_PREFERENCES (dummy_prefs), "user_level", 2); diff --git a/libnautilus/nautilus-global-preferences.c b/libnautilus/nautilus-global-preferences.c index 65ce157d8..7aa66c6d6 100644 --- a/libnautilus/nautilus-global-preferences.c +++ b/libnautilus/nautilus-global-preferences.c @@ -45,6 +45,7 @@ static GtkWidget *global_preferences_create_check_group (GtkWidget *pa const char * const pref_names[], guint num_prefs); static GtkWidget *global_preferences_get_dialog (void); +static void global_preferences_register_for_ui (void); static void global_preferences_register_static (NautilusPreferences *prefs); static void global_preferences_register_dynamic (NautilusPreferences *prefs); @@ -116,20 +117,6 @@ static const NautilusPreferencesInfo global_preferences_static_info[] = FALSE, NULL }, - { - NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, - "", /* No caption since not currently displayed in preferences dialog */ - NAUTILUS_PREFERENCE_STRING, - "name|size|date_modified|type", - NULL - }, - { - NAUTILUS_PREFERENCES_ICON_THEME, - "", /* No caption since not currently displayed in preferences dialog */ - NAUTILUS_PREFERENCE_STRING, - "default", - NULL - } }; /* @@ -142,6 +129,8 @@ global_preferences_create_dialog (void) GtkWidget *prefs_dialog; NautilusPreferencesBox *prefs_box; + global_preferences_register_for_ui (); + prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE); prefs_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog))); @@ -241,9 +230,13 @@ global_preferences_register_static (NautilusPreferences *prefs) g_assert (prefs != NULL); /* Register the static prefs */ - for (i = 0; i < NAUTILUS_N_ELEMENTS (global_preferences_static_info); i++) - { - nautilus_preferences_register_from_info (prefs, &global_preferences_static_info[i]); + for (i = 0; i < NAUTILUS_N_ELEMENTS (global_preferences_static_info); i++) { + nautilus_preferences_set_info (prefs, + global_preferences_static_info[i].name, + global_preferences_static_info[i].description, + global_preferences_static_info[i].type, + global_preferences_static_info[i].default_value, + global_preferences_static_info[i].data); } } @@ -280,47 +273,47 @@ global_preferences_register_dynamic (NautilusPreferences *prefs) { g_assert (prefs != NULL); - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HISTORY, - "History View", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HISTORY, + "History View", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_WEB_SEARCH, - "Web Search View", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_ANNOTATIONS, - "Annotations", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_CONTENTS, - "Help Contents", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) TRUE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_INDEX, - "Help Index", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) FALSE, - NULL); - - nautilus_preferences_register_from_values (prefs, - NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_SEARCH, - "Help Search", - NAUTILUS_PREFERENCE_BOOLEAN, - (gconstpointer) FALSE, - NULL); + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_WEB_SEARCH, + "Web Search View", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_ANNOTATIONS, + "Annotations", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_CONTENTS, + "Help Contents", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) TRUE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_INDEX, + "Help Index", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) FALSE, + NULL); + + nautilus_preferences_set_info (prefs, + NAUTILUS_PREFERENCES_META_VIEWS_SHOW_HELP_SEARCH, + "Help Search", + NAUTILUS_PREFERENCE_BOOLEAN, + (gconstpointer) FALSE, + NULL); } static GtkWidget * @@ -345,6 +338,20 @@ global_preferences_get_dialog (void) return global_prefs_dialog; } +static void +global_preferences_register_for_ui (void) +{ + static gboolean initialized = FALSE; + + if (!initialized) + { + initialized = TRUE; + + global_preferences_register_static (nautilus_preferences_get_global_preferences ()); + global_preferences_register_dynamic (nautilus_preferences_get_global_preferences ()); + } +} + /* * Public functions */ @@ -373,16 +380,3 @@ nautilus_global_preferences_shutdown (void) gtk_object_unref (global_prefs); } -void -nautilus_global_preferences_initialize (void) -{ - static gboolean initialized = FALSE; - - if (!initialized) - { - initialized = TRUE; - - global_preferences_register_static (nautilus_preferences_get_global_preferences ()); - global_preferences_register_dynamic (nautilus_preferences_get_global_preferences ()); - } -} diff --git a/libnautilus/nautilus-global-preferences.h b/libnautilus/nautilus-global-preferences.h index accb6879a..72855b7d6 100644 --- a/libnautilus/nautilus-global-preferences.h +++ b/libnautilus/nautilus-global-preferences.h @@ -58,7 +58,6 @@ enum }; void nautilus_global_preferences_shutdown (void); -void nautilus_global_preferences_initialize (void); void nautilus_global_preferences_show_dialog (void); const NautilusStringList *nautilus_global_preferences_get_meta_view_iids (void); diff --git a/libnautilus/nautilus-icon-factory.c b/libnautilus/nautilus-icon-factory.c index 9b66c7ecc..8d942c9f5 100644 --- a/libnautilus/nautilus-icon-factory.c +++ b/libnautilus/nautilus-icon-factory.c @@ -180,7 +180,6 @@ typedef struct { static void icon_theme_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); static GtkType nautilus_icon_factory_get_type (void); @@ -219,22 +218,20 @@ nautilus_get_current_icon_factory (void) if (global_icon_factory == NULL) { char *theme_preference; - /* No guarantee that nautilus preferences have been set - * up properly, so we have to initialize them all here just - * to be sure that the icon_theme preference will work. - */ - nautilus_global_preferences_initialize (); theme_preference = nautilus_preferences_get_string (nautilus_preferences_get_global_preferences (), NAUTILUS_PREFERENCES_ICON_THEME); + + g_assert (theme_preference != NULL); + global_icon_factory = nautilus_icon_factory_new (theme_preference); g_free (theme_preference); - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_ICON_THEME, - icon_theme_changed_callback, - NULL); - + nautilus_preferences_add_string_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_THEME, + icon_theme_changed_callback, + NULL); + } return global_icon_factory; } @@ -287,6 +284,19 @@ nautilus_icon_factory_initialize_class (NautilusIconFactoryClass *class) GTK_TYPE_NONE, 0); gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + + /* Set the default icon theme. + * + * We might want to change things such that no default has to be installed + * for this preference. If so, then the code that fetches the preference + * would have to deal with either a NULL return value (or ""). + */ + nautilus_preferences_set_info (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_THEME, + NULL, + NAUTILUS_PREFERENCE_STRING, + "default", + NULL); } /* Destroy one image in the cache. */ @@ -599,13 +609,11 @@ get_icon_file_path (const char *name, guint size_in_pixels, ArtIRect *text_rect) static void icon_theme_changed_callback (NautilusPreferences *preferences, const char *name, - GtkFundamentalType type, gconstpointer value, gpointer user_data) { g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_ICON_THEME) == 0); - g_assert (type == NAUTILUS_PREFERENCE_STRING); g_assert (value != NULL); g_assert (user_data == NULL); diff --git a/nautilus-widgets/nautilus-preferences.c b/nautilus-widgets/nautilus-preferences.c index b125e7fa9..7729ecf22 100644 --- a/nautilus-widgets/nautilus-preferences.c +++ b/nautilus-widgets/nautilus-preferences.c @@ -63,50 +63,65 @@ typedef struct { */ struct NautilusPreferencesDetails { char *domain; - GHashTable *prefs_hash_table; + GHashTable *preference_hash_table; }; /* NautilusPreferencesClass methods */ -static void nautilus_preferences_initialize_class (NautilusPreferencesClass *klass); -static void nautilus_preferences_initialize (NautilusPreferences *prefs); +static void nautilus_preferences_initialize_class (NautilusPreferencesClass *klass); +static void nautilus_preferences_initialize (NautilusPreferences *preferences); /* GtkObjectClass methods */ -static void nautilus_preferences_destroy (GtkObject *object); +static void nautilus_preferences_destroy (GtkObject *object); /* PrefHashNode functions */ -static PrefHashNode * pref_hash_node_alloc (const NautilusPreferencesInfo *info); -static void pref_hash_node_free (PrefHashNode *pref_hash_node); -static void pref_hash_node_free_func (gpointer key, - gpointer value, - gpointer user_data); +static PrefHashNode * pref_hash_node_alloc (char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); +static void pref_hash_node_free (PrefHashNode *pref_hash_node); +static void pref_hash_node_free_func (gpointer key, + gpointer value, + gpointer user_data); /* PrefCallbackInfo functions */ -static PrefCallbackInfo *pref_callback_info_alloc (NautilusPreferencesCallback callback_proc, - gpointer user_data, - const PrefHashNode *hash_node); -static void pref_callback_info_free (PrefCallbackInfo *pref_hash_node); -static void pref_callback_info_free_func (gpointer data, - gpointer user_data); -static void pref_callback_info_invoke_func (gpointer data, - gpointer user_data); -static void pref_hash_node_add_callback (PrefHashNode *pref_hash_node, - NautilusPreferencesCallback callback_proc, - gpointer user_data); -static void pref_hash_node_remove_callback (PrefHashNode *pref_hash_node, - NautilusPreferencesCallback callback_proc, - gpointer user_data); - +static PrefCallbackInfo *pref_callback_info_alloc (NautilusPreferencesCallback callback_proc, + gpointer user_data, + const PrefHashNode *hash_node); +static void pref_callback_info_free (PrefCallbackInfo *pref_hash_node); +static void pref_callback_info_free_func (gpointer data, + gpointer user_data); +static void pref_callback_info_invoke_func (gpointer data, + gpointer user_data); +static void pref_hash_node_add_callback (PrefHashNode *pref_hash_node, + NautilusPreferencesCallback callback_proc, + gpointer user_data); +static void pref_hash_node_remove_callback (PrefHashNode *pref_hash_node, + NautilusPreferencesCallback callback_proc, + gpointer user_data); /* Private stuff */ -static void prefs_set_pref (NautilusPreferences *prefs, - const char *name, - gconstpointer value); -static gboolean prefs_get_pref (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesType *type_out, - gconstpointer *value_out); -PrefHashNode * prefs_hash_lookup (NautilusPreferences *prefs, - const char *name); -static char * make_gnome_config_string (const NautilusPreferencesInfo *info); +static void preference_set (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer value); +static void preference_get (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer *value_out); +PrefHashNode * prefs_hash_lookup (NautilusPreferences *preferences, + const char *name); +PrefHashNode * prefs_hash_lookup_with_implicit_registration (NautilusPreferences *preferences, + const char *pref_name, + NautilusPreferencesType pref_type); +static char * gnome_config_make_string (char *name, + NautilusPreferencesType type, + gconstpointer default_value); +static void preferences_register (NautilusPreferences *preferences, + char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferences, nautilus_preferences, GTK_TYPE_OBJECT) @@ -138,14 +153,14 @@ nautilus_preferences_initialize_class (NautilusPreferencesClass *preferences_cla * **/ static void -nautilus_preferences_initialize (NautilusPreferences *prefs) +nautilus_preferences_initialize (NautilusPreferences *preferences) { - prefs->details = g_new (NautilusPreferencesDetails, 1); + preferences->details = g_new (NautilusPreferencesDetails, 1); - prefs->details->domain = NULL; + preferences->details->domain = NULL; - prefs->details->prefs_hash_table = g_hash_table_new (g_str_hash, - g_str_equal); + preferences->details->preference_hash_table = g_hash_table_new (g_str_hash, + g_str_equal); } /** @@ -158,23 +173,23 @@ nautilus_preferences_initialize (NautilusPreferences *prefs) static void nautilus_preferences_destroy (GtkObject *object) { - NautilusPreferences * prefs; + NautilusPreferences *preferences; - prefs = NAUTILUS_PREFERENCES (object); - - g_free (prefs->details->domain); + preferences = NAUTILUS_PREFERENCES (object); - if (prefs->details->prefs_hash_table != NULL) { - g_hash_table_foreach (prefs->details->prefs_hash_table, + g_free (preferences->details->domain); + + if (preferences->details->preference_hash_table != NULL) { + g_hash_table_foreach (preferences->details->preference_hash_table, pref_hash_node_free_func, NULL); - g_hash_table_destroy (prefs->details->prefs_hash_table); - - prefs->details->prefs_hash_table = NULL; + g_hash_table_destroy (preferences->details->preference_hash_table); + + preferences->details->preference_hash_table = NULL; } - - g_free (prefs->details); + + g_free (preferences->details); /* Chain */ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); @@ -189,24 +204,25 @@ nautilus_preferences_destroy (GtkObject *object) * Return value: A newly allocated node. **/ static PrefHashNode * -pref_hash_node_alloc (const NautilusPreferencesInfo *info) +pref_hash_node_alloc (char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { PrefHashNode * pref_hash_node; - g_assert (info != NULL); - - g_assert (info->name != NULL); - g_assert (info->description != NULL); + g_assert (name != NULL); pref_hash_node = g_new (PrefHashNode, 1); - pref_hash_node->info.name = g_strdup (info->name); - pref_hash_node->info.description = g_strdup (info->description); - pref_hash_node->info.type = info->type; - pref_hash_node->info.default_value = info->default_value; - pref_hash_node->info.data = info->data; + pref_hash_node->info.name = g_strdup (name); + pref_hash_node->info.description = description ? g_strdup (description) : NULL; + pref_hash_node->info.type = type; + pref_hash_node->info.default_value = default_value; + pref_hash_node->info.data = data; - pref_hash_node->value = (gpointer) info->default_value; + pref_hash_node->value = (gpointer) default_value; pref_hash_node->callback_list = NULL; return pref_hash_node; @@ -231,7 +247,9 @@ pref_hash_node_free (PrefHashNode *pref_hash_node) NULL); g_free (pref_hash_node->info.name); - g_free (pref_hash_node->info.description); + + if (pref_hash_node->info.description) + g_free (pref_hash_node->info.description); pref_hash_node->info.name = NULL; pref_hash_node->info.type = GTK_TYPE_INVALID; @@ -270,9 +288,8 @@ pref_hash_node_add_callback (PrefHashNode *pref_hash_node, g_assert (pref_callback_info != NULL); - pref_hash_node->callback_list = - g_list_append (pref_hash_node->callback_list, - (gpointer) pref_callback_info); + pref_hash_node->callback_list = g_list_append (pref_hash_node->callback_list, + (gpointer) pref_callback_info); } /** @@ -420,7 +437,7 @@ static void pref_callback_info_invoke_func (gpointer data, gpointer user_data) { - NautilusPreferences *prefs; + NautilusPreferences *preferences; PrefCallbackInfo *pref_callback_info; pref_callback_info = (PrefCallbackInfo *) data; @@ -429,30 +446,28 @@ pref_callback_info_invoke_func (gpointer data, g_assert (pref_callback_info->callback_proc != NULL); - prefs = (NautilusPreferences *) user_data; + preferences = (NautilusPreferences *) user_data; - (* pref_callback_info->callback_proc) (prefs, + (* pref_callback_info->callback_proc) (preferences, pref_callback_info->hash_node->info.name, - pref_callback_info->hash_node->info.type, pref_callback_info->hash_node->value, pref_callback_info->user_data); } static void -prefs_set_pref (NautilusPreferences *prefs, - const char *name, - gconstpointer value) +preference_set (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer value) { PrefHashNode * pref_hash_node; - g_assert (NAUTILUS_IS_PREFERENCES (prefs)); + g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (name != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); - if (!pref_hash_node) { - g_warning ("tried to set an unregistered preference '%s'", name); - return; - } + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); + + g_assert (pref_hash_node != NULL); /* gnome-config for now ; in the future gconf */ switch (pref_hash_node->info.type) { @@ -468,45 +483,41 @@ prefs_set_pref (NautilusPreferences *prefs, break; case NAUTILUS_PREFERENCE_STRING: + if (pref_hash_node->value) + g_free (pref_hash_node->value); pref_hash_node->value = g_strdup (value); gnome_config_set_string (name, pref_hash_node->value); break; - - } /* Sync all the damn time. Yes it sucks. it will be better with gconf */ gnome_config_sync (); + /* Invoke callbacks for this node */ if (pref_hash_node->callback_list) { g_list_foreach (pref_hash_node->callback_list, pref_callback_info_invoke_func, - (gpointer) prefs); + (gpointer) preferences); } } -static gboolean -prefs_get_pref (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesType *type_out, - gconstpointer *value_out) +static void +preference_get (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type, + gconstpointer *value_out) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (type_out != NULL, FALSE); - g_return_val_if_fail (value_out != NULL, FALSE); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); + g_return_if_fail (name != NULL); + g_return_if_fail (value_out != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); - if (pref_hash_node == NULL) { - return FALSE; - } + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); - *type_out = pref_hash_node->info.type; - *value_out = pref_hash_node->value; + g_assert (pref_hash_node != NULL); - return TRUE; + *value_out = pref_hash_node->value; } /* @@ -515,48 +526,50 @@ prefs_get_pref (NautilusPreferences *prefs, GtkObject * nautilus_preferences_new (const char *domain) { - NautilusPreferences *prefs; + NautilusPreferences *preferences; g_return_val_if_fail (domain != NULL, NULL); - prefs = gtk_type_new (nautilus_preferences_get_type ()); + preferences = gtk_type_new (nautilus_preferences_get_type ()); - return GTK_OBJECT (prefs); + return GTK_OBJECT (preferences); } -void -nautilus_preferences_register_from_info (NautilusPreferences *prefs, - const NautilusPreferencesInfo *info) +static void +preferences_register (NautilusPreferences *preferences, + char *name, + char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { char *gnome_config_string; PrefHashNode *pref_hash_node; - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); - g_return_if_fail (info != NULL); - - g_return_if_fail (info->name != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (description != NULL); - pref_hash_node = prefs_hash_lookup (prefs, info->name); + pref_hash_node = prefs_hash_lookup (preferences, name); if (pref_hash_node) { - g_warning ("the '%s' preference is already registered", info->name); + g_warning ("the '%s' preference is already registered", name); return; } - pref_hash_node = pref_hash_node_alloc (info); + pref_hash_node = pref_hash_node_alloc (name, description, type, default_value, data); - g_hash_table_insert (prefs->details->prefs_hash_table, - (gpointer) info->name, + g_hash_table_insert (preferences->details->preference_hash_table, + (gpointer) name, (gpointer) pref_hash_node); - gnome_config_string = make_gnome_config_string (info); + gnome_config_string = gnome_config_make_string (name, type, default_value); g_assert (gnome_config_string != NULL); /* gnome-config for now; in the future gconf */ switch (pref_hash_node->info.type) { - case NAUTILUS_PREFERENCE_BOOLEAN: pref_hash_node->value = GINT_TO_POINTER (gnome_config_get_bool (gnome_config_string)); break; @@ -577,7 +590,7 @@ nautilus_preferences_register_from_info (NautilusPreferences *prefs, } /** - * make_gnome_config_string + * gnome_config_make_string * * Make a gnome_config conformant string out of NautilusPreferencesInfo. The 'path' * for the config string is the same for both gnome_config and nautilus preferences. @@ -590,21 +603,22 @@ nautilus_preferences_register_from_info (NautilusPreferences *prefs, * Return value: A newly allocated string with the gnome_config conformant string. **/ static char * -make_gnome_config_string (const NautilusPreferencesInfo *info) +gnome_config_make_string (char *name, + NautilusPreferencesType type, + gconstpointer default_value) { char * rv = NULL; GString * tmp = NULL; - g_assert (info != NULL); + g_assert (name != NULL); - tmp = g_string_new (info->name); + tmp = g_string_new (name); - g_string_append (tmp, "="); - - switch (info->type) { - + switch (type) { case NAUTILUS_PREFERENCE_BOOLEAN: - if (GPOINTER_TO_INT (info->default_value)) { + g_string_append (tmp, "="); + + if (GPOINTER_TO_INT (default_value)) { g_string_append (tmp, "true"); } else { g_string_append (tmp, "false"); @@ -612,11 +626,17 @@ make_gnome_config_string (const NautilusPreferencesInfo *info) break; case NAUTILUS_PREFERENCE_ENUM: - g_string_sprintfa (tmp, "%d", GPOINTER_TO_INT (info->default_value)); + g_string_append (tmp, "="); + + g_string_sprintfa (tmp, "%d", GPOINTER_TO_INT (default_value)); break; case NAUTILUS_PREFERENCE_STRING: - g_string_append (tmp, info->default_value); + if (default_value != NULL) + { + g_string_append (tmp, "="); + g_string_append (tmp, (char *) default_value); + } break; } @@ -630,74 +650,164 @@ make_gnome_config_string (const NautilusPreferencesInfo *info) return rv; } -void -nautilus_preferences_register_from_values (NautilusPreferences *prefs, - char *name, - char *description, - NautilusPreferencesType type, - gconstpointer default_value, - gpointer data) +const NautilusPreferencesInfo * +nautilus_preferences_get_info (NautilusPreferences *preferences, + const char *name) { - NautilusPreferencesInfo info; - - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + PrefHashNode * pref_hash_node; - g_return_if_fail (name != NULL); - g_return_if_fail (description != NULL); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), NULL); + g_return_val_if_fail (name != NULL, NULL); - info.name = name; - info.description = description; - info.type = type; - info.default_value = default_value; - info.data = data; + pref_hash_node = prefs_hash_lookup (preferences, name); + + g_assert (pref_hash_node != NULL); - nautilus_preferences_register_from_info (prefs, &info); + return &pref_hash_node->info; } -const NautilusPreferencesInfo * -nautilus_preferences_get_info (NautilusPreferences *prefs, - const char *name) +void +nautilus_preferences_set_info (NautilusPreferences *preferences, + const char *name, + const char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data) { - PrefHashNode * pref_hash_node; + PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), NULL); - g_return_val_if_fail (name != NULL, NULL); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); + g_return_if_fail (name != NULL); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, type); g_assert (pref_hash_node != NULL); - return &pref_hash_node->info; + pref_hash_node->info.default_value = default_value; + + if (pref_hash_node->info.description) + g_free (pref_hash_node->info.description); + + pref_hash_node->info.description = g_strdup (description); + + pref_hash_node->info.data = data; + + if (!pref_hash_node->value) + preference_set (preferences, + name, + type, + default_value); } PrefHashNode * -prefs_hash_lookup (NautilusPreferences *prefs, +prefs_hash_lookup (NautilusPreferences *preferences, const char *name) { gpointer hash_value; - g_assert (prefs != NULL); + g_assert (preferences != NULL); g_assert (name != NULL); - hash_value = g_hash_table_lookup (prefs->details->prefs_hash_table, + hash_value = g_hash_table_lookup (preferences->details->preference_hash_table, (gconstpointer) name); return (PrefHashNode *) hash_value; } +PrefHashNode * +prefs_hash_lookup_with_implicit_registration (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesType type) +{ + PrefHashNode * hash_node; + + g_assert (preferences != NULL); + g_assert (name != NULL); + + hash_node = prefs_hash_lookup (preferences, name); + + if (!hash_node) { + preferences_register (preferences, + (char *) name, + "Unspecified Description", + type, + (gconstpointer) 0, + (gpointer) NULL); + + hash_node = prefs_hash_lookup (preferences, name); + } + + g_assert (hash_node != NULL); + + return hash_node; +} + +gboolean +nautilus_preferences_add_boolean_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) +{ + PrefHashNode *pref_hash_node; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_BOOLEAN); + + if (pref_hash_node == NULL) { + g_warning ("trying to add a callback for an unregistered preference"); + return FALSE; + } + + pref_hash_node_add_callback (pref_hash_node, + callback_proc, + user_data); + + return TRUE; +} + +gboolean +nautilus_preferences_add_enum_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) +{ + PrefHashNode *pref_hash_node; + + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (callback_proc != NULL, FALSE); + + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_ENUM); + + if (pref_hash_node == NULL) { + g_warning ("trying to add a callback for an unregistered preference"); + return FALSE; + } + + pref_hash_node_add_callback (pref_hash_node, + callback_proc, + user_data); + + return TRUE; +} + gboolean -nautilus_preferences_add_callback (NautilusPreferences *prefs, - const char *name, - NautilusPreferencesCallback callback_proc, - gpointer user_data) +nautilus_preferences_add_string_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback_proc, + gpointer user_data) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (callback_proc != NULL, FALSE); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup_with_implicit_registration (preferences, name, NAUTILUS_PREFERENCE_STRING); + if (pref_hash_node == NULL) { g_warning ("trying to add a callback for an unregistered preference"); return FALSE; @@ -711,18 +821,18 @@ nautilus_preferences_add_callback (NautilusPreferences *prefs, } gboolean -nautilus_preferences_remove_callback (NautilusPreferences *prefs, +nautilus_preferences_remove_callback (NautilusPreferences *preferences, const char *name, NautilusPreferencesCallback callback_proc, gpointer user_data) { PrefHashNode *pref_hash_node; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (callback_proc != NULL, FALSE); - pref_hash_node = prefs_hash_lookup (prefs, name); + pref_hash_node = prefs_hash_lookup (preferences, name); if (pref_hash_node == NULL) { g_warning ("trying to remove a callback for an unregistered preference"); return FALSE; @@ -736,102 +846,96 @@ nautilus_preferences_remove_callback (NautilusPreferences *prefs, } void -nautilus_preferences_set_boolean (NautilusPreferences *prefs, +nautilus_preferences_set_boolean (NautilusPreferences *preferences, const char *name, gboolean boolean_value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); - prefs_set_pref (prefs, name, GINT_TO_POINTER (boolean_value)); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_BOOLEAN, + GINT_TO_POINTER (boolean_value)); } gboolean -nautilus_preferences_get_boolean (NautilusPreferences *prefs, +nautilus_preferences_get_boolean (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered boolean preference '%s'", name); - return FALSE; - } - - g_assert (type == NAUTILUS_PREFERENCE_BOOLEAN); + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_BOOLEAN, + &value); return GPOINTER_TO_INT (value); } void -nautilus_preferences_set_enum (NautilusPreferences *prefs, +nautilus_preferences_set_enum (NautilusPreferences *preferences, const char *name, int enum_value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); - prefs_set_pref (prefs, name, GINT_TO_POINTER (enum_value)); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_ENUM, + GINT_TO_POINTER (enum_value)); } int -nautilus_preferences_get_enum (NautilusPreferences *prefs, +nautilus_preferences_get_enum (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered enum preference '%s'", name); - return 0; - } - - g_assert (type == NAUTILUS_PREFERENCE_ENUM); - + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_ENUM, + &value); + return GPOINTER_TO_INT (value); } void -nautilus_preferences_set_string (NautilusPreferences *prefs, +nautilus_preferences_set_string (NautilusPreferences *preferences, const char *name, const char *value) { - g_return_if_fail (NAUTILUS_IS_PREFERENCES (prefs)); + g_return_if_fail (NAUTILUS_IS_PREFERENCES (preferences)); g_return_if_fail (name != NULL); g_return_if_fail (value != NULL); - prefs_set_pref (prefs, name, value); + preference_set (preferences, + name, + NAUTILUS_PREFERENCE_STRING, + value); } char * -nautilus_preferences_get_string (NautilusPreferences *prefs, +nautilus_preferences_get_string (NautilusPreferences *preferences, const char *name) { - gboolean rv; - NautilusPreferencesType type; - gconstpointer value; + gconstpointer value; - g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (prefs), FALSE); + g_return_val_if_fail (NAUTILUS_IS_PREFERENCES (preferences), FALSE); g_return_val_if_fail (name != NULL, FALSE); - rv = prefs_get_pref (prefs, name, &type, &value); - if (!rv) { - g_warning ("tried to get an unregistered string preference '%s'", name); - return NULL; - } - - g_assert (type == NAUTILUS_PREFERENCE_STRING); - + preference_get (preferences, + name, + NAUTILUS_PREFERENCE_STRING, + &value); + return g_strdup (value); } diff --git a/nautilus-widgets/nautilus-preferences.h b/nautilus-widgets/nautilus-preferences.h index ba23fdcbf..88e36e74f 100644 --- a/nautilus-widgets/nautilus-preferences.h +++ b/nautilus-widgets/nautilus-preferences.h @@ -64,7 +64,6 @@ typedef enum */ typedef void (*NautilusPreferencesCallback) (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); @@ -91,43 +90,48 @@ typedef struct } NautilusPreferencesEnumData; GtkType nautilus_preferences_get_type (void); -GtkObject * nautilus_preferences_new (const char *domain); -void nautilus_preferences_register_from_info (NautilusPreferences *preferences, - const NautilusPreferencesInfo *pref_info); -void nautilus_preferences_register_from_values (NautilusPreferences *preferences, - char *name, - char *description, - NautilusPreferencesType type, - gconstpointer default_value, - gpointer data); -const NautilusPreferencesInfo *nautilus_preferences_get_info (NautilusPreferences *preferences, - const char *name); -gboolean nautilus_preferences_add_callback (NautilusPreferences *preferences, - const char *name, - NautilusPreferencesCallback callback, - gpointer user_data); -gboolean nautilus_preferences_remove_callback (NautilusPreferences *preferences, - const char *name, - NautilusPreferencesCallback callback, - gpointer user_data); -void nautilus_preferences_set_boolean (NautilusPreferences *preferences, - const char *name, - gboolean value); -gboolean nautilus_preferences_get_boolean (NautilusPreferences *preferences, - const char *name); -void nautilus_preferences_set_enum (NautilusPreferences *preferences, - const char *name, - int value); -int nautilus_preferences_get_enum (NautilusPreferences *preferences, - const char *name); -void nautilus_preferences_set_string (NautilusPreferences *preferences, - const char *name, - const char *value); -char * nautilus_preferences_get_string (NautilusPreferences *preferences, - const char *name); +GtkObject * nautilus_preferences_new (const char *domain); +const NautilusPreferencesInfo *nautilus_preferences_get_info (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_info (NautilusPreferences *preferences, + const char *name, + const char *description, + NautilusPreferencesType type, + gconstpointer default_value, + gpointer data); +gboolean nautilus_preferences_add_enum_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_add_boolean_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_add_string_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +gboolean nautilus_preferences_remove_callback (NautilusPreferences *preferences, + const char *name, + NautilusPreferencesCallback callback, + gpointer user_data); +void nautilus_preferences_set_boolean (NautilusPreferences *preferences, + const char *name, + gboolean value); +gboolean nautilus_preferences_get_boolean (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_enum (NautilusPreferences *preferences, + const char *name, + int value); +int nautilus_preferences_get_enum (NautilusPreferences *preferences, + const char *name); +void nautilus_preferences_set_string (NautilusPreferences *preferences, + const char *name, + const char *value); +char * nautilus_preferences_get_string (NautilusPreferences *preferences, + const char *name); NautilusPreferences * nautilus_preferences_get_global_preferences (void); - BEGIN_GNOME_DECLS #endif /* NAUTILUS_PREFERENCES_H */ diff --git a/nautilus-widgets/test-nautilus-widgets.c b/nautilus-widgets/test-nautilus-widgets.c index d09acd1e5..01be23f50 100644 --- a/nautilus-widgets/test-nautilus-widgets.c +++ b/nautilus-widgets/test-nautilus-widgets.c @@ -145,7 +145,6 @@ create_bool_item (void) return item; } - static const gchar * prefs_global_user_level_names[] = { "novice", @@ -213,11 +212,14 @@ create_dummy_prefs (void) /* Register the static prefs */ for (i = 0; i < 3; i++) { - nautilus_preferences_register_from_info (NAUTILUS_PREFERENCES (dummy_prefs), - &prefs_global_static_pref_info[i]); + nautilus_preferences_set_info (NAUTILUS_PREFERENCES (dummy_prefs), + prefs_global_static_pref_info[i].name, + prefs_global_static_pref_info[i].description, + prefs_global_static_pref_info[i].type, + prefs_global_static_pref_info[i].default_value, + prefs_global_static_pref_info[i].data); } - - + nautilus_preferences_set_enum (NAUTILUS_PREFERENCES (dummy_prefs), "user_level", 2); diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index 0138582b3..9582bd373 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -168,12 +168,10 @@ static void unschedule_display_of_pending_files static void disconnect_model_handlers (FMDirectoryView *view); static void user_level_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); static void use_new_window_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); static void add_nautilus_file_to_uri_map (FMDirectoryView *preferences, @@ -469,19 +467,19 @@ fm_directory_view_initialize (FMDirectoryView *directory_view) /* Keep track of subsequent user level changes so that we dont have to query * preferences continually */ - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_USER_LEVEL, - user_level_changed_callback, - directory_view); + nautilus_preferences_add_enum_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_USER_LEVEL, + user_level_changed_callback, + directory_view); directory_view->details->use_new_window = nautilus_preferences_get_boolean (nautilus_preferences_get_global_preferences (), NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW); - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW, - use_new_window_changed_callback, - directory_view); + nautilus_preferences_add_boolean_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW, + use_new_window_changed_callback, + directory_view); } static void @@ -2014,13 +2012,11 @@ fm_directory_view_update_menus (FMDirectoryView *view) static void use_new_window_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data) { g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW) == 0); - g_assert (type == NAUTILUS_PREFERENCE_BOOLEAN); g_assert (GPOINTER_TO_INT (value) == FALSE || GPOINTER_TO_INT (value) == TRUE); g_assert (FM_IS_DIRECTORY_VIEW (user_data)); @@ -2030,7 +2026,6 @@ use_new_window_changed_callback (NautilusPreferences *preferences, static void user_level_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data) { @@ -2039,7 +2034,6 @@ user_level_changed_callback (NautilusPreferences *preferences, g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_USER_LEVEL) == 0); - g_assert (type == NAUTILUS_PREFERENCE_ENUM); g_assert (FM_IS_DIRECTORY_VIEW (user_data)); directory_view = FM_DIRECTORY_VIEW (user_data); diff --git a/src/file-manager/fm-icon-text-window.c b/src/file-manager/fm-icon-text-window.c index 44cdba20e..9b6a98ee9 100644 --- a/src/file-manager/fm-icon-text-window.c +++ b/src/file-manager/fm-icon-text-window.c @@ -128,14 +128,12 @@ synch_menus_with_preference (void) static void preference_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data) { g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES) == 0); - g_assert (type == NAUTILUS_PREFERENCE_STRING); g_assert (value != NULL); g_assert (user_data == NULL); @@ -282,10 +280,10 @@ create_icon_text_window (void) synch_menus_with_preference (); - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, - preference_changed_callback, - NULL); + nautilus_preferences_add_string_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, + preference_changed_callback, + NULL); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (fm_icon_text_window_delete_event_cb), diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c index 605569b72..42cea525b 100644 --- a/src/file-manager/fm-icon-view.c +++ b/src/file-manager/fm-icon-view.c @@ -132,7 +132,6 @@ static char * get_icon_property_callback FMIconView *icon_view); static void text_attribute_names_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data); @@ -177,6 +176,19 @@ fm_icon_view_initialize_class (FMIconViewClass *klass) fm_directory_view_class->append_selection_context_menu_items = fm_icon_view_append_selection_context_menu_items; fm_directory_view_class->merge_menus = fm_icon_view_merge_menus; fm_directory_view_class->update_menus = fm_icon_view_update_menus; + + /* Set the text attribute preferences info. We do this so that we can later get a sane default value. + * + * We might want to change things such that no default has to be installed + * for this preference. If so, then the code that fetches the preference + * would have to deal with either a NULL return value (or ""). + */ + nautilus_preferences_set_info (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, + NULL, + NAUTILUS_PREFERENCE_STRING, + "name|size|date_modified|type", + NULL); } static void @@ -192,11 +204,11 @@ fm_icon_view_initialize (FMIconView *icon_view) = nautilus_preferences_get_string (nautilus_preferences_get_global_preferences (), NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES); - nautilus_preferences_add_callback (nautilus_preferences_get_global_preferences (), - NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, - text_attribute_names_changed_callback, - icon_view); - + nautilus_preferences_add_string_callback (nautilus_preferences_get_global_preferences (), + NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES, + text_attribute_names_changed_callback, + icon_view); + icon_container = create_icon_container (icon_view); } @@ -1113,7 +1125,6 @@ get_icon_property_callback (NautilusIconContainer *container, static void text_attribute_names_changed_callback (NautilusPreferences *preferences, const char *name, - NautilusPreferencesType type, gconstpointer value, gpointer user_data) @@ -1122,7 +1133,6 @@ text_attribute_names_changed_callback (NautilusPreferences *preferences, g_assert (NAUTILUS_IS_PREFERENCES (preferences)); g_assert (strcmp (name, NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ATTRIBUTE_NAMES) == 0); - g_assert (type == NAUTILUS_PREFERENCE_STRING); g_assert (value != NULL); g_assert (FM_IS_ICON_VIEW (user_data)); diff --git a/src/nautilus-application.c b/src/nautilus-application.c index ed4c46d03..b6780a520 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -255,7 +255,6 @@ nautilus_app_startup(NautilusApp *app, const char *initial_url) NautilusWindow *mainwin; nautilus_navinfo_init(); - nautilus_global_preferences_initialize (); /* Set default configuration */ mainwin = nautilus_app_create_window(app); diff --git a/src/ntl-app.c b/src/ntl-app.c index ed4c46d03..b6780a520 100644 --- a/src/ntl-app.c +++ b/src/ntl-app.c @@ -255,7 +255,6 @@ nautilus_app_startup(NautilusApp *app, const char *initial_url) NautilusWindow *mainwin; nautilus_navinfo_init(); - nautilus_global_preferences_initialize (); /* Set default configuration */ mainwin = nautilus_app_create_window(app); |