core/collection: Convert file to C

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-07 09:35:58 -05:00
parent 49457751c9
commit 7065b6312e
14 changed files with 63 additions and 64 deletions

View File

@ -2,8 +2,10 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/audio.h>
extern "C" {
#include <core/collection.h>
}
#include <core/deck.h>
#include <core/library.h>
#include <core/string.h>

View File

@ -1,13 +1,11 @@
/**
/*
* Copyright 2013 (c) Anna Schumaker.
*/
extern "C" {
#include <core/collection.h>
#include <core/idle.h>
}
#include <core/library.h>
#include <core/print.h>
#include <glib.h>
#include <stdlib.h>
static struct queue library_q;
@ -23,7 +21,7 @@ static void __scan_dir(void *);
static void __scan_dir_later(struct library *library, const gchar *dir)
{
struct scan_data *data = new struct scan_data;
struct scan_data *data = g_malloc(sizeof(struct scan_data));
data->sd_lib = library;
data->sd_path = g_strdup(dir);
@ -50,10 +48,11 @@ static void __scan_path(struct scan_data *scan, const gchar *name)
static void __scan_dir(void *data)
{
struct scan_data *scan = (struct scan_data *)data;
GDir *dir = g_dir_open(scan->sd_path, 0, NULL);
struct scan_data *scan = data;
const char *name;
GDir *dir;
dir = g_dir_open(scan->sd_path, 0, NULL);
if (dir == NULL)
goto out;
@ -69,12 +68,12 @@ static void __scan_dir(void *data)
out:
/* Allocated by __scan_dir_later() */
g_free(scan->sd_path);
delete scan;
g_free(scan);
}
static void __validate_library(void *data)
{
struct library *library = (struct library *)data;
struct library *library = data;
struct db_entry *dbe, *next;
struct track *track;
gchar *path;
@ -118,10 +117,9 @@ void collection_init(struct queue_ops *ops)
for (i = 0; i < n; i++) {
file_readf(&c_file, "%u %d", &field, &ascending);
queue_sort(&library_q, (compare_t)(field + 1),
(i == 0) ? true : false);
queue_sort(&library_q, field + 1, (i == 0) ? true : false);
if (ascending == false)
queue_sort(&library_q, (compare_t)(field + 1), false);
queue_sort(&library_q, field + 1, false);
}
file_close(&c_file);

View File

@ -5,10 +5,10 @@
#include <core/core.h>
#include <core/deck.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/tags/tags.h>
}
#include <core/library.h>
#include <core/playlist.h>

View File

@ -1,10 +1,11 @@
/**
* Copyright 2013 (c) Anna Schumaker.
*/
extern "C" {
#include <core/collection.h>
}
#include <core/deck.h>
#include <core/file.h>
#include <core/library.h>
static std::list<TempQueue> queue_deck;
static struct queue recent_queue;

View File

@ -1,7 +1,9 @@
/**
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/library.h>
extern "C" {
#include <core/collection.h>
}
#include <core/playlist.h>

View File

@ -1,7 +1,9 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/library.h>
extern "C" {
#include <core/collection.h>
}
#include <core/playlist.h>
#include <gui/tabs.h>
#include <gui/queue/label.h>

View File

@ -2,11 +2,10 @@
* Copyright 2014 (c) Anna Schumaker.
*/
extern "C" {
#include <core/containers/database.h>
#include <core/collection.h>
#include <core/containers/index.h>
#include <core/idle.h>
}
#include <core/containers/index.h>
#include <core/library.h>
#include <core/playlist.h>
#include <gui/ocarina.h>

View File

@ -10,13 +10,10 @@
*
* flags sort.length ... sort[N].field sort[N].ascending ...
*/
#ifndef OCARINA_CORE_LIBRARY_H
#define OCARINA_CORE_LIBRARY_H
#ifndef OCARINA_CORE_COLLECTION_H
#define OCARINA_CORE_COLLECTION_H
extern "C" {
#include <core/queue.h>
}
#include <string>
/* Called to initialize the collection manager. */
@ -48,4 +45,4 @@ void collection_set_enabled(struct library *, bool);
/* Called to access the collection queue. */
struct queue *collection_get_queue();
#endif /* OCARINA_CORE_LIBRARY_H */
#endif /* OCARINA_CORE_COLLECTION_H */

View File

@ -1,4 +1,5 @@
audio
collection
database
date
deck
@ -7,7 +8,6 @@ file
filter
idle
index
library
playlist
queue
random

View File

@ -25,7 +25,7 @@ res += [ CoreTest("idle", "idle.c") ]
res += SConscript("tags/Sconscript")
res += [ CoreTest("queue", "queue.c") ]
res += [ CoreTest("library", "library.cpp") ]
res += [ CoreTest("collection", "collection.c") ]
res += [ CoreTest("playlist", "playlist.cpp") ]
res += [ CoreTest("deck", "deck.cpp") ]
res += [ CoreTest("audio", "audio.cpp") ]

View File

@ -3,11 +3,11 @@
*/
#include <core/audio.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/tags/tags.h>
}
#include <core/deck.h>
#include <core/library.h>
#include "test.h"
struct track *TRACK_NULL = NULL;

View File

@ -1,13 +1,11 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/idle.h>
#include <core/tags/tags.h>
}
#include <core/library.h>
#include "test.h"
#include <tests/test.h>
static void test_init()
{
@ -18,12 +16,12 @@ static void test_init()
tags_init();
collection_init(NULL);
test_not_equal(q, NULL);
test_equal(queue_has_flag(q, Q_ENABLED), true);
test_equal(queue_has_flag(q, Q_REPEAT), true);
test_equal(queue_has_flag(q, Q_SAVE_SORT), true);
test_equal(queue_has_flag(q, Q_SAVE_FLAGS), true);
test_equal(queue_has_flag(q, Q_ADD_FRONT), false);
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)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);
list = q->q_sort;
@ -40,19 +38,19 @@ static void test_add()
struct queue *q = collection_get_queue();
struct library *lib;
test_equal(collection_add("tests/Invalid"), NULL);
test_equal((void *)collection_add("tests/Invalid"), NULL);
lib = collection_add("tests/Music");
test_not_equal(lib, NULL);
test_not_equal((void *)lib, NULL);
test_equal(lib->li_size, 0);
test_equal(lib->li_enabled, true);
test_equal(lib->li_enabled, (bool)true);
test_equal(lib->li_path, "tests/Music");
test_equal(queue_size(q), 0);
test_equal(idle_run_task(), true); /* collection validation */
test_equal(idle_run_task(), true); /* tests/Music/ */
test_equal(idle_run_task(), true); /* tests/Music/Hyrule Symphony/ */
test_equal(idle_run_task(), false); /* tests/Music/Ocarina of Time/ */
test_equal(idle_run_task(), (bool)true); /* collection validation */
test_equal(idle_run_task(), (bool)true); /* tests/Music/ */
test_equal(idle_run_task(), (bool)true); /* <DIR>/Hyrule Symphony/ */
test_equal(idle_run_task(), (bool)false); /* <DIR>/Ocarina of Time/ */
test_equal(track_db_get()->db_size, 48);
test_equal(lib->li_size, 48);
@ -73,20 +71,20 @@ static void test_update()
collection_update(lib);
/* Collection validation removes tests/Music/Hyrule Symphony/ */
test_equal(idle_run_task(), 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 and tests/Music/Ocarina of Time/ have not changed */
test_equal(idle_run_task(), true);
test_equal(idle_run_task(), true);
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(), false);
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);
@ -98,20 +96,20 @@ static void test_update()
* Collection validation removes tests/Music/symphony/,
* and tests/Music has not changed
*/
test_equal(idle_run_task(), true);
test_equal(idle_run_task(), true);
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(), true);
test_equal(idle_run_task(), (bool)true);
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(), false);
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);
@ -144,14 +142,14 @@ static void test_save_load()
GSList *list;
collection_save(NULL, Q_ENABLED);
test_equal(test_data_file_exists("library.q"), false);
test_equal(test_data_file_exists("library.q"), (bool)false);
queue_sort(q, COMPARE_TRACK, true);
queue_sort(q, COMPARE_TRACK, false);
queue_sort(q, COMPARE_GENRE, 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"), true);
test_equal(test_data_file_exists("library.q"), (bool)true);
collection_deinit();
test_equal(queue_size(q), 0);
@ -176,7 +174,7 @@ static void test_remove()
collection_remove(library_get(0));
test_equal(track_db_get()->db_size, 0);
test_equal(library_get(0), NULL);
test_equal((void *)library_get(0), NULL);
test_equal(queue_size(q), 0);
collection_deinit();

View File

@ -3,10 +3,10 @@
*/
#include <core/deck.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/tags/tags.h>
}
#include <core/library.h>
#include "test.h"
static queue *Q_NULL = NULL;

View File

@ -2,10 +2,10 @@
* Copyright 2013 (c) Anna Schumaker.
*/
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/tags/tags.h>
}
#include <core/library.h>
#include <core/playlist.h>
#include "test.h"