2 * Copyright (C) 2006-2007 Async Open Source,
3 * Johan Dahlin <jdahlin@async.com.br>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 #include "gtktypeutils.h"
27 #include "gtkbuilderprivate.h"
28 #include "gtkbuilder.h"
29 #include "gtkbuildable.h"
31 #include "gtkversion.h"
32 #include "gtktypeutils.h"
36 static void free_property_info (PropertyInfo *info);
37 static void free_object_info (ObjectInfo *info);
40 state_push (ParserData *data, gpointer info)
42 data->stack = g_slist_prepend (data->stack, info);
45 static inline gpointer
46 state_peek (ParserData *data)
51 return data->stack->data;
54 static inline gpointer
55 state_pop (ParserData *data)
62 old = data->stack->data;
63 data->stack = g_slist_delete_link (data->stack, data->stack);
66 #define state_peek_info(data, st) ((st*)state_peek(data))
67 #define state_pop_info(data, st) ((st*)state_pop(data))
70 error_missing_attribute (ParserData *data,
72 const gchar *attribute,
75 gint line_number, char_number;
77 g_markup_parse_context_get_position (data->ctx,
83 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
84 "%s:%d:%d <%s> requires attribute \"%s\"",
86 line_number, char_number, tag, attribute);
90 error_invalid_attribute (ParserData *data,
92 const gchar *attribute,
95 gint line_number, char_number;
97 g_markup_parse_context_get_position (data->ctx,
103 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
104 "%s:%d:%d '%s' is not a valid attribute of <%s>",
106 line_number, char_number, attribute, tag);
110 error_invalid_tag (ParserData *data,
112 const gchar *expected,
115 gint line_number, char_number;
117 g_markup_parse_context_get_position (data->ctx,
124 GTK_BUILDER_ERROR_INVALID_TAG,
125 "%s:%d:%d '%s' is not a valid tag here, expected a '%s' tag",
127 line_number, char_number, tag, expected);
131 GTK_BUILDER_ERROR_INVALID_TAG,
132 "%s:%d:%d '%s' is not a valid tag here",
134 line_number, char_number, tag);
138 _gtk_builder_boolean_from_string (const gchar *string,
142 gboolean retval = TRUE;
145 g_assert (string != NULL);
146 length = strlen (string);
150 else if (length == 1)
152 gchar c = g_ascii_tolower (string[0]);
153 if (c == 'y' || c == 't' || c == '1')
155 else if (c == 'n' || c == 'f' || c == '0')
162 gchar *lower = g_ascii_strdown (string, length);
164 if (strcmp (lower, "yes") == 0 || strcmp (lower, "true") == 0)
166 else if (strcmp (lower, "no") == 0 || strcmp (lower, "false") == 0)
176 GTK_BUILDER_ERROR_INVALID_VALUE,
177 "could not parse boolean `%s'",
184 builder_construct (ParserData *data,
185 ObjectInfo *object_info,
190 g_assert (object_info != NULL);
192 if (object_info->object)
193 return object_info->object;
195 object_info->properties = g_slist_reverse (object_info->properties);
197 object = _gtk_builder_construct (data->builder, object_info, error);
201 g_assert (G_IS_OBJECT (object));
203 object_info->object = object;
209 _get_type_by_symbol (const gchar* symbol)
211 static GModule *module = NULL;
216 module = g_module_open (NULL, 0);
218 if (!g_module_symbol (module, symbol, (gpointer)&func))
222 if (type == G_TYPE_INVALID)
225 return g_strdup (g_type_name (type));
229 parse_requires (ParserData *data,
230 const gchar *element_name,
232 const gchar **values,
235 RequiresInfo *req_info;
236 const gchar *library = NULL;
237 const gchar *version = NULL;
239 gint i, version_major = 0, version_minor = 0;
240 gint line_number, char_number;
242 g_markup_parse_context_get_position (data->ctx,
246 for (i = 0; names[i] != NULL; i++)
248 if (strcmp (names[i], "lib") == 0)
250 else if (strcmp (names[i], "version") == 0)
253 error_invalid_attribute (data, element_name, names[i], error);
256 if (!library || !version)
258 error_missing_attribute (data, element_name,
259 version ? "lib" : "version", error);
263 if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1])
267 GTK_BUILDER_ERROR_INVALID_VALUE,
268 "%s:%d:%d <%s> attribute has malformed value \"%s\"",
270 line_number, char_number, "version", version);
273 version_major = g_ascii_strtoll (split[0], NULL, 10);
274 version_minor = g_ascii_strtoll (split[1], NULL, 10);
277 req_info = g_slice_new0 (RequiresInfo);
278 req_info->library = g_strdup (library);
279 req_info->major = version_major;
280 req_info->minor = version_minor;
281 state_push (data, req_info);
282 req_info->tag.name = element_name;
286 is_requested_object (const gchar *object,
291 for (l = data->requested_objects; l; l = l->next)
293 if (strcmp (l->data, object) == 0)
301 parse_object (GMarkupParseContext *context,
303 const gchar *element_name,
305 const gchar **values,
308 ObjectInfo *object_info;
309 ChildInfo* child_info;
311 gchar *object_class = NULL;
312 gchar *object_id = NULL;
313 gchar *constructor = NULL;
316 child_info = state_peek_info (data, ChildInfo);
317 if (child_info && strcmp (child_info->tag.name, "object") == 0)
319 error_invalid_tag (data, element_name, NULL, error);
323 for (i = 0; names[i] != NULL; i++)
325 if (strcmp (names[i], "class") == 0)
326 object_class = g_strdup (values[i]);
327 else if (strcmp (names[i], "id") == 0)
328 object_id = g_strdup (values[i]);
329 else if (strcmp (names[i], "constructor") == 0)
330 constructor = g_strdup (values[i]);
331 else if (strcmp (names[i], "type-func") == 0)
333 /* Call the GType function, and return the name of the GType,
334 * it's guaranteed afterwards that g_type_from_name on the name
335 * will return our GType
337 object_class = _get_type_by_symbol (values[i]);
340 g_markup_parse_context_get_position (context, &line, NULL);
341 g_set_error (error, GTK_BUILDER_ERROR,
342 GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
343 _("Invalid type function on line %d: '%s'"),
350 error_invalid_attribute (data, element_name, names[i], error);
357 error_missing_attribute (data, element_name, "class", error);
363 error_missing_attribute (data, element_name, "id", error);
367 ++data->cur_object_level;
369 /* check if we reached a requested object (if it is specified) */
370 if (data->requested_objects && !data->inside_requested_object)
372 if (is_requested_object (object_id, data))
374 data->requested_object_level = data->cur_object_level;
376 GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
378 data->requested_object_level));
380 data->inside_requested_object = TRUE;
384 g_free (object_class);
386 g_free (constructor);
391 object_info = g_slice_new0 (ObjectInfo);
392 object_info->class_name = object_class;
393 object_info->id = object_id;
394 object_info->constructor = constructor;
395 state_push (data, object_info);
396 object_info->tag.name = element_name;
399 object_info->parent = (CommonInfo*)child_info;
401 g_markup_parse_context_get_position (context, &line, NULL);
402 line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
405 g_set_error (error, GTK_BUILDER_ERROR,
406 GTK_BUILDER_ERROR_DUPLICATE_ID,
407 _("Duplicate object id '%s' on line %d (previously on line %d)"),
408 object_id, line, line2);
413 g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
417 free_object_info (ObjectInfo *info)
419 /* Do not free the signal items, which GtkBuilder takes ownership of */
420 g_slist_free (info->signals);
421 g_slist_foreach (info->properties,
422 (GFunc)free_property_info, NULL);
423 g_slist_free (info->properties);
424 g_free (info->constructor);
425 g_free (info->class_name);
427 g_slice_free (ObjectInfo, info);
431 parse_child (ParserData *data,
432 const gchar *element_name,
434 const gchar **values,
438 ObjectInfo* object_info;
439 ChildInfo *child_info;
442 object_info = state_peek_info (data, ObjectInfo);
443 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
445 error_invalid_tag (data, element_name, NULL, error);
449 child_info = g_slice_new0 (ChildInfo);
450 state_push (data, child_info);
451 child_info->tag.name = element_name;
452 for (i = 0; names[i]; i++)
454 if (strcmp (names[i], "type") == 0)
455 child_info->type = g_strdup (values[i]);
456 else if (strcmp (names[i], "internal-child") == 0)
457 child_info->internal_child = g_strdup (values[i]);
459 error_invalid_attribute (data, element_name, names[i], error);
462 child_info->parent = (CommonInfo*)object_info;
464 object_info->object = builder_construct (data, object_info, error);
468 free_child_info (ChildInfo *info)
471 g_free (info->internal_child);
472 g_slice_free (ChildInfo, info);
476 parse_property (ParserData *data,
477 const gchar *element_name,
479 const gchar **values,
484 gchar *context = NULL;
485 gboolean translatable = FALSE;
486 ObjectInfo *object_info;
489 object_info = state_peek_info (data, ObjectInfo);
490 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
492 error_invalid_tag (data, element_name, NULL, error);
496 for (i = 0; names[i] != NULL; i++)
498 if (strcmp (names[i], "name") == 0)
499 name = g_strdelimit (g_strdup (values[i]), "_", '-');
500 else if (strcmp (names[i], "translatable") == 0)
502 if (!_gtk_builder_boolean_from_string (values[i], &translatable,
506 else if (strcmp (names[i], "comments") == 0)
508 /* do nothing, comments are for translators */
510 else if (strcmp (names[i], "context") == 0)
512 context = g_strdup (values[i]);
516 error_invalid_attribute (data, element_name, names[i], error);
523 error_missing_attribute (data, element_name, "name", error);
527 info = g_slice_new0 (PropertyInfo);
529 info->translatable = translatable;
530 info->context = context;
531 info->text = g_string_new ("");
532 state_push (data, info);
534 info->tag.name = element_name;
538 free_property_info (PropertyInfo *info)
542 g_slice_free (PropertyInfo, info);
546 parse_signal (ParserData *data,
547 const gchar *element_name,
549 const gchar **values,
554 gchar *handler = NULL;
555 gchar *object = NULL;
556 gboolean after = FALSE;
557 gboolean swapped = FALSE;
558 gboolean swapped_set = FALSE;
559 ObjectInfo *object_info;
562 object_info = state_peek_info (data, ObjectInfo);
563 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
565 error_invalid_tag (data, element_name, NULL, error);
569 for (i = 0; names[i] != NULL; i++)
571 if (strcmp (names[i], "name") == 0)
572 name = g_strdup (values[i]);
573 else if (strcmp (names[i], "handler") == 0)
574 handler = g_strdup (values[i]);
575 else if (strcmp (names[i], "after") == 0)
577 if (!_gtk_builder_boolean_from_string (values[i], &after, error))
580 else if (strcmp (names[i], "swapped") == 0)
582 if (!_gtk_builder_boolean_from_string (values[i], &swapped, error))
586 else if (strcmp (names[i], "object") == 0)
587 object = g_strdup (values[i]);
588 else if (strcmp (names[i], "last_modification_time") == 0)
589 /* parse but ignore */
593 error_invalid_attribute (data, element_name, names[i], error);
600 error_missing_attribute (data, element_name, "name", error);
605 error_missing_attribute (data, element_name, "handler", error);
609 /* Swapped defaults to FALSE except when object is set */
610 if (object && !swapped_set)
613 info = g_slice_new0 (SignalInfo);
615 info->handler = handler;
617 info->flags |= G_CONNECT_AFTER;
619 info->flags |= G_CONNECT_SWAPPED;
620 info->connect_object_name = object;
621 state_push (data, info);
623 info->tag.name = element_name;
626 /* Called by GtkBuilder */
628 _free_signal_info (SignalInfo *info,
632 g_free (info->handler);
633 g_free (info->connect_object_name);
634 g_free (info->object_name);
635 g_slice_free (SignalInfo, info);
639 _free_requires_info (RequiresInfo *info,
642 g_free (info->library);
643 g_slice_free (RequiresInfo, info);
647 parse_interface (ParserData *data,
648 const gchar *element_name,
650 const gchar **values,
655 for (i = 0; names[i] != NULL; i++)
657 if (strcmp (names[i], "domain") == 0)
661 if (strcmp (data->domain, values[i]) == 0)
664 g_warning ("%s: interface domain '%s' overrides "
665 "programically set domain '%s'",
671 g_free (data->domain);
674 data->domain = g_strdup (values[i]);
675 gtk_builder_set_translation_domain (data->builder, data->domain);
678 error_invalid_attribute (data, "interface", names[i], error);
683 create_subparser (GObject *object,
685 const gchar *element_name,
686 GMarkupParser *parser,
689 SubParser *subparser;
691 subparser = g_slice_new0 (SubParser);
692 subparser->object = object;
693 subparser->child = child;
694 subparser->tagname = g_strdup (element_name);
695 subparser->start = element_name;
696 subparser->parser = g_memdup (parser, sizeof (GMarkupParser));
697 subparser->data = user_data;
703 free_subparser (SubParser *subparser)
705 g_free (subparser->tagname);
706 g_slice_free (SubParser, subparser);
710 subparser_start (GMarkupParseContext *context,
711 const gchar *element_name,
713 const gchar **values,
717 SubParser *subparser = data->subparser;
719 if (!subparser->start &&
720 strcmp (element_name, subparser->tagname) == 0)
721 subparser->start = element_name;
723 if (subparser->start)
725 if (subparser->parser->start_element)
726 subparser->parser->start_element (context,
727 element_name, names, values,
728 subparser->data, error);
735 subparser_end (GMarkupParseContext *context,
736 const gchar *element_name,
740 if (data->subparser->parser->end_element)
741 data->subparser->parser->end_element (context, element_name,
742 data->subparser->data, error);
744 if (!strcmp (data->subparser->start, element_name) == 0)
747 gtk_buildable_custom_tag_end (GTK_BUILDABLE (data->subparser->object),
749 data->subparser->child,
751 data->subparser->data);
752 g_free (data->subparser->parser);
754 if (GTK_BUILDABLE_GET_IFACE (data->subparser->object)->custom_finished)
755 data->custom_finalizers = g_slist_prepend (data->custom_finalizers,
758 free_subparser (data->subparser);
760 data->subparser = NULL;
764 parse_custom (GMarkupParseContext *context,
765 const gchar *element_name,
767 const gchar **values,
771 CommonInfo* parent_info;
772 GMarkupParser parser;
773 gpointer subparser_data;
777 parent_info = state_peek_info (data, CommonInfo);
781 if (strcmp (parent_info->tag.name, "object") == 0)
783 ObjectInfo* object_info = (ObjectInfo*)parent_info;
784 if (!object_info->object)
786 object_info->properties = g_slist_reverse (object_info->properties);
787 object_info->object = _gtk_builder_construct (data->builder,
790 if (!object_info->object)
791 return TRUE; /* A GError is already set */
793 g_assert (object_info->object);
794 object = object_info->object;
797 else if (strcmp (parent_info->tag.name, "child") == 0)
799 ChildInfo* child_info = (ChildInfo*)parent_info;
801 _gtk_builder_add (data->builder, child_info);
803 object = ((ObjectInfo*)child_info->parent)->object;
804 child = child_info->object;
809 if (!gtk_buildable_custom_tag_start (GTK_BUILDABLE (object),
817 data->subparser = create_subparser (object, child, element_name,
818 &parser, subparser_data);
820 if (parser.start_element)
821 parser.start_element (context,
822 element_name, names, values,
823 subparser_data, error);
828 start_element (GMarkupParseContext *context,
829 const gchar *element_name,
831 const gchar **values,
835 ParserData *data = (ParserData*)user_data;
837 #ifdef GTK_ENABLE_DEBUG
838 if (gtk_debug_flags & GTK_DEBUG_BUILDER)
840 GString *tags = g_string_new ("");
842 for (i = 0; names[i]; i++)
843 g_string_append_printf (tags, "%s=\"%s\" ", names[i], values[i]);
847 g_string_insert_c (tags, 0, ' ');
848 g_string_truncate (tags, tags->len - 1);
850 g_print ("<%s%s>\n", element_name, tags->str);
851 g_string_free (tags, TRUE);
855 if (!data->last_element && strcmp (element_name, "interface") != 0)
857 g_set_error (error, GTK_BUILDER_ERROR,
858 GTK_BUILDER_ERROR_UNHANDLED_TAG,
859 _("Invalid root element: '%s'"),
863 data->last_element = element_name;
866 if (!subparser_start (context, element_name, names, values,
870 if (strcmp (element_name, "requires") == 0)
871 parse_requires (data, element_name, names, values, error);
872 else if (strcmp (element_name, "object") == 0)
873 parse_object (context, data, element_name, names, values, error);
874 else if (data->requested_objects && !data->inside_requested_object)
876 /* If outside a requested object, simply ignore this tag */
879 else if (strcmp (element_name, "child") == 0)
880 parse_child (data, element_name, names, values, error);
881 else if (strcmp (element_name, "property") == 0)
882 parse_property (data, element_name, names, values, error);
883 else if (strcmp (element_name, "signal") == 0)
884 parse_signal (data, element_name, names, values, error);
885 else if (strcmp (element_name, "interface") == 0)
886 parse_interface (data, element_name, names, values, error);
887 else if (strcmp (element_name, "placeholder") == 0)
889 /* placeholder has no special treatmeant, but it needs an
890 * if clause to avoid an error below.
894 if (!parse_custom (context, element_name, names, values,
896 g_set_error (error, GTK_BUILDER_ERROR,
897 GTK_BUILDER_ERROR_UNHANDLED_TAG,
898 _("Unhandled tag: '%s'"),
903 _gtk_builder_parser_translate (const gchar *domain,
904 const gchar *context,
910 s = g_dpgettext2 (domain, context, text);
912 s = g_dgettext (domain, text);
917 /* Called for close tags </foo> */
919 end_element (GMarkupParseContext *context,
920 const gchar *element_name,
924 ParserData *data = (ParserData*)user_data;
926 GTK_NOTE (BUILDER, g_print ("</%s>\n", element_name));
928 if (data->subparser && data->subparser->start)
930 subparser_end (context, element_name, data, error);
934 if (strcmp (element_name, "requires") == 0)
936 RequiresInfo *req_info = state_pop_info (data, RequiresInfo);
938 /* TODO: Allow third party widget developers to check thier
939 * required versions, possibly throw a signal allowing them
940 * to check thier library versions here.
942 if (!strcmp (req_info->library, "gtk+"))
944 if (!GTK_CHECK_VERSION (req_info->major, req_info->minor, 0))
947 GTK_BUILDER_ERROR_VERSION_MISMATCH,
948 "%s: required %s version %d.%d, current version is %d.%d",
949 data->filename, req_info->library,
950 req_info->major, req_info->minor,
951 GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
953 _free_requires_info (req_info, NULL);
955 else if (strcmp (element_name, "interface") == 0)
958 else if (data->requested_objects && !data->inside_requested_object)
960 /* If outside a requested object, simply ignore this tag */
963 else if (strcmp (element_name, "object") == 0)
965 ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
966 ChildInfo* child_info = state_peek_info (data, ChildInfo);
968 if (data->requested_objects && data->inside_requested_object &&
969 (data->cur_object_level == data->requested_object_level))
971 GTK_NOTE (BUILDER, g_print ("requested object end found at level %d\n",
972 data->requested_object_level));
974 data->inside_requested_object = FALSE;
977 --data->cur_object_level;
979 g_assert (data->cur_object_level >= 0);
981 object_info->object = builder_construct (data, object_info, error);
982 if (!object_info->object)
984 free_object_info (object_info);
988 child_info->object = object_info->object;
990 if (GTK_IS_BUILDABLE (object_info->object) &&
991 GTK_BUILDABLE_GET_IFACE (object_info->object)->parser_finished)
992 data->finalizers = g_slist_prepend (data->finalizers, object_info->object);
993 _gtk_builder_add_signals (data->builder, object_info->signals);
995 free_object_info (object_info);
997 else if (strcmp (element_name, "property") == 0)
999 PropertyInfo *prop_info = state_pop_info (data, PropertyInfo);
1000 CommonInfo *info = state_peek_info (data, CommonInfo);
1002 /* Normal properties */
1003 if (strcmp (info->tag.name, "object") == 0)
1005 ObjectInfo *object_info = (ObjectInfo*)info;
1007 if (prop_info->translatable && prop_info->text->len)
1009 prop_info->data = _gtk_builder_parser_translate (data->domain,
1011 prop_info->text->str);
1012 g_string_free (prop_info->text, TRUE);
1016 prop_info->data = g_string_free (prop_info->text, FALSE);
1020 object_info->properties =
1021 g_slist_prepend (object_info->properties, prop_info);
1024 g_assert_not_reached ();
1026 else if (strcmp (element_name, "child") == 0)
1028 ChildInfo *child_info = state_pop_info (data, ChildInfo);
1030 _gtk_builder_add (data->builder, child_info);
1032 free_child_info (child_info);
1034 else if (strcmp (element_name, "signal") == 0)
1036 SignalInfo *signal_info = state_pop_info (data, SignalInfo);
1037 ObjectInfo *object_info = (ObjectInfo*)state_peek_info (data, CommonInfo);
1038 signal_info->object_name = g_strdup (object_info->id);
1039 object_info->signals =
1040 g_slist_prepend (object_info->signals, signal_info);
1042 else if (strcmp (element_name, "placeholder") == 0)
1047 g_assert_not_reached ();
1051 /* Called for character data */
1052 /* text is not nul-terminated */
1054 text (GMarkupParseContext *context,
1060 ParserData *data = (ParserData*)user_data;
1063 if (data->subparser && data->subparser->start)
1065 GError *tmp_error = NULL;
1067 if (data->subparser->parser->text)
1068 data->subparser->parser->text (context, text, text_len,
1069 data->subparser->data, &tmp_error);
1071 g_propagate_error (error, tmp_error);
1078 info = state_peek_info (data, CommonInfo);
1079 g_assert (info != NULL);
1081 if (strcmp (g_markup_parse_context_get_element (context), "property") == 0)
1083 PropertyInfo *prop_info = (PropertyInfo*)info;
1085 g_string_append_len (prop_info->text, text, text_len);
1090 free_info (CommonInfo *info)
1092 if (strcmp (info->tag.name, "object") == 0)
1093 free_object_info ((ObjectInfo *)info);
1094 else if (strcmp (info->tag.name, "child") == 0)
1095 free_child_info ((ChildInfo *)info);
1096 else if (strcmp (info->tag.name, "property") == 0)
1097 free_property_info ((PropertyInfo *)info);
1098 else if (strcmp (info->tag.name, "signal") == 0)
1099 _free_signal_info ((SignalInfo *)info, NULL);
1100 else if (strcmp (info->tag.name, "requires") == 0)
1101 _free_requires_info ((RequiresInfo *)info, NULL);
1103 g_assert_not_reached ();
1106 static const GMarkupParser parser = {
1115 _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
1116 const gchar *filename,
1117 const gchar *buffer,
1119 gchar **requested_objs,
1122 const gchar* domain;
1126 /* Store the original domain so that interface domain attribute can be
1127 * applied for the builder and the original domain can be restored after
1128 * parsing has finished. This allows subparsers to translate elements with
1129 * gtk_builder_get_translation_domain() without breaking the ABI or API
1131 domain = gtk_builder_get_translation_domain (builder);
1133 data = g_new0 (ParserData, 1);
1134 data->builder = builder;
1135 data->filename = filename;
1136 data->domain = g_strdup (domain);
1137 data->object_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
1138 (GDestroyNotify)g_free, NULL);
1140 data->requested_objects = NULL;
1145 data->inside_requested_object = FALSE;
1146 for (i = 0; requested_objs[i]; ++i)
1148 data->requested_objects = g_slist_prepend (data->requested_objects,
1149 g_strdup (requested_objs[i]));
1154 /* get all the objects */
1155 data->inside_requested_object = TRUE;
1158 data->ctx = g_markup_parse_context_new (&parser,
1159 G_MARKUP_TREAT_CDATA_AS_TEXT,
1162 if (!g_markup_parse_context_parse (data->ctx, buffer, length, error))
1165 _gtk_builder_finish (builder);
1167 /* Custom parser_finished */
1168 data->custom_finalizers = g_slist_reverse (data->custom_finalizers);
1169 for (l = data->custom_finalizers; l; l = l->next)
1171 SubParser *sub = (SubParser*)l->data;
1173 gtk_buildable_custom_finished (GTK_BUILDABLE (sub->object),
1180 /* Common parser_finished, for all created objects */
1181 data->finalizers = g_slist_reverse (data->finalizers);
1182 for (l = data->finalizers; l; l = l->next)
1184 GtkBuildable *buildable = (GtkBuildable*)l->data;
1185 gtk_buildable_parser_finished (GTK_BUILDABLE (buildable), builder);
1190 g_slist_foreach (data->stack, (GFunc)free_info, NULL);
1191 g_slist_free (data->stack);
1192 g_slist_foreach (data->custom_finalizers, (GFunc)free_subparser, NULL);
1193 g_slist_free (data->custom_finalizers);
1194 g_slist_free (data->finalizers);
1195 g_slist_foreach (data->requested_objects, (GFunc) g_free, NULL);
1196 g_slist_free (data->requested_objects);
1197 g_free (data->domain);
1198 g_hash_table_destroy (data->object_ids);
1199 g_markup_parse_context_free (data->ctx);
1202 /* restore the original domain */
1203 gtk_builder_set_translation_domain (builder, domain);