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

Add & plug tracks removal callbacks

parent 6acd94ed
......@@ -81,10 +81,10 @@ public:
/**
* @brief onTrackAdded Called when a media gets detected as an album track
* and after it has been added to the album representation
* @param media The media, containing most of the informations
* @param track Some track specific informations
*/
virtual void onTrackAdded( MediaPtr media, AlbumTrackPtr track ) = 0;
virtual void onTracksAdded( std::vector<AlbumTrackPtr> tracks ) = 0;
// Tracks are never modified after their creation, so there is no tracksModified event
virtual void onTracksDeleted( std::vector<int64_t> trackIds ) = 0;
virtual void onDiscoveryStarted( const std::string& entryPoint ) = 0;
virtual void onDiscoveryCompleted( const std::string& entryPoint ) = 0;
......
......@@ -174,6 +174,13 @@ void MediaLibrary::registerEntityHooks()
Album::removeFromCache( rowId );
m_modificationNotifier->notifyAlbumRemoval( rowId );
});
m_dbConnection->registerUpdateHook( policy::AlbumTrackTable::Name,
[this]( SqliteConnection::HookReason reason, int64_t rowId ) {
if ( reason != SqliteConnection::HookReason::Delete )
return;
AlbumTrack::removeFromCache( rowId );
m_modificationNotifier->notifyAlbumTrackRemoval( rowId );
});
}
......
......@@ -356,7 +356,7 @@ std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album>
// using Album class internals.
album->setReleaseYear( releaseYear, false );
}
m_cb->onTrackAdded( task.media, track );
m_notifier->notifyAlbumTrackCreation( track );
return track;
}
......
......@@ -93,6 +93,21 @@ void ModificationNotifier::notifyAlbumRemoval( int64_t albumId )
notifyRemoval( albumId, m_albums );
}
void ModificationNotifier::notifyAlbumTrackCreation( AlbumTrackPtr track )
{
notifyCreation( std::move( track ), m_tracks );
}
void ModificationNotifier::notifyAlbumTrackModification( AlbumTrackPtr track )
{
notifyModification( std::move( track ), m_tracks );
}
void ModificationNotifier::notifyAlbumTrackRemoval( int64_t trackId )
{
notifyRemoval( trackId, m_tracks );
}
void ModificationNotifier::run()
{
constexpr auto ZeroTimeout = std::chrono::time_point<std::chrono::steady_clock>{};
......@@ -103,6 +118,7 @@ void ModificationNotifier::run()
Queue<IMedia> media;
Queue<IArtist> artists;
Queue<IAlbum> albums;
Queue<IAlbumTrack> tracks;
while ( m_stop == false )
{
......@@ -118,10 +134,14 @@ void ModificationNotifier::run()
checkQueue( m_media, media, nextTimeout, now );
checkQueue( m_artists, artists, nextTimeout, now );
checkQueue( m_albums, albums, nextTimeout, now );
checkQueue( m_tracks, tracks, nextTimeout, now );
m_timeout = nextTimeout;
}
notify( std::move( media ), &IMediaLibraryCb::onMediaAdded, &IMediaLibraryCb::onMediaUpdated, &IMediaLibraryCb::onMediaDeleted );
notify( std::move( artists ), &IMediaLibraryCb::onArtistsAdded, &IMediaLibraryCb::onArtistsModified, &IMediaLibraryCb::onArtistsDeleted );
notify( std::move( albums ), &IMediaLibraryCb::onAlbumsAdded, &IMediaLibraryCb::onAlbumsModified, &IMediaLibraryCb::onAlbumsDeleted );
// 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 );
}
}
......@@ -52,6 +52,10 @@ public:
void notifyAlbumModification( AlbumPtr album );
void notifyAlbumRemoval( int64_t albumId );
void notifyAlbumTrackCreation( AlbumTrackPtr track );
void notifyAlbumTrackModification( AlbumTrackPtr track );
void notifyAlbumTrackRemoval( int64_t trackId );
private:
void run();
void notify();
......@@ -139,6 +143,7 @@ private:
Queue<IMedia> m_media;
Queue<IArtist> m_artists;
Queue<IAlbum> m_albums;
Queue<IAlbumTrack> m_tracks;
// Notifier thread
std::mutex m_lock;
......
......@@ -42,7 +42,8 @@ class NoopCallback : public IMediaLibraryCb
virtual void onAlbumsAdded( std::vector<AlbumPtr> ) override {}
virtual void onAlbumsModified( std::vector<AlbumPtr> ) override {}
virtual void onAlbumsDeleted( std::vector<int64_t> ) override {}
virtual void onTrackAdded( MediaPtr, AlbumTrackPtr ) override {}
virtual void onTracksAdded( std::vector<AlbumTrackPtr> ) override {}
virtual void onTracksDeleted( std::vector<int64_t> ) override {}
virtual void onParsingStatsUpdated( uint32_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