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

Add ShowEpisode

parent 0f6d92e0
......@@ -24,6 +24,7 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
src/Show.cpp
src/Label.cpp
src/AlbumTrack.cpp
src/ShowEpisode.cpp
)
find_package(Sqlite3 REQUIRED)
......
......@@ -16,7 +16,6 @@ class IFile
virtual ~IFile() {}
virtual IAlbumTrack* albumTrack() = 0;
virtual const std::string& artworkUrl() = 0;
virtual unsigned int duration() = 0;
virtual IShowEpisode* showEpisode() = 0;
virtual int playCount() = 0;
......
......@@ -3,6 +3,8 @@
class IShow;
#include <string>
class IShowEpisode
{
public:
......@@ -14,9 +16,7 @@ class IShowEpisode
virtual const std::string& name() = 0;
virtual unsigned int seasonNuber() = 0;
virtual const std::string& shortSummary() = 0;
virtual bool shouldBeDisplayed() = 0;
virtual const std::string& tvdbId() = 0;
virtual bool isUnread() = 0;
virtual IShow* show() = 0;
};
......
......@@ -54,7 +54,7 @@ bool Album::CreateTable(sqlite3* dbConnection)
"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 );
return SqliteTools::createTable( dbConnection, req );
}
Album* Album::fetch(sqlite3* dbConnection, unsigned int albumTrackId)
......
......@@ -23,7 +23,7 @@ bool AlbumTrack::createTable(sqlite3* dbConnection)
"album_id UNSIGNED INTEGER NOT NULL,"
"FOREIGN KEY (album_id) REFERENCES Album(id_album) ON DELETE CASCADE"
")";
return SqliteTools::CreateTable( dbConnection, req );
return SqliteTools::createTable( dbConnection, req );
}
AlbumTrack* AlbumTrack::fetch(sqlite3* dbConnection, unsigned int idTrack )
......
#include <cassert>
#include "Album.h"
#include "AlbumTrack.h"
#include "File.h"
#include "Label.h"
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "Album.h"
File::File( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
......@@ -17,6 +18,7 @@ File::File( sqlite3* dbConnection, sqlite3_stmt* stmt )
m_duration = sqlite3_column_int( stmt, 2 );
m_albumTrackId = sqlite3_column_int( stmt, 3 );
m_playCount = sqlite3_column_int( stmt, 4 );
m_showEpisodeId = sqlite3_column_int( stmt, 5 );
}
File::File()
......@@ -52,10 +54,6 @@ IAlbumTrack* File::albumTrack()
return m_albumTrack;
}
const std::string&File::artworkUrl()
{
}
unsigned int File::duration()
{
return m_duration;
......@@ -63,6 +61,12 @@ unsigned int File::duration()
IShowEpisode*File::showEpisode()
{
if ( m_showEpisode == NULL && m_showEpisodeId != 0 )
{
const char* req = "SELECT * FROM ShowEpisode WHERE id_episode = ?";
m_showEpisode = SqliteTools::fetchOne<ShowEpisode>( m_dbConnection, req, m_showEpisodeId );
}
return m_showEpisode;
}
std::vector<ILabel*> File::labels()
......@@ -79,7 +83,7 @@ std::vector<ILabel*> File::labels()
int File::playCount()
{
return m_playCount;
}
bool File::CreateTable(sqlite3* connection)
......@@ -88,6 +92,8 @@ bool File::CreateTable(sqlite3* connection)
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER, duration UNSIGNED INTEGER,"
"album_track_id UNSIGNED INTEGER,"
"play_count UNSIGNED INTEGER)";
return SqliteTools::CreateTable( connection, req );
"play_count UNSIGNED INTEGER"
"show_episode_id UNSIGNED INTEGER"
")";
return SqliteTools::createTable( connection, req );
}
......@@ -26,7 +26,6 @@ class File : public IFile
bool insert(sqlite3* dbConnection);
virtual IAlbumTrack* albumTrack();
virtual const std::string& artworkUrl();
virtual unsigned int duration();
virtual IShowEpisode* showEpisode();
virtual std::vector<ILabel*> labels();
......@@ -43,6 +42,7 @@ class File : public IFile
unsigned int m_duration;
unsigned int m_albumTrackId;
unsigned int m_playCount;
unsigned int m_showEpisodeId;
// Auto fetched related properties
Album* m_album;
......
......@@ -34,7 +34,7 @@ bool Label::createTable(sqlite3* dbConnection)
"id_label INTEGER PRIMARY KEY AUTO INCREMENT, "
"name TEXT"
")";
if ( SqliteTools::CreateTable( dbConnection, req ) )
if ( SqliteTools::createTable( dbConnection, req ) )
return false;
req = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
"id_label INTEGER,"
......@@ -42,5 +42,5 @@ bool Label::createTable(sqlite3* dbConnection)
"PRIMARY KEY (id_label, id_file)"
"FOREIGN KEY(id_label) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(id_file) REFERENCES File(id_file) ON DELETE CASCADE);";
return SqliteTools::CreateTable( dbConnection, req );
return SqliteTools::createTable( dbConnection, req );
}
......@@ -56,5 +56,5 @@ bool Show::CreateTable(sqlite3* dbConnection)
"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 );
return SqliteTools::createTable( dbConnection, req );
}
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "Show.h"
ShowEpisode::ShowEpisode( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 1 );
m_artworkUrl = (const char*)sqlite3_column_text( stmt, 2 );
m_episodeNumber = sqlite3_column_int( stmt, 3 );
m_lastSyncDate = sqlite3_column_int( stmt, 4 );
m_name = (const char*)sqlite3_column_text( stmt, 5 );
m_seasonNumber = sqlite3_column_int( stmt, 6 );
m_shortSummary = (const char*)sqlite3_column_text( stmt, 7 );
m_tvdbId = (const char*)sqlite3_column_text( stmt, 8 );
m_showId = sqlite3_column_int( stmt, 9 );
}
const std::string&ShowEpisode::artworkUrl()
{
return m_artworkUrl;
}
unsigned int ShowEpisode::episodeNumber()
{
return m_episodeNumber;
}
time_t ShowEpisode::lastSyncDate()
{
return m_lastSyncDate;
}
const std::string&ShowEpisode::name()
{
return m_name;
}
unsigned int ShowEpisode::seasonNuber()
{
return m_seasonNumber;
}
const std::string&ShowEpisode::shortSummary()
{
return m_shortSummary;
}
const std::string&ShowEpisode::tvdbId()
{
return m_tvdbId;
}
IShow* ShowEpisode::show()
{
if ( m_show == NULL && m_showId != 0 )
{
const char* req = "SELECT * FROM Show WHERE id_show = ?";
m_show = SqliteTools::fetchOne<Show>( m_dbConnection, req, m_showId );
}
return m_show;
}
bool ShowEpisode::createTable(sqlite3* dbConnection)
{
const char* req = "CREATE TABLE IF NOT EXISTS ("
"id_episode INTEGER PRIMARY KEY AUTO INCREMENT,"
"artwork_url TEXT,"
"episode_number UNSIGNED INT,"
"last_sync_date UNSIGNED INT,"
"name TEXT,"
"season_number UNSIGNED INT,"
"episode_summary TEXT,"
"tvdb_id TEXT,"
"show_id UNSIGNED INT,"
"FOREIGN KEY(show_id) REFERENCES Show(id_show)"
")";
SqliteTools::createTable( dbConnection, req );
}
#ifndef SHOWEPISODE_H
#define SHOWEPISODE_H
class Show;
#include <string>
#include <sqlite3.h>
#include "IShowEpisode.h"
class ShowEpisode : public IShowEpisode
{
public:
ShowEpisode(sqlite3* dbConnection, sqlite3_stmt* stmt);
virtual const std::string& artworkUrl();
virtual unsigned int episodeNumber();
virtual time_t lastSyncDate();
virtual const std::string& name();
virtual unsigned int seasonNuber();
virtual const std::string& shortSummary();
virtual const std::string& tvdbId();
virtual IShow*show();
static bool createTable( sqlite3* dbConnection );
private:
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_artworkUrl;
unsigned int m_episodeNumber;
time_t m_lastSyncDate;
std::string m_name;
unsigned int m_seasonNumber;
std::string m_shortSummary;
std::string m_tvdbId;
unsigned int m_showId;
Show* m_show;
};
#endif // SHOWEPISODE_H
......@@ -2,7 +2,7 @@
#include "SqliteTools.h"
bool SqliteTools::CreateTable( sqlite3 *db, const char* request )
bool SqliteTools::createTable( sqlite3 *db, const char* request )
{
sqlite3_stmt* stmt;
int res = sqlite3_prepare_v2( db, request, -1, &stmt, NULL );
......
......@@ -8,7 +8,7 @@
class SqliteTools
{
public:
static bool CreateTable(sqlite3* db, const char* request );
static bool createTable(sqlite3* db, const char* request );
template <typename T, typename U>
static bool fetchAll( sqlite3* dbConnection, const char* req, unsigned int foreignKey, std::vector<U*>*& results)
......
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