Yet another API evolution: multi-valued GrlData



Rationale: some fields might need to have several values, such as
thumbnails that can be provided in several resolutions, or description
provided in several languages, also, there could be more than one author
to a media.

API Proposal:

The idea would be to have key-(value list) pairs instead of key-value
pairs. That idea can also be seen in ocaml's Hashtbl:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Hashtbl.html

The present API would work by only addressing the first value of the list.

Then, we would need:

GList * grl_data_get_all (GrlData *data, GrlKeyID key);

Return a GList of all the GValue that have been set for key. The list
should be freed by the caller, but its content remain owned by the
GrlData object and should not be modified

The methods grl_data_set*() would change meaning, in that they will
prepend a value to the list of value. The "old" getters will get the
first value of the list.
Some "options" would probably make sense, like a _remove_all() and a
_replace().

Then, for instance for the thumbnail case, a user that only want the
default thumbnail would do a simple:
  thumbnail = grl_media_get_thumbnail (media);
But the use who want to chose among all those available would access two
keys: thumbnail and thumbnail-size, here is a very basic (and maybe
unpractical) example of use:
  GList *thumbnails = grl_data_get_all (GRL_DATA (media),
GRL_METADATA_KEY_THUMBNAIL);
  GList *sizes = grl_data_get_all (GRL_DATA (media),
GRL_METADATA_KEY_THUMBNAIL_SIZE);
  gchar *thumbnail_url = g_list_nth_data (thumbnails, g_list_index
(sizes, 320*200))

Thoughts? Ideas? Alternatives?

Guij


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