/** * Empties the idlist. * @param coll The collection to update. * @return TRUE on success, false otherwise. */ int xmmsv_coll_idlist_clear (xmmsv_t *coll) { x_return_val_if_fail (coll, 0); return xmmsv_list_clear (coll->value.coll->idlist); }
/** * Set the list of ids in the given collection. * The list must be 0-terminated. * Note that the idlist is only relevant for idlist collections. * * @param coll the collection to modify. * @param ids the 0-terminated list of ids to store in the collection. */ void xmmsv_coll_set_idlist (xmmsv_t *coll, int ids[]) { unsigned int i; xmmsv_list_clear (coll->value.coll->idlist); for (i = 0; ids[i]; i++) { xmmsv_list_append_int (coll->value.coll->idlist, ids[i]); } }
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); }
/** 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_sort (xmms_playlist_t *playlist, const gchar *plname, xmmsv_t *properties, xmms_error_t *err) { xmmsv_t *tmp, *idlist, *val, *spec, *metadata, *get; xmmsv_coll_t *plcoll, *ordered; gint currpos, pos; xmms_medialib_entry_t currid; g_return_if_fail (playlist); g_return_if_fail (properties); if (xmmsv_list_get_size (properties) < 1) { xmms_error_set (err, XMMS_ERROR_NOENT, "need at least one property to sort"); return; } 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; } currpos = xmms_playlist_coll_get_currpos (plcoll); xmmsv_coll_idlist_get_index (plcoll, currpos, &currid); get = xmmsv_new_list (); xmmsv_list_append_string (get, "id"); metadata = xmmsv_new_dict (); xmmsv_dict_set_string (metadata, "type", "metadata"); xmmsv_dict_set_string (metadata, "aggregate", "first"); xmmsv_dict_set (metadata, "get", get); xmmsv_unref (get); spec = xmmsv_new_dict (); xmmsv_dict_set_string (spec, "type", "cluster-list"); xmmsv_dict_set_string (spec, "cluster-by", "position"); xmmsv_dict_set (spec, "data", metadata); xmmsv_unref (metadata); ordered = xmmsv_coll_add_order_operators (plcoll, properties); MEDIALIB_BEGIN (playlist->medialib); tmp = xmms_medialib_query (session, ordered, spec, err); MEDIALIB_COMMIT (); xmmsv_coll_unref (ordered); xmmsv_unref (spec); if (tmp == NULL) { g_mutex_unlock (playlist->mutex); return; } idlist = xmmsv_coll_idlist_get (plcoll); xmmsv_list_clear (idlist); for (pos = 0; xmmsv_list_get (tmp, pos, &val); pos++) { xmms_medialib_entry_t id; xmmsv_get_int (val, &id); xmmsv_list_append (idlist, val); if (id == currid) { xmms_collection_set_int_attr (plcoll, "position", pos); currpos = pos; } } xmmsv_unref (tmp); XMMS_PLAYLIST_CHANGED_MSG (XMMS_PLAYLIST_CHANGED_SORT, 0, plname); XMMS_PLAYLIST_CURRPOS_MSG (currpos, plname); g_mutex_unlock (playlist->mutex); }