core/collection: Move collection_save() out of the collection namespace
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
295a4424ed
commit
f413d14720
|
@ -171,9 +171,10 @@ void collection_deinit()
|
|||
queue_deinit(&library_q);
|
||||
}
|
||||
|
||||
void collection :: save(struct queue *queue, enum queue_flags flag)
|
||||
void collection_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
library_q.save();
|
||||
if (&library_q == queue)
|
||||
library_q.save();
|
||||
}
|
||||
|
||||
struct library *collection_add(const gchar *path)
|
||||
|
|
|
@ -76,7 +76,7 @@ struct queue_ops collection_ops = {
|
|||
collection_added,
|
||||
collection_removed,
|
||||
collection_cleared,
|
||||
collection :: save,
|
||||
collection_save,
|
||||
collection_updated,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
/**
|
||||
/*
|
||||
* 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_LIBRARY_H
|
||||
#define OCARINA_CORE_LIBRARY_H
|
||||
|
@ -10,31 +19,15 @@ extern "C" {
|
|||
#include <string>
|
||||
|
||||
|
||||
/**
|
||||
* The Library is in charge of scanning and updating Library tags along
|
||||
* with every other tag in the tag database. This code will also manage
|
||||
* a special Queue used by the UI to display all enabled Tracks.
|
||||
*
|
||||
* The library queue is dynamic, so saving involves only storing the current
|
||||
* flags and sort order.
|
||||
*
|
||||
* ... << flags << _sort_order.size()
|
||||
* ... << _sort_order[N].field << _sort_order[N].ascending << ...
|
||||
*/
|
||||
namespace collection
|
||||
{
|
||||
|
||||
void save(struct queue *, enum queue_flags);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
/* Called to add a new library directory to the collection manager. */
|
||||
struct library *collection_add(const gchar *);
|
||||
|
|
|
@ -133,6 +133,35 @@ static void test_enable()
|
|||
test_equal(queue_size(q), 48);
|
||||
}
|
||||
|
||||
static void test_save_load()
|
||||
{
|
||||
struct queue *q = collection_get_queue();
|
||||
GSList *list;
|
||||
|
||||
collection_save(NULL, Q_ENABLED);
|
||||
test_equal(test_data_file_exists("library.q"), false);
|
||||
|
||||
queue_sort(q, COMPARE_TRACK, true);
|
||||
queue_sort(q, COMPARE_TRACK, false);
|
||||
queue_sort(q, COMPARE_GENRE, false);
|
||||
|
||||
collection_save(q, Q_ENABLED);
|
||||
test_equal(test_data_file_exists("library.q"), true);
|
||||
|
||||
collection_deinit();
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(g_slist_length(q->q_sort), 0);
|
||||
|
||||
collection_init(NULL);
|
||||
test_equal(queue_size(q), 48);
|
||||
test_equal(g_slist_length(q->q_sort), 2);
|
||||
|
||||
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_remove()
|
||||
{
|
||||
struct queue *q = collection_get_queue();
|
||||
|
@ -144,18 +173,10 @@ static void test_remove()
|
|||
test_equal(track_db_get()->db_size, 0);
|
||||
test_equal(library_get(0), NULL);
|
||||
test_equal(queue_size(q), 0);
|
||||
}
|
||||
|
||||
static void test_deinit()
|
||||
{
|
||||
struct queue *q = collection_get_queue();
|
||||
|
||||
collection_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(g_slist_length(q->q_sort), 0);
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
|
@ -163,6 +184,6 @@ DECLARE_UNIT_TESTS(
|
|||
UNIT_TEST("Collection Add Path", test_add),
|
||||
UNIT_TEST("Collection Update Path", test_update),
|
||||
UNIT_TEST("Collection Enable and Disable", test_enable),
|
||||
UNIT_TEST("Collection Save and Load", test_save_load),
|
||||
UNIT_TEST("Collection Remove Path", test_remove),
|
||||
UNIT_TEST("Collection De-Initialization", test_deinit),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue