Exemplo n.º 1
0
static void
playlist_setup_pshuffle (xmmsc_connection_t *conn, xmmsv_coll_t *coll, gchar *ref)
{
	xmmsc_result_t *psres;
	xmmsv_coll_t *refcoll;
	gchar *s_name, *s_namespace;

	if (!coll_read_collname (ref, &s_name, &s_namespace)) {
		print_error ("invalid source collection name");
	}

	/* Quick shortcut to use Universe for "All Media" */
	if (strcmp (s_name, "All Media") == 0) {
		refcoll = xmmsv_coll_universe ();
	} else {
		psres = xmmsc_coll_get (conn, s_name, s_namespace);
		xmmsc_result_wait (psres);

		if (xmmsc_result_iserror (psres)) {
			print_error ("%s", xmmsc_result_get_error (psres));
		}

		refcoll = xmmsv_coll_new (XMMS_COLLECTION_TYPE_REFERENCE);
		xmmsv_coll_attribute_set (refcoll, "reference", s_name);
		xmmsv_coll_attribute_set (refcoll, "namespace", s_namespace);
	}

	/* Set operand */
	xmmsv_coll_add_operand (coll, refcoll);
	xmmsv_coll_unref (refcoll);

	g_free (s_name);
	g_free (s_namespace);
}
Exemplo n.º 2
0
static xmmsv_coll_t *
coll_make_reference (const char *name, xmmsc_coll_namespace_t ns)
{
	xmmsv_coll_t *ref;

	ref = xmmsv_coll_new (XMMS_COLLECTION_TYPE_REFERENCE);
	xmmsv_coll_attribute_set (ref, "reference", name);
	xmmsv_coll_attribute_set (ref, "namespace", ns);

	return ref;
}
Exemplo n.º 3
0
static void
setup_default_playlist (void)
{
	xmmsv_coll_t *coll;

	coll = xmmsv_coll_new (XMMS_COLLECTION_TYPE_IDLIST);

	xmms_collection_dag_replace (colldag, XMMS_COLLECTION_NSID_PLAYLISTS,
	                             "Default", coll);
	xmmsv_coll_ref (coll);

	xmms_collection_dag_replace (colldag, XMMS_COLLECTION_NSID_PLAYLISTS,
	                             XMMS_ACTIVE_PLAYLIST, coll);
}
Exemplo n.º 4
0
/**
 * Create a new empty playlist.
 */
xmmsc_result_t *
xmmsc_playlist_create (xmmsc_connection_t *c, const char *playlist)
{
	xmmsc_result_t *res;
	xmmsv_coll_t *plcoll;

	x_check_conn (c, NULL);
	x_api_error_if (!playlist, "playlist name cannot be NULL", NULL);

	plcoll = xmmsv_coll_new (XMMS_COLLECTION_TYPE_IDLIST);
	res = xmmsc_coll_save (c, plcoll, playlist, XMMS_COLLECTION_NS_PLAYLISTS);

	xmmsv_coll_unref (plcoll);

	return res;
}
Exemplo n.º 5
0
xmmsv_coll_t *
xmmsv_coll_copy (xmmsv_coll_t *orig_coll)
{
	xmmsv_coll_t *new_coll, *coll_elem;
	xmmsv_list_iter_t *it;
	xmmsv_dict_iter_t *itd;
	xmmsv_t *v, *list, *dict;
	const char *key;
	int32_t i;
	const char *s;

	new_coll = xmmsv_coll_new (xmmsv_coll_get_type (orig_coll));

	list = xmmsv_coll_idlist_get (orig_coll);
	x_return_val_if_fail (xmmsv_get_list_iter (list, &it), NULL);
	while (xmmsv_list_iter_valid (it)) {
		xmmsv_list_iter_entry (it, &v);
		xmmsv_get_int (v, &i);
		xmmsv_coll_idlist_append (new_coll, i);
		xmmsv_list_iter_next (it);
	}
	xmmsv_list_iter_explicit_destroy (it);

	list = xmmsv_coll_operands_get (orig_coll);
	x_return_val_if_fail (xmmsv_get_list_iter (list, &it), NULL);
	while (xmmsv_list_iter_valid (it)) {
		xmmsv_list_iter_entry (it, &v);
		xmmsv_get_coll (v, &coll_elem);
		xmmsv_coll_add_operand (new_coll, xmmsv_coll_copy (coll_elem));
		xmmsv_list_iter_next (it);
	}
	xmmsv_list_iter_explicit_destroy (it);

	dict = xmmsv_coll_attributes_get (orig_coll);
	x_return_val_if_fail (xmmsv_get_dict_iter (dict, &itd), NULL);
	while (xmmsv_dict_iter_valid (itd)) {
		xmmsv_dict_iter_pair (itd, &key, &v);
		xmmsv_get_string (v, &s);
		xmmsv_coll_attribute_set (new_coll, key, s);
		xmmsv_dict_iter_next (itd);
	}
	xmmsv_dict_iter_explicit_destroy (itd);
	return new_coll;
}
Exemplo n.º 6
0
static xmmsv_coll_t *
coll_copy_retype (xmmsv_coll_t *coll, xmmsv_coll_type_t type)
{
	xmmsv_coll_t *copy;
	gint idlistsize;
	gint i;
	guint id;

	copy = xmmsv_coll_new (type);

	idlistsize = xmmsv_coll_idlist_get_size (coll);
	for (i = 0; i < idlistsize; i++) {
		xmmsv_coll_idlist_get_index (coll, i, &id);
		xmmsv_coll_idlist_append (copy, id);
	}

	xmmsv_coll_attribute_foreach (coll, coll_copy_attributes, copy);

	return copy;
}
Exemplo n.º 7
0
static void
handle_file_del (xmonitor_t *mon, gchar *filename)
{
	xmmsc_result_t *res;
	xmmsv_coll_t *univ, *coll;
	gchar tmp[MON_FILENAME_MAX];

	g_snprintf (tmp, MON_FILENAME_MAX, "file://%s%%", filename);

	univ = xmmsv_coll_universe ();
	coll = xmmsv_coll_new (XMMS_COLLECTION_TYPE_MATCH);
	xmmsv_coll_add_operand (coll, univ);
	xmmsv_coll_attribute_set (coll, "field", "url");
	xmmsv_coll_attribute_set (coll, "value", tmp);

	res = xmmsc_coll_query_ids (mon->conn, coll, NULL, 0, 0);

	DBG ("remove '%s' from mlib", tmp);
	xmmsc_result_notifier_set (res, handle_remove_from_mlib, mon);
	xmmsc_result_unref (res);
	xmmsv_coll_unref (coll);
	xmmsv_coll_unref (univ);
}
Exemplo n.º 8
0
static bool
_internal_get_from_bb_collection_alloc (xmmsv_t *bb, xmmsv_coll_t **coll)
{
	int i;
	int32_t type;
	int32_t n_items;
	int id;
	int32_t *idlist = NULL;
	char *key, *val;

	/* Get the type and create the collection */
	if (!_internal_get_from_bb_int32_positive (bb, &type)) {
		return false;
	}

	*coll = xmmsv_coll_new (type);

	/* Get the list of attributes */
	if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
		goto err;
	}

	for (i = 0; i < n_items; i++) {
		unsigned int len;
		if (!_internal_get_from_bb_string_alloc (bb, &key, &len)) {
			goto err;
		}
		if (!_internal_get_from_bb_string_alloc (bb, &val, &len)) {
			free (key);
			goto err;
		}

		xmmsv_coll_attribute_set (*coll, key, val);
		free (key);
		free (val);
	}

	/* Get the idlist */
	if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
		goto err;
	}

	if (!(idlist = x_new (int32_t, n_items + 1))) {
		goto err;
	}

	for (i = 0; i < n_items; i++) {
		if (!_internal_get_from_bb_int32 (bb, &id)) {
			goto err;
		}

		idlist[i] = id;
	}

	idlist[i] = 0;
	xmmsv_coll_set_idlist (*coll, idlist);
	free (idlist);
	idlist = NULL;

	/* Get the operands */
	if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
		goto err;
	}

	for (i = 0; i < n_items; i++) {
		xmmsv_coll_t *operand;

		if (!_internal_get_from_bb_int32_positive (bb, &type) ||
		    type != XMMSV_TYPE_COLL ||
		    !_internal_get_from_bb_collection_alloc (bb, &operand)) {
			goto err;
		}

		xmmsv_coll_add_operand (*coll, operand);
		xmmsv_coll_unref (operand);
	}

	return true;

err:
	if (idlist != NULL) {
		free (idlist);
	}

	xmmsv_coll_unref (*coll);

	return false;
}
Exemplo n.º 9
0
/** Given a collection id, query the DB to build the corresponding
 *  collection DAG.
 *
 * @param session  The medialib session connected to the DB.
 * @param id  The id of the collection to create.
 * @param type  The type of the collection operator.
 * @return  The created collection DAG.
 */
static xmmsv_coll_t *
xmms_collection_dbread_operator (xmms_medialib_session_t *session,
                                 gint id, xmmsv_coll_type_t type)
{
	xmmsv_coll_t *coll;
	xmmsv_coll_t *op;
	GList *res;
	GList *n;
	xmmsv_t *cmdval;
	gchar query[256];

	coll = xmmsv_coll_new (type);

	/* Retrieve the attributes */
	g_snprintf (query, sizeof (query),
	            "SELECT attr.key AS key, attr.value AS value "
	            "FROM CollectionOperators AS op, CollectionAttributes AS attr "
	            "WHERE op.id=%d AND attr.collid=op.id", id);

	res = xmms_medialib_select (session, query, NULL);
	for (n = res; n; n = n->next) {
		const gchar *key, *value;

		cmdval = (xmmsv_t*) n->data;
		key = value_get_dict_string (cmdval, "key");
		value = value_get_dict_string (cmdval, "value");
		xmmsv_coll_attribute_set (coll, key, value);

		xmmsv_unref (n->data);
	}
	g_list_free (res);

	/* Retrieve the idlist */
	g_snprintf (query, sizeof (query),
	            "SELECT idl.mid AS mid "
	            "FROM CollectionOperators AS op, CollectionIdlists AS idl "
	            "WHERE op.id=%d AND idl.collid=op.id "
	            "ORDER BY idl.position", id);

	res = xmms_medialib_select (session, query, NULL);
	for (n = res; n; n = n->next) {

		cmdval = (xmmsv_t *) n->data;
		xmmsv_coll_idlist_append (coll, value_get_dict_int (cmdval, "mid"));

		xmmsv_unref (cmdval);
	}
	g_list_free (res);

	/* Retrieve the operands */
	g_snprintf (query, sizeof (query),
	            "SELECT op.id AS id, op.type AS type "
	            "FROM CollectionOperators AS op, CollectionConnections AS conn "
	            "WHERE conn.to_id=%d AND conn.from_id=op.id", id);

	res = xmms_medialib_select (session, query, NULL);
	for (n = res; n; n = n->next) {
		gint _id;
		gint type;

		cmdval = (xmmsv_t *) n->data;
		_id = value_get_dict_int (cmdval, "id");
		type = value_get_dict_int (cmdval, "type");

		op = xmms_collection_dbread_operator (session, _id, type);
		xmmsv_coll_add_operand (coll, op);

		xmmsv_coll_unref (op);
		xmmsv_unref (cmdval);
	}
	g_list_free (res);

	return coll;
}
Exemplo n.º 10
0
void
cmd_playlist_type (xmmsc_connection_t *conn, gint argc, gchar **argv)
{
	gchar *name;
	xmmsv_coll_type_t prevtype, newtype;
	xmmsc_result_t *res;
	xmmsv_t *val;
	xmmsv_coll_t *coll;

	/* Read playlist name */
	if (argc < 4) {
		print_error ("usage: type_playlist [playlistname] [type] [options]");
	}
	name = argv[3];

	/* Retrieve the playlist operator */
	res = xmmsc_coll_get (conn, name, XMMS_COLLECTION_NS_PLAYLISTS);
	xmmsc_result_wait (res);
	val = xmmsc_result_get_value (res);

	if (xmmsv_is_error (val)) {
		print_error ("%s", xmmsv_get_error_old (val));
	}

	xmmsv_get_coll (val, &coll);
	prevtype = xmmsv_coll_get_type (coll);

	/* No type argument, simply display the current type */
	if (argc < 5) {
		print_info (get_playlist_type_string (prevtype));

	/* Type argument, set the new type */
	} else {
		gint typelen;
		gint idlistsize;
		xmmsc_result_t *saveres;
		xmmsv_coll_t *newcoll;
		gint i;

		typelen = strlen (argv[4]);
		if (g_ascii_strncasecmp (argv[4], "list", typelen) == 0) {
			newtype = XMMS_COLLECTION_TYPE_IDLIST;
		} else if (g_ascii_strncasecmp (argv[4], "queue", typelen) == 0) {
			newtype = XMMS_COLLECTION_TYPE_QUEUE;
		} else if (g_ascii_strncasecmp (argv[4], "pshuffle", typelen) == 0) {
			newtype = XMMS_COLLECTION_TYPE_PARTYSHUFFLE;

			/* Setup operand for party shuffle (set operand) ! */
			if (argc < 6) {
				print_error ("Give the source collection for the party shuffle");
			}

		} else {
			print_error ("Invalid playlist type (valid types: list, queue, pshuffle)");
		}

		/* Copy collection idlist, attributes and operand (if needed) */
		newcoll = xmmsv_coll_new (newtype);

		idlistsize = xmmsv_coll_idlist_get_size (coll);
		for (i = 0; i < idlistsize; i++) {
			guint id;
			xmmsv_coll_idlist_get_index (coll, i, &id);
			xmmsv_coll_idlist_append (newcoll, id);
		}

		xmmsv_coll_attribute_foreach (coll, coll_copy_attributes, newcoll);

		if (newtype == XMMS_COLLECTION_TYPE_PARTYSHUFFLE) {
			playlist_setup_pshuffle (conn, newcoll, argv[5]);
		}

		/* Overwrite with new collection */
		saveres = xmmsc_coll_save (conn, newcoll, name, XMMS_COLLECTION_NS_PLAYLISTS);
		xmmsc_result_wait (saveres);

		if (xmmsc_result_iserror (saveres)) {
			print_error ("Couldn't save %s : %s",
			             name, xmmsc_result_get_error (saveres));
		}

		xmmsv_coll_unref (newcoll);
		xmmsc_result_unref (saveres);
	}

	xmmsc_result_unref (res);
}
Exemplo n.º 11
0
static bool
_internal_get_from_bb_collection_alloc (xmmsv_t *bb, xmmsv_coll_t **coll)
{
	int i;
	int32_t type;
	int32_t n_items;
	int id;
	int32_t *idlist = NULL;
	xmmsv_t *dict, *attrs;
	xmmsv_dict_iter_t *it;

	/* Get the type and create the collection */
	if (!_internal_get_from_bb_int32_positive (bb, &type)) {
		return false;
	}

	*coll = xmmsv_coll_new (type);

	/* Get the attributes */
	if (!_internal_get_from_bb_value_dict_alloc (bb, &dict)) {
		return false;
	}

	attrs = xmmsv_coll_attributes_get (*coll);

	xmmsv_get_dict_iter (dict, &it);
	while (xmmsv_dict_iter_valid (it)) {
		const char *key;
		xmmsv_t *value;
		xmmsv_dict_iter_pair (it, &key, &value);
		xmmsv_dict_set (attrs, key, value);
		xmmsv_dict_iter_next (it);
	}

	xmmsv_unref (dict);

	/* Get the idlist */
	if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
		goto err;
	}

	if (!(idlist = x_new (int32_t, n_items + 1))) {
		goto err;
	}

	for (i = 0; i < n_items; i++) {
		if (!_internal_get_from_bb_int32 (bb, &id)) {
			goto err;
		}

		idlist[i] = id;
	}

	idlist[i] = 0;
	xmmsv_coll_set_idlist (*coll, idlist);
	free (idlist);
	idlist = NULL;

	/* Get the operands */
	if (!_internal_get_from_bb_int32_positive (bb, &n_items)) {
		goto err;
	}

	for (i = 0; i < n_items; i++) {
		xmmsv_coll_t *operand;

		if (!_internal_get_from_bb_int32_positive (bb, &type) ||
		    type != XMMSV_TYPE_COLL ||
		    !_internal_get_from_bb_collection_alloc (bb, &operand)) {
			goto err;
		}

		xmmsv_coll_add_operand (*coll, operand);
		xmmsv_coll_unref (operand);
	}

	return true;

err:
	if (idlist != NULL) {
		free (idlist);
	}

	xmmsv_coll_unref (*coll);

	return false;
}