[vlmc-devel] [PATCH] Library: Merge m_videoModel and m_audioModel

yikei lu luyikei.qmltu at gmail.com
Wed Mar 8 21:57:00 CET 2017


> so feel free to push this!
OK :) I'm going to do it.

> I'd like to have a audio/video specific view at some point though,
I didn't know that. How do you want to represent them in different views?

Regards,

On Wed, Mar 8, 2017 at 2:53 PM, Hugo Beauzée-Luyssen <hugo at beauzee.fr> wrote:
> On 03/08/2017 09:51 PM, yikei lu wrote:
>> On Wed, Mar 8, 2017 at 2:48 PM, Hugo Beauzée-Luyssen <hugo at beauzee.fr> wrote:
>>> On 03/08/2017 09:41 PM, Yikai Lu wrote:
>>>> ---
>>>>  src/Gui/library/MediaLibraryView.cpp |  4 +--
>>>>  src/Library/Library.cpp              | 55 ++++++------------------------------
>>>>  src/Library/Library.h                | 11 ++------
>>>>  src/Library/MediaLibraryModel.cpp    | 20 ++++---------
>>>>  src/Library/MediaLibraryModel.h      |  4 +--
>>>>  5 files changed, 19 insertions(+), 75 deletions(-)
>>>>
>>>> diff --git a/src/Gui/library/MediaLibraryView.cpp b/src/Gui/library/MediaLibraryView.cpp
>>>> index 530cea2..d06e16d 100644
>>>> --- a/src/Gui/library/MediaLibraryView.cpp
>>>> +++ b/src/Gui/library/MediaLibraryView.cpp
>>>> @@ -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 );
>>>>      }
>>>>
>>>> diff --git a/src/Library/Library.cpp b/src/Library/Library.cpp
>>>> index 8168870..5d150d1 100644
>>>> --- a/src/Library/Library.cpp
>>>> +++ b/src/Library/Library.cpp
>>>> @@ -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 );
>>>>      }
>>>>  }
>>>>
>>>> diff --git a/src/Library/Library.h b/src/Library/Library.h
>>>> index 31617b8..2879745 100644
>>>> --- a/src/Library/Library.h
>>>> +++ b/src/Library/Library.h
>>>> @@ -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;
>>>> diff --git a/src/Library/MediaLibraryModel.cpp b/src/Library/MediaLibraryModel.cpp
>>>> index 5a52a89..b46ddf3 100644
>>>> --- a/src/Library/MediaLibraryModel.cpp
>>>> +++ b/src/Library/MediaLibraryModel.cpp
>>>> @@ -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();
>>>>  }
>>>> diff --git a/src/Library/MediaLibraryModel.h b/src/Library/MediaLibraryModel.h
>>>> index 0add020..7729ff0 100644
>>>> --- a/src/Library/MediaLibraryModel.h
>>>> +++ b/src/Library/MediaLibraryModel.h
>>>> @@ -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;
>>>>
>>>
>>> Looks good to me!
>>> Although I guess there will be things to change as far as the view is
>>> concerned since I expect it to display audio & video all at once no?
>>
>> Yeah, it will show audio files but without thumbnails I guess. Except
>> that, it will work fine.
>>
>>>
>>> Regards,
>>> _______________________________________________
>>> Vlmc-devel mailing list
>>> Vlmc-devel at videolan.org
>>> https://mailman.videolan.org/listinfo/vlmc-devel
>> _______________________________________________
>> Vlmc-devel mailing list
>> Vlmc-devel at videolan.org
>> https://mailman.videolan.org/listinfo/vlmc-devel
>>
> Then all fine by me!
> I'd like to have a audio/video specific view at some point though, but
> this patch makes the code a lot easier, and having a model per type of
> entity (audio/video and most likely album/artist/tracks/genre) would be
> a pain to maintain, so feel free to push this!
>
> Regards,
> _______________________________________________
> Vlmc-devel mailing list
> Vlmc-devel at videolan.org
> https://mailman.videolan.org/listinfo/vlmc-devel


More information about the Vlmc-devel mailing list