diff --git a/core/queue.cpp b/core/queue.cpp index 97cf3507..86333dc2 100644 --- a/core/queue.cpp +++ b/core/queue.cpp @@ -47,6 +47,17 @@ static inline unsigned int __queue_added(struct queue *queue, return pos; } +static inline void __queue_removed(struct queue *queue, + struct track *track, + unsigned int pos) +{ + queue->q_length -= track->tr_length; + if (queue->q_cur == pos) + queue->q_cur--; + if (queue->q_ops) + queue->q_ops->qop_removed(queue, pos); +} + static inline void __queue_save(struct queue *queue, enum queue_flags flag) { if (queue->q_ops && queue_has_flag(queue, flag)) @@ -118,12 +129,9 @@ unsigned int queue_add(struct queue *queue, struct track *track) void queue_remove(struct queue *queue, unsigned int index) { - queue->q_length -= queue->q_tracks[index]->tr_length; + struct track *track = queue->q_tracks[index]; queue->q_tracks.erase(queue->q_tracks.begin() + index); - queue->q_notify->on_track_removed(index); - - if (queue->q_cur == index) - queue->q_cur--; + __queue_removed(queue, track, index); } void queue_remove_all(struct queue *queue, struct track *track) diff --git a/gui/collection.cpp b/gui/collection.cpp index 133a0ba3..82f6295a 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -54,8 +54,14 @@ static void collection_added(struct queue *queue, unsigned int pos) collection_tab->on_track_added(pos); } +static void collection_removed(struct queue *queue, unsigned int pos) +{ + collection_tab->on_track_removed(pos); +} + struct queue_ops collection_ops = { collection_added, + collection_removed, collection :: save, }; diff --git a/gui/history.cpp b/gui/history.cpp index 47e41772..ebb1d9fa 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -40,8 +40,14 @@ static void history_added(struct queue *queue, unsigned int pos) history_tab->on_track_added(pos); } +static void history_removed(struct queue *queue, unsigned int pos) +{ + history_tab->on_track_removed(pos); +} + struct queue_ops history_ops = { history_added, + history_removed, NULL, }; diff --git a/gui/playlist.cpp b/gui/playlist.cpp index c7d4f149..e9c7db98 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -149,8 +149,14 @@ static void playlist_added(struct queue *queue, unsigned int pos) p_tab->on_track_added(pos); } +static void playlist_removed(struct queue *queue, unsigned int pos) +{ + p_tab->on_track_removed(pos); +} + struct queue_ops playlist_ops = { playlist_added, + playlist_removed, NULL, }; diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 1114c7ef..69eae641 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -26,8 +26,15 @@ static void tempq_added(struct queue *queue, unsigned int pos) deck :: write(); } +static void tempq_removed(struct queue *queue, unsigned int pos) +{ + find_tab(queue)->on_track_removed(pos); + deck :: write(); +} + struct queue_ops tempq_ops = { tempq_added, + tempq_removed, deck :: save, }; diff --git a/include/core/queue.h b/include/core/queue.h index 52d101dc..e1d10e36 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -34,13 +34,6 @@ class QNotifier { public: QNotifier() {}; /**< Notifier constructor. */ - /** - * 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; - /** * Called when a track has been updated. * @@ -54,6 +47,9 @@ struct queue_ops { /* Called to tell a higher layer that a track has been added. */ void (*qop_added)(struct queue *, unsigned int); + /* Called to tell a higher layer that a track has been removed. */ + void (*qop_removed)(struct queue *, unsigned int); + /* Called to have a higher layer save the queue. */ void (*qop_save)(struct queue *, enum queue_flags); }; diff --git a/tests/core/queue.cpp b/tests/core/queue.cpp index b4ec65e8..235d4458 100644 --- a/tests/core/queue.cpp +++ b/tests/core/queue.cpp @@ -20,7 +20,6 @@ unsigned int count_updated = 0; static class TestNotifier : public QNotifier { public: TestNotifier() : QNotifier() {} - void on_track_removed(unsigned int i) { count_deleted++; } void on_track_updated(unsigned int i) { count_updated++; } } test_notifier; @@ -30,6 +29,11 @@ static void queue_op_added(struct queue *queue, unsigned int pos) count_added++; } +static void queue_op_removed(struct queue *queue, unsigned int pos) +{ + count_deleted++; +} + static void queue_op_save(struct queue *queue, enum queue_flags flag) { if (flag == Q_SAVE_FLAGS) @@ -41,6 +45,7 @@ static void queue_op_save(struct queue *queue, enum queue_flags flag) static const struct queue_ops test_ops = { queue_op_added, + queue_op_removed, queue_op_save, };