Commit 73433d60 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Media: Add progress & rating

parent f879cc72
...@@ -55,6 +55,19 @@ class IMedia ...@@ -55,6 +55,19 @@ class IMedia
virtual int playCount() const = 0; virtual int playCount() const = 0;
virtual void increasePlayCount() = 0; virtual void increasePlayCount() = 0;
virtual const std::string& mrl() const = 0; virtual const std::string& mrl() const = 0;
///
/// \brief progress Returns the progress, in the [0;1] range
///
virtual float progress() const = 0;
virtual void setProgress( float progress ) = 0;
///
/// \brief rating The media rating, or -1 if unset.
/// It is up to the application to determine the values it wishes to use.
/// No value is enforced, and any positive value (less or equal to INT32_MAX)
/// will be accepted.
///
virtual int rating() const = 0;
virtual void setRating( int rating ) = 0;
virtual bool addLabel( LabelPtr label ) = 0; virtual bool addLabel( LabelPtr label ) = 0;
virtual bool removeLabel( LabelPtr label ) = 0; virtual bool removeLabel( LabelPtr label ) = 0;
virtual MoviePtr movie() = 0; virtual MoviePtr movie() = 0;
......
...@@ -52,6 +52,8 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row ) ...@@ -52,6 +52,8 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row )
>> m_type >> m_type
>> m_duration >> m_duration
>> m_playCount >> m_playCount
>> m_progress
>> m_rating
>> m_showEpisodeId >> m_showEpisodeId
>> m_mrl >> m_mrl
>> m_artist >> m_artist
...@@ -71,6 +73,8 @@ Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& t ...@@ -71,6 +73,8 @@ Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& t
, m_type( type ) , m_type( type )
, m_duration( -1 ) , m_duration( -1 )
, m_playCount( 0 ) , m_playCount( 0 )
, m_progress( .0f )
, m_rating( -1 )
, m_showEpisodeId( 0 ) , m_showEpisodeId( 0 )
, m_mrl( isRemovable == true ? file->name() : file->fullPath() ) , m_mrl( isRemovable == true ? file->name() : file->fullPath() )
, m_movieId( 0 ) , m_movieId( 0 )
...@@ -179,6 +183,32 @@ void Media::increasePlayCount() ...@@ -179,6 +183,32 @@ void Media::increasePlayCount()
m_changed = true; m_changed = true;
} }
float Media::progress() const
{
return m_progress;
}
void Media::setProgress( float progress )
{
if ( progress == m_progress || progress < 0 || progress > 1.0 )
return;
m_progress = progress;
m_changed = true;
}
int Media::rating() const
{
return m_rating;
}
void Media::setRating( int rating )
{
if ( m_rating == rating )
return;
m_rating = rating;
m_changed = true;
}
const std::string& Media::mrl() const const std::string& Media::mrl() const
{ {
if ( m_isRemovable == false ) if ( m_isRemovable == false )
...@@ -259,12 +289,13 @@ void Media::setSnapshot( const std::string& snapshot ) ...@@ -259,12 +289,13 @@ void Media::setSnapshot( const std::string& snapshot )
bool Media::save() bool Media::save()
{ {
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET " static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"type = ?, duration = ?, play_count = ?, show_episode_id = ?, artist = ?," "type = ?, duration = ?, play_count = ?, progress = ?, rating = ?, show_episode_id = ?,"
"movie_id = ?, last_modification_date = ?, snapshot = ?, parsed = ?, title = ? " "artist = ?, movie_id = ?, last_modification_date = ?, snapshot = ?, parsed = ?,"
"WHERE id_media = ?"; "title = ? WHERE id_media = ?";
if ( m_changed == false ) if ( m_changed == false )
return true; return true;
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_type, m_duration, m_playCount, if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_type, m_duration, m_playCount,
m_progress, m_rating,
sqlite::ForeignKey{ m_showEpisodeId }, m_artist, sqlite::ForeignKey{ m_showEpisodeId }, m_artist,
sqlite::ForeignKey{ m_movieId }, m_lastModificationDate, sqlite::ForeignKey{ m_movieId }, m_lastModificationDate,
m_snapshot, m_isParsed, m_title, m_id ) == false ) m_snapshot, m_isParsed, m_title, m_id ) == false )
...@@ -331,6 +362,8 @@ bool Media::createTable( DBConnection connection ) ...@@ -331,6 +362,8 @@ bool Media::createTable( DBConnection connection )
"type INTEGER," "type INTEGER,"
"duration INTEGER DEFAULT -1," "duration INTEGER DEFAULT -1,"
"play_count UNSIGNED INTEGER," "play_count UNSIGNED INTEGER,"
"progress REAL,"
"rating INTEGER DEFAULT -1,"
"show_episode_id UNSIGNED INTEGER," "show_episode_id UNSIGNED INTEGER,"
"mrl TEXT," "mrl TEXT,"
"artist TEXT," "artist TEXT,"
......
...@@ -77,6 +77,10 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable> ...@@ -77,6 +77,10 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual std::vector<LabelPtr> labels() override; virtual std::vector<LabelPtr> labels() override;
virtual int playCount() const override; virtual int playCount() const override;
virtual void increasePlayCount() override; virtual void increasePlayCount() override;
virtual float progress() const override;
virtual void setProgress( float progress ) override;
virtual int rating() const override;
virtual void setRating( int rating ) override;
virtual const std::string& mrl() const override; virtual const std::string& mrl() const override;
virtual MoviePtr movie() override; virtual MoviePtr movie() override;
void setMovie( MoviePtr movie ); void setMovie( MoviePtr movie );
...@@ -107,6 +111,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable> ...@@ -107,6 +111,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
Type m_type; Type m_type;
int64_t m_duration; int64_t m_duration;
unsigned int m_playCount; unsigned int m_playCount;
float m_progress;
int m_rating;
unsigned int m_showEpisodeId; unsigned int m_showEpisodeId;
std::string m_mrl; std::string m_mrl;
std::string m_artist; std::string m_artist;
......
...@@ -157,3 +157,34 @@ TEST_F( Medias, PlayCount ) ...@@ -157,3 +157,34 @@ TEST_F( Medias, PlayCount )
f = std::static_pointer_cast<Media>( ml->media( f->id() ) ); f = std::static_pointer_cast<Media>( ml->media( f->id() ) );
ASSERT_EQ( 1, f->playCount() ); ASSERT_EQ( 1, f->playCount() );
} }
TEST_F( Medias, Progress )
{
auto f = ml->addFile( "media.avi" );
ASSERT_EQ( .0f, f->progress() );
f->setProgress( 123.0f );
// Check that a non-sensical value is ignored
ASSERT_EQ( .0f, f->progress() );
f->setProgress( 0.666f );
ASSERT_EQ( .666f, f->progress() );
f->save();
Reload();
f = ml->media( f->id() );
ASSERT_EQ( .666f, f->progress() );
}
TEST_F( Medias, Rating )
{
auto f = ml->addFile( "media.avi" );
ASSERT_EQ( -1, f->rating() );
f->setRating( 12345 );
f->save();
ASSERT_EQ( 12345, f->rating() );
Reload();
f = ml->media( f->id() );
ASSERT_EQ( 12345, f->rating() );
}
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