Пример #1
0
static int
operator_callback (void *userdata, int cols, char **col_strs, char **col_names)
{
    struct db_info *info = userdata;
    xmmsv_t *coll = info->coll;
    xmmsv_t *op;
    int i;
    gint id;
    gint type;

    for (i = 0; i < cols; i++) {
        if (!strcmp (col_names[i], "id")) {
            id = atoi (col_strs[i]);
        } else if (!strcmp (col_names[i], "type")) {
            type = atoi (col_strs[i]);
        }
    }


    op = xmms_collection_dbread_operator (info->db, id, type);
    xmmsv_coll_add_operand (coll, op);
    xmmsv_unref (op);

    return 0;
}
Пример #2
0
static void
updater_remove_directory (updater_t *updater, GFile *file)
{
	xmmsc_result_t *res;
	xmmsv_t *univ, *coll;
	gchar *path, *pattern, *encoded;

	path = g_file_get_path (file);
	encoded = xmmsv_encode_url (path);
	g_free (path);

	pattern = g_strdup_printf ("file://%s/*", encoded);
	g_free (encoded);

	univ = xmmsv_new_coll (XMMS_COLLECTION_TYPE_UNIVERSE);
	coll = xmmsv_new_coll (XMMS_COLLECTION_TYPE_MATCH);

	xmmsv_coll_add_operand (coll, univ);
	xmmsv_coll_attribute_set_string (coll, "field", "url");
	xmmsv_coll_attribute_set_string (coll, "value", pattern);
	xmmsv_coll_attribute_set_string (coll, "case-sensitive", "true");

	g_debug ("remove '%s' from mlib", pattern);

	res = xmmsc_coll_query_ids (updater->conn, coll, NULL, 0, 0);
	xmmsc_result_notifier_set (res, updater_remove_directory_by_id, updater);
	xmmsc_result_unref (res);

	xmmsv_unref (coll);
	xmmsv_unref (univ);

	g_free (pattern);
}
Пример #3
0
/**
 * Returns a collection with a LIMIT operator added
 *
 * @param coll The collection to add the limit operator to
 * @param lim_start The index of the first element to include, or 0 to disable
 * @param lim_len The length of the interval, or 0 to disable
 * @return A new collection with LIMIT operator added
 */
xmmsv_t *
xmmsv_coll_add_limit_operator (xmmsv_t *coll, int lim_start, int lim_len)
{
	xmmsv_t *ret;
	char str[12];

	x_return_val_if_fail (lim_start >= 0 && lim_len >= 0, NULL);

	if (lim_start == 0 && lim_len == 0) {
		return xmmsv_ref (coll);
	}

	ret = xmmsv_new_coll (XMMS_COLLECTION_TYPE_LIMIT);
	xmmsv_coll_add_operand (ret, coll);

	if (lim_start != 0) {
		int count = snprintf (str, sizeof (str), "%i", lim_start);
		if (count > 0 && count < sizeof (str)) {
			xmmsv_coll_attribute_set_string (ret, "start", str);
		} else {
			x_api_warning ("could not set collection limit operator start");
		}
	}

	if (lim_len != 0) {
		int count = snprintf (str, sizeof (str), "%i", lim_len);
		if (count > 0 && count < sizeof (str)) {
			xmmsv_coll_attribute_set_string (ret, "length", str);
		} else {
			x_api_warning ("could not set collection limit operator length");
		}
	}

	return ret;
}
Пример #4
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);
}
Пример #5
0
void
configure_playlist (xmmsc_result_t *res, cli_infos_t *infos, gchar *playlist,
                    gint history, gint upcoming, xmmsv_coll_type_t type,
                    gchar *input)
{
	xmmsc_result_t *saveres;
	xmmsv_coll_t *coll;
	xmmsv_coll_t *newcoll;
	xmmsv_t *val;

	gboolean copied = FALSE;

	val = xmmsc_result_get_value (res);

	if (xmmsv_get_coll (val, &coll)) {
		if (type >= 0 && xmmsv_coll_get_type (coll) != type) {
			newcoll = coll_copy_retype (coll, type);
			coll = newcoll;
			copied = TRUE;
		}
		if (history >= 0) {
			coll_int_attribute_set (coll, "history", history);
		}
		if (upcoming >= 0) {
			coll_int_attribute_set (coll, "upcoming", upcoming);
		}
		if (input) {
			/* Replace previous operand. */
			newcoll = coll_make_reference (input, XMMS_COLLECTION_NS_COLLECTIONS);
			xmmsv_list_clear (xmmsv_coll_operands_get (coll));
			xmmsv_coll_add_operand (coll, newcoll);
			xmmsv_coll_unref (newcoll);
		}

		saveres = xmmsc_coll_save (infos->sync, coll, playlist,
		                           XMMS_COLLECTION_NS_PLAYLISTS);
		xmmsc_result_wait (saveres);
		done (saveres, infos);
	} else {
		g_printf (_("Cannot find the playlist to configure!\n"));
		cli_infos_loop_resume (infos);
	}

	if (copied) {
		xmmsv_coll_unref (coll);
	}

	xmmsc_result_unref (res);
}
Пример #6
0
static VALUE
c_operands_push (VALUE self, VALUE arg)
{
	RbCollection *coll = NULL, *coll2 = NULL;
	VALUE tmp;

	tmp = rb_iv_get (self, "collection");
	Data_Get_Struct (tmp, RbCollection, coll);

	Data_Get_Struct (arg, RbCollection, coll2);

	xmmsv_coll_add_operand (coll->real, coll2->real);

	return self;
}
Пример #7
0
/**
 * Return a collection with an order-operator added.
 *
 * @param coll  the original collection
 * @param value an ordering string, optionally starting with "-" (for
 *              descending ordering), followed by a string "id", "random"
 *              or a key identifying a  property, such as "artist" or "album".
 *              Or it can be a dict containing the attributes to set.
 * @return coll with order-operators added
 */
xmmsv_t *
xmmsv_coll_add_order_operator (xmmsv_t *coll, xmmsv_t *value)
{
	value = xmmsv_coll_normalize_order_arguments (value);
	if (value != NULL) {
		xmmsv_t *ordered;

		ordered = xmmsv_new_coll (XMMS_COLLECTION_TYPE_ORDER);
		xmmsv_coll_add_operand (ordered, coll);
		xmmsv_coll_attributes_set (ordered, value);

		xmmsv_unref (value);

		return ordered;
	}

	return xmmsv_ref (coll);
}
Пример #8
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;
}
Пример #9
0
static void
parse_operands (xmmsv_t *coll, xmmsv_t *operands)
{
	xmmsv_list_iter_t *it;
	xmmsv_t *entry;

	assert (xmmsv_is_type (operands, XMMSV_TYPE_LIST));
	assert (xmmsv_get_list_iter (operands, &it));

	while (xmmsv_list_iter_entry (it, &entry)) {
		xmmsv_t *operand;

		operand = parse_collection (entry);
		assert (operand != NULL);

		xmmsv_coll_add_operand (coll, operand);
		xmmsv_unref (operand);

		xmmsv_list_iter_next (it);
	}
}
Пример #10
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);
}
Пример #11
0
	void PartyShuffle::setOperand( Coll& operand )
	{
		removeOperand();
		xmmsv_coll_add_operand( coll_, operand.getColl() );
	}
Пример #12
0
	void Unary::setOperand( Coll& operand )
	{
		removeOperand();
		xmmsv_coll_add_operand( coll_, operand.getColl() );
	}
Пример #13
0
	void Nary::addOperand( Coll& operand )
	{
		xmmsv_coll_add_operand( coll_, operand.getColl() );
	}
Пример #14
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;
}
Пример #15
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;
}
Пример #16
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;
}