Skip to content

Commit

Permalink
clean metadata on media removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodmg committed Nov 3, 2023
1 parent 1b36b68 commit 96f3824
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions qmediaplaylist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ bool QMediaPlaylist::removeMedia(int start, int end)
this->shuffle();
}

vacuumMetadata();

emit mediaRemoved(start, end);
return true;
}
Expand All @@ -592,6 +594,7 @@ void QMediaPlaylist::clear()
emit mediaAboutToBeRemoved(0, size - 1);
d->playlist.clear();
d->playqueue.clear();
vacuumMetadata();
emit mediaRemoved(0, size - 1);
}

Expand Down Expand Up @@ -785,7 +788,6 @@ void QMediaPlaylist::previous()
/*!
Activate media content from playlist at position \a playlistPosition.
*/

void QMediaPlaylist::setCurrentIndex(int playlistPosition)
{
Q_D(QMediaPlaylist);
Expand All @@ -800,7 +802,6 @@ void QMediaPlaylist::setCurrentIndex(int playlistPosition)
/*!
Activate media content from playlist at position \a playlistPosition.
*/

void QMediaPlaylist::setCurrentQueueIndex(int playlistPosition)
{
Q_D(QMediaPlaylist);
Expand All @@ -812,6 +813,9 @@ void QMediaPlaylist::setCurrentQueueIndex(int playlistPosition)
emit currentMediaChanged(currentMedia());
}

/*!
Loads media metadata
*/
void QMediaPlaylist::loadMetadata(const QUrl &url)
{
if(m_mediaMetadata.contains(url)) {
Expand All @@ -823,6 +827,21 @@ void QMediaPlaylist::loadMetadata(const QUrl &url)
m_mediaMetadata.insert(url, meta);
}

/*!
Cleans unused metadata (for example, after removing media from the playlist)
*/
void QMediaPlaylist::vacuumMetadata()
{
Q_D(const QMediaPlaylist);

for(const QUrl &key : m_mediaMetadata.keys()) {
if(!d->playlist.contains(key)) {
// Metadata not used, remove
m_mediaMetadata.remove(key);
}
}
}


/*!
\fn void QMediaPlaylist::mediaInserted(int start, int end)
Expand Down
1 change: 1 addition & 0 deletions qmediaplaylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public slots:
// Metadata for files in the playlist
QMap<QUrl, QMediaMetaData> m_mediaMetadata;
void loadMetadata(const QUrl &url);
void vacuumMetadata();
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 96f3824

Please sign in to comment.