Reworked the project layout

This commit is contained in:
emeric
2014-10-10 20:41:34 +02:00
parent 92a176c899
commit 49ff050539
146 changed files with 156 additions and 162 deletions
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AudioTypes.hpp"
namespace Database
{
Artist::Artist(const std::string& name)
: _name(std::string(name, 0 , _maxNameLength))
{
}
// Accesoors
Artist::pointer
Artist::getByName(Wt::Dbo::Session& session, const std::string& name)
{
return session.find<Artist>().where("name = ?").bind( std::string(name, 0, _maxNameLength) );
}
// Create
Artist::pointer
Artist::create(Wt::Dbo::Session& session, const std::string& name)
{
return session.add( new Artist( name ) );
}
Artist::pointer
Artist::getNone(Wt::Dbo::Session& session)
{
pointer res = getByName(session, "<None>");
if (!res)
res = create(session, "<None>");
return res;
}
Wt::Dbo::collection<Artist::pointer>
Artist::getAll(Wt::Dbo::Session& session, int offset, int size)
{
return session.find<Artist>().offset(offset).limit(size);
}
Wt::Dbo::collection<Artist::pointer>
Artist::getAllOrphans(Wt::Dbo::Session& session)
{
return session.query< Wt::Dbo::ptr<Artist> >("select a from artist a LEFT OUTER JOIN Track t ON a.id = t.artist_id WHERE t.id IS NULL");
}
} // namespace Database
+251
View File
@@ -0,0 +1,251 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIO_TYPES_HPP_
#define _AUDIO_TYPES_HPP_
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/WtSqlTraits>
#include <Wt/WDateTime>
namespace Database {
class Track;
class Release;
class Artist;
class Artist
{
public:
typedef Wt::Dbo::ptr<Artist> pointer;
typedef Wt::Dbo::dbo_traits<Artist>::IdType id_type;
Artist() {}
Artist(const std::string& p_name);
// Accessors
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
const std::string& getName(void) const { return _name; }
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks(void) const { return _tracks;}
// Create
static pointer create(Wt::Dbo::Session& session, const std::string& name);
bool isNone(void) const;
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToOne, "artist");
}
private:
static const std::size_t _maxNameLength = 128;
std::string _name;
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks; // Tracks of this artist
};
// Album release
class Release
{
public:
typedef Wt::Dbo::ptr<Release> pointer;
typedef Wt::Dbo::dbo_traits<Release>::IdType id_type;
Release() {}
Release(const std::string& name);
// Accessors
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getById(Wt::Dbo::Session& session, id_type id);
static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::vector<Artist::id_type> artistIds, int offset = -1, int size = -1);
// Create
static pointer create(Wt::Dbo::Session& session, const std::string& name);
std::string getName() const { return _name; }
bool isNone(void) const;
const Wt::Dbo::collection<Wt::Dbo::ptr<Track> >& getTracks(void) const { return _tracks;}
boost::posix_time::time_duration getDuration(void) const;
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToOne, "release");
}
private:
static const std::size_t _maxNameLength = 128;
std::string _name;
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks; // Tracks in the release
};
class Genre
{
public:
typedef Wt::Dbo::ptr<Genre> pointer;
typedef Wt::Dbo::dbo_traits<Genre>::IdType id_type;
Genre();
Genre(const std::string& name);
// Find utility
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset = -1, std::size_t size = -1);
// Create utility
static pointer create(Wt::Dbo::Session& session, const std::string& name);
// Accessors
const std::string& getName(void) const { return _name; }
bool isNone(void) const;
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks() const { return _tracks;}
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToMany, "track_genre", "", Wt::Dbo::OnDeleteCascade);
}
private:
static const std::size_t _maxNameLength = 128;
std::string _name;
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks;
};
class Track
{
public:
typedef Wt::Dbo::ptr<Track> pointer;
typedef Wt::Dbo::dbo_traits<Track>::IdType id_type;
Track() {}
Track(const boost::filesystem::path& p, Artist::pointer artist, Release::pointer release);
// Find utilities
static pointer getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
static pointer getById(Wt::Dbo::Session& session, id_type id);
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session,
const std::vector<Artist::id_type>& artistIds,
const std::vector<Release::id_type>& releaseIds,
const std::vector<Genre::id_type>& genreIds,
int offset = -1, int size = -1);
// Create utility
static pointer create(Wt::Dbo::Session& session, const boost::filesystem::path& p, Artist::pointer artist, Release::pointer release);
// Accessors
void setTrackNumber(int num) { _trackNumber = num; }
void setDiscNumber(int num) { _discNumber = num; }
void setName(const std::string& name) { _name = std::string(name, 0, _maxNameLength); }
void setDuration(boost::posix_time::time_duration duration) { _duration = duration; }
void setLastWriteTime(boost::posix_time::ptime time) { _fileLastWrite = time; }
void setChecksum(const std::vector<unsigned char>& checksum) { _fileChecksum = checksum; }
void setCreationTime(const boost::posix_time::ptime& time) { _creationTime = time; }
void setGenres(const std::string& genreList) { _genreList = genreList; }
void setGenres(std::vector<Genre::pointer> genres);
void setArtist(Artist::pointer artist) { _artist = artist; }
void setRelease(Release::pointer release) { _release = release; }
int getTrackNumber(void) const { return _trackNumber; }
int getDiscNumber(void) const { return _discNumber; }
std::string getName(void) const { return _name; }
const std::string& getPath(void) const { return _filePath; }
boost::posix_time::time_duration getDuration(void) const { return _duration; }
boost::posix_time::ptime getCreationTime(void) const { return _creationTime; }
Artist::pointer getArtist(void) const { return _artist; }
Release::pointer getRelease(void) const { return _release; }
bool hasGenre(Genre::pointer genre) const { return _genres.count(genre); }
std::vector< Genre::pointer > getGenres(void) const;
boost::posix_time::ptime getLastWriteTime(void) const { return _fileLastWrite; }
const std::vector<unsigned char>& getChecksum(void) const { return _fileChecksum; }
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _trackNumber, "track_number");
Wt::Dbo::field(a, _discNumber, "disc_number");
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::field(a, _duration, "duration");
Wt::Dbo::field(a, _creationTime, "creation_time");
Wt::Dbo::field(a, _genreList, "genre_list");
Wt::Dbo::field(a, _filePath, "path");
Wt::Dbo::field(a, _fileLastWrite, "last_write");
Wt::Dbo::field(a, _fileChecksum, "checksum");
Wt::Dbo::hasMany(a, _genres, Wt::Dbo::ManyToMany, "track_genre", "", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _release, "release", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _artist, "artist", Wt::Dbo::OnDeleteCascade);
}
private:
static const std::size_t _maxNameLength = 128;
int _trackNumber;
int _discNumber;
std::string _name;
boost::posix_time::time_duration _duration;
boost::posix_time::ptime _creationTime;
std::string _genreList;
std::string _filePath;
std::vector<unsigned char> _fileChecksum;
boost::posix_time::ptime _fileLastWrite;
Artist::pointer _artist; // Associated Artist
Release::pointer _release; // Associated Release
Wt::Dbo::collection< Genre::pointer > _genres; // Tracks in the release
};
} // namespace database
#endif
+154
View File
@@ -0,0 +1,154 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Wt/Auth/Dbo/AuthInfo>
#include <Wt/Auth/Dbo/UserDatabase>
#include <Wt/Auth/AuthService>
#include <Wt/Auth/HashFunction>
#include <Wt/Auth/PasswordService>
#include <Wt/Auth/PasswordStrengthValidator>
#include <Wt/Auth/PasswordVerifier>
#include "logger/Logger.hpp"
// Db types
#include "AudioTypes.hpp"
#include "VideoTypes.hpp"
#include "MediaDirectory.hpp"
#include "User.hpp"
#include "DatabaseHandler.hpp"
namespace Database {
namespace {
Wt::Auth::AuthService authService;
Wt::Auth::PasswordService passwordService(authService);
}
void
Handler::configureAuth(void)
{
authService.setEmailVerificationEnabled(true);
Wt::Auth::PasswordVerifier *verifier = new Wt::Auth::PasswordVerifier();
verifier->addHashFunction(new Wt::Auth::BCryptHashFunction(8));
passwordService.setVerifier(verifier);
passwordService.setAttemptThrottlingEnabled(true);
Wt::Auth::PasswordStrengthValidator* strengthValidator = new Wt::Auth::PasswordStrengthValidator();
// Reduce some constraints...
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::PassPhrase, 10);
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::OneCharClass, 8);
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::TwoCharClass, 7);
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::ThreeCharClass, 6 );
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthValidator::FourCharClass, 5 );
passwordService.setStrengthValidator(strengthValidator);
}
const Wt::Auth::AuthService&
Handler::getAuthService()
{
return authService;
}
const Wt::Auth::PasswordService&
Handler::getPasswordService()
{
return passwordService;
}
Handler::Handler(boost::filesystem::path db)
:
_dbBackend( db.string() )
{
_session.setConnection(_dbBackend);
_session.mapClass<Database::Genre>("genre");
_session.mapClass<Database::Track>("track");
_session.mapClass<Database::Artist>("artist");
_session.mapClass<Database::Release>("release");
_session.mapClass<Database::Release>("release");
_session.mapClass<Database::Video>("video");
_session.mapClass<Database::MediaDirectory>("media_directory");
_session.mapClass<Database::MediaDirectorySettings>("media_directory_settings");
_session.mapClass<Database::User>("user");
_session.mapClass<Database::AuthInfo>("auth_info");
_session.mapClass<Database::AuthInfo::AuthIdentityType>("auth_identity");
_session.mapClass<Database::AuthInfo::AuthTokenType>("auth_token");
try {
_session.createTables();
}
catch(std::exception& e) {
LMS_LOG(MOD_DB, SEV_ERROR) << "Cannot create tables: " << e.what();
}
_dbBackend.executeSql("pragma journal_mode=WAL");
_users = new UserDatabase(_session);
}
Handler::~Handler()
{
delete _users;
}
Wt::Auth::AbstractUserDatabase&
Handler::getUserDatabase()
{
return *_users;
}
User::pointer
Handler::getCurrentUser()
{
if (_login.loggedIn())
return getUser(_login.user());
else
return User::pointer();
}
User::pointer
Handler::getUser(const Wt::Auth::User& authUser)
{
if (!authUser.isValid()) {
LMS_LOG(MOD_DB, SEV_ERROR) << "Handler::getUser: invalid authUser";
return User::pointer();
}
Wt::Dbo::ptr<AuthInfo> authInfo = _users->find(authUser);
User::pointer user = authInfo->user();
if (!user) {
user = _session.add(new User());
authInfo.modify()->setUser(user);
}
return user;
}
} // namespace Database
+73
View File
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATABASE_HANDLER_HPP
#define DATABASE_HANDLER_HPP
#include <boost/filesystem.hpp>
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>
#include <Wt/Auth/Dbo/UserDatabase>
#include <Wt/Auth/Login>
#include <Wt/Auth/PasswordService>
#include "User.hpp"
namespace Database {
typedef Wt::Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
// Session living class handling the database and the login
class Handler
{
public:
Handler(boost::filesystem::path db);
~Handler();
Wt::Dbo::Session& getSession() { return _session; }
User::pointer getCurrentUser(); // get the current user, may return empty
User::pointer getUser(const Wt::Auth::User& authUser); // Get or create the given user
Wt::Auth::AbstractUserDatabase& getUserDatabase();
Wt::Auth::Login& getLogin() { return _login; }
// Long living shared associated services
static void configureAuth();
static const Wt::Auth::AuthService& getAuthService();
static const Wt::Auth::PasswordService& getPasswordService();
private:
Wt::Dbo::backend::Sqlite3 _dbBackend;
Wt::Dbo::Session _session;
UserDatabase* _users;
Wt::Auth::Login _login;
};
} // namespace Database
#endif
+68
View File
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AudioTypes.hpp"
namespace Database {
Genre::Genre()
{
}
Genre::Genre(const std::string& name)
: _name( std::string(name, 0, _maxNameLength) )
{
}
Genre::pointer
Genre::getByName(Wt::Dbo::Session& session, const std::string& name)
{
// TODO use like search
return session.find<Genre>().where("name = ?").bind( std::string(name, 0, _maxNameLength) );
}
Genre::pointer
Genre::getNone(Wt::Dbo::Session& session)
{
pointer res = getByName(session, "<None>");
if (!res)
res = create(session, "<None>");
return res;
}
bool
Genre::isNone(void) const
{
return (_name == "<None>");
}
Genre::pointer
Genre::create(Wt::Dbo::Session& session, const std::string& name)
{
return session.add(new Genre(name));
}
Wt::Dbo::collection<Genre::pointer>
Genre::getAll(Wt::Dbo::Session& session, std::size_t offset, std::size_t size)
{
return session.find<Genre>().offset(offset).limit(size);
}
} // namespace Database
+87
View File
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/foreach.hpp>
#include "MediaDirectory.hpp"
namespace Database {
MediaDirectorySettings::MediaDirectorySettings()
: _manualScanRequested(false),
_updatePeriod(Never)
{
}
MediaDirectory::MediaDirectory(boost::filesystem::path p, Type type)
: _type(type),
_path(p.string())
{
}
MediaDirectorySettings::pointer
MediaDirectorySettings::get(Wt::Dbo::Session& session)
{
MediaDirectorySettings::pointer res;
res = session.find<MediaDirectorySettings>().where("id = ?").bind(1);
// TODO bind necessary?
if (!res)
res = session.add( new MediaDirectorySettings());
return res;
}
MediaDirectory::pointer
MediaDirectory::create(Wt::Dbo::Session& session, boost::filesystem::path p, Type type)
{
return session.add( new MediaDirectory( p, type ) );
}
void
MediaDirectory::eraseAll(Wt::Dbo::Session& session)
{
std::vector<MediaDirectory::pointer> dirs = getAll(session);
BOOST_FOREACH(MediaDirectory::pointer dir, dirs)
dir.remove();
}
std::vector<MediaDirectory::pointer>
MediaDirectory::getAll(Wt::Dbo::Session& session)
{
Wt::Dbo::collection< MediaDirectory::pointer > res = session.find<MediaDirectory>();
return std::vector<MediaDirectory::pointer>(res.begin(), res.end());
}
std::vector<MediaDirectory::pointer>
MediaDirectory::getByType(Wt::Dbo::Session& session, Type type)
{
Wt::Dbo::collection< MediaDirectory::pointer > res = session.find<MediaDirectory>().where("type = ?").bind (type);
return std::vector<MediaDirectory::pointer>(res.begin(), res.end());
}
MediaDirectory::pointer
MediaDirectory::get(Wt::Dbo::Session& session, boost::filesystem::path p, Type type)
{
return session.find<MediaDirectory>().where("path = ?").where("type = ?").bind( p.string()).bind(type);
}
} // namespace Database
+133
View File
@@ -0,0 +1,133 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATABASE_MEDIA_DIRECTORY_HPP
#define DATABASE_MEDIA_DIRECTORY_HPP
#include <vector>
#include <boost/filesystem/path.hpp>
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/WtSqlTraits>
namespace Database {
class MediaDirectory;
class MediaDirectorySettings
{
public:
enum UpdatePeriod {
Never,
Daily,
Weekly,
Monthly
};
typedef Wt::Dbo::ptr<MediaDirectorySettings> pointer;
MediaDirectorySettings();
// accessors
static pointer get(Wt::Dbo::Session& session);
// write accessors
void setManualScanRequested(bool value) { _manualScanRequested = value;}
void setUpdatePeriod(UpdatePeriod period) { _updatePeriod = period;}
void setUpdateStartTime(boost::posix_time::time_duration dur) { _updateStartTime = dur;}
void setLastUpdate(boost::posix_time::ptime time) { _lastUpdate = time; }
void setLastScan(boost::posix_time::ptime time) { _lastScan = time; }
// Read accessors
bool getManualScanRequested(void) const { return _manualScanRequested; }
UpdatePeriod getUpdatePeriod(void) const { return _updatePeriod; }
boost::posix_time::time_duration getUpdateStartTime(void) const { return _updateStartTime; }
boost::posix_time::ptime getLastUpdated(void) const { return _lastUpdate; }
boost::posix_time::ptime getLastScan(void) const { return _lastScan; }
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _manualScanRequested, "manual_scan_requested");
Wt::Dbo::field(a, _updatePeriod, "update_period");
Wt::Dbo::field(a, _updateStartTime, "update_start_time");
Wt::Dbo::field(a, _lastUpdate, "last_update");
Wt::Dbo::field(a, _lastScan, "last_scan");
Wt::Dbo::hasMany(a, _mediaDirectories, Wt::Dbo::ManyToOne, "media_directory_settings");
}
private:
bool _manualScanRequested; // Immadiate scan has been requested by user
UpdatePeriod _updatePeriod; // How long between updates
boost::posix_time::time_duration _updateStartTime; // Time of day to begin the update
boost::posix_time::ptime _lastUpdate; // last time the database has changed
boost::posix_time::ptime _lastScan; // last time the database has been scanned
Wt::Dbo::collection< Wt::Dbo::ptr<MediaDirectory> > _mediaDirectories; // list of media directories
};
class MediaDirectory
{
public:
typedef Wt::Dbo::ptr<MediaDirectory> pointer;
enum Type {
Audio = 1,
Video = 2,
};
MediaDirectory() {}
MediaDirectory(boost::filesystem::path p, Type type);
// Accessors
static pointer create(Wt::Dbo::Session& session, boost::filesystem::path p, Type type);
static std::vector<MediaDirectory::pointer> getAll(Wt::Dbo::Session& session);
static std::vector<MediaDirectory::pointer> getByType(Wt::Dbo::Session& session, Type type);
static pointer get(Wt::Dbo::Session& session, boost::filesystem::path p, Type type);
static void eraseAll(Wt::Dbo::Session& session);
Type getType(void) const { return _type; }
boost::filesystem::path getPath(void) const { return boost::filesystem::path(_path); }
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _type, "type");
Wt::Dbo::field(a, _path, "path");
Wt::Dbo::belongsTo(a, _settings, "media_directory_settings", Wt::Dbo::OnDeleteCascade);
}
private:
Type _type;
std::string _path;
MediaDirectorySettings::pointer _settings; // back pointer
};
} // namespace Database
#endif
+103
View File
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/foreach.hpp>
#include "SqlQuery.hpp"
#include "AudioTypes.hpp"
namespace Database {
Release::Release(const std::string& name)
: _name(std::string(name, 0, _maxNameLength))
{
}
Release::pointer
Release::getByName(Wt::Dbo::Session& session, const std::string& name)
{
return session.find<Release>().where("name = ?").bind( std::string(name, 0, _maxNameLength) );
}
Release::pointer
Release::getById(Wt::Dbo::Session& session, id_type id)
{
return session.find<Release>().where("id = ?").bind(id);
}
Release::pointer
Release::getNone(Wt::Dbo::Session& session)
{
pointer res = getByName(session, "<None>");
if (!res)
res = create(session, "<None>");
return res;
}
Release::pointer
Release::create(Wt::Dbo::Session& session, const std::string& name)
{
return session.add(new Release(name));
}
Wt::Dbo::collection<Release::pointer>
Release::getAll(Wt::Dbo::Session& session, std::vector<Artist::id_type> artistIds, int offset, int size)
{
std::string sqlQuery = "SELECT r FROM release r";
if (!artistIds.empty())
{
sqlQuery += " INNER JOIN artist a ON a.id = t.artist_id";
sqlQuery += " INNER JOIN track t ON t.release_id = r.id";
}
Wt::Dbo::Query<Release::pointer> query = session.query<Release::pointer>( sqlQuery ).offset(offset).limit(size);
BOOST_FOREACH(const Artist::id_type artistId, artistIds)
query.where("a.id = ?").bind(artistId);
query.groupBy("r");
return query;
}
boost::posix_time::time_duration
Release::getDuration(void) const
{
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Track> > Tracks;
boost::posix_time::time_duration res;
for (Tracks::const_iterator it = _tracks.begin(); it != _tracks.end(); ++it)
res += (*it)->getDuration();
return res;
}
Wt::Dbo::collection<Release::pointer>
Release::getAllOrphans(Wt::Dbo::Session& session)
{
return session.query< Wt::Dbo::ptr<Release> >("select r from release r LEFT OUTER JOIN Track t ON r.id = t.release_id WHERE t.id IS NULL");
}
} // namespace Database
+200
View File
@@ -0,0 +1,200 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <boost/foreach.hpp>
#include <sstream>
#include <stdexcept>
#include "SqlQuery.hpp"
WhereClause&
WhereClause::And(const WhereClause& otherClause)
{
if (!otherClause._clause.empty()) {
if (!_clause.empty())
_clause += " AND ";
_clause += "(" + otherClause._clause + ")";
// Add associated bind args
BOOST_FOREACH(const std::string& otherBindArg, otherClause._bindArgs) {
_bindArgs.push_back(otherBindArg);
}
}
return *this;
}
WhereClause&
WhereClause::Or(const WhereClause& otherClause)
{
if (!otherClause._clause.empty()) {
if (!_clause.empty())
_clause += " OR ";
_clause += "(" + otherClause._clause + ")";
// Add associated bind args
BOOST_FOREACH(const std::string& otherBindArg, otherClause._bindArgs) {
_bindArgs.push_back(otherBindArg);
}
}
return *this;
}
std::string
WhereClause::get(void) const
{
if (!_clause.empty())
return "WHERE " + _clause;
else
return "";
}
WhereClause&
WhereClause::bind(const std::string& bindArg)
{
if (_bindArgs.size() >= static_cast<std::size_t>( std::count(_clause.begin(), _clause.end(), '?') ))
throw std::runtime_error("Too many bind args!");
_bindArgs.push_back(bindArg);
return *this;
}
InnerJoinClause::InnerJoinClause(const std::string& clause)
:_clause(clause)
{
}
InnerJoinClause&
InnerJoinClause::And(const InnerJoinClause& clause)
{
if (!_clause.empty())
_clause += " ";
_clause += clause._clause;
return *this;
}
SelectStatement::SelectStatement(const std::string& statement)
{
And(statement);
}
SelectStatement&
SelectStatement::And(const std::string& statement)
{
_statement.push_back(statement);
_statement.sort();
_statement.unique();
return *this;
}
std::string
SelectStatement::get() const
{
std::string res = "SELECT ";
for (std::list<std::string>::const_iterator it = _statement.begin(); it != _statement.end(); ++it)
{
if (it != _statement.begin())
res += ",";
res += *it;
}
return res;
}
GroupByStatement&
GroupByStatement::And(const GroupByStatement& statement)
{
if( _statement.empty() && !statement._statement.empty())
_statement = "GROUP BY ";
else if (!_statement.empty() && !statement._statement.empty())
_statement += ",";
_statement += statement._statement;
return *this;
}
FromClause::FromClause(const std::string& clause)
{
_clause.push_back(clause);
}
FromClause&
FromClause::And(const FromClause& clause)
{
BOOST_FOREACH(const std::string fromClause, clause._clause) {
_clause.push_back(fromClause);
}
_clause.sort();
_clause.unique();
return *this;
}
std::string
FromClause::get() const
{
std::ostringstream oss;
if (!_clause.empty())
{
oss << "FROM ";
for (std::list<std::string>::const_iterator it = _clause.begin(); it != _clause.end(); ++it) {
if (it != _clause.begin())
oss << ",";
oss << *it;
}
}
return oss.str();
}
std::string
SqlQuery::get(void) const
{
std::ostringstream oss;
oss << _selectStatement.get();
if (!_fromClause.get().empty())
oss << " " << _fromClause.get();
if (!_innerJoinClause.get().empty())
oss << " " << _innerJoinClause.get();
if (!_whereClause.get().empty())
oss << " " << _whereClause.get();
if (!_groupByStatement.get().empty())
oss << " " << _groupByStatement.get();
return oss.str();
}
+138
View File
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SQL_QUERY_HPP___
#define SQL_QUERY_HPP___
#include <list>
#include <string>
class WhereClause
{
public:
WhereClause() {}
WhereClause(const std::string& clause) { _clause = clause; }
WhereClause& And(const WhereClause& clause);
WhereClause& Or(const WhereClause& clause);
// Arguments binding (for each '?' in where clause)
WhereClause& bind(const std::string& arg);
std::string get() const;
const std::list<std::string>& getBindArgs(void) const {return _bindArgs;}
private:
std::string _clause; // WHERE clause
std::list<std::string> _bindArgs;
};
class InnerJoinClause
{
public:
InnerJoinClause() {}
InnerJoinClause(const std::string& clause);
InnerJoinClause& And(const InnerJoinClause& clause);
std::string get() const { return _clause;}
private:
std::string _clause;
};
class GroupByStatement
{
public:
GroupByStatement() {}
GroupByStatement(const std::string& statement) { _statement = statement; }
GroupByStatement& And(const GroupByStatement& statement);
std::string get() const {return _statement;}
private:
std::string _statement; // SELECT statement
};
class SelectStatement
{
public:
SelectStatement() {};
SelectStatement(const std::string& item);
SelectStatement& And(const std::string& item);
std::string get() const;
private:
std::list<std::string> _statement;
};
class FromClause
{
public:
FromClause() {}
FromClause(const std::string& clause);
FromClause& And(const FromClause& clause);
std::string get() const;
private:
std::list<std::string> _clause;
};
class SqlQuery
{
public:
SelectStatement& select(void) { return _selectStatement;}
SelectStatement& select(const std::string& statement) { _selectStatement = SelectStatement(statement); return _selectStatement; }
FromClause& from(void) { return _fromClause; }
FromClause& from(const std::string& clause) { _whereClause = WhereClause(clause); return _fromClause; }
InnerJoinClause& innerJoin(void) { return _innerJoinClause; }
WhereClause& where(void) { return _whereClause; }
const WhereClause& where(void) const { return _whereClause; }
GroupByStatement& groupBy(void) { return _groupByStatement; }
const GroupByStatement& groupBy(void) const { return _groupByStatement; }
std::string get(void) const;
private:
SelectStatement _selectStatement; // SELECT statement
InnerJoinClause _innerJoinClause; // INNER JOIN
FromClause _fromClause; // FROM tables
WhereClause _whereClause; // WHERE clause
GroupByStatement _groupByStatement; // GROUP BY statement
};
#endif
+153
View File
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/foreach.hpp>
#include "SqlQuery.hpp"
#include "AudioTypes.hpp"
namespace Database {
Track::Track(const boost::filesystem::path& p, Artist::pointer artist, Release::pointer release)
:
_trackNumber(0),
_discNumber(0),
_filePath( p.string() ),
_artist(artist),
_release(release)
{
}
void
Track::setGenres(std::vector<Genre::pointer> genres)
{
if (_genres.size())
_genres.clear();
BOOST_FOREACH(Genre::pointer genre, genres) {
_genres.insert( genre );
}
}
Track::pointer
Track::getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p)
{
return session.find<Track>().where("path = ?").bind(p.string());
}
Track::pointer
Track::getById(Wt::Dbo::Session& session, id_type id)
{
return session.find<Track>().where("id = ?").bind(id);
}
Track::pointer
Track::create(Wt::Dbo::Session& session, const boost::filesystem::path& p, Artist::pointer artist, Release::pointer release)
{
return session.add(new Track(p, artist, release) );
}
Wt::Dbo::collection< Track::pointer >
Track::getAll(Wt::Dbo::Session& session)
{
return session.find<Track>();
}
std::vector< Genre::pointer >
Track::getGenres(void) const
{
std::vector< Genre::pointer > genres;
std::copy(_genres.begin(), _genres.end(), std::back_inserter(genres));
return genres;
}
Wt::Dbo::collection< Track::pointer >
Track::getAll(Wt::Dbo::Session& session,
const std::vector<Artist::id_type>& artistIds,
const std::vector<Release::id_type>& releaseIds,
const std::vector<Genre::id_type>& genreIds,
int offset, int size)
{
std::string sqlQuery = "SELECT t FROM track t";
if (!artistIds.empty())
sqlQuery += " INNER JOIN artist a ON a.id = t.artist_id";
if (!releaseIds.empty())
sqlQuery += " INNER JOIN release r ON r.id = t.release_id";
if (!genreIds.empty())
{
sqlQuery += " INNER JOIN genre g ON g.id = t_g.genre_id";
sqlQuery += " INNER JOIN track_genre t_g ON t_g.track_id = t.id AND t_d.genre_id = g.id";
}
WhereClause where;
{
WhereClause artistWhere;
for (std::size_t i = 0; i < artistIds.size(); ++i)
artistWhere.Or( WhereClause("a.id = ?") );
where.And(artistWhere);
}
{
WhereClause releaseWhere;
for (std::size_t i = 0; i < releaseIds.size(); ++i)
releaseWhere.Or( WhereClause("r.id = ?") );
where.And(releaseWhere);
}
{
WhereClause genreWhere;
for (std::size_t i = 0; i < genreIds.size(); ++i)
genreWhere.Or( WhereClause("g.id = ?") );
where.And(genreWhere);
}
Wt::Dbo::Query<Track::pointer> query = session.query<Track::pointer>( sqlQuery + " " + where.get() ).offset(offset).limit(size);
BOOST_FOREACH(const Artist::id_type artistId, artistIds)
query.bind(artistId);
BOOST_FOREACH(const Release::id_type releaseId, releaseIds)
query.bind(releaseId);
BOOST_FOREACH(const Genre::id_type genreId, genreIds)
query.bind(genreId);
query.groupBy("t");
return query;
}
} // namespace Database
+146
View File
@@ -0,0 +1,146 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "User.hpp"
namespace Database {
// must be ordered
const std::vector<std::size_t>
User::audioBitrates =
{
64000,
96000,
128000,
160000,
192000,
224000,
256000,
320000,
512000
};
const std::vector<std::size_t>
User::videoBitrates =
{
256000,
512000,
1024000,
2048000,
4096000,
8192000
};
User::User()
: _maxAudioBitrate(maxAudioBitrate),
_maxVideoBitrate(maxVideoBitrate),
_isAdmin(false),
_audioBitrate(defaultAudioBitrate),
_videoBitrate(defaultVideoBitrate)
{
}
std::vector<User::pointer>
User::getAll(Wt::Dbo::Session& session)
{
Wt::Dbo::collection<pointer> res = session.find<User>();
return std::vector<pointer>(res.begin(), res.end());
}
User::pointer
User::getById(Wt::Dbo::Session& session, std::string id)
{
return session.find<User>().where("id = ?").bind( id );
}
std::string
User::getId( pointer user)
{
std::ostringstream oss; oss << user.id();
return oss.str();
}
void
User::setAudioBitrate(std::size_t bitrate)
{
_audioBitrate = std::min(bitrate, std::min(static_cast<std::size_t>(_maxAudioBitrate), audioBitrates.back()));
}
void
User::setVideoBitrate(std::size_t bitrate)
{
_videoBitrate = std::min(bitrate, std::min(static_cast<std::size_t>(_maxVideoBitrate), videoBitrates.back()));
}
void
User::setMaxAudioBitrate(std::size_t bitrate)
{
_maxAudioBitrate = std::min(bitrate, static_cast<std::size_t>(_maxAudioBitrate));
}
void
User::setMaxVideoBitrate(std::size_t bitrate)
{
_maxVideoBitrate = std::min(bitrate, static_cast<std::size_t>(_maxVideoBitrate));
}
std::size_t
User::getAudioBitrate(void) const
{
if (!isAdmin())
return std::min(static_cast<std::size_t>(_audioBitrate), std::min(static_cast<std::size_t>(_maxAudioBitrate), audioBitrates.back()));
else
return std::min(static_cast<std::size_t>(_audioBitrate), audioBitrates.back());
}
std::size_t
User::getVideoBitrate(void) const
{
if (!isAdmin())
return std::min(static_cast<std::size_t>(_videoBitrate), std::min(static_cast<std::size_t>(_maxVideoBitrate), videoBitrates.back()));
else
return std::min(static_cast<std::size_t>(_videoBitrate), videoBitrates.back());
}
std::size_t
User::getMaxAudioBitrate(void) const
{
if (!isAdmin())
return std::min(static_cast<std::size_t>(_maxAudioBitrate), audioBitrates.back());
else
return audioBitrates.back();
}
std::size_t
User::getMaxVideoBitrate(void) const
{
if (!isAdmin())
return std::min(static_cast<std::size_t>(_maxVideoBitrate), videoBitrates.back());
else
return videoBitrates.back();
}
} // namespace Database
+94
View File
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATABASE_USER_HPP
#define DATABASE_USER_HPP
#include <Wt/Auth/Dbo/AuthInfo>
namespace Database {
class User;
typedef Wt::Auth::Dbo::AuthInfo<User> AuthInfo;
class User {
public:
static const std::size_t MaxNameLength = 15;
// list of commonly used bitrates
static const std::vector<std::size_t> audioBitrates;
static const std::vector<std::size_t> videoBitrates;
User();
typedef Wt::Dbo::ptr<User> pointer;
// accessors
static pointer getById(Wt::Dbo::Session& session, std::string id);
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
static std::string getId(pointer user);
// write
void setAdmin(bool admin) { _isAdmin = admin; }
void setAudioBitrate(std::size_t bitrate);
void setVideoBitrate(std::size_t bitrate);
void setMaxAudioBitrate(std::size_t bitrate);
void setMaxVideoBitrate(std::size_t bitrate);
// read
bool isAdmin() const {return _isAdmin;}
std::size_t getAudioBitrate() const;
std::size_t getVideoBitrate() const;
std::size_t getMaxAudioBitrate() const;
std::size_t getMaxVideoBitrate() const;
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _maxAudioBitrate, "max_audio_bitrate");
Wt::Dbo::field(a, _maxVideoBitrate, "max_video_bitrate");
Wt::Dbo::field(a, _isAdmin, "admin");
Wt::Dbo::field(a, _audioBitrate, "audio_bitrate");
Wt::Dbo::field(a, _videoBitrate, "video_bitrate");
}
private:
static const std::size_t maxAudioBitrate = 320000;
static const std::size_t maxVideoBitrate = 2048000;
static const std::size_t defaultAudioBitrate = 128000;
static const std::size_t defaultVideoBitrate = 1024000;
// Admin defined settings
int _maxAudioBitrate;
int _maxVideoBitrate;
bool _isAdmin;
// User defined settings
int _audioBitrate;
int _videoBitrate;
};
} // namespace Databas'
#endif
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "VideoTypes.hpp"
namespace Database {
Video::Video()
{
}
Video::Video(const boost::filesystem::path& p)
: _filePath(p.string())
{
}
Video::pointer
Video::create(Wt::Dbo::Session& session, const boost::filesystem::path& p)
{
return session.add(new Video(p));
}
Wt::Dbo::collection< Video::pointer >
Video::getAll(Wt::Dbo::Session& session)
{
return session.find<Video>();
}
Video::pointer
Video::getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p)
{
return session.find<Video>().where("path = ?").bind(p.string());
}
} // namespace Video
+84
View File
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _VIDEO_TYPES_HPP
#define _VIDEO_TYPES_HPP
#include <string>
#include <boost/filesystem.hpp>
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/WtSqlTraits>
#include <Wt/WDateTime>
namespace Database {
class Video
{
public:
typedef Wt::Dbo::ptr<Video> pointer;
Video();
Video( const boost::filesystem::path& p);
// Find utilities
static pointer getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
static Wt::Dbo::collection< pointer > getByParentPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
// Create utility
static pointer create(Wt::Dbo::Session& session, const boost::filesystem::path& p);
// Modifiers
void setName(const std::string& name) { _name = name; }
void setDuration(boost::posix_time::time_duration duration) { _duration = duration; }
void setLastWriteTime(boost::posix_time::ptime time) { _fileLastWrite = time; }
// Accessors
std::string getName(void) const { return _name; }
boost::posix_time::time_duration getDuration(void) const { return _duration; }
boost::filesystem::path getPath(void) const { return _filePath; }
boost::posix_time::ptime getLastWriteTime(void) const { return _fileLastWrite; }
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::field(a, _duration, "duration");
Wt::Dbo::field(a, _fileLastWrite, "last_write");
Wt::Dbo::field(a, _filePath, "path");
}
private:
std::string _name;
boost::posix_time::time_duration _duration;
std::string _filePath;
boost::posix_time::ptime _fileLastWrite;
}; // Video
} // namespace Database
#endif