From 3b87b68e10a2982de2bac68a5ab6cc5922c2c5c6 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Fri, 15 Jun 2001 22:44:54 +0000 Subject: New function. 2001-06-16 Martin Baulig * bonobo-config-ditem-utils.c (bonobo_config_ditem_get_subtype): New function. * bonobo-config-ditem.c (real_get_type): New static function; this uses bonobo_config_ditem_get_subtype() if we're accessing structure fields. (dir_lookup_entry, dir_lookup_subdir): Implemented `create'. --- libgnome-desktop/bonobo-config-ditem-utils.c | 24 ++++ libgnome-desktop/bonobo-config-ditem-utils.h | 5 + libgnome-desktop/bonobo-config-ditem.c | 80 +++++++++----- libgnome-desktop/test-ditem.c | 159 +++++++++++---------------- 4 files changed, 145 insertions(+), 123 deletions(-) diff --git a/libgnome-desktop/bonobo-config-ditem-utils.c b/libgnome-desktop/bonobo-config-ditem-utils.c index f5c0eb65..68a64c48 100644 --- a/libgnome-desktop/bonobo-config-ditem-utils.c +++ b/libgnome-desktop/bonobo-config-ditem-utils.c @@ -557,3 +557,27 @@ case CORBA_tk_ ## k: \ } } +CORBA_TypeCode +bonobo_config_ditem_get_subtype (BonoboConfigDItem *ditem, DirEntry *de, const gchar *path, + CORBA_TypeCode type, CORBA_Environment *ev) +{ + switch (type->kind) { + case CORBA_tk_struct: { + gulong i; + + for (i = 0; i < type->sub_parts; i++) + if (!strcmp (type->subnames [i], path)) + return type->subtypes [i]; + + break; + } + + default: + g_message (G_STRLOC ": |%s| => |%s| - %d - %s (%s)", path, de->name, + type->kind, type->name, type->repo_id); + + break; + } + + return CORBA_OBJECT_NIL; +} diff --git a/libgnome-desktop/bonobo-config-ditem-utils.h b/libgnome-desktop/bonobo-config-ditem-utils.h index 5c1f0a65..4e084782 100644 --- a/libgnome-desktop/bonobo-config-ditem-utils.h +++ b/libgnome-desktop/bonobo-config-ditem-utils.h @@ -24,6 +24,11 @@ bonobo_config_ditem_encode_any (BonoboConfigDItem *ditem, DirEntry *de, const gchar *path, const CORBA_any *any, CORBA_Environment *ev); +CORBA_TypeCode +bonobo_config_ditem_get_subtype (BonoboConfigDItem *ditem, DirEntry *de, + const gchar *path, CORBA_TypeCode type, + CORBA_Environment *ev); + G_END_DECLS #endif /* ! __BONOBO_CONFIG_DITEM_UTILS_H__ */ diff --git a/libgnome-desktop/bonobo-config-ditem.c b/libgnome-desktop/bonobo-config-ditem.c index 996d5539..238221c0 100644 --- a/libgnome-desktop/bonobo-config-ditem.c +++ b/libgnome-desktop/bonobo-config-ditem.c @@ -249,8 +249,6 @@ load (const char *file) Key->value = decode_string_and_dup (CharBuffer); state = c == '\n' ? KeyDef : IgnoreToEOL; next = CharBuffer; -#ifdef GNOME_ENABLE_DEBUG -#endif } else *next++ = c; break; @@ -345,20 +343,14 @@ dir_lookup_entry (Section *section, return de; } -#if 0 if (create) { - de = g_new0 (DirEntry, 1); - de->dir = dir; - de->name = g_strdup (name); - - dir->entries = g_slist_prepend (dir->entries, de); + section->root.subvalues = g_slist_prepend (section->root.subvalues, de); return de; } -#endif return NULL; } @@ -377,20 +369,16 @@ dir_lookup_subdir (Directory *dir, return section; } -#if 0 if (create) { + Section *section; - dd = g_new0 (DirData, 1); - - dd->dir = dir; - - dd->name = g_strdup (name); + section = g_new0 (Section, 1); + section->name = g_strdup (name); - dir->subdirs = g_slist_prepend (dir->subdirs, dd); + dir->sections = g_slist_prepend (dir->sections, section); - return dd; + return section; } -#endif return NULL; } @@ -466,6 +454,46 @@ lookup_dir_entry (BonoboConfigDItem *ditem, return de; } +static CORBA_TypeCode +real_get_type (BonoboConfigDatabase *db, + const CORBA_char *key, + CORBA_Environment *ev) +{ + BonoboConfigDItem *ditem = BONOBO_CONFIG_DITEM (db); + gchar *dir_name, *leaf_name; + DirEntry *de; + CORBA_any *default_value = NULL; + CORBA_TypeCode tc; + + de = lookup_dir_entry (ditem, key, FALSE); + if (!de) { + bonobo_exception_set (ev, ex_Bonobo_PropertyBag_NotFound); + return CORBA_OBJECT_NIL; + } + + default_value = Bonobo_ConfigDatabase_getDefault (BONOBO_OBJREF (db), key, ev); + if (!BONOBO_EX (ev) && default_value != NULL) + return default_value->_type; + + dir_name = bonobo_config_dir_name (key); + if (!dir_name) + return CORBA_OBJECT_NIL; + + leaf_name = bonobo_config_leaf_name (key); + if (!leaf_name) + return CORBA_OBJECT_NIL; + + CORBA_exception_init (ev); + + default_value = Bonobo_ConfigDatabase_getDefault (BONOBO_OBJREF (db), dir_name, ev); + if (BONOBO_EX (ev) || default_value == NULL) + return CORBA_OBJECT_NIL; + + tc = bonobo_config_ditem_get_subtype (ditem, de, leaf_name, default_value->_type, ev); + + return tc; +} + static CORBA_any * real_get_value (BonoboConfigDatabase *db, const CORBA_char *key, @@ -474,7 +502,6 @@ real_get_value (BonoboConfigDatabase *db, BonoboConfigDItem *ditem = BONOBO_CONFIG_DITEM (db); DirEntry *de; CORBA_TypeCode tc; - CORBA_any *default_value = NULL; CORBA_any *value = NULL; char *locale = NULL; @@ -486,14 +513,9 @@ real_get_value (BonoboConfigDatabase *db, return NULL; } - g_message (G_STRLOC ": (%s) - `%s' - `%s' - %p", key, de->name, de->value, - de->subvalues); - - default_value = Bonobo_ConfigDatabase_getDefault (BONOBO_OBJREF (db), key, ev); - if (BONOBO_EX (ev) || !default_value) - tc = TC_CORBA_string; - else - tc = default_value->_type; + tc = real_get_type (db, key, ev); + if (!tc) + return NULL; CORBA_exception_init (ev); @@ -796,6 +818,10 @@ bonobo_config_ditem_new (const char *filename) BONOBO_CONFIG_DATABASE (ditem)->writeable = TRUE; ditem->_priv->dir = load (ditem->filename); + if (!ditem->_priv->dir) { + ditem->_priv->dir = g_new0 (Directory, 1); + ditem->_priv->dir->path = g_strdup (ditem->filename); + } ditem->_priv->es = bonobo_event_source_new (); diff --git a/libgnome-desktop/test-ditem.c b/libgnome-desktop/test-ditem.c index 68f14eb4..929f2218 100644 --- a/libgnome-desktop/test-ditem.c +++ b/libgnome-desktop/test-ditem.c @@ -81,9 +81,34 @@ test_ditem (Bonobo_ConfigDatabase db) gnome_desktop_item_save (ditem, NULL); #endif - // gnome_desktop_item_save (ditem, "~/work/foo.desktop"); + gnome_desktop_item_save (ditem, "~/work/foo.desktop"); } +#if 0 +static void G_GNUC_UNUSED +test_builtin (void) +{ + Bonobo_ConfigDatabase db, parent_db; + CORBA_Environment ev; + CORBA_TypeCode type; + BonoboArg *value; + gchar *string; + + db = bonobo_config_ditem_new ("/home/martin/work/test.desktop"); + g_assert (db != CORBA_OBJECT_NIL); + + CORBA_exception_init (&ev); + parent_db = bonobo_get_object ("xmldb:~/work/foo.xmldb", "Bonobo/ConfigDatabase", &ev); + g_assert (!BONOBO_EX (&ev) && parent_db != CORBA_OBJECT_NIL); + CORBA_exception_free (&ev); + + CORBA_exception_init (&ev); + Bonobo_ConfigDatabase_addDatabase (db, parent_db, "", &ev); + g_assert (!BONOBO_EX (&ev)); + CORBA_exception_free (&ev); +} +#endif + int main (int argc, char **argv) { @@ -93,6 +118,7 @@ main (int argc, char **argv) CORBA_Environment ev; CORBA_TypeCode type; CORBA_any *value; + gchar *string; guint i, j; CORBA_exception_init (&ev); @@ -104,6 +130,8 @@ main (int argc, char **argv) bonobo_activate (); + // test_builtin (); + // db = bonobo_config_ditem_new ("~/work/test.desktop"); CORBA_exception_init (&ev); @@ -167,115 +195,54 @@ main (int argc, char **argv) CORBA_exception_free (&ev); CORBA_exception_init (&ev); - Bonobo_ConfigDatabase_sync (db, &ev); - CORBA_exception_free (&ev); + type = bonobo_pbclient_get_type (db, "/Foo/Test", &ev); + if (type) + g_message (G_STRLOC ": type is %d - %s (%s)", type->kind, type->name, type->repo_id); + CORBA_exception_free (&ev); CORBA_exception_init (&ev); - value = bonobo_pbclient_get_value (db, "/Desktop Entry", TC_GNOME_DesktopEntry, &ev); - g_message (G_STRLOC ": %p", value); - if (value) - printf ("got value as string (%s)\n", BONOBO_ARG_GET_STRING (value)); + value = bonobo_pbclient_get_value (db, "/Foo/Test", TC_CORBA_long, &ev); + if (value) { + g_message (G_STRLOC ": got value as long %d", BONOBO_ARG_GET_LONG (value)); + BONOBO_ARG_SET_LONG (value, 512); + bonobo_pbclient_set_value (db, "/Foo/Test", value, &ev); + } + bonobo_arg_release (value); CORBA_exception_free (&ev); CORBA_exception_init (&ev); - value = bonobo_pbclient_get_value (db, "/Desktop Entry", - TC_GNOME_LocalizedStringList, &ev); - g_message (G_STRLOC ": %p", value); - if (value) - printf ("got value as string (%s)\n", BONOBO_ARG_GET_STRING (value)); - CORBA_exception_free (&ev); - - exit (0); + type = bonobo_pbclient_get_type (db, "/Desktop Entry/Terminal", &ev); + if (type) + g_message (G_STRLOC ": type is %d - %s (%s)", type->kind, type->name, type->repo_id); + CORBA_exception_free (&ev); CORBA_exception_init (&ev); + type = bonobo_pbclient_get_type (db, "/Desktop Entry/Name", &ev); + if (type) + g_message (G_STRLOC ": type is %d - %s (%s)", type->kind, type->name, type->repo_id); + CORBA_exception_free (&ev); - value = bonobo_pbclient_get_value (db, "/storagetype", - TC_Bonobo_StorageType, &ev); - if (value) { - printf ("got value\n"); - } CORBA_exception_init (&ev); + type = bonobo_pbclient_get_type (db, "/Desktop Entry/URL", &ev); + if (type) + g_message (G_STRLOC ": type is %d - %s (%s)", type->kind, type->name, type->repo_id); + CORBA_exception_free (&ev); - value = bonobo_arg_new (TC_CORBA_long); - BONOBO_ARG_SET_LONG (value, 5); - - Bonobo_ConfigDatabase_setValue (db, "/test", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/test/level2", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/test/level21", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/test/level3/level3", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/bonobo/test1", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - value = bonobo_arg_new (TC_Bonobo_StorageType); - - Bonobo_ConfigDatabase_setValue (db, "/storagetype", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - value = bonobo_arg_new (TC_CORBA_string); - BONOBO_ARG_SET_STRING (value, "a simple test"); - Bonobo_ConfigDatabase_setValue (db, "a/b/c/d", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_removeDir (db, "/", &ev); - g_assert (!BONOBO_EX (&ev)); - - value = bonobo_arg_new (TC_CORBA_long); - BONOBO_ARG_SET_LONG (value, 5); - - Bonobo_ConfigDatabase_setValue (db, "/test", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/test/level2", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/test/level21", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - Bonobo_ConfigDatabase_setValue (db, "/test/level3/level3", value, &ev); - g_assert (!BONOBO_EX (&ev)); - - - value = bonobo_arg_new (TC_Bonobo_StorageType); - Bonobo_ConfigDatabase_setValue (db, "/storagetype", value, &ev); - g_assert (!BONOBO_EX (&ev)); + string = bonobo_pbclient_get_string (db, "/Desktop Entry/URL", NULL); + g_message (G_STRLOC ": |%s|", string); + bonobo_pbclient_set_string (db, "/Desktop Entry/URL", "http://www.gnome.org/", NULL); + CORBA_exception_init (&ev); Bonobo_ConfigDatabase_sync (db, &ev); g_assert (!BONOBO_EX (&ev)); + CORBA_exception_free (&ev); - - /* - { - BonoboConfigBag *config_bag; - Bonobo_Unknown bag, v; - char *name; - - config_bag = bonobo_config_bag_new (db, "/bonobo"); - - g_assert (config_bag); - - bag = BONOBO_OBJREF (config_bag); - - prop =Bonobo_PropertyBag_getPropertyByName (bag, "test1", &ev); - g_assert (!BONOBO_EX (&ev)); - - - printf("TEST3\n"); - name = Bonobo_Property_getName (prop, &ev); - printf("TEST3e %s\n", name); - g_assert (!BONOBO_EX (&ev)); - - - } - */ - + CORBA_exception_init (&ev); + value = bonobo_pbclient_get_value (db, "/Desktop Entry", TC_GNOME_DesktopEntry, &ev); + g_message (G_STRLOC ": %p", value); + if (value) + printf ("got value as GNOME::DesktopEntry\n"); + CORBA_exception_free (&ev); exit (0); } -- cgit v1.2.1