Commit b2ac2320 authored by luyikei's avatar luyikei

Library: Merge m_videoModel and m_audioModel

parent 1bd109af
......@@ -52,7 +52,7 @@ MediaLibraryView::MediaLibraryView( QWidget* parent )
m_container->setObjectName( objectName() );
auto ctx = view->rootContext();
ctx->setContextProperty( QStringLiteral( "mlModel" ), Core::instance()->library()->model( Library::MediaType::Video ) );
ctx->setContextProperty( QStringLiteral( "mlModel" ), Core::instance()->library()->model() );
ctx->setContextProperty( QStringLiteral( "view" ), this );
view->setSource( QUrl( QStringLiteral( "qrc:/QML/MediaLibraryView.qml" ) ) );
......@@ -90,7 +90,7 @@ MediaLibraryView::onMediaSelected( qint64 mediaId )
{
QSharedPointer<Media> media = Core::instance()->library()->media( mediaId );
if ( media == nullptr ) {
media.reset( new Media( Core::instance()->library()->model( Library::MediaType::Video )->findMedia( mediaId ) ) );
media.reset( new Media( Core::instance()->library()->model()->findMedia( mediaId ) ) );
Core::instance()->library()->addMedia( media );
}
......
......@@ -51,8 +51,7 @@ Library::Library( Settings* vlmcSettings, Settings *projectSettings )
// Setting up the external media library
m_ml.reset( NewMediaLibrary() );
m_ml->setVerbosity( medialibrary::LogLevel::Warning );
m_videoModel = new MediaLibraryModel( *m_ml, medialibrary::IMedia::Type::Video, this );
m_audioModel = new MediaLibraryModel( *m_ml, medialibrary::IMedia::Type::Audio, this );
m_model = new MediaLibraryModel( *m_ml, this );
auto s = vlmcSettings->createVar( SettingValue::List, QStringLiteral( "vlmc/mlDirs" ), QVariantList(),
"Media Library folders", "List of folders VLMC will search for media files",
......@@ -141,16 +140,9 @@ Library::mlMedia( qint64 mediaId )
}
MediaLibraryModel*
Library::model(Library::MediaType type) const
Library::model() const
{
switch ( type )
{
case MediaType::Video:
return m_videoModel;
case MediaType::Audio:
return m_audioModel;
}
Q_UNREACHABLE();
return m_model;
}
QSharedPointer<Clip>
......@@ -215,17 +207,7 @@ Library::onMediaAdded( std::vector<medialibrary::MediaPtr> mediaList )
{
for ( auto m : mediaList )
{
switch ( m->type() )
{
case medialibrary::IMedia::Type::Video:
m_videoModel->addMedia( m );
break;
case medialibrary::IMedia::Type::Audio:
m_audioModel->addMedia( m );
break;
default:
Q_UNREACHABLE();
}
m_model->addMedia( m );
}
}
......@@ -234,17 +216,7 @@ Library::onMediaUpdated( std::vector<medialibrary::MediaPtr> mediaList )
{
for ( auto m : mediaList )
{
switch ( m->type() )
{
case medialibrary::IMedia::Type::Video:
m_videoModel->updateMedia( m );
break;
case medialibrary::IMedia::Type::Audio:
m_audioModel->updateMedia( m );
break;
default:
Q_UNREACHABLE();
}
m_model->updateMedia( m );
}
}
......@@ -252,13 +224,7 @@ void
Library::onMediaDeleted( std::vector<int64_t> mediaList )
{
for ( auto id : mediaList )
{
// We can't know the media type, however ID are unique regardless of the type
// so we are sure that we will remove the correct media.
if ( m_videoModel->removeMedia( id ) == true )
continue;
m_audioModel->removeMedia( id );
}
m_model->removeMedia( id );
}
void
......@@ -316,10 +282,7 @@ void
Library::onDiscoveryCompleted( const std::string& entryPoint )
{
if ( entryPoint.empty() == true )
{
m_videoModel->refresh();
m_audioModel->refresh();
}
m_model->refresh();
emit discoveryCompleted( QString::fromStdString( entryPoint ) );
}
......@@ -356,10 +319,10 @@ Library::onReloadCompleted( const std::string& entryPoint )
if ( entryPoint.empty() == true )
{
for ( auto media : m_ml->videoFiles() )
m_videoModel->addMedia( media );
m_model->addMedia( media );
for ( auto media : m_ml->audioFiles() )
m_audioModel->addMedia( media );
m_model->addMedia( media );
}
}
......
......@@ -54,12 +54,6 @@ class Library : public QObject, private medialibrary::IMediaLibraryCb
Q_DISABLE_COPY( Library )
public:
enum class MediaType
{
Video,
Audio
};
Library( Settings* vlmcSettings, Settings* projectSettings );
virtual ~Library();
void addMedia( QSharedPointer<Media> media );
......@@ -69,7 +63,7 @@ public:
//FIXME: This feels rather ugly
medialibrary::MediaPtr mlMedia( qint64 mediaId);
MediaLibraryModel* model( MediaType type ) const;
MediaLibraryModel* model() const;
/**
* @brief clip returns an existing clip
......@@ -115,8 +109,7 @@ private:
private:
std::unique_ptr<medialibrary::IMediaLibrary> m_ml;
MediaLibraryModel* m_videoModel;
MediaLibraryModel* m_audioModel;
MediaLibraryModel* m_model;
Settings* m_settings;
bool m_initialized;
bool m_cleanState;
......
......@@ -29,18 +29,15 @@
#include <QPixmap>
#endif
MediaLibraryModel::MediaLibraryModel( medialibrary::IMediaLibrary& ml, medialibrary::IMedia::Type type, QObject *parent )
MediaLibraryModel::MediaLibraryModel( medialibrary::IMediaLibrary& ml, QObject *parent )
: QAbstractListModel(parent)
, m_ml( ml )
, m_mediaType( type )
, m_rowCount( 0 )
{
}
void MediaLibraryModel::addMedia( medialibrary::MediaPtr media )
{
if ( media->type() != m_mediaType )
return;
std::lock_guard<std::mutex> lock( m_mediaMutex );
auto size = m_media.size();
beginInsertRows( QModelIndex(), size, size );
......@@ -143,17 +140,10 @@ void MediaLibraryModel::refresh()
beginResetModel();
switch ( m_mediaType )
{
case medialibrary::IMedia::Type::Audio:
m_media = m_ml.audioFiles();
break;
case medialibrary::IMedia::Type::Video:
m_media = m_ml.videoFiles();
break;
default:
Q_UNREACHABLE();
}
const auto& audioFiles = m_ml.audioFiles();
const auto& videoFiles = m_ml.videoFiles();
m_media.insert( m_media.end(), audioFiles.begin(), audioFiles.end() );
m_media.insert( m_media.end(), videoFiles.begin(), videoFiles.end() );
m_rowCount = m_media.size();
endResetModel();
}
......@@ -44,8 +44,7 @@ public:
Id,
};
explicit MediaLibraryModel( medialibrary::IMediaLibrary& ml, medialibrary::IMedia::Type type,
QObject *parent = 0 );
explicit MediaLibraryModel( medialibrary::IMediaLibrary& ml, QObject *parent = 0 );
void addMedia( medialibrary::MediaPtr media );
medialibrary::MediaPtr findMedia( qint64 mediaId );
......@@ -59,7 +58,6 @@ public:
private:
medialibrary::IMediaLibrary& m_ml;
const medialibrary::IMedia::Type m_mediaType;
// Use an atomic int to avoid locking m_media within rowCount()
mutable std::mutex m_mediaMutex;
......
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