/** List a playlist */ static xmmsv_t * xmms_playlist_client_list_entries (xmms_playlist_t *playlist, const gchar *plname, xmms_error_t *err) { xmmsv_t *entries = NULL; xmmsv_coll_t *plcoll; xmms_medialib_entry_t entry; xmmsv_list_iter_t *it; g_return_val_if_fail (playlist, NULL); g_mutex_lock (playlist->mutex); plcoll = xmms_playlist_get_coll (playlist, plname, err); if (plcoll == NULL) { g_mutex_unlock (playlist->mutex); return NULL; } entries = xmmsv_new_list (); xmmsv_get_list_iter (xmmsv_coll_idlist_get (plcoll), &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_list_iter_entry_int (it, &entry); xmmsv_list_append_int (entries, entry); } xmmsv_list_iter_explicit_destroy (it); g_mutex_unlock (playlist->mutex); return entries; }
/** * Append a value to the idlist. * @param coll The collection to update. * @param id The id to append to the idlist. * @return TRUE on success, false otherwise. */ int xmmsv_coll_idlist_append (xmmsv_t *coll, int64_t id) { x_return_val_if_fail (coll, 0); return xmmsv_list_append_int (coll->value.coll->idlist, id); }
/** * 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]); } }
static gint update_active_playlist (xmmsv_t *val, void *udata) { cli_cache_t *cache = (cli_cache_t *) udata; xmmsc_result_t *refres; gint pos, newpos, type; gint id; const gchar *name; xmmsv_dict_entry_get_int (val, "type", &type); xmmsv_dict_entry_get_int (val, "position", &pos); xmmsv_dict_entry_get_int (val, "id", &id); xmmsv_dict_entry_get_string (val, "name", &name); /* Active playlist not changed, nevermind */ if (strcmp (name, cache->active_playlist_name) != 0) { return TRUE; } /* Apply changes to the cached playlist */ switch (type) { case XMMS_PLAYLIST_CHANGED_ADD: xmmsv_list_append_int (cache->active_playlist, id); break; case XMMS_PLAYLIST_CHANGED_INSERT: xmmsv_list_insert_int (cache->active_playlist, pos, id); break; case XMMS_PLAYLIST_CHANGED_MOVE: xmmsv_dict_entry_get_int (val, "newposition", &newpos); xmmsv_list_remove (cache->active_playlist, pos); xmmsv_list_insert_int (cache->active_playlist, newpos, id); break; case XMMS_PLAYLIST_CHANGED_REMOVE: xmmsv_list_remove (cache->active_playlist, pos); break; case XMMS_PLAYLIST_CHANGED_SHUFFLE: case XMMS_PLAYLIST_CHANGED_SORT: case XMMS_PLAYLIST_CHANGED_CLEAR: /* Oops, reload the whole playlist */ refres = xmmsc_playlist_list_entries (cache->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_notifier_set (refres, &refresh_active_playlist, cache); xmmsc_result_unref (refres); freshness_requested (&cache->freshness_active_playlist); break; } return TRUE; }
/** * Sanitize the 'get' property of a 'metadata' fetch specification. */ static xmmsv_t * normalize_metadata_get (xmmsv_t *fetch, xmms_error_t *err) { xmmsv_list_iter_t *it; xmmsv_t *get, *list; guint32 values; if (!xmmsv_dict_get (fetch, "get", &get) || xmmsv_get_type (get) != XMMSV_TYPE_LIST || xmmsv_list_get_size (get) < 1) { const gchar *message = "'get' must be a non-empty list of strings."; xmms_error_set (err, XMMS_ERROR_INVAL, message); return NULL; } list = xmmsv_new_list (); values = 0; /* Scan for duplicates or invalid values */ xmmsv_get_list_iter (get, &it); while (xmmsv_list_iter_valid (it)) { const gchar *value = NULL; guint32 get_as_int, mask; xmmsv_list_iter_entry_string (it, &value); if (!metadata_value_from_string (value, &get_as_int)) { const gchar *message = "'get' entries must be 'id', 'field', 'value' or 'source'."; xmms_error_set (err, XMMS_ERROR_INVAL, message); xmmsv_unref (list); return NULL; } mask = 1 << (get_as_int + 1); if (values & mask) { const gchar *message = "'get' entries must be unique."; xmms_error_set (err, XMMS_ERROR_INVAL, message); xmmsv_unref (list); return NULL; } values |= mask; xmmsv_list_append_int (list, get_as_int); xmmsv_list_iter_next (it); } return list; }
static xmmsv_t * aggregate_list (xmmsv_t *current, gint int_value, const gchar *str_value) { if (current == NULL) { current = xmmsv_new_list (); } if (str_value != NULL) { xmmsv_list_append_string (current, str_value); } else { xmmsv_list_append_int (current, int_value); } return current; }