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

Add albums removed & modified callbacks, and plug them with sqlite hooks

parent 46c7040e
......@@ -75,7 +75,9 @@ public:
virtual void onArtistsModified( std::vector<ArtistPtr> artist ) = 0;
virtual void onArtistsDeleted( std::vector<int64_t> ids ) = 0;
virtual void onAlbumAdded( AlbumPtr album ) = 0;
virtual void onAlbumsAdded( std::vector<AlbumPtr> albums ) = 0;
virtual void onAlbumsModified( std::vector<AlbumPtr> albums ) = 0;
virtual void onAlbumsDeleted( std::vector<int64_t> ids ) = 0;
/**
* @brief onTrackAdded Called when a media gets detected as an album track
* and after it has been added to the album representation
......
......@@ -167,6 +167,13 @@ void MediaLibrary::registerEntityHooks()
Artist::removeFromCache( rowId );
m_modificationNotifier->notifyArtistRemoval( rowId );
});
m_dbConnection->registerUpdateHook( policy::AlbumTable::Name,
[this]( SqliteConnection::HookReason reason, int64_t rowId ) {
if ( reason != SqliteConnection::HookReason::Delete )
return;
Album::removeFromCache( rowId );
m_modificationNotifier->notifyAlbumRemoval( rowId );
});
}
......
......@@ -245,7 +245,7 @@ std::shared_ptr<Album> MetadataParser::handleAlbum( parser::Task& task, std::sha
if ( task.artworkMrl.length() != 0 )
album->setArtworkMrl( task.artworkMrl );
}
m_cb->onAlbumAdded( album );
m_notifier->notifyAlbumCreation( album );
}
}
else
......
......@@ -68,7 +68,7 @@ void ModificationNotifier::notifyArtistCreation( ArtistPtr artist )
notifyCreation( std::move( artist ), m_artists );
}
void ModificationNotifier::notifyArtistModification(ArtistPtr artist)
void ModificationNotifier::notifyArtistModification( ArtistPtr artist )
{
notifyModification( std::move( artist ), m_artists );
}
......@@ -78,6 +78,21 @@ void ModificationNotifier::notifyArtistRemoval( int64_t artist )
notifyRemoval( std::move( artist ), m_artists );
}
void ModificationNotifier::notifyAlbumCreation( AlbumPtr album )
{
notifyCreation( std::move( album ), m_albums );
}
void ModificationNotifier::notifyAlbumModification( AlbumPtr album )
{
notifyModification( std::move( album ), m_albums );
}
void ModificationNotifier::notifyAlbumRemoval( int64_t albumId )
{
notifyRemoval( albumId, m_albums );
}
void ModificationNotifier::run()
{
constexpr auto ZeroTimeout = std::chrono::time_point<std::chrono::steady_clock>{};
......@@ -87,6 +102,7 @@ void ModificationNotifier::run()
// more insertions to proceed
Queue<IMedia> media;
Queue<IArtist> artists;
Queue<IAlbum> albums;
while ( m_stop == false )
{
......@@ -101,9 +117,11 @@ void ModificationNotifier::run()
auto nextTimeout = ZeroTimeout;
checkQueue( m_media, media, nextTimeout, now );
checkQueue( m_artists, artists, nextTimeout, now );
checkQueue( m_albums, albums, 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 );
}
}
......@@ -48,6 +48,10 @@ public:
void notifyArtistModification( ArtistPtr artist );
void notifyArtistRemoval( int64_t artist );
void notifyAlbumCreation( AlbumPtr album );
void notifyAlbumModification( AlbumPtr album );
void notifyAlbumRemoval( int64_t albumId );
private:
void run();
void notify();
......@@ -134,6 +138,7 @@ private:
// Queues
Queue<IMedia> m_media;
Queue<IArtist> m_artists;
Queue<IAlbum> m_albums;
// Notifier thread
std::mutex m_lock;
......
......@@ -39,7 +39,9 @@ class NoopCallback : public IMediaLibraryCb
virtual void onArtistsAdded( std::vector<ArtistPtr> ) override {}
virtual void onArtistsModified( std::vector<ArtistPtr> ) override {}
virtual void onArtistsDeleted( std::vector<int64_t> ) override {}
virtual void onAlbumAdded( AlbumPtr ) override {}
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 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