/*
 * call-seq:
 *  xc.medialib_entry_property_set(id, key, value, *source) -> result
 *
 * Write info to the medialib at _id_. _source_ is an optional argument that
 * describes where to write the mediainfo. If _source_ is omitted, the
 * mediainfo is written to "client/<yourclient>" where <yourclient> is the
 * name you specified in _Xmms::Client.new(name)_.
 */
static VALUE
c_medialib_entry_property_set (int argc, VALUE *argv, VALUE self)
{
        VALUE tmp, key, value, src = Qnil;
        RbXmmsClient *xmms = NULL;
        xmmsc_result_t *res;
        const char *ckey;
        bool is_str = false;
        uint32_t id;
        int32_t ivalue;

        Data_Get_Struct (self, RbXmmsClient, xmms);

        CHECK_DELETED (xmms);

        rb_scan_args (argc, argv, "31", &tmp, &key, &value, &src);

        id = check_uint32 (tmp);
        Check_Type (key, T_SYMBOL);

        if (!NIL_P (rb_check_string_type (value)))
                is_str = true;
        else
                ivalue = check_int32 (value);

        ckey = rb_id2name (SYM2ID (key));

        if (NIL_P (src) && is_str)
                res = xmmsc_medialib_entry_property_set_str (xmms->real, id,
                                                             ckey,
                                                             StringValuePtr (value));
        else if (NIL_P (src))
                res = xmmsc_medialib_entry_property_set_int (xmms->real, id,
                                                             ckey, ivalue);
        else if (is_str)
                res = xmmsc_medialib_entry_property_set_str_with_source (
                        xmms->real, id,
                        StringValuePtr (src),
                        ckey,
                        StringValuePtr (value));
        else
                res = xmmsc_medialib_entry_property_set_int_with_source (
                        xmms->real, id,
                        StringValuePtr (src),
                        ckey, ivalue);

        return TO_XMMS_CLIENT_RESULT (self, res);
}