2014-11-08 13:43:23 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-10-22 13:19:09 -04:00
|
|
|
extern "C" {
|
|
|
|
#include <core/string.h>
|
|
|
|
}
|
2014-11-08 13:43:23 -05:00
|
|
|
#include <core/tags/artist.h>
|
|
|
|
|
2014-11-16 10:08:12 -05:00
|
|
|
|
2015-10-22 11:28:45 -04:00
|
|
|
static database<struct artist> artist_db;
|
2014-11-16 10:08:12 -05:00
|
|
|
|
|
|
|
|
2015-10-22 13:19:09 -04:00
|
|
|
artist :: artist() {}
|
2014-11-08 13:43:23 -05:00
|
|
|
|
2015-10-22 11:28:45 -04:00
|
|
|
artist :: artist(const std::string &name)
|
2014-11-08 13:43:23 -05:00
|
|
|
{
|
2015-10-22 13:19:09 -04:00
|
|
|
gchar *lower = string_lowercase(name.c_str());
|
|
|
|
|
|
|
|
ar_name = name;
|
|
|
|
ar_lower = lower;
|
|
|
|
|
|
|
|
g_free(lower);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string artist :: primary_key() const
|
|
|
|
{
|
|
|
|
return ar_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void artist :: read(file &file)
|
|
|
|
{
|
|
|
|
gchar *name = file_readl(&file);
|
|
|
|
gchar *g_lc = string_lowercase(name);
|
|
|
|
|
|
|
|
ar_name = name;
|
|
|
|
ar_lower = g_lc;
|
|
|
|
|
|
|
|
g_free(name);
|
|
|
|
g_free(g_lc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void artist :: write(file &file)
|
|
|
|
{
|
|
|
|
file_writef(&file, "%s", ar_name.c_str());
|
2014-11-08 13:43:23 -05:00
|
|
|
}
|
2014-11-16 10:08:12 -05:00
|
|
|
|
|
|
|
|
2015-10-22 13:06:12 -04:00
|
|
|
void artist_db_init()
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-09-21 09:02:13 -04:00
|
|
|
db_init(&artist_db, "artist.db", true);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&artist_db);
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
|
|
|
|
2015-10-22 13:06:12 -04:00
|
|
|
void artist_db_deinit()
|
|
|
|
{
|
|
|
|
db_deinit(&artist_db);
|
|
|
|
}
|
|
|
|
|
2015-10-22 12:05:28 -04:00
|
|
|
struct artist *artist_find(const std::string &name)
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-10-20 10:10:26 -04:00
|
|
|
return db_find(&artist_db, name.c_str());
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
|
|
|
|
2015-10-22 12:01:25 -04:00
|
|
|
struct artist *artist_get(const unsigned int index)
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-10-20 08:19:47 -04:00
|
|
|
return db_at(&artist_db, index);
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
2015-10-22 13:19:09 -04:00
|
|
|
|
|
|
|
int artist_compare(struct artist *lhs, struct artist *rhs)
|
|
|
|
{
|
|
|
|
return string_compare(lhs->ar_lower.c_str(), rhs->ar_lower.c_str());
|
|
|
|
}
|