Beispiel #1
0
static void
parse_interface (ParserData   *data,
		 const gchar  *element_name,
		 const gchar **names,
		 const gchar **values,
		 GError      **error)
{
  int i;

  for (i = 0; names[i] != NULL; i++)
    {
      if (strcmp (names[i], "domain") == 0)
	{
	  if (data->domain)
	    {
	      if (strcmp (data->domain, values[i]) == 0)
		continue;
	      else
		g_warning ("%s: interface domain '%s' overrides "
			   "programically set domain '%s'",
			   data->filename,
			   values[i],
			   data->domain
			   );
	      
	      g_free (data->domain);
	    }
	  
 	  data->domain = g_strdup (values[i]);
	  gtk_builder_set_translation_domain (data->builder, data->domain);
	}
      else
	error_invalid_attribute (data, "interface", names[i], error);
    }
}
Beispiel #2
0
static void
parse_requires (ParserData   *data,
		const gchar  *element_name,
		const gchar **names,
		const gchar **values,
		GError      **error)
{
  RequiresInfo *req_info;
  const gchar  *library = NULL;
  const gchar  *version = NULL;
  gchar       **split;
  gint          i, version_major = 0, version_minor = 0;
  gint          line_number, char_number;

  g_markup_parse_context_get_position (data->ctx,
                                       &line_number,
                                       &char_number);

  for (i = 0; names[i] != NULL; i++)
    {
      if (strcmp (names[i], "lib") == 0)
        library = values[i];
      else if (strcmp (names[i], "version") == 0)
	version = values[i];
      else
	error_invalid_attribute (data, element_name, names[i], error);
    }

  if (!library || !version)
    {
      error_missing_attribute (data, element_name, 
			       version ? "lib" : "version", error);
      return;
    }

  if (!(split = g_strsplit (version, ".", 2)) || !split[0] || !split[1])
    {
      g_set_error (error,
		   GTK_BUILDER_ERROR,
		   GTK_BUILDER_ERROR_INVALID_VALUE,
		   "%s:%d:%d <%s> attribute has malformed value \"%s\"",
		   data->filename,
		   line_number, char_number, "version", version);
      return;
    }
  version_major = g_ascii_strtoll (split[0], NULL, 10);
  version_minor = g_ascii_strtoll (split[1], NULL, 10);
  g_strfreev (split);

  req_info = g_slice_new0 (RequiresInfo);
  req_info->library = g_strdup (library);
  req_info->major   = version_major;
  req_info->minor   = version_minor;
  state_push (data, req_info);
  req_info->tag.name = element_name;
}
static void
parse_child (ParserData   *data,
             const gchar  *element_name,
             const gchar **names,
             const gchar **values,
             GError      **error)

{
  ObjectInfo* object_info;
  ChildInfo *child_info;
  guint i;

  object_info = state_peek_info (data, ObjectInfo);
  if (!object_info ||
      !(strcmp (object_info->tag.name, "object") == 0 ||
	strcmp (object_info->tag.name, "template") == 0))
    {
      error_invalid_tag (data, element_name, NULL, error);
      return;
    }
  
  child_info = g_slice_new0 (ChildInfo);
  state_push (data, child_info);
  child_info->tag.name = element_name;
  for (i = 0; names[i]; i++)
    {
      if (strcmp (names[i], "type") == 0)
        child_info->type = g_strdup (values[i]);
      else if (strcmp (names[i], "internal-child") == 0)
        child_info->internal_child = g_strdup (values[i]);
      else
	error_invalid_attribute (data, element_name, names[i], error);
    }

  child_info->parent = (CommonInfo*)object_info;

  object_info->object = builder_construct (data, object_info, error);
}
Beispiel #4
0
static void
parse_signal (ParserData   *data,
              const gchar  *element_name,
              const gchar **names,
              const gchar **values,
              GError      **error)
{
  SignalInfo *info;
  gchar *name = NULL;
  gchar *handler = NULL;
  gchar *object = NULL;
  gboolean after = FALSE;
  gboolean swapped = FALSE;
  gboolean swapped_set = FALSE;
  ObjectInfo *object_info;
  int i;

  object_info = state_peek_info (data, ObjectInfo);
  if (!object_info || strcmp (object_info->tag.name, "object") != 0)
    {
      error_invalid_tag (data, element_name, NULL, error);
      return;
    }

  for (i = 0; names[i] != NULL; i++)
    {
      if (strcmp (names[i], "name") == 0)
        name = g_strdup (values[i]);
      else if (strcmp (names[i], "handler") == 0)
        handler = g_strdup (values[i]);
      else if (strcmp (names[i], "after") == 0)
	{
	  if (!_gtk_builder_boolean_from_string (values[i], &after, error))
	    return;
	}
      else if (strcmp (names[i], "swapped") == 0)
	{
	  if (!_gtk_builder_boolean_from_string (values[i], &swapped, error))
	    return;
	  swapped_set = TRUE;
	}
      else if (strcmp (names[i], "object") == 0)
        object = g_strdup (values[i]);
      else if (strcmp (names[i], "last_modification_time") == 0)
	/* parse but ignore */
	;
      else
	{
	  error_invalid_attribute (data, element_name, names[i], error);
	  return;
	}
    }

  if (!name)
    {
      error_missing_attribute (data, element_name, "name", error);
      return;
    }
  else if (!handler)
    {
      error_missing_attribute (data, element_name, "handler", error);
      return;
    }

  /* Swapped defaults to FALSE except when object is set */
  if (object && !swapped_set)
    swapped = TRUE;
  
  info = g_slice_new0 (SignalInfo);
  info->name = name;
  info->handler = handler;
  if (after)
    info->flags |= G_CONNECT_AFTER;
  if (swapped)
    info->flags |= G_CONNECT_SWAPPED;
  info->connect_object_name = object;
  state_push (data, info);

  info->tag.name = element_name;
}
Beispiel #5
0
static void
parse_property (ParserData   *data,
                const gchar  *element_name,
                const gchar **names,
                const gchar **values,
                GError      **error)
{
  PropertyInfo *info;
  gchar *name = NULL;
  gchar *context = NULL;
  gboolean translatable = FALSE;
  ObjectInfo *object_info;
  int i;

  object_info = state_peek_info (data, ObjectInfo);
  if (!object_info || strcmp (object_info->tag.name, "object") != 0)
    {
      error_invalid_tag (data, element_name, NULL, error);
      return;
    }

  for (i = 0; names[i] != NULL; i++)
    {
      if (strcmp (names[i], "name") == 0)
        name = g_strdelimit (g_strdup (values[i]), "_", '-');
      else if (strcmp (names[i], "translatable") == 0)
	{
	  if (!_gtk_builder_boolean_from_string (values[i], &translatable,
						 error))
	    return;
	}
      else if (strcmp (names[i], "comments") == 0)
        {
          /* do nothing, comments are for translators */
        }
      else if (strcmp (names[i], "context") == 0) 
        {
          context = g_strdup (values[i]);
        }
      else
	{
	  error_invalid_attribute (data, element_name, names[i], error);
	  return;
	}
    }

  if (!name)
    {
      error_missing_attribute (data, element_name, "name", error);
      return;
    }

  info = g_slice_new0 (PropertyInfo);
  info->name = name;
  info->translatable = translatable;
  info->context = context;
  info->text = g_string_new ("");
  state_push (data, info);

  info->tag.name = element_name;
}
Beispiel #6
0
static void
parse_object (GMarkupParseContext  *context,
              ParserData           *data,
              const gchar          *element_name,
              const gchar         **names,
              const gchar         **values,
              GError              **error)
{
  ObjectInfo *object_info;
  ChildInfo* child_info;
  int i;
  gchar *object_class = NULL;
  gchar *object_id = NULL;
  gchar *constructor = NULL;
  gint line, line2;

  child_info = state_peek_info (data, ChildInfo);
  if (child_info && strcmp (child_info->tag.name, "object") == 0)
    {
      error_invalid_tag (data, element_name, NULL, error);
      return;
    }

  for (i = 0; names[i] != NULL; i++)
    {
      if (strcmp (names[i], "class") == 0)
        object_class = g_strdup (values[i]);
      else if (strcmp (names[i], "id") == 0)
        object_id = g_strdup (values[i]);
      else if (strcmp (names[i], "constructor") == 0)
        constructor = g_strdup (values[i]);
      else if (strcmp (names[i], "type-func") == 0)
        {
	  /* Call the GType function, and return the name of the GType,
	   * it's guaranteed afterwards that g_type_from_name on the name
	   * will return our GType
	   */
          object_class = _get_type_by_symbol (values[i]);
          if (!object_class)
            {
              g_markup_parse_context_get_position (context, &line, NULL);
              g_set_error (error, GTK_BUILDER_ERROR,
                           GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,
                           _("Invalid type function on line %d: '%s'"),
                           line, values[i]);
              return;
            }
        }
      else
	{
	  error_invalid_attribute (data, element_name, names[i], error);
	  return;
	}
    }

  if (!object_class)
    {
      error_missing_attribute (data, element_name, "class", error);
      return;
    }

  if (!object_id)
    {
      error_missing_attribute (data, element_name, "id", error);
      return;
    }

  ++data->cur_object_level;

  /* check if we reached a requested object (if it is specified) */
  if (data->requested_objects && !data->inside_requested_object)
    {
      if (is_requested_object (object_id, data))
        {
          data->requested_object_level = data->cur_object_level;

          GTK_NOTE (BUILDER, g_print ("requested object \"%s\" found at level %d\n",
                                      object_id,
                                      data->requested_object_level));

          data->inside_requested_object = TRUE;
        }
      else
        {
          g_free (object_class);
          g_free (object_id);
          g_free (constructor);
          return;
        }
    }

  object_info = g_slice_new0 (ObjectInfo);
  object_info->class_name = object_class;
  object_info->id = object_id;
  object_info->constructor = constructor;
  state_push (data, object_info);
  object_info->tag.name = element_name;

  if (child_info)
    object_info->parent = (CommonInfo*)child_info;

  g_markup_parse_context_get_position (context, &line, NULL);
  line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_id));
  if (line2 != 0)
    {
      g_set_error (error, GTK_BUILDER_ERROR,
                   GTK_BUILDER_ERROR_DUPLICATE_ID,
                   _("Duplicate object id '%s' on line %d (previously on line %d)"),
                   object_id, line, line2);
      return;
    }


  g_hash_table_insert (data->object_ids, g_strdup (object_id), GINT_TO_POINTER (line));
}
static void
parse_template (GMarkupParseContext  *context,
		ParserData           *data,
		const gchar          *element_name,
		const gchar         **names,
		const gchar         **values,
		GError              **error)
{
  ObjectInfo *object_info;
  int i;
  gchar *object_class = NULL;
  gint line, line2;
  GType template_type = _gtk_builder_get_template_type (data->builder);
  GType parsed_type;

  if (template_type == 0)
    {
      g_set_error (error,
		   GTK_BUILDER_ERROR,
		   GTK_BUILDER_ERROR_UNHANDLED_TAG,
		   "Encountered template definition but not parsing a template.");
      return;
    }
  else if (state_peek (data) != NULL)
    {
      g_set_error (error,
		   GTK_BUILDER_ERROR,
		   GTK_BUILDER_ERROR_UNHANDLED_TAG,
		   "Encountered template definition that is not at the top level.");
      return;
    }

  for (i = 0; names[i] != NULL; i++)
    {
      if (strcmp (names[i], "class") == 0)
        object_class = g_strdup (values[i]);
      else if (strcmp (names[i], "parent") == 0)
        /* Ignore 'parent' attribute, however it's needed by Glade */;
      else
	{
	  error_invalid_attribute (data, element_name, names[i], error);
	  return;
	}
    }

  if (!object_class)
    {
      error_missing_attribute (data, element_name, "class", error);
      return;
    }

  parsed_type = g_type_from_name (object_class);
  if (template_type != parsed_type)
    {
      g_set_error (error,
		   GTK_BUILDER_ERROR,
		   GTK_BUILDER_ERROR_TEMPLATE_MISMATCH,
		   "Parsed template definition for type `%s', expected type `%s'.",
		   object_class, g_type_name (template_type));
      return;
    }

  ++data->cur_object_level;

  object_info = g_slice_new0 (ObjectInfo);
  object_info->class_name = object_class;
  object_info->id = g_strdup (object_class);
  object_info->object = gtk_builder_get_object (data->builder, object_class);
  state_push (data, object_info);
  object_info->tag.name = element_name;

  g_markup_parse_context_get_position (context, &line, NULL);
  line2 = GPOINTER_TO_INT (g_hash_table_lookup (data->object_ids, object_class));
  if (line2 != 0)
    {
      g_set_error (error, GTK_BUILDER_ERROR,
                   GTK_BUILDER_ERROR_DUPLICATE_ID,
                   _("Duplicate object ID '%s' on line %d (previously on line %d)"),
                   object_class, line, line2);
      return;
    }

  g_hash_table_insert (data->object_ids, g_strdup (object_class), GINT_TO_POINTER (line));
}