2014-11-08 20:53:08 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-01-27 14:02:47 -05:00
|
|
|
#include <core/string.h>
|
2014-11-08 20:53:08 -05:00
|
|
|
#include <core/tags/album.h>
|
2015-09-01 08:58:34 -04:00
|
|
|
#include <glib.h>
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2014-11-16 14:47:51 -05:00
|
|
|
|
|
|
|
static Database<Album> album_db("album.db", true);
|
|
|
|
|
|
|
|
static const std::string make_key(const std::string &name, unsigned int year)
|
|
|
|
{
|
2015-09-01 08:58:34 -04:00
|
|
|
gchar *g_res = g_strdup_printf("%u/%s", year, name.c_str());
|
|
|
|
std :: string res = g_res;
|
|
|
|
|
|
|
|
g_free(g_res);
|
|
|
|
return res;
|
2014-11-16 14:47:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-08 20:53:08 -05:00
|
|
|
Album :: Album() : GenericTag(), _year(0) {}
|
|
|
|
|
|
|
|
Album :: Album(const std::string &name, unsigned int year)
|
|
|
|
: GenericTag(name), _year(year)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string Album :: primary_key() const
|
|
|
|
{
|
2014-11-16 14:47:51 -05:00
|
|
|
return make_key(GenericTag :: primary_key(), _year);
|
2014-11-08 20:53:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Album :: read(File &file)
|
|
|
|
{
|
|
|
|
file >> _year;
|
|
|
|
GenericTag :: read(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Album :: write(File &file)
|
|
|
|
{
|
|
|
|
file << _year << " ";
|
|
|
|
GenericTag :: write(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Album :: year()
|
|
|
|
{
|
|
|
|
return _year;
|
|
|
|
}
|
2014-11-16 14:47:51 -05:00
|
|
|
|
|
|
|
|
|
|
|
void tags :: init_album_db()
|
|
|
|
{
|
|
|
|
album_db.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
Album *tags :: get_album(const std::string &name, unsigned int year)
|
|
|
|
{
|
|
|
|
Album *ret = album_db.find(make_key(name, year));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return album_db.insert(Album(name, year));
|
|
|
|
}
|
|
|
|
|
|
|
|
Album *tags ::get_album(const unsigned int index)
|
|
|
|
{
|
|
|
|
return album_db.at(index);
|
|
|
|
}
|