/* Get length of @playlist or of active playlist if @playlist == NULL. */ static gboolean playlist_length_get (cli_context_t *ctx, const gchar *playlist, gint *length) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); *length = -1; if (playlist) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS), FUNC_CALL_P (playlist_coll_idlist_get_size, XMMS_PREV_VALUE, length)); } else { xmmsv_t *entries = cli_context_active_playlist (ctx); *length = xmmsv_list_get_size (entries); } return *length >= 0; }
static void cli_jump_relative (cli_context_t *ctx, gint inc, xmmsv_t *value) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); xmmsv_list_iter_t *it; gint i, plid, id, currpos, plsize; xmmsv_t *playlist; currpos = cli_context_current_position (ctx); playlist = cli_context_active_playlist (ctx); plsize = xmmsv_list_get_size (playlist); /* If no currpos, start jump from beginning */ if (currpos < 0) { currpos = 0; } /* magic trick so we can loop in either direction */ inc += plsize; xmmsv_get_list_iter (value, &it); /* Loop on the playlist */ for (i = (currpos + inc) % plsize; i != currpos; i = (i + inc) % plsize) { xmmsv_list_iter_first (it); xmmsv_list_get_int (playlist, i, &plid); /* Loop on the matched media */ while (xmmsv_list_iter_entry_int (it, &id)) { /* If both match, jump! */ if (plid == id) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next, conn, i), XMMS_CALL_P (xmmsc_playback_tickle, conn)); return; } xmmsv_list_iter_next (it); } } /* No matching media found, don't jump */ g_printf (_("No media matching the pattern in the playlist!\n")); }
static void cli_info_print_position (gint pos, void *userdata) { cli_info_print_positions_t *pack = (cli_info_print_positions_t *) userdata; xmmsc_connection_t *conn = cli_context_xmms_sync (pack->ctx); xmmsv_t *playlist = cli_context_active_playlist (pack->ctx); gint id; /* Skip if outside of playlist */ if (!xmmsv_list_get_int (playlist, pos, &id)) { return; } /* Do not prepend newline before the first entry */ if (pack->inc > 0) { g_printf ("\n"); } else { pack->inc++; } XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, conn, id), FUNC_CALL_P (cli_info_print, XMMS_PREV_VALUE)); }