ocarina/core/tags/library.cpp

86 lines
1.4 KiB
C++
Raw Normal View History

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/tags/library.h>
static database<struct library> library_db;
library :: library()
: li_size(0), li_enabled(false)
{
}
library :: library(const std::string &path)
: li_size(0), li_enabled(true), li_path(path)
{
}
const std::string library :: primary_key() const
{
return li_path;
}
void library :: read(file &file)
{
int enabled;
gchar *path;
file_readf(&file, "%d\n", &enabled);
li_enabled = enabled;
path = file_readl(&file);
li_path = path;
g_free(path);
}
void library :: write(file &file)
{
file_writef(&file, "%d %s", li_enabled, li_path.c_str());
}
void library_db_init()
{
db_init(&library_db, "library.db", true);
db_load(&library_db);
}
void library_db_deinit()
{
db_deinit(&library_db);
}
const database<struct library> *library_db_get()
{
return &library_db;
}
struct library *library_find(const std::string &path)
{
return db_find(&library_db, path.c_str());
}
struct library *library_get(const unsigned int index)
{
return db_at(&library_db, index);
}
void library_remove(struct library *library)
{
if (library)
db_remove(&library_db, library);
}
void library_set_enabled(struct library *library, bool enabled)
{
library->li_enabled = enabled;
db_save(&library_db);
}
std::string library_file(struct library *library, const std::string &path)
{
return library->li_path + "/" + path;
}