core/queue: Replace on_track_added() with qop_added()
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
daa09becf7
commit
df06b444cf
|
@ -17,8 +17,8 @@ void core :: init(struct core_init_data *init)
|
|||
filter_init();
|
||||
tags_init();
|
||||
collection :: init(init->collection_ops);
|
||||
playlist :: init();
|
||||
deck :: init(init->tempq_ops);
|
||||
playlist :: init(init->playlist_ops);
|
||||
deck :: init(init->history_ops, init->tempq_ops);
|
||||
audio :: init();
|
||||
}
|
||||
|
||||
|
|
|
@ -80,13 +80,13 @@ static void upgrade_v0()
|
|||
}
|
||||
}
|
||||
|
||||
void deck :: init(struct queue_ops *ops)
|
||||
void deck :: init(struct queue_ops *history_ops, struct queue_ops *temp_ops)
|
||||
{
|
||||
unsigned int num;
|
||||
bool upgraded = false;
|
||||
std::list<TempQueue>::iterator it;
|
||||
|
||||
queue_init(&recent_queue, Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_ADD_FRONT, NULL);
|
||||
queue_init(&recent_queue, Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_ADD_FRONT, history_ops);
|
||||
file_init(&deck_file, "deck", 1);
|
||||
|
||||
if (!file_open(&deck_file, OPEN_READ))
|
||||
|
@ -102,7 +102,7 @@ void deck :: init(struct queue_ops *ops)
|
|||
|
||||
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
||||
it->read(deck_file);
|
||||
it->q_ops = ops;
|
||||
it->q_ops = temp_ops;
|
||||
}
|
||||
file_close(&deck_file);
|
||||
|
||||
|
|
|
@ -69,11 +69,11 @@ static PlaylistQueue playlist_q;
|
|||
static std::string cur_plist;
|
||||
|
||||
|
||||
void playlist :: init()
|
||||
void playlist :: init(struct queue_ops *ops)
|
||||
{
|
||||
struct set_iter it;
|
||||
|
||||
queue_init(&playlist_q, Q_ENABLED | Q_REPEAT, NULL);
|
||||
queue_init(&playlist_q, Q_ENABLED | Q_REPEAT, ops);
|
||||
queue_sort(&playlist_q, COMPARE_ARTIST, true);
|
||||
queue_sort(&playlist_q, COMPARE_YEAR, false);
|
||||
queue_sort(&playlist_q, COMPARE_TRACK, false);
|
||||
|
|
|
@ -14,7 +14,6 @@ extern "C" {
|
|||
static class DefaultNotifier : public QNotifier {
|
||||
public:
|
||||
DefaultNotifier() {};
|
||||
void on_track_added(unsigned int pos) {};
|
||||
void on_track_removed(unsigned int pos) {};
|
||||
void on_track_updated(unsigned int pos) {};
|
||||
} def_notify;
|
||||
|
@ -38,6 +37,16 @@ static bool track_less_than(struct track *lhs, struct track *rhs,
|
|||
}
|
||||
|
||||
|
||||
static inline unsigned int __queue_added(struct queue *queue,
|
||||
struct track *track,
|
||||
unsigned int pos)
|
||||
{
|
||||
queue->q_length += track->tr_length;
|
||||
if (queue->q_ops)
|
||||
queue->q_ops->qop_added(queue, pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
static inline void __queue_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
if (queue->q_ops && queue_has_flag(queue, flag))
|
||||
|
@ -104,9 +113,7 @@ unsigned int queue_add(struct queue *queue, struct track *track)
|
|||
pos = __queue_find_sorted_id(queue, track);
|
||||
|
||||
queue->q_tracks.insert(queue->q_tracks.begin() + pos, track);
|
||||
queue->q_length += track->tr_length;
|
||||
queue->q_notify->on_track_added(pos);
|
||||
return pos;
|
||||
return __queue_added(queue, track, pos);
|
||||
}
|
||||
|
||||
void queue_remove(struct queue *queue, unsigned int index)
|
||||
|
|
|
@ -48,7 +48,14 @@ public:
|
|||
|
||||
static CollectionTab *collection_tab;
|
||||
|
||||
static void collection_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (collection_tab)
|
||||
collection_tab->on_track_added(pos);
|
||||
}
|
||||
|
||||
struct queue_ops collection_ops = {
|
||||
collection_added,
|
||||
collection :: save,
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,17 @@ public:
|
|||
|
||||
static HistoryTab *history_tab;
|
||||
|
||||
static void history_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (history_tab)
|
||||
history_tab->on_track_added(pos);
|
||||
}
|
||||
|
||||
struct queue_ops history_ops = {
|
||||
history_added,
|
||||
NULL,
|
||||
};
|
||||
|
||||
void init_history_tab()
|
||||
{
|
||||
history_tab = new HistoryTab;
|
||||
|
|
|
@ -12,6 +12,8 @@ static Glib::RefPtr<Gtk::Application> ocarina_app;
|
|||
|
||||
struct core_init_data init_data = {
|
||||
&collection_ops,
|
||||
&history_ops,
|
||||
&playlist_ops,
|
||||
&tempq_ops,
|
||||
};
|
||||
|
||||
|
|
|
@ -143,7 +143,16 @@ static void on_favorite()
|
|||
playlist :: del(track, "Favorites");
|
||||
}
|
||||
|
||||
static void playlist_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (p_tab)
|
||||
p_tab->on_track_added(pos);
|
||||
}
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
playlist_added,
|
||||
NULL,
|
||||
};
|
||||
|
||||
void plist :: track_loaded(struct track *track)
|
||||
{
|
||||
|
|
|
@ -20,8 +20,14 @@ static compare_t sort_fields[] = {
|
|||
COMPARE_GENRE, COMPARE_COUNT, COMPARE_PLAYED
|
||||
};
|
||||
|
||||
static void tempq_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
find_tab(queue)->on_track_added(pos);
|
||||
deck :: write();
|
||||
}
|
||||
|
||||
struct queue_ops tempq_ops = {
|
||||
tempq_added,
|
||||
deck :: save,
|
||||
};
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
struct core_init_data {
|
||||
struct queue_ops *collection_ops;
|
||||
struct queue_ops *history_ops;
|
||||
struct queue_ops *playlist_ops;
|
||||
struct queue_ops *tempq_ops;
|
||||
};
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace deck
|
|||
/**
|
||||
* Read the deck file from disk and restore the queues.
|
||||
*/
|
||||
void init(struct queue_ops *);
|
||||
void init(struct queue_ops *, struct queue_ops *);
|
||||
|
||||
/**
|
||||
* Save the current queues to a file on disk.
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace playlist
|
|||
* Read playlist information from disk and removed banned tracks
|
||||
* from the Library queue.
|
||||
*/
|
||||
void init();
|
||||
void init(struct queue_ops *);
|
||||
|
||||
/**
|
||||
* Check if a specific track is in a playlist.
|
||||
|
|
|
@ -34,13 +34,6 @@ class QNotifier {
|
|||
public:
|
||||
QNotifier() {}; /**< Notifier constructor. */
|
||||
|
||||
/**
|
||||
* Called when a track is added to a queue.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
|
@ -58,6 +51,9 @@ public:
|
|||
|
||||
|
||||
struct queue_ops {
|
||||
/* Called to tell a higher layer that a track has been added. */
|
||||
void (*qop_added)(struct queue *, unsigned int);
|
||||
|
||||
/* Called to have a higher layer save the queue. */
|
||||
void (*qop_save)(struct queue *, enum queue_flags);
|
||||
};
|
||||
|
|
|
@ -31,6 +31,8 @@ namespace gui
|
|||
}
|
||||
|
||||
extern struct queue_ops collection_ops;
|
||||
extern struct queue_ops history_ops;
|
||||
extern struct queue_ops playlist_ops;
|
||||
extern struct queue_ops tempq_ops;
|
||||
|
||||
void on_pq_created(queue *, unsigned int);
|
||||
|
|
|
@ -89,7 +89,7 @@ void test_init()
|
|||
filter_init();
|
||||
tags_init();
|
||||
collection :: init(NULL);
|
||||
deck :: init(NULL);
|
||||
deck :: init(NULL, NULL);
|
||||
audio :: init();
|
||||
|
||||
track = audio :: current_track();
|
||||
|
|
|
@ -24,7 +24,7 @@ static void test_init()
|
|||
filter_init();
|
||||
tags_init();
|
||||
collection :: init(NULL);
|
||||
deck :: init(NULL);
|
||||
deck :: init(NULL, NULL);
|
||||
|
||||
test_equal(queue_has_flag(collection :: get_queue(), Q_RANDOM), true);
|
||||
test_equal(deck :: get_queues().size(), (size_t)2);
|
||||
|
|
|
@ -21,7 +21,7 @@ static void test_init()
|
|||
filter_init();
|
||||
tags_init();
|
||||
collection :: init(NULL);
|
||||
playlist :: init();
|
||||
playlist :: init(NULL);
|
||||
|
||||
test_not_equal(q, Q_NULL);
|
||||
test_equal(queue_has_flag(q, Q_ENABLED), true);
|
||||
|
|
|
@ -20,12 +20,16 @@ unsigned int count_updated = 0;
|
|||
static class TestNotifier : public QNotifier {
|
||||
public:
|
||||
TestNotifier() : QNotifier() {}
|
||||
void on_track_added(unsigned int i) { count_added++; }
|
||||
void on_track_removed(unsigned int i) { count_deleted++; }
|
||||
void on_track_updated(unsigned int i) { count_updated++; }
|
||||
} test_notifier;
|
||||
|
||||
|
||||
static void queue_op_added(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
count_added++;
|
||||
}
|
||||
|
||||
static void queue_op_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
if (flag == Q_SAVE_FLAGS)
|
||||
|
@ -36,6 +40,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_save,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue