core/queue: Replace on_track_updated() with qop_updated()
This patch also removes the now-unused queue notifier class. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
da0c96ac51
commit
0a331a44f5
|
@ -11,14 +11,6 @@ extern "C" {
|
|||
#include <sstream>
|
||||
|
||||
|
||||
static class DefaultNotifier : public QNotifier {
|
||||
public:
|
||||
DefaultNotifier() {};
|
||||
void on_track_removed(unsigned int pos) {};
|
||||
void on_track_updated(unsigned int pos) {};
|
||||
} def_notify;
|
||||
|
||||
|
||||
static bool track_less_than(struct track *lhs, struct track *rhs,
|
||||
std::vector<struct sort_info> &order)
|
||||
{
|
||||
|
@ -58,6 +50,12 @@ static inline void __queue_removed(struct queue *queue,
|
|||
queue->q_ops->qop_removed(queue, pos);
|
||||
}
|
||||
|
||||
static inline void __queue_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (queue->q_ops)
|
||||
queue->q_ops->qop_updated(queue, pos);
|
||||
}
|
||||
|
||||
static inline void __queue_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
if (queue->q_ops && queue_has_flag(queue, flag))
|
||||
|
@ -98,7 +96,6 @@ void queue_init(struct queue *queue, unsigned int flags,
|
|||
queue->q_cur = -1;
|
||||
queue->q_flags = flags;
|
||||
queue->q_length = 0;
|
||||
queue->q_notify = &def_notify;
|
||||
queue->q_ops = ops;
|
||||
}
|
||||
|
||||
|
@ -147,7 +144,7 @@ void queue_updated(struct queue *queue, struct track *track)
|
|||
{
|
||||
for (unsigned int i = 0; i < queue_size(queue); i++) {
|
||||
if (queue->q_tracks[i] == track)
|
||||
queue->q_notify->on_track_updated(i);
|
||||
__queue_updated(queue, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,6 +213,6 @@ void queue_sort(struct queue *queue, enum compare_t field, bool reset)
|
|||
SortTracks(queue->q_sort));
|
||||
|
||||
for (unsigned int i = 0; i < queue->q_tracks.size(); i++)
|
||||
queue->q_notify->on_track_updated(i);
|
||||
__queue_updated(queue, i);
|
||||
__queue_save(queue, Q_SAVE_SORT);
|
||||
}
|
||||
|
|
|
@ -59,10 +59,17 @@ static void collection_removed(struct queue *queue, unsigned int pos)
|
|||
collection_tab->on_track_removed(pos);
|
||||
}
|
||||
|
||||
static void collection_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (collection_tab)
|
||||
collection_tab->on_track_updated(pos);
|
||||
}
|
||||
|
||||
struct queue_ops collection_ops = {
|
||||
collection_added,
|
||||
collection_removed,
|
||||
collection :: save,
|
||||
collection_updated,
|
||||
};
|
||||
|
||||
void init_collection_tab()
|
||||
|
|
|
@ -45,10 +45,16 @@ static void history_removed(struct queue *queue, unsigned int pos)
|
|||
history_tab->on_track_removed(pos);
|
||||
}
|
||||
|
||||
static void history_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
history_tab->on_track_updated(pos);
|
||||
}
|
||||
|
||||
struct queue_ops history_ops = {
|
||||
history_added,
|
||||
history_removed,
|
||||
NULL,
|
||||
history_updated,
|
||||
};
|
||||
|
||||
void init_history_tab()
|
||||
|
|
|
@ -154,10 +154,16 @@ static void playlist_removed(struct queue *queue, unsigned int pos)
|
|||
p_tab->on_track_removed(pos);
|
||||
}
|
||||
|
||||
static void playlist_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
p_tab->on_track_updated(pos);
|
||||
}
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
playlist_added,
|
||||
playlist_removed,
|
||||
NULL,
|
||||
playlist_updated,
|
||||
};
|
||||
|
||||
void plist :: track_loaded(struct track *track)
|
||||
|
|
|
@ -32,10 +32,16 @@ static void tempq_removed(struct queue *queue, unsigned int pos)
|
|||
deck :: write();
|
||||
}
|
||||
|
||||
static void tempq_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
find_tab(queue)->on_track_updated(pos);
|
||||
}
|
||||
|
||||
struct queue_ops tempq_ops = {
|
||||
tempq_added,
|
||||
tempq_removed,
|
||||
deck :: save,
|
||||
tempq_updated,
|
||||
};
|
||||
|
||||
|
||||
|
@ -48,7 +54,6 @@ struct queue_ops tempq_ops = {
|
|||
Tab :: Tab(queue *pq)
|
||||
: tab_sorting_count(0), tab_pq(pq), tab_label(NULL)
|
||||
{
|
||||
pq->q_notify = this;
|
||||
queue_mapping[tab_pq] = this;
|
||||
|
||||
tab_builder = Gtk::Builder::create();
|
||||
|
|
|
@ -27,22 +27,6 @@ enum queue_flags {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Class to assist in notifying the GUI of queue changes.
|
||||
*/
|
||||
class QNotifier {
|
||||
public:
|
||||
QNotifier() {}; /**< Notifier constructor. */
|
||||
|
||||
/**
|
||||
* Called when a track has been updated.
|
||||
*
|
||||
* @param pos Position in the queue of the updated track.
|
||||
*/
|
||||
virtual void on_track_updated(unsigned int) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct queue_ops {
|
||||
/* Called to tell a higher layer that a track has been added. */
|
||||
void (*qop_added)(struct queue *, unsigned int);
|
||||
|
@ -52,6 +36,9 @@ struct queue_ops {
|
|||
|
||||
/* Called to have a higher layer save the queue. */
|
||||
void (*qop_save)(struct queue *, enum queue_flags);
|
||||
|
||||
/* Called to hell a higher layer that a track has been updated. */
|
||||
void (*qop_updated)(struct queue *, unsigned int);
|
||||
};
|
||||
|
||||
|
||||
|
@ -77,7 +64,6 @@ struct queue {
|
|||
unsigned int q_cur; /* The queue's last-played index. */
|
||||
unsigned int q_flags; /* The queue's set of flags. */
|
||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
||||
QNotifier *q_notify; /* The queue's notification functions. */
|
||||
|
||||
std :: vector <struct track *> q_tracks; /* The queue's list of tracks. */
|
||||
std :: vector <struct sort_info> q_sort; /* The queue's sort settings. */
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <gui/queue/window.h>
|
||||
#include <core/queue.h>
|
||||
|
||||
class Tab : public QNotifier {
|
||||
class Tab {
|
||||
private:
|
||||
unsigned int tab_sorting_count;
|
||||
std::string tab_sorting_title;
|
||||
|
|
|
@ -64,20 +64,11 @@ static void test_init()
|
|||
file_close(&f);
|
||||
}
|
||||
|
||||
static class TestNotifier : public QNotifier {
|
||||
public:
|
||||
TestNotifier() : QNotifier() {}
|
||||
void on_track_added(unsigned int i) {}
|
||||
void on_track_removed(unsigned int i) {}
|
||||
void on_track_updated(unsigned int i) {}
|
||||
} test_notifier;
|
||||
|
||||
static void test_create_mv_destroy()
|
||||
{
|
||||
queue *q1, *q2;
|
||||
|
||||
q1 = deck :: create(true, NULL);
|
||||
q1->q_notify = &test_notifier;
|
||||
test_not_equal(q1, Q_NULL);
|
||||
test_equal(queue_has_flag(q1, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(q1, Q_RANDOM), true);
|
||||
|
@ -85,7 +76,6 @@ static void test_create_mv_destroy()
|
|||
test_equal(deck :: get(2), q1);
|
||||
|
||||
q2 = deck :: create(false, NULL);
|
||||
q2->q_notify = &test_notifier;
|
||||
test_not_equal(q2, Q_NULL);
|
||||
test_equal(queue_has_flag(q2, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(q2, Q_RANDOM), false);
|
||||
|
@ -116,7 +106,6 @@ static void test_next_prev()
|
|||
queue *q0 = deck :: get(0);
|
||||
queue *q1 = deck :: get(1);
|
||||
|
||||
q0->q_notify = &test_notifier;
|
||||
queue_unset_flag(q0, Q_RANDOM);
|
||||
for (unsigned int i = 0; i < 4; i++)
|
||||
queue_add(q0, track_get(i));
|
||||
|
|
|
@ -17,13 +17,6 @@ unsigned int count_sort = 0;
|
|||
unsigned int count_updated = 0;
|
||||
|
||||
|
||||
static class TestNotifier : public QNotifier {
|
||||
public:
|
||||
TestNotifier() : QNotifier() {}
|
||||
void on_track_updated(unsigned int i) { count_updated++; }
|
||||
} test_notifier;
|
||||
|
||||
|
||||
static void queue_op_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
count_added++;
|
||||
|
@ -42,11 +35,17 @@ static void queue_op_save(struct queue *queue, enum queue_flags flag)
|
|||
count_sort++;
|
||||
}
|
||||
|
||||
static void queue_op_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
count_updated++;
|
||||
}
|
||||
|
||||
|
||||
static const struct queue_ops test_ops = {
|
||||
queue_op_added,
|
||||
queue_op_removed,
|
||||
queue_op_save,
|
||||
queue_op_updated,
|
||||
};
|
||||
|
||||
|
||||
|
@ -93,10 +92,8 @@ static void test_init()
|
|||
test_equal(q.q_sort.size(), (size_t)0);
|
||||
test_equal(q.q_ops, NULL);
|
||||
test_equal(queue_next(&q), (struct track *)NULL);
|
||||
test_not_equal(q.q_notify, NULL);
|
||||
|
||||
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops);
|
||||
q.q_notify = &test_notifier;
|
||||
|
||||
test_equal(q.q_cur, (unsigned int )-1);
|
||||
test_equal(q.q_flags, Q_ENABLED | Q_RANDOM);
|
||||
|
@ -104,7 +101,6 @@ static void test_init()
|
|||
test_equal(q.q_sort.size(), 0);
|
||||
test_equal(q.q_ops, &test_ops);
|
||||
test_equal(queue_next(&q), (struct track *)NULL);
|
||||
test_equal(q.q_notify, &test_notifier);
|
||||
}
|
||||
|
||||
static void test_flags()
|
||||
|
@ -166,7 +162,6 @@ static void test_stress(unsigned int N)
|
|||
count_updated = 0;
|
||||
|
||||
queue_init(&q, 0, &test_ops);
|
||||
q.q_notify = &test_notifier;
|
||||
|
||||
/* queue_add() */
|
||||
for (i = 0; i < N; i++) {
|
||||
|
|
Loading…
Reference in New Issue