core/collection: Remove file

I have replaced everything in this file with the code in
core/playlists/library.c

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-11 11:13:42 -04:00 committed by Anna Schumaker
parent bddbd04ef5
commit 9733b82ae8
19 changed files with 7 additions and 497 deletions

View File

@ -2,7 +2,6 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/collection.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tempq.h>
@ -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);

View File

@ -1,205 +0,0 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <glib.h>
#include <stdlib.h>
#include <unistd.h>
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;
}

View File

@ -3,7 +3,6 @@
*/
#include <core/audio.h>
#include <core/core.h>
#include <core/collection.h>
#include <core/filter.h>
#include <core/idle.h>
#include <core/playlist.h>
@ -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);
}

View File

@ -1,7 +1,6 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/file.h>
#include <core/idle.h>
#include <core/tempq.h>

View File

@ -2,7 +2,6 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/collection.h>
#include <core/playlist.h>
#include <core/string.h>
#include <gui/artwork.h>

View File

@ -1,7 +1,6 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/idle.h>
#include <core/string.h>
#include <gui/builder.h>

View File

@ -1,7 +1,6 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/queue.h>
#include <core/tempq.h>
#include <gui/builder.h>

View File

@ -2,7 +2,6 @@
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/collection.h>
#include <core/playlist.h>
#include <core/tempq.h>
#include <gui/builder.h>

View File

@ -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 <core/queue.h>
/* 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 */

View File

@ -15,6 +15,5 @@ playlists/system
playlists/artist
playlists/library
playlist
collection
tempq
audio

View File

@ -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") ]

View File

@ -2,7 +2,6 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/collection.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tempq.h>
@ -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);

View File

@ -1,218 +0,0 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/filter.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
#include <tests/test.h>
#include <errno.h>
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),
);

View File

@ -1,7 +1,6 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/filter.h>
#include <core/idle.h>
#include <core/playlist.h>
@ -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);

View File

@ -2,7 +2,6 @@
* Copyright 2015 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/collection.h>
#include <core/core.h>
#include <core/idle.h>
#include <core/playlist.h>
@ -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()) {

View File

@ -2,7 +2,6 @@
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/collection.h>
#include <core/idle.h>
#include <core/core.h>
#include <core/playlist.h>
@ -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);

View File

@ -7,7 +7,6 @@
#define TEST_NEED_SIDEBAR
#define TEST_NEED_WINDOW
#include <core/core.h>
#include <core/collection.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <gui/builder.h>
@ -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");

View File

@ -4,7 +4,6 @@
#define TEST_NEED_AUDIO
#define TEST_NEED_COLLECTION
#define TEST_NEED_PLAYLIST
#include <core/collection.h>
#include <gui/builder.h>
#include <gui/settings.h>
#include <gui/sidebar.h>

View File

@ -8,7 +8,6 @@
#define TEST_NEED_SIDEBAR
#define TEST_NEED_WINDOW
#include <core/audio.h>
#include <core/collection.h>
#include <core/core.h>
#include <core/idle.h>
#include <core/playlist.h>
@ -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);