Пример #1
0
static gboolean
xmms_playlist_remove_unlocked (xmms_playlist_t *playlist, const gchar *plname,
                               xmmsv_coll_t *plcoll, guint pos, xmms_error_t *err)
{
	gint currpos;
	xmmsv_t *dict;

	g_return_val_if_fail (playlist, FALSE);

	currpos = xmms_playlist_coll_get_currpos (plcoll);

	if (!xmmsv_coll_idlist_remove (plcoll, pos)) {
		if (err) xmms_error_set (err, XMMS_ERROR_NOENT, "Entry was not in list!");
		return FALSE;
	}

	dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_REMOVE, 0, plname);
	xmmsv_dict_set_int (dict, "position", pos);
	xmms_playlist_changed_msg_send (playlist, dict);

	/* decrease current position if removed entry was before or if it's
	 * the current entry, but only if current position is a valid entry.
	 */
	if (currpos != -1 && pos <= currpos) {
		currpos = MAX (0, currpos - 1);
		xmms_collection_set_int_attr (plcoll, "position", currpos);
		XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);
	}

	return TRUE;
}
Пример #2
0
/**
 * Insert an entry at a given position in the playlist without
 * validating it.
 *
 * @internal
 */
void
xmms_playlist_insert_entry (xmms_playlist_t *playlist, const gchar *plname,
                            guint32 pos, xmms_medialib_entry_t file,
                            xmms_error_t *err)
{
    xmms_medialib_session_t *session;
    xmmsv_t *dict;
    gint currpos;
    gint len;
    xmmsv_coll_t *plcoll;
    gboolean valid;

    g_mutex_lock (playlist->mutex);

    do {
        session = xmms_medialib_session_begin_ro (playlist->medialib);
        valid = xmms_medialib_check_id (session, file);
    } while (!xmms_medialib_session_commit (session));

    if (!valid) {
        g_mutex_unlock (playlist->mutex);
        xmms_error_set (err, XMMS_ERROR_NOENT,
                        "That is not a valid medialib id!");
        return;
    }


    plcoll = xmms_playlist_get_coll (playlist, plname, err);
    if (plcoll == NULL) {
        /* FIXME: happens ? */
        g_mutex_unlock (playlist->mutex);
        return;
    }

    len = xmms_playlist_coll_get_size (plcoll);
    if (pos > len) {
        xmms_error_set (err, XMMS_ERROR_GENERIC,
                        "Could not insert entry outside of playlist!");
        g_mutex_unlock (playlist->mutex);
        return;
    }
    xmmsv_coll_idlist_insert (plcoll, pos, file);

    /** propagate the MID ! */
    dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_INSERT, file, plname);
    xmmsv_dict_set_int (dict, "position", pos);
    xmms_playlist_changed_msg_send (playlist, dict);

    /** update position once client is familiar with the new item. */
    currpos = xmms_playlist_coll_get_currpos (plcoll);
    if (pos <= currpos) {
        currpos++;
        xmms_collection_set_int_attr (plcoll, "position", currpos);
        XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);
    }

    g_mutex_unlock (playlist->mutex);
}
Пример #3
0
/**
 * Add an entry to the playlist without locking the mutex.
 */
void
xmms_playlist_add_entry_unlocked (xmms_playlist_t *playlist,
                                  const gchar *plname,
                                  xmmsv_coll_t *plcoll,
                                  xmms_medialib_entry_t file,
                                  xmms_error_t *err)
{
	gint prev_size;
	xmmsv_t *dict;

	prev_size = xmms_playlist_coll_get_size (plcoll);
	xmmsv_coll_idlist_append (plcoll, file);

	/** propagate the MID ! */
	dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_ADD, file, plname);
	xmmsv_dict_set_int (dict, "position", prev_size);
	xmms_playlist_changed_msg_send (playlist, dict);
}
Пример #4
0
/**
 * Move an entry in playlist
 *
 */
static void
xmms_playlist_client_move_entry (xmms_playlist_t *playlist,
                                 const gchar *plname, gint32 pos,
                                 gint32 newpos, xmms_error_t *err)
{
	xmmsv_t *dict;
	xmms_medialib_entry_t id;
	gint currpos, size;
	gint64 ipos, inewpos;
	xmmsv_coll_t *plcoll;

	g_return_if_fail (playlist);

	XMMS_DBG ("Moving %d, to %d", pos, newpos);

	g_mutex_lock (playlist->mutex);

	plcoll = xmms_playlist_get_coll (playlist, plname, err);
	if (plcoll == NULL) {
		/* FIXME: happens ? */
		g_mutex_unlock (playlist->mutex);
		return;
	}

	currpos = xmms_playlist_coll_get_currpos (plcoll);
	size = xmms_playlist_coll_get_size (plcoll);

	if (size == 0 || newpos > (size - 1)) {
		xmms_error_set (err, XMMS_ERROR_NOENT,
		                "Cannot move entry outside playlist");
		g_mutex_unlock (playlist->mutex);
		return;
	}

	if (!xmmsv_coll_idlist_move (plcoll, pos, newpos)) {
		xmms_error_set (err, XMMS_ERROR_NOENT, "Entry was not in list!");
		g_mutex_unlock (playlist->mutex);
		return;
	}

	/* Update the current position pointer */
	ipos = pos;
	inewpos = newpos;
	if (inewpos <= currpos && ipos > currpos)
		currpos++;
	else if (inewpos >= currpos && ipos < currpos)
		currpos--;
	else if (ipos == currpos)
		currpos = inewpos;

	xmms_collection_set_int_attr (plcoll, "position", currpos);

	xmmsv_coll_idlist_get_index (plcoll, newpos, &id);

	dict = xmms_playlist_changed_msg_new (playlist, XMMS_PLAYLIST_CHANGED_MOVE, id, plname);
	xmmsv_dict_set_int (dict, "position", pos);
	xmmsv_dict_set_int (dict, "newposition", newpos);
	xmms_playlist_changed_msg_send (playlist, dict);

	XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname);

	g_mutex_unlock (playlist->mutex);

	return;

}