core/tags/track: Wire up the dbe_alloc() database operation
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a9ec9aa7f2
commit
bd1de2262d
|
@ -25,17 +25,18 @@ track :: track()
|
|||
tr_count(0), tr_length(0), tr_track(0)
|
||||
{}
|
||||
|
||||
track :: track(const std::string &key)
|
||||
struct db_entry *track_alloc(const gchar *key)
|
||||
{
|
||||
const TagLib_AudioProperties *audio;
|
||||
struct library *library;
|
||||
struct track *track = NULL;
|
||||
unsigned int lib_id;
|
||||
TagLib_File *file;
|
||||
TagLib_Tag *tag;
|
||||
std::string full;
|
||||
char *path, *lower;
|
||||
|
||||
sscanf(key.c_str(), "%u/%m[^\n]", &lib_id, &path);
|
||||
sscanf(key, "%u/%m[^\n]", &lib_id, &path);
|
||||
library = library_get(lib_id);
|
||||
full = library_file(library, path);
|
||||
file = taglib_file_new(full.c_str());
|
||||
|
@ -44,29 +45,31 @@ track :: track(const std::string &key)
|
|||
goto out;
|
||||
}
|
||||
|
||||
track = new struct track;
|
||||
tag = taglib_file_tag(file);
|
||||
audio = taglib_file_audioproperties(file);
|
||||
|
||||
tr_album = album_find(taglib_tag_album(tag), taglib_tag_year(tag));
|
||||
tr_artist = artist_find(taglib_tag_artist(tag));
|
||||
tr_genre = genre_find(taglib_tag_genre(tag));
|
||||
tr_library = library;
|
||||
track->tr_album = album_find(taglib_tag_album(tag), taglib_tag_year(tag));
|
||||
track->tr_artist = artist_find(taglib_tag_artist(tag));
|
||||
track->tr_genre = genre_find(taglib_tag_genre(tag));
|
||||
track->tr_library = library;
|
||||
|
||||
tr_count = 0;
|
||||
tr_length = taglib_audioproperties_length(audio);
|
||||
tr_track = taglib_tag_track(tag);
|
||||
date_set(&tr_date, 0, 0, 0);
|
||||
track->tr_count = 0;
|
||||
track->tr_length = taglib_audioproperties_length(audio);
|
||||
track->tr_track = taglib_tag_track(tag);
|
||||
date_set(&track->tr_date, 0, 0, 0);
|
||||
|
||||
tr_path = path;
|
||||
tr_title = taglib_tag_title(tag);
|
||||
lower = string_lowercase(tr_title.c_str());
|
||||
tr_lower = lower;
|
||||
track->tr_path = path;
|
||||
track->tr_title = taglib_tag_title(tag);
|
||||
lower = string_lowercase(track->tr_title.c_str());
|
||||
track->tr_lower = lower;
|
||||
|
||||
taglib_tag_free_strings();
|
||||
taglib_file_free(file);
|
||||
g_free(lower);
|
||||
out:
|
||||
g_free(path);
|
||||
return track;
|
||||
}
|
||||
|
||||
static void track_free(struct db_entry *dbe)
|
||||
|
@ -139,7 +142,7 @@ static void track_write(struct file *file, struct db_entry *dbe)
|
|||
|
||||
|
||||
static const struct db_ops track_ops = {
|
||||
NULL,
|
||||
track_alloc,
|
||||
track_free,
|
||||
track_key,
|
||||
track_read,
|
||||
|
@ -176,7 +179,7 @@ struct track *track_add(struct library *library, const std::string &filepath)
|
|||
struct track *track = NULL;
|
||||
|
||||
if (!db_get(&track_db, key))
|
||||
track = TRACK(db_insert(&track_db, new struct track(key)));
|
||||
track = TRACK(db_insert(&track_db, track_alloc(key)));
|
||||
|
||||
g_free(key);
|
||||
return track;
|
||||
|
|
|
@ -33,7 +33,6 @@ struct track : public db_entry {
|
|||
std::string tr_title; /* This track's title. */
|
||||
std::string tr_lower; /* This track's title (lowercased). */
|
||||
|
||||
track(const std::string &);
|
||||
track(); /**< Track constructor. */
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,12 @@ extern "C" {
|
|||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
static struct track *test_alloc(const gchar *key)
|
||||
{
|
||||
const struct db_ops *track_ops = test_track_ops();
|
||||
return TRACK(track_ops->dbe_alloc(key));
|
||||
}
|
||||
|
||||
static void test_verify_empty(struct track *track)
|
||||
{
|
||||
const struct db_ops *track_ops = test_track_ops();
|
||||
|
@ -96,7 +102,7 @@ static void test_track()
|
|||
date = string_tm2str(now);
|
||||
library = library_find("tests/Music");
|
||||
|
||||
track = new struct track("0/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
track = test_alloc("0/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
track->dbe_index = 0;
|
||||
track_ops->dbe_setup(track);
|
||||
test_verify_track(track);
|
||||
|
@ -157,8 +163,8 @@ static void test_track_filter()
|
|||
static void test_track_compare()
|
||||
{
|
||||
const struct db_ops *track_ops = test_track_ops();
|
||||
struct track *title = new struct track("0/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
struct track *kokiri = new struct track("0/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
||||
struct track *title = test_alloc("0/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
struct track *kokiri = test_alloc("0/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
||||
|
||||
test_equal(track_compare(title, title), 0);
|
||||
test_equal(track_compare(kokiri, title), -1);
|
||||
|
|
Loading…
Reference in New Issue