[vlmc-devel] MediaLibraryModel: Add findMedia

Yikai Lu git at videolan.org
Fri Aug 19 12:09:40 CEST 2016


vlmc | branch: medialibrary | Yikai Lu <luyikei.qmltu at gmail.com> | Fri Aug 19 00:36:59 2016 -0500| [8b369fd1c9a8581219473366136e1a68da14e043] | committer: Hugo Beauzée-Luyssen

MediaLibraryModel: Add findMedia

> https://code.videolan.org/videolan/vlmc/commit/8b369fd1c9a8581219473366136e1a68da14e043
---

 src/Library/MediaLibraryModel.cpp | 11 +++++++++++
 src/Library/MediaLibraryModel.h   |  1 +
 2 files changed, 12 insertions(+)

diff --git a/src/Library/MediaLibraryModel.cpp b/src/Library/MediaLibraryModel.cpp
index 7a3ebed..8f07274 100644
--- a/src/Library/MediaLibraryModel.cpp
+++ b/src/Library/MediaLibraryModel.cpp
@@ -48,6 +48,17 @@ void MediaLibraryModel::addMedia( medialibrary::MediaPtr media )
     endInsertRows();
 }
 
+medialibrary::MediaPtr
+MediaLibraryModel::findMedia( qint64 mediaId )
+{
+    auto it = std::find_if( begin( m_media ), end( m_media ), [mediaId](medialibrary::MediaPtr m) {
+        return m->id() == mediaId;
+    });
+    if ( it == end( m_media ) )
+        return nullptr;
+    return *it;
+}
+
 void MediaLibraryModel::updateMedia( medialibrary::MediaPtr media )
 {
     auto m = createIndex( media->id(), 0 );
diff --git a/src/Library/MediaLibraryModel.h b/src/Library/MediaLibraryModel.h
index 6910e60..d9be33b 100644
--- a/src/Library/MediaLibraryModel.h
+++ b/src/Library/MediaLibraryModel.h
@@ -47,6 +47,7 @@ public:
                                 QObject *parent = 0 );
 
     void addMedia( medialibrary::MediaPtr media );
+    medialibrary::MediaPtr findMedia( qint64 mediaId );
     void updateMedia( medialibrary::MediaPtr media );
     bool removeMedia( int64_t media );
     void refresh();



More information about the Vlmc-devel mailing list