Commit 1fcdb6a9 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Expose video model

parent 3720af51
......@@ -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> )
......
......@@ -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;
};
......
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