diff options
author | Marco Pesenti Gritti <marco@gnome.org> | 2003-11-05 05:43:09 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2003-11-05 05:43:09 +0800 |
commit | 8180308e57e97c0c4e69331aac409e49e6a38876 (patch) | |
tree | f507f2923ead34164153f2825eea87f8199d3e5d /lib | |
parent | f077672b83507d7ae5dedad6c7d82105e5d5d42f (diff) | |
download | gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.tar gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.tar.gz gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.tar.bz2 gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.tar.lz gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.tar.xz gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.tar.zst gsoc2013-epiphany-8180308e57e97c0c4e69331aac409e49e6a38876.zip |
Resync with eel.
2003-11-04 Marco Pesenti Gritti <marco@gnome.org>
* lib/eel-gconf-extensions.c: (global_client_free),
(eel_gconf_client_get_global), (eel_gconf_handle_error),
(eel_gconf_set_string), (eel_gconf_is_default),
(eel_gconf_key_is_writable), (eel_gconf_monitor_add),
(eel_gconf_monitor_remove), (eel_gconf_preload_cache),
(eel_gconf_get_default_value), (eel_strcmp), (eel_str_is_equal),
(simple_value_is_equal), (eel_gconf_value_is_equal),
(eel_gconf_value_get_string_list),
(eel_gconf_value_set_string_list), (eel_gconf_set_float),
(eel_gconf_get_float):
* lib/eel-gconf-extensions.h:
Resync with eel.
* lib/ephy-prefs.h:
* lib/widgets/ephy-spinner.c:
* embed/ephy-embed-prefs.h:
* embed/mozilla/mozilla-notifiers.cpp:
Migrate old font size settings. This will screw things
for 1.1 users, not much we can do about it now.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/eel-gconf-extensions.c | 413 | ||||
-rw-r--r-- | lib/eel-gconf-extensions.h | 95 | ||||
-rw-r--r-- | lib/ephy-prefs.h | 3 | ||||
-rw-r--r-- | lib/widgets/ephy-spinner.c | 1 |
4 files changed, 319 insertions, 193 deletions
diff --git a/lib/eel-gconf-extensions.c b/lib/eel-gconf-extensions.c index 564085704..ff016b5f5 100644 --- a/lib/eel-gconf-extensions.c +++ b/lib/eel-gconf-extensions.c @@ -22,15 +22,13 @@ Authors: Ramiro Estrugo <ramiro@eazel.com> */ -#include <stdlib.h> #include <config.h> #include "eel-gconf-extensions.h" +#include <bonobo/bonobo-i18n.h> #include <gconf/gconf-client.h> #include <gconf/gconf.h> -#include <gtk/gtkwidget.h> -#include <bonobo/bonobo-i18n.h> -#include <gtk/gtkmessagedialog.h> +#include <string.h> static GConfClient *global_gconf_client = NULL; @@ -40,8 +38,8 @@ global_client_free (void) if (global_gconf_client == NULL) { return; } - - g_object_unref (G_OBJECT (global_gconf_client)); + + g_object_unref (global_gconf_client); global_gconf_client = NULL; } @@ -59,7 +57,6 @@ eel_gconf_client_get_global (void) return NULL; } } - } if (global_gconf_client == NULL) { @@ -73,10 +70,23 @@ eel_gconf_client_get_global (void) gboolean eel_gconf_handle_error (GError **error) { + char *message; + static gboolean shown_dialog = FALSE; + g_return_val_if_fail (error != NULL, FALSE); if (*error != NULL) { g_warning (_("GConf error:\n %s"), (*error)->message); + if (! shown_dialog) { + shown_dialog = TRUE; + + message = g_strdup_printf (_("GConf error:\n %s\n" + "All further errors shown " + "only on terminal"), + (*error)->message); + g_error (message, _("GConf Error"), NULL); + g_free (message); + } g_error_free (*error); *error = NULL; @@ -161,51 +171,13 @@ eel_gconf_get_integer (const char *key) } void -eel_gconf_set_float (const char *key, - gfloat float_value) -{ - GConfClient *client; - GError *error = NULL; - - g_return_if_fail (key != NULL); - - client = eel_gconf_client_get_global (); - g_return_if_fail (client != NULL); - - gconf_client_set_float (client, key, float_value, &error); - eel_gconf_handle_error (&error); -} - -gfloat -eel_gconf_get_float (const char *key) -{ - gfloat result; - GConfClient *client; - GError *error = NULL; - - g_return_val_if_fail (key != NULL, 0); - - client = eel_gconf_client_get_global (); - g_return_val_if_fail (client != NULL, 0); - - result = gconf_client_get_float (client, key, &error); - - if (eel_gconf_handle_error (&error)) { - result = 0; - } - - return result; -} - -void eel_gconf_set_string (const char *key, - const char *string_value) + const char *string_value) { GConfClient *client; GError *error = NULL; g_return_if_fail (key != NULL); - g_return_if_fail (string_value != NULL); client = eel_gconf_client_get_global (); g_return_if_fail (client != NULL); @@ -214,21 +186,6 @@ eel_gconf_set_string (const char *key, eel_gconf_handle_error (&error); } -void -eel_gconf_unset (const char *key) -{ - GConfClient *client; - GError *error = NULL; - - g_return_if_fail (key != NULL); - - client = eel_gconf_client_get_global (); - g_return_if_fail (client != NULL); - - gconf_client_unset (client, key, &error); - eel_gconf_handle_error (&error); -} - char * eel_gconf_get_string (const char *key) { @@ -291,49 +248,6 @@ eel_gconf_get_string_list (const char *key) return slist; } -/* This code wasn't part of the original eel-gconf-extensions.c */ -void -eel_gconf_set_integer_list (const char *key, - const GSList *slist) -{ - GConfClient *client; - GError *error; - - g_return_if_fail (key != NULL); - - client = eel_gconf_client_get_global (); - g_return_if_fail (client != NULL); - - error = NULL; - gconf_client_set_list (client, key, GCONF_VALUE_INT, - /* Need cast cause of GConf api bug */ - (GSList *) slist, - &error); - eel_gconf_handle_error (&error); -} - -GSList * -eel_gconf_get_integer_list (const char *key) -{ - GSList *slist; - GConfClient *client; - GError *error; - - g_return_val_if_fail (key != NULL, NULL); - - client = eel_gconf_client_get_global (); - g_return_val_if_fail (client != NULL, NULL); - - error = NULL; - slist = gconf_client_get_list (client, key, GCONF_VALUE_INT, &error); - if (eel_gconf_handle_error (&error)) { - slist = NULL; - } - - return slist; -} -/* End of added code */ - gboolean eel_gconf_is_default (const char *key) { @@ -353,12 +267,24 @@ eel_gconf_is_default (const char *key) } result = (value == NULL); + eel_gconf_value_free (value); + return result; +} + +gboolean +eel_gconf_key_is_writable (const char *key) +{ + gboolean result; + GError *error = NULL; + + g_return_val_if_fail (key != NULL, FALSE); + + result = gconf_client_key_is_writable (eel_gconf_client_get_global (), key, &error); - if (value != NULL) { - gconf_value_free (value); + if (eel_gconf_handle_error (&error)) { + return result; } - return result; } @@ -370,7 +296,7 @@ eel_gconf_monitor_add (const char *directory) g_return_val_if_fail (directory != NULL, FALSE); - client = eel_gconf_client_get_global (); + client = gconf_client_get_default (); g_return_val_if_fail (client != NULL, FALSE); gconf_client_add_dir (client, @@ -395,7 +321,7 @@ eel_gconf_monitor_remove (const char *directory) return FALSE; } - client = eel_gconf_client_get_global (); + client = gconf_client_get_default (); g_return_val_if_fail (client != NULL, FALSE); gconf_client_remove_dir (client, @@ -410,6 +336,28 @@ eel_gconf_monitor_remove (const char *directory) } void +eel_gconf_preload_cache (const char *directory, + GConfClientPreloadType preload_type) +{ + GError *error = NULL; + GConfClient *client; + + if (directory == NULL) { + return; + } + + client = gconf_client_get_default (); + g_return_if_fail (client != NULL); + + gconf_client_preload (client, + directory, + preload_type, + &error); + + eel_gconf_handle_error (&error); +} + +void eel_gconf_suggest_sync (void) { GConfClient *client; @@ -446,22 +394,150 @@ eel_gconf_get_value (const char *key) return value; } -void -eel_gconf_set_value (const char *key, GConfValue *value) +GConfValue* +eel_gconf_get_default_value (const char *key) { + GConfValue *value = NULL; GConfClient *client; GError *error = NULL; - - g_return_if_fail (key != NULL); + + g_return_val_if_fail (key != NULL, NULL); client = eel_gconf_client_get_global (); - g_return_if_fail (client != NULL); + g_return_val_if_fail (client != NULL, NULL); - gconf_client_set (client, key, value, &error); + value = gconf_client_get_default_from_schema (client, key, &error); if (eel_gconf_handle_error (&error)) { - return; + if (value != NULL) { + gconf_value_free (value); + value = NULL; + } + } + + return value; +} + +static int +eel_strcmp (const char *string_a, const char *string_b) +{ + /* FIXME bugzilla.eazel.com 5450: Maybe we need to make this + * treat 'NULL < ""', or have a flavor that does that. If we + * didn't have code that already relies on 'NULL == ""', I + * would change it right now. + */ + return strcmp (string_a == NULL ? "" : string_a, + string_b == NULL ? "" : string_b); +} + +static gboolean +eel_str_is_equal (const char *string_a, const char *string_b) +{ + /* FIXME bugzilla.eazel.com 5450: Maybe we need to make this + * treat 'NULL != ""', or have a flavor that does that. If we + * didn't have code that already relies on 'NULL == ""', I + * would change it right now. + */ + return eel_strcmp (string_a, string_b) == 0; +} + +static gboolean +simple_value_is_equal (const GConfValue *a, + const GConfValue *b) +{ + g_return_val_if_fail (a != NULL, FALSE); + g_return_val_if_fail (b != NULL, FALSE); + + switch (a->type) { + case GCONF_VALUE_STRING: + return eel_str_is_equal (gconf_value_get_string (a), + gconf_value_get_string (b)); + break; + + case GCONF_VALUE_INT: + return gconf_value_get_int (a) == + gconf_value_get_int (b); + break; + + case GCONF_VALUE_FLOAT: + return gconf_value_get_float (a) == + gconf_value_get_float (b); + break; + + case GCONF_VALUE_BOOL: + return gconf_value_get_bool (a) == + gconf_value_get_bool (b); + break; + default: + g_assert_not_reached (); + } + + return FALSE; +} + +gboolean +eel_gconf_value_is_equal (const GConfValue *a, + const GConfValue *b) +{ + GSList *node_a; + GSList *node_b; + + if (a == NULL && b == NULL) { + return TRUE; + } + + if (a == NULL || b == NULL) { + return FALSE; + } + + if (a->type != b->type) { + return FALSE; + } + + switch (a->type) { + case GCONF_VALUE_STRING: + case GCONF_VALUE_INT: + case GCONF_VALUE_FLOAT: + case GCONF_VALUE_BOOL: + return simple_value_is_equal (a, b); + break; + + case GCONF_VALUE_LIST: + if (gconf_value_get_list_type (a) != + gconf_value_get_list_type (b)) { + return FALSE; + } + + node_a = gconf_value_get_list (a); + node_b = gconf_value_get_list (b); + + if (node_a == NULL && node_b == NULL) { + return TRUE; + } + + if (g_slist_length (node_a) != + g_slist_length (node_b)) { + return FALSE; + } + + for (; + node_a != NULL && node_b != NULL; + node_a = node_a->next, node_b = node_b->next) { + g_assert (node_a->data != NULL); + g_assert (node_b->data != NULL); + if (!simple_value_is_equal (node_a->data, node_b->data)) { + return FALSE; + } + } + + return TRUE; + default: + /* FIXME: pair ? */ + g_assert (0); } + + g_assert_not_reached (); + return FALSE; } void @@ -521,36 +597,93 @@ eel_gconf_notification_remove (guint notification_id) gconf_client_notify_remove (client, notification_id); } -/* Simple wrapper for eel_gconf_notifier_add which - * adds the notifier id to the GList given as argument - * so that a call to ephy_notification_free can remove the notifiers - */ +GSList * +eel_gconf_value_get_string_list (const GConfValue *value) +{ + GSList *result; + const GSList *slist; + const GSList *node; + const char *string; + const GConfValue *next_value; + + if (value == NULL) { + return NULL; + } + + g_return_val_if_fail (value->type == GCONF_VALUE_LIST, NULL); + g_return_val_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING, NULL); + + slist = gconf_value_get_list (value); + result = NULL; + for (node = slist; node != NULL; node = node->next) { + next_value = node->data; + g_return_val_if_fail (next_value != NULL, NULL); + g_return_val_if_fail (next_value->type == GCONF_VALUE_STRING, NULL); + string = gconf_value_get_string (next_value); + result = g_slist_append (result, g_strdup (string)); + } + return result; +} + void -ephy_notification_add (const char *key, - GConfClientNotifyFunc notification_callback, - gpointer callback_data, - GList **notifiers) +eel_gconf_value_set_string_list (GConfValue *value, + const GSList *string_list) { - guint id = 0; - - id = eel_gconf_notification_add(key, - notification_callback, - callback_data); - if (notifiers != NULL) { - *notifiers = g_list_append(*notifiers, - GINT_TO_POINTER(id)); + const GSList *node; + GConfValue *next_value; + GSList *value_list; + + g_return_if_fail (value->type == GCONF_VALUE_LIST); + g_return_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING); + + value_list = NULL; + for (node = string_list; node != NULL; node = node->next) { + next_value = gconf_value_new (GCONF_VALUE_STRING); + gconf_value_set_string (next_value, node->data); + value_list = g_slist_append (value_list, next_value); } + + gconf_value_set_list (value, value_list); + + for (node = value_list; node != NULL; node = node->next) { + gconf_value_free (node->data); + } + g_slist_free (value_list); } -/* Removes all the notifiers listed in notifiers */ -/* Frees the notifiers list */ void -ephy_notification_remove (GList **notifiers) +eel_gconf_set_float (const char *key, + gfloat float_value) { - g_list_foreach(*notifiers, - (GFunc)eel_gconf_notification_remove, - NULL); - g_list_free(*notifiers); - *notifiers = NULL; + GConfClient *client; + GError *error = NULL; + + g_return_if_fail (key != NULL); + + client = eel_gconf_client_get_global (); + g_return_if_fail (client != NULL); + + gconf_client_set_float (client, key, float_value, &error); + eel_gconf_handle_error (&error); } +gfloat +eel_gconf_get_float (const char *key) +{ + gfloat result; + GConfClient *client; + GError *error = NULL; + + g_return_val_if_fail (key != NULL, 0); + + client = eel_gconf_client_get_global (); + g_return_val_if_fail (client != NULL, 0); + + result = gconf_client_get_float (client, key, &error); + + if (eel_gconf_handle_error (&error)) { + result = 0; + } + + return result; +} diff --git a/lib/eel-gconf-extensions.h b/lib/eel-gconf-extensions.h index df51afaa1..13196d7ee 100644 --- a/lib/eel-gconf-extensions.h +++ b/lib/eel-gconf-extensions.h @@ -25,63 +25,54 @@ #ifndef EEL_GCONF_EXTENSIONS_H #define EEL_GCONF_EXTENSIONS_H -#include <glib/gerror.h> +#include <glib.h> #include <gconf/gconf.h> #include <gconf/gconf-client.h> -#ifdef __cplusplus -extern "C" { -#endif +G_BEGIN_DECLS #define EEL_GCONF_UNDEFINED_CONNECTION 0 -GConfClient *eel_gconf_client_get_global (void); -gboolean eel_gconf_handle_error (GError **error); -void eel_gconf_set_boolean (const char *key, - gboolean boolean_value); -gboolean eel_gconf_get_boolean (const char *key); -int eel_gconf_get_integer (const char *key); -void eel_gconf_set_integer (const char *key, - int int_value); -gfloat eel_gconf_get_float (const char *key); -void eel_gconf_set_float (const char *key, - gfloat float_value); -char * eel_gconf_get_string (const char *key); -void eel_gconf_set_string (const char *key, - const char *string_value); -GSList * eel_gconf_get_string_list (const char *key); -void eel_gconf_set_string_list (const char *key, - const GSList *string_list_value); -gboolean eel_gconf_is_default (const char *key); -gboolean eel_gconf_monitor_add (const char *directory); -gboolean eel_gconf_monitor_remove (const char *directory); -void eel_gconf_suggest_sync (void); -GConfValue* eel_gconf_get_value (const char *key); -gboolean eel_gconf_value_is_equal (const GConfValue *a, - const GConfValue *b); -void eel_gconf_set_value (const char *key, GConfValue *value); -void eel_gconf_value_free (GConfValue *value); -void eel_gconf_unset (const char *key); - -/* Functions which weren't part of the eel-gconf-extensions.h file from eel */ -GSList *eel_gconf_get_integer_list (const char *key); -void eel_gconf_set_integer_list (const char *key, - const GSList *slist); -guint eel_gconf_notification_add (const char *key, - GConfClientNotifyFunc notification_callback, - gpointer callback_data); -void eel_gconf_notification_remove (guint notification_id); - -void ephy_notification_add (const char *key, - GConfClientNotifyFunc notification_callback, - gpointer callback_data, - GList **notifiers); - -void ephy_notification_remove (GList **notifiers); - - -#ifdef __cplusplus -} -#endif +GConfClient *eel_gconf_client_get_global (void); +gboolean eel_gconf_handle_error (GError **error); +void eel_gconf_set_boolean (const char *key, + gboolean boolean_value); +gboolean eel_gconf_get_boolean (const char *key); +int eel_gconf_get_integer (const char *key); +void eel_gconf_set_integer (const char *key, + int int_value); +char * eel_gconf_get_string (const char *key); +void eel_gconf_set_string (const char *key, + const char *string_value); +GSList * eel_gconf_get_string_list (const char *key); +void eel_gconf_set_string_list (const char *key, + const GSList *string_list_value); +gboolean eel_gconf_key_is_writable (const char *key); +gboolean eel_gconf_is_default (const char *key); +gboolean eel_gconf_monitor_add (const char *directory); +gboolean eel_gconf_monitor_remove (const char *directory); +void eel_gconf_preload_cache (const char *directory, + GConfClientPreloadType preload_type); +void eel_gconf_suggest_sync (void); +GConfValue* eel_gconf_get_value (const char *key); +GConfValue* eel_gconf_get_default_value (const char *key); +gboolean eel_gconf_value_is_equal (const GConfValue *a, + const GConfValue *b); +void eel_gconf_value_free (GConfValue *value); +guint eel_gconf_notification_add (const char *key, + GConfClientNotifyFunc notification_callback, + gpointer callback_data); +void eel_gconf_notification_remove (guint notification_id); +GSList * eel_gconf_value_get_string_list (const GConfValue *value); +void eel_gconf_value_set_string_list (GConfValue *value, + const GSList *string_list); + +/* These are ephy additions, not part of the eel code */ + +void eel_gconf_set_float (const char *key, + gfloat float_value); +gfloat eel_gconf_get_float (const char *key); + +G_END_DECLS #endif /* EEL_GCONF_EXTENSIONS_H */ diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h index e23b9ad6b..53c07e5d8 100644 --- a/lib/ephy-prefs.h +++ b/lib/ephy-prefs.h @@ -21,6 +21,9 @@ G_BEGIN_DECLS +#define EPIPHANY_SCHEMA_VERSION 1 +#define CONF_SCHEMA_VERSION "/apps/epiphany/schema_version" + /* General */ #define CONF_GENERAL_HOMEPAGE "/apps/epiphany/general/homepage" #define CONF_ALWAYS_SHOW_TABS_BAR "/apps/epiphany/general/always_show_tabs_bar" diff --git a/lib/widgets/ephy-spinner.c b/lib/widgets/ephy-spinner.c index c88d326d2..0443eb0de 100644 --- a/lib/widgets/ephy-spinner.c +++ b/lib/widgets/ephy-spinner.c @@ -31,7 +31,6 @@ #endif #include "ephy-spinner.h" -#include "eel-gconf-extensions.h" #include "ephy-string.h" #include "ephy-file-helpers.h" |