On Tue, 27 Apr 2010 20:13:52 +0200
Erik Massop <[email protected]> wrote:

> I think the code in the attachment (if the attachment is not eaten by
> the list) should do what you want. Compile with gcc -Wall -Wextra
> `pkg-config --cflags --libs xmms2-client` -o foo foo.c or similar.

Of course the list devoured the attachment. Let's try again with a
different mime-type.
#include <stdlib.h>
#include <stdio.h>
#include <xmmsclient/xmmsclient.h>

const char *fieldnames[] = {
        "artist",
        "album",
        NULL};

static void
handle_list_dicts (xmmsv_t *val) {
        xmmsv_list_iter_t *it;
        xmmsv_t *dict;
        unsigned int i;
        const char *buf;

        /* Iterate over list */
        if (!xmmsv_get_list_iter (val, &it)) {
                fputs ("Oh no!\n", stderr);
                return;
        }
        for (xmmsv_list_iter_first (it);
             xmmsv_list_iter_valid (it);
             xmmsv_list_iter_next (it)) {

                if (!xmmsv_list_iter_entry (it, &dict)) {
                        fputs ("Creepy!\n", stderr);
                        return;
                }

                /* print wanted fields */
                for (i = 0; fieldnames[i]; i++) {
                        if (!xmmsv_dict_entry_get_string (dict, fieldnames[i], 
&buf)) {
                                buf = "?????";
                        }

                        if (i > 0) {
                                fputc ('\t', stdout);
                        }
                        fputs (buf, stdout);
                }
                fputc ('\n', stdout);
        }
}

int main () {
        xmmsc_connection_t *conn;
        xmmsc_result_t *res;
        xmmsv_coll_t *univ;
        xmmsv_t *fields, *val;

        /* connect */
        conn = xmmsc_init ("akkabakkalakkabakka");
        if (!xmmsc_connect (conn, NULL)) {
                fputs ("Auch!\n", stderr);
                xmmsc_unref (conn);

                return 1;
        }

        /* request stuff */
        univ = xmmsv_coll_universe ();
        fields = xmmsv_make_stringlist ((char **)fieldnames, -1);

        res = xmmsc_coll_query_infos (conn, univ, fields, 0, 0, fields, fields);

        xmmsv_unref (fields);
        xmmsv_coll_unref (univ);

        /* get stuff */
        xmmsc_result_wait (res);
        val = xmmsc_result_get_value (res); // val still owned by res
        if (xmmsv_is_error (val)) {
                fputs ("Arg!\n", stderr);
                xmmsc_result_unref (res);
                xmmsc_unref (conn);

                return 1;
        }

        /* process stuff */
        handle_list_dicts (val);

        /* clean up */
        xmmsc_result_unref (res);
        xmmsc_unref (conn);

        return 0;
}
--
_______________________________________________
Xmms2-devel mailing list
[email protected]
http://lists.xmms.se/cgi-bin/mailman/listinfo/xmms2-devel

Reply via email to