core/queue: Use a GQueue directly
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2b426cff48
commit
db01ed3208
26
core/queue.c
26
core/queue.c
|
@ -54,25 +54,25 @@ static inline unsigned int __queue_added(struct queue *queue,
|
|||
static inline unsigned int __queue_add_head(struct queue *queue,
|
||||
struct track *track)
|
||||
{
|
||||
g_queue_push_head(&queue->q_tracks._queue, track);
|
||||
g_queue_push_head(&queue->q_tracks, track);
|
||||
return __queue_added(queue, track, 0);
|
||||
}
|
||||
|
||||
static inline unsigned int __queue_add_tail(struct queue *queue,
|
||||
struct track *track)
|
||||
{
|
||||
g_queue_push_tail(&queue->q_tracks._queue, track);
|
||||
g_queue_push_tail(&queue->q_tracks, track);
|
||||
return __queue_added(queue, track, queue_size(queue) - 1);
|
||||
}
|
||||
|
||||
static inline unsigned int __queue_add_sorted(struct queue *queue,
|
||||
struct track *track)
|
||||
{
|
||||
struct _q_iter it;
|
||||
struct queue_iter it;
|
||||
|
||||
_q_for_each(&queue->q_tracks, &it) {
|
||||
if (track_less_than(_q_iter_val(&it), track, queue->q_sort) > 0) {
|
||||
g_queue_insert_before(&queue->q_tracks._queue, it.it_iter, track);
|
||||
queue_for_each(queue, &it) {
|
||||
if (track_less_than(queue_iter_val(&it), track, queue->q_sort) > 0) {
|
||||
g_queue_insert_before(&queue->q_tracks, it.it_iter, track);
|
||||
return __queue_added(queue, track, it.it_pos);
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ static inline void __queue_remove(struct queue *queue, struct queue_iter *it)
|
|||
GList *link = it->it_iter;
|
||||
|
||||
queue_iter_prev(it);
|
||||
g_queue_delete_link(&queue->q_tracks._queue, link);
|
||||
g_queue_delete_link(&queue->q_tracks, link);
|
||||
|
||||
queue->q_length -= track->tr_length;
|
||||
if (queue->q_ops)
|
||||
|
@ -140,7 +140,7 @@ void queue_init(struct queue *queue, unsigned int flags,
|
|||
queue->q_sort = NULL;
|
||||
queue->q_ops = ops;
|
||||
|
||||
g_queue_init(&queue->q_tracks._queue);
|
||||
g_queue_init(&queue->q_tracks);
|
||||
queue_iter_init(queue, &queue->q_cur);
|
||||
|
||||
queue->q_private = __queue_init(queue);
|
||||
|
@ -209,16 +209,16 @@ void queue_clear(struct queue *queue)
|
|||
{
|
||||
unsigned int n = queue_size(queue);
|
||||
|
||||
g_queue_clear(&queue->q_tracks._queue);
|
||||
g_queue_clear(&queue->q_tracks);
|
||||
__queue_clear(queue, n);
|
||||
}
|
||||
|
||||
void queue_updated(struct queue *queue, struct track *track)
|
||||
{
|
||||
struct _q_iter it;
|
||||
struct queue_iter it;
|
||||
|
||||
_q_for_each(&queue->q_tracks, &it) {
|
||||
if (_q_iter_val(&it) == track)
|
||||
queue_for_each(queue, &it) {
|
||||
if (queue_iter_val(&it) == track)
|
||||
__queue_updated(queue, it.it_pos);
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ struct track *queue_next(struct queue *queue)
|
|||
|
||||
void queue_resort(struct queue *queue)
|
||||
{
|
||||
g_queue_sort(&queue->q_tracks._queue, track_less_than, queue->q_sort);
|
||||
g_queue_sort(&queue->q_tracks, track_less_than, queue->q_sort);
|
||||
|
||||
for (unsigned int i = 0; i < queue_size(queue); i++)
|
||||
__queue_updated(queue, i);
|
||||
|
|
|
@ -46,12 +46,12 @@ static void __tempq_read_queue()
|
|||
|
||||
static void __tempq_write_queue(struct queue *queue)
|
||||
{
|
||||
struct _q_iter it;
|
||||
struct queue_iter it;
|
||||
struct track *track;
|
||||
|
||||
file_writef(&tempq_file, "%u %u", queue->q_flags, queue_size(queue));
|
||||
_q_for_each(&queue->q_tracks, &it) {
|
||||
track = (struct track *)_q_iter_val(&it);
|
||||
queue_for_each(queue, &it) {
|
||||
track = queue_iter_val(&it);
|
||||
file_writef(&tempq_file, " %u", track->tr_dbe.dbe_index);
|
||||
}
|
||||
file_writef(&tempq_file, "\n");
|
||||
|
|
10
gui/model.c
10
gui/model.c
|
@ -33,10 +33,10 @@ static gboolean __queue_model_iter_nth(GuiQueueModel *model,
|
|||
if (n >= queue_size(model->gqm_queue))
|
||||
return FALSE;
|
||||
|
||||
_q_iter_set(&model->gqm_queue->q_tracks, &model->gqm_iter, n);
|
||||
queue_iter_set(model->gqm_queue, &model->gqm_iter, n);
|
||||
iter->stamp = model->gqm_stamp;
|
||||
iter->user_data = &model->gqm_iter;
|
||||
iter->user_data2 = _q_iter_val(&model->gqm_iter);
|
||||
iter->user_data2 = queue_iter_val(&model->gqm_iter);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ static gboolean _queue_model_get_iter(GtkTreeModel *model, GtkTreeIter *iter,
|
|||
|
||||
static GtkTreePath *_queue_model_get_path(GtkTreeModel *model, GtkTreeIter *iter)
|
||||
{
|
||||
struct _q_iter *q_it;
|
||||
struct queue_iter *q_it;
|
||||
GtkTreePath *path;
|
||||
|
||||
g_return_val_if_fail(iter != NULL, FALSE);
|
||||
|
@ -145,13 +145,13 @@ static gboolean _queue_model_iter_next(GtkTreeModel *model, GtkTreeIter *iter)
|
|||
g_return_val_if_fail(iter->user_data, FALSE);
|
||||
g_return_val_if_fail(iter->user_data2, FALSE);
|
||||
|
||||
_q_iter_next(&gqm->gqm_iter);
|
||||
queue_iter_next(&gqm->gqm_iter);
|
||||
if (gqm->gqm_iter.it_iter == NULL)
|
||||
return FALSE;
|
||||
|
||||
iter->stamp = gqm->gqm_stamp;
|
||||
iter->user_data = &gqm->gqm_iter;
|
||||
iter->user_data2 = _q_iter_val(&gqm->gqm_iter);
|
||||
iter->user_data2 = queue_iter_val(&gqm->gqm_iter);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,9 +62,9 @@ struct queue_iter {
|
|||
struct queue {
|
||||
unsigned int q_flags; /* The queue's set of flags. */
|
||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
||||
struct _queue q_tracks; /* The queue's list of tracks. */
|
||||
GQueue q_tracks; /* The queue's list of tracks. */
|
||||
GSList *q_sort; /* The queue's sort order. */
|
||||
void *q_private; /* The queue's private data. */
|
||||
void *q_private; /* The queue's private data. */
|
||||
|
||||
struct queue_iter q_cur; /* The queue's last-played position. */
|
||||
const struct queue_ops *q_ops; /* The queue's operations vector. */
|
||||
|
@ -75,8 +75,8 @@ struct queue {
|
|||
/* Called to initialize a queue iterator. */
|
||||
static inline void queue_iter_init(struct queue *queue, struct queue_iter *it)
|
||||
{
|
||||
it->it_iter = g_queue_peek_head_link(&queue->q_tracks._queue);
|
||||
it->it_pos = g_queue_link_index(&queue->q_tracks._queue, it->it_iter);
|
||||
it->it_iter = g_queue_peek_head_link(&queue->q_tracks);
|
||||
it->it_pos = g_queue_link_index(&queue->q_tracks, it->it_iter);
|
||||
}
|
||||
|
||||
/* Called to advance a queue iterator by one step. */
|
||||
|
@ -97,7 +97,7 @@ static inline void queue_iter_prev(struct queue_iter *it)
|
|||
static inline void queue_iter_set(struct queue *queue, struct queue_iter *it,
|
||||
unsigned int pos)
|
||||
{
|
||||
it->it_iter = g_queue_peek_nth_link(&queue->q_tracks._queue, pos);
|
||||
it->it_iter = g_queue_peek_nth_link(&queue->q_tracks, pos);
|
||||
it->it_pos = pos;
|
||||
}
|
||||
|
||||
|
@ -134,13 +134,13 @@ static inline bool queue_has_flag(struct queue *queue, enum queue_flags flag)
|
|||
/* Called to find the size of the queue. */
|
||||
static inline unsigned int queue_size(struct queue *queue)
|
||||
{
|
||||
return g_queue_get_length(&queue->q_tracks._queue);
|
||||
return g_queue_get_length(&queue->q_tracks);
|
||||
}
|
||||
|
||||
/* Called to access the queued track at a given index. */
|
||||
static inline struct track *queue_at(struct queue *queue, unsigned int index)
|
||||
{
|
||||
return (struct track *)g_queue_peek_nth(&queue->q_tracks._queue, index);
|
||||
return (struct track *)g_queue_peek_nth(&queue->q_tracks, index);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
#ifndef OCARINA_GUI_MODEL_H
|
||||
#define OCARINA_GUI_MODEL_H
|
||||
#include <core/containers/queue.h>
|
||||
#include <core/queue.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define GUI_QUEUE_MODEL_TYPE (gui_queue_model_get_type())
|
||||
|
@ -33,8 +33,8 @@ struct _gui_queue_model {
|
|||
GObject gqm_parent; /* This MUST be the first member. */
|
||||
gint gqm_stamp; /* This is used to check iter validity. */
|
||||
|
||||
struct queue *gqm_queue; /* The model's associated queue. */
|
||||
struct _q_iter gqm_iter; /* The current _q_iter. */
|
||||
struct queue *gqm_queue; /* The model's associated queue. */
|
||||
struct queue_iter gqm_iter; /* The current _q_iter. */
|
||||
};
|
||||
|
||||
struct _gui_queue_model_class {
|
||||
|
|
Loading…
Reference in New Issue