From 5a54fb69b60f6ea4a46ff76e09b5bc2f4e1c1055 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 2 May 2016 10:18:17 -0400 Subject: [PATCH] core/collection: Remove unused queue And remove collection_ops from the core initdata Signed-off-by: Anna Schumaker --- core/audio.c | 4 +- core/collection.c | 77 ++----------------------------- core/core.c | 3 +- core/playlists/system.c | 2 +- gui/ocarina.c | 1 - include/core/collection.h | 17 +------ include/core/core.h | 1 - tests/core/audio.c | 6 +-- tests/core/collection.c | 97 ++++----------------------------------- tests/core/history.c | 3 +- tests/core/tempq.c | 3 +- tests/gui/audio.c | 1 + tests/gui/view.c | 3 +- 13 files changed, 25 insertions(+), 193 deletions(-) diff --git a/core/audio.c b/core/audio.c index ad817f40..002b37c3 100644 --- a/core/audio.c +++ b/core/audio.c @@ -55,8 +55,8 @@ static struct track *__audio_load_basic(struct track *track, GstState state) __audio_change_state(state); tempq_updated(prev); - queue_updated(collection_get_queue(), prev); - queue_updated(collection_get_queue(), audio_track); + queue_updated(playlist_get_queue("Collection"), prev); + queue_updated(playlist_get_queue("Collection"), audio_track); __audio_save(); g_free(uri); diff --git a/core/collection.c b/core/collection.c index 9cceef5b..b4a51154 100644 --- a/core/collection.c +++ b/core/collection.c @@ -10,9 +10,6 @@ #include -static struct file c_file = FILE_INIT("library.q", 0, 0); -static struct queue c_queue; - struct scan_data { struct library *sd_lib; gchar *sd_path; @@ -55,7 +52,6 @@ static void __scan_path(struct scan_data *scan, const gchar *name) else { track = track_add(scan->sd_lib, path); if (track) { - queue_add(&c_queue, track); playlist_add("Collection", track); playlist_add("Unplayed", track); } @@ -110,7 +106,6 @@ static bool __validate_library(void *data) if (access < 0) { if (collection_check_library(library) < 0) return true; - queue_remove_all(&c_queue, track); playlist_remove("Collection", track); playlist_remove("Favorites", track); playlist_remove("Hidden", track); @@ -126,29 +121,6 @@ static bool __validate_library(void *data) bool __collection_init_idle(void *data) { - struct db_entry *track, *next; - - db_for_each(track, next, track_db_get()) { - if (TRACK(track)->tr_library->li_enabled && - !playlist_has("Hidden", TRACK(track))) - queue_add(&c_queue, TRACK(track)); - } - queue_unset_flag(&c_queue, Q_ADD_FRONT); - - if (file_open(&c_file, OPEN_READ)) { - queue_load_flags(&c_queue, &c_file); - file_close(&c_file); - } - - if (!c_queue.q_sort) { - queue_sort(&c_queue, COMPARE_ARTIST, true); - queue_sort(&c_queue, COMPARE_YEAR, false); - queue_sort(&c_queue, COMPARE_TRACK, false); - } - - queue_set_flag(&c_queue, Q_SAVE_SORT); - queue_set_flag(&c_queue, Q_SAVE_FLAGS); - collection_update_all(); return true; } @@ -158,26 +130,13 @@ bool __collection_init_idle(void *data) /* * External API begins here */ -void collection_init(struct queue_ops *ops) +void collection_init() { - queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops, NULL); idle_schedule(IDLE_SYNC, __collection_init_idle, NULL); } void collection_deinit() { - queue_deinit(&c_queue); -} - -void collection_save(struct queue *queue, enum queue_flags flag) -{ - if (&c_queue != queue) - return; - if (!file_open(&c_file, OPEN_WRITE)) - return; - - queue_save_flags(&c_queue, &c_file); - file_close(&c_file); } struct library *collection_add(const gchar *path) @@ -219,22 +178,6 @@ void collection_update_all() collection_update(LIBRARY(library)); } -bool collection_ban(struct track *track) -{ - bool ret = playlist_add("Hidden", track); - if (ret) - queue_remove_all(&c_queue, track); - return ret; -} - -bool collection_unban(struct track *track) -{ - bool ret = playlist_remove("Hidden", track); - if (ret) - queue_add(&c_queue, track); - return ret; -} - void collection_set_enabled(struct library *library, bool enabled) { struct db_entry *dbe, *next; @@ -246,21 +189,16 @@ void collection_set_enabled(struct library *library, bool enabled) return; library_set_enabled(library, enabled); - queue_set_flag(&c_queue, Q_ADD_FRONT); db_for_each(dbe, next, track_db_get()) { track = TRACK(dbe); if (track->tr_library == library) { - if (enabled) { - if (!playlist_has("Hidden", track)) - queue_add(&c_queue, track); - } else - queue_remove_all(&c_queue, track); + if (enabled) + playlist_add("Collection", track); + else + playlist_remove("Collection", track); } } - - queue_unset_flag(&c_queue, Q_ADD_FRONT); - queue_resort(&c_queue); } int collection_check_library(struct library *library) @@ -272,8 +210,3 @@ int collection_check_library(struct library *library) } return ret; } - -struct queue *collection_get_queue() -{ - return &c_queue; -} diff --git a/core/core.c b/core/core.c index 85358563..3590d5c0 100644 --- a/core/core.c +++ b/core/core.c @@ -22,7 +22,7 @@ void core_init(int *argc, char ***argv, struct core_init_data *init) filter_init(); tags_init(); playlist_init(init->playlist_ops); - collection_init(init->collection_ops); + collection_init(); history_init(init->history_ops); tempq_init(init->tempq_ops); audio_init(argc, argv, init->audio_ops); @@ -33,7 +33,6 @@ void core_deinit() audio_deinit(); tempq_deinit(); history_deinit(); - collection_deinit(); playlist_deinit(); tags_deinit(); filter_deinit(); diff --git a/core/playlists/system.c b/core/playlists/system.c index c53023d3..2cbbe4eb 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -112,7 +112,7 @@ static bool __sys_pl_can_add(enum sys_playlist_t plist, struct track *track, unsigned int average) { if (plist == SYS_PL_COLLECTION) - return true; + return track->tr_library->li_enabled; else if (track->tr_count == 0) return plist == SYS_PL_UNPLAYED; else if (track->tr_count <= average) diff --git a/gui/ocarina.c b/gui/ocarina.c index 99b7d0a7..822c2ee4 100644 --- a/gui/ocarina.c +++ b/gui/ocarina.c @@ -22,7 +22,6 @@ const static gchar *OCARINA_NAME = "org.gtk.ocarina-debug"; #endif struct core_init_data init_data = { - NULL, NULL, &playlist_ops, &tempq_ops, diff --git a/include/core/collection.h b/include/core/collection.h index 8834a7d2..2a8a1d3e 100644 --- a/include/core/collection.h +++ b/include/core/collection.h @@ -17,13 +17,7 @@ /* Called to initialize the collection manager. */ -void collection_init(struct queue_ops *); - -/* Called to deinitialize the collection manager. */ -void collection_deinit(); - -/* Called to save the collection queue. */ -void collection_save(struct queue *, enum queue_flags); +void collection_init(void); /* Called to add a new library directory to the collection manager. */ @@ -38,12 +32,6 @@ void collection_update(struct library *); /* Called to update all library paths. */ void collection_update_all(); -/* Called to ban a track from the collection. */ -bool collection_ban(struct track *); - -/* Called to unban a track from the collection. */ -bool collection_unban(struct track *); - /* Called to enable or disable a library directory. */ void collection_set_enabled(struct library *, bool); @@ -51,9 +39,6 @@ void collection_set_enabled(struct library *, bool); /* Called to check if the library path is good. */ int collection_check_library(struct library *); -/* Called to access the collection queue. */ -struct queue *collection_get_queue(); - #ifdef CONFIG_TESTING extern bool test_collection_error; diff --git a/include/core/core.h b/include/core/core.h index 75a3c14a..a8f5d1ea 100644 --- a/include/core/core.h +++ b/include/core/core.h @@ -7,7 +7,6 @@ struct core_init_data { - struct queue_ops *collection_ops; struct queue_ops *history_ops; struct queue_ops *playlist_ops; struct queue_ops *tempq_ops; diff --git a/tests/core/audio.c b/tests/core/audio.c index 277cbadf..75699f26 100644 --- a/tests/core/audio.c +++ b/tests/core/audio.c @@ -50,11 +50,7 @@ static struct audio_ops test_audio_ops = { }; static struct core_init_data test_init_data = { - NULL, - NULL, - NULL, - NULL, - &test_audio_ops, + .audio_ops = &test_audio_ops, }; diff --git a/tests/core/collection.c b/tests/core/collection.c index 34b83615..38c39257 100644 --- a/tests/core/collection.c +++ b/tests/core/collection.c @@ -11,14 +11,14 @@ static void test_init() { - struct queue *q = collection_get_queue(); + struct queue *q = playlist_get_queue("Collection"); GSList *list; idle_init_sync(); filter_init(); tags_init(); playlist_init(NULL); - collection_init(NULL); + collection_init(); test_not_equal((void *)q, NULL); test_equal(queue_has_flag(q, Q_ENABLED), (bool)true); @@ -30,8 +30,6 @@ static void test_init() while (idle_run_task()) {}; test_equal(queue_has_flag(q, Q_ENABLED), (bool)true); test_equal(queue_has_flag(q, Q_REPEAT), (bool)true); - test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)true); - test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)true); test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)false); test_equal(queue_size(q), 0); @@ -46,7 +44,7 @@ static void test_init() static void test_add() { - struct queue *q = collection_get_queue(); + struct queue *q = playlist_get_queue("Collection"); struct library *lib; test_equal((void *)collection_add("tests/Invalid"), NULL); @@ -66,7 +64,7 @@ static void test_add() static void test_update() { - struct queue *q = collection_get_queue(); + struct queue *q = playlist_get_queue("Collection"); struct library *lib = library_get(0); collection_update(NULL); @@ -123,41 +121,9 @@ static void test_update() test_equal(queue_size(q), 48); } -static void test_ban() -{ - const struct database *track_db = track_db_get(); - struct queue *q = collection_get_queue(); - struct db_entry *dbe, *next; - struct track *track; - unsigned int i = 0; - - db_for_each(dbe, next, track_db) { - track = TRACK(dbe); - test_loop_equal(playlist_has("Hidden", track), (bool)false, i); - test_loop_equal(collection_ban(track), (bool)true, i); - test_loop_equal(collection_ban(track), (bool)false, i); - test_loop_equal(playlist_has("Hidden", track), (bool)true, i); - test_loop_equal(queue_size(q), track_db->db_size - (i + 1), i); - i++; - } test_loop_passed(); - test_equal(queue_size(q), 0); - - i = 0; - db_for_each(dbe, next, track_db) { - track = TRACK(dbe); - test_loop_equal(playlist_has("Hidden", track), (bool)true, i); - test_loop_equal(collection_unban(track), (bool)true, i); - test_loop_equal(collection_unban(track), (bool)false, i); - test_loop_equal(playlist_has("Hidden", track), (bool)false, i); - test_loop_equal(queue_size(q), i + 1, i); - i++; - } test_loop_passed(); - test_equal(queue_size(q), track_db->db_size); -} - static void test_enable() { - struct queue *q = collection_get_queue(); + struct queue *q = playlist_get_queue("Collection"); struct library *lib = library_get(0); struct db_entry *dbe, *next; @@ -172,7 +138,7 @@ static void test_enable() /* Banned tracks should not be re-added to the queue. */ db_for_each(dbe, next, track_db_get()) { - collection_ban(TRACK(dbe)); + playlist_add("Hidden", TRACK(dbe)); next = db_next(track_db_get(), next); } @@ -183,57 +149,15 @@ static void test_enable() test_equal(queue_size(q), 24); db_for_each(dbe, next, track_db_get()) { - collection_unban(TRACK(dbe)); + playlist_remove("Hidden", TRACK(dbe)); next = db_next(track_db_get(), next); } test_equal(queue_size(q), 48); } -static void test_save_load() -{ - struct queue *q = collection_get_queue(); - struct db_entry *dbe, *next; - GSList *list; - - collection_save(NULL, Q_ENABLED); - test_equal(test_data_file_exists("library.q"), (bool)false); - - queue_sort(q, COMPARE_TRACK, (bool)true); - queue_sort(q, COMPARE_TRACK, (bool)false); - queue_sort(q, COMPARE_GENRE, (bool)false); - - collection_save(q, Q_ENABLED); - test_equal(test_data_file_exists("library.q"), (bool)true); - - collection_deinit(); - test_equal(queue_size(q), 0); - test_equal(g_slist_length(q->q_sort), 0); - - db_for_each(dbe, next, track_db_get()) { - collection_ban(TRACK(dbe)); - next = db_next(track_db_get(), next); - } - - collection_init(NULL); - while (idle_run_task()) {}; - test_equal(queue_size(q), track_db_get()->db_size / 2); - test_equal(g_slist_length(q->q_sort), 2); - - db_for_each(dbe, next, track_db_get()) { - collection_unban(TRACK(dbe)); - next = db_next(track_db_get(), next); - } - test_equal(queue_size(q), track_db_get()->db_size); - - list = q->q_sort; - test_equal(GPOINTER_TO_INT(list->data), -COMPARE_TRACK); - list = g_slist_next(list); - test_equal(GPOINTER_TO_INT(list->data), COMPARE_GENRE); -} - static void test_eio() { - struct queue *q = collection_get_queue(); + struct queue *q = playlist_get_queue("Collection"); struct library *lib = library_get(0); test_equal(queue_size(q), 48); @@ -269,7 +193,7 @@ static void test_eio() static void test_remove() { - struct queue *q = collection_get_queue(); + struct queue *q = playlist_get_queue("Collection"); collection_remove(NULL); test_equal(track_db_get()->db_size, 48); @@ -279,7 +203,6 @@ static void test_remove() test_equal((void *)library_get(0), NULL); test_equal(queue_size(q), 0); - collection_deinit(); playlist_deinit(); tags_deinit(); filter_deinit(); @@ -289,9 +212,7 @@ DECLARE_UNIT_TESTS( UNIT_TEST("Collection Initialization", test_init), UNIT_TEST("Collection Add Path", test_add), UNIT_TEST("Collection Update Path", test_update), - UNIT_TEST("Collection Ban and Unban", test_ban), UNIT_TEST("Collection Enable and Disable", test_enable), - UNIT_TEST("Collection Save and Load", test_save_load), UNIT_TEST("Colleciton -EIO Handling", test_eio), UNIT_TEST("Collection Remove Path", test_remove), ); diff --git a/tests/core/history.c b/tests/core/history.c index 4702faf5..8318d50e 100644 --- a/tests/core/history.c +++ b/tests/core/history.c @@ -18,7 +18,7 @@ static void test_init() filter_init(); tags_init(); playlist_init(NULL); - collection_init(NULL); + collection_init(); history_init(NULL); test_not_equal((void *)q, NULL); @@ -77,7 +77,6 @@ static void test_history() test_equal(queue_size(q), 2 * track_db->db_size); history_deinit(); - collection_deinit(); playlist_deinit(); tags_deinit(); filter_deinit(); diff --git a/tests/core/tempq.c b/tests/core/tempq.c index 292dc280..24f9044a 100644 --- a/tests/core/tempq.c +++ b/tests/core/tempq.c @@ -17,7 +17,7 @@ static void test_init() filter_init(); tags_init(); playlist_init(NULL); - collection_init(NULL); + collection_init(); history_init(NULL); test_equal((void *)tempq_next(), NULL); @@ -162,7 +162,6 @@ static void test_next() tempq_deinit(); history_deinit(); - collection_deinit(); playlist_deinit(); tags_deinit(); filter_deinit(); diff --git a/tests/gui/audio.c b/tests/gui/audio.c index 59c33147..ba369c3f 100644 --- a/tests/gui/audio.c +++ b/tests/gui/audio.c @@ -84,6 +84,7 @@ static void test_audio() playlist_add("Hidden", track); test_equal(playlist_has("Collection", track), (bool)false); audio_load(track); + test_equal(audio_cur_track()->tr_track, track->tr_track); duration = string_sec2str(track->tr_length); test_equal(test_get_label_text("o_title"), track->tr_title); diff --git a/tests/gui/view.c b/tests/gui/view.c index b82593a7..7a449299 100644 --- a/tests/gui/view.c +++ b/tests/gui/view.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -74,7 +75,7 @@ static void test_treeview() collection_add("tests/Music/Hyrule Symphony"); while (idle_run_task() == true) {} - model = GTK_TREE_MODEL(gui_queue_model_new(collection_get_queue())); + model = GTK_TREE_MODEL(gui_queue_model_new(playlist_get_queue("Collection"))); filter = gtk_tree_model_filter_new(model, NULL); treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));