gboolean cli_jump (cli_context_t *ctx, command_t *cmd) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); xmmsv_t *query; gboolean backward = FALSE; playlist_positions_t *positions; command_flag_boolean_get (cmd, "backward", &backward); /* Select by positions */ if (command_arg_positions_get (cmd, 0, &positions, cli_context_current_position (ctx))) { gint pos; if (playlist_positions_get_single (positions, &pos)) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_playlist_set_next, conn, pos), XMMS_CALL_P (xmmsc_playback_tickle, conn)); } else { g_printf (_("Cannot jump to several positions!\n")); } playlist_positions_free (positions); /* Select by pattern */ } else if (command_arg_pattern_get (cmd, 0, &query, TRUE)) { query = xmmsv_coll_intersect_with_playlist (query, XMMS_ACTIVE_PLAYLIST); XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0), FUNC_CALL_P (cli_jump_relative, ctx, (backward ? -1 : 1), XMMS_PREV_VALUE)); xmmsv_unref (query); } return FALSE; }
/* Get current position in @playlist or in active playlist if @playlist == NULL. */ static gboolean playlist_currpos_get (cli_context_t *ctx, const gchar *playlist, gint *pos) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); if (playlist) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_get, conn, playlist, XMMS_COLLECTION_NS_PLAYLISTS), FUNC_CALL_P (playlist_coll_attribute_get_position, XMMS_PREV_VALUE, pos)); } else { *pos = cli_context_current_position (ctx); } return TRUE; }
static column_display_t * cli_list_classic_column_display (cli_context_t *ctx) { configuration_t *config = cli_context_config (ctx); column_display_t *coldisp; const gchar *format, *marker; marker = configuration_get_string (config, "PLAYLIST_MARKER"); format = configuration_get_string (config, "CLASSIC_LIST_FORMAT"); /* FIXME: compute field size dynamically instead of hardcoding maxlen? */ coldisp = column_display_init (); column_display_set_list_marker (coldisp, marker); column_display_add_special (coldisp, "", GINT_TO_POINTER(cli_context_current_position (ctx)), 2, COLUMN_DEF_SIZE_FIXED, COLUMN_DEF_ALIGN_LEFT, column_display_render_highlight); column_display_add_separator (coldisp, "["); column_display_add_special (coldisp, "pos", NULL, 0, COLUMN_DEF_SIZE_AUTO, COLUMN_DEF_ALIGN_RIGHT, column_display_render_position); column_display_add_separator (coldisp, "/"); column_display_add_property (coldisp, "id", "id", 0, COLUMN_DEF_SIZE_AUTO, COLUMN_DEF_ALIGN_LEFT); column_display_add_separator (coldisp, "] "); column_display_add_format (coldisp, "tracks", format, 0, COLUMN_DEF_SIZE_AUTO, COLUMN_DEF_ALIGN_LEFT); /* FIXME: making duration part of the format would require proper * rendering of duration in xmmsv_dict_format and conditional * expressions to the parentheses if no duration is present. */ /* FIXME: if time takes 6 chars, the display will exceed termwidth.. */ column_display_add_separator (coldisp, " ("); column_display_add_special (coldisp, "duration", (gpointer) "duration", 5, COLUMN_DEF_SIZE_FIXED, COLUMN_DEF_ALIGN_LEFT, column_display_render_time); column_display_add_separator (coldisp, ")"); return coldisp; }
/* TODO: Not really a part of the server sub-command, but in the future it * can be refactored to just call "xmms2 server property" and let that * do the printing */ gboolean cli_info (cli_context_t *ctx, command_t *cmd) { xmmsc_connection_t *conn = cli_context_xmms_sync (ctx); playlist_positions_t *positions; xmmsv_t *query; gint current_position = cli_context_current_position (ctx); gint current_id = cli_context_current_id (ctx); if (command_arg_positions_get (cmd, 0, &positions, current_position)) { cli_info_print_positions (ctx, positions); playlist_positions_free (positions); } else if (command_arg_pattern_get (cmd, 0, &query, FALSE)) { XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_coll_query_ids, conn, query, NULL, 0, 0); FUNC_CALL_P (cli_info_print_list, ctx, XMMS_PREV_VALUE)); xmmsv_unref (query); } else {
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 currently_playing_update_position (currently_playing_t *entry) { gint current_position = cli_context_current_position (entry->ctx); xmmsv_dict_set_int (entry->data, "position", current_position); }