core/tempq: Add tempq_index() function
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2770403c61
commit
5bc9f65cd9
|
@ -109,6 +109,11 @@ struct queue *tempq_get(unsigned int index)
|
|||
return (struct queue *)g_slist_nth_data(tempq_list, index);
|
||||
}
|
||||
|
||||
unsigned int tempq_index(struct queue *queue)
|
||||
{
|
||||
return g_slist_index(tempq_list, queue);
|
||||
}
|
||||
|
||||
void tempq_move(struct queue *queue, unsigned int index)
|
||||
{
|
||||
GSList *cur = g_slist_find(tempq_list, queue);
|
||||
|
|
|
@ -84,7 +84,7 @@ bool __sidebar_keypress(GtkTreeView *treeview, GdkEventKey *event, gpointer data
|
|||
queue = __sidebar_get_queue(&iter);
|
||||
page = gtk_tree_path_get_indices(path)[0];
|
||||
|
||||
if (!queue || page >= tempq_count())
|
||||
if (tempq_index(queue) == -1)
|
||||
goto out;
|
||||
|
||||
tempq_free(queue);
|
||||
|
@ -167,7 +167,7 @@ void gui_sidebar_add(struct queue *queue)
|
|||
GtkTreeIter iter, sibling;
|
||||
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(sb_store),
|
||||
&sibling, NULL, tempq_count() - 1);
|
||||
&sibling, NULL, tempq_index(queue));
|
||||
|
||||
gtk_list_store_insert_before(sb_store, &iter, &sibling);
|
||||
gtk_list_store_set(sb_store, &iter, SB_IMAGE, "audio-x-generic",
|
||||
|
|
|
@ -33,6 +33,9 @@ void tempq_free(struct queue *);
|
|||
/* Called to find a temporary queue by index. */
|
||||
struct queue *tempq_get(unsigned int);
|
||||
|
||||
/* Called to find the index of a temporary queue. */
|
||||
unsigned int tempq_index(struct queue *);
|
||||
|
||||
/* Called to move a temporary queue to a new index in the list. */
|
||||
void tempq_move(struct queue *, unsigned int);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ static void test_init()
|
|||
tempq_move(NULL, 1);
|
||||
test_equal((void *)tempq_get(0), NULL);
|
||||
test_equal(tempq_count(), 0);
|
||||
test_equal(tempq_index(NULL), (unsigned int)-1);
|
||||
}
|
||||
|
||||
static void test_alloc()
|
||||
|
@ -39,6 +40,7 @@ static void test_alloc()
|
|||
test_equal(queue_has_flag(q0, Q_SAVE_FLAGS), (bool)true);
|
||||
test_equal((void *)tempq_get(0), (void *)q0);
|
||||
test_equal(tempq_count(), 1);
|
||||
test_equal(tempq_index(q0), 0);
|
||||
|
||||
q1 = tempq_alloc(NULL, Q_RANDOM);
|
||||
test_not_equal((void *)q1, NULL);
|
||||
|
@ -48,6 +50,7 @@ static void test_alloc()
|
|||
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), (bool)true);
|
||||
test_equal((void *)tempq_get(1), (void *)q1);
|
||||
test_equal(tempq_count(), 2);
|
||||
test_equal(tempq_index(q1), 1);
|
||||
|
||||
tempq_deinit();
|
||||
test_equal(tempq_count(), 0);
|
||||
|
|
Loading…
Reference in New Issue