From e1d635e6dde837ccdc61736eedb86a53f3dd2916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Fri, 5 Dec 2025 23:36:30 +0100 Subject: [PATCH] clapper: Function to insert into queue after other item position --- src/lib/clapper/clapper-queue.c | 45 +++++++++++++++++++++++++++++++++ src/lib/clapper/clapper-queue.h | 3 +++ 2 files changed, 48 insertions(+) diff --git a/src/lib/clapper/clapper-queue.c b/src/lib/clapper/clapper-queue.c index faf3b7b4..3d79461c 100644 --- a/src/lib/clapper/clapper-queue.c +++ b/src/lib/clapper/clapper-queue.c @@ -548,6 +548,51 @@ clapper_queue_insert_item (ClapperQueue *self, ClapperMediaItem *item, gint inde CLAPPER_QUEUE_REC_UNLOCK (self); } +/** + * clapper_queue_insert_item_after: + * @queue: a #ClapperQueue + * @item: a #ClapperMediaItem + * @after_item: (nullable): a #ClapperMediaItem after which to + * insert @item or %NULL to prepend + * + * Insert another #ClapperMediaItem after some other item position. + * + * If @after_item is %NULL, item will be prepended. When set but + * not found however, item will be appended at the end of queue. + * + * If item is already in queue, this function will do nothing, + * so it is safe to call multiple times if unsure. + * + * Since: 0.10 + */ +void +clapper_queue_insert_item_after (ClapperQueue *self, ClapperMediaItem *item, + ClapperMediaItem *after_item) +{ + g_return_if_fail (CLAPPER_IS_QUEUE (self)); + g_return_if_fail (CLAPPER_IS_MEDIA_ITEM (item)); + g_return_if_fail (after_item == NULL || CLAPPER_IS_MEDIA_ITEM (after_item)); + + CLAPPER_QUEUE_REC_LOCK (self); + + if (!g_ptr_array_find (self->items, item, NULL)) { + guint index; + + if (after_item) { + if (g_ptr_array_find (self->items, after_item, &index)) + index++; + else + index = self->items->len; // Append if not found + } else { + index = 0; + } + + _take_item_unlocked (self, gst_object_ref (item), index); + } + + CLAPPER_QUEUE_REC_UNLOCK (self); +} + /** * clapper_queue_reposition_item: * @queue: a #ClapperQueue diff --git a/src/lib/clapper/clapper-queue.h b/src/lib/clapper/clapper-queue.h index f1965426..75258799 100644 --- a/src/lib/clapper/clapper-queue.h +++ b/src/lib/clapper/clapper-queue.h @@ -51,6 +51,9 @@ void clapper_queue_add_item (ClapperQueue *queue, ClapperMediaItem *item); CLAPPER_API void clapper_queue_insert_item (ClapperQueue *queue, ClapperMediaItem *item, gint index); +CLAPPER_API +void clapper_queue_insert_item_after (ClapperQueue *queue, ClapperMediaItem *item, ClapperMediaItem *after_item); + CLAPPER_API void clapper_queue_reposition_item (ClapperQueue *queue, ClapperMediaItem *item, gint index);