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 "gtkbuilderprivate.h"
27 #include "gtkbuilder.h"
28 #include "gtkbuildable.h"
30 #include "gtkversion.h"
31 #include "gtktypebuiltins.h"
35 static void free_property_info (PropertyInfo *info);
36 static void free_object_info (ObjectInfo *info);
39 state_push (ParserData *data, gpointer info)
41 data->stack = g_slist_prepend (data->stack, info);
44 static inline gpointer
45 state_peek (ParserData *data)
50 return data->stack->data;
53 static inline gpointer
54 state_pop (ParserData *data)
61 old = data->stack->data;
62 data->stack = g_slist_delete_link (data->stack, data->stack);
65 #define state_peek_info(data, st) ((st*)state_peek(data))
66 #define state_pop_info(data, st) ((st*)state_pop(data))
69 error_missing_attribute (ParserData *data,
71 const gchar *attribute,
74 gint line_number, char_number;
76 g_markup_parse_context_get_position (data->ctx,
82 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
83 "%s:%d:%d <%s> requires attribute \"%s\"",
85 line_number, char_number, tag, attribute);
89 error_invalid_attribute (ParserData *data,
91 const gchar *attribute,
94 gint line_number, char_number;
96 g_markup_parse_context_get_position (data->ctx,
102 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
103 "%s:%d:%d '%s' is not a valid attribute of <%s>",
105 line_number, char_number, attribute, tag);
109 error_invalid_tag (ParserData *data,
111 const gchar *expected,
114 gint line_number, char_number;
116 g_markup_parse_context_get_position (data->ctx,
123 GTK_BUILDER_ERROR_INVALID_TAG,
124 "%s:%d:%d '%s' is not a valid tag here, expected a '%s' tag",
126 line_number, char_number, tag, expected);
130 GTK_BUILDER_ERROR_INVALID_TAG,
131 "%s:%d:%d '%s' is not a valid tag here",
133 line_number, char_number, tag);
137 _gtk_builder_boolean_from_string (const gchar *string,
141 gboolean retval = TRUE;
144 g_assert (string != NULL);
145 length = strlen (string);
149 else if (length == 1)
151 gchar c = g_ascii_tolower (string[0]);
152 if (c == 'y' || c == 't' || c == '1')
154 else if (c == 'n' || c == 'f' || c == '0')
161 gchar *lower = g_ascii_strdown (string, length);
163 if (strcmp (lower, "yes") == 0 || strcmp (lower, "true") == 0)
165 else if (strcmp (lower, "no") == 0 || strcmp (lower, "false") == 0)
175 GTK_BUILDER_ERROR_INVALID_VALUE,
176 "could not parse boolean `%s'",
183 builder_construct (ParserData *data,
184 ObjectInfo *object_info,
189 g_assert (object_info != NULL);
191 if (object_info->object)
192 return object_info->object;
194 object_info->properties = g_slist_reverse (object_info->properties);
196 object = _gtk_builder_construct (data->builder, object_info, error);
200 g_assert (G_IS_OBJECT (object));
202 object_info->object = object;
208 _get_type_by_symbol (const gchar* symbol)
210 static GModule *module = NULL;
215 module = g_module_open (NULL, 0);
217 if (!g_module_symbol (module, symbol, (gpointer)&func))
221 if (type == G_TYPE_INVALID)
224 return g_strdup (g_type_name (type));
228 parse_requires (ParserData *data,
229 const gchar *element_name,
231 const gchar **values,
234 RequiresInfo *req_info;
235 const gchar *library = NULL;
236 const gchar *version = NULL;
238 gint i, version_major = 0, version_minor = 0;
239 gint line_number, char_number;
241 g_markup_parse_context_get_position (data->ctx,
245 for (i = 0; names[i] != NULL; i++)
247 if (strcmp (names[i], "lib") == 0)
249 else if (strcmp (names[i], "version") == 0)
252 error_invalid_attribute (data, element_name, names[i], error);
255 if (!library || !version)
257 error_missing_attribute (data, element_name,
258 version ? "lib" : "version", error);
262 if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1])
266 GTK_BUILDER_ERROR_INVALID_VALUE,
267 "%s:%d:%d <%s> attribute has malformed value \"%s\"",
269 line_number, char_number, "version", version);
272 version_major = g_ascii_strtoll (split[0], NULL, 10);
273 version_minor = g_ascii_strtoll (split[1], NULL, 10);
276 req_info = g_slice_new0 (RequiresInfo);
277 req_info->library = g_strdup (library);
278 req_info->major = version_major;
279 req_info->minor = version_minor;
280 state_push (data, req_info);
281 req_info->tag.name = element_name;
285 is_requested_object (const gchar *object,
290 for (l = data->requested_objects; l; l = l->next)
292 if (strcmp (l->data, object) == 0)
300 parse_object (GMarkupParseContext *context,
302 const gchar *element_name,
304 const gchar **values,
307 ObjectInfo *object_info;
308 ChildInfo* child_info;
310 gchar *object_class = NULL;
311 gchar *object_id = NULL;
312 gchar *constructor = NULL;
315 child_info = state_peek_info (data, ChildInfo);
316 if (child_info && strcmp (child_info->tag.name, "object") == 0)
318 error_invalid_tag (data, element_name, NULL, error);
322 for (i = 0; names[i] != NULL; i++)
324 if (strcmp (names[i], "class") == 0)
325 object_class = g_strdup (values[i]);
326 else if (strcmp (names[i], "id") == 0)
327 object_id = g_strdup (values[i]);
328 else if (strcmp (names[i], "constructor") == 0)
329 constructor = g_strdup (values[i]);
330 else if (strcmp (names[i], "type-func") == 0)
332 /* Call the GType function, and return the name of the GType,
333 * it's guaranteed afterwards that g_type_from_name on the name
334 * will return our GType
336 object_class = _get_type_by_symbol (values[i]);
339 g_markup_parse_context_get_position (context, &line, NULL);
340 g_set_error (error, GTK_BUILDER_ERROR,
341 GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
342 _("Invalid type function on line %d: '%s'"),
349 error_invalid_attribute (data, element_name, names[i], error);
356 error_missing_attribute (data, element_name, "class", error);
362 error_missing_attribute (data, element_name, "id", error);
366 ++data->cur_object_level;
368 /* check if we reached a requested object (if it is specified) */
369 if (data->requested_objects && !data->inside_requested_object)
371 if (is_requested_object (object_id, data))
373 data->requested_object_level = data->cur_object_level;
375 GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
377 data->requested_object_level));
379 data->inside_requested_object = TRUE;
383 g_free (object_class);
385 g_free (constructor);
390 object_info = g_slice_new0 (ObjectInfo);
391 object_info->class_name = object_class;
392 object_info->id = object_id;
393 object_info->constructor = constructor;
394 state_push (data, object_info);
395 object_info->tag.name = element_name;
398 object_info->parent = (CommonInfo*)child_info;
400 g_markup_parse_context_get_position (context, &line, NULL);
401 line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
404 g_set_error (error, GTK_BUILDER_ERROR,
405 GTK_BUILDER_ERROR_DUPLICATE_ID,
406 _("Duplicate object ID '%s' on line %d (previously on line %d)"),
407 object_id, line, line2);
412 g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
416 free_object_info (ObjectInfo *info)
418 /* Do not free the signal items, which GtkBuilder takes ownership of */
419 g_slist_free (info->signals);
420 g_slist_foreach (info->properties,
421 (GFunc)free_property_info, NULL);
422 g_slist_free (info->properties);
423 g_free (info->constructor);
424 g_free (info->class_name);
426 g_slice_free (ObjectInfo, info);
430 parse_child (ParserData *data,
431 const gchar *element_name,
433 const gchar **values,
437 ObjectInfo* object_info;
438 ChildInfo *child_info;
441 object_info = state_peek_info (data, ObjectInfo);
442 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
444 error_invalid_tag (data, element_name, NULL, error);
448 child_info = g_slice_new0 (ChildInfo);
449 state_push (data, child_info);
450 child_info->tag.name = element_name;
451 for (i = 0; names[i]; i++)
453 if (strcmp (names[i], "type") == 0)
454 child_info->type = g_strdup (values[i]);
455 else if (strcmp (names[i], "internal-child") == 0)
456 child_info->internal_child = g_strdup (values[i]);
458 error_invalid_attribute (data, element_name, names[i], error);
461 child_info->parent = (CommonInfo*)object_info;
463 object_info->object = builder_construct (data, object_info, error);
467 free_child_info (ChildInfo *info)
470 g_free (info->internal_child);
471 g_slice_free (ChildInfo, info);
475 parse_property (ParserData *data,
476 const gchar *element_name,
478 const gchar **values,
483 gchar *context = NULL;
484 gboolean translatable = FALSE;
485 ObjectInfo *object_info;
488 object_info = state_peek_info (data, ObjectInfo);
489 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
491 error_invalid_tag (data, element_name, NULL, error);
495 for (i = 0; names[i] != NULL; i++)
497 if (strcmp (names[i], "name") == 0)
498 name = g_strdelimit (g_strdup (values[i]), "_", '-');
499 else if (strcmp (names[i], "translatable") == 0)
501 if (!_gtk_builder_boolean_from_string (values[i], &translatable,
505 else if (strcmp (names[i], "comments") == 0)
507 /* do nothing, comments are for translators */
509 else if (strcmp (names[i], "context") == 0)
511 context = g_strdup (values[i]);
515 error_invalid_attribute (data, element_name, names[i], error);
522 error_missing_attribute (data, element_name, "name", error);
526 info = g_slice_new0 (PropertyInfo);
528 info->translatable = translatable;
529 info->context = context;
530 info->text = g_string_new ("");
531 state_push (data, info);
533 info->tag.name = element_name;
537 free_property_info (PropertyInfo *info)
541 g_slice_free (PropertyInfo, info);
545 parse_signal (ParserData *data,
546 const gchar *element_name,
548 const gchar **values,
553 gchar *handler = NULL;
554 gchar *object = NULL;
555 gboolean after = FALSE;
556 gboolean swapped = FALSE;
557 gboolean swapped_set = FALSE;
558 ObjectInfo *object_info;
561 object_info = state_peek_info (data, ObjectInfo);
562 if (!object_info || strcmp (object_info->tag.name, "object") != 0)
564 error_invalid_tag (data, element_name, NULL, error);
568 for (i = 0; names[i] != NULL; i++)
570 if (strcmp (names[i], "name") == 0)
571 name = g_strdup (values[i]);
572 else if (strcmp (names[i], "handler") == 0)
573 handler = g_strdup (values[i]);
574 else if (strcmp (names[i], "after") == 0)
576 if (!_gtk_builder_boolean_from_string (values[i], &after, error))
579 else if (strcmp (names[i], "swapped") == 0)
581 if (!_gtk_builder_boolean_from_string (values[i], &swapped, error))
585 else if (strcmp (names[i], "object") == 0)
586 object = g_strdup (values[i]);
587 else if (strcmp (names[i], "last_modification_time") == 0)
588 /* parse but ignore */
592 error_invalid_attribute (data, element_name, names[i], error);
599 error_missing_attribute (data, element_name, "name", error);
604 error_missing_attribute (data, element_name, "handler", error);
608 /* Swapped defaults to FALSE except when object is set */
609 if (object && !swapped_set)
612 info = g_slice_new0 (SignalInfo);
614 info->handler = handler;
616 info->flags |= G_CONNECT_AFTER;
618 info->flags |= G_CONNECT_SWAPPED;
619 info->connect_object_name = object;
620 state_push (data, info);
622 info->tag.name = element_name;
625 /* Called by GtkBuilder */
627 _free_signal_info (SignalInfo *info,
631 g_free (info->handler);
632 g_free (info->connect_object_name);
633 g_free (info->object_name);
634 g_slice_free (SignalInfo, info);
638 _free_requires_info (RequiresInfo *info,
641 g_free (info->library);
642 g_slice_free (RequiresInfo, info);
646 parse_interface (ParserData *data,
647 const gchar *element_name,
649 const gchar **values,
654 for (i = 0; names[i] != NULL; i++)
656 if (strcmp (names[i], "domain") == 0)
660 if (strcmp (data->domain, values[i]) == 0)
663 g_warning ("%s: interface domain '%s' overrides "
664 "programically set domain '%s'",
670 g_free (data->domain);
673 data->domain = g_strdup (values[i]);
674 gtk_builder_set_translation_domain (data->builder, data->domain);
677 error_invalid_attribute (data, "interface", names[i], error);
682 create_subparser (GObject *object,
684 const gchar *element_name,
685 GMarkupParser *parser,
688 SubParser *subparser;
690 subparser = g_slice_new0 (SubParser);
691 subparser->object = object;
692 subparser->child = child;
693 subparser->tagname = g_strdup (element_name);
694 subparser->start = element_name;
695 subparser->parser = g_memdup (parser, sizeof (GMarkupParser));
696 subparser->data = user_data;
702 free_subparser (SubParser *subparser)
704 g_free (subparser->tagname);
705 g_slice_free (SubParser, subparser);
709 subparser_start (GMarkupParseContext *context,
710 const gchar *element_name,
712 const gchar **values,
716 SubParser *subparser = data->subparser;
718 if (!subparser->start &&
719 strcmp (element_name, subparser->tagname) == 0)
720 subparser->start = element_name;
722 if (subparser->start)
724 if (subparser->parser->start_element)
725 subparser->parser->start_element (context,
726 element_name, names, values,
727 subparser->data, error);
734 subparser_end (GMarkupParseContext *context,
735 const gchar *element_name,
739 if (data->subparser->parser->end_element)
740 data->subparser->parser->end_element (context, element_name,
741 data->subparser->data, error);
743 if (!strcmp (data->subparser->start, element_name) == 0)
746 gtk_buildable_custom_tag_end (GTK_BUILDABLE (data->subparser->object),
748 data->subparser->child,
750 data->subparser->data);
751 g_free (data->subparser->parser);
753 if (GTK_BUILDABLE_GET_IFACE (data->subparser->object)->custom_finished)
754 data->custom_finalizers = g_slist_prepend (data->custom_finalizers,
757 free_subparser (data->subparser);
759 data->subparser = NULL;
763 parse_custom (GMarkupParseContext *context,
764 const gchar *element_name,
766 const gchar **values,
770 CommonInfo* parent_info;
771 GMarkupParser parser;
772 gpointer subparser_data;
776 parent_info = state_peek_info (data, CommonInfo);
780 if (strcmp (parent_info->tag.name, "object") == 0)
782 ObjectInfo* object_info = (ObjectInfo*)parent_info;
783 if (!object_info->object)
785 object_info->properties = g_slist_reverse (object_info->properties);
786 object_info->object = _gtk_builder_construct (data->builder,
789 if (!object_info->object)
790 return TRUE; /* A GError is already set */
792 g_assert (object_info->object);
793 object = object_info->object;
796 else if (strcmp (parent_info->tag.name, "child") == 0)
798 ChildInfo* child_info = (ChildInfo*)parent_info;
800 _gtk_builder_add (data->builder, child_info);
802 object = ((ObjectInfo*)child_info->parent)->object;
803 child = child_info->object;
808 if (!gtk_buildable_custom_tag_start (GTK_BUILDABLE (object),
816 data->subparser = create_subparser (object, child, element_name,
817 &parser, subparser_data);
819 if (parser.start_element)
820 parser.start_element (context,
821 element_name, names, values,
822 subparser_data, error);
827 start_element (GMarkupParseContext *context,
828 const gchar *element_name,
830 const gchar **values,
834 ParserData *data = (ParserData*)user_data;
836 #ifdef GTK_ENABLE_DEBUG
837 if (gtk_get_debug_flags () & GTK_DEBUG_BUILDER)
839 GString *tags = g_string_new ("");
841 for (i = 0; names[i]; i++)
842 g_string_append_printf (tags, "%s=\"%s\" ", names[i], values[i]);
846 g_string_insert_c (tags, 0, ' ');
847 g_string_truncate (tags, tags->len - 1);
849 g_print ("<%s%s>\n", element_name, tags->str);
850 g_string_free (tags, TRUE);
854 if (!data->last_element && strcmp (element_name, "interface") != 0)
856 g_set_error (error, GTK_BUILDER_ERROR,
857 GTK_BUILDER_ERROR_UNHANDLED_TAG,
858 _("Invalid root element: '%s'"),
862 data->last_element = element_name;
865 if (!subparser_start (context, element_name, names, values,
869 if (strcmp (element_name, "requires") == 0)
870 parse_requires (data, element_name, names, values, error);
871 else if (strcmp (element_name, "object") == 0)
872 parse_object (context, data, element_name, names, values, error);
873 else if (data->requested_objects && !data->inside_requested_object)
875 /* If outside a requested object, simply ignore this tag */
878 else if (strcmp (element_name, "child") == 0)
879 parse_child (data, element_name, names, values, error);
880 else if (strcmp (element_name, "property") == 0)
881 parse_property (data, element_name, names, values, error);
882 else if (strcmp (element_name, "signal") == 0)
883 parse_signal (data, element_name, names, values, error);
884 else if (strcmp (element_name, "interface") == 0)
885 parse_interface (data, element_name, names, values, error);
886 else if (strcmp (element_name, "placeholder") == 0)
888 /* placeholder has no special treatmeant, but it needs an
889 * if clause to avoid an error below.
893 if (!parse_custom (context, element_name, names, values,
895 g_set_error (error, GTK_BUILDER_ERROR,
896 GTK_BUILDER_ERROR_UNHANDLED_TAG,
897 _("Unhandled tag: '%s'"),
902 _gtk_builder_parser_translate (const gchar *domain,
903 const gchar *context,
909 s = g_dpgettext2 (domain, context, text);
911 s = g_dgettext (domain, text);
916 /* Called for close tags </foo> */
918 end_element (GMarkupParseContext *context,
919 const gchar *element_name,
923 ParserData *data = (ParserData*)user_data;
925 GTK_NOTE (BUILDER, g_print ("</%s>\n", element_name));
927 if (data->subparser && data->subparser->start)
929 subparser_end (context, element_name, data, error);
933 if (strcmp (element_name, "requires") == 0)
935 RequiresInfo *req_info = state_pop_info (data, RequiresInfo);
937 /* TODO: Allow third party widget developers to check thier
938 * required versions, possibly throw a signal allowing them
939 * to check thier library versions here.
941 if (!strcmp (req_info->library, "gtk+"))
943 if (!GTK_CHECK_VERSION (req_info->major, req_info->minor, 0))
946 GTK_BUILDER_ERROR_VERSION_MISMATCH,
947 "%s: required %s version %d.%d, current version is %d.%d",
948 data->filename, req_info->library,
949 req_info->major, req_info->minor,
950 GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
952 _free_requires_info (req_info, NULL);
954 else if (strcmp (element_name, "interface") == 0)
957 else if (data->requested_objects && !data->inside_requested_object)
959 /* If outside a requested object, simply ignore this tag */
962 else if (strcmp (element_name, "object") == 0)
964 ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
965 ChildInfo* child_info = state_peek_info (data, ChildInfo);
967 if (data->requested_objects && data->inside_requested_object &&
968 (data->cur_object_level == data->requested_object_level))
970 GTK_NOTE (BUILDER, g_print ("requested object end found at level %d\n",
971 data->requested_object_level));
973 data->inside_requested_object = FALSE;
976 --data->cur_object_level;
978 g_assert (data->cur_object_level >= 0);
980 object_info->object = builder_construct (data, object_info, error);
981 if (!object_info->object)
983 free_object_info (object_info);
987 child_info->object = object_info->object;
989 if (GTK_IS_BUILDABLE (object_info->object) &&
990 GTK_BUILDABLE_GET_IFACE (object_info->object)->parser_finished)
991 data->finalizers = g_slist_prepend (data->finalizers, object_info->object);
992 _gtk_builder_add_signals (data->builder, object_info->signals);
994 free_object_info (object_info);
996 else if (strcmp (element_name, "property") == 0)
998 PropertyInfo *prop_info = state_pop_info (data, PropertyInfo);
999 CommonInfo *info = state_peek_info (data, CommonInfo);
1001 /* Normal properties */
1002 if (strcmp (info->tag.name, "object") == 0)
1004 ObjectInfo *object_info = (ObjectInfo*)info;
1006 if (prop_info->translatable && prop_info->text->len)
1008 prop_info->data = _gtk_builder_parser_translate (data->domain,
1010 prop_info->text->str);
1011 g_string_free (prop_info->text, TRUE);
1015 prop_info->data = g_string_free (prop_info->text, FALSE);
1019 object_info->properties =
1020 g_slist_prepend (object_info->properties, prop_info);
1023 g_assert_not_reached ();
1025 else if (strcmp (element_name, "child") == 0)
1027 ChildInfo *child_info = state_pop_info (data, ChildInfo);
1029 _gtk_builder_add (data->builder, child_info);
1031 free_child_info (child_info);
1033 else if (strcmp (element_name, "signal") == 0)
1035 SignalInfo *signal_info = state_pop_info (data, SignalInfo);
1036 ObjectInfo *object_info = (ObjectInfo*)state_peek_info (data, CommonInfo);
1037 signal_info->object_name = g_strdup (object_info->id);
1038 object_info->signals =
1039 g_slist_prepend (object_info->signals, signal_info);
1041 else if (strcmp (element_name, "placeholder") == 0)
1046 g_assert_not_reached ();
1050 /* Called for character data */
1051 /* text is not nul-terminated */
1053 text (GMarkupParseContext *context,
1059 ParserData *data = (ParserData*)user_data;
1062 if (data->subparser && data->subparser->start)
1064 GError *tmp_error = NULL;
1066 if (data->subparser->parser->text)
1067 data->subparser->parser->text (context, text, text_len,
1068 data->subparser->data, &tmp_error);
1070 g_propagate_error (error, tmp_error);
1077 info = state_peek_info (data, CommonInfo);
1078 g_assert (info != NULL);
1080 if (strcmp (g_markup_parse_context_get_element (context), "property") == 0)
1082 PropertyInfo *prop_info = (PropertyInfo*)info;
1084 g_string_append_len (prop_info->text, text, text_len);
1089 free_info (CommonInfo *info)
1091 if (strcmp (info->tag.name, "object") == 0)
1092 free_object_info ((ObjectInfo *)info);
1093 else if (strcmp (info->tag.name, "child") == 0)
1094 free_child_info ((ChildInfo *)info);
1095 else if (strcmp (info->tag.name, "property") == 0)
1096 free_property_info ((PropertyInfo *)info);
1097 else if (strcmp (info->tag.name, "signal") == 0)
1098 _free_signal_info ((SignalInfo *)info, NULL);
1099 else if (strcmp (info->tag.name, "requires") == 0)
1100 _free_requires_info ((RequiresInfo *)info, NULL);
1102 g_assert_not_reached ();
1105 static const GMarkupParser parser = {
1114 _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
1115 const gchar *filename,
1116 const gchar *buffer,
1118 gchar **requested_objs,
1121 const gchar* domain;
1125 /* Store the original domain so that interface domain attribute can be
1126 * applied for the builder and the original domain can be restored after
1127 * parsing has finished. This allows subparsers to translate elements with
1128 * gtk_builder_get_translation_domain() without breaking the ABI or API
1130 domain = gtk_builder_get_translation_domain (builder);
1132 data = g_new0 (ParserData, 1);
1133 data->builder = builder;
1134 data->filename = filename;
1135 data->domain = g_strdup (domain);
1136 data->object_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
1137 (GDestroyNotify)g_free, NULL);
1139 data->requested_objects = NULL;
1144 data->inside_requested_object = FALSE;
1145 for (i = 0; requested_objs[i]; ++i)
1147 data->requested_objects = g_slist_prepend (data->requested_objects,
1148 g_strdup (requested_objs[i]));
1153 /* get all the objects */
1154 data->inside_requested_object = TRUE;
1157 data->ctx = g_markup_parse_context_new (&parser,
1158 G_MARKUP_TREAT_CDATA_AS_TEXT,
1161 if (!g_markup_parse_context_parse (data->ctx, buffer, length, error))
1164 _gtk_builder_finish (builder);
1166 /* Custom parser_finished */
1167 data->custom_finalizers = g_slist_reverse (data->custom_finalizers);
1168 for (l = data->custom_finalizers; l; l = l->next)
1170 SubParser *sub = (SubParser*)l->data;
1172 gtk_buildable_custom_finished (GTK_BUILDABLE (sub->object),
1179 /* Common parser_finished, for all created objects */
1180 data->finalizers = g_slist_reverse (data->finalizers);
1181 for (l = data->finalizers; l; l = l->next)
1183 GtkBuildable *buildable = (GtkBuildable*)l->data;
1184 gtk_buildable_parser_finished (GTK_BUILDABLE (buildable), builder);
1189 g_slist_foreach (data->stack, (GFunc)free_info, NULL);
1190 g_slist_free (data->stack);
1191 g_slist_foreach (data->custom_finalizers, (GFunc)free_subparser, NULL);
1192 g_slist_free (data->custom_finalizers);
1193 g_slist_free (data->finalizers);
1194 g_slist_foreach (data->requested_objects, (GFunc) g_free, NULL);
1195 g_slist_free (data->requested_objects);
1196 g_free (data->domain);
1197 g_hash_table_destroy (data->object_ids);
1198 g_markup_parse_context_free (data->ctx);
1201 /* restore the original domain */
1202 gtk_builder_set_translation_domain (builder, domain);