Commit 8cef10fd authored by Ramiro Estrugo's avatar Ramiro Estrugo

Once again, back to implicit initialization of preferences stuff. It makes

* components/history/nautilus-history-view.c: (main):
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_get_dialog),
(global_preferences_register_for_ui),
(global_preferences_initialize_if_needed),
(nautilus_global_preferences_shutdown):
* libnautilus-extensions/nautilus-global-preferences.h:
* nautilus-widgets/nautilus-preferences-group.c:
(nautilus_preferences_group_add_item):
* nautilus-widgets/nautilus-preferences-item.c:
(preferences_item_construct), (nautilus_preferences_item_new):
* nautilus-widgets/nautilus-preferences-pane.c:
(nautilus_preferences_pane_add_item_to_nth_group):
* nautilus-widgets/nautilus-preferences.c: (preferences_register),
(set_default_value_if_needed), (preferences_hash_node_lookup),
(preferences_hash_node_lookup_with_registration),
(preferences_gconf_callback), (preferences_initialize_if_needed),
(nautilus_preferences_find_preference),
(nautilus_preferences_set_info),
(nautilus_preferences_enum_add_entry),
(nautilus_preferences_add_boolean_callback),
(nautilus_preferences_add_enum_callback),
(nautilus_preferences_add_callback),
(nautilus_preferences_set_boolean),
(nautilus_preferences_get_boolean),
(nautilus_preferences_set_enum), (nautilus_preferences_get_enum),
(nautilus_preferences_set), (nautilus_preferences_get),
(nautilus_preferences_shutdown):
* nautilus-widgets/nautilus-preferences.h:
* nautilus-widgets/test-nautilus-preferences.c: (main),
(register_global_preferences):
* src/nautilus-main.c: (main):
Once again, back to implicit initialization of preferences stuff.
It makes things simpler.
parent 6c112717
2000-06-02 Ramiro Estrugo <ramiro@eazel.com>
* components/history/nautilus-history-view.c: (main):
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_get_dialog),
(global_preferences_register_for_ui),
(global_preferences_initialize_if_needed),
(nautilus_global_preferences_shutdown):
* libnautilus-extensions/nautilus-global-preferences.h:
* nautilus-widgets/nautilus-preferences-group.c:
(nautilus_preferences_group_add_item):
* nautilus-widgets/nautilus-preferences-item.c:
(preferences_item_construct), (nautilus_preferences_item_new):
* nautilus-widgets/nautilus-preferences-pane.c:
(nautilus_preferences_pane_add_item_to_nth_group):
* nautilus-widgets/nautilus-preferences.c: (preferences_register),
(set_default_value_if_needed), (preferences_hash_node_lookup),
(preferences_hash_node_lookup_with_registration),
(preferences_gconf_callback), (preferences_initialize_if_needed),
(nautilus_preferences_find_preference),
(nautilus_preferences_set_info),
(nautilus_preferences_enum_add_entry),
(nautilus_preferences_add_boolean_callback),
(nautilus_preferences_add_enum_callback),
(nautilus_preferences_add_callback),
(nautilus_preferences_set_boolean),
(nautilus_preferences_get_boolean),
(nautilus_preferences_set_enum), (nautilus_preferences_get_enum),
(nautilus_preferences_set), (nautilus_preferences_get),
(nautilus_preferences_shutdown):
* nautilus-widgets/nautilus-preferences.h:
* nautilus-widgets/test-nautilus-preferences.c: (main),
(register_global_preferences):
* src/nautilus-main.c: (main):
Once again, back to implicit initialization of preferences stuff.
It makes things simpler.
2000-06-02 Ramiro Estrugo <ramiro@eazel.com>
* nautilus-widgets/nautilus-user-level-manager.c:
......
......@@ -29,7 +29,6 @@
#include <libnautilus/libnautilus.h>
#include <libnautilus-extensions/nautilus-bookmark.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-init.h>
#include <libgnomevfs/gnome-vfs-uri.h>
......@@ -265,13 +264,6 @@ int main(int argc, char *argv[])
oaf_popt_options, 0, NULL);
orb = oaf_init (argc, argv);
/* Initialize global preferences. */
nautilus_global_preferences_startup (argc, argv);
/* FIXME bugzilla.eazel.com 672:
* Need better error reporting here if preferences initialization fails.
*/
bonobo_init(orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
gnome_vfs_init ();
......
......@@ -47,8 +47,9 @@ static char * global_preferences_get_sidebar_panel_key (const c
static gboolean global_preferences_is_sidebar_panel_enabled (NautilusViewIdentifier *panel_identifier,
gpointer ignore);
static GList * global_preferences_get_sidebar_panel_view_identifiers (void);
static gboolean global_preferences_close_dialog_callback (GtkWidget *dialog,
static gboolean global_preferences_close_dialog_callback (GtkWidget *dialog,
gpointer user_data);
static void global_preferences_initialize_if_needed (void);
/*
* Private stuff
......@@ -264,7 +265,7 @@ global_preferences_get_dialog (void)
{
static GtkWidget * global_prefs_dialog = NULL;
g_assert (nautilus_preferences_is_initialized ());
global_preferences_initialize_if_needed ();
if (!global_prefs_dialog)
{
......@@ -337,8 +338,6 @@ global_preferences_register_for_ui (void)
{
static gboolean preference_for_ui_registered = FALSE;
g_assert (nautilus_preferences_is_initialized ());
if (preference_for_ui_registered)
return;
......@@ -484,6 +483,29 @@ user_level_changed_callback (GtkObject *user_level_manager,
g_free (home_uri_string);
}
static void
global_preferences_initialize_if_needed (void)
{
static gboolean initialized = FALSE;
if (initialized) {
return;
}
global_preferences_register_for_ui ();
/* Register to find out about user level changes */
gtk_signal_connect (GTK_OBJECT (nautilus_user_level_manager_get ()),
"user_level_changed",
user_level_changed_callback,
NULL);
/* Invoke the callback once to make sure stuff is properly setup */
user_level_changed_callback (NULL, NULL);
initialized = TRUE;
}
/*
* Public functions
*/
......@@ -529,28 +551,3 @@ nautilus_global_preferences_shutdown (void)
nautilus_preferences_shutdown ();
}
void
nautilus_global_preferences_startup (int argc, char **argv)
{
gboolean result;
/* Initialize preferences */
result = nautilus_preferences_initialize (argc, argv);
/* FIXME bugzilla.eazel.com 672:
* Need error reporting if this fails instead of a core dump.
*/
g_assert (result);
global_preferences_register_for_ui ();
/* Register to find out about user level changes */
gtk_signal_connect (GTK_OBJECT (nautilus_user_level_manager_get ()),
"user_level_changed",
user_level_changed_callback,
NULL);
/* Invoke the callback once to make sure stuff is properly setup */
user_level_changed_callback (NULL, NULL);
}
......@@ -73,8 +73,6 @@ enum
#define NAUTILUS_PREFERENCES_SHOW_TEXT_IN_REMOTE_ICONS "/nautilus/preferences/remote_icon_text"
void nautilus_global_preferences_startup (int argc,
char **argv);
void nautilus_global_preferences_shutdown (void);
void nautilus_global_preferences_show_dialog (void);
void nautilus_global_preferences_hide_dialog (void);
......
......@@ -206,8 +206,6 @@ nautilus_preferences_group_add_item (NautilusPreferencesGroup *group,
g_return_val_if_fail (group != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group), NULL);
g_return_val_if_fail (nautilus_preferences_is_initialized (), NULL);
g_return_val_if_fail (preference_name != NULL, NULL);
preference = nautilus_preferences_find_preference (preference_name);
......
......@@ -239,8 +239,6 @@ preferences_item_construct (NautilusPreferencesItem *item,
g_assert (item != NULL);
g_assert (nautilus_preferences_is_initialized ());
g_assert (preference_name != NULL);
g_assert (item_type != PREFERENCES_ITEM_UNDEFINED_ITEM);
......@@ -409,7 +407,6 @@ nautilus_preferences_item_new (const gchar *preference_name,
{
NautilusPreferencesItem * item;
g_return_val_if_fail (nautilus_preferences_is_initialized (), NULL);
g_return_val_if_fail (preference_name != NULL, NULL);
item = gtk_type_new (nautilus_preferences_item_get_type ());
......
......@@ -294,8 +294,6 @@ nautilus_preferences_pane_add_item_to_nth_group (NautilusPreferencesPane *prefs_
g_return_val_if_fail (prefs_pane != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_PREFS_PANE (prefs_pane), NULL);
g_return_val_if_fail (nautilus_preferences_is_initialized (), NULL);
g_return_val_if_fail (preference_name != NULL, NULL);
if (!prefs_pane->details->groups) {
......
......@@ -89,7 +89,6 @@ static void preferences_hash_node_free_func (
/* PreferencesCallbackNode functions */
static PreferencesCallbackNode *preferneces_callback_node_alloc (NautilusPreferencesCallback callback_proc,
gpointer callback_data,
......@@ -107,11 +106,9 @@ static void preferences_hash_node_remove_callback (
gpointer callback_data);
/* Private stuff */
PreferencesHashNode * preferences_hash_node_lookup (const char *name);
PreferencesHashNode * preferences_hash_node_lookup_with_registration (const char *pref_name,
static PreferencesHashNode * preferences_hash_node_lookup (const char *name);
static PreferencesHashNode * preferences_hash_node_lookup_with_registration (const char *pref_name,
NautilusPreferenceType pref_type,
gconstpointer default_value);
static void preferences_register (char *name,
......@@ -123,8 +120,6 @@ static void set_default_value_if_needed (
NautilusPreferenceType type,
gconstpointer default_value);
/* Gconf callbacks */
static void preferences_gconf_callback (GConfClient *client,
guint cnxn_id,
......@@ -132,6 +127,8 @@ static void preferences_gconf_callback (
GConfValue *value,
gboolean is_default,
gpointer user_data);
static gboolean preferences_initialize_if_needed (void);
/**
* preferences_hash_node_alloc
......@@ -444,10 +441,10 @@ preferences_register (char *name,
{
PreferencesHashNode *node;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
g_return_if_fail (description != NULL);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup (name);
......@@ -463,56 +460,6 @@ preferences_register (char *name,
g_assert (node->preference != NULL);
}
/**
* nautilus_preferences_find_preference
*
* Search for a named preference in the given preferences and return it.
* @preferences: The preferences to search
*
* Return value: A referenced pointer to the preference object that corresponds
* to the given preference name. The caller should gtk_object_unref() the return
* value of this function.
**/
NautilusPreference *
nautilus_preferences_find_preference (const char *name)
{
PreferencesHashNode *node;
g_return_val_if_fail (nautilus_preferences_is_initialized (), NULL);
g_return_val_if_fail (name != NULL, NULL);
node = preferences_hash_node_lookup (name);
g_assert (node != NULL);
gtk_object_ref (GTK_OBJECT (node->preference));
return node->preference;
}
void
nautilus_preferences_set_info (const char *name,
const char *description,
NautilusPreferenceType type,
gconstpointer default_value)
{
PreferencesHashNode *node;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
node = preferences_hash_node_lookup_with_registration (name, type, default_value);
g_assert (node != NULL);
g_assert (node->preference != NULL);
if (description) {
nautilus_preference_set_description (node->preference, description);
}
set_default_value_if_needed (name, type, default_value);
}
/**
* set_default_value_if_needed
*
......@@ -535,9 +482,10 @@ set_default_value_if_needed (const char *name,
{
GConfValue *value = NULL;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
preferences_initialize_if_needed ();
/* Find out if the preference exists at all */
value = gconf_client_get_without_default (GLOBAL.gconf_client,
name,
......@@ -574,53 +522,31 @@ set_default_value_if_needed (const char *name,
}
}
void
nautilus_preferences_enum_add_entry (const char *name,
const char *entry_name,
const char *entry_description,
int entry_value)
{
PreferencesHashNode *node;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
node = preferences_hash_node_lookup_with_registration (name, NAUTILUS_PREFERENCE_ENUM, NULL);
g_assert (node != NULL);
g_assert (node->preference != NULL);
g_assert (nautilus_preference_get_preference_type (node->preference) == NAUTILUS_PREFERENCE_ENUM);
nautilus_preference_enum_add_entry (node->preference,
entry_name,
entry_description,
entry_value);
}
PreferencesHashNode *
static PreferencesHashNode *
preferences_hash_node_lookup (const char *name)
{
gpointer hash_value;
g_assert (nautilus_preferences_is_initialized ());
g_assert (name != NULL);
preferences_initialize_if_needed ();
hash_value = g_hash_table_lookup (GLOBAL.preference_table, (gconstpointer) name);
return (PreferencesHashNode *) hash_value;
}
PreferencesHashNode *
static PreferencesHashNode *
preferences_hash_node_lookup_with_registration (const char *name,
NautilusPreferenceType type,
gconstpointer default_value)
{
PreferencesHashNode * node;
g_assert (nautilus_preferences_is_initialized ());
g_assert (name != NULL);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup (name);
if (!node) {
......@@ -650,9 +576,10 @@ preferences_gconf_callback (GConfClient *client,
NautilusPreference *expected_preference;
char *expected_key;
g_assert (nautilus_preferences_is_initialized ());
g_assert (key != NULL);
preferences_initialize_if_needed ();
g_assert (user_data != NULL);
g_assert (NAUTILUS_IS_PREFERENCE (user_data));
......@@ -705,6 +632,133 @@ preferences_gconf_callback (GConfClient *client,
g_free (expected_key);
}
static gboolean
preferences_initialize_if_needed (void)
{
if (GLOBAL.preference_table != NULL && GLOBAL.gconf_client != NULL) {
return TRUE;
}
if (!gconf_is_initialized ()) {
GConfError *error = NULL;
char *argv[] = { "nautilus", NULL };
if (!gconf_init (1, argv, &error)) {
g_assert (error != NULL);
/* FIXME bugzilla.eazel.com 672: Need better error reporting here */
g_warning ("GConf init failed:\n %s", error->str);
gconf_error_destroy (error);
error = NULL;
return FALSE;
}
}
g_assert (GLOBAL.preference_table == NULL);
g_assert (GLOBAL.gconf_client == NULL);
GLOBAL.preference_table = g_hash_table_new (g_str_hash, g_str_equal);
g_assert (GLOBAL.preference_table != NULL);
GLOBAL.gconf_client = gconf_client_new ();
/* Let gconf know about ~/.gconf/nautilus */
gconf_client_add_dir (GLOBAL.gconf_client,
PREFERENCES_GCONF_PATH,
GCONF_CLIENT_PRELOAD_RECURSIVE,
NULL);
g_assert (GLOBAL.gconf_client != NULL);
return TRUE;
}
/*
* Public functions
*/
/**
* nautilus_preferences_find_preference
*
* Search for a named preference in the given preferences and return it.
* @preferences: The preferences to search
*
* Return value: A referenced pointer to the preference object that corresponds
* to the given preference name. The caller should gtk_object_unref() the return
* value of this function.
**/
NautilusPreference *
nautilus_preferences_find_preference (const char *name)
{
PreferencesHashNode *node;
g_return_val_if_fail (name != NULL, NULL);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup (name);
g_assert (node != NULL);
gtk_object_ref (GTK_OBJECT (node->preference));
return node->preference;
}
void
nautilus_preferences_set_info (const char *name,
const char *description,
NautilusPreferenceType type,
gconstpointer default_value)
{
PreferencesHashNode *node;
g_return_if_fail (name != NULL);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup_with_registration (name, type, default_value);
g_assert (node != NULL);
g_assert (node->preference != NULL);
if (description) {
nautilus_preference_set_description (node->preference, description);
}
set_default_value_if_needed (name, type, default_value);
}
void
nautilus_preferences_enum_add_entry (const char *name,
const char *entry_name,
const char *entry_description,
int entry_value)
{
PreferencesHashNode *node;
g_return_if_fail (name != NULL);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup_with_registration (name, NAUTILUS_PREFERENCE_ENUM, NULL);
g_assert (node != NULL);
g_assert (node->preference != NULL);
g_assert (nautilus_preference_get_preference_type (node->preference) == NAUTILUS_PREFERENCE_ENUM);
nautilus_preference_enum_add_entry (node->preference,
entry_name,
entry_description,
entry_value);
}
gboolean
nautilus_preferences_add_boolean_callback (const char *name,
NautilusPreferencesCallback callback_proc,
......@@ -712,10 +766,11 @@ nautilus_preferences_add_boolean_callback (const char *name,
{
PreferencesHashNode *node;
g_return_val_if_fail (nautilus_preferences_is_initialized (), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (callback_proc != NULL, FALSE);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup_with_registration (name, NAUTILUS_PREFERENCE_BOOLEAN, NULL);
if (node == NULL) {
......@@ -735,10 +790,11 @@ nautilus_preferences_add_enum_callback (const char *name,
{
PreferencesHashNode *node;
g_return_val_if_fail (nautilus_preferences_is_initialized (), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (callback_proc != NULL, FALSE);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup_with_registration (name, NAUTILUS_PREFERENCE_ENUM, NULL);
if (node == NULL) {
......@@ -758,10 +814,11 @@ nautilus_preferences_add_callback (const char *name,
{
PreferencesHashNode *node;
g_return_val_if_fail (nautilus_preferences_is_initialized (), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (callback_proc != NULL, FALSE);
preferences_initialize_if_needed ();
node = preferences_hash_node_lookup_with_registration (name, NAUTILUS_PREFERENCE_STRING, NULL);
if (node == NULL) {
......@@ -801,9 +858,10 @@ nautilus_preferences_set_boolean (const char *name,
{
gboolean gconf_result;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
preferences_initialize_if_needed ();
/* Make sure the preference value is indeed different */
if (gconf_client_get_bool (GLOBAL.gconf_client, name, NULL) == boolean_value) {
return;
......@@ -820,9 +878,10 @@ gboolean
nautilus_preferences_get_boolean (const char *name,
gboolean default_value)
{
g_return_val_if_fail (nautilus_preferences_is_initialized (), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
preferences_initialize_if_needed ();
return gconf_client_get_bool (GLOBAL.gconf_client, name, NULL);
}
......@@ -832,9 +891,10 @@ nautilus_preferences_set_enum (const char *name,
{
gboolean gconf_result;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
preferences_initialize_if_needed ();
/* Make sure the preference value is indeed different */
if (gconf_client_get_int (GLOBAL.gconf_client, name, NULL) == enum_value) {
return;
......@@ -851,9 +911,10 @@ int
nautilus_preferences_get_enum (const char *name,
int default_value)
{
g_return_val_if_fail (nautilus_preferences_is_initialized (), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
preferences_initialize_if_needed ();
return gconf_client_get_int (GLOBAL.gconf_client, name, NULL);
}
......@@ -863,9 +924,10 @@ nautilus_preferences_set (const char *name,
{
gboolean gconf_result;
g_return_if_fail (nautilus_preferences_is_initialized ());
g_return_if_fail (name != NULL);
preferences_initialize_if_needed ();
/* Make sure the preference value is indeed different */
if (value) {
char *current_value = gconf_client_get_string (GLOBAL.gconf_client, name, NULL);
......@@ -893,9 +955,10 @@ nautilus_preferences_get (const char *name,
{
gchar *value = NULL;
g_return_val_if_fail (nautilus_preferences_is_initialized (), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
preferences_initialize_if_needed ();
value = gconf_client_get_string (GLOBAL.gconf_client, name, NULL);
if (!value && default_value) {
......@@ -905,55 +968,13 @@ nautilus_preferences_get (const char *name,
return value;
}
gboolean
nautilus_preferences_initialize (int argc, char **argv)
{
GConfError *error = NULL;
if (!gconf_init (argc, argv, &error)) {
g_assert (error != NULL);
/* FIXME bugzilla.eazel.com 672: Need better error reporting here */
g_warning ("GConf init failed:\n %s", error->str);
gconf_error_destroy (error);
error = NULL;
return FALSE;
}
g_assert (GLOBAL.preference_table == NULL);
g_assert (GLOBAL.gconf_client == NULL);
GLOBAL.preference_table = g_hash_table_new (g_str_hash, g_str_equal);
g_assert (GLOBAL.preference_table != NULL);
GLOBAL.gconf_client = gconf_client_new ();
/* Let gconf know about ~/.gconf/nautilus */
gconf_client_add_dir (GLOBAL.gconf_client,
PREFERENCES_GCONF_PATH,
GCONF_CLIENT_PRELOAD_RECURSIVE,
NULL);
g_assert (GLOBAL.gconf_client != NULL);
return TRUE;
}
gboolean
nautilus_preferences_is_initialized (void)
{
return ((GLOBAL.preference_table != NULL) && (GLOBAL.gconf_client != NULL));
}
gboolean
void
nautilus_preferences_shutdown (void)
{
g_assert (nautilus_preferences_is_initialized ());