Commit ee95ca88 authored by Ramiro Estrugo's avatar Ramiro Estrugo
Browse files

Preferences work. Make preference registration implicit. Update code that

required preferences to be explicitly registered before using them.
parent c34c6f30
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:
......
......@@ -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 ());
}
}
......@@ -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);
......
......@@ -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);
......
......@@ -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 */
......@@ -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);
......
......@@ -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,