2014-11-10 08:27:31 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/tags/library.h>
|
|
|
|
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
static database<struct library> library_db;
|
2014-11-17 08:30:54 -05:00
|
|
|
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
library :: library()
|
|
|
|
: li_size(0), li_enabled(false)
|
2014-11-10 08:27:31 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
library :: library(const std::string &path)
|
|
|
|
: li_size(0), li_enabled(true), li_path(path)
|
2014-11-10 08:27:31 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
const std::string library :: primary_key() const
|
2014-11-10 08:27:31 -05:00
|
|
|
{
|
2015-10-23 10:21:12 -04:00
|
|
|
return li_path;
|
2014-11-10 08:27:31 -05:00
|
|
|
}
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
void library :: read(file &file)
|
2014-11-10 08:27:31 -05:00
|
|
|
{
|
2015-10-08 11:16:38 -04:00
|
|
|
int enabled;
|
2015-10-09 13:09:47 -04:00
|
|
|
gchar *path;
|
2015-10-08 11:16:38 -04:00
|
|
|
|
|
|
|
file_readf(&file, "%d\n", &enabled);
|
2015-10-23 10:21:12 -04:00
|
|
|
li_enabled = enabled;
|
2015-10-09 13:09:47 -04:00
|
|
|
|
|
|
|
path = file_readl(&file);
|
2015-10-23 10:21:12 -04:00
|
|
|
li_path = path;
|
2015-10-09 13:09:47 -04:00
|
|
|
g_free(path);
|
2014-11-10 08:27:31 -05:00
|
|
|
}
|
|
|
|
|
2015-10-23 10:21:12 -04:00
|
|
|
void library :: write(file &file)
|
2014-11-10 08:27:31 -05:00
|
|
|
{
|
2015-10-23 10:21:12 -04:00
|
|
|
file_writef(&file, "%d %s", li_enabled, li_path.c_str());
|
2014-11-13 08:14:29 -05:00
|
|
|
}
|
|
|
|
|
2014-11-17 08:30:54 -05:00
|
|
|
|
2015-09-28 09:45:50 -04:00
|
|
|
void library_db_init()
|
2014-11-17 08:30:54 -05:00
|
|
|
{
|
2015-09-21 09:02:13 -04:00
|
|
|
db_init(&library_db, "library.db", true);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&library_db);
|
2014-11-17 08:30:54 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 09:45:50 -04:00
|
|
|
void library_db_deinit()
|
|
|
|
{
|
|
|
|
db_deinit(&library_db);
|
|
|
|
}
|
|
|
|
|
2015-10-23 13:32:20 -04:00
|
|
|
const database<struct library> *library_db_get()
|
|
|
|
{
|
|
|
|
return &library_db;
|
|
|
|
}
|
|
|
|
|
2015-09-28 10:00:06 -04:00
|
|
|
struct library *library_find(const std::string &path)
|
2014-11-17 08:30:54 -05:00
|
|
|
{
|
2015-10-20 10:10:26 -04:00
|
|
|
return db_find(&library_db, path.c_str());
|
2014-11-17 08:30:54 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 10:08:11 -04:00
|
|
|
struct library *library_get(const unsigned int index)
|
2014-11-17 08:30:54 -05:00
|
|
|
{
|
2015-10-20 08:19:47 -04:00
|
|
|
return db_at(&library_db, index);
|
2014-11-17 08:30:54 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 09:55:29 -04:00
|
|
|
void library_remove(struct library *library)
|
2014-11-17 08:30:54 -05:00
|
|
|
{
|
|
|
|
if (library)
|
2015-10-20 08:05:13 -04:00
|
|
|
db_remove(&library_db, library);
|
2014-11-17 08:30:54 -05:00
|
|
|
}
|
2015-10-23 14:19:42 -04:00
|
|
|
|
|
|
|
void library_set_enabled(struct library *library, bool enabled)
|
|
|
|
{
|
|
|
|
library->li_enabled = enabled;
|
|
|
|
db_save(&library_db);
|
|
|
|
}
|