Browsing the contents of a source

The major use case of a source is browsing. Developers can explore the contents of a particular container exposed by the source using the method mafw_source_browse and the object identifier of the container. Here is an example that browses contents from the root container of a certain source:

static void
browse_cb(MafwSource *source,
          guint browseid,
          gint remaining,
          guint index,
          const gchar *objectid,
          GHashTable *metadata,
          gpointer user_data,
          const GError *error)
        if (error != NULL) {
                g_print("Browse error %d: %s\n", error->code, error->message);
        } else if (objectid != NULL) {
                gchar *title, *artist, *album, *mime;

                if (metadata) {
                        GValue *v;
                        v = mafw_metadata_first(metadata,
                        title = v ? g_value_get_string(v) : "Unknown";
                        v = mafw_metadata_first(metadata,
                        artist = v ? g_value_get_string(v) : "Unknown";
                        v = mafw_metadata_first(metadata,
                        album = v ? g_value_get_string(v) : "Unknown";
                        v = mafw_metadata_first(metadata,
                        mime = v ? g_value_get_string(v) : "Unknown";
                } else {
                        title = "Unknown";
                        artist = "Unknown";
                        album = "Unknown";
                        mime = "Unknown";

                g_print("Got object ID: %s\n", objectid);
                g_print("        Index: %u\n", index);
                g_print("        Title: %s\n", title);
                g_print("       Artist: %s\n", artist);
                g_print("        Album: %s\n", album);
                g_print("         Mime: %s\n", mime);
        } else {
                g_print("The query %d did not return any results\n", browseid);

static void
browse_example (MafwSource *source, gchar *objectid)
        const gchar *const *keys;
        guint browseid;

        keys = MAFW_SOURCE_LIST(

        browseid =
                   source,            /* The source object */
                   objectid,          /* The object ID to browse */
                   FALSE,             /* Do recursive browse? */
                   NULL,              /* Filter */
                   NULL,              /* Sort criteria */
                   keys,              /* Metadata to retrieve */
                   0, 20,             /* Offset and count */
                   browse_cb,         /* Callback */
                   NULL);             /* Callback user data */

The example browses the contents of a given object identifier in particular source. The meaning of the parameters is:

For more details, please check the Mafw API reference.

The mafw_source_browse function returns a browse identifier that can be used to match browse results with the corresponding browse operations.

The results of the browse call are returned using the provided callback. This callback is invoked each time a matching result is found by the source. Each time the callback is invoked it informs about:

Also, in case that no results match the browse operation, the callback is invoked once, with the object ID parameter set to NULL.