[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt: load cache on ml initialization

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Jul 8 16:50:42 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
1e5352e1 by Prince Gupta at 2023-07-08T16:29:04+00:00
qt: load cache on ml initialization

this make sure model always get ready (see MLBaseModel::isReady)
otherwise Model will wait for any attempt to access data before
initiating cache loading, MLBaseModel::isReady will be false till then

- - - - -
a355f026 by Prince Gupta at 2023-07-08T16:29:04+00:00
qt: make sure to initialize MLBaseModel cache after qml parsing

- - - - -
06837326 by Prince Gupta at 2023-07-08T16:29:04+00:00
qml: don't load any view until model is ready

this fixes various qml warnings and unnecessary view loading,
model gets ready very fast (in most of cases), so just
don't load anything until model isn't ready

- - - - -
c177d489 by Prince Gupta at 2023-07-08T16:29:04+00:00
qt: rename mlbasemodel property

- - - - -
10e14f64 by Prince Gupta at 2023-07-08T16:29:04+00:00
qml: implement loadingComponent in MainViewLoader

- - - - -
2ab429c8 by Prince Gupta at 2023-07-08T16:29:04+00:00
qt: rename Network*Models::parsingPending to loading

- - - - -
b0a4295e by Prince Gupta at 2023-07-08T16:29:04+00:00
qml: use loadingComponent in BrowseTreeDisplay

- - - - -


12 changed files:

- modules/gui/qt/maininterface/qml/MainViewLoader.qml
- modules/gui/qt/medialibrary/mlbasemodel.cpp
- modules/gui/qt/medialibrary/mlbasemodel.hpp
- modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
- modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml
- modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
- modules/gui/qt/network/networkmediamodel.cpp
- modules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
- modules/gui/qt/network/qml/ServicesManage.qml
- modules/gui/qt/network/servicesdiscoverymodel.cpp
- modules/gui/qt/network/servicesdiscoverymodel.hpp


Changes:

=====================================
modules/gui/qt/maininterface/qml/MainViewLoader.qml
=====================================
@@ -49,6 +49,8 @@ Widgets.StackViewExt {
     // view's model
     /* required */ property var model
 
+    // optional, loaded when model.loading is true
+    property Component loadingComponent: null
 
 
     property var selectionModel: Util.SelectableDelegateModel {
@@ -72,7 +74,9 @@ Widgets.StackViewExt {
     property var currentComponent: {
         if (typeof model === "undefined" || !model)
             return null // invalid state
-        if (model.isReady && model.count === 0)
+        if (model.loading)
+            return loadingComponent
+        if (model.count === 0)
             return emptyLabel
         else if (MainCtx.gridView)
             return grid


=====================================
modules/gui/qt/medialibrary/mlbasemodel.cpp
=====================================
@@ -39,8 +39,8 @@ MLBaseModel::MLBaseModel(QObject *parent)
 {
     connect( this, &MLBaseModel::resetRequested, this, &MLBaseModel::onResetRequested );
 
-    connect( this, &MLBaseModel::mlChanged, this, &MLBaseModel::isReadyChanged );
-    connect( this, &MLBaseModel::countChanged, this, &MLBaseModel::isReadyChanged );
+    connect( this, &MLBaseModel::mlChanged, this, &MLBaseModel::loadingChanged );
+    connect( this, &MLBaseModel::countChanged, this, &MLBaseModel::loadingChanged );
 }
 
 /* For std::unique_ptr, see Effective Modern C++, Item 22 */
@@ -251,6 +251,18 @@ void MLBaseModel::onVlcMlEvent(void* data, const vlc_ml_event_t* event)
     });
 }
 
+void MLBaseModel::classBegin()
+{
+    m_qmlInitializing = true;
+}
+
+void MLBaseModel::componentComplete()
+{
+    m_qmlInitializing = false;
+
+    validateCache();
+}
+
 MLItemId MLBaseModel::parentId() const
 {
     return m_parent;
@@ -285,6 +297,9 @@ void MLBaseModel::setMl(MediaLib* medialib)
     m_mediaLib = medialib;
     if ( m_ml_event_handle == nullptr )
         m_ml_event_handle.reset( m_mediaLib->registerEventListener(onVlcMlEvent, this ) );
+
+    validateCache();
+
     mlChanged();
 }
 
@@ -346,7 +361,7 @@ void MLBaseModel::unsetSortCriteria()
 
 int MLBaseModel::rowCount(const QModelIndex &parent) const
 {
-    if (!m_mediaLib || parent.isValid())
+    if (!cachable() || parent.isValid())
         return 0;
 
     validateCache();
@@ -406,9 +421,11 @@ QVariantList MLBaseModel::getIdsForIndexes(const QVariantList & indexes) const
 
 unsigned MLBaseModel::getCount() const
 {
-    if (!m_mediaLib)
+    if (!cachable())
         return 0;
+
     validateCache();
+
     if (m_cache->count() == COUNT_UNINITIALIZED)
         return 0;
     return static_cast<unsigned>(m_cache->count());
@@ -440,7 +457,7 @@ void MLBaseModel::validateCache() const
     if (m_cache)
         return;
 
-    if (!m_mediaLib)
+    if (!cachable())
         return;
 
     auto loader = createLoader();
@@ -468,7 +485,7 @@ void MLBaseModel::validateCache() const
 
     m_cache->initCount();
 
-    emit isReadyChanged();
+    emit loadingChanged();
 }
 
 
@@ -485,7 +502,7 @@ void MLBaseModel::invalidateCache()
     if (m_cache)
     {
         m_cache->invalidate();
-        emit isReadyChanged();
+        emit loadingChanged();
     }
     else
         validateCache();
@@ -628,7 +645,7 @@ MLQueryParams MLBaseModel::BaseLoader::getParams(size_t index, size_t count) con
     return { m_searchPattern.toUtf8(), m_sort, m_sort_desc, index, count };
 }
 
-bool MLBaseModel::isReady() const
+bool MLBaseModel::loading() const
 {
-    return (m_mediaLib && m_cache && (m_cache->count() != COUNT_UNINITIALIZED));
+    return !(m_mediaLib && m_cache && (m_cache->count() != COUNT_UNINITIALIZED));
 }


=====================================
modules/gui/qt/medialibrary/mlbasemodel.hpp
=====================================
@@ -27,6 +27,8 @@
 
 #include <memory>
 #include <QAbstractListModel>
+#include <QQmlParserStatus>
+
 #include <vlc_media_library.h>
 #include "mlqmltypes.hpp"
 #include "medialib.hpp"
@@ -39,9 +41,10 @@
 class MLListCache;
 class MediaLib;
 
-class MLBaseModel : public QAbstractListModel
+class MLBaseModel : public QAbstractListModel, public QQmlParserStatus
 {
     Q_OBJECT
+    Q_INTERFACES(QQmlParserStatus)
 
     Q_PROPERTY(MLItemId parentId READ parentId WRITE setParentId NOTIFY parentIdChanged
                RESET unsetParentId FINAL)
@@ -57,8 +60,11 @@ class MLBaseModel : public QAbstractListModel
 
     Q_PROPERTY(unsigned int count READ getCount NOTIFY countChanged FINAL)
 
-    // isReady is true when the ml object is not null and the cache count is initialized
-    Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged FINAL)
+    /**
+     * @brief loading
+     * @return true till no data is available
+     */
+    Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged FINAL)
 
 public:
     explicit MLBaseModel(QObject *parent = nullptr);
@@ -89,7 +95,7 @@ signals:
     void sortOrderChanged();
     void sortCriteriaChanged();
     void countChanged(unsigned int) const;
-    void isReadyChanged() const;
+    void loadingChanged() const;
 
 protected slots:
     void onResetRequested();
@@ -99,6 +105,9 @@ private:
     static void onVlcMlEvent( void* data, const vlc_ml_event_t* event );
 
 protected:
+    void classBegin() override;
+    void componentComplete() override;
+
     virtual vlc_ml_sorting_criteria_t roleToCriteria(int role) const = 0;
     static QString getFirstSymbol(QString str);
     virtual vlc_ml_sorting_criteria_t nameToCriteria(QByteArray) const {
@@ -175,7 +184,7 @@ public:
     int rowCount(const QModelIndex &parent = {}) const override;
     virtual unsigned int getCount() const;
 
-    bool isReady() const;
+    bool loading() const;
 
 private:
     void onCacheDataChanged(int first, int last);
@@ -183,6 +192,8 @@ private:
     void onCacheBeginRemoveRows(int first, int last);
     void onCacheBeginMoveRows(int first, int last, int destination);
 
+    inline bool cachable() const { return m_mediaLib && !m_qmlInitializing; }
+
 protected:
     MLItemId m_parent;
 
@@ -199,6 +210,8 @@ protected:
 
     //loader used to load single items
     std::shared_ptr<BaseLoader> m_itemLoader;
+
+    bool m_qmlInitializing = false;
 };
 
 #endif // MLBASEMODEL_HPP


=====================================
modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml
=====================================
@@ -250,7 +250,7 @@ FocusScope {
 
     Widgets.EmptyLabelButton {
         anchors.fill: parent
-        visible: artistModel.isReady && (artistModel.count <= 0)
+        visible: !artistModel.loading && (artistModel.count <= 0)
         focus: visible
         text: I18n.qtr("No artists found\nPlease try adding sources, by going to the Browse tab")
         Navigation.parentItem: root


=====================================
modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml
=====================================
@@ -74,7 +74,7 @@ FocusScope {
 
     Widgets.EmptyLabelButton {
         anchors.fill: parent
-        visible: tracklistdisplay_id.model.isReady && (tracklistdisplay_id.model.count <= 0)
+        visible: !tracklistdisplay_id.model.loading && (tracklistdisplay_id.model.count <= 0)
         focus: visible
         text: I18n.qtr("No tracks found\nPlease try adding sources, by going to the Browse tab")
         Navigation.parentItem: root


=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
=====================================
@@ -199,7 +199,7 @@ FocusScope {
     Widgets.EmptyLabelButton {
         anchors.fill: parent
 
-        visible: model.isReady && (model.count <= 0)
+        visible: !model.loading && (model.count <= 0)
 
         focus: visible
 


=====================================
modules/gui/qt/network/networkmediamodel.cpp
=====================================
@@ -449,8 +449,8 @@ bool NetworkMediaModel::initializeMediaSources()
 
     m_preparseSem.acquire();
     vlc_media_tree_Preparse( tree, libvlc, m_treeItem.media.get(), this );
-    m_parsingPending = true;
-    emit parsingPendingChanged(m_parsingPending);
+    m_loading = true;
+    emit loadingChanged(m_loading);
 
     m_listener = std::move( l );
 
@@ -548,8 +548,8 @@ void NetworkMediaModel::ListenerCb::onItemPreparseEnded(MediaTreePtr, input_item
         if (p_node != model->m_treeItem.media)
             return;
 
-        model->m_parsingPending = false;
-        model->emit parsingPendingChanged(false);
+        model->m_loading = false;
+        model->emit loadingChanged(false);
     });
 }
 


=====================================
modules/gui/qt/network/networkmediamodel.hpp
=====================================
@@ -141,7 +141,7 @@ public:
     Q_PROPERTY(ItemType type READ getType NOTIFY typeChanged)
     Q_PROPERTY(bool indexed READ isIndexed WRITE setIndexed NOTIFY isIndexedChanged)
     Q_PROPERTY(bool canBeIndexed READ canBeIndexed NOTIFY canBeIndexedChanged)
-    Q_PROPERTY(bool parsingPending READ getParsingPending NOTIFY parsingPendingChanged)
+    Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
     Q_PROPERTY(int count READ getCount NOTIFY countChanged)
 
     explicit NetworkMediaModel(QObject* parent = nullptr);
@@ -167,7 +167,7 @@ public:
     inline ItemType getType() const { return m_type; }
     inline bool isIndexed() const { return m_indexed; }
     inline bool canBeIndexed() const { return m_canBeIndexed; }
-    inline bool getParsingPending() const { return m_parsingPending; }
+    inline bool isLoading() const { return m_loading; }
     int getCount() const;
 
     Q_INVOKABLE QMap<QString, QVariant> getDataAt(int idx);
@@ -188,7 +188,7 @@ signals:
     void typeChanged();
     void isIndexedChanged();
     void canBeIndexedChanged();
-    void parsingPendingChanged(bool);
+    void loadingChanged(bool);
     void countChanged();
 
     void ctxChanged();
@@ -237,7 +237,7 @@ private:
     ItemType m_type = ItemType::TYPE_UNKNOWN;
     bool m_indexed = false;
     bool m_canBeIndexed  = false;
-    bool m_parsingPending = false;
+    bool m_loading = false;
     QSemaphore m_preparseSem;
 
     std::vector<Item> m_items;


=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -39,8 +39,8 @@ MainInterface.MainViewLoader {
 
     readonly property bool isViewMultiView: true
 
-     // 'parsingPending' property is not available with NetworkDevicesModel
-    readonly property bool parsing: Helpers.get(providerModel, "parsingPending", false)
+     // 'loading' property is not available with NetworkDevicesModel
+    readonly property bool loading: Helpers.get(providerModel, "loading", false)
 
     property var sortModel: [
         { text: I18n.qtr("Alphabetic"), criteria: "name"},
@@ -65,17 +65,11 @@ MainInterface.MainViewLoader {
         searchRole: "name"
     }
 
-    // override the default currentComponent assignment from MainViewLoader
-    // because we need to show empty label when model is parsing
-    currentComponent: {
-        if (filterModel.count == 0 || root.parsing)
-            return emptyLabelComponent
-        else if (MainCtx.gridView)
-            return gridComponent
-        else
-            return tableComponent
-    }
+    grid: gridComponent
+    list: tableComponent
 
+    loadingComponent: emptyLabelComponent
+    emptyLabel: emptyLabelComponent
 
     onTreeChanged: providerModel.tree = tree
 
@@ -349,7 +343,7 @@ MainInterface.MainViewLoader {
                 Widgets.EmptyLabelButton {
                     id: emptyLabel
 
-                    visible: !root.parsing
+                    visible: !root.loading
 
                     // FIXME: find better cover
                     cover: VLCStyle.noArtVideoCover
@@ -384,7 +378,7 @@ MainInterface.MainViewLoader {
                 }
 
                 Item {
-                    visible: root.parsing
+                    visible: root.loading
 
                     Layout.fillHeight: true
                     Layout.fillWidth: true
@@ -392,7 +386,7 @@ MainInterface.MainViewLoader {
                     Widgets.BusyIndicatorExt {
                         id: busyIndicator
 
-                        runningDelayed: root.parsing
+                        runningDelayed: root.loading
                         anchors.centerIn: parent
                         z: 1
                     }


=====================================
modules/gui/qt/network/qml/ServicesManage.qml
=====================================
@@ -143,7 +143,7 @@ Widgets.KeyNavigableListView {
     }
 
     Widgets.BusyIndicatorExt {
-        runningDelayed: discoveryModel.parsingPending
+        runningDelayed: discoveryModel.loading
         anchors.centerIn: parent
         color: servicesView.colorContext.fg.primary
         z: 1


=====================================
modules/gui/qt/network/servicesdiscoverymodel.cpp
=====================================
@@ -154,8 +154,8 @@ void ServicesDiscoveryModel::initializeManager()
     m_manager = addons_manager_New( VLC_OBJECT( m_ctx->getIntf() ), &owner );
     assert( m_manager );
 
-    m_parsingPending = true;
-    emit parsingPendingChanged();
+    m_loading = true;
+    emit loadingChanged();
     addons_manager_LoadCatalog( m_manager );
     addons_manager_Gather( m_manager, "repo://" );
 }
@@ -215,9 +215,9 @@ void ServicesDiscoveryModel::addonChanged( ServicesDiscoveryModel::AddonPtr addo
 
 void ServicesDiscoveryModel::discoveryEnded()
 {
-    assert( m_parsingPending );
-    m_parsingPending = false;
-    emit parsingPendingChanged();
+    assert( m_loading );
+    m_loading = false;
+    emit loadingChanged();
 }
 
 ServicesDiscoveryModel::Item::Item( ServicesDiscoveryModel::AddonPtr addon )


=====================================
modules/gui/qt/network/servicesdiscoverymodel.hpp
=====================================
@@ -40,7 +40,7 @@ class ServicesDiscoveryModel : public QAbstractListModel
 public:
 
     Q_PROPERTY(MainCtx* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged FINAL)
-    Q_PROPERTY(bool parsingPending READ getParsingPending NOTIFY parsingPendingChanged FINAL)
+    Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged FINAL)
     Q_PROPERTY(int count READ getCount NOTIFY countChanged FINAL)
 
     enum State // equivalent to addon_state_t
@@ -74,7 +74,7 @@ public:
     void setCtx(MainCtx* ctx);
 
     inline MainCtx* getCtx() const { return m_ctx; }
-    inline bool getParsingPending() const { return m_parsingPending; }
+    inline bool isLoading() const { return m_loading; }
     int getCount() const;
 
     Q_INVOKABLE QMap<QString, QVariant> getDataAt(int idx);
@@ -82,7 +82,7 @@ public:
     Q_INVOKABLE void removeService(int idx);
 
 signals:
-    void parsingPendingChanged();
+    void loadingChanged();
     void countChanged();
     void ctxChanged();
 
@@ -116,7 +116,7 @@ private:
     std::vector<Item> m_items;
     MainCtx* m_ctx = nullptr;
     addons_manager_t* m_manager = nullptr;
-    bool m_parsingPending = false;
+    bool m_loading = false;
 };
 
 #endif // MLServicesDiscoveryModel_HPP



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f7c3a6fb7d56f05f0d7baea8ab26b75cf585bb68...b0a4295efa0c37580edd0e4327a10d81bc4485c5

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f7c3a6fb7d56f05f0d7baea8ab26b75cf585bb68...b0a4295efa0c37580edd0e4327a10d81bc4485c5
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list