core/tempq: Move tempq_move() out of the deck namespace
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
c22b93b2cf
commit
ecda136015
|
@ -120,6 +120,27 @@ struct queue *tempq_get(unsigned int index)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tempq_move(struct queue *queue, unsigned int index)
|
||||||
|
{
|
||||||
|
unsigned int old_pos = __tempq_index(queue);
|
||||||
|
std::list<TempQueue>::iterator it_old = queue_deck.begin();
|
||||||
|
std::list<TempQueue>::iterator it_new = queue_deck.begin();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < queue_deck.size(); i++) {
|
||||||
|
if (i < old_pos)
|
||||||
|
it_old++;
|
||||||
|
|
||||||
|
if (i < index)
|
||||||
|
it_new++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > old_pos)
|
||||||
|
it_new++;
|
||||||
|
|
||||||
|
queue_deck.splice(it_new, queue_deck, it_old);
|
||||||
|
deck :: write();
|
||||||
|
}
|
||||||
|
|
||||||
void deck :: write()
|
void deck :: write()
|
||||||
{
|
{
|
||||||
std::list<TempQueue>::iterator it;
|
std::list<TempQueue>::iterator it;
|
||||||
|
@ -141,27 +162,6 @@ void deck :: save(struct queue *queue, enum queue_flags flag)
|
||||||
deck :: write();
|
deck :: write();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deck :: move(queue *queue, unsigned int index)
|
|
||||||
{
|
|
||||||
unsigned int old_pos = __tempq_index(queue);
|
|
||||||
std::list<TempQueue>::iterator it_old = queue_deck.begin();
|
|
||||||
std::list<TempQueue>::iterator it_new = queue_deck.begin();
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < queue_deck.size(); i++) {
|
|
||||||
if (i < old_pos)
|
|
||||||
it_old++;
|
|
||||||
|
|
||||||
if (i < index)
|
|
||||||
it_new++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index > old_pos)
|
|
||||||
it_new++;
|
|
||||||
|
|
||||||
queue_deck.splice(it_new, queue_deck, it_old);
|
|
||||||
write();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct track *deck :: next()
|
struct track *deck :: next()
|
||||||
{
|
{
|
||||||
struct track *track = NULL;
|
struct track *track = NULL;
|
||||||
|
|
|
@ -159,7 +159,7 @@ void QueueTab :: on_tab_reordered()
|
||||||
|
|
||||||
void QueueTab :: on_move_queue(int num)
|
void QueueTab :: on_move_queue(int num)
|
||||||
{
|
{
|
||||||
deck :: move(tab_pq, num);
|
tempq_move(tab_pq, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,6 @@ namespace deck
|
||||||
void write();
|
void write();
|
||||||
void save(struct queue *, enum queue_flags);
|
void save(struct queue *, enum queue_flags);
|
||||||
|
|
||||||
/**
|
|
||||||
* Move the queue to a new location in the deck.
|
|
||||||
*
|
|
||||||
* @param queue The queue to be moved.
|
|
||||||
* @param index The new index of the queue.
|
|
||||||
*/
|
|
||||||
void move(queue *, unsigned int);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A track from the first enabled queue. If no queues are
|
* @return A track from the first enabled queue. If no queues are
|
||||||
* enabled, return a track from the Library.
|
* enabled, return a track from the Library.
|
||||||
|
@ -81,4 +73,7 @@ void tempq_free(struct queue *);
|
||||||
/* Called to find a temporary queue by index. */
|
/* Called to find a temporary queue by index. */
|
||||||
struct queue *tempq_get(unsigned int);
|
struct queue *tempq_get(unsigned int);
|
||||||
|
|
||||||
|
/* Called to move a temporary queue to a new index in the list. */
|
||||||
|
void tempq_move(struct queue *, unsigned int);
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_DECK_H */
|
#endif /* OCARINA_CORE_DECK_H */
|
||||||
|
|
|
@ -25,6 +25,7 @@ static void test_init()
|
||||||
test_equal(deck :: next(), NULL);
|
test_equal(deck :: next(), NULL);
|
||||||
tempq_init(NULL);
|
tempq_init(NULL);
|
||||||
test_equal(deck :: next(), NULL);
|
test_equal(deck :: next(), NULL);
|
||||||
|
tempq_move(NULL, 1);
|
||||||
test_equal(tempq_get(0), NULL);
|
test_equal(tempq_get(0), NULL);
|
||||||
test_equal(deck :: get_queues().size(), (size_t)0);
|
test_equal(deck :: get_queues().size(), (size_t)0);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +50,16 @@ static void test_tempq()
|
||||||
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), true);
|
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), true);
|
||||||
test_equal(tempq_get(1), q1);
|
test_equal(tempq_get(1), q1);
|
||||||
|
|
||||||
|
tempq_move(q1, 0);
|
||||||
|
test_equal(tempq_get(0), q1);
|
||||||
|
test_equal(tempq_get(1), q0);
|
||||||
|
test_equal(tempq_get(2), NULL);
|
||||||
|
|
||||||
|
tempq_move(q0, 1);
|
||||||
|
test_equal(tempq_get(0), q1);
|
||||||
|
test_equal(tempq_get(1), q0);
|
||||||
|
test_equal(tempq_get(2), NULL);
|
||||||
|
|
||||||
tempq_free(q0);
|
tempq_free(q0);
|
||||||
test_equal(tempq_get(0), q1);
|
test_equal(tempq_get(0), q1);
|
||||||
|
|
||||||
|
@ -62,10 +73,8 @@ static void test_tempq()
|
||||||
filter_deinit();
|
filter_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_create_mv_destroy()
|
static void test_next_prev()
|
||||||
{
|
{
|
||||||
queue *q1, *q2;
|
|
||||||
|
|
||||||
test_cp_data_dir();
|
test_cp_data_dir();
|
||||||
filter_init();
|
filter_init();
|
||||||
tags_init();
|
tags_init();
|
||||||
|
@ -74,30 +83,6 @@ static void test_create_mv_destroy()
|
||||||
history_init(NULL);
|
history_init(NULL);
|
||||||
tempq_init(NULL);
|
tempq_init(NULL);
|
||||||
|
|
||||||
q1 = tempq_alloc(NULL, Q_RANDOM);
|
|
||||||
test_not_equal(q1, Q_NULL);
|
|
||||||
test_equal(queue_has_flag(q1, Q_ENABLED), true);
|
|
||||||
test_equal(queue_has_flag(q1, Q_RANDOM), true);
|
|
||||||
test_equal(tempq_get(2), q1);
|
|
||||||
|
|
||||||
q2 = tempq_alloc(NULL, 0);
|
|
||||||
test_not_equal(q2, Q_NULL);
|
|
||||||
test_equal(queue_has_flag(q2, Q_ENABLED), true);
|
|
||||||
test_equal(queue_has_flag(q2, Q_RANDOM), false);
|
|
||||||
test_equal(tempq_get(3), q2);
|
|
||||||
|
|
||||||
deck :: move(q1, 3);
|
|
||||||
deck :: move(q1, 3);
|
|
||||||
deck :: move(q1, 2);
|
|
||||||
|
|
||||||
tempq_free(q1);
|
|
||||||
tempq_free(q2);
|
|
||||||
|
|
||||||
test_equal(tempq_get(3), Q_NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_next_prev()
|
|
||||||
{
|
|
||||||
std::list<TempQueue>::iterator it = deck :: get_queues().begin();
|
std::list<TempQueue>::iterator it = deck :: get_queues().begin();
|
||||||
queue *q = history_get_queue();
|
queue *q = history_get_queue();
|
||||||
queue *q0 = tempq_get(0);
|
queue *q0 = tempq_get(0);
|
||||||
|
@ -135,6 +120,5 @@ static void test_next_prev()
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
UNIT_TEST("Temporary Queue Initialization", test_init),
|
UNIT_TEST("Temporary Queue Initialization", test_init),
|
||||||
UNIT_TEST("Temporary Queue", test_tempq),
|
UNIT_TEST("Temporary Queue", test_tempq),
|
||||||
UNIT_TEST("Deck Create, Move, and Destroy", test_create_mv_destroy),
|
|
||||||
UNIT_TEST("Deck Next and Prev", test_next_prev),
|
UNIT_TEST("Deck Next and Prev", test_next_prev),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue