summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-09-05 21:59:16 +0200
committerStefano Karapetsas <[email protected]>2012-09-05 21:59:16 +0200
commitbe3f666650c0da1aac5232291d83a51e127b005e (patch)
tree2d862d6db5c40d7957921e264469cc5dba57c88e /eel
parent45742f8351e2991d54b00189f6e0c772e257f395 (diff)
downloadcaja-be3f666650c0da1aac5232291d83a51e127b005e.tar.bz2
caja-be3f666650c0da1aac5232291d83a51e127b005e.tar.xz
remove latest mateconf stuff
Diffstat (limited to 'eel')
-rw-r--r--eel/Makefile.am7
-rw-r--r--eel/eel-enumeration.c555
-rw-r--r--eel/eel-enumeration.h63
-rw-r--r--eel/eel-lib-self-check-functions.h4
-rw-r--r--eel/eel-mateconf-extensions.c687
-rw-r--r--eel/eel-mateconf-extensions.h78
-rw-r--r--eel/eel-preferences-builder.c646
-rw-r--r--eel/eel-preferences.c1764
-rw-r--r--eel/eel-preferences.h165
-rw-r--r--eel/eel.h3
10 files changed, 1 insertions, 3971 deletions
diff --git a/eel/Makefile.am b/eel/Makefile.am
index d690eba2..a973fee8 100644
--- a/eel/Makefile.am
+++ b/eel/Makefile.am
@@ -39,8 +39,6 @@ libeel_2_la_SOURCES = \
eel-debug-drawing.c \
eel-debug.c \
eel-editable-label.c \
- eel-enumeration.c \
- eel-mateconf-extensions.c \
eel-gdk-extensions.c \
eel-gdk-pixbuf-extensions.c \
eel-glib-extensions.c \
@@ -53,8 +51,6 @@ libeel_2_la_SOURCES = \
eel-labeled-image.c \
eel-lib-self-check-functions.c \
eel-pango-extensions.c \
- eel-preferences-builder.c \
- eel-preferences.c \
eel-self-checks.c \
eel-stock-dialogs.c \
eel-string.c \
@@ -78,8 +74,6 @@ eel_headers = \
eel-debug-drawing.h \
eel-debug.h \
eel-editable-label.h \
- eel-enumeration.h \
- eel-mateconf-extensions.h \
eel-gdk-extensions.h \
eel-gdk-pixbuf-extensions.h \
eel-glib-extensions.h \
@@ -92,7 +86,6 @@ eel_headers = \
eel-image-table.h \
eel-labeled-image.h \
eel-pango-extensions.h \
- eel-preferences.h \
eel-self-checks.h \
eel-stock-dialogs.h \
eel-string.h \
diff --git a/eel/eel-enumeration.c b/eel/eel-enumeration.c
deleted file mode 100644
index df46ec61..00000000
--- a/eel/eel-enumeration.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
-
- eel-enumeration.c: Enumeration data structure.
-
- Copyright (C) 2000 Eazel, Inc.
-
- This program 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.
-
- This program 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 this program; if not, write to the
- Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Author: Ramiro Estrugo <[email protected]>
-*/
-
-#include <config.h>
-#include "eel-enumeration.h"
-
-#include "eel-debug.h"
-#include "eel-glib-extensions.h"
-#include "eel-lib-self-check-functions.h"
-#include "eel-string.h"
-#include "eel-i18n.h"
-
-static gboolean suppress_duplicate_registration_warning;
-
-struct EelEnumeration
-{
- char *id;
- GPtrArray *entries; /* array of EelEnumerationEntry */
-};
-
-static EelEnumeration *
-eel_enumeration_new (const char *id)
-{
- EelEnumeration *enumeration;
-
- g_assert (id != NULL);
- g_assert (id[0] != '\0');
-
- enumeration = g_new0 (EelEnumeration, 1);
-
- enumeration->id = g_strdup (id);
- enumeration->entries = g_ptr_array_new ();
-
- return enumeration;
-}
-
-static void
-free_entry (EelEnumerationEntry *entry)
-{
- g_free (entry->name);
- g_free (entry->description);
- g_free (entry);
-}
-
-static void
-eel_enumeration_free (EelEnumeration *enumeration)
-{
- if (enumeration == NULL)
- {
- return;
- }
-
- g_free (enumeration->id);
- g_ptr_array_foreach (enumeration->entries, (GFunc) free_entry, NULL);
- g_ptr_array_free (enumeration->entries, TRUE);
- g_free (enumeration);
-}
-
-char *
-eel_enumeration_get_id (const EelEnumeration *enumeration)
-{
- g_return_val_if_fail (enumeration != NULL, NULL);
-
- return g_strdup (enumeration->id);
-}
-
-guint
-eel_enumeration_get_length (const EelEnumeration *enumeration)
-{
- g_return_val_if_fail (enumeration != NULL, 0);
-
- return enumeration->entries->len;
-}
-
-const EelEnumerationEntry *
-eel_enumeration_get_nth_entry (const EelEnumeration *enumeration,
- guint n)
-{
- g_return_val_if_fail (enumeration != NULL, NULL);
- g_return_val_if_fail (n < enumeration->entries->len, NULL);
-
- return (EelEnumerationEntry *) g_ptr_array_index (enumeration->entries, n);
-}
-
-int
-eel_enumeration_get_name_position (const EelEnumeration *enumeration,
- const char *name)
-{
- int i;
-
- g_return_val_if_fail (enumeration != NULL, -1);
- g_return_val_if_fail (name != NULL, -1);
-
- for (i = 0; i < enumeration->entries->len; ++i)
- {
- EelEnumerationEntry *entry = enumeration->entries->pdata[i];
- if (strcmp (name, entry->name) == 0)
- {
- return i;
- }
- }
-
- return -1;
-}
-
-gboolean
-eel_enumeration_contains_name (const EelEnumeration *enumeration,
- const char *name)
-{
- g_return_val_if_fail (enumeration != NULL, FALSE);
- g_return_val_if_fail (name != NULL, FALSE);
-
- return eel_enumeration_get_name_position (enumeration, name) != -1;
-}
-
-guint
-eel_enumeration_get_value_for_name (const EelEnumeration *enumeration,
- const char *name)
-{
- int i;
-
- g_return_val_if_fail (enumeration != NULL, 0);
- g_return_val_if_fail (name != NULL, 0);
-
- for (i = 0; i < enumeration->entries->len; ++i)
- {
- EelEnumerationEntry *entry = enumeration->entries->pdata[i];
- if (strcmp (name, entry->name) == 0)
- {
- return entry->value;
- }
- }
-
- g_warning ("No name '%s' in enumeration '%s'", name, enumeration->id);
-
- return 0;
-}
-
-const char *
-eel_enumeration_get_name_for_value (const EelEnumeration *enumeration,
- int value)
-{
- int i;
-
- g_return_val_if_fail (enumeration != NULL, 0);
-
- for (i = 0; i < enumeration->entries->len; ++i)
- {
- EelEnumerationEntry *entry = enumeration->entries->pdata[i];
- if (value == entry->value)
- {
- return entry->name;
- }
- }
-
- g_warning ("No value '%d' in enumeration '%s'", value, enumeration->id);
-
- return NULL;
-}
-
-char **
-eel_enumeration_get_names (const EelEnumeration *enumeration)
-{
- GPtrArray *names;
- int i;
-
- g_return_val_if_fail (enumeration != NULL, NULL);
-
- if (enumeration->entries->len == 0)
- {
- return NULL;
- }
-
- names = g_ptr_array_sized_new (enumeration->entries->len + 1);
- for (i = 0; i < enumeration->entries->len; ++i)
- {
- EelEnumerationEntry *entry = enumeration->entries->pdata[i];
- g_ptr_array_add (names, g_strdup (entry->name));
- }
- g_ptr_array_add (names, NULL);
-
- return (char **) g_ptr_array_free (names, FALSE);
-}
-
-static EelEnumeration *
-eel_enumeration_new_from_tokens (const char *id,
- const char *names,
- const char *descriptions,
- const char *values,
- const char *delimiter)
-{
- EelEnumeration *enumeration;
- char **namev;
- char **descriptionv;
- char **valuev;
- int length;
- guint i;
-
- g_return_val_if_fail (id != NULL, NULL);
- g_return_val_if_fail (id[0] != '\0', NULL);
- g_return_val_if_fail (names != NULL, NULL);
- g_return_val_if_fail (names[0] != '\0', NULL);
- g_return_val_if_fail (values != NULL, NULL);
- g_return_val_if_fail (values[0] != '\0', NULL);
- g_return_val_if_fail (delimiter != NULL, NULL);
- g_return_val_if_fail (delimiter[0] != '\0', NULL);
-
- enumeration = eel_enumeration_new (id);
-
- namev = g_strsplit (names, delimiter, -1);
- valuev = g_strsplit (values, delimiter, -1);
-
- length = g_strv_length (namev);
- if (g_strv_length (valuev) != length)
- {
- g_warning ("names and values have different lengths.");
- g_strfreev (namev);
- g_strfreev (valuev);
- return NULL;
- }
-
- descriptionv = descriptions != NULL ?
- g_strsplit (descriptions, delimiter, -1) : NULL;
-
- if (descriptionv != NULL)
- {
- if (g_strv_length (descriptionv) != length)
- {
- g_warning ("names and descriptions have different lengths.");
- g_strfreev (namev);
- g_strfreev (descriptionv);
- g_strfreev (valuev);
- return NULL;
- }
- }
-
- for (i = 0; i < length; i++)
- {
- EelEnumerationEntry *entry;
- int value;
-
- if (!eel_str_to_int (valuev[i], &value))
- {
- g_warning ("Could not convert value '%d' to an integer. Using 0.", i);
- value = 0;
- }
-
- entry = g_new0 (EelEnumerationEntry, 1);
- entry->name = namev[i];
- entry->description = descriptionv ? descriptionv[i] : NULL;
- entry->value = value;
-
- g_ptr_array_add (enumeration->entries, entry);
- }
-
- return enumeration;
-}
-
-static EelEnumerationEntry *
-dup_entry (const EelEnumerationEntry *entry)
-{
- EelEnumerationEntry *res;
-
- res = g_new0 (EelEnumerationEntry, 1);
- res->name = g_strdup (entry->name);
- res->description = g_strdup (entry->description);
- res->value = entry->value;
-
- return res;
-}
-
-static EelEnumeration *
-eel_enumeration_new_from_entries (const char *id,
- const EelEnumerationEntry entries[],
- guint n_entries)
-{
- EelEnumeration *enumeration;
- guint i;
-
- g_assert (id != NULL);
- g_assert (id[0] != '\0');
- g_assert (entries != NULL);
-
- enumeration = eel_enumeration_new (id);
-
- for (i = 0; i < n_entries; i++)
- {
- g_ptr_array_add (enumeration->entries, dup_entry (&entries[i]));
- }
-
- return enumeration;
-}
-
-static GHashTable *enumeration_table = NULL;
-
-static void
-enumeration_table_free (void)
-{
- if (enumeration_table != NULL)
- {
- g_hash_table_destroy (enumeration_table);
- enumeration_table = NULL;
- }
-}
-
-static GHashTable *
-enumeration_table_get (void)
-{
- if (enumeration_table != NULL)
- {
- return enumeration_table;
- }
-
- enumeration_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) eel_enumeration_free);
-
- eel_debug_call_at_shutdown (enumeration_table_free);
-
- return enumeration_table;
-}
-
-const EelEnumeration *
-eel_enumeration_lookup (const char *id)
-{
- GHashTable *table;
-
- g_return_val_if_fail (id != NULL, NULL);
- g_return_val_if_fail (id[0] != '\0', NULL);
-
- table = enumeration_table_get ();
- g_return_val_if_fail (table != NULL, NULL);
-
- return g_hash_table_lookup (table, id);
-}
-
-void
-eel_enumeration_register (const char *id,
- const EelEnumerationEntry entries[],
- guint n_entries)
-{
- GHashTable *table;
- EelEnumeration *enumeration;
-
- g_return_if_fail (id != NULL);
- g_return_if_fail (id[0] != '\0');
- g_return_if_fail (entries != NULL);
-
- table = enumeration_table_get ();
- g_return_if_fail (table != NULL);
-
- if (eel_enumeration_lookup (id) != NULL)
- {
- if (!suppress_duplicate_registration_warning)
- {
- g_warning ("Trying to register duplicate enumeration '%s'.", id);
- }
-
- return;
- }
-
- enumeration = eel_enumeration_new_from_entries (id, entries, n_entries);
-
- g_hash_table_insert (table, g_strdup (id), enumeration);
-}
-
-
-#if !defined (EEL_OMIT_SELF_CHECK)
-
-#define CHECK_ENUMERATION_ENTRY(enumeration, i, name, description, value) \
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_name_position (enumeration, name), i); \
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_value_for_name (enumeration, name), value); \
- EEL_CHECK_STRING_RESULT (g_strdup (eel_enumeration_get_name_for_value (enumeration, value)), name);
-
-static EelEnumerationEntry speed_tradeoff_enum_entries[] =
-{
- { "always", "Always", 10 },
- { "local_only", "Local Files Only", 20 },
- { "never", "Never", 30 }
-};
-
-static EelEnumerationEntry standard_zoom_levels_enum_entries[] =
-{
- { "smallest", "25%", 25 },
- { "smaller", "50%", 50 },
- { "small", "75%", 75 },
- { "standard", "100%", 100 },
- { "large", "150%", 150 },
- { "larger", "200%", 200 },
- { "largest", "400%", 400 }
-};
-
-static EelEnumerationEntry file_size_enum_entries[] =
-{
- { "102400", "100 K", 102400 },
- { "512000", "500 K", 512000 },
- { "1048576", "1 MB", 1048576 },
- { "3145728", "3 MB", 3145728 },
- { "5242880", "5 MB", 5242880 },
- { "10485760", "10 MB", 10485760 },
- { "104857600", "100 MB", 104857600 }
-};
-
-#define CHECK_REGISTERED_ENUMERATION(enumname) \
-G_STMT_START { \
- const EelEnumeration *e; \
- int i; \
- e = eel_enumeration_lookup (#enumname); \
- g_return_if_fail (e != NULL); \
- for (i = 0; i < G_N_ELEMENTS (enumname##_enum_entries); i++) { \
- CHECK_ENUMERATION_ENTRY (e, \
- i, \
- enumname##_enum_entries[i].name, \
- enumname##_enum_entries[i].description, \
- enumname##_enum_entries[i].value); \
- } \
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), i); \
-} G_STMT_END
-
-void
-eel_self_check_enumeration (void)
-{
- EelEnumeration *e;
- char **names;
-
- /***/
- e = eel_enumeration_new_from_tokens ("id",
- "single",
- NULL,
- "1",
- ",");
-
- CHECK_ENUMERATION_ENTRY (e, 0, "single", "", 1);
- EEL_CHECK_STRING_RESULT (eel_enumeration_get_id (e), "id");
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), 1);
- eel_enumeration_free (e);
-
- /***/
- e = eel_enumeration_new_from_tokens ("id",
- "apple,orange,banana",
- NULL,
- "1,2,3",
- ",");
-
- CHECK_ENUMERATION_ENTRY (e, 0, "apple", "", 1);
- CHECK_ENUMERATION_ENTRY (e, 1, "orange", "", 2);
- CHECK_ENUMERATION_ENTRY (e, 2, "banana", "", 3);
- EEL_CHECK_STRING_RESULT (eel_enumeration_get_id (e), "id");
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), 3);
- eel_enumeration_free (e);
-
- /***/
- e = eel_enumeration_new_from_tokens ("id",
- "foo",
- NULL,
- "666",
- ",");
- CHECK_ENUMERATION_ENTRY (e, 0, "foo", "", 666);
- EEL_CHECK_STRING_RESULT (eel_enumeration_get_id (e), "id");
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), 1);
- eel_enumeration_free (e);
-
- /***/
- e = eel_enumeration_new_from_tokens ("id",
- "one,two,---,three",
- "One,Two,---,Three",
- "1,2,0,3",
- ",");
- CHECK_ENUMERATION_ENTRY (e, 0, "one", "One", 1);
- CHECK_ENUMERATION_ENTRY (e, 1, "two", "Two", 2);
- CHECK_ENUMERATION_ENTRY (e, 2, "---", "---", 0);
- CHECK_ENUMERATION_ENTRY (e, 3, "three", "Three", 3);
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), 4);
- eel_enumeration_free (e);
-
- /***/
- e = eel_enumeration_new_from_tokens ("id",
- "red,green,blue",
- "Red Desc,Green Desc,Blue Desc",
- "10,20,30",
- ",");
-
- CHECK_ENUMERATION_ENTRY (e, 0, "red", "Red Desc", 10);
- CHECK_ENUMERATION_ENTRY (e, 1, "green", "Green Desc", 20);
- CHECK_ENUMERATION_ENTRY (e, 2, "blue", "Blue Desc", 30);
- EEL_CHECK_STRING_RESULT (eel_enumeration_get_id (e), "id");
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), 3);
-
- EEL_CHECK_BOOLEAN_RESULT (eel_enumeration_contains_name (e, "red"), TRUE);
- EEL_CHECK_BOOLEAN_RESULT (eel_enumeration_contains_name (e, "green"), TRUE);
- EEL_CHECK_BOOLEAN_RESULT (eel_enumeration_contains_name (e, "blue"), TRUE);
- EEL_CHECK_BOOLEAN_RESULT (eel_enumeration_contains_name (e, "pink"), FALSE);
-
- eel_enumeration_free (e);
-
- /***/
- e = eel_enumeration_new_from_tokens ("id",
- "red,foo:green,bar:blue,baz",
- "Red,Desc:Green,Desc:Blue,Desc",
- "10:20:30",
- ":");
-
- CHECK_ENUMERATION_ENTRY (e, 0, "red,foo", "Red,Desc", 10);
- CHECK_ENUMERATION_ENTRY (e, 1, "green,bar", "Green,Desc", 20);
- CHECK_ENUMERATION_ENTRY (e, 2, "blue,baz", "Blue,Desc", 30);
- EEL_CHECK_STRING_RESULT (eel_enumeration_get_id (e), "id");
- EEL_CHECK_INTEGER_RESULT (eel_enumeration_get_length (e), 3);
- EEL_CHECK_BOOLEAN_RESULT (eel_enumeration_contains_name (e, "black"), FALSE);
-
- names = eel_enumeration_get_names (e);
- EEL_CHECK_INTEGER_RESULT (strcmp(names[2], "blue,baz"), 0);
- g_strfreev (names);
- eel_enumeration_free (e);
-
- /***/
- suppress_duplicate_registration_warning = TRUE;
- eel_enumeration_register ("speed_tradeoff",
- speed_tradeoff_enum_entries,
- G_N_ELEMENTS (speed_tradeoff_enum_entries));
- eel_enumeration_register ("standard_zoom_levels",
- standard_zoom_levels_enum_entries,
- G_N_ELEMENTS (standard_zoom_levels_enum_entries));
- eel_enumeration_register ("file_size",
- file_size_enum_entries,
- G_N_ELEMENTS (file_size_enum_entries));
- suppress_duplicate_registration_warning = FALSE;
-
- CHECK_REGISTERED_ENUMERATION(speed_tradeoff);
- CHECK_REGISTERED_ENUMERATION(standard_zoom_levels);
- CHECK_REGISTERED_ENUMERATION(file_size);
-}
-
-#endif /* !EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-enumeration.h b/eel/eel-enumeration.h
deleted file mode 100644
index 72cad6b4..00000000
--- a/eel/eel-enumeration.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
-
- eel-enumeration.h: Enumeration data structure.
-
- Copyright (C) 2000 Eazel, Inc.
-
- This program 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.
-
- This program 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 this program; if not, write to the
- Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Author: Ramiro Estrugo <[email protected]>
-*/
-
-#ifndef EEL_ENUMERATION_H
-#define EEL_ENUMERATION_H
-
-#include <glib.h>
-
-/* Opaque EelEnumeration declaration. */
-typedef struct EelEnumeration EelEnumeration;
-
-typedef struct
-{
- char *name;
- char *description;
- guint value;
-} EelEnumerationEntry;
-
-char * eel_enumeration_get_id (const EelEnumeration *enumeration);
-
-guint eel_enumeration_get_length (const EelEnumeration *enumeration);
-const EelEnumerationEntry *
-eel_enumeration_get_nth_entry (const EelEnumeration *enumeration,
- guint n);
-int eel_enumeration_get_name_position (const EelEnumeration *enumeration,
- const char *name);
-gboolean eel_enumeration_contains_name (const EelEnumeration *enumeration,
- const char *name);
-guint eel_enumeration_get_value_for_name (const EelEnumeration *enumeration,
- const char *name);
-const char * eel_enumeration_get_name_for_value (const EelEnumeration *enumeration,
- int value);
-char ** eel_enumeration_get_names (const EelEnumeration *enumeration);
-
-void eel_enumeration_register (const char *id,
- const EelEnumerationEntry entries[],
- guint n_entries);
-const EelEnumeration *
-eel_enumeration_lookup (const char *id);
-
-#endif /* EEL_ENUMERATION_H */
-
diff --git a/eel/eel-lib-self-check-functions.h b/eel/eel-lib-self-check-functions.h
index e538178e..6c3e07d1 100644
--- a/eel/eel-lib-self-check-functions.h
+++ b/eel/eel-lib-self-check-functions.h
@@ -40,12 +40,10 @@ void eel_run_lib_self_checks (void);
#define EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro (eel_self_check_background) \
- macro (eel_self_check_enumeration) \
macro (eel_self_check_gdk_extensions) \
macro (eel_self_check_gdk_pixbuf_extensions) \
macro (eel_self_check_glib_extensions) \
- macro (eel_self_check_pango_extensions) \
- macro (eel_self_check_preferences) \
+ macro (eel_self_check_pango_extensions) \
macro (eel_self_check_string) \
/* Add new self-check functions to the list above this line. */
diff --git a/eel/eel-mateconf-extensions.c b/eel/eel-mateconf-extensions.c
deleted file mode 100644
index 43f5b8b2..00000000
--- a/eel/eel-mateconf-extensions.c
+++ /dev/null
@@ -1,687 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-
-/* eel-mateconf-extensions.c - Stuff to make MateConf easier to use.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- The Mate 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 Mate 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 Mate Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Authors: Ramiro Estrugo <[email protected]>
-*/
-
-#include <config.h>
-#include "eel-mateconf-extensions.h"
-
-#include "eel-debug.h"
-#include "eel-glib-extensions.h"
-#include "eel-stock-dialogs.h"
-#include "eel-string.h"
-#include "eel-i18n.h"
-
-#include <mateconf/mateconf-client.h>
-#include <mateconf/mateconf.h>
-
-static MateConfClient *global_mateconf_client = NULL;
-
-static void
-global_client_free (void)
-{
- if (global_mateconf_client == NULL)
- {
- return;
- }
-
- g_object_unref (global_mateconf_client);
- global_mateconf_client = NULL;
-}
-
-/* Public */
-MateConfClient *
-eel_mateconf_client_get_global (void)
-{
- /* Initialize mateconf if needed */
- if (!mateconf_is_initialized ())
- {
- char *argv[] = { "eel-preferences", NULL };
- GError *error = NULL;
-
- if (!mateconf_init (1, argv, &error))
- {
- if (eel_mateconf_handle_error (&error))
- {
- return NULL;
- }
- }
- }
-
- if (global_mateconf_client == NULL)
- {
- global_mateconf_client = mateconf_client_get_default ();
- eel_debug_call_at_shutdown (global_client_free);
- }
-
- return global_mateconf_client;
-}
-
-gboolean
-eel_mateconf_handle_error (GError **error)
-{
- char *message;
- static gboolean shown_dialog = FALSE;
-
- g_return_val_if_fail (error != NULL, FALSE);
-
- if (*error != NULL)
- {
- g_warning (_("MateConf error:\n %s"), (*error)->message);
- if (! shown_dialog)
- {
- shown_dialog = TRUE;
-
- message = g_strdup_printf (_("MateConf error: %s"),
- (*error)->message);
- eel_show_error_dialog (message,
- _("All further errors shown "
- "only on terminal."),
- NULL);
- g_free (message);
- }
- g_error_free (*error);
- *error = NULL;
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-void
-eel_mateconf_set_boolean (const char *key,
- gboolean boolean_value)
-{
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_bool (client, key, boolean_value, &error);
- eel_mateconf_handle_error (&error);
-}
-
-gboolean
-eel_mateconf_get_boolean (const char *key)
-{
- gboolean result;
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, FALSE);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, FALSE);
-
- result = mateconf_client_get_bool (client, key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- result = FALSE;
- }
-
- return result;
-}
-
-void
-eel_mateconf_set_integer (const char *key,
- int int_value)
-{
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_int (client, key, int_value, &error);
- eel_mateconf_handle_error (&error);
-}
-
-int
-eel_mateconf_get_integer (const char *key)
-{
- int result;
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, 0);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, 0);
-
- result = mateconf_client_get_int (client, key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- result = 0;
- }
-
- return result;
-}
-
-void
-eel_mateconf_set_string (const char *key,
- const char *string_value)
-{
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_string (client, key, string_value, &error);
- eel_mateconf_handle_error (&error);
-}
-
-char *
-eel_mateconf_get_string (const char *key)
-{
- char *result;
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, NULL);
-
- result = mateconf_client_get_string (client, key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- result = g_strdup ("");
- }
-
- return result;
-}
-
-void
-eel_mateconf_set_string_list (const char *key,
- const GSList *slist)
-{
- MateConfClient *client;
- GError *error;
-
- g_return_if_fail (key != NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- error = NULL;
- mateconf_client_set_list (client, key, MATECONF_VALUE_STRING,
- /* Need cast cause of MateConf api bug */
- (GSList *) slist,
- &error);
- eel_mateconf_handle_error (&error);
-}
-
-GSList *
-eel_mateconf_get_string_list (const char *key)
-{
- GSList *slist;
- MateConfClient *client;
- GError *error;
-
- g_return_val_if_fail (key != NULL, NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, NULL);
-
- error = NULL;
- slist = mateconf_client_get_list (client, key, MATECONF_VALUE_STRING, &error);
- if (eel_mateconf_handle_error (&error))
- {
- slist = NULL;
- }
-
- return slist;
-}
-
-void
-eel_mateconf_unset (const char *key)
-{
- MateConfClient *client;
- GError *error;
-
- g_return_if_fail (key != NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- error = NULL;
- mateconf_client_unset (client, key, &error);
- eel_mateconf_handle_error (&error);
-}
-
-gboolean
-eel_mateconf_is_default (const char *key)
-{
- gboolean result;
- MateConfValue *value;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, FALSE);
-
- value = mateconf_client_get_without_default (eel_mateconf_client_get_global (), key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- if (value != NULL)
- {
- mateconf_value_free (value);
- }
- return FALSE;
- }
-
- result = (value == NULL);
- eel_mateconf_value_free (value);
- return result;
-}
-
-gboolean
-eel_mateconf_key_is_writable (const char *key)
-{
- gboolean result;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, FALSE);
-
- result = mateconf_client_key_is_writable (eel_mateconf_client_get_global (), key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- return result;
- }
-
- return result;
-}
-
-gboolean
-eel_mateconf_monitor_add (const char *directory)
-{
- GError *error = NULL;
- MateConfClient *client;
-
- g_return_val_if_fail (directory != NULL, FALSE);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, FALSE);
-
- mateconf_client_add_dir (client,
- directory,
- MATECONF_CLIENT_PRELOAD_NONE,
- &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-eel_mateconf_monitor_remove (const char *directory)
-{
- GError *error = NULL;
- MateConfClient *client;
-
- if (directory == NULL)
- {
- return FALSE;
- }
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, FALSE);
-
- mateconf_client_remove_dir (client,
- directory,
- &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-void
-eel_mateconf_preload_cache (const char *directory,
- MateConfClientPreloadType preload_type)
-{
- GError *error = NULL;
- MateConfClient *client;
-
- if (directory == NULL)
- {
- return;
- }
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_preload (client,
- directory,
- preload_type,
- &error);
-
- eel_mateconf_handle_error (&error);
-}
-
-void
-eel_mateconf_suggest_sync (void)
-{
- MateConfClient *client;
- GError *error = NULL;
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_suggest_sync (client, &error);
- eel_mateconf_handle_error (&error);
-}
-
-MateConfValue*
-eel_mateconf_get_value (const char *key)
-{
- MateConfValue *value = NULL;
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, NULL);
-
- value = mateconf_client_get (client, key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- if (value != NULL)
- {
- mateconf_value_free (value);
- value = NULL;
- }
- }
-
- return value;
-}
-
-MateConfValue*
-eel_mateconf_get_default_value (const char *key)
-{
- MateConfValue *value = NULL;
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, NULL);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, NULL);
-
- value = mateconf_client_get_default_from_schema (client, key, &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- if (value != NULL)
- {
- mateconf_value_free (value);
- value = NULL;
- }
- }
-
- return value;
-}
-
-static gboolean
-simple_value_is_equal (const MateConfValue *a,
- const MateConfValue *b)
-{
- g_assert (a != NULL);
- g_assert (b != NULL);
-
- switch (a->type)
- {
- case MATECONF_VALUE_STRING:
- return eel_str_is_equal (mateconf_value_get_string (a),
- mateconf_value_get_string (b));
-
- case MATECONF_VALUE_INT:
- return mateconf_value_get_int (a) ==
- mateconf_value_get_int (b);
-
- case MATECONF_VALUE_FLOAT:
- return mateconf_value_get_float (a) ==
- mateconf_value_get_float (b);
-
- case MATECONF_VALUE_BOOL:
- return mateconf_value_get_bool (a) ==
- mateconf_value_get_bool (b);
- default:
- g_assert_not_reached ();
- }
-
- return FALSE;
-}
-
-gboolean
-eel_mateconf_value_is_equal (const MateConfValue *a,
- const MateConfValue *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 MATECONF_VALUE_STRING:
- case MATECONF_VALUE_INT:
- case MATECONF_VALUE_FLOAT:
- case MATECONF_VALUE_BOOL:
- return simple_value_is_equal (a, b);
- break;
-
- case MATECONF_VALUE_LIST:
- if (mateconf_value_get_list_type (a) !=
- mateconf_value_get_list_type (b))
- {
- return FALSE;
- }
-
- node_a = mateconf_value_get_list (a);
- node_b = mateconf_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
-eel_mateconf_value_free (MateConfValue *value)
-{
- if (value == NULL)
- {
- return;
- }
-
- mateconf_value_free (value);
-}
-
-guint
-eel_mateconf_notification_add (const char *key,
- MateConfClientNotifyFunc notification_callback,
- gpointer callback_data)
-{
- guint notification_id;
- MateConfClient *client;
- GError *error = NULL;
-
- g_return_val_if_fail (key != NULL, EEL_MATECONF_UNDEFINED_CONNECTION);
- g_return_val_if_fail (notification_callback != NULL, EEL_MATECONF_UNDEFINED_CONNECTION);
-
- client = eel_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, EEL_MATECONF_UNDEFINED_CONNECTION);
-
- notification_id = mateconf_client_notify_add (client,
- key,
- notification_callback,
- callback_data,
- NULL,
- &error);
-
- if (eel_mateconf_handle_error (&error))
- {
- if (notification_id != EEL_MATECONF_UNDEFINED_CONNECTION)
- {
- mateconf_client_notify_remove (client, notification_id);
- notification_id = EEL_MATECONF_UNDEFINED_CONNECTION;
- }
- }
-
- return notification_id;
-}
-
-void
-eel_mateconf_notification_remove (guint notification_id)
-{
- MateConfClient *client;
-
- if (notification_id == EEL_MATECONF_UNDEFINED_CONNECTION)
- {
- return;
- }
-
- client = eel_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_notify_remove (client, notification_id);
-}
-
-GSList *
-eel_mateconf_value_get_string_list (const MateConfValue *value)
-{
- GSList *result;
- const GSList *slist;
- const GSList *node;
- const char *string;
- const MateConfValue *next_value;
-
- if (value == NULL)
- {
- return NULL;
- }
-
- g_return_val_if_fail (value->type == MATECONF_VALUE_LIST, NULL);
- g_return_val_if_fail (mateconf_value_get_list_type (value) == MATECONF_VALUE_STRING, NULL);
-
- slist = mateconf_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 == MATECONF_VALUE_STRING, NULL);
- string = mateconf_value_get_string (next_value);
- result = g_slist_prepend (result, g_strdup (string));
- }
- return g_slist_reverse (result);
-}
-
-void
-eel_mateconf_value_set_string_list (MateConfValue *value,
- const GSList *string_list)
-{
- const GSList *node;
- MateConfValue *next_value;
- GSList *value_list;
-
- g_return_if_fail (value->type == MATECONF_VALUE_LIST);
- g_return_if_fail (mateconf_value_get_list_type (value) == MATECONF_VALUE_STRING);
-
- value_list = NULL;
- for (node = string_list; node != NULL; node = node->next)
- {
- next_value = mateconf_value_new (MATECONF_VALUE_STRING);
- mateconf_value_set_string (next_value, node->data);
- value_list = g_slist_append (value_list, next_value);
- }
-
- mateconf_value_set_list (value, value_list);
-
- for (node = value_list; node != NULL; node = node->next)
- {
- mateconf_value_free (node->data);
- }
- g_slist_free (value_list);
-}
-
diff --git a/eel/eel-mateconf-extensions.h b/eel/eel-mateconf-extensions.h
deleted file mode 100644
index 60554272..00000000
--- a/eel/eel-mateconf-extensions.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-
-/* eel-mateconf-extensions.h - Stuff to make MateConf easier to use.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- The Mate 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 Mate 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 Mate Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Authors: Ramiro Estrugo <[email protected]>
-*/
-
-#ifndef EEL_MATECONF_EXTENSIONS_H
-#define EEL_MATECONF_EXTENSIONS_H
-
-#include <glib.h>
-
-#include <mateconf/mateconf.h>
-#include <mateconf/mateconf-client.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define EEL_MATECONF_UNDEFINED_CONNECTION 0
-
- MateConfClient *eel_mateconf_client_get_global (void);
- gboolean eel_mateconf_handle_error (GError **error);
- void eel_mateconf_set_boolean (const char *key,
- gboolean boolean_value);
- gboolean eel_mateconf_get_boolean (const char *key);
- int eel_mateconf_get_integer (const char *key);
- void eel_mateconf_set_integer (const char *key,
- int int_value);
- char * eel_mateconf_get_string (const char *key);
- void eel_mateconf_set_string (const char *key,
- const char *string_value);
- GSList * eel_mateconf_get_string_list (const char *key);
- void eel_mateconf_set_string_list (const char *key,
- const GSList *string_list_value);
- void eel_mateconf_unset (const char *key);
- gboolean eel_mateconf_key_is_writable (const char *key);
- gboolean eel_mateconf_is_default (const char *key);
- gboolean eel_mateconf_monitor_add (const char *directory);
- gboolean eel_mateconf_monitor_remove (const char *directory);
- void eel_mateconf_preload_cache (const char *directory,
- MateConfClientPreloadType preload_type);
- void eel_mateconf_suggest_sync (void);
- MateConfValue* eel_mateconf_get_value (const char *key);
- MateConfValue* eel_mateconf_get_default_value (const char *key);
- gboolean eel_mateconf_value_is_equal (const MateConfValue *a,
- const MateConfValue *b);
- void eel_mateconf_value_free (MateConfValue *value);
- guint eel_mateconf_notification_add (const char *key,
- MateConfClientNotifyFunc notification_callback,
- gpointer callback_data);
- void eel_mateconf_notification_remove (guint notification_id);
- GSList * eel_mateconf_value_get_string_list (const MateConfValue *value);
- void eel_mateconf_value_set_string_list (MateConfValue *value,
- const GSList *string_list);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* EEL_MATECONF_EXTENSIONS_H */
diff --git a/eel/eel-preferences-builder.c b/eel/eel-preferences-builder.c
deleted file mode 100644
index 87ea530b..00000000
--- a/eel/eel-preferences-builder.c
+++ /dev/null
@@ -1,646 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-
-/* eel-preferences-glade.c - Some functions to connect a Glade-file to mateconf keys.
-
- Copyright (C) 2002 Jan Arne Petersen
-
- The Mate 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 Mate 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 Mate Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Authors: Jan Arne Petersen <[email protected]>
-*/
-
-#include <glib.h>
-
-#include <gtk/gtk.h>
-
-#include "eel-preferences.h"
-
-#define EEL_PREFERENCES_BUILDER_DATA_KEY "eel_preferences_builder_data_key"
-#define EEL_PREFERENCES_BUILDER_DATA_VALUE "eel_preferences_builder_data_value"
-#define EEL_PREFERENCES_BUILDER_DATA_MAP "eel_preferences_builder_data_map"
-#define EEL_PREFERENCES_BUILDER_DATA_WIDGETS "eel_preferences_builder_data_widgets"
-
-/* helper */
-
-static void
-eel_preferences_builder_combo_box_update (GtkComboBox *combo_box,
- gpointer value,
- GCallback change_callback)
-{
- GHashTable *map;
- int active;
- gpointer key;
-
- map = (GHashTable *) g_object_get_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_MAP);
- active = GPOINTER_TO_INT (g_hash_table_lookup (map, value));
-
- if (active == -1)
- {
- return;
- }
-
- key = g_object_get_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_KEY);
-
- g_signal_handlers_block_by_func (combo_box, change_callback, key);
- gtk_combo_box_set_active (combo_box, active);
- g_signal_handlers_unblock_by_func (combo_box, change_callback, key);
-}
-
-static void
-eel_preference_glade_never_sensitive (GtkWidget *widget, GtkStateType state)
-{
- gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE);
-}
-
-static void
-eel_preferences_builder_set_never_sensitive (GtkWidget *widget)
-{
- gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE);
- g_signal_connect (G_OBJECT (widget), "state_changed",
- G_CALLBACK (eel_preference_glade_never_sensitive),
- NULL);
-}
-
-/* bool preference */
-
-static void
-eel_preferences_builder_bool_toggled (GtkToggleButton *toggle_button,
- char *key)
-{
- eel_preferences_set_boolean (key, gtk_toggle_button_get_active (toggle_button));
-}
-
-static void
-eel_preferences_builder_bool_update (GtkToggleButton *toggle_button)
-{
- gboolean value;
- gpointer key;
-
- key = g_object_get_data (G_OBJECT (toggle_button), EEL_PREFERENCES_BUILDER_DATA_KEY);
-
- value = eel_preferences_get_boolean (key);
- g_signal_handlers_block_by_func (toggle_button, eel_preferences_builder_bool_toggled, key);
- gtk_toggle_button_set_active (toggle_button, value);
- g_signal_handlers_unblock_by_func (toggle_button, eel_preferences_builder_bool_toggled, key);
-}
-
-void
-eel_preferences_builder_connect_bool (GtkBuilder *builder,
- const char *component,
- const char *key)
-{
- GtkToggleButton *toggle_button;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (component != NULL);
- g_return_if_fail (key != NULL);
-
- toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, component));
- g_object_set_data_full (G_OBJECT (toggle_button), EEL_PREFERENCES_BUILDER_DATA_KEY,
- g_strdup (key), (GDestroyNotify) g_free);
-
- eel_preferences_add_callback_while_alive (key,
- (EelPreferencesCallback) eel_preferences_builder_bool_update,
- toggle_button, G_OBJECT (toggle_button));
-
- if (!eel_preferences_key_is_writable (key))
- {
- eel_preferences_builder_set_never_sensitive (GTK_WIDGET (toggle_button));
- }
-
- g_signal_connect (G_OBJECT (toggle_button), "toggled",
- G_CALLBACK (eel_preferences_builder_bool_toggled),
- g_object_get_data (G_OBJECT (toggle_button),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
-
- eel_preferences_builder_bool_update (toggle_button);
-}
-
-static void
-eel_preferences_builder_inverted_bool_toggled (GtkToggleButton *toggle_button,
- char *key)
-{
- eel_preferences_set_boolean (key, !gtk_toggle_button_get_active (toggle_button));
-}
-
-static void
-eel_preferences_builder_inverted_bool_update (GtkToggleButton *toggle_button)
-{
- gboolean value;
- gpointer key;
-
- key = g_object_get_data (G_OBJECT (toggle_button), EEL_PREFERENCES_BUILDER_DATA_KEY);
-
- value = eel_preferences_get_boolean (key);
- g_signal_handlers_block_by_func (toggle_button, eel_preferences_builder_bool_toggled, key);
- gtk_toggle_button_set_active (toggle_button, !value);
- g_signal_handlers_unblock_by_func (toggle_button, eel_preferences_builder_bool_toggled, key);
-}
-
-void
-eel_preferences_builder_connect_inverted_bool (GtkBuilder *builder,
- const char *component,
- const char *key)
-{
- GtkToggleButton *toggle_button;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (component != NULL);
- g_return_if_fail (key != NULL);
-
- toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, component));
- g_object_set_data_full (G_OBJECT (toggle_button), EEL_PREFERENCES_BUILDER_DATA_KEY,
- g_strdup (key), (GDestroyNotify) g_free);
-
- eel_preferences_add_callback_while_alive (key,
- (EelPreferencesCallback) eel_preferences_builder_inverted_bool_update,
- toggle_button, G_OBJECT (toggle_button));
-
- if (!eel_preferences_key_is_writable (key))
- {
- eel_preferences_builder_set_never_sensitive (GTK_WIDGET (toggle_button));
- }
-
- g_signal_connect (G_OBJECT (toggle_button), "toggled",
- G_CALLBACK (eel_preferences_builder_inverted_bool_toggled),
- g_object_get_data (G_OBJECT (toggle_button),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
-
- eel_preferences_builder_inverted_bool_update (toggle_button);
-}
-
-void
-eel_preferences_builder_connect_bool_slave (GtkBuilder *builder,
- const char *component,
- const char *key)
-{
- GtkToggleButton *toggle_button;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (component != NULL);
- g_return_if_fail (key != NULL);
-
- toggle_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, component));
-
- if (!eel_preferences_key_is_writable (key))
- {
- eel_preferences_builder_set_never_sensitive (GTK_WIDGET (toggle_button));
- }
-
- g_signal_connect_data (G_OBJECT (toggle_button), "toggled",
- G_CALLBACK (eel_preferences_builder_bool_toggled),
- g_strdup (key), (GClosureNotify) g_free, 0);
-}
-
-/* string enum (ComboBox) preference */
-
-static void
-eel_preferences_builder_string_enum_combo_box_changed (GtkComboBox *combo_box,
- char *key)
-{
- int active;
- char **values;
- int i;
-
- active = gtk_combo_box_get_active (combo_box);
- values = g_object_get_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_VALUE);
-
- i = 0;
- while (i < active && values[i] != NULL)
- {
- i++;
- }
-
- if (values[i] == NULL)
- {
- return;
- }
-
- eel_preferences_set (key, values[i]);
-}
-
-static void
-eel_preferences_builder_string_enum_combo_box_update (GtkComboBox *combo_box)
-{
- char *value;
-
- value = eel_preferences_get (g_object_get_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
-
- eel_preferences_builder_combo_box_update (combo_box, value,
- G_CALLBACK (eel_preferences_builder_string_enum_combo_box_changed));
-
- g_free (value);
-}
-
-void
-eel_preferences_builder_connect_string_enum_combo_box (GtkBuilder *builder,
- const char *component,
- const char *key,
- const char **values)
-{
- GtkWidget *combo_box;
- GHashTable *map;
- int i;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (component != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (values != NULL);
-
- combo_box = GTK_WIDGET (gtk_builder_get_object (builder, component));
-
- map = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
-
- for (i = 0; values[i] != NULL; i++)
- {
- g_hash_table_insert (map, g_strdup (values[i]), GINT_TO_POINTER (i));
- }
-
- g_object_set_data_full (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_MAP, map,
- (GDestroyNotify) g_hash_table_destroy);
- g_object_set_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_VALUE, values);
- g_object_set_data_full (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_KEY,
- g_strdup (key), (GDestroyNotify) g_free);
-
- eel_preferences_add_callback_while_alive (key,
- (EelPreferencesCallback) eel_preferences_builder_string_enum_combo_box_update,
- combo_box, G_OBJECT (combo_box));
-
- if (!eel_preferences_key_is_writable (key))
- {
- eel_preferences_builder_set_never_sensitive (GTK_WIDGET (combo_box));
- }
-
- g_signal_connect (G_OBJECT (combo_box), "changed",
- G_CALLBACK (eel_preferences_builder_string_enum_combo_box_changed),
- g_object_get_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_KEY));
-
- eel_preferences_builder_string_enum_combo_box_update (GTK_COMBO_BOX (combo_box));
-}
-
-void
-eel_preferences_builder_connect_string_enum_combo_box_slave (GtkBuilder *builder,
- const char *component,
- const char *key)
-{
- GtkWidget *combo_box;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (component != NULL);
- g_return_if_fail (key != NULL);
-
- combo_box = GTK_WIDGET (gtk_builder_get_object (builder, component));
-
- g_assert (g_object_get_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_MAP) != NULL);
-
- if (!eel_preferences_key_is_writable (key))
- {
- eel_preferences_builder_set_never_sensitive (GTK_WIDGET (combo_box));
- }
-
- g_signal_connect_data (G_OBJECT (combo_box), "changed",
- G_CALLBACK (eel_preferences_builder_string_enum_combo_box_changed),
- g_strdup (key), (GClosureNotify) g_free, 0);
-}
-
-
-/* int enum preference */
-
-static void
-eel_preferences_builder_uint_enum_changed (GtkComboBox *combo_box,
- char *key)
-{
- int active;
- GSList *value_list;
- int i;
-
- active = gtk_combo_box_get_active (combo_box);
- value_list = (GSList *) g_object_get_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_VALUE);
-
- i = 0;
- while (i < active && value_list->next != NULL)
- {
- i++;
- value_list = value_list->next;
- }
-
- eel_preferences_set_uint (key, GPOINTER_TO_UINT (value_list->data));
-}
-
-static void
-eel_preferences_builder_uint_enum_update (GtkComboBox *combo_box)
-{
- guint value;
-
- value = eel_preferences_get_uint (g_object_get_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
-
- eel_preferences_builder_combo_box_update (combo_box, GUINT_TO_POINTER (value),
- G_CALLBACK (eel_preferences_builder_uint_enum_changed));
-}
-
-void
-eel_preferences_builder_connect_uint_enum (GtkBuilder *builder,
- const char *component,
- const char *key,
- const guint *values,
- int num_values)
-{
- GHashTable *map;
- int i;
- guint value;
- GtkComboBox *combo_box;
- GSList *value_list;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (component != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (values != NULL);
-
- combo_box = GTK_COMBO_BOX (gtk_builder_get_object (builder, component));
-
- map = g_hash_table_new (g_direct_hash, g_direct_equal);
- value_list = NULL;
-
- for (i = 0; i < num_values; i++)
- {
- value = values[i];
- value_list = g_slist_append (value_list, GUINT_TO_POINTER (value));
- g_hash_table_insert (map, GUINT_TO_POINTER (value), GINT_TO_POINTER (i));
- }
-
- g_object_set_data_full (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_MAP, map,
- (GDestroyNotify) g_hash_table_destroy);
- g_object_set_data_full (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_VALUE, value_list,
- (GDestroyNotify) g_slist_free);
- g_object_set_data_full (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_KEY,
- g_strdup (key), (GDestroyNotify) g_free);
-
- if (!eel_preferences_key_is_writable (key))
- {
- eel_preferences_builder_set_never_sensitive (GTK_WIDGET (combo_box));
- }
-
- g_signal_connect (G_OBJECT (combo_box), "changed",
- G_CALLBACK (eel_preferences_builder_uint_enum_changed),
- g_object_get_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_KEY));
-
- eel_preferences_add_callback_while_alive (key,
- (EelPreferencesCallback) eel_preferences_builder_uint_enum_update,
- combo_box, G_OBJECT (combo_box));
-
- eel_preferences_builder_uint_enum_update (combo_box);
-}
-
-
-/* String Enum (RadioButton) preference */
-
-static void
-eel_preferences_builder_string_enum_radio_button_toggled (GtkToggleButton *toggle_button,
- char *key)
-{
- if (gtk_toggle_button_get_active (toggle_button) == FALSE)
- {
- return;
- }
-
- eel_preferences_set (key,
- g_object_get_data (G_OBJECT (toggle_button),
- EEL_PREFERENCES_BUILDER_DATA_VALUE));
-}
-
-static void
-eel_preferences_builder_string_enum_radio_button_update (GtkWidget *widget)
-{
- gpointer key;
- char *value;
- GHashTable *map;
- gpointer object;
-
- key = g_object_get_data (G_OBJECT (widget), EEL_PREFERENCES_BUILDER_DATA_KEY);
- value = eel_preferences_get (key);
- map = g_object_get_data (G_OBJECT (widget), EEL_PREFERENCES_BUILDER_DATA_MAP);
- object = g_hash_table_lookup (map, value);
- g_free (value);
- if (object == NULL)
- {
- return;
- }
-
- g_signal_handlers_block_by_func (widget,
- eel_preferences_builder_string_enum_radio_button_toggled,
- key);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (object), TRUE);
- g_signal_handlers_unblock_by_func (widget,
- eel_preferences_builder_string_enum_radio_button_toggled,
- key);
-}
-
-void
-eel_preferences_builder_connect_string_enum_radio_button (GtkBuilder *builder,
- const char **components,
- const char *key,
- const char **values)
-{
- GHashTable *map;
- int i;
- GtkWidget *widget;
- gboolean writable;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (components != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (values != NULL);
-
- map = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
-
- writable = eel_preferences_key_is_writable (key);
-
- widget = NULL;
- for (i = 0; components[i] != NULL && values[i] != NULL; i++)
- {
- widget = GTK_WIDGET (gtk_builder_get_object (builder, components[i]));
- g_hash_table_insert (map, g_strdup (values[i]), widget);
- if (i == 0)
- {
- g_object_set_data_full (G_OBJECT (widget),
- EEL_PREFERENCES_BUILDER_DATA_MAP, map,
- (GDestroyNotify) g_hash_table_destroy);
- }
- else
- {
- g_object_set_data (G_OBJECT (widget),
- EEL_PREFERENCES_BUILDER_DATA_MAP, map);
- }
- g_object_set_data_full (G_OBJECT (widget),
- EEL_PREFERENCES_BUILDER_DATA_VALUE, g_strdup (values[i]),
- (GDestroyNotify) g_free);
- g_object_set_data_full (G_OBJECT (widget),
- EEL_PREFERENCES_BUILDER_DATA_KEY, g_strdup (key),
- (GDestroyNotify) g_free);
-
- if (!writable)
- {
- eel_preferences_builder_set_never_sensitive (widget);
- }
-
- g_signal_connect (G_OBJECT (widget), "toggled",
- G_CALLBACK (eel_preferences_builder_string_enum_radio_button_toggled),
- g_object_get_data (G_OBJECT (widget),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
- }
-
- eel_preferences_add_callback_while_alive (key,
- (EelPreferencesCallback) eel_preferences_builder_string_enum_radio_button_update,
- widget, G_OBJECT (widget));
-
- eel_preferences_builder_string_enum_radio_button_update (widget);
-}
-
-
-/* list enum preference */
-
-static void
-eel_preferences_builder_list_enum_changed (GtkComboBox *combo_box,
- char *key)
-{
- GSList *widgets;
- int active;
- char **values;
- int i;
- GPtrArray *v;
-
- widgets = g_object_get_data (G_OBJECT (combo_box), EEL_PREFERENCES_BUILDER_DATA_WIDGETS);
-
- v = g_ptr_array_new ();
- for (; widgets != NULL; widgets = widgets->next)
- {
- active = gtk_combo_box_get_active (GTK_COMBO_BOX (widgets->data));
- values = g_object_get_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_VALUE);
-
- i = 0;
- while (i < active && values[i] != NULL)
- {
- i++;
- }
-
- if (values[i] != NULL)
- {
- g_ptr_array_add (v, values[i]);
- }
- }
- g_ptr_array_add (v, NULL);
-
- eel_preferences_set_string_array (key, (char **) v->pdata);
- g_ptr_array_free (v, TRUE);
-}
-
-static void
-eel_preferences_builder_list_enum_update (GtkWidget *widget)
-{
- char **values;
- GSList *components;
- int i;
-
- values = eel_preferences_get_string_array (g_object_get_data (G_OBJECT (widget),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
- components = g_object_get_data (G_OBJECT (widget), EEL_PREFERENCES_BUILDER_DATA_WIDGETS);
- for (i = 0; values[i] != NULL && components != NULL; i++, components = components->next)
- {
- eel_preferences_builder_combo_box_update (GTK_COMBO_BOX (components->data),
- values[i],
- G_CALLBACK (eel_preferences_builder_list_enum_changed));
- }
-
- g_strfreev (values);
-}
-
-void
-eel_preferences_builder_connect_list_enum (GtkBuilder *builder,
- const char **components,
- const char *key,
- const char **values)
-{
- GtkWidget *combo_box;
- GHashTable *map;
- int i;
- GSList *widgets;
- gboolean writable;
-
- g_return_if_fail (builder != NULL);
- g_return_if_fail (components != NULL);
- g_return_if_fail (key != NULL);
- g_return_if_fail (values != NULL);
-
- map = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
-
- for (i = 0; values[i] != NULL; i++)
- {
- g_hash_table_insert (map, g_strdup (values[i]), GINT_TO_POINTER (i));
- }
-
- writable = eel_preferences_key_is_writable (key);
-
- combo_box = NULL;
- widgets = NULL;
- for (i = 0; components[i] != NULL; i++)
- {
- combo_box = GTK_WIDGET (gtk_builder_get_object (builder, components[i]));
- widgets = g_slist_append (widgets, combo_box);
- if (i == 0)
- {
- g_object_set_data_full (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_MAP, map,
- (GDestroyNotify) g_hash_table_destroy);
- g_object_set_data_full (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_WIDGETS,
- widgets, (GDestroyNotify) g_slist_free);
- }
- else
- {
- g_object_set_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_MAP, map);
- g_object_set_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_WIDGETS, widgets);
- }
- g_object_set_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_VALUE, values);
- g_object_set_data_full (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_KEY, g_strdup (key),
- (GDestroyNotify) g_free);
-
- if (!writable)
- {
- eel_preferences_builder_set_never_sensitive (combo_box);
- }
-
- g_signal_connect (G_OBJECT (combo_box), "changed",
- G_CALLBACK (eel_preferences_builder_list_enum_changed),
- g_object_get_data (G_OBJECT (combo_box),
- EEL_PREFERENCES_BUILDER_DATA_KEY));
- }
-
- eel_preferences_add_callback_while_alive (key,
- (EelPreferencesCallback) eel_preferences_builder_list_enum_update,
- combo_box, G_OBJECT (combo_box));
-
- eel_preferences_builder_list_enum_update (combo_box);
-}
-
diff --git a/eel/eel-preferences.c b/eel/eel-preferences.c
deleted file mode 100644
index a60d0a9e..00000000
--- a/eel/eel-preferences.c
+++ /dev/null
@@ -1,1764 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-
-/* eel-preferences.c - Preference peek/poke/notify implementation.
-
- Copyright (C) 1999, 2000 Eazel, Inc.
-
- The Mate 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 Mate 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 Mate Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Authors: Ramiro Estrugo <[email protected]>
-*/
-
-#include <config.h>
-#include "eel-preferences.h"
-
-#include "eel-debug.h"
-#include "eel-mateconf-extensions.h"
-#include "eel-lib-self-check-functions.h"
-#include "eel-enumeration.h"
-#include "eel-glib-extensions.h"
-#include "eel-string.h"
-#include <mateconf/mateconf-client.h>
-#include <mateconf/mateconf.h>
-#include <gtk/gtk.h>
-
-/* An enumeration used for updating auto-storage variables in a type-specific way.
- * FIXME: there is another enumeration like this in eel-global-preferences.c,
- * used for different purposes but in a related way. Should we combine them?
- */
-typedef enum
-{
- PREFERENCE_BOOLEAN = 1,
- PREFERENCE_INTEGER,
- PREFERENCE_STRING,
- PREFERENCE_STRING_ARRAY,
- PREFERENCE_STRING_ARRAY_AS_QUARKS
-} PreferenceType;
-
-/*
- * PreferencesEntry:
- *
- * A structure to manage preference hash table nodes.
- * Preferences are hash tables. The hash key is the preference name
- * (a string). The hash value is a pointer of the following struct:
- */
-typedef struct
-{
- char *name;
- char *description;
- PreferenceType type;
- gboolean invisible;
- GList *callback_list;
- GList *auto_storage_list;
- int mateconf_connection_id;
- char *enumeration_id;
- MateConfValue *fallback;
-} PreferencesEntry;
-
-/*
- * PreferencesCallbackEntry:
- *
- * A structure to manage callback lists. A callback list is a GList.
- * The callback_data in each list node is a pointer to the following
- * struct:
- */
-typedef struct
-{
- EelPreferencesCallback callback;
- gpointer callback_data;
-} PreferencesCallbackEntry;
-
-static GHashTable *global_table = NULL;
-static char *storage_path = NULL;
-static gboolean initialized = FALSE;
-
-static void preferences_global_table_free (void);
-static char * preferences_key_make (const char *name);
-static void preferences_callback_entry_free (PreferencesCallbackEntry *callback_entry);
-static void preferences_entry_update_auto_storage (PreferencesEntry *entry);
-static PreferencesEntry *preferences_global_table_lookup_or_insert (const char *name);
-
-static int
-preferences_mateconf_value_get_int (const MateConfValue *value)
-{
- if (value == NULL)
- {
- return 0;
- }
- g_assert (value->type == MATECONF_VALUE_INT);
- return mateconf_value_get_int (value);
-}
-
-static gboolean
-preferences_mateconf_value_get_bool (const MateConfValue *value)
-{
- if (value == NULL)
- {
- return FALSE;
- }
- g_assert (value->type == MATECONF_VALUE_BOOL);
- return mateconf_value_get_bool (value);
-}
-
-static char *
-preferences_mateconf_value_get_string (const MateConfValue *value)
-{
- if (value == NULL)
- {
- return g_strdup ("");
- }
- g_assert (value->type == MATECONF_VALUE_STRING);
- return g_strdup (mateconf_value_get_string (value));
-}
-
-static char **
-preferences_mateconf_value_get_string_array (const MateConfValue *value)
-{
- GSList *slist, *l;
- GPtrArray *result;
-
- if (value == NULL)
- {
- return NULL;
- }
-
- g_assert (value->type == MATECONF_VALUE_LIST);
- g_assert (mateconf_value_get_list_type (value) == MATECONF_VALUE_STRING);
-
- slist = eel_mateconf_value_get_string_list (value);
-
- result = g_ptr_array_new ();
- for (l = slist; l != NULL; l = l->next)
- {
- g_ptr_array_add (result, l->data);
- }
- g_slist_free (slist);
- g_ptr_array_add (result, NULL);
-
- return (char **) g_ptr_array_free (result, FALSE);
-}
-
-static const char *
-preferences_peek_storage_path (void)
-{
- g_assert (storage_path != NULL);
-
- return storage_path;
-}
-
-static void
-preferences_set_storage_path (const char *new_storage_path)
-{
- g_assert (eel_strlen (new_storage_path) > 0);
-
- /* Make sure the path is indeed different */
- if (eel_str_is_equal (new_storage_path, storage_path))
- {
- return;
- }
-
- /* Free the preference hash table */
- preferences_global_table_free ();
-
- /* Stop monitoring the old path */
- eel_mateconf_monitor_remove (storage_path);
-
- g_free (storage_path);
- storage_path = g_strdup (new_storage_path);
-
- /* Start monitoring the new path */
- eel_mateconf_monitor_add (storage_path);
-}
-
-static gboolean
-preferences_is_initialized (void)
-{
- return initialized;
-}
-
-static MateConfValue *
-preferences_get_value (const char *name)
-{
- MateConfValue *result;
- char *key;
- PreferencesEntry *entry;
-
- g_assert (name != NULL);
- g_assert (preferences_is_initialized ());
-
- key = preferences_key_make (name);
- result = eel_mateconf_get_value (key);
- g_free (key);
-
- if (result == NULL)
- {
- entry = preferences_global_table_lookup_or_insert (name);
-
- if (entry->fallback)
- result = mateconf_value_copy (entry->fallback);
- }
-
- return result;
-}
-
-/* If the preference name begind with a "/", we interpret
- * it as a straight mateconf key. */
-static gboolean
-preferences_preference_is_mateconf_key (const char *name)
-{
- g_assert (name != NULL);
-
- if (eel_str_has_prefix (name, "/"))
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-static char *
-preferences_key_make (const char *name)
-{
- g_assert (name != NULL);
-
- if (!preferences_preference_is_mateconf_key (name))
- {
- return g_strdup (name);
- }
-
- /* Otherwise, we prefix it with the path */
- return g_strconcat (preferences_peek_storage_path (), "/",
- name, NULL);
-}
-
-/* Get default from schema or emergency fallback */
-static MateConfValue *
-preferences_get_default_value (const char *name)
-{
- MateConfValue *result;
- PreferencesEntry *entry;
- char *key;
-
- g_assert (name != NULL);
-
- key = preferences_key_make (name);
-
- result = eel_mateconf_get_default_value (key);
-
- g_free (key);
-
- if (result == NULL)
- {
- entry = preferences_global_table_lookup_or_insert (name);
- if (entry && entry->fallback)
- result = mateconf_value_copy (entry->fallback);
- }
-
- return result;
-}
-
-static int
-preferences_callback_entry_compare (gconstpointer a,
- gconstpointer b)
-{
- const PreferencesCallbackEntry *a_entry = a;
- const PreferencesCallbackEntry *b_entry = b;
-
- if (a_entry->callback < b_entry->callback)
- {
- return -1;
- }
-
- if (a_entry->callback > b_entry->callback)
- {
- return +1;
- }
-
- if (a_entry->callback_data < b_entry->callback_data)
- {
- return -1;
- }
-
- if (a_entry->callback_data > b_entry->callback_data)
- {
- return +1;
- }
-
- return 0;
-}
-
-/* Public preferences functions */
-
-gboolean
-eel_preferences_get_is_invisible (const char *name)
-{
- g_assert (name != NULL);
- g_assert (preferences_is_initialized ());
-
- return preferences_global_table_lookup_or_insert (name)->invisible;
-}
-
-void
-eel_preferences_set_is_invisible (const char *name,
- gboolean is_invisible)
-{
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- preferences_global_table_lookup_or_insert (name)->invisible = is_invisible;
-}
-
-void
-eel_preferences_set_boolean (const char *name,
- gboolean boolean_value)
-{
- char *key;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- key = preferences_key_make (name);
- eel_mateconf_set_boolean (key, boolean_value);
- g_free (key);
-
- eel_mateconf_suggest_sync ();
-}
-
-gboolean
-eel_preferences_get_boolean (const char *name)
-{
- gboolean result;
- MateConfValue *value;
-
- g_return_val_if_fail (name != NULL, 0);
- g_return_val_if_fail (preferences_is_initialized (), 0);
-
- value = preferences_get_value (name);
- result = preferences_mateconf_value_get_bool (value);
- eel_mateconf_value_free (value);
-
- return result;
-}
-
-void
-eel_preferences_set_integer (const char *name,
- int int_value)
-{
- char *key;
- int old_value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- key = preferences_key_make (name);
- old_value = eel_preferences_get_integer (name);
-
- if (int_value != old_value)
- {
- eel_mateconf_set_integer (key, int_value);
- }
- g_free (key);
-}
-
-int
-eel_preferences_get_integer (const char *name)
-{
- int result;
- MateConfValue *value;
-
- g_return_val_if_fail (name != NULL, 0);
- g_return_val_if_fail (preferences_is_initialized (), 0);
-
- value = preferences_get_value (name);
- result = preferences_mateconf_value_get_int (value);
- eel_mateconf_value_free (value);
-
- return result;
-}
-
-/* MateConf has no unsigned store, save as signed and cast */
-guint
-eel_preferences_get_uint (const char *name)
-{
- return (guint)eel_preferences_get_integer (name);
-}
-void
-eel_preferences_set_uint (const char *name,
- guint uint_value)
-{
- eel_preferences_set_integer (name, (int)uint_value);
-}
-
-guint
-eel_preferences_get_enum (const char *name)
-{
- guint ret_val;
- char *str_value;
- MateConfValue *value;
- const EelEnumeration *enumeration;
- PreferencesEntry *entry;
-
- g_return_val_if_fail (name != NULL, 0);
- g_return_val_if_fail (preferences_is_initialized (), 0);
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_return_val_if_fail (entry != NULL, 0);
-
- enumeration = eel_enumeration_lookup (entry->enumeration_id);
-
- if (!enumeration)
- {
- g_warning ("No enum entry for '%s' (%s)",
- name, entry->enumeration_id);
- return 0;
- }
-
- value = preferences_get_value (name);
- if (value->type == MATECONF_VALUE_INT) /* compatibility path */
- {
- ret_val = (guint)preferences_mateconf_value_get_int (value);
- eel_mateconf_value_free (value);
- return ret_val;
- }
-
- str_value = preferences_mateconf_value_get_string (value);
- eel_mateconf_value_free (value);
-
- if (str_value == NULL)
- {
- g_warning ("No key for '%s' at %s", str_value, name);
- return 0;
- }
-
- ret_val = eel_enumeration_get_value_for_name (enumeration, str_value);
-
- g_free (str_value);
-
- return ret_val;
-}
-
-void
-eel_preferences_set_enum (const char *name,
- guint int_value)
-{
- const char *str_value;
- const EelEnumeration *enumeration;
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_return_if_fail (entry != NULL);
-
- enumeration = eel_enumeration_lookup (entry->enumeration_id);
-
- if (!enumeration)
- {
- g_warning ("No enum entry for '%s' (%s)",
- name, entry->enumeration_id);
- return;
- }
-
- str_value = eel_enumeration_get_name_for_value (enumeration, int_value);
-
- if (str_value == NULL)
- {
- g_warning ("No enum match for '%d'", int_value);
- return;
- }
-
- eel_preferences_set (name, str_value);
-}
-
-void
-eel_preferences_set (const char *name,
- const char *string_value)
-{
- char *key;
- char *old_value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- key = preferences_key_make (name);
- old_value = eel_preferences_get (name);
-
- if (strcmp (string_value, old_value) != 0)
- {
- eel_mateconf_set_string (key, string_value);
- }
- g_free (key);
- g_free (old_value);
-}
-
-char *
-eel_preferences_get (const char *name)
-{
- char *result;
- MateConfValue *value;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (preferences_is_initialized (), NULL);
-
- value = preferences_get_value (name);
- result = preferences_mateconf_value_get_string (value);
- eel_mateconf_value_free (value);
-
- return result;
-}
-
-void
-eel_preferences_set_string_array (const char *name,
- char **strv_value)
-{
- GSList *slist;
- int i;
- char *key;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- slist = NULL;
- if (strv_value != NULL)
- {
- for (i = 0; strv_value[i] != NULL; i++)
- {
- slist = g_slist_prepend (slist, strv_value[i]);
- }
- slist = g_slist_reverse (slist);
- }
-
- key = preferences_key_make (name);
- eel_mateconf_set_string_list (key, slist);
- g_free (key);
-
- g_slist_free (slist);
-}
-
-static gboolean
-string_array_is_valid (char **strv, const char *enumeration_id)
-{
- guint i;
- gboolean res;
-
- g_assert (strv != NULL);
- g_assert (enumeration_id != NULL);
-
- res = TRUE;
- for (i = 0; strv[i] != NULL; i++)
- {
- const EelEnumeration *enumeration;
-
- enumeration = eel_enumeration_lookup (enumeration_id);
- if (!enumeration)
- {
- res = FALSE;
- break;
- }
-
- if (!eel_enumeration_contains_name (enumeration, strv[i]))
- {
- res = FALSE;
- break;
- }
- }
-
- return res;
-}
-
-char **
-eel_preferences_get_string_array (const char *name)
-{
- char **result;
- MateConfValue *value;
- PreferencesEntry *entry;
- MateConfValue *default_value;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (preferences_is_initialized (), NULL);
-
- value = preferences_get_value (name);
- result = preferences_mateconf_value_get_string_array (value);
- eel_mateconf_value_free (value);
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- /* No enumeration_id so we're done */
- if (entry->enumeration_id == NULL)
- {
- return result;
- }
-
- /* Do a sanity check on the validity of the values */
- if (string_array_is_valid (result, entry->enumeration_id))
- {
- return result;
- }
-
- /* Forget the bad value and use the default instead */
- g_strfreev (result);
-
- default_value = preferences_get_default_value (name);
- if (default_value)
- {
- result = preferences_mateconf_value_get_string_array (default_value);
- mateconf_value_free (default_value);
- }
-
- return result;
-}
-
-void
-eel_preferences_unset (const char *name)
-{
- char *key;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- key = preferences_key_make (name);
-
- eel_mateconf_unset (key);
-
- g_free (key);
-}
-
-gboolean
-eel_preferences_key_is_writable (const char *name)
-{
- gboolean result;
- char *key;
-
- g_return_val_if_fail (name != NULL, 0);
- g_return_val_if_fail (preferences_is_initialized (), 0);
-
- key = preferences_key_make (name);
- result = eel_mateconf_key_is_writable (key);
- g_free (key);
-
- return result;
-}
-
-/**
- * preferences_callback_entry_invoke_function
- *
- * A function that invokes a callback from the given struct. It is meant to be fed to
- * g_list_foreach ()
- * @data: The list data privately maintained by the GList.
- * @callback_data: The callback_data privately maintained by the GList.
- **/
-static void
-preferences_callback_entry_invoke_function (gpointer data,
- gpointer callback_data)
-{
- PreferencesCallbackEntry *callback_entry;
-
- g_assert (data != NULL);
-
- callback_entry = data;
-
- (* callback_entry->callback) (callback_entry->callback_data);
-}
-
-static void
-preferences_entry_invoke_callbacks (PreferencesEntry *entry)
-{
- g_assert (entry != NULL);
-
- /* Update the auto storage preferences */
- if (entry->auto_storage_list != NULL)
- {
- preferences_entry_update_auto_storage (entry);
- }
-
- /* Invoke callbacks for this entry if any */
- if (entry->callback_list != NULL)
- {
- g_list_foreach (entry->callback_list,
- preferences_callback_entry_invoke_function,
- NULL);
- }
-}
-
-static void
-update_auto_string (gpointer data, gpointer callback_data)
-{
- char **storage;
- const char *value;
-
- g_assert (data != NULL);
- g_assert (callback_data != NULL);
-
- storage = (char **)data;
- value = (const char *)callback_data;
-
- g_free (*storage);
- *(char **)storage = g_strdup (value);
-}
-
-static void
-update_auto_string_array (gpointer data, gpointer callback_data)
-{
- char ***storage;
- char **value;
-
- g_assert (data != NULL);
- g_assert (callback_data != NULL);
-
- storage = (char ***)data;
- value = (char **)callback_data;
-
- g_strfreev (*storage);
- *(char ***)storage = value ? g_strdupv (value) : NULL;
-}
-
-static void
-update_auto_string_array_as_quarks (gpointer data, gpointer callback_data)
-{
- GQuark **storage;
- char **value;
- int i = 0;
-
- g_assert (data != NULL);
- g_assert (callback_data != NULL);
-
- storage = (GQuark **)data;
- value = (char **)callback_data;
-
- g_free (*storage);
- *storage = g_new (GQuark, g_strv_length (value) + 1);
-
- if (value != NULL)
- {
- for (i = 0; value[i] != NULL; ++i)
- {
- (*storage)[i] = g_quark_from_string (value[i]);
- }
- }
- (*storage)[i] = 0;
-}
-
-static void
-update_auto_integer_or_boolean (gpointer data, gpointer callback_data)
-{
- g_assert (data != NULL);
-
- *(int *)data = GPOINTER_TO_INT (callback_data);
-}
-
-static void
-preferences_entry_update_auto_storage (PreferencesEntry *entry)
-{
- char *new_string_value;
- char **new_string_array_value;
- int new_int_value;
- guint new_uint_value;
- gboolean new_boolean_value;
-
- switch (entry->type)
- {
- case PREFERENCE_STRING:
- if (entry->enumeration_id != NULL)
- {
- new_uint_value = eel_preferences_get_enum (entry->name);
- g_list_foreach (entry->auto_storage_list,
- update_auto_integer_or_boolean,
- GINT_TO_POINTER (new_uint_value));
- }
- else
- {
- new_string_value = eel_preferences_get (entry->name);
- g_list_foreach (entry->auto_storage_list,
- update_auto_string,
- new_string_value);
- g_free (new_string_value);
- }
- break;
- case PREFERENCE_STRING_ARRAY:
- new_string_array_value = eel_preferences_get_string_array (entry->name);
- g_list_foreach (entry->auto_storage_list,
- update_auto_string_array,
- new_string_array_value);
- g_strfreev (new_string_array_value);
- break;
- case PREFERENCE_STRING_ARRAY_AS_QUARKS:
- new_string_array_value = eel_preferences_get_string_array (entry->name);
- g_list_foreach (entry->auto_storage_list,
- update_auto_string_array_as_quarks,
- new_string_array_value);
- g_strfreev (new_string_array_value);
- break;
- case PREFERENCE_INTEGER:
- new_int_value = eel_preferences_get_integer (entry->name);
- g_list_foreach (entry->auto_storage_list,
- update_auto_integer_or_boolean,
- GINT_TO_POINTER (new_int_value));
- break;
- case PREFERENCE_BOOLEAN:
- new_boolean_value = eel_preferences_get_boolean (entry->name);
- g_list_foreach (entry->auto_storage_list,
- update_auto_integer_or_boolean,
- GINT_TO_POINTER (new_boolean_value));
- break;
- default:
- g_warning ("unexpected preferences type %d in preferences_entry_update_auto_storage", entry->type);
- }
-}
-
-static void
-preferences_something_changed_notice (MateConfClient *client,
- guint connection_id,
- MateConfEntry *entry,
- gpointer notice_data)
-{
- g_assert (entry != NULL);
- g_assert (entry->key != NULL);
- g_assert (notice_data != NULL);
-
- preferences_entry_invoke_callbacks (notice_data);
-}
-
-static void
-preferences_entry_ensure_mateconf_connection (PreferencesEntry *entry)
-{
- char *key;
-
- /*
- * We install only one mateconf notification for each preference entry.
- * Otherwise, we would invoke the installed callbacks more than once
- * per registered callback.
- */
- if (entry->mateconf_connection_id != EEL_MATECONF_UNDEFINED_CONNECTION)
- {
- return;
- }
-
- g_assert (entry->name != NULL);
-
- key = preferences_key_make (entry->name);
-
- entry->mateconf_connection_id = eel_mateconf_notification_add (key,
- preferences_something_changed_notice,
- entry);
- g_free (key);
-
- g_assert (entry->mateconf_connection_id != EEL_MATECONF_UNDEFINED_CONNECTION);
-}
-
-/**
- * preferences_entry_add_callback
- *
- * Add a callback to a pref node. Callbacks are fired whenever
- * the pref value changes.
- * @preferences_entry: The hash node.
- * @callback: The user-supplied callback.
- * @callback_data: The user-supplied closure.
- **/
-static void
-preferences_entry_add_callback (PreferencesEntry *entry,
- EelPreferencesCallback callback,
- gpointer callback_data)
-{
- PreferencesCallbackEntry *callback_entry;
- GList *l;
-
- g_assert (entry != NULL);
- g_assert (callback != NULL);
-
- callback_entry = g_new0 (PreferencesCallbackEntry, 1);
- callback_entry->callback = callback;
- callback_entry->callback_data = callback_data;
-
- l = g_list_find_custom (entry->callback_list, callback_entry, preferences_callback_entry_compare);
- if (l == NULL)
- {
- entry->callback_list = g_list_append (entry->callback_list, callback_entry);
- preferences_entry_ensure_mateconf_connection (entry);
- }
- else
- {
- g_warning ("Trying to add a callback for %s that already exists.", entry->name);
- }
-}
-
-/**
- * preferences_entry_add_auto_storage
- *
- * Add an auto-storage variable to a pref node. The variable will
- * be updated to match the pref value whenever the pref
- * the pref value changes.
- * @preferences_entry: The hash node.
- * @storage: The user-supplied location at which to store the value.
- * @type: Which type of variable this is.
- **/
-static void
-preferences_entry_add_auto_storage (PreferencesEntry *entry,
- gpointer storage,
- PreferenceType type)
-{
- g_assert (entry != NULL);
- g_assert (storage != NULL);
- g_assert (entry->type == 0 || entry->type == type);
- if (g_list_find (entry->auto_storage_list, storage) != NULL)
- {
- g_warning ("Trying to add an auto storage for %s that already exists.", entry->name);
- return;
- }
-
- entry->type = type;
-
- entry->auto_storage_list = g_list_append (entry->auto_storage_list, storage);
-
- preferences_entry_ensure_mateconf_connection (entry);
-}
-
-static void
-preferences_entry_check_remove_connection (PreferencesEntry *entry)
-{
- /*
- * If there are no callbacks or auto-storage variables left in the entry,
- * remove the mateconf notification.
- */
- if (entry->callback_list != NULL || entry->auto_storage_list != NULL)
- {
- return;
- }
-
- eel_mateconf_notification_remove (entry->mateconf_connection_id);
- entry->mateconf_connection_id = EEL_MATECONF_UNDEFINED_CONNECTION;
-}
-
-/**
- * preferences_entry_remove_callback
- *
- * remove a callback from a pref entry. Both the callback and the callback_data must
- * match in order for a callback to be removed from the entry.
- * @preferences_entry: The hash entry.
- * @callback: The user-supplied callback.
- * @callback_data: The user-supplied closure.
- **/
-static void
-preferences_entry_remove_callback (PreferencesEntry *entry,
- EelPreferencesCallback callback,
- gpointer callback_data)
-{
- PreferencesCallbackEntry cb_entry;
- GList *l;
-
- g_assert (entry != NULL);
- g_assert (callback != NULL);
-
- cb_entry.callback = callback;
- cb_entry.callback_data = callback_data;
-
- l = g_list_find_custom (entry->callback_list, &cb_entry, preferences_callback_entry_compare);
- if (l != NULL)
- {
- preferences_callback_entry_free (l->data);
- entry->callback_list = g_list_delete_link (entry->callback_list, l);
- preferences_entry_check_remove_connection (entry);
- }
- else
- {
- g_warning ("Trying to remove a callback for %s without adding it first.", entry->name);
- }
-
- g_assert (g_list_find_custom (entry->callback_list, &cb_entry, preferences_callback_entry_compare) == NULL);
-}
-
-/**
- * preferences_entry_remove_auto_storage
- *
- * remove an auto-storage variable from a pref entry.
- * @preferences_entry: The hash entry.
- * @storage: The user-supplied location.
- **/
-static void
-preferences_entry_remove_auto_storage (PreferencesEntry *entry,
- gpointer storage)
-{
- GList *new_list;
- const GList *node;
- gpointer storage_in_entry;
-
- g_assert (entry != NULL);
- g_assert (storage != NULL);
- g_assert (entry->auto_storage_list != NULL);
-
- new_list = g_list_copy (entry->auto_storage_list);
-
- for (node = new_list; node != NULL; node = node->next)
- {
- storage_in_entry = node->data;
-
- g_assert (storage_in_entry != NULL);
-
- if (storage_in_entry == storage)
- {
- entry->auto_storage_list = g_list_remove (entry->auto_storage_list,
- storage);
-
- switch (entry->type)
- {
- case PREFERENCE_STRING:
- update_auto_string (storage, NULL);
- break;
- case PREFERENCE_STRING_ARRAY:
- update_auto_string_array (storage, NULL);
- break;
- case PREFERENCE_STRING_ARRAY_AS_QUARKS:
- update_auto_string_array_as_quarks (storage, NULL);
- break;
- case PREFERENCE_BOOLEAN:
- case PREFERENCE_INTEGER:
- update_auto_integer_or_boolean (storage, NULL);
- break;
- default:
- g_warning ("unexpected preference type %d in preferences_entry_remove_auto_storage", entry->type);
- }
- }
- }
-
- g_list_free (new_list);
-
- preferences_entry_check_remove_connection (entry);
-}
-
-/**
- * preferences_callback_entry_free
- *
- * Free a callback info struct.
- * @preferences_callback_entry: The struct to free.
- **/
-static void
-preferences_callback_entry_free (PreferencesCallbackEntry *callback_entry)
-{
- g_assert (callback_entry != NULL);
-
- callback_entry->callback = NULL;
- callback_entry->callback_data = NULL;
-
- g_free (callback_entry);
-}
-
-/**
- * preferences_callback_entry_free_func
- *
- * A function that frees a callback info struct. It is meant to be fed to
- * g_list_foreach ()
- * @data: The list data privately maintained by the GList.
- * @callback_data: The callback_data privately maintained by the GList.
- **/
-static void
-preferences_callback_entry_free_func (gpointer data,
- gpointer callback_data)
-{
- g_assert (data != NULL);
-
- preferences_callback_entry_free (data);
-}
-
-/**
- * preferences_entry_free
- *
- * Free a preference hash node's members along with the node itself.
- * @preferences_hash_node: The node to free.
- **/
-static void
-preferences_entry_free (PreferencesEntry *entry)
-{
- g_assert (entry != NULL);
-
- eel_mateconf_notification_remove (entry->mateconf_connection_id);
- entry->mateconf_connection_id = EEL_MATECONF_UNDEFINED_CONNECTION;
-
- g_list_free (entry->auto_storage_list);
- eel_g_list_free_deep_custom (entry->callback_list,
- preferences_callback_entry_free_func,
- NULL);
-
- entry->auto_storage_list = NULL;
- entry->callback_list = NULL;
-
- g_free (entry->name);
- g_free (entry->description);
- g_free (entry->enumeration_id);
-
- eel_mateconf_value_free (entry->fallback);
-
- g_free (entry);
-}
-
-/**
- * preferences_entry_free_func
- *
- * A function that frees a pref hash node. It is meant to be fed to
- * g_hash_table_foreach ()
- * @key: The hash key privately maintained by the GHashTable.
- * @value: The hash value privately maintained by the GHashTable.
- * @callback_data: The callback_data privately maintained by the GHashTable.
- **/
-static void
-preferences_entry_free_func (gpointer key,
- gpointer value,
- gpointer callback_data)
-{
- g_assert (value != NULL);
-
- preferences_entry_free (value);
-}
-
-static void
-preferences_global_table_free (void)
-{
- if (global_table == NULL)
- {
- return;
- }
-
- g_hash_table_foreach (global_table, preferences_entry_free_func, NULL);
- g_hash_table_destroy (global_table);
- global_table = NULL;
-
- g_free (storage_path);
- storage_path = NULL;
-}
-
-static void
-preferences_uninitialize (void)
-{
- initialized = FALSE;
-}
-
-static GHashTable *
-preferences_global_table_get_global (void)
-{
- static gboolean at_exit_handler_added = FALSE;
-
- if (global_table == NULL)
- {
- global_table = g_hash_table_new (g_str_hash, g_str_equal);
-
- if (!at_exit_handler_added)
- {
- at_exit_handler_added = TRUE;
- eel_debug_call_at_shutdown (preferences_global_table_free);
- /* ensure that we catch calls to preferences functions after eel shutdown */
- eel_debug_call_at_shutdown (preferences_uninitialize);
- }
- }
-
- return global_table;
-}
-
-static PreferencesEntry *
-preferences_global_table_lookup (const char *name)
-{
- g_assert (name != NULL);
- g_assert (preferences_global_table_get_global () != NULL);
-
- return g_hash_table_lookup (preferences_global_table_get_global (), name);
-}
-
-static PreferencesEntry *
-preferences_global_table_insert (const char *name)
-{
- PreferencesEntry *entry;
-
- g_assert (name != NULL);
- g_assert (preferences_global_table_get_global () != NULL);
- g_assert (preferences_global_table_lookup (name) == NULL);
-
- entry = g_new0 (PreferencesEntry, 1);
- entry->name = g_strdup (name);
-
- g_hash_table_insert (preferences_global_table_get_global (), entry->name, entry);
-
- g_assert (entry == preferences_global_table_lookup (name));
-
- return entry;
-}
-
-static PreferencesEntry *
-preferences_global_table_lookup_or_insert (const char *name)
-{
- PreferencesEntry *entry;
-
- g_assert (name != NULL);
-
- entry = preferences_global_table_lookup (name);
-
- if (entry != NULL)
- {
- return entry;
- }
-
- entry = preferences_global_table_insert (name);
- g_assert (entry != NULL);
-
- return entry;
-}
-
-void
-eel_preferences_add_callback (const char *name,
- EelPreferencesCallback callback,
- gpointer callback_data)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (callback != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- preferences_entry_add_callback (entry, callback, callback_data);
-}
-
-void
-eel_preferences_add_auto_string (const char *name,
- const char **storage)
-{
- PreferencesEntry *entry;
- char *value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- preferences_entry_add_auto_storage (entry, storage, PREFERENCE_STRING);
-
- value = eel_preferences_get (entry->name);
- update_auto_string (storage, value);
- g_free (value);
-}
-
-void
-eel_preferences_add_auto_string_array (const char *name,
- char ***storage)
-{
- PreferencesEntry *entry;
- char **value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- preferences_entry_add_auto_storage (entry, storage, PREFERENCE_STRING_ARRAY);
-
- value = eel_preferences_get_string_array (entry->name);
- update_auto_string_array (storage, value);
- g_strfreev (value);
-}
-
-void
-eel_preferences_add_auto_string_array_as_quarks (const char *name,
- GQuark **storage)
-{
- PreferencesEntry *entry;
- char **value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- preferences_entry_add_auto_storage (entry, storage, PREFERENCE_STRING_ARRAY_AS_QUARKS);
-
- value = eel_preferences_get_string_array (entry->name);
- update_auto_string_array_as_quarks (storage, value);
- g_strfreev (value);
-}
-
-void
-eel_preferences_add_auto_integer (const char *name,
- int *storage)
-{
- PreferencesEntry *entry;
- int value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- preferences_entry_add_auto_storage (entry, storage, PREFERENCE_INTEGER);
-
- value = eel_preferences_get_integer (entry->name);
- update_auto_integer_or_boolean (storage, GINT_TO_POINTER (value));
-}
-
-
-void
-eel_preferences_add_auto_enum (const char *name,
- guint *storage)
-{
- PreferencesEntry *entry;
- guint value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
- g_assert (entry->enumeration_id != NULL);
-
- preferences_entry_add_auto_storage (entry, storage, PREFERENCE_STRING);
-
- value = eel_preferences_get_enum (entry->name);
- update_auto_integer_or_boolean (storage, GINT_TO_POINTER (value));
-}
-
-void
-eel_preferences_add_auto_boolean (const char *name,
- gboolean *storage)
-{
- PreferencesEntry *entry;
- gboolean value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- preferences_entry_add_auto_storage (entry, storage, PREFERENCE_BOOLEAN);
-
- value = eel_preferences_get_boolean (entry->name);
- update_auto_integer_or_boolean (storage, GINT_TO_POINTER (value));
-}
-
-void
-eel_preferences_remove_auto_string (const char *name,
- const char **storage)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup (name);
- if (entry == NULL)
- {
- g_warning ("Trying to remove auto-string for %s without adding it first.", name);
- return;
- }
-
- preferences_entry_remove_auto_storage (entry, storage);
-}
-
-void
-eel_preferences_remove_auto_string_array (const char *name,
- char ***storage)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup (name);
- if (entry == NULL)
- {
- g_warning ("Trying to remove auto-string for %s without adding it first.", name);
- return;
- }
-
- preferences_entry_remove_auto_storage (entry, storage);
-}
-
-void
-eel_preferences_remove_auto_integer (const char *name,
- int *storage)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup (name);
- if (entry == NULL)
- {
- g_warning ("Trying to remove auto-integer for %s without adding it first.", name);
- return;
- }
-
- preferences_entry_remove_auto_storage (entry, storage);
-}
-
-void
-eel_preferences_remove_auto_boolean (const char *name,
- gboolean *storage)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (storage != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup (name);
- if (entry == NULL)
- {
- g_warning ("Trying to remove auto-boolean for %s without adding it first.", name);
- return;
- }
-
- preferences_entry_remove_auto_storage (entry, storage);
-}
-
-typedef struct
-{
- char *name;
- EelPreferencesCallback callback;
- gpointer callback_data;
-} WhileAliveData;
-
-static void
-preferences_while_alive_disconnector (gpointer callback_data, GObject *where_object_was)
-{
- WhileAliveData *data;
-
- g_assert (callback_data != NULL);
-
- data = callback_data;
-
- /* we might have survived an eel shutdown, which
- * already cleared all the callbacks */
- if (preferences_is_initialized ())
- {
- eel_preferences_remove_callback (data->name,
- data->callback,
- data->callback_data);
- }
-
- g_free (data->name);
- g_free (data);
-}
-
-void
-eel_preferences_add_callback_while_alive (const char *name,
- EelPreferencesCallback callback,
- gpointer callback_data,
- GObject *alive_object)
-{
- WhileAliveData *data;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (callback != NULL);
- g_return_if_fail (G_IS_OBJECT (alive_object));
- g_return_if_fail (preferences_is_initialized ());
-
- data = g_new (WhileAliveData, 1);
- data->name = g_strdup (name);
- data->callback = callback;
- data->callback_data = callback_data;
-
- eel_preferences_add_callback (name, callback, callback_data);
-
- g_object_weak_ref (alive_object,
- preferences_while_alive_disconnector,
- data);
-}
-
-void
-eel_preferences_remove_callback (const char *name,
- EelPreferencesCallback callback,
- gpointer callback_data)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (callback != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup (name);
-
- if (entry == NULL)
- {
- g_warning ("Trying to remove a callback for %s without adding it first.", name);
- return;
- }
-
- preferences_entry_remove_callback (entry, callback, callback_data);
-}
-
-void
-eel_preferences_set_description (const char *name,
- const char *description)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (description != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- g_free (entry->description);
- entry->description = g_strdup (description);
-}
-
-char *
-eel_preferences_get_description (const char *name)
-{
- PreferencesEntry *entry;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (preferences_is_initialized (), NULL);
-
- entry = preferences_global_table_lookup_or_insert (name);
-
- return g_strdup (entry->description ? entry->description : "");
-}
-
-void
-eel_preferences_set_enumeration_id (const char *name,
- const char *enumeration_id)
-{
- PreferencesEntry *entry;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (enumeration_id != NULL);
- g_return_if_fail (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- g_free (entry->enumeration_id);
- entry->enumeration_id = g_strdup (enumeration_id);
-}
-
-char *
-eel_preferences_get_enumeration_id (const char *name)
-{
- PreferencesEntry *entry;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (preferences_is_initialized (), NULL);
-
- entry = preferences_global_table_lookup_or_insert (name);
-
- return g_strdup (entry->enumeration_id);
-}
-
-static void
-preferences_set_emergency_fallback_stealing_value (const char *name,
- MateConfValue *value)
-{
- PreferencesEntry *entry;
-
- g_assert (name != NULL);
- g_assert (preferences_is_initialized ());
-
- entry = preferences_global_table_lookup_or_insert (name);
- g_assert (entry != NULL);
-
- if (entry->fallback)
- mateconf_value_free (entry->fallback);
- entry->fallback = value; /* steal ownership of value */
-}
-
-void
-eel_preferences_set_emergency_fallback_string (const char *name,
- const char *value)
-{
- MateConfValue *mateconf_value;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (value != NULL);
-
- mateconf_value = mateconf_value_new (MATECONF_VALUE_STRING);
-
- mateconf_value_set_string (mateconf_value, value);
-
- preferences_set_emergency_fallback_stealing_value (name, mateconf_value);
-}
-
-void
-eel_preferences_set_emergency_fallback_integer (const char *name,
- int value)
-{
- MateConfValue *mateconf_value;
-
- g_return_if_fail (name != NULL);
-
- mateconf_value = mateconf_value_new (MATECONF_VALUE_INT);
-
- mateconf_value_set_int (mateconf_value, value);
-
- preferences_set_emergency_fallback_stealing_value (name, mateconf_value);
-}
-
-void
-eel_preferences_set_emergency_fallback_boolean (const char *name,
- gboolean value)
-{
- MateConfValue *mateconf_value;
-
- g_return_if_fail (name != NULL);
-
- mateconf_value = mateconf_value_new (MATECONF_VALUE_BOOL);
-
- mateconf_value_set_bool (mateconf_value, value);
-
- preferences_set_emergency_fallback_stealing_value (name, mateconf_value);
-}
-
-
-void
-eel_preferences_set_emergency_fallback_string_array (const char *name,
- char **value)
-{
- MateConfValue *mateconf_value;
- GSList *list;
- int i;
-
- g_return_if_fail (name != NULL);
- g_return_if_fail (value != NULL);
-
- mateconf_value = mateconf_value_new (MATECONF_VALUE_LIST);
- mateconf_value_set_list_type (mateconf_value, MATECONF_VALUE_STRING);
-
- list = NULL;
- for (i = 0; value[i] != NULL; ++i)
- {
- MateConfValue *v;
-
- v = mateconf_value_new (MATECONF_VALUE_STRING);
- mateconf_value_set_string (v, value[i]);
-
- list = g_slist_prepend (list, v);
- }
-
- mateconf_value_set_list_nocopy (mateconf_value, g_slist_reverse (list));
-
- preferences_set_emergency_fallback_stealing_value (name, mateconf_value);
-}
-
-MateConfValue*
-eel_preferences_get_emergency_fallback (const char *name)
-{
- PreferencesEntry *entry;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (preferences_is_initialized (), NULL);
-
- entry = preferences_global_table_lookup_or_insert (name);
-
- return entry->fallback ? mateconf_value_copy (entry->fallback) : NULL;
-}
-
-gboolean
-eel_preferences_monitor_directory (const char *directory)
-{
- g_return_val_if_fail (preferences_is_initialized (), FALSE);
-
- return eel_mateconf_monitor_add (directory);
-}
-
-gboolean
-eel_preferences_is_visible (const char *name)
-{
- g_return_val_if_fail (name != NULL, FALSE);
- g_return_val_if_fail (preferences_is_initialized (), FALSE);
-
- return !preferences_global_table_lookup_or_insert (name)->invisible;
-}
-
-void
-eel_preferences_init (const char *path)
-{
- g_return_if_fail (eel_strlen (path) > 0);
-
- if (initialized)
- {
- return;
- }
-
- initialized = TRUE;
-
- preferences_set_storage_path (path);
-}
-
-#if !defined (EEL_OMIT_SELF_CHECK)
-
-#define CHECK_BOOLEAN(name__, value__) \
-G_STMT_START { \
- eel_preferences_set_boolean ((name__), (value__)); \
- EEL_CHECK_BOOLEAN_RESULT (eel_preferences_get_boolean (name__), (value__)); \
-} G_STMT_END
-
-#define CHECK_INTEGER(name__, value__) \
-G_STMT_START { \
- eel_preferences_set_integer ((name__), (value__)); \
- EEL_CHECK_INTEGER_RESULT (eel_preferences_get_integer (name__), (value__)); \
-} G_STMT_END
-
-#define CHECK_STRING(name__, value__) \
-G_STMT_START { \
- eel_preferences_set ((name__), (value__)); \
- EEL_CHECK_STRING_RESULT (eel_preferences_get (name__), (value__)); \
-} G_STMT_END
-
-void
-eel_self_check_preferences (void)
-{
- /* Disabled until I can debug why these seemingly harmless tests
- * dont work. -re
- */
-#if 0
- int original_user_level;
-
- original_user_level = eel_preferences_get_user_level ();
-
- EEL_CHECK_INTEGER_RESULT (eel_preferences_get_integer ("self-check/neverset/i"), 0);
- EEL_CHECK_STRING_RESULT (eel_preferences_get ("self-check/neverset/s"), "");
- EEL_CHECK_BOOLEAN_RESULT (eel_preferences_get_boolean ("self-check/neverset/b"), FALSE);
-
- eel_preferences_set_user_level (0);
-
- /* FIXME: Fails if you add the commented-out lines. */
- /* CHECK_INTEGER ("self-check/i", 0); */
- CHECK_INTEGER ("self-check/i", 666);
- /* CHECK_BOOLEAN ("self-check/b", FALSE); */
- CHECK_BOOLEAN ("self-check/b", TRUE);
- /* CHECK_STRING ("self-check/s", ""); */
- CHECK_STRING ("self-check/s", "foo");
-
- /* Restore the original user level */
- eel_preferences_set_user_level (original_user_level);
-#endif
-}
-
-#endif /* !EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-preferences.h b/eel/eel-preferences.h
deleted file mode 100644
index 75fbeaf5..00000000
--- a/eel/eel-preferences.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-
-/* eel-preferences.c - Preference peek/poke/notify interface.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Mate 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 Mate 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 Mate Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- Authors: Ramiro Estrugo <[email protected]>
-*/
-
-#ifndef EEL_PREFERENCES_H
-#define EEL_PREFERENCES_H
-
-#include <glib.h>
-
-#include <eel/eel-mateconf-extensions.h>
-#include <gtk/gtk.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- /*
- * A callback which you can register to to be notified when a particular
- * preference changes.
- */
- typedef void (*EelPreferencesCallback) (gpointer callback_data);
-
- /* Preferences getters and setters */
- gboolean eel_preferences_get_boolean (const char *name);
- void eel_preferences_set_boolean (const char *name,
- gboolean boolean_value);
- int eel_preferences_get_integer (const char *name);
- void eel_preferences_set_integer (const char *name,
- int int_value);
- guint eel_preferences_get_uint (const char *name);
- void eel_preferences_set_uint (const char *name,
- guint uint_value);
- guint eel_preferences_get_enum (const char *name);
- void eel_preferences_set_enum (const char *name,
- guint int_value);
- char * eel_preferences_get (const char *name);
- void eel_preferences_set (const char *name,
- const char *string_value);
- char ** eel_preferences_get_string_array (const char *name);
- void eel_preferences_set_string_array (const char *name,
- char **strv_value);
-
- void eel_preferences_unset (const char *name);
-
- /* Writability of a key */
- gboolean eel_preferences_key_is_writable (const char *name);
-
- /* Callbacks */
- void eel_preferences_add_callback (const char *name,
- EelPreferencesCallback callback,
- gpointer callback_data);
- void eel_preferences_add_callback_while_alive (const char *name,
- EelPreferencesCallback callback,
- gpointer callback_data,
- GObject *alive_object);
- void eel_preferences_remove_callback (const char *name,
- EelPreferencesCallback callback,
- gpointer callback_data);
-
- /* Variables that are automatically updated (lightweight "callbacks") */
- void eel_preferences_add_auto_string (const char *name,
- const char **storage);
- void eel_preferences_add_auto_string_array (const char *name,
- char ***storage);
- void eel_preferences_add_auto_string_array_as_quarks (const char *name,
- GQuark **storage);
- void eel_preferences_add_auto_integer (const char *name,
- int *storage);
- void eel_preferences_add_auto_enum (const char *name,
- guint *storage);
- void eel_preferences_add_auto_boolean (const char *name,
- gboolean *storage);
- void eel_preferences_remove_auto_string (const char *name,
- const char **storage);
- void eel_preferences_remove_auto_string_array (const char *name,
- char ***storage);
- void eel_preferences_remove_auto_integer (const char *name,
- int *storage);
- void eel_preferences_remove_auto_boolean (const char *name,
- int *storage);
-
- /* Preferences attributes */
-
- gboolean eel_preferences_get_is_invisible (const char *name);
- void eel_preferences_set_is_invisible (const char *name,
- gboolean invisible);
- char * eel_preferences_get_description (const char *name);
- void eel_preferences_set_description (const char *name,
- const char *description);
- char * eel_preferences_get_enumeration_id (const char *name);
- void eel_preferences_set_enumeration_id (const char *name,
- const char *enumeration_id);
-
- void eel_preferences_set_emergency_fallback_string (const char *name,
- const char *value);
- void eel_preferences_set_emergency_fallback_integer (const char *name,
- int value);
- void eel_preferences_set_emergency_fallback_boolean (const char *name,
- gboolean value);
- void eel_preferences_set_emergency_fallback_string_array(const char *name,
- char **value);
- MateConfValue *eel_preferences_get_emergency_fallback (const char *name);
-
-
- gboolean eel_preferences_monitor_directory (const char *directory);
- gboolean eel_preferences_is_visible (const char *name);
- void eel_preferences_init (const char *storage_path);
-
- void eel_preferences_builder_connect_bool (GtkBuilder *builder,
- const char *component,
- const char *key);
- void eel_preferences_builder_connect_inverted_bool (GtkBuilder *builder,
- const char *component,
- const char *key);
- void eel_preferences_builder_connect_bool_slave (GtkBuilder *builder,
- const char *component,
- const char *key);
- void eel_preferences_builder_connect_string_enum_combo_box (GtkBuilder *builder,
- const char *component,
- const char *key,
- const char **values);
- void eel_preferences_builder_connect_string_enum_combo_box_slave (GtkBuilder *builder,
- const char *component,
- const char *key);
-
- void eel_preferences_builder_connect_uint_enum (GtkBuilder *builder,
- const char *component,
- const char *key,
- const guint *values,
- int num_values);
- void eel_preferences_builder_connect_string_enum_radio_button (GtkBuilder *builder,
- const char **components,
- const char *key,
- const char **values);
- void eel_preferences_builder_connect_list_enum (GtkBuilder *builder,
- const char **components,
- const char *key,
- const char **values);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* EEL_PREFERENCES_H */
diff --git a/eel/eel.h b/eel/eel.h
index 7af76e96..615958ca 100644
--- a/eel/eel.h
+++ b/eel/eel.h
@@ -28,8 +28,6 @@
#include <eel/eel-art-extensions.h>
#include <eel/eel-art-gtk-extensions.h>
#include <eel/eel-background.h>
-#include <eel/eel-enumeration.h>
-#include <eel/eel-mateconf-extensions.h>
#include <eel/eel-gdk-extensions.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <eel/eel-glib-extensions.h>
@@ -41,7 +39,6 @@
#include <eel/eel-image-table.h>
#include <eel/eel-labeled-image.h>
#include <eel/eel-pango-extensions.h>
-#include <eel/eel-preferences.h>
#include <eel/eel-self-checks.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>