Re: [Multi-valued V2 (grilo) 07/12] core: Create property with an initial set of keys




On Wed, 02 Mar 2011 13:53:35 +0100, "Juan A." Suárez Romero <jasuarez igalia com> wrote:
On Tue, 2011-03-01 at 10:35 +0000, Iago Toral wrote:
> + * Returns: a new #GrlProperty
> + **/
> +GrlProperty *
> +grl_property_new_with_keys (const GList *keys)
> +{
> +  GrlProperty *prop = grl_property_new ();
> +
> +  while (keys) {
> +    grl_data_add (GRL_DATA (prop), keys->data);

 Do we have API in GrlData for adding a key with no value like this?
 Please let's not do strange things. grl_data_add should receive a
key
 and a value.

> +    keys = g_list_next (keys);
> +  }
> +
> +  return prop;
> +}



This function has been superseded by this one (it is in a later patch):

/**
 * grl_property_new_for_key:
 * @key: a metadata key.
 *
 * Creates a new property instance that can be used to store @key and
related
 * keys, with their values.
 *
 * Returns: a new #GrlProperty
 **/
GrlProperty *
grl_property_new_for_key (GrlKeyID key)
{
  GrlPluginRegistry *registry = grl_plugin_registry_get_default ();
  GrlProperty *prop = grl_property_new ();
  const GList *related_keys = NULL;

  if (!registry) {
    GRL_ERROR ("Unable to get registry");
    return prop;
  }

  related_keys =
    grl_plugin_registry_lookup_metadata_key_relation (registry, key);

  while (related_keys) {
    grl_property_add (prop, related_keys->data);
    related_keys = g_list_next (related_keys);
  }

  return prop;
}



The main reason for this function is that user can create a GrlProperty
to store the @key and related keys, and the property will returned
pre-filled with the set of related keys that is intended to be used in
the property (pre-filled with keys but not values).

Thus, user can query the GrlProperty to get the keys it has, which in
fact all of them are related. They could do:

GrlProperty *property = grl_property_new_for_key (GRL_METADATA_KEY_URI);
keys = grl_property_get_keys (property, TRUE);
for (key = keys; key; key = g_list_next (keys)) {
   if (handle_key(key)) {
      grl_property_set_string (key, key_value);
   }
}

As it can be notice, related keys are already embedded in GrlProperty;
application does not need to ask registry about related keys.


But if you dislike this function, I can get rid of it.

I think this is a bit unnatural. If people need to know the keys related with another, they should just use the registry API for that, since that is the API used to register these relations to begin with. I would remove this from the API.

Iago


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]