/* * call-seq: * pl.insert_entry(pos, arg) -> result * * Inserts an entry to the current playlist at position _pos_ in the playlist. * _arg_ can be either a URL or an id. */ static VALUE c_insert_entry (VALUE self, VALUE pos, VALUE arg) { int32_t id; int32_t ipos; PLAYLIST_METHOD_HANDLER_HEADER ipos = check_int32 (pos); if (!NIL_P (rb_check_string_type (arg))) res = xmmsc_playlist_insert_url (xmms->real, pl->name, ipos, StringValuePtr (arg)); else { id = check_int32 (arg); res = xmmsc_playlist_insert_id (xmms->real, pl->name, ipos, id); } PLAYLIST_METHOD_HANDLER_FOOTER }
void cmd_insert (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *playlist = NULL; guint pos; gchar *url; char *endptr; xmmsc_result_t *res; if (argc < 4) { print_error ("Need a position and a file"); } pos = strtol (argv[2], &endptr, 10); if (*endptr == '\0') { url = format_url (argv[3], G_FILE_TEST_IS_REGULAR); /* No playlist name */ } else { playlist = argv[2]; /* extract playlist name */ pos = strtol (argv[3], NULL, 10); url = format_url (argv[4], G_FILE_TEST_IS_REGULAR); } if (!url) { print_error ("Invalid url"); } res = xmmsc_playlist_insert_url (conn, playlist, pos, url); xmmsc_result_wait (res); if (xmmsc_result_iserror (res)) { print_error ("Unable to add %s at postion %u: %s", url, pos, xmmsc_result_get_error (res)); } xmmsc_result_unref (res); print_info ("Inserted %s at %u", url, pos); g_free (url); }