[vlmc-devel] MediaLibrary: Expose video model
Hugo Beauzée-Luyssen
git at videolan.org
Mon Jul 4 15:34:50 CEST 2016
vlmc | branch: medialibrary | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Jul 4 15:25:34 2016 +0200| [f964117ad596a0cc3808f4d5d7ebb44e5e4b2e24] | committer: Hugo Beauzée-Luyssen
MediaLibrary: Expose video model
> https://code.videolan.org/videolan/vlmc/commit/f964117ad596a0cc3808f4d5d7ebb44e5e4b2e24
---
src/Library/MediaLibrary.cpp | 23 +++++++++++++++++++++--
src/Library/MediaLibrary.h | 9 +++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/Library/MediaLibrary.cpp b/src/Library/MediaLibrary.cpp
index 4619527..5f49ae7 100644
--- a/src/Library/MediaLibrary.cpp
+++ b/src/Library/MediaLibrary.cpp
@@ -22,9 +22,11 @@
#include "MediaLibrary.h"
#include "Settings/Settings.h"
+#include "MediaLibraryModel.h"
MediaLibrary::MediaLibrary( Settings* settings )
- : m_initialized( false )
+ : m_videoModel( nullptr )
+ , m_initialized( false )
{
m_ml.reset( NewMediaLibrary() );
auto s = settings->createVar( SettingValue::List, QStringLiteral( "vlmc/mlDirs" ), QVariantList(),
@@ -35,6 +37,18 @@ MediaLibrary::MediaLibrary( Settings* settings )
connect( ws, &SettingValue::changed, this, &MediaLibrary::workspaceChanged );
}
+MediaLibraryModel* MediaLibrary::model( MediaLibrary::MediaType type ) const
+{
+ switch ( type )
+ {
+ case MediaType::Video:
+ return m_videoModel;
+ case MediaType::Audio:
+ return nullptr;
+ }
+ Q_UNREACHABLE();
+}
+
void
MediaLibrary::mlDirsChanged( const QVariant& value )
{
@@ -59,13 +73,18 @@ MediaLibrary::workspaceChanged( const QVariant& workspace )
auto w = workspace.toString().toStdString();
Q_ASSERT( w.empty() == false );
m_ml->initialize( w + "/ml.db", w + "/thumbnails/", this );
+ //FIXME: Race condition, this could trigger onMediaAdded before m_videoModel has been created.
+ //However, we need the model to be created AFTER the ML gets initialized
+ m_videoModel = new MediaLibraryModel( *m_ml, medialibrary::IMedia::Type::VideoType, this );
m_initialized = true;
}
//else FIXME, and relocate the media library
}
-void MediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> )
+void MediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> mediaList )
{
+ for ( auto m : mediaList )
+ m_videoModel->addMedia( m );
}
void MediaLibrary::onMediaUpdated( std::vector<medialibrary::MediaPtr> )
diff --git a/src/Library/MediaLibrary.h b/src/Library/MediaLibrary.h
index 06f9f2c..5baf4df 100644
--- a/src/Library/MediaLibrary.h
+++ b/src/Library/MediaLibrary.h
@@ -30,6 +30,7 @@
#include <memory>
class Settings;
+class MediaLibraryModel;
class MediaLibrary : public QObject, private medialibrary::IMediaLibraryCb
{
@@ -37,7 +38,14 @@ class MediaLibrary : public QObject, private medialibrary::IMediaLibraryCb
Q_DISABLE_COPY( MediaLibrary )
public:
+ enum class MediaType
+ {
+ Video,
+ Audio
+ };
+
explicit MediaLibrary( Settings* settings );
+ MediaLibraryModel* model( MediaType type ) const;
signals:
void progressUpdated( int percent );
@@ -71,6 +79,7 @@ private:
private:
std::unique_ptr<medialibrary::IMediaLibrary> m_ml;
+ MediaLibraryModel* m_videoModel;
bool m_initialized;
};
More information about the Vlmc-devel
mailing list