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

Playlist: Add a clearContent method

parent a3e98574
......@@ -350,6 +350,12 @@ void Playlist::clearExternalPlaylistContent(MediaLibraryPtr ml)
sqlite::Tools::executeDelete( ml->getConn(), req );
}
void Playlist::clearContent()
{
const std::string req = "DELETE FROM PlaylistMediaRelation WHERE playlist_id = ?";
sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id );
}
void Playlist::insertMrlFromMediaId( MediaLibraryPtr ml )
{
sqlite::Statement stmt{ ml->getConn()->handle(),
......
......@@ -79,6 +79,11 @@ public:
*/
static void clearExternalPlaylistContent( MediaLibraryPtr ml );
/**
* @brief clearContent Removes all media from this playlist.
*/
void clearContent();
/**
* Fetches all PlaylistMediaRelation items without an MRL and assign it
*/
......
......@@ -425,3 +425,21 @@ TEST_F( Playlists, RemoveMedia )
ASSERT_EQ( 1u, media.size() );
ASSERT_EQ( m3->id(), media[0]->id() );
}
TEST_F( Playlists, ClearContent )
{
auto m1 = ml->addMedia( "seaotter.mkv" );
auto m2 = ml->addMedia( "fluffyfurball.mp4" );
auto pl2 = ml->createPlaylist( "playlist 2" );
pl->append( *m1 );
pl2->append( *m2 );
ASSERT_EQ( 1u, pl->media()->count() );
ASSERT_EQ( 1u, pl2->media()->count() );
pl->clearContent();
ASSERT_EQ( 0u, pl->media()->count() );
ASSERT_EQ( 1u, pl2->media()->count() );
}
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