Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
bd055d78
Commit
bd055d78
authored
Feb 10, 2016
by
Hugo Beauzée-Luyssen
Browse files
Add & plug tracks removal callbacks
parent
6acd94ed
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/IMediaLibrary.h
View file @
bd055d78
...
...
@@ -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
;
...
...
src/MediaLibrary.cpp
View file @
bd055d78
...
...
@@ -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
);
});
}
...
...
src/metadata_services/MetadataParser.cpp
View file @
bd055d78
...
...
@@ -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
;
}
...
...
src/utils/ModificationsNotifier.cpp
View file @
bd055d78
...
...
@@ -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
);
}
}
src/utils/ModificationsNotifier.h
View file @
bd055d78
...
...
@@ -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
;
...
...
test/mocks/NoopCallback.h
View file @
bd055d78
...
...
@@ -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
{}
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment