Exemplo n.º 1
0
/* For all label-operator pairs, write the operator and all its
 * operands to the DB recursively. */
static void
dbwrite_operator (void *key, void *value, void *udata)
{
	gchar *query;
	gchar *label = key;
	xmmsv_coll_t *coll = value;
	coll_dbwrite_t *dbinfos = udata;
	gchar *esc_label;
	gint serial_id;

	/* Only serialize each operator once, get previous id if exists */
	if (!xmms_collection_get_int_attr (coll, XMMS_COLLSERIAL_ATTR_ID, &serial_id)) {
		serial_id = dbinfos->collid;
		dbinfos->collid = xmms_collection_dbwrite_operator (dbinfos->session,
		                                                    dbinfos->collid, coll);
		xmms_collection_set_int_attr (coll, XMMS_COLLSERIAL_ATTR_ID, serial_id);
	}

	esc_label = sqlite_prepare_string (label);
	query = g_strdup_printf ("INSERT INTO CollectionLabels VALUES(%d, %d, %s)",
	                         serial_id, dbinfos->nsid, esc_label);
	xmms_medialib_select (dbinfos->session, query, NULL);

	g_free (query);
	g_free (esc_label);
}
Exemplo n.º 2
0
static void
xmms_playlist_update_partyshuffle (xmms_playlist_t *playlist,
                                   const gchar *plname, xmmsv_coll_t *coll)
{
	gint history, upcoming, currpos, size;
	xmmsv_coll_t *src;
	xmmsv_t *tmp;

	XMMS_DBG ("PLAYLIST: Update partyshuffle.");

	if (!xmms_collection_get_int_attr (coll, "history", &history)) {
		history = 0;
	}

	if (!xmms_collection_get_int_attr (coll, "upcoming", &upcoming)) {
		upcoming = XMMS_DEFAULT_PARTYSHUFFLE_UPCOMING;
	}

	currpos = xmms_playlist_coll_get_currpos (coll);
	while (currpos > history) {
		/* Removing entries is fast enough to be processed at once. */
		xmms_playlist_remove_unlocked (playlist, plname, coll, 0, NULL);
		currpos = xmms_playlist_coll_get_currpos (coll);
	}

	g_return_if_fail(xmmsv_list_get (xmmsv_coll_operands_get (coll), 0, &tmp));
	g_return_if_fail(xmmsv_get_coll (tmp, &src));

	/* Since getting random media can be slow on huge medialibs, we refill only
	 * one entry at a time. This let other threads a chance to get the lock on
	 * the playlist object as soon as possible. */
	size = xmms_playlist_coll_get_size (coll);
	if (size < currpos + 1 + upcoming) {
		xmms_medialib_entry_t randentry;
		randentry = xmms_collection_get_random_media (playlist->colldag, src);
		if (randentry > 0) {
			xmms_playlist_add_entry_unlocked (playlist, plname, coll, randentry, NULL);
		}
	}
}
Exemplo n.º 3
0
/** Get the current position in the given playlist (set to -1 if absent). */
static gint
xmms_playlist_coll_get_currpos (xmmsv_coll_t *plcoll)
{
	gint currpos;

	/* If absent, set to -1 and save it */
	if (!xmms_collection_get_int_attr (plcoll, "position", &currpos)) {
		currpos = -1;
		xmms_collection_set_int_attr (plcoll, "position", currpos);
	}

	return currpos;
}
Exemplo n.º 4
0
static void
xmms_playlist_update_queue (xmms_playlist_t *playlist, const gchar *plname,
                            xmmsv_coll_t *coll)
{
	gint history, currpos;

	XMMS_DBG ("PLAYLIST: update queue.");

	if (!xmms_collection_get_int_attr (coll, "history", &history)) {
		history = 0;
	}

	currpos = xmms_playlist_coll_get_currpos (coll);
	while (currpos > history) {
		/* Removing entries is fast enough to be processed at once. */
		xmms_playlist_remove_unlocked (playlist, plname, coll, 0, NULL);
		currpos = xmms_playlist_coll_get_currpos (coll);
	}
}