Exemplo n.º 1
0
static xmms_fetch_spec_t *
xmms_fetch_spec_new_metadata (xmmsv_t *fetch, xmms_fetch_info_t *info,
                              s4_sourcepref_t *prefs, xmms_error_t *err)
{
	xmms_fetch_spec_t *ret = NULL;
	s4_sourcepref_t *sp;
	const gchar *key;
	xmmsv_t *gets, *fields;
	gint i, size, aggregate, get;

	aggregate = normalize_aggregate_function (fetch, err);
	if (xmms_error_iserror (err)) {
		return NULL;
	}

	fields = normalize_metadata_fields (fetch, err);
	if (xmms_error_iserror (err)) {
		return NULL;
	}

	gets = normalize_metadata_get (fetch, err);
	if (xmms_error_iserror (err)) {
		return NULL;
	}

	sp = normalize_source_preferences (fetch, prefs, err);
	if (xmms_error_iserror (err)) {
		xmmsv_unref (gets);
		return NULL;
	}

	ret = g_new0 (xmms_fetch_spec_t, 1);
	ret->type = FETCH_METADATA;
	ret->data.metadata.aggr_func = aggregate;

	for (i = 0; i < 4 && xmmsv_list_get_int (gets, i, &get); i++) {
		ret->data.metadata.get[i] = get;
	}
	ret->data.metadata.get_size = i;

	if (fields != NULL) {
		size = xmmsv_list_get_size (fields);
		ret->data.metadata.col_count = size;
		ret->data.metadata.cols = g_new (gint32, size);
		for (i = 0; xmmsv_list_get_string (fields, i, &key); i++) {
			ret->data.metadata.cols[i] = xmms_fetch_info_add_key (info, fetch, key, sp);
		}
	} else {
		/* No fields requested, fetching all available */
		ret->data.metadata.col_count = 1;
		ret->data.metadata.cols = g_new0 (gint32, 1);
		ret->data.metadata.cols[0] = xmms_fetch_info_add_key (info, fetch, NULL, sp);
	}

	s4_sourcepref_unref (sp);
	xmmsv_unref (gets);

	return ret;
}
Exemplo n.º 2
0
/**
 * Retrieves the value at the given position in the idlist.
 * @param coll  The collection to update.
 * @param index The position of the value to retrieve.
 * @param val   The pointer at which to store the found value.
 * @return  TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_get_index_int32 (xmmsv_t *coll, int index, int32_t *val)
{
	int64_t raw_val;
	x_return_val_if_fail (coll, 0);
	if (xmmsv_list_get_int (coll->value.coll->idlist, index, &raw_val)) {
		*val = INT64_TO_INT32 (raw_val);
		return true;
	}
	return false;
}
Exemplo n.º 3
0
static void
cli_list_print_positions_row (gint pos, void *udata)
{
	cli_list_positions_t *pack = (cli_list_positions_t *) udata;
	gint id;

	if (pos >= xmmsv_list_get_size (pack->entries)) {
		return;
	}

	if (xmmsv_list_get_int (pack->entries, pos, &id)) {
		column_display_set_position (pack->coldisp, pos);
		XMMS_CALL_CHAIN (XMMS_CALL_P (xmmsc_medialib_get_info, pack->sync, id),
		                 FUNC_CALL_P (cli_list_print_row, pack->coldisp, XMMS_PREV_VALUE));
	}
}
Exemplo n.º 4
0
void
xmms_playlist_client_add_collection (xmms_playlist_t *playlist, const gchar *plname,
                                     xmmsv_coll_t *coll, xmms_error_t *err)
{
    xmmsv_t *res;
    int32_t id;
    int i;

    res = xmms_collection_query_ids (playlist->colldag, coll, err);

    for (i = 0; xmmsv_list_get_int (res, i, &id); i++) {
        xmms_playlist_add_entry (playlist, plname, id, err);
    }

    xmmsv_unref (res);
}
Exemplo n.º 5
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"));
}
Exemplo n.º 6
0
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));
}
Exemplo n.º 7
0
/** Sorts the playlist by properties.
 *
 *  This will sort the list.
 *  @param playlist The playlist to sort.
 *  @param properties Tells xmms_playlist_sort which properties it
 *  should use when sorting.
 *  @param err An #xmms_error_t - needed since xmms_playlist_sort is an ipc
 *  method handler.
 */
static void
xmms_playlist_client_replace (xmms_playlist_t *playlist, const gchar *plname,
                              xmmsv_coll_t *coll, xmms_playlist_position_action_t action,
                              xmms_error_t *err)
{
    xmms_medialib_entry_t id, current_id;
    xmmsv_coll_t *plcoll;
    xmmsv_t *result;
    gint current_position, i;

    g_return_if_fail (playlist);
    g_return_if_fail (coll);

    g_mutex_lock (playlist->mutex);

    plcoll = xmms_playlist_get_coll (playlist, plname, err);
    if (plcoll == NULL) {
        xmms_error_set (err, XMMS_ERROR_NOENT, "no such playlist!");
        g_mutex_unlock (playlist->mutex);
        return;
    }

    current_position = xmms_playlist_coll_get_currpos (plcoll);
    xmmsv_coll_idlist_get_index (plcoll, current_position, &current_id);

    result = xmms_collection_query_ids (playlist->colldag, coll, err);
    if (result == NULL) {
        g_mutex_unlock (playlist->mutex);
        return;
    }

    xmmsv_coll_idlist_clear (plcoll);

    current_position = -1;

    for (i = 0; xmmsv_list_get_int (result, i, &id); i++) {
        if (id == current_id)
            current_position = i;
        xmmsv_coll_idlist_append (plcoll, id);
    }

    switch (action) {
    case XMMS_PLAYLIST_CURRENT_ID_FORGET:
        current_position = -1;
        break;
    case XMMS_PLAYLIST_CURRENT_ID_MOVE_TO_FRONT:
        if (current_position > 0) {
            xmmsv_coll_idlist_move (plcoll, current_position, 0);
            current_position = 0;
        }
        break;
    default:
        break;
    }

    xmmsv_unref (result);

    xmms_collection_set_int_attr (plcoll, "position", current_position);

    XMMS_PLAYLIST_CHANGED_MSG (XMMS_PLAYLIST_CHANGED_REPLACE,
                               (current_position < 0) ? 0 : current_id, plname);
    XMMS_PLAYLIST_CURRPOS_MSG (current_position, plname);

    g_mutex_unlock (playlist->mutex);
}
Exemplo n.º 8
0
/**
 * Retrieves the value at the given position in the idlist.
 * @param coll  The collection to update.
 * @param index The position of the value to retrieve.
 * @param val   The pointer at which to store the found value.
 * @return TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_get_index_int64 (xmmsv_t *coll, int index, int64_t *val)
{
	x_return_val_if_fail (coll, 0);
	return xmmsv_list_get_int (coll->value.coll->idlist, index, val);
}