core/queue: Move queue_has_flag() out of the queue struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
3e5bef5f3c
commit
b3a8fa293b
|
@ -204,7 +204,7 @@ struct track *deck :: next()
|
|||
std::list<TempQueue>::iterator it;
|
||||
|
||||
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
||||
if (it->has_flag(Q_ENABLED) == false)
|
||||
if (queue_has_flag(&(*it), Q_ENABLED) == false)
|
||||
continue;
|
||||
|
||||
track = queue_next(&(*it));
|
||||
|
|
|
@ -60,11 +60,6 @@ void queue :: unset_flag(queue_flags flag)
|
|||
q_flags &= ~flag;
|
||||
}
|
||||
|
||||
bool queue :: has_flag(queue_flags flag)
|
||||
{
|
||||
return (q_flags & flag) == (unsigned int)flag;
|
||||
}
|
||||
|
||||
static bool track_less_than(struct track *lhs, struct track *rhs,
|
||||
std::vector<struct sort_info> &order)
|
||||
{
|
||||
|
@ -154,7 +149,7 @@ void queue_updated(struct queue *queue, struct track *track)
|
|||
void queue_selected(struct queue *queue, unsigned int index)
|
||||
{
|
||||
queue->q_cur = index;
|
||||
if (queue->has_flag(Q_REPEAT) == false)
|
||||
if (queue_has_flag(queue, Q_REPEAT) == false)
|
||||
queue->del(index);
|
||||
}
|
||||
|
||||
|
@ -163,13 +158,13 @@ struct track *queue_next(struct queue *queue)
|
|||
unsigned int size = queue_size(queue);
|
||||
struct track *res;
|
||||
|
||||
if (!(queue->q_flags & Q_ENABLED))
|
||||
if (!queue_has_flag(queue, Q_ENABLED))
|
||||
return NULL;
|
||||
else if (size == 0)
|
||||
return NULL;
|
||||
else if (size == 1)
|
||||
queue->q_cur = 0;
|
||||
else if (queue->has_flag(Q_RANDOM))
|
||||
else if (queue_has_flag(queue, Q_RANDOM))
|
||||
queue->q_cur += random_range(1, size / 2);
|
||||
else
|
||||
queue->q_cur++;
|
||||
|
@ -195,7 +190,7 @@ void queue :: sort(compare_t field, bool reset)
|
|||
bool found = false;
|
||||
struct sort_info info = { field, true };
|
||||
|
||||
if (q_flags & Q_NO_SORT)
|
||||
if (queue_has_flag(this, Q_NO_SORT))
|
||||
return;
|
||||
if (reset)
|
||||
q_sort.clear();
|
||||
|
|
|
@ -32,21 +32,21 @@ void QueueToolbar :: init(queue *queue, QueueLabel *label,
|
|||
if (flags & T_SWITCH) {
|
||||
_q_switch->property_active().signal_changed().connect(
|
||||
sigc::mem_fun(*this, &QueueToolbar::on_switch_toggled));
|
||||
_q_switch->set_active(_queue->has_flag(Q_ENABLED));
|
||||
_q_switch->set_active(queue_has_flag(_queue, Q_ENABLED));
|
||||
_q_switch->show();
|
||||
}
|
||||
|
||||
if (flags & T_RANDOM) {
|
||||
_q_random->signal_toggled().connect(sigc::mem_fun(*this,
|
||||
&QueueToolbar::on_random_toggled));
|
||||
_q_random->set_active(_queue->has_flag(Q_RANDOM));
|
||||
_q_random->set_active(queue_has_flag(_queue, Q_RANDOM));
|
||||
_q_random->show();
|
||||
}
|
||||
|
||||
if (flags & T_REPEAT) {
|
||||
_q_repeat->signal_toggled().connect(sigc::mem_fun(*this,
|
||||
&QueueToolbar::on_repeat_toggled));
|
||||
_q_repeat->set_active(_queue->has_flag(Q_REPEAT));
|
||||
_q_repeat->set_active(queue_has_flag(_queue, Q_REPEAT));
|
||||
_q_repeat->show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -422,7 +422,7 @@ void post_init_tabs()
|
|||
|
||||
unsigned int tab = 0;
|
||||
for (tab = 0; tab < deck::get_queues().size(); tab++) {
|
||||
if ((deck :: get(tab)->has_flag(Q_ENABLED)))
|
||||
if (queue_has_flag(deck :: get(tab), Q_ENABLED))
|
||||
break;
|
||||
}
|
||||
gui :: get_widget<Gtk::Notebook>("o_notebook")->set_current_page(tab);
|
||||
|
|
|
@ -124,14 +124,6 @@ struct queue {
|
|||
*/
|
||||
virtual void unset_flag(queue_flags);
|
||||
|
||||
/**
|
||||
* Check if a queue has a specific flag set.
|
||||
*
|
||||
* @param flag queue_flag to check.
|
||||
* @return true if queue_flag is set and false otherwise.
|
||||
*/
|
||||
bool has_flag(queue_flags);
|
||||
|
||||
|
||||
/**
|
||||
* Add a track to the queue, possibly matching the
|
||||
|
@ -171,6 +163,12 @@ struct queue {
|
|||
};
|
||||
|
||||
|
||||
/* Called to check if the queue has a specific flag set. */
|
||||
static inline bool queue_has_flag(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
return (queue->q_flags & flag) == (unsigned int)flag;
|
||||
}
|
||||
|
||||
/* Called to find the size of the queue. */
|
||||
static inline unsigned int queue_size(struct queue *queue)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ static void test_init()
|
|||
collection :: init();
|
||||
deck :: init();
|
||||
|
||||
test_equal(collection :: get_queue()->has_flag(Q_RANDOM), true);
|
||||
test_equal(queue_has_flag(collection :: get_queue(), Q_RANDOM), true);
|
||||
test_equal(deck :: get_queues().size(), (size_t)2);
|
||||
|
||||
it = deck :: get_queues().begin();
|
||||
|
@ -79,16 +79,16 @@ static void test_create_mv_destroy()
|
|||
q1 = deck :: create(true);
|
||||
q1->q_notify = &test_notifier;
|
||||
test_not_equal(q1, Q_NULL);
|
||||
test_equal(q1->has_flag(Q_ENABLED), true);
|
||||
test_equal(q1->has_flag(Q_RANDOM), true);
|
||||
test_equal(queue_has_flag(q1, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(q1, Q_RANDOM), true);
|
||||
test_equal(deck :: index(q1), (unsigned)2);
|
||||
test_equal(deck :: get(2), q1);
|
||||
|
||||
q2 = deck :: create(false);
|
||||
q2->q_notify = &test_notifier;
|
||||
test_not_equal(q2, Q_NULL);
|
||||
test_equal(q2->has_flag(Q_ENABLED), true);
|
||||
test_equal(q2->has_flag(Q_RANDOM), false);
|
||||
test_equal(queue_has_flag(q2, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(q2, Q_RANDOM), false);
|
||||
test_equal(deck :: index(q2), (unsigned)3);
|
||||
test_equal(deck :: get(3), q2);
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ static void test_init()
|
|||
queue *q = collection :: get_queue();
|
||||
|
||||
test_not_equal(q, Q_NULL);
|
||||
test_equal(q->has_flag(Q_ENABLED), true);
|
||||
test_equal(q->has_flag(Q_REPEAT), true);
|
||||
test_equal(queue_has_flag(q, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(q, Q_REPEAT), true);
|
||||
|
||||
test_cp_data_dir();
|
||||
filter_init();
|
||||
|
|
|
@ -18,9 +18,9 @@ static void test_init()
|
|||
queue *q = playlist :: get_queue();
|
||||
|
||||
test_not_equal(q, Q_NULL);
|
||||
test_equal(q->has_flag(Q_ENABLED), true);
|
||||
test_equal(q->has_flag(Q_REPEAT), true);
|
||||
test_equal(q->has_flag(Q_NO_SORT), true);
|
||||
test_equal(queue_has_flag(q, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(q, Q_REPEAT), true);
|
||||
test_equal(queue_has_flag(q, Q_NO_SORT), true);
|
||||
|
||||
/* init should work even if playlist.db doesn't exist! */
|
||||
playlist :: init();
|
||||
|
|
|
@ -83,10 +83,10 @@ static void test_flags()
|
|||
struct queue q(0);
|
||||
|
||||
test_equal(q.q_flags, 0);
|
||||
test_equal(q.has_flag(Q_ENABLED), false);
|
||||
test_equal(q.has_flag(Q_RANDOM), false);
|
||||
test_equal(q.has_flag(Q_REPEAT), false);
|
||||
test_equal(q.has_flag(Q_NO_SORT), false);
|
||||
test_equal(queue_has_flag(&q, Q_ENABLED), false);
|
||||
test_equal(queue_has_flag(&q, Q_RANDOM), false);
|
||||
test_equal(queue_has_flag(&q, Q_REPEAT), false);
|
||||
test_equal(queue_has_flag(&q, Q_NO_SORT), false);
|
||||
|
||||
q.set_flag(Q_ENABLED);
|
||||
test_equal(q.q_flags, Q_ENABLED);
|
||||
|
@ -98,10 +98,10 @@ static void test_flags()
|
|||
q.set_flag(Q_RANDOM);
|
||||
q.set_flag(Q_REPEAT);
|
||||
q.set_flag(Q_NO_SORT);
|
||||
test_equal(q.has_flag(Q_ENABLED), true);
|
||||
test_equal(q.has_flag(Q_RANDOM), true);
|
||||
test_equal(q.has_flag(Q_REPEAT), true);
|
||||
test_equal(q.has_flag(Q_NO_SORT), true);
|
||||
test_equal(queue_has_flag(&q, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(&q, Q_RANDOM), true);
|
||||
test_equal(queue_has_flag(&q, Q_REPEAT), true);
|
||||
test_equal(queue_has_flag(&q, Q_NO_SORT), true);
|
||||
}
|
||||
|
||||
static void test_stress(unsigned int N)
|
||||
|
@ -329,7 +329,7 @@ static void test_save_load()
|
|||
r.read(f);
|
||||
file_close(&f);
|
||||
|
||||
test_equal(r.has_flag(Q_RANDOM), true);
|
||||
test_equal(queue_has_flag(&r, Q_RANDOM), true);
|
||||
test_equal(r.q_length, q.q_length);
|
||||
test_equal(queue_size(&r), 13);
|
||||
|
||||
|
|
Loading…
Reference in New Issue