2013-10-27 17:25:26 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <library.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
|
|
|
static Database<library :: Library> library_db("library.db", DB_NORMAL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* library :: Library: Basic information about each directory in the library
|
|
|
|
*/
|
|
|
|
|
2013-11-03 16:03:01 -05:00
|
|
|
library :: Library :: Library()
|
|
|
|
: root_path(""), enabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-27 17:25:26 -04:00
|
|
|
library :: Library :: Library(const std::string &path, bool is_enabled)
|
|
|
|
: root_path(path), enabled(is_enabled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void library :: Library :: read(File &f)
|
|
|
|
{
|
2013-11-03 16:03:01 -05:00
|
|
|
f >> enabled;
|
|
|
|
root_path = f.getline();
|
2013-10-27 17:25:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void library :: Library :: write(File &f)
|
|
|
|
{
|
2013-11-03 16:03:01 -05:00
|
|
|
f << enabled << " " << root_path;
|
2013-10-27 17:25:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
void library :: Library :: print()
|
|
|
|
{
|
|
|
|
:: print("%s", root_path.c_str());
|
|
|
|
if (enabled == true)
|
|
|
|
:: print(" (enabled)");
|
|
|
|
else
|
|
|
|
:: print(" (disabled)");
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG */
|
|
|
|
|
|
|
|
bool library :: Library :: operator==(library :: Library &rhs)
|
|
|
|
{
|
|
|
|
return root_path == rhs.root_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* API used by the GUI begins here
|
|
|
|
*/
|
|
|
|
|
2013-11-03 16:03:01 -05:00
|
|
|
void library :: init()
|
|
|
|
{
|
|
|
|
library_db.load();
|
|
|
|
}
|
|
|
|
|
2013-10-27 17:25:26 -04:00
|
|
|
bool library :: add_path(const std::string &dir)
|
|
|
|
{
|
|
|
|
if (g_file_test(dir.c_str(), G_FILE_TEST_IS_DIR) == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
library_db.insert(library :: Library(dir, true));
|
2013-11-03 16:03:01 -05:00
|
|
|
library_db.save();
|
2013-10-27 17:25:26 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void library :: del_path(unsigned int id)
|
|
|
|
{
|
|
|
|
library_db.remove(id);
|
2013-11-03 16:03:01 -05:00
|
|
|
library_db.save();
|
2013-10-27 17:25:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
void library :: print_db(DB_Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case DB_LIBRARY:
|
|
|
|
library_db.print();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void library :: reset()
|
|
|
|
{
|
|
|
|
library_db.clear();
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG */
|