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

Playlist: Add a clearContent method

(cherry picked from commit cd512b75)
Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent d8726e1e
...@@ -350,6 +350,12 @@ void Playlist::clearExternalPlaylistContent(MediaLibraryPtr ml) ...@@ -350,6 +350,12 @@ void Playlist::clearExternalPlaylistContent(MediaLibraryPtr ml)
sqlite::Tools::executeDelete( ml->getConn(), req ); 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 ) void Playlist::insertMrlFromMediaId( MediaLibraryPtr ml )
{ {
sqlite::Statement stmt{ ml->getConn()->handle(), sqlite::Statement stmt{ ml->getConn()->handle(),
......
...@@ -79,6 +79,11 @@ public: ...@@ -79,6 +79,11 @@ public:
*/ */
static void clearExternalPlaylistContent( MediaLibraryPtr ml ); 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 * Fetches all PlaylistMediaRelation items without an MRL and assign it
*/ */
......
...@@ -425,3 +425,21 @@ TEST_F( Playlists, RemoveMedia ) ...@@ -425,3 +425,21 @@ TEST_F( Playlists, RemoveMedia )
ASSERT_EQ( 1u, media.size() ); ASSERT_EQ( 1u, media.size() );
ASSERT_EQ( m3->id(), media[0]->id() ); 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