Commit fe1de73f authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Provide some initial dummy implementations

parent 5df35c12
project(medialibrary)
cmake_minimum_required(VERSION 2.8)
list(APPEND SRC_LIST
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
list(APPEND HEADERS_LIST
include/IAudioTrackInformation.h
include/ITrackInformation.h
include/IDescription.h
......@@ -10,6 +12,20 @@ list(APPEND SRC_LIST
include/IAlbum.h
include/IAlbumTrack.h
include/IFile.h
include/IMediaLibrary.h
)
include_directories("include")
list(APPEND SRC_LIST ${HEADERS_LIST}
src/MediaLibrary.cpp
src/SqliteTools.cpp
src/File.cpp
src/Album.cpp
src/Show.cpp
)
add_executable(${PROJECT_NAME} ${SRC_LIST})
find_package(Sqlite3 REQUIRED)
add_library(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIBRARIES})
......@@ -6,11 +6,18 @@
#include "IDescription.h"
class IAlbum : public IDescription
class ITrack;
class IAlbum
{
public:
virtual ~IAlbum() {}
virtual const std::string& name() = 0;
virtual unsigned int releaseYear() = 0;
virtual const std::string& shortSummary() = 0;
virtual const std::string& artworkUrl() = 0;
virtual const std::vector<ITrack*>& tracks() = 0;
virtual const std::string& tvdbId() = 0;
};
#endif // IALBUM_H
......@@ -16,11 +16,11 @@ class IFile
virtual ~IFile() {}
virtual IAlbumTrack* albumTrack() = 0;
virtual const std::string& artist() = 0;
virtual const std::string& artworkUrl() = 0;
virtual unsigned int duration() = 0;
virtual IShowEpisode* showEpisode() = 0;
virtual int playCount() = 0;
virtual std::vector<ITrackInformation*> tracks() = 0;
virtual std::vector<ILabel*> labels() = 0;
......
#ifndef IMEDIALIBRARY_H
#define IMEDIALIBRARY_H
#include <vector>
#include <string>
#include "IFile.h"
class IMediaLibrary
{
public:
virtual ~IMediaLibrary(){}
virtual bool initialize( const std::string& dbPath );
virtual const std::vector<IFile*>& files() = 0;
};
#endif // IMEDIALIBRARY_H
......@@ -4,14 +4,16 @@
#include <string>
#include "IDescription.h"
class IShow : public IDescription
class IShow
{
public:
virtual ~IShow() {}
virtual const std::string& name() = 0;
virtual unsigned int releaseYear() = 0;
virtual const std::string& shortSummary() = 0;
virtual const std::string& artworkUrl() = 0;
virtual time_t lastSyncDate() = 0;
virtual const std::string& tvdbId() = 0;
};
#endif // ISHOW_H
#include "Album.h"
#include "SqliteTools.h"
Album::Album(sqlite3* dbConnection, sqlite3_stmt* stmt)
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 1 );
m_name = (const char*)sqlite3_column_text( stmt, 2 );
m_releaseYear = sqlite3_column_int( stmt, 3 );
m_shortSummary = (const char*)sqlite3_column_text( stmt, 4 );
m_artworkUrl = (const char*)sqlite3_column_text( stmt, 5 );
m_lastSyncDate = sqlite3_column_int( stmt, 6 );
}
Album::Album(sqlite3* dbConnection)
{
}
const std::string& Album::name()
{
return m_name;
}
unsigned int Album::releaseYear()
{
return m_releaseYear;
}
const std::string& Album::shortSummary()
{
return m_shortSummary;
}
const std::string& Album::artworkUrl()
{
return m_artworkUrl;
}
time_t Album::lastSyncDate()
{
return m_lastSyncDate;
}
bool Album::CreateTable(sqlite3* dbConnection)
{
std::string req = "CREATE TABLE IF NOT EXISTS Album("
"id_album INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT, UNSIGNED INTEGER release_year, TEXT short_summary,"
"TEXT artwork_url, UNSIGNED INTEGER last_sync_date)";
return SqliteTools::CreateTable( dbConnection, req );
}
#ifndef ALBUM_H
#define ALBUM_H
#include <sqlite3.h>
#include "IAlbum.h"
class Album : public IAlbum
{
public:
Album( sqlite3* dbConnection, sqlite3_stmt* stmt );
Album( sqlite3* dbConnection );
virtual const std::string& name();
virtual unsigned int releaseYear();
virtual const std::string& shortSummary();
virtual const std::string& artworkUrl();
virtual time_t lastSyncDate();
static bool CreateTable( sqlite3* dbConnection );
protected:
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_name;
unsigned int m_releaseYear;
std::string m_shortSummary;
std::string m_artworkUrl;
time_t m_lastSyncDate;
};
#endif // ALBUM_H
#include "DBConnection.h"
DBConnection::DBConnection()
{
}
bool DBConnection::connect(const std::string& dbPath )
{
sqlite3* stmt;
int res = sqlite3_open( dbPath.c_str(), &stmt );
return res == SQLITE_OK;
}
#ifndef DBCONNECTION_H
#define DBCONNECTION_H
#include <sqlite3.h>
#include <string>
class DBConnection
{
public:
DBConnection();
bool connect( const std::string& dbPath );
};
#endif // DBCONNECTION_H
#include "File.h"
#include "SqliteTools.h"
File::File( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 0 );
m_type = (Type)sqlite3_column_int( stmt, 1 );
m_duration = sqlite3_column_int( stmt, 2 );
}
File::File(sqlite3* dbConnection)
: m_dbConnection( dbConnection )
, m_id( 0 )
{
}
bool File::insert()
{
sqlite3_stmt* stmt;
std::string req = "INSERT INTO File VALUES(NULL, ?, ?)";
if ( sqlite3_prepare_v2( m_dbConnection, req.c_str(), -1, &stmt, NULL ) != SQLITE_OK )
return false;
sqlite3_bind_int( stmt, 1, m_type );
sqlite3_bind_int( stmt, 2, m_duration );
if ( sqlite3_step( stmt ) != SQLITE_DONE )
return false;
m_id = sqlite3_last_insert_rowid( m_dbConnection );
return true;
}
IAlbumTrack*File::albumTrack()
{
}
const std::string&File::artworkUrl()
{
}
unsigned int File::duration()
{
return m_duration;
}
IShowEpisode*File::showEpisode()
{
}
std::vector<ILabel*> File::labels()
{
}
bool File::CreateTable(sqlite3* connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS File("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER, duration UNSIGNED INTEGER)";
return SqliteTools::CreateTable( connection, req );
}
#ifndef FILE_H
#define FILE_H
#include <sqlite3.h>
#include "IFile.h"
class File : public IFile
{
public:
enum Type
{
Video, // Any video file, not being a tv show episode
Audio, // Any kind of audio file, not being an album track
ShowEpisode,
AlbumTrack,
};
File(sqlite3* dbConnection , sqlite3_stmt* stmt);
File( sqlite3* dbConnection );
bool insert();
virtual IAlbumTrack* albumTrack();
virtual const std::string& artworkUrl();
virtual unsigned int duration();
virtual IShowEpisode* showEpisode();
virtual std::vector<ILabel*> labels();
static bool CreateTable( sqlite3* connection );
private:
sqlite3* m_dbConnection;
// DB fields:
unsigned int m_id;
Type m_type;
unsigned int m_duration;
};
#endif // FILE_H
#include "MediaLibrary.h"
MediaLibrary::MediaLibrary()
{
}
bool MediaLibrary::initialize(const std::string& dbPath)
{
int res = sqlite3_open( dbPath.c_str(), &m_dbConnection );
return res == SQLITE_OK;
}
const std::vector<IFile*>&MediaLibrary::files()
{
if ( m_files == NULL )
{
m_files = new std::vector<IFile*>();
// magic
}
return *m_files;
}
#ifndef MEDIALIBRARY_H
#define MEDIALIBRARY_H
#include <sqlite3.h>
#include "IMediaLibrary.h"
class MediaLibrary : public IMediaLibrary
{
public:
MediaLibrary();
virtual bool initialize( const std::string& dbPath );
virtual const std::vector<IFile*>& files();
private:
sqlite3* m_dbConnection;
std::vector<IFile*>* m_files;
};
#endif // MEDIALIBRARY_H
#include "Show.h"
#include "SqliteTools.h"
Show::Show(sqlite3* dbConnection, sqlite3_stmt* stmt)
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 1 );
m_name = (const char*)sqlite3_column_text( stmt, 2 );
m_releaseYear = sqlite3_column_int( stmt, 3 );
m_shortSummary = (const char*)sqlite3_column_text( stmt, 4 );
m_artworkUrl = (const char*)sqlite3_column_text( stmt, 5 );
m_lastSyncDate = sqlite3_column_int( stmt, 6 );
m_tvdbId = (const char*)sqlite3_column_text( stmt, 7 );
}
Show::Show(sqlite3* dbConnection)
: m_dbConnection( dbConnection )
, m_id( 0 )
{
}
const std::string& Show::name()
{
return m_name;
}
unsigned int Show::releaseYear()
{
return m_releaseYear;
}
const std::string& Show::shortSummary()
{
return m_shortSummary;
}
const std::string& Show::artworkUrl()
{
return m_artworkUrl;
}
time_t Show::lastSyncDate()
{
return m_lastSyncDate;
}
const std::string& Show::tvdbId()
{
return m_tvdbId;
}
bool Show::CreateTable(sqlite3* dbConnection)
{
std::string req = "CREATE TABLE IF NOT EXISTS Show("
"id_show INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT, UNSIGNED INTEGER release_year, TEXT short_summary,"
"TEXT artwork_url, UNSIGNED INTEGER last_sync_date, TEXT tvdb_id)";
return SqliteTools::CreateTable( dbConnection, req );
}
#ifndef SHOW_H
#define SHOW_H
#include <sqlite3.h>
#include "IShow.h"
class Show : public IShow
{
public:
Show( sqlite3* dbConnection, sqlite3_stmt* stmt );
Show( sqlite3* dbConnection );
virtual const std::string& name();
virtual unsigned int releaseYear();
virtual const std::string& shortSummary();
virtual const std::string& artworkUrl();
virtual time_t lastSyncDate();
virtual const std::string& tvdbId();
static bool CreateTable( sqlite3* dbConnection );
protected:
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_name;
unsigned int m_releaseYear;
std::string m_shortSummary;
std::string m_artworkUrl;
time_t m_lastSyncDate;
std::string m_tvdbId;
};
#endif // SHOW_H
#include <iostream>
#include "SqliteTools.h"
bool SqliteTools::CreateTable( sqlite3 *db, const std::string& request )
{
sqlite3_stmt* stmt;
int res = sqlite3_prepare_v2( db, request.c_str(), -1, &stmt, NULL );
if ( res != SQLITE_OK )
{
std::cerr << "Failed to execute request: " << request << std::endl;
return false;
}
res = sqlite3_step( stmt );
while ( res != SQLITE_DONE && res != SQLITE_ERROR )
res = sqlite3_step( stmt );
return res == SQLITE_DONE;
}
#ifndef SQLITETOOLS_H
#define SQLITETOOLS_H
#include <sqlite3.h>
#include <string>
class SqliteTools
{
public:
static bool CreateTable(sqlite3* db, const std::string& request );
};
#endif // SQLITETOOLS_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment