From 9733b82ae895e33ad2815039e1e3a1b280bd8d69 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 11 May 2016 11:13:42 -0400 Subject: [PATCH] core/collection: Remove file I have replaced everything in this file with the code in core/playlists/library.c Signed-off-by: Anna Schumaker --- core/audio.c | 5 +- core/collection.c | 205 ----------------------------------- core/core.c | 2 - core/tempq.c | 1 - gui/audio.c | 1 - gui/playlist.c | 1 - gui/sidebar.c | 1 - gui/view.c | 1 - include/core/collection.h | 47 -------- tests/core/.gitignore | 1 - tests/core/Sconscript | 1 - tests/core/audio.c | 3 +- tests/core/collection.c | 218 -------------------------------------- tests/core/tempq.c | 4 +- tests/gui/audio.c | 3 +- tests/gui/model.c | 3 +- tests/gui/queue.c | 3 +- tests/gui/sidebar.c | 1 - tests/gui/view.c | 3 +- 19 files changed, 7 insertions(+), 497 deletions(-) delete mode 100644 core/collection.c delete mode 100644 include/core/collection.h delete mode 100644 tests/core/collection.c diff --git a/core/audio.c b/core/audio.c index 9bdc58a8..47efb3c7 100644 --- a/core/audio.c +++ b/core/audio.c @@ -2,7 +2,6 @@ * Copyright 2013 (c) Anna Schumaker. */ #include -#include #include #include #include @@ -235,10 +234,8 @@ void audio_error(GstMessage *error) gchar *path = NULL, *debug = NULL; GError *err = NULL; - if (audio_track) { - collection_check_library(audio_track->tr_library); + if (audio_track) path = track_path(audio_track); - } if (error) gst_message_parse_error(error, &err, &debug); diff --git a/core/collection.c b/core/collection.c deleted file mode 100644 index 1348d368..00000000 --- a/core/collection.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2013 (c) Anna Schumaker. - */ -#include -#include -#include - -#include -#include -#include - - -struct scan_data { - struct library *sd_lib; - gchar *sd_path; -}; - -static bool __scan_dir(void *); - - -#ifdef CONFIG_TESTING -bool test_collection_error = false; -static inline int __g_access(const gchar *path) -{ - if (test_collection_error) - return -1; - return g_access(path, F_OK); -} -#else -#define __g_access(path) g_access(path, F_OK) -#endif /* CONFIG_TESTING */ - - -static void __scan_dir_later(struct library *library, const gchar *dir) -{ - struct scan_data *data = g_malloc(sizeof(struct scan_data)); - - data->sd_lib = library; - data->sd_path = g_strdup(dir); - - /* data is freed by __scan_dir() */ - idle_schedule(IDLE_SYNC, __scan_dir, data); -} - -static void __scan_path(struct scan_data *scan, const gchar *name) -{ - gchar *path = g_strdup_printf("%s/%s", scan->sd_path, name); - struct track *track; - - if (g_file_test(path, G_FILE_TEST_IS_DIR)) - __scan_dir_later(scan->sd_lib, path); - else { - track = track_add(scan->sd_lib, path); - if (track) - pl_system_new_track(track); - } - - g_free(path); -} - -static bool __scan_dir(void *data) -{ - struct scan_data *scan = data; - const char *name; - GDir *dir; - - dir = g_dir_open(scan->sd_path, 0, NULL); - if (dir == NULL) - goto out; - - name = g_dir_read_name(dir); - while (name != NULL) { - __scan_path(scan, name); - name = g_dir_read_name(dir); - } - - g_dir_close(dir); - track_db_commit(); - -out: - /* Allocated by __scan_dir_later() */ - g_free(scan->sd_path); - g_free(scan); - return true; -} - -static bool __validate_library(void *data) -{ - struct library *library = data; - struct db_entry *dbe, *next; - struct track *track; - int access; - gchar *path; - - db_for_each(dbe, next, track_db_get()) { - track = TRACK(dbe); - if (track->tr_library != library) - continue; - - path = track_path(track); - access = __g_access(path); - g_free(path); - - if (access < 0) { - if (collection_check_library(library) < 0) - return true; - pl_system_delete_track(track); - track_remove(track); - } - } - - return true; -} - -bool __collection_init_idle(void *data) -{ - collection_update_all(); - return true; -} - - - -/* - * External API begins here - */ -void collection_init() -{ - idle_schedule(IDLE_SYNC, __collection_init_idle, NULL); -} - -void collection_deinit() -{ -} - -struct library *collection_add(const gchar *path) -{ - struct library *library = NULL; - - if (g_file_test(path, G_FILE_TEST_IS_DIR) == false) - return library; - - library = library_find(path); - if (library) - collection_update(library); - return library; -} - -void collection_remove(struct library *library) -{ - if (library) { - collection_set_enabled(library, false); - track_remove_all(library); - library_remove(library); - } -} - -void collection_update(struct library *library) -{ - if (!library) - return; - - idle_schedule(IDLE_SYNC, __validate_library, library); - __scan_dir_later(library, library->li_path); -} - -void collection_update_all() -{ - struct db_entry *library, *next; - - db_for_each(library, next, library_db_get()) - collection_update(LIBRARY(library)); -} - -void collection_set_enabled(struct library *library, bool enabled) -{ - struct db_entry *dbe, *next; - struct track *track; - - if (!library || (library->li_enabled == enabled)) - return; - if (enabled && (collection_check_library(library) < 0)) - return; - - library_set_enabled(library, enabled); - - db_for_each(dbe, next, track_db_get()) { - track = TRACK(dbe); - if (track->tr_library == library) { - if (enabled) - playlist_add(PL_SYSTEM, "Collection", track); - else - playlist_remove(PL_SYSTEM, "Collection", track); - } - } -} - -int collection_check_library(struct library *library) -{ - int ret = __g_access(library->li_path); - if (ret < 0) { - g_warning("Can't access library at %s/\n", library->li_path); - collection_set_enabled(library, false); - } - return ret; -} diff --git a/core/core.c b/core/core.c index 4c3606f2..c2368e35 100644 --- a/core/core.c +++ b/core/core.c @@ -3,7 +3,6 @@ */ #include #include -#include #include #include #include @@ -21,7 +20,6 @@ void core_init(int *argc, char ***argv, struct core_init_data *init) filter_init(); tags_init(); playlist_init(init->playlist_ops); - collection_init(); tempq_init(init->tempq_ops); audio_init(argc, argv, init->audio_ops); } diff --git a/core/tempq.c b/core/tempq.c index 258873aa..2f18077d 100644 --- a/core/tempq.c +++ b/core/tempq.c @@ -1,7 +1,6 @@ /* * Copyright 2013 (c) Anna Schumaker. */ -#include #include #include #include diff --git a/gui/audio.c b/gui/audio.c index 27e1fad4..a7ce5e2d 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -2,7 +2,6 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include #include #include #include diff --git a/gui/playlist.c b/gui/playlist.c index d1a43f7f..75b75635 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -1,7 +1,6 @@ /* * Copyright 2016 (c) Anna Schumaker. */ -#include #include #include #include diff --git a/gui/sidebar.c b/gui/sidebar.c index 09a5b768..2a5a463f 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -1,7 +1,6 @@ /* * Copyright 2015 (c) Anna Schumaker. */ -#include #include #include #include diff --git a/gui/view.c b/gui/view.c index db7e6085..e3e77e46 100644 --- a/gui/view.c +++ b/gui/view.c @@ -2,7 +2,6 @@ * Copyright 2016 (c) Anna Schumaker. */ #include -#include #include #include #include diff --git a/include/core/collection.h b/include/core/collection.h deleted file mode 100644 index 2a8a1d3e..00000000 --- a/include/core/collection.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013 (c) Anna Schumaker. - * - * The collection manager is in charge of creating, updating, and removing - * Library and Track tags. This code also manages a special queue used by - * the GUI to display all tracks in the collection. - * - * The entire collection queue does not need to be saved, so instead the - * collection manager only stores flags and the current sort order: - * - * flags sort.length ... sort[N].field sort[N].ascending ... - */ -#ifndef OCARINA_CORE_COLLECTION_H -#define OCARINA_CORE_COLLECTION_H - -#include - - -/* Called to initialize the collection manager. */ -void collection_init(void); - - -/* Called to add a new library directory to the collection manager. */ -struct library *collection_add(const gchar *); - -/* Called to remove a library directory from the collection manager. */ -void collection_remove(struct library *); - -/* Called to update a library directory. */ -void collection_update(struct library *); - -/* Called to update all library paths. */ -void collection_update_all(); - - -/* Called to enable or disable a library directory. */ -void collection_set_enabled(struct library *, bool); - -/* Called to check if the library path is good. */ -int collection_check_library(struct library *); - - -#ifdef CONFIG_TESTING -extern bool test_collection_error; -#endif /* CONFIG_TESTING */ - -#endif /* OCARINA_CORE_COLLECTION_H */ diff --git a/tests/core/.gitignore b/tests/core/.gitignore index 6fbc2fc7..95fce546 100644 --- a/tests/core/.gitignore +++ b/tests/core/.gitignore @@ -15,6 +15,5 @@ playlists/system playlists/artist playlists/library playlist -collection tempq audio diff --git a/tests/core/Sconscript b/tests/core/Sconscript index df9778c9..cae9a3ed 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -37,7 +37,6 @@ res += [ CoreTest("queue") ] res += SConscript("playlists/Sconscript") res += [ CoreTest("playlist") ] -res += [ CoreTest("collection") ] res += [ CoreTest("tempq") ] core_objs += [ env.Object("../../core/core.c") ] diff --git a/tests/core/audio.c b/tests/core/audio.c index 5f13469f..555b7084 100644 --- a/tests/core/audio.c +++ b/tests/core/audio.c @@ -2,7 +2,6 @@ * Copyright 2013 (c) Anna Schumaker. */ #include -#include #include #include #include @@ -77,7 +76,7 @@ static void test_init() test_equal(load_count, 0); test_equal(state_count, 0); - collection_add("tests/Music/Hyrule Symphony"); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task()) {}; test_equal((void *)audio_cur_track(), NULL); diff --git a/tests/core/collection.c b/tests/core/collection.c deleted file mode 100644 index 1a26d1aa..00000000 --- a/tests/core/collection.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2013 (c) Anna Schumaker. - */ -#include -#include -#include -#include -#include -#include -#include - -static void test_init() -{ - struct queue *q = playlist_get_queue(PL_SYSTEM, "Collection"); - GSList *list; - - idle_init_sync(); - filter_init(); - tags_init(); - playlist_init(NULL); - collection_init(); - - test_not_equal((void *)q, NULL); - 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)false); - test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)false); - test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)true); - - 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_ADD_FRONT), (bool)false); - test_equal(queue_size(q), 0); - - list = q->q_sort; - test_equal(g_slist_length(q->q_sort), 3); - test_equal(GPOINTER_TO_INT(list->data), COMPARE_ARTIST); - list = g_slist_next(list); - test_equal(GPOINTER_TO_INT(list->data), COMPARE_YEAR); - list = g_slist_next(list); - test_equal(GPOINTER_TO_INT(list->data), COMPARE_TRACK); -} - -static void test_add() -{ - struct queue *q = playlist_get_queue(PL_SYSTEM, "Collection"); - struct library *lib; - - test_equal((void *)collection_add("tests/Invalid"), NULL); - - lib = collection_add("tests/Music"); - test_not_equal((void *)lib, NULL); - test_equal(lib->li_size, 0); - test_equal(lib->li_enabled, (bool)true); - test_equal(lib->li_path, "tests/Music"); - - test_equal(queue_size(q), 0); - while (idle_run_task()) {}; - test_equal(track_db_get()->db_size, 48); - test_equal(lib->li_size, 48); - test_equal(queue_size(q), 48); -} - -static void test_update() -{ - struct queue *q = playlist_get_queue(PL_SYSTEM, "Collection"); - struct library *lib = library_get(0); - - collection_update(NULL); - test_equal(track_db_get()->db_size, 48); - test_equal(lib->li_size, 48); - test_equal(queue_size(q), 48); - - g_rename("tests/Music/Hyrule Symphony/", "tests/Music/symphony/"); - collection_update(lib); - - /* Collection validation removes tests/Music/Hyrule Symphony/ */ - test_equal(idle_run_task(), (bool)true); - test_equal(track_db_get()->db_size, 35); - test_equal(lib->li_size, 35); - test_equal(queue_size(q), 35); - - /* tests/Music and tests/Music/Ocarina of Time/ have not changed */ - test_equal(idle_run_task(), (bool)true); - test_equal(idle_run_task(), (bool)true); - test_equal(track_db_get()->db_size, 35); - test_equal(lib->li_size, 35); - test_equal(queue_size(q), 35); - - /* Scan tests/Music/symphony/ */ - test_equal(idle_run_task(), (bool)false); - test_equal(track_db_get()->db_size, 48); - test_equal(lib->li_size, 48); - test_equal(queue_size(q), 48); - - g_rename("tests/Music/symphony", "tests/Music/Hyrule Symphony/"); - collection_update_all(); - - /* - * Collection validation removes tests/Music/symphony/, - * and tests/Music has not changed - */ - test_equal(idle_run_task(), (bool)true); - test_equal(idle_run_task(), (bool)true); - test_equal(track_db_get()->db_size, 35); - test_equal(lib->li_size, 35); - test_equal(queue_size(q), 35); - - /* tests/Music/Hyrule Symphony exists again */ - test_equal(idle_run_task(), (bool)true); - test_equal(idle_run_task(), (bool)false); - test_equal(track_db_get()->db_size, 48); - test_equal(lib->li_size, 48); - test_equal(queue_size(q), 48); - - /* tests/Music/Ocarina of Time/ has not changed */ - test_equal(idle_run_task(), (bool)false); - test_equal(track_db_get()->db_size, 48); - test_equal(lib->li_size, 48); - test_equal(queue_size(q), 48); -} - -static void test_enable() -{ - struct queue *q = playlist_get_queue(PL_SYSTEM, "Collection"); - struct library *lib = library_get(0); - struct db_entry *dbe, *next; - - collection_set_enabled(NULL, true); - test_equal(queue_size(q), 48); - - collection_set_enabled(lib, false); - test_equal(queue_size(q), 0); - - collection_set_enabled(lib, false); - test_equal(queue_size(q), 0); - - /* Banned tracks should not be re-added to the queue. */ - db_for_each(dbe, next, track_db_get()) { - playlist_add(PL_SYSTEM, "Hidden", TRACK(dbe)); - next = db_next(track_db_get(), next); - } - - collection_set_enabled(lib, true); - test_equal(queue_size(q), 24); - - collection_set_enabled(lib, true); - test_equal(queue_size(q), 24); - - db_for_each(dbe, next, track_db_get()) { - playlist_remove(PL_SYSTEM, "Hidden", TRACK(dbe)); - next = db_next(track_db_get(), next); - } - test_equal(queue_size(q), 48); -} - -static void test_eio() -{ - struct queue *q = playlist_get_queue(PL_SYSTEM, "Collection"); - struct library *lib = library_get(0); - - test_equal(queue_size(q), 48); - test_equal(collection_check_library(lib), 0); - test_equal(lib->li_enabled, (bool)true); - test_equal(queue_size(q), 48); - - test_collection_error = true; - test_equal(collection_check_library(lib), -1); - test_equal(lib->li_enabled, (bool)false); - test_equal(queue_size(q), 0); - - collection_set_enabled(lib, true); - test_equal(lib->li_enabled, (bool)false); - test_equal(queue_size(q), 0); - - test_collection_error = false; - collection_set_enabled(lib, true); - test_equal(lib->li_enabled, (bool)true); - test_equal(queue_size(q), 48); - - test_collection_error = true; - collection_update_all(); - test_equal(idle_run_task(), (bool)true); - test_equal(lib->li_enabled, (bool)false); - test_equal(queue_size(q), 0); - - test_collection_error = false; - collection_set_enabled(lib, true); - test_equal(lib->li_enabled, (bool)true); - test_equal(queue_size(q), 48); -} - -static void test_remove() -{ - struct queue *q = playlist_get_queue(PL_SYSTEM, "Collection"); - - collection_remove(NULL); - test_equal(track_db_get()->db_size, 48); - - collection_remove(library_get(0)); - test_equal(track_db_get()->db_size, 0); - test_equal((void *)library_get(0), NULL); - test_equal(queue_size(q), 0); - - playlist_deinit(); - tags_deinit(); - filter_deinit(); -} - -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 Enable and Disable", test_enable), - UNIT_TEST("Colleciton -EIO Handling", test_eio), - UNIT_TEST("Collection Remove Path", test_remove), -); diff --git a/tests/core/tempq.c b/tests/core/tempq.c index 0890d49d..9faa93ad 100644 --- a/tests/core/tempq.c +++ b/tests/core/tempq.c @@ -1,7 +1,6 @@ /* * Copyright 2013 (c) Anna Schumaker. */ -#include #include #include #include @@ -16,7 +15,6 @@ static void test_init() filter_init(); tags_init(); playlist_init(NULL); - collection_init(); test_equal((void *)tempq_next(), NULL); @@ -119,7 +117,7 @@ static void test_next() struct queue *q0, *q1; unsigned int i; - collection_add("tests/Music/Hyrule Symphony"); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task()) {}; q0 = tempq_alloc(0); diff --git a/tests/gui/audio.c b/tests/gui/audio.c index 29e48940..de22cff8 100644 --- a/tests/gui/audio.c +++ b/tests/gui/audio.c @@ -2,7 +2,6 @@ * Copyright 2015 (c) Anna Schumaker. */ #include -#include #include #include #include @@ -70,7 +69,7 @@ static void test_audio() test_equal(test_get_toggle_state("o_hide"), (bool)false); core_init(&argc, NULL, &init_data); - collection_add("tests/Music/Hyrule Symphony"); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task()) {}; db_for_each(dbe, next, track_db_get()) { diff --git a/tests/gui/model.c b/tests/gui/model.c index 2098581a..e6e6490c 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -2,7 +2,6 @@ * Copyright 2016 (c) Anna Schumaker. */ #include -#include #include #include #include @@ -180,7 +179,7 @@ static void test_model() /* Okay, now scan a directory ... */ playlist_get_queue(PL_SYSTEM, "Collection")->q_private = model; - collection_add("tests/Music/Hyrule Symphony"); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task() == true) {} test_equal(playlist_size(PL_SYSTEM, "Collection"), 13); test_equal(count_insert, 13); diff --git a/tests/gui/queue.c b/tests/gui/queue.c index 8620379d..52786e74 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -7,7 +7,6 @@ #define TEST_NEED_SIDEBAR #define TEST_NEED_WINDOW #include -#include #include #include #include @@ -167,7 +166,7 @@ static void test_tracks() gui_queue_show(gq); test_equal(gtk_label_get_text(runtime), ""); - collection_add("tests/Music/Hyrule Symphony"); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task() == true) {} test_equal(gtk_label_get_text(runtime), "42 minutes, 45 seconds"); diff --git a/tests/gui/sidebar.c b/tests/gui/sidebar.c index 1aa0f5fd..c367d114 100644 --- a/tests/gui/sidebar.c +++ b/tests/gui/sidebar.c @@ -4,7 +4,6 @@ #define TEST_NEED_AUDIO #define TEST_NEED_COLLECTION #define TEST_NEED_PLAYLIST -#include #include #include #include diff --git a/tests/gui/view.c b/tests/gui/view.c index cfff200c..654a58dd 100644 --- a/tests/gui/view.c +++ b/tests/gui/view.c @@ -8,7 +8,6 @@ #define TEST_NEED_SIDEBAR #define TEST_NEED_WINDOW #include -#include #include #include #include @@ -73,7 +72,7 @@ static void test_treeview() gui_view_init(); while (idle_run_task()) {} - collection_add("tests/Music/Hyrule Symphony"); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task() == true) {} model = GTK_TREE_MODEL(gui_queue_model_new(playlist_get_queue(PL_SYSTEM, "Collection"))); filter = gtk_tree_model_filter_new(model, NULL);