library: Initial backend updates
I do not make any of the library spec changes yet, instead I update the backend code so it compiles and still works with the changes I have made so far. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
e484653d71
commit
8d8e9262d6
|
@ -22,13 +22,12 @@ namespace library
|
|||
};
|
||||
|
||||
|
||||
class Artist : public DatabaseEntry<const std::string> {
|
||||
class Artist : public DatabaseEntry {
|
||||
public:
|
||||
std :: string name;
|
||||
|
||||
Artist();
|
||||
Artist(TagLib :: Tag *);
|
||||
const std::string &primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
@ -37,16 +36,14 @@ namespace library
|
|||
};
|
||||
|
||||
|
||||
class Album : public DatabaseEntry<std::pair<std::string, unsigned int> >{
|
||||
class Album : public DatabaseEntry {
|
||||
public:
|
||||
std :: pair<std::string, unsigned int> key;
|
||||
std :: string name;
|
||||
unsigned int year;
|
||||
unsigned int artist_id;
|
||||
|
||||
Album();
|
||||
Album(TagLib :: Tag *, unsigned int);
|
||||
std::pair<std::string, unsigned int> &primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
@ -55,13 +52,12 @@ namespace library
|
|||
};
|
||||
|
||||
|
||||
class Genre : public DatabaseEntry<const std::string> {
|
||||
class Genre : public DatabaseEntry {
|
||||
public:
|
||||
std:: string name;
|
||||
|
||||
Genre();
|
||||
Genre(TagLib :: Tag *);
|
||||
const std::string &primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
@ -70,14 +66,13 @@ namespace library
|
|||
};
|
||||
|
||||
|
||||
class Library : public DatabaseEntry<const std::string> {
|
||||
class Library : public DatabaseEntry {
|
||||
public:
|
||||
std::string root_path;
|
||||
bool enabled;
|
||||
|
||||
Library();
|
||||
Library(const std::string &, bool);
|
||||
const std::string &primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
@ -86,7 +81,7 @@ namespace library
|
|||
};
|
||||
|
||||
|
||||
class Track : public DatabaseEntry<const std::string> {
|
||||
class Track : public DatabaseEntry {
|
||||
public:
|
||||
unsigned int library_id;
|
||||
unsigned int artist_id;
|
||||
|
@ -109,7 +104,6 @@ namespace library
|
|||
Track(TagLib :: Tag *, TagLib :: AudioProperties *,
|
||||
unsigned int, unsigned int, unsigned int,
|
||||
unsigned int, const std :: string &);
|
||||
const std::string &primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
#ifdef CONFIG_DEBUG
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <library.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <sstream>
|
||||
|
||||
static Database<library :: Artist, const std::string> artist_db("artist.db");
|
||||
static Database<library :: Album, std::pair<const std::string, unsigned int> > album_db("album.db");
|
||||
static Database<library :: Genre, const std::string> genre_db("genre.db");
|
||||
static Database<library :: Library, const std::string> library_db("library.db");
|
||||
static Database<library :: Track, const std::string> track_db("track.db");
|
||||
static Database<library :: Artist> artist_db("artist.db");
|
||||
static Database<library :: Album> album_db("album.db");
|
||||
static Database<library :: Genre> genre_db("genre.db");
|
||||
static Database<library :: Library> library_db("library.db");
|
||||
static Database<library :: Track> track_db("track.db");
|
||||
|
||||
|
||||
|
||||
|
@ -25,11 +27,7 @@ library :: Artist :: Artist()
|
|||
library :: Artist :: Artist(TagLib :: Tag *tag)
|
||||
: name(tag->artist().stripWhiteSpace().to8Bit(true))
|
||||
{
|
||||
}
|
||||
|
||||
const std::string &library :: Artist :: primary_key()
|
||||
{
|
||||
return name;
|
||||
primary_key = name;
|
||||
}
|
||||
|
||||
void library :: Artist :: read(File &f)
|
||||
|
@ -64,12 +62,9 @@ library :: Album :: Album(TagLib :: Tag *tag, unsigned int artist)
|
|||
: name(tag->album().stripWhiteSpace().to8Bit(true)),
|
||||
year(tag->year()), artist_id(artist)
|
||||
{
|
||||
key = make_pair(name, artist_id);
|
||||
}
|
||||
|
||||
std :: pair<std::string, unsigned int> &library :: Album :: primary_key()
|
||||
{
|
||||
return key;
|
||||
std::stringstream ss;
|
||||
ss << name << "." << year << "." << artist_id;
|
||||
primary_key = ss.str();
|
||||
}
|
||||
|
||||
void library :: Album :: read(File &f)
|
||||
|
@ -104,11 +99,7 @@ library :: Genre :: Genre()
|
|||
library :: Genre :: Genre(TagLib :: Tag *tag)
|
||||
: name(tag->genre().stripWhiteSpace().to8Bit(true))
|
||||
{
|
||||
}
|
||||
|
||||
const std::string &library :: Genre :: primary_key()
|
||||
{
|
||||
return name;
|
||||
primary_key = name;
|
||||
}
|
||||
|
||||
void library :: Genre :: read(File &f)
|
||||
|
@ -142,11 +133,7 @@ library :: Library :: Library()
|
|||
library :: Library :: Library(const std::string &path, bool is_enabled)
|
||||
: root_path(path), enabled(is_enabled)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string &library :: Library :: primary_key()
|
||||
{
|
||||
return root_path;
|
||||
primary_key = root_path;
|
||||
}
|
||||
|
||||
void library :: Library :: read(File &f)
|
||||
|
@ -190,14 +177,10 @@ library :: Track :: Track(TagLib :: Tag *tag, TagLib :: AudioProperties *audio,
|
|||
play_count(0), length(audio->length()), banned(false),
|
||||
title(tag->title().stripWhiteSpace().to8Bit(true))
|
||||
{
|
||||
primary_key = path;
|
||||
filepath = path.substr(library_db[library_id].root_path.size() + 1);
|
||||
}
|
||||
|
||||
const std::string &library :: Track :: primary_key()
|
||||
{
|
||||
return filepath;
|
||||
}
|
||||
|
||||
void library :: Track :: read(File &f)
|
||||
{
|
||||
f >> library_id >> artist_id >> album_id >> genre_id;
|
||||
|
|
Loading…
Reference in New Issue