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

Media: Add favorite flag handling

parent 542ede0d
......@@ -76,6 +76,8 @@ class IMedia
///
virtual int rating() const = 0;
virtual void setRating( int rating ) = 0;
virtual bool isFavorite() const = 0;
virtual void setFavorite( bool favorite ) = 0;
virtual bool addLabel( LabelPtr label ) = 0;
virtual bool removeLabel( LabelPtr label ) = 0;
virtual MoviePtr movie() const = 0;
......
......@@ -61,7 +61,8 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row )
>> m_rating
>> m_insertionDate
>> m_thumbnail
>> m_title;
>> m_title
>> m_isFavorite;
}
Media::Media( const std::string& title, Type type )
......@@ -74,6 +75,7 @@ Media::Media( const std::string& title, Type type )
, m_rating( -1 )
, m_insertionDate( time( nullptr ) )
, m_title( title )
, m_isFavorite( false )
, m_changed( false )
{
}
......@@ -186,6 +188,19 @@ void Media::setRating( int rating )
m_changed = true;
}
bool Media::isFavorite() const
{
return m_isFavorite;
}
void Media::setFavorite( bool favorite )
{
if ( m_isFavorite == favorite )
return;
m_isFavorite = favorite;
m_changed = true;
}
const std::vector<FilePtr>& Media::files() const
{
auto lock = m_files.lock();
......@@ -266,11 +281,11 @@ bool Media::save()
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"type = ?, subtype = ?, duration = ?, play_count = ?, progress = ?, rating = ?,"
"thumbnail = ?, title = ? WHERE id_media = ?";
"thumbnail = ?, title = ?, is_favorite = ? WHERE id_media = ?";
if ( m_changed == false )
return true;
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_type, m_subType, m_duration, m_playCount,
m_progress, m_rating, m_thumbnail, m_title, m_id ) == false )
m_progress, m_rating, m_thumbnail, m_title, m_isFavorite, m_id ) == false )
{
return false;
}
......@@ -349,6 +364,7 @@ bool Media::createTable( DBConnection connection )
"insertion_date UNSIGNED INTEGER,"
"thumbnail TEXT,"
"title TEXT,"
"is_favorite BOOLEAN NOT NULL DEFAULT 0,"
"is_present BOOLEAN NOT NULL DEFAULT 1"
")";
static const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
......
......@@ -84,6 +84,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual void setProgress( float progress ) override;
virtual int rating() const override;
virtual void setRating( int rating ) override;
virtual bool isFavorite() const override;
virtual void setFavorite( bool favorite ) override;
virtual const std::vector<FilePtr>& files() const override;
virtual MoviePtr movie() const override;
void setMovie( MoviePtr movie );
......@@ -118,6 +120,7 @@ private:
unsigned int m_insertionDate;
std::string m_thumbnail;
std::string m_title;
bool m_isFavorite;
// Auto fetched related properties
mutable Cache<AlbumTrackPtr> m_albumTrack;
......
......@@ -261,3 +261,18 @@ TEST_F( Medias, SearchTracks )
tracks = ml->searchMedia( "rack" ).tracks;
ASSERT_EQ( 0u, tracks.size() );
}
TEST_F( Medias, Favorite )
{
auto m = ml->addFile( "media.mkv" );
ASSERT_FALSE( m->isFavorite() );
m->setFavorite( true );
m->save();
ASSERT_TRUE( m->isFavorite() );
Reload();
m = ml->media( m->id() );
ASSERT_TRUE( m->isFavorite() );
}
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