queue: Create an on_track_removed() notification

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-04-03 12:24:26 -04:00
parent 89a13ff6f7
commit 9eef2ad35d
3 changed files with 12 additions and 12 deletions

View File

@ -14,7 +14,8 @@
static class DefaultNotifier : public QNotifier {
public:
DefaultNotifier() {};
void on_track_added(unsigned int pos) {};
void on_track_added(unsigned int pos) {};
void on_track_removed(unsigned int pos) {};
} def_notify;
@ -164,6 +165,7 @@ void Queue :: del(unsigned int index)
{
_length -= _tracks[index]->length();
_tracks.erase(_tracks.begin() + index);
_notify->on_track_removed(index);
get_callbacks()->on_queue_track_del(this, index);
}

View File

@ -53,6 +53,13 @@ public:
* @param pos Position in the queue that the track was added.
*/
virtual void on_track_added(unsigned int) = 0;
/**
* Called when a track is removed from a queue.
*
* @param pos Position in the queue that the track was removed from.
*/
virtual void on_track_removed(unsigned int) = 0;
};

View File

@ -19,7 +19,8 @@ Track *TRACK_NULL = NULL;
static class TestNotifier : public QNotifier {
public:
TestNotifier() : QNotifier() {}
void on_track_added(unsigned int i) { count_add++; }
void on_track_added(unsigned int i) { count_add++; }
void on_track_removed(unsigned int i) { count_del++; }
} test_notifier;
@ -34,7 +35,6 @@ public:
};
TestQueue *Q = NULL, *R = NULL;
void test_del_cb_noop(Queue *q, unsigned int id) { }
void test_default()
@ -82,11 +82,6 @@ void test_flags()
test_equal(q.has_flag(Q_NO_SORT), false);
}
void test_del_cb(Queue *q, unsigned int id)
{
count_del++;
}
unsigned int _test_add_loop(unsigned int i)
{
@ -132,12 +127,9 @@ void test_add_remove()
TestQueue q(0);
Q = &q;
get_callbacks()->on_queue_track_del = test_del_cb;
test_equal(q.length(), expected);
test_equal(q.size(), (unsigned)0);
/* Add tracks */
test_for_each(0, 24, 1, _test_add_loop);
test_equal(q.length(), expected);
@ -244,7 +236,6 @@ void test_next()
TestQueue q(0);
Q = &q;
get_callbacks()->on_queue_track_del = test_del_cb_noop;
test_fill_q();
test_for_each(0, 24, 1, _test_next_loop);