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

Plug Media deletion with DeletionNotifier

parent 4a7ab23e
......@@ -30,6 +30,7 @@
#include "Artist.h"
#include "AudioTrack.h"
#include "discoverer/DiscovererWorker.h"
#include "utils/DeletionNotifier.h"
#include "Device.h"
#include "File.h"
#include "Folder.h"
......@@ -147,6 +148,18 @@ bool MediaLibrary::createAllTables()
return true;
}
void MediaLibrary::registerEntityHooks()
{
m_dbConnection->registerUpdateHook( policy::MediaTable::Name,
[this]( SqliteConnection::HookReason reason, int64_t rowId ) {
if ( reason != SqliteConnection::HookReason::Delete )
return;
Media::removeFromCache( rowId );
m_deletionNotifier->notifyMediaRemoval( rowId );
});
}
bool MediaLibrary::validateSearchPattern( const std::string& pattern )
{
return pattern.size() >= 3;
......@@ -161,6 +174,8 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
m_callback = mlCallback;
m_dbConnection.reset( new SqliteConnection( dbPath ) );
registerEntityHooks();
if ( createAllTables() == false )
{
LOG_ERROR( "Failed to create database structure" );
......@@ -175,6 +190,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
}
startDiscoverer();
startParser();
startDeletionNotifier();
return true;
}
......@@ -467,6 +483,12 @@ void MediaLibrary::startDiscoverer()
m_discoverer->reload();
}
void MediaLibrary::startDeletionNotifier()
{
m_deletionNotifier.reset( new DeletionNotifier( this ) );
m_deletionNotifier->start();
}
bool MediaLibrary::updateDatabaseModel( unsigned int previousVersion )
{
if ( previousVersion == 1 )
......
......@@ -23,9 +23,10 @@
#ifndef MEDIALIBRARY_H
#define MEDIALIBRARY_H
class DeletionNotifier;
class DiscovererWorker;
class Parser;
class ParserService;
class DiscovererWorker;
class SqliteConnection;
#include "IMediaLibrary.h"
......@@ -124,8 +125,10 @@ class MediaLibrary : public IMediaLibrary
private:
virtual void startParser();
virtual void startDiscoverer();
virtual void startDeletionNotifier();
bool updateDatabaseModel( unsigned int previousVersion );
bool createAllTables();
void registerEntityHooks();
static bool validateSearchPattern( const std::string& pattern );
protected:
......@@ -143,6 +146,7 @@ class MediaLibrary : public IMediaLibrary
// Same reasoning applies here.
//FIXME: Having to maintain a specific ordering sucks, let's use shared_ptr or something
std::unique_ptr<DiscovererWorker> m_discoverer;
std::unique_ptr<DeletionNotifier> m_deletionNotifier;
LogLevel m_verbosity;
Settings m_settings;
};
......
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