mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-11-05 16:04:31 +00:00
properly handle gconf error, and init it to NULL first. This will avoid
Mon Aug 21 23:35:18 2000 George Lebl <jirka@5z.com> * components/html/ntl-web-browser.c (main): properly handle gconf error, and init it to NULL first. This will avoid crashes on error. * libnautilus-extentions/Makefile.am, libnautilus-extentions/nautilus-preferences-private.h, libnautilus-extentions/nautilus-preferences.c: Add a nautilus_preferences_handle_error functions for use in nautilus-preferences and user level manager to handle and reset GConf exceptions. The reason a new "private" header was added is to preserve the gconf encapsulation outside libnautilus-extentions, plus it's only useful there. * libnautilus-extentions/nautilus-preferences.c (preferences_hash_node_add_callback) (preferences_hash_node_remove_callback) (preferences_gconf_callback) (preferences_initialize_if_needed) (nautilus_preferences_set_boolean) (nautilus_preferences_get_boolean) (nautilus_preferences_set_string_list) (nautilus_preferences_get_string_list) (nautilus_preferences_set_enum) (nautilus_preferences_get_enum) (nautilus_preferences_set) (nautilus_preferences_get) libnautilus-extensions/nautilus-user-level-manager.c (user_level_manager_new) (user_level_manager_ensure_global_manager) (nautilus_user_level_manager_set_user_level) (nautilus_user_level_manager_get_user_level_as_string) (nautilus_user_level_manager_set_default_value_if_needed) (nautilus_user_level_manager_compare_preference_between_user_levels): Handle GConf exceptions. Try to revert to sane behaviour on errors, such as using defaults. Remove all the asserts for conditions that arise from gconf errors. Fixes bug 672
This commit is contained in:
parent
7295589544
commit
dc605a304c
10 changed files with 497 additions and 173 deletions
34
ChangeLog
34
ChangeLog
|
@ -1,3 +1,37 @@
|
|||
Mon Aug 21 23:35:18 2000 George Lebl <jirka@5z.com>
|
||||
|
||||
* components/html/ntl-web-browser.c (main): properly handle
|
||||
gconf error, and init it to NULL first. This will avoid
|
||||
crashes on error.
|
||||
|
||||
* libnautilus-extentions/Makefile.am,
|
||||
libnautilus-extentions/nautilus-preferences-private.h,
|
||||
libnautilus-extentions/nautilus-preferences.c: Add a
|
||||
nautilus_preferences_handle_error functions for use in
|
||||
nautilus-preferences and user level manager to handle and reset
|
||||
GConf exceptions. The reason a new "private" header was added is
|
||||
to preserve the gconf encapsulation outside libnautilus-extentions,
|
||||
plus it's only useful there.
|
||||
|
||||
* libnautilus-extentions/nautilus-preferences.c
|
||||
(preferences_hash_node_add_callback)
|
||||
(preferences_hash_node_remove_callback)
|
||||
(preferences_gconf_callback) (preferences_initialize_if_needed)
|
||||
(nautilus_preferences_set_boolean) (nautilus_preferences_get_boolean)
|
||||
(nautilus_preferences_set_string_list)
|
||||
(nautilus_preferences_get_string_list)
|
||||
(nautilus_preferences_set_enum) (nautilus_preferences_get_enum)
|
||||
(nautilus_preferences_set) (nautilus_preferences_get)
|
||||
libnautilus-extensions/nautilus-user-level-manager.c
|
||||
(user_level_manager_new) (user_level_manager_ensure_global_manager)
|
||||
(nautilus_user_level_manager_set_user_level)
|
||||
(nautilus_user_level_manager_get_user_level_as_string)
|
||||
(nautilus_user_level_manager_set_default_value_if_needed)
|
||||
(nautilus_user_level_manager_compare_preference_between_user_levels):
|
||||
Handle GConf exceptions. Try to revert to sane behaviour on
|
||||
errors, such as using defaults. Remove all the asserts for
|
||||
conditions that arise from gconf errors. Fixes bug 672
|
||||
|
||||
2000-08-21 Darin Adler <darin@eazel.com>
|
||||
|
||||
Finished task 571 (Make a Trash "virtual directory" with trash
|
||||
|
|
|
@ -595,7 +595,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
BonoboGenericFactory *factory;
|
||||
CORBA_ORB orb;
|
||||
GConfError *error;
|
||||
GConfError *error = NULL;
|
||||
|
||||
if (g_getenv("NAUTILUS_DEBUG") != NULL)
|
||||
nautilus_make_warnings_and_criticals_stop_in_debugger
|
||||
|
@ -616,6 +616,12 @@ int main(int argc, char *argv[])
|
|||
orb = oaf_init (argc, argv);
|
||||
/* Init the GConf library.*/
|
||||
gconf_init (argc, argv, &error);
|
||||
if (error != NULL) {
|
||||
g_warning(_("GConf init failed:\n %s"), error->str);
|
||||
gconf_error_destroy(error);
|
||||
error = NULL;
|
||||
}
|
||||
|
||||
gnome_vfs_init();
|
||||
gdk_rgb_init();
|
||||
glibwww_init("ntl-web-browser", _VERSION);
|
||||
|
|
|
@ -184,6 +184,7 @@ noinst_HEADERS = \
|
|||
nautilus-preferences-item.h \
|
||||
nautilus-preferences-pane.h \
|
||||
nautilus-preferences.h \
|
||||
nautilus-preferences-private.h \
|
||||
nautilus-program-chooser.h \
|
||||
nautilus-program-choosing.h \
|
||||
nautilus-radio-button-group.h \
|
||||
|
|
39
libnautilus-extensions/nautilus-preferences-private.h
Normal file
39
libnautilus-extensions/nautilus-preferences-private.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
|
||||
|
||||
/* nautilus-preferences-private.h - Private preferences functions
|
||||
|
||||
Copyright (C) 2000 Eazel, Inc.
|
||||
|
||||
The Gnome Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
Authors: George Lebl <jirka@5z.com>
|
||||
*/
|
||||
|
||||
#ifndef NAUTILUS_PREFERENCES_PRIVATE_H
|
||||
#define NAUTILUS_PREFERENCES_PRIVATE_H
|
||||
|
||||
#include <gconf/gconf.h>
|
||||
#include <gconf/gconf-client.h>
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
/* returns FALSE if no error, and TRUE if an error was handeled */
|
||||
gboolean nautilus_preferences_handle_error (GConfError **error);
|
||||
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
#endif /* NAUTILUS_PREFERENCES_PRIVATE_H */
|
|
@ -26,6 +26,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "nautilus-preferences.h"
|
||||
#include "nautilus-preferences-private.h"
|
||||
#include "nautilus-user-level-manager.h"
|
||||
|
||||
#include "nautilus-gtk-macros.h"
|
||||
|
@ -36,6 +37,11 @@
|
|||
#include <gconf/gconf-client.h>
|
||||
|
||||
#include <gtk/gtksignal.h>
|
||||
|
||||
#include <libgnome/gnome-defs.h>
|
||||
#include <libgnome/gnome-i18n.h>
|
||||
#include <libgnomeui/gnome-dialog.h>
|
||||
#include <libgnomeui/gnome-dialog-util.h>
|
||||
|
||||
static const char PREFERENCES_GCONF_PATH[] = "/apps/nautilus";
|
||||
|
||||
|
@ -228,6 +234,8 @@ preferences_hash_node_add_callback (PreferencesHashNode *node,
|
|||
{
|
||||
if (node->gconf_connections[i] == 0) {
|
||||
char *key;
|
||||
GConfError *error = NULL;
|
||||
|
||||
g_assert (node->name != NULL);
|
||||
g_assert (node->gconf_connections[i] == 0);
|
||||
|
||||
|
@ -239,7 +247,10 @@ preferences_hash_node_add_callback (PreferencesHashNode *node,
|
|||
preferences_gconf_callback,
|
||||
node,
|
||||
NULL,
|
||||
NULL);
|
||||
&error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
node->gconf_connections[i] = 0;
|
||||
}
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -294,10 +305,12 @@ preferences_hash_node_remove_callback (PreferencesHashNode *node,
|
|||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
g_assert (node->gconf_connections[i] != 0);
|
||||
|
||||
gconf_client_notify_remove (GLOBAL.gconf_client,
|
||||
node->gconf_connections[i]);
|
||||
/* we don't assert here. if we had trouble with gconf
|
||||
* notify addition, this would be 0 */
|
||||
if (node->gconf_connections[i] != 0) {
|
||||
gconf_client_notify_remove (GLOBAL.gconf_client,
|
||||
node->gconf_connections[i]);
|
||||
}
|
||||
|
||||
node->gconf_connections[i] = 0;
|
||||
}
|
||||
|
@ -507,6 +520,7 @@ preferences_gconf_callback (GConfClient *client,
|
|||
PreferencesHashNode *node;
|
||||
const char *expected_name;
|
||||
char *expected_key;
|
||||
GConfError *error = NULL;
|
||||
|
||||
g_return_if_fail (user_data != NULL);
|
||||
|
||||
|
@ -559,7 +573,8 @@ preferences_gconf_callback (GConfClient *client,
|
|||
|
||||
g_assert (node != NULL);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
/* Invoke callbacks for this node */
|
||||
if (node->callback_list) {
|
||||
|
@ -589,23 +604,19 @@ user_level_changed_callback (GtkObject *user_level_manager,
|
|||
static gboolean
|
||||
preferences_initialize_if_needed (void)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
|
||||
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;
|
||||
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -620,13 +631,14 @@ preferences_initialize_if_needed (void)
|
|||
|
||||
GLOBAL.gconf_client = gconf_client_get_default ();
|
||||
|
||||
g_assert (GLOBAL.gconf_client != NULL);
|
||||
|
||||
/* 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);
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
GLOBAL.old_user_level = nautilus_user_level_manager_get_user_level ();
|
||||
|
||||
|
@ -692,9 +704,9 @@ void
|
|||
nautilus_preferences_set_boolean (const char *name,
|
||||
gboolean boolean_value)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
char *key;
|
||||
|
||||
gboolean gconf_result;
|
||||
gboolean old_value;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
|
@ -704,16 +716,19 @@ nautilus_preferences_set_boolean (const char *name,
|
|||
g_assert (key != NULL);
|
||||
|
||||
/* Make sure the preference value is indeed different */
|
||||
if (gconf_client_get_bool (GLOBAL.gconf_client, key, NULL) == boolean_value) {
|
||||
old_value = gconf_client_get_bool (GLOBAL.gconf_client, key, &error);
|
||||
if (error == NULL
|
||||
&& old_value == boolean_value) {
|
||||
g_free (key);
|
||||
return;
|
||||
}
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_result = gconf_client_set_bool (GLOBAL.gconf_client, key, boolean_value, NULL);
|
||||
gconf_client_set_bool (GLOBAL.gconf_client, key, boolean_value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -722,7 +737,8 @@ gboolean
|
|||
nautilus_preferences_get_boolean (const char *name,
|
||||
gboolean default_value)
|
||||
{
|
||||
gboolean result;
|
||||
GConfError *error = NULL;
|
||||
gboolean result;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
@ -732,7 +748,10 @@ nautilus_preferences_get_boolean (const char *name,
|
|||
key = nautilus_user_level_manager_make_current_gconf_key (name);
|
||||
g_assert (key != NULL);
|
||||
|
||||
result = gconf_client_get_bool (GLOBAL.gconf_client, key, NULL);
|
||||
result = gconf_client_get_bool (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
result = default_value;
|
||||
}
|
||||
|
||||
g_free (key);
|
||||
|
||||
|
@ -744,10 +763,9 @@ void
|
|||
nautilus_preferences_set_string_list (const char *name,
|
||||
GSList *string_list_value)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
char *key;
|
||||
|
||||
gboolean gconf_result;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
preferences_initialize_if_needed ();
|
||||
|
@ -758,18 +776,14 @@ nautilus_preferences_set_string_list (const char *name,
|
|||
/* FIXME: Make sure the preference value is indeed different
|
||||
before setting, like the other functions */
|
||||
|
||||
/* FIXME: we are passing NULL for the last argument and thus
|
||||
missing out on any opportunity to handle errors. */
|
||||
gconf_client_set_list (GLOBAL.gconf_client, key,
|
||||
GCONF_VALUE_STRING,
|
||||
string_list_value,
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_result = gconf_client_set_list (GLOBAL.gconf_client, key,
|
||||
GCONF_VALUE_STRING,
|
||||
string_list_value,
|
||||
NULL);
|
||||
|
||||
/* FIXME: wrong to assert this, what if there is an error? */
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -777,8 +791,9 @@ nautilus_preferences_set_string_list (const char *name,
|
|||
GSList *
|
||||
nautilus_preferences_get_string_list (const char *name)
|
||||
{
|
||||
GSList *result;
|
||||
char *key;
|
||||
GConfError *error = NULL;
|
||||
GSList *result;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
||||
|
@ -788,7 +803,8 @@ nautilus_preferences_get_string_list (const char *name)
|
|||
g_assert (key != NULL);
|
||||
|
||||
result = gconf_client_get_list (GLOBAL.gconf_client, key,
|
||||
GCONF_VALUE_STRING, NULL);
|
||||
GCONF_VALUE_STRING, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
|
||||
|
@ -800,7 +816,8 @@ void
|
|||
nautilus_preferences_set_enum (const char *name,
|
||||
int enum_value)
|
||||
{
|
||||
gboolean gconf_result;
|
||||
GConfError *error = NULL;
|
||||
int old_value;
|
||||
char *key;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
@ -811,16 +828,19 @@ nautilus_preferences_set_enum (const char *name,
|
|||
g_assert (key != NULL);
|
||||
|
||||
/* Make sure the preference value is indeed different */
|
||||
if (gconf_client_get_int (GLOBAL.gconf_client, key, NULL) == enum_value) {
|
||||
old_value = gconf_client_get_int (GLOBAL.gconf_client, key, &error);
|
||||
if (error == NULL
|
||||
&& old_value == enum_value) {
|
||||
g_free (key);
|
||||
return;
|
||||
}
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_result = gconf_client_set_int (GLOBAL.gconf_client, key, enum_value, NULL);
|
||||
gconf_client_set_int (GLOBAL.gconf_client, key, enum_value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -829,7 +849,8 @@ int
|
|||
nautilus_preferences_get_enum (const char *name,
|
||||
int default_value)
|
||||
{
|
||||
int result;
|
||||
GConfError *error = NULL;
|
||||
int result;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
@ -839,7 +860,10 @@ nautilus_preferences_get_enum (const char *name,
|
|||
key = nautilus_user_level_manager_make_current_gconf_key (name);
|
||||
g_assert (key != NULL);
|
||||
|
||||
result = gconf_client_get_int (GLOBAL.gconf_client, key, NULL);
|
||||
result = gconf_client_get_int (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
result = default_value;
|
||||
}
|
||||
|
||||
g_free (key);
|
||||
|
||||
|
@ -850,7 +874,7 @@ void
|
|||
nautilus_preferences_set (const char *name,
|
||||
const char *value)
|
||||
{
|
||||
gboolean gconf_result;
|
||||
GConfError *error = NULL;
|
||||
char *key;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
@ -862,8 +886,15 @@ nautilus_preferences_set (const char *name,
|
|||
|
||||
/* Make sure the preference value is indeed different */
|
||||
if (value) {
|
||||
char *current_value = gconf_client_get_string (GLOBAL.gconf_client, key, NULL);
|
||||
int result = nautilus_strcmp (current_value, value);
|
||||
char *current_value;
|
||||
int result;
|
||||
|
||||
current_value = gconf_client_get_string (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
result = ! 0;
|
||||
} else {
|
||||
result = nautilus_strcmp (current_value, value);
|
||||
}
|
||||
|
||||
if (current_value) {
|
||||
g_free (current_value);
|
||||
|
@ -875,11 +906,11 @@ nautilus_preferences_set (const char *name,
|
|||
}
|
||||
}
|
||||
|
||||
gconf_result = gconf_client_set_string (GLOBAL.gconf_client, key, value, NULL);
|
||||
gconf_client_set_string (GLOBAL.gconf_client, key, value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -888,7 +919,8 @@ char *
|
|||
nautilus_preferences_get (const char *name,
|
||||
const char *default_value)
|
||||
{
|
||||
gchar *value = NULL;
|
||||
GConfError *error = NULL;
|
||||
gchar *value = NULL;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
@ -898,7 +930,12 @@ nautilus_preferences_get (const char *name,
|
|||
key = nautilus_user_level_manager_make_current_gconf_key (name);
|
||||
g_assert (key != NULL);
|
||||
|
||||
value = gconf_client_get_string (GLOBAL.gconf_client, key, NULL);
|
||||
value = gconf_client_get_string (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
/* note: g_free and g_strdup handle NULL correctly */
|
||||
g_free (value);
|
||||
value = g_strdup (default_value);
|
||||
}
|
||||
|
||||
if (!value && default_value) {
|
||||
value = g_strdup (default_value);
|
||||
|
@ -938,3 +975,33 @@ nautilus_preferences_shutdown (void)
|
|||
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_preferences_handle_error (GConfError **error)
|
||||
{
|
||||
static gboolean shown_dialog = FALSE;
|
||||
|
||||
g_return_val_if_fail (error != NULL, FALSE);
|
||||
|
||||
if (*error != NULL) {
|
||||
g_warning (_("GConf error:\n %s"), (*error)->str);
|
||||
if ( ! shown_dialog) {
|
||||
char *message;
|
||||
GtkWidget *dialog;
|
||||
|
||||
shown_dialog = TRUE;
|
||||
|
||||
message = g_strdup_printf (_("GConf error:\n %s\n"
|
||||
"All further errors shown "
|
||||
"only on terminal"),
|
||||
(*error)->str);
|
||||
|
||||
dialog = gnome_error_dialog (message);
|
||||
}
|
||||
gconf_error_destroy(*error);
|
||||
*error = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include "nautilus-gtk-macros.h"
|
||||
#include "nautilus-glib-extensions.h"
|
||||
|
||||
#include "nautilus-preferences.h"
|
||||
#include "nautilus-preferences-private.h"
|
||||
|
||||
#include <gtk/gtksignal.h>
|
||||
|
||||
#include <gconf/gconf.h>
|
||||
|
@ -105,22 +108,17 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusUserLevelManager, nautilus_user_level
|
|||
static NautilusUserLevelManager *
|
||||
user_level_manager_new (void)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
NautilusUserLevelManager *manager;
|
||||
guint i;
|
||||
|
||||
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;
|
||||
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -134,7 +132,8 @@ user_level_manager_new (void)
|
|||
gconf_client_add_dir (manager->gconf_client,
|
||||
USER_LEVEL_PATH,
|
||||
GCONF_CLIENT_PRELOAD_RECURSIVE,
|
||||
NULL);
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
manager->num_user_levels = DEFAULT_NUM_USER_LEVELS;
|
||||
manager->user_level_names = nautilus_string_list_new (TRUE);
|
||||
|
@ -153,7 +152,8 @@ user_level_manager_new (void)
|
|||
gconf_user_level_changed_callback,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
@ -224,21 +224,30 @@ user_level_manager_ensure_global_manager (void)
|
|||
static void
|
||||
user_level_set_default_if_needed (NautilusUserLevelManager *manager)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
GConfValue *value;
|
||||
|
||||
g_assert (manager != NULL);
|
||||
g_assert (manager->gconf_client != NULL);
|
||||
|
||||
value = gconf_client_get_without_default (manager->gconf_client, USER_LEVEL_KEY, NULL);
|
||||
value = gconf_client_get_without_default (manager->gconf_client, USER_LEVEL_KEY, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value != NULL) {
|
||||
gconf_value_destroy (value);
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
value = gconf_value_new (GCONF_VALUE_STRING);
|
||||
|
||||
gconf_value_set_string (value, DEFAULT_USER_LEVEL_NAMES[DEFAULT_USER_LEVEL]);
|
||||
|
||||
gconf_client_set (manager->gconf_client, USER_LEVEL_KEY, value, NULL);
|
||||
gconf_client_set (manager->gconf_client, USER_LEVEL_KEY, value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_client_suggest_sync (manager->gconf_client, NULL);
|
||||
gconf_client_suggest_sync (manager->gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
}
|
||||
|
||||
g_assert (value != NULL);
|
||||
|
@ -274,9 +283,9 @@ nautilus_user_level_manager_get (void)
|
|||
void
|
||||
nautilus_user_level_manager_set_user_level (guint user_level)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
char *user_level_string;
|
||||
gboolean result;
|
||||
guint old_user_level;
|
||||
|
||||
g_return_if_fail (user_level < manager->num_user_levels);
|
||||
|
@ -292,14 +301,14 @@ nautilus_user_level_manager_set_user_level (guint user_level)
|
|||
|
||||
g_assert (user_level_string != NULL);
|
||||
|
||||
result = gconf_client_set_string (manager->gconf_client,
|
||||
USER_LEVEL_KEY,
|
||||
user_level_string,
|
||||
NULL);
|
||||
gconf_client_set_string (manager->gconf_client,
|
||||
USER_LEVEL_KEY,
|
||||
user_level_string,
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (result);
|
||||
|
||||
gconf_client_suggest_sync (manager->gconf_client, NULL);
|
||||
gconf_client_suggest_sync (manager->gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
}
|
||||
|
||||
guint
|
||||
|
@ -384,12 +393,17 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
|
|||
char *
|
||||
nautilus_user_level_manager_get_user_level_as_string (void)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
char *user_level_string;
|
||||
char *user_level_string = NULL;
|
||||
|
||||
g_assert (manager->gconf_client != NULL);
|
||||
|
||||
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
|
||||
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
g_free (user_level_string);
|
||||
user_level_string = NULL;
|
||||
}
|
||||
|
||||
if (!user_level_string)
|
||||
user_level_string = g_strdup ("novice");
|
||||
|
@ -420,6 +434,7 @@ nautilus_user_level_manager_set_default_value_if_needed (const char *preference
|
|||
gconstpointer default_value)
|
||||
{
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
GConfError *error = NULL;
|
||||
GConfValue *value = NULL;
|
||||
char *key;
|
||||
|
||||
|
@ -429,7 +444,13 @@ nautilus_user_level_manager_set_default_value_if_needed (const char *preference
|
|||
g_assert (key != NULL);
|
||||
|
||||
/* Find out if the preference exists at all */
|
||||
value = gconf_client_get_without_default (manager->gconf_client, key, NULL);
|
||||
value = gconf_client_get_without_default (manager->gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value != NULL) {
|
||||
gconf_value_destroy (value);
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* The value does not exist, so create one */
|
||||
if (!value) {
|
||||
|
@ -453,7 +474,8 @@ nautilus_user_level_manager_set_default_value_if_needed (const char *preference
|
|||
}
|
||||
|
||||
if (value) {
|
||||
gconf_client_set (manager->gconf_client, key, value, NULL);
|
||||
gconf_client_set (manager->gconf_client, key, value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,6 +497,7 @@ nautilus_user_level_manager_compare_preference_between_user_levels (const char *
|
|||
char *key_b;
|
||||
GConfValue *value_a;
|
||||
GConfValue *value_b;
|
||||
GConfError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (preference_name != NULL, FALSE);
|
||||
|
||||
|
@ -484,8 +507,20 @@ nautilus_user_level_manager_compare_preference_between_user_levels (const char *
|
|||
key_b = nautilus_user_level_manager_make_gconf_key (preference_name, user_level_b);
|
||||
g_assert (key_b != NULL);
|
||||
|
||||
value_a = gconf_client_get (manager->gconf_client, key_a, NULL);
|
||||
value_b = gconf_client_get (manager->gconf_client, key_b, NULL);
|
||||
value_a = gconf_client_get (manager->gconf_client, key_a, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value_a != NULL) {
|
||||
gconf_value_destroy (value_a);
|
||||
value_a = NULL;
|
||||
}
|
||||
}
|
||||
value_b = gconf_client_get (manager->gconf_client, key_b, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value_b != NULL) {
|
||||
gconf_value_destroy (value_b);
|
||||
value_b = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (key_a);
|
||||
g_free (key_b);
|
||||
|
|
|
@ -184,6 +184,7 @@ noinst_HEADERS = \
|
|||
nautilus-preferences-item.h \
|
||||
nautilus-preferences-pane.h \
|
||||
nautilus-preferences.h \
|
||||
nautilus-preferences-private.h \
|
||||
nautilus-program-chooser.h \
|
||||
nautilus-program-choosing.h \
|
||||
nautilus-radio-button-group.h \
|
||||
|
|
39
libnautilus-private/nautilus-preferences-private.h
Normal file
39
libnautilus-private/nautilus-preferences-private.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
|
||||
|
||||
/* nautilus-preferences-private.h - Private preferences functions
|
||||
|
||||
Copyright (C) 2000 Eazel, Inc.
|
||||
|
||||
The Gnome Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
Authors: George Lebl <jirka@5z.com>
|
||||
*/
|
||||
|
||||
#ifndef NAUTILUS_PREFERENCES_PRIVATE_H
|
||||
#define NAUTILUS_PREFERENCES_PRIVATE_H
|
||||
|
||||
#include <gconf/gconf.h>
|
||||
#include <gconf/gconf-client.h>
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
/* returns FALSE if no error, and TRUE if an error was handeled */
|
||||
gboolean nautilus_preferences_handle_error (GConfError **error);
|
||||
|
||||
|
||||
BEGIN_GNOME_DECLS
|
||||
|
||||
#endif /* NAUTILUS_PREFERENCES_PRIVATE_H */
|
|
@ -26,6 +26,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "nautilus-preferences.h"
|
||||
#include "nautilus-preferences-private.h"
|
||||
#include "nautilus-user-level-manager.h"
|
||||
|
||||
#include "nautilus-gtk-macros.h"
|
||||
|
@ -36,6 +37,11 @@
|
|||
#include <gconf/gconf-client.h>
|
||||
|
||||
#include <gtk/gtksignal.h>
|
||||
|
||||
#include <libgnome/gnome-defs.h>
|
||||
#include <libgnome/gnome-i18n.h>
|
||||
#include <libgnomeui/gnome-dialog.h>
|
||||
#include <libgnomeui/gnome-dialog-util.h>
|
||||
|
||||
static const char PREFERENCES_GCONF_PATH[] = "/apps/nautilus";
|
||||
|
||||
|
@ -228,6 +234,8 @@ preferences_hash_node_add_callback (PreferencesHashNode *node,
|
|||
{
|
||||
if (node->gconf_connections[i] == 0) {
|
||||
char *key;
|
||||
GConfError *error = NULL;
|
||||
|
||||
g_assert (node->name != NULL);
|
||||
g_assert (node->gconf_connections[i] == 0);
|
||||
|
||||
|
@ -239,7 +247,10 @@ preferences_hash_node_add_callback (PreferencesHashNode *node,
|
|||
preferences_gconf_callback,
|
||||
node,
|
||||
NULL,
|
||||
NULL);
|
||||
&error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
node->gconf_connections[i] = 0;
|
||||
}
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -294,10 +305,12 @@ preferences_hash_node_remove_callback (PreferencesHashNode *node,
|
|||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
g_assert (node->gconf_connections[i] != 0);
|
||||
|
||||
gconf_client_notify_remove (GLOBAL.gconf_client,
|
||||
node->gconf_connections[i]);
|
||||
/* we don't assert here. if we had trouble with gconf
|
||||
* notify addition, this would be 0 */
|
||||
if (node->gconf_connections[i] != 0) {
|
||||
gconf_client_notify_remove (GLOBAL.gconf_client,
|
||||
node->gconf_connections[i]);
|
||||
}
|
||||
|
||||
node->gconf_connections[i] = 0;
|
||||
}
|
||||
|
@ -507,6 +520,7 @@ preferences_gconf_callback (GConfClient *client,
|
|||
PreferencesHashNode *node;
|
||||
const char *expected_name;
|
||||
char *expected_key;
|
||||
GConfError *error = NULL;
|
||||
|
||||
g_return_if_fail (user_data != NULL);
|
||||
|
||||
|
@ -559,7 +573,8 @@ preferences_gconf_callback (GConfClient *client,
|
|||
|
||||
g_assert (node != NULL);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
/* Invoke callbacks for this node */
|
||||
if (node->callback_list) {
|
||||
|
@ -589,23 +604,19 @@ user_level_changed_callback (GtkObject *user_level_manager,
|
|||
static gboolean
|
||||
preferences_initialize_if_needed (void)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
|
||||
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;
|
||||
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -620,13 +631,14 @@ preferences_initialize_if_needed (void)
|
|||
|
||||
GLOBAL.gconf_client = gconf_client_get_default ();
|
||||
|
||||
g_assert (GLOBAL.gconf_client != NULL);
|
||||
|
||||
/* 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);
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
GLOBAL.old_user_level = nautilus_user_level_manager_get_user_level ();
|
||||
|
||||
|
@ -692,9 +704,9 @@ void
|
|||
nautilus_preferences_set_boolean (const char *name,
|
||||
gboolean boolean_value)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
char *key;
|
||||
|
||||
gboolean gconf_result;
|
||||
gboolean old_value;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
|
@ -704,16 +716,19 @@ nautilus_preferences_set_boolean (const char *name,
|
|||
g_assert (key != NULL);
|
||||
|
||||
/* Make sure the preference value is indeed different */
|
||||
if (gconf_client_get_bool (GLOBAL.gconf_client, key, NULL) == boolean_value) {
|
||||
old_value = gconf_client_get_bool (GLOBAL.gconf_client, key, &error);
|
||||
if (error == NULL
|
||||
&& old_value == boolean_value) {
|
||||
g_free (key);
|
||||
return;
|
||||
}
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_result = gconf_client_set_bool (GLOBAL.gconf_client, key, boolean_value, NULL);
|
||||
gconf_client_set_bool (GLOBAL.gconf_client, key, boolean_value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -722,7 +737,8 @@ gboolean
|
|||
nautilus_preferences_get_boolean (const char *name,
|
||||
gboolean default_value)
|
||||
{
|
||||
gboolean result;
|
||||
GConfError *error = NULL;
|
||||
gboolean result;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
@ -732,7 +748,10 @@ nautilus_preferences_get_boolean (const char *name,
|
|||
key = nautilus_user_level_manager_make_current_gconf_key (name);
|
||||
g_assert (key != NULL);
|
||||
|
||||
result = gconf_client_get_bool (GLOBAL.gconf_client, key, NULL);
|
||||
result = gconf_client_get_bool (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
result = default_value;
|
||||
}
|
||||
|
||||
g_free (key);
|
||||
|
||||
|
@ -744,10 +763,9 @@ void
|
|||
nautilus_preferences_set_string_list (const char *name,
|
||||
GSList *string_list_value)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
char *key;
|
||||
|
||||
gboolean gconf_result;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
preferences_initialize_if_needed ();
|
||||
|
@ -758,18 +776,14 @@ nautilus_preferences_set_string_list (const char *name,
|
|||
/* FIXME: Make sure the preference value is indeed different
|
||||
before setting, like the other functions */
|
||||
|
||||
/* FIXME: we are passing NULL for the last argument and thus
|
||||
missing out on any opportunity to handle errors. */
|
||||
gconf_client_set_list (GLOBAL.gconf_client, key,
|
||||
GCONF_VALUE_STRING,
|
||||
string_list_value,
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_result = gconf_client_set_list (GLOBAL.gconf_client, key,
|
||||
GCONF_VALUE_STRING,
|
||||
string_list_value,
|
||||
NULL);
|
||||
|
||||
/* FIXME: wrong to assert this, what if there is an error? */
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -777,8 +791,9 @@ nautilus_preferences_set_string_list (const char *name,
|
|||
GSList *
|
||||
nautilus_preferences_get_string_list (const char *name)
|
||||
{
|
||||
GSList *result;
|
||||
char *key;
|
||||
GConfError *error = NULL;
|
||||
GSList *result;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
||||
|
@ -788,7 +803,8 @@ nautilus_preferences_get_string_list (const char *name)
|
|||
g_assert (key != NULL);
|
||||
|
||||
result = gconf_client_get_list (GLOBAL.gconf_client, key,
|
||||
GCONF_VALUE_STRING, NULL);
|
||||
GCONF_VALUE_STRING, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
|
||||
|
@ -800,7 +816,8 @@ void
|
|||
nautilus_preferences_set_enum (const char *name,
|
||||
int enum_value)
|
||||
{
|
||||
gboolean gconf_result;
|
||||
GConfError *error = NULL;
|
||||
int old_value;
|
||||
char *key;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
@ -811,16 +828,19 @@ nautilus_preferences_set_enum (const char *name,
|
|||
g_assert (key != NULL);
|
||||
|
||||
/* Make sure the preference value is indeed different */
|
||||
if (gconf_client_get_int (GLOBAL.gconf_client, key, NULL) == enum_value) {
|
||||
old_value = gconf_client_get_int (GLOBAL.gconf_client, key, &error);
|
||||
if (error == NULL
|
||||
&& old_value == enum_value) {
|
||||
g_free (key);
|
||||
return;
|
||||
}
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_result = gconf_client_set_int (GLOBAL.gconf_client, key, enum_value, NULL);
|
||||
gconf_client_set_int (GLOBAL.gconf_client, key, enum_value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -829,7 +849,8 @@ int
|
|||
nautilus_preferences_get_enum (const char *name,
|
||||
int default_value)
|
||||
{
|
||||
int result;
|
||||
GConfError *error = NULL;
|
||||
int result;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
@ -839,7 +860,10 @@ nautilus_preferences_get_enum (const char *name,
|
|||
key = nautilus_user_level_manager_make_current_gconf_key (name);
|
||||
g_assert (key != NULL);
|
||||
|
||||
result = gconf_client_get_int (GLOBAL.gconf_client, key, NULL);
|
||||
result = gconf_client_get_int (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
result = default_value;
|
||||
}
|
||||
|
||||
g_free (key);
|
||||
|
||||
|
@ -850,7 +874,7 @@ void
|
|||
nautilus_preferences_set (const char *name,
|
||||
const char *value)
|
||||
{
|
||||
gboolean gconf_result;
|
||||
GConfError *error = NULL;
|
||||
char *key;
|
||||
|
||||
g_return_if_fail (name != NULL);
|
||||
|
@ -862,8 +886,15 @@ nautilus_preferences_set (const char *name,
|
|||
|
||||
/* Make sure the preference value is indeed different */
|
||||
if (value) {
|
||||
char *current_value = gconf_client_get_string (GLOBAL.gconf_client, key, NULL);
|
||||
int result = nautilus_strcmp (current_value, value);
|
||||
char *current_value;
|
||||
int result;
|
||||
|
||||
current_value = gconf_client_get_string (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
result = ! 0;
|
||||
} else {
|
||||
result = nautilus_strcmp (current_value, value);
|
||||
}
|
||||
|
||||
if (current_value) {
|
||||
g_free (current_value);
|
||||
|
@ -875,11 +906,11 @@ nautilus_preferences_set (const char *name,
|
|||
}
|
||||
}
|
||||
|
||||
gconf_result = gconf_client_set_string (GLOBAL.gconf_client, key, value, NULL);
|
||||
gconf_client_set_string (GLOBAL.gconf_client, key, value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (gconf_result);
|
||||
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, NULL);
|
||||
gconf_client_suggest_sync (GLOBAL.gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_free (key);
|
||||
}
|
||||
|
@ -888,7 +919,8 @@ char *
|
|||
nautilus_preferences_get (const char *name,
|
||||
const char *default_value)
|
||||
{
|
||||
gchar *value = NULL;
|
||||
GConfError *error = NULL;
|
||||
gchar *value = NULL;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
|
@ -898,7 +930,12 @@ nautilus_preferences_get (const char *name,
|
|||
key = nautilus_user_level_manager_make_current_gconf_key (name);
|
||||
g_assert (key != NULL);
|
||||
|
||||
value = gconf_client_get_string (GLOBAL.gconf_client, key, NULL);
|
||||
value = gconf_client_get_string (GLOBAL.gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
/* note: g_free and g_strdup handle NULL correctly */
|
||||
g_free (value);
|
||||
value = g_strdup (default_value);
|
||||
}
|
||||
|
||||
if (!value && default_value) {
|
||||
value = g_strdup (default_value);
|
||||
|
@ -938,3 +975,33 @@ nautilus_preferences_shutdown (void)
|
|||
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_preferences_handle_error (GConfError **error)
|
||||
{
|
||||
static gboolean shown_dialog = FALSE;
|
||||
|
||||
g_return_val_if_fail (error != NULL, FALSE);
|
||||
|
||||
if (*error != NULL) {
|
||||
g_warning (_("GConf error:\n %s"), (*error)->str);
|
||||
if ( ! shown_dialog) {
|
||||
char *message;
|
||||
GtkWidget *dialog;
|
||||
|
||||
shown_dialog = TRUE;
|
||||
|
||||
message = g_strdup_printf (_("GConf error:\n %s\n"
|
||||
"All further errors shown "
|
||||
"only on terminal"),
|
||||
(*error)->str);
|
||||
|
||||
dialog = gnome_error_dialog (message);
|
||||
}
|
||||
gconf_error_destroy(*error);
|
||||
*error = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include "nautilus-gtk-macros.h"
|
||||
#include "nautilus-glib-extensions.h"
|
||||
|
||||
#include "nautilus-preferences.h"
|
||||
#include "nautilus-preferences-private.h"
|
||||
|
||||
#include <gtk/gtksignal.h>
|
||||
|
||||
#include <gconf/gconf.h>
|
||||
|
@ -105,22 +108,17 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusUserLevelManager, nautilus_user_level
|
|||
static NautilusUserLevelManager *
|
||||
user_level_manager_new (void)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
NautilusUserLevelManager *manager;
|
||||
guint i;
|
||||
|
||||
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;
|
||||
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -134,7 +132,8 @@ user_level_manager_new (void)
|
|||
gconf_client_add_dir (manager->gconf_client,
|
||||
USER_LEVEL_PATH,
|
||||
GCONF_CLIENT_PRELOAD_RECURSIVE,
|
||||
NULL);
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
manager->num_user_levels = DEFAULT_NUM_USER_LEVELS;
|
||||
manager->user_level_names = nautilus_string_list_new (TRUE);
|
||||
|
@ -153,7 +152,8 @@ user_level_manager_new (void)
|
|||
gconf_user_level_changed_callback,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
@ -224,21 +224,30 @@ user_level_manager_ensure_global_manager (void)
|
|||
static void
|
||||
user_level_set_default_if_needed (NautilusUserLevelManager *manager)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
GConfValue *value;
|
||||
|
||||
g_assert (manager != NULL);
|
||||
g_assert (manager->gconf_client != NULL);
|
||||
|
||||
value = gconf_client_get_without_default (manager->gconf_client, USER_LEVEL_KEY, NULL);
|
||||
value = gconf_client_get_without_default (manager->gconf_client, USER_LEVEL_KEY, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value != NULL) {
|
||||
gconf_value_destroy (value);
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
value = gconf_value_new (GCONF_VALUE_STRING);
|
||||
|
||||
gconf_value_set_string (value, DEFAULT_USER_LEVEL_NAMES[DEFAULT_USER_LEVEL]);
|
||||
|
||||
gconf_client_set (manager->gconf_client, USER_LEVEL_KEY, value, NULL);
|
||||
gconf_client_set (manager->gconf_client, USER_LEVEL_KEY, value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
gconf_client_suggest_sync (manager->gconf_client, NULL);
|
||||
gconf_client_suggest_sync (manager->gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
}
|
||||
|
||||
g_assert (value != NULL);
|
||||
|
@ -274,9 +283,9 @@ nautilus_user_level_manager_get (void)
|
|||
void
|
||||
nautilus_user_level_manager_set_user_level (guint user_level)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
char *user_level_string;
|
||||
gboolean result;
|
||||
guint old_user_level;
|
||||
|
||||
g_return_if_fail (user_level < manager->num_user_levels);
|
||||
|
@ -292,14 +301,14 @@ nautilus_user_level_manager_set_user_level (guint user_level)
|
|||
|
||||
g_assert (user_level_string != NULL);
|
||||
|
||||
result = gconf_client_set_string (manager->gconf_client,
|
||||
USER_LEVEL_KEY,
|
||||
user_level_string,
|
||||
NULL);
|
||||
gconf_client_set_string (manager->gconf_client,
|
||||
USER_LEVEL_KEY,
|
||||
user_level_string,
|
||||
&error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
|
||||
g_assert (result);
|
||||
|
||||
gconf_client_suggest_sync (manager->gconf_client, NULL);
|
||||
gconf_client_suggest_sync (manager->gconf_client, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
}
|
||||
|
||||
guint
|
||||
|
@ -384,12 +393,17 @@ nautilus_user_level_manager_make_current_gconf_key (const char *preference_name)
|
|||
char *
|
||||
nautilus_user_level_manager_get_user_level_as_string (void)
|
||||
{
|
||||
GConfError *error = NULL;
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
char *user_level_string;
|
||||
char *user_level_string = NULL;
|
||||
|
||||
g_assert (manager->gconf_client != NULL);
|
||||
|
||||
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, NULL);
|
||||
user_level_string = gconf_client_get_string (manager->gconf_client, USER_LEVEL_KEY, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
g_free (user_level_string);
|
||||
user_level_string = NULL;
|
||||
}
|
||||
|
||||
if (!user_level_string)
|
||||
user_level_string = g_strdup ("novice");
|
||||
|
@ -420,6 +434,7 @@ nautilus_user_level_manager_set_default_value_if_needed (const char *preference
|
|||
gconstpointer default_value)
|
||||
{
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
GConfError *error = NULL;
|
||||
GConfValue *value = NULL;
|
||||
char *key;
|
||||
|
||||
|
@ -429,7 +444,13 @@ nautilus_user_level_manager_set_default_value_if_needed (const char *preference
|
|||
g_assert (key != NULL);
|
||||
|
||||
/* Find out if the preference exists at all */
|
||||
value = gconf_client_get_without_default (manager->gconf_client, key, NULL);
|
||||
value = gconf_client_get_without_default (manager->gconf_client, key, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value != NULL) {
|
||||
gconf_value_destroy (value);
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* The value does not exist, so create one */
|
||||
if (!value) {
|
||||
|
@ -453,7 +474,8 @@ nautilus_user_level_manager_set_default_value_if_needed (const char *preference
|
|||
}
|
||||
|
||||
if (value) {
|
||||
gconf_client_set (manager->gconf_client, key, value, NULL);
|
||||
gconf_client_set (manager->gconf_client, key, value, &error);
|
||||
nautilus_preferences_handle_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,6 +497,7 @@ nautilus_user_level_manager_compare_preference_between_user_levels (const char *
|
|||
char *key_b;
|
||||
GConfValue *value_a;
|
||||
GConfValue *value_b;
|
||||
GConfError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (preference_name != NULL, FALSE);
|
||||
|
||||
|
@ -484,8 +507,20 @@ nautilus_user_level_manager_compare_preference_between_user_levels (const char *
|
|||
key_b = nautilus_user_level_manager_make_gconf_key (preference_name, user_level_b);
|
||||
g_assert (key_b != NULL);
|
||||
|
||||
value_a = gconf_client_get (manager->gconf_client, key_a, NULL);
|
||||
value_b = gconf_client_get (manager->gconf_client, key_b, NULL);
|
||||
value_a = gconf_client_get (manager->gconf_client, key_a, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value_a != NULL) {
|
||||
gconf_value_destroy (value_a);
|
||||
value_a = NULL;
|
||||
}
|
||||
}
|
||||
value_b = gconf_client_get (manager->gconf_client, key_b, &error);
|
||||
if (nautilus_preferences_handle_error (&error)) {
|
||||
if (value_b != NULL) {
|
||||
gconf_value_destroy (value_b);
|
||||
value_b = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (key_a);
|
||||
g_free (key_b);
|
||||
|
|
Loading…
Reference in a new issue