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

IMediaLibrary: Add playlist modification callbacks

For now, only the deletion callback is plugged, and add/modify callback
will come later.
This completes #5
parent 537da739
......@@ -102,6 +102,10 @@ public:
// Tracks are never modified after their creation, so there is no tracksModified event
virtual void onTracksDeleted( std::vector<int64_t> trackIds ) = 0;
virtual void onPlaylistsAdded( std::vector<PlaylistPtr> playlists ) = 0;
virtual void onPlaylistsModified( std::vector<PlaylistPtr> playlists ) = 0;
virtual void onPlaylistsDeleted( std::vector<int64_t> playlistIds ) = 0;
/**
* @brief onDiscoveryStarted This callback will be invoked when a folder queued for discovery
* (by calling IMediaLibrary::discover()) gets processed.
......
......@@ -191,6 +191,13 @@ void MediaLibrary::registerEntityHooks()
AlbumTrack::removeFromCache( rowId );
m_modificationNotifier->notifyAlbumTrackRemoval( rowId );
});
m_dbConnection->registerUpdateHook( policy::PlaylistTable::Name,
[this]( SqliteConnection::HookReason reason, int64_t rowId ) {
if ( reason != SqliteConnection::HookReason::Delete )
return;
Playlist::removeFromCache( rowId );
m_modificationNotifier->notifyPlaylistRemoval( rowId );
});
}
......
......@@ -115,6 +115,21 @@ void ModificationNotifier::notifyAlbumTrackRemoval( int64_t trackId )
notifyRemoval( trackId, m_tracks );
}
void ModificationNotifier::notifyPlaylistCreation( PlaylistPtr playlist )
{
notifyCreation( std::move( playlist ), m_playlists );
}
void ModificationNotifier::notifyPlaylistModification( PlaylistPtr playlist )
{
notifyModification( std::move( playlist ), m_playlists );
}
void ModificationNotifier::notifyPlaylistRemoval( int64_t playlistId )
{
notifyRemoval( playlistId, m_playlists );
}
void ModificationNotifier::run()
{
#if !defined(_LIBCPP_STD_VER) || (_LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR))
......@@ -130,6 +145,7 @@ void ModificationNotifier::run()
Queue<IArtist> artists;
Queue<IAlbum> albums;
Queue<IAlbumTrack> tracks;
Queue<IPlaylist> playlists;
while ( m_stop == false )
{
......@@ -146,6 +162,7 @@ void ModificationNotifier::run()
checkQueue( m_artists, artists, nextTimeout, now );
checkQueue( m_albums, albums, nextTimeout, now );
checkQueue( m_tracks, tracks, nextTimeout, now );
checkQueue( m_playlists, playlists, nextTimeout, now );
m_timeout = nextTimeout;
}
notify( std::move( media ), &IMediaLibraryCb::onMediaAdded, &IMediaLibraryCb::onMediaUpdated, &IMediaLibraryCb::onMediaDeleted );
......@@ -154,6 +171,7 @@ void ModificationNotifier::run()
// We pass the onTrackAdded callback twice, to avoid having to do some nifty templates specialization
// for nullptr callbacks. There is no onTracksModified callback, as tracks are never modified.
notify( std::move( tracks ), &IMediaLibraryCb::onTracksAdded, &IMediaLibraryCb::onTracksAdded, &IMediaLibraryCb::onTracksDeleted );
notify( std::move( playlists ), &IMediaLibraryCb::onPlaylistsAdded, &IMediaLibraryCb::onPlaylistsAdded, &IMediaLibraryCb::onPlaylistsDeleted );
}
}
......
......@@ -59,6 +59,10 @@ public:
void notifyAlbumTrackModification( AlbumTrackPtr track );
void notifyAlbumTrackRemoval( int64_t trackId );
void notifyPlaylistCreation( PlaylistPtr track );
void notifyPlaylistModification( PlaylistPtr track );
void notifyPlaylistRemoval( int64_t trackId );
private:
void run();
void notify();
......@@ -151,6 +155,7 @@ private:
Queue<IArtist> m_artists;
Queue<IAlbum> m_albums;
Queue<IAlbumTrack> m_tracks;
Queue<IPlaylist> m_playlists;
// Notifier thread
compat::Mutex m_lock;
......
......@@ -46,6 +46,9 @@ class NoopCallback : public IMediaLibraryCb
virtual void onTracksAdded( std::vector<AlbumTrackPtr> ) override {}
virtual void onTracksDeleted( std::vector<int64_t> ) override {}
virtual void onParsingStatsUpdated( uint32_t ) override {}
virtual void onPlaylistsAdded( std::vector<PlaylistPtr> ) override {}
virtual void onPlaylistsModified( std::vector<PlaylistPtr> ) override {}
virtual void onPlaylistsDeleted( std::vector<int64_t> ) override {}
};
}
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