diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp index 3d14f02b1a..49e2f59a95 100644 --- a/modules/gui/qt/medialibrary/mlbasemodel.cpp +++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp @@ -40,8 +40,8 @@ MLBaseModel::MLBaseModel(QObject *parent) { connect( this, &MLBaseModel::resetRequested, this, &MLBaseModel::onResetRequested ); - connect( this, &MLBaseModel::mlChanged, this, &MLBaseModel::hasContentChanged ); - connect( this, &MLBaseModel::countChanged, this, &MLBaseModel::hasContentChanged ); + connect( this, &MLBaseModel::mlChanged, this, &MLBaseModel::isReadyChanged ); + connect( this, &MLBaseModel::countChanged, this, &MLBaseModel::isReadyChanged ); } /* For std::unique_ptr, see Effective Modern C++, Item 22 */ @@ -468,6 +468,8 @@ void MLBaseModel::validateCache() const this, &MLBaseModel::onCacheBeginMoveRows); m_cache->initCount(); + + emit isReadyChanged(); } @@ -482,7 +484,10 @@ void MLBaseModel::resetCache() void MLBaseModel::invalidateCache() { if (m_cache) + { m_cache->invalidate(); + emit isReadyChanged(); + } else validateCache(); } @@ -624,7 +629,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::hasContent() const +bool MLBaseModel::isReady() const { - return m_mediaLib && (getCount() > 0); + return (m_mediaLib && m_cache && (m_cache->count() != COUNT_UNINITIALIZED)); } diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp index 7088757bd1..a1cab4e47a 100644 --- a/modules/gui/qt/medialibrary/mlbasemodel.hpp +++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp @@ -57,7 +57,8 @@ class MLBaseModel : public QAbstractListModel Q_PROPERTY(unsigned int count READ getCount NOTIFY countChanged FINAL) - Q_PROPERTY(bool hasContent READ hasContent NOTIFY hasContentChanged FINAL) + // isReady is true when ml is not null pointer and cache count is not uninitialized + Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged FINAL) public: explicit MLBaseModel(QObject *parent = nullptr); @@ -88,7 +89,7 @@ signals: void sortOrderChanged(); void sortCriteriaChanged(); void countChanged(unsigned int) const; - void hasContentChanged(); + void isReadyChanged() const; protected slots: void onResetRequested(); @@ -174,7 +175,7 @@ public: int rowCount(const QModelIndex &parent = {}) const override; virtual unsigned int getCount() const; - bool hasContent() const; + bool isReady() const; private: void onCacheDataChanged(int first, int last); diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml index 576a24b4ed..5f191e9a26 100644 --- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml +++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml @@ -332,7 +332,7 @@ FocusScope { EmptyLabelButton { anchors.fill: parent - visible: !albumModelId.hasContent + visible: albumModelId.isReady && (albumModelId.count <= 0) focus: visible text: I18n.qtr("No albums found\nPlease try adding sources, by going to the Browse tab") Navigation.parentItem: root diff --git a/modules/gui/qt/medialibrary/qml/MusicAllArtists.qml b/modules/gui/qt/medialibrary/qml/MusicAllArtists.qml index e662bef31b..bf05b2a8c2 100644 --- a/modules/gui/qt/medialibrary/qml/MusicAllArtists.qml +++ b/modules/gui/qt/medialibrary/qml/MusicAllArtists.qml @@ -273,7 +273,7 @@ FocusScope { EmptyLabelButton { anchors.fill: parent - visible: !artistModel.hasContent + visible: artistModel.isReady && (artistModel.count <= 0) focus: visible text: I18n.qtr("No artists found\nPlease try adding sources, by going to the Browse tab") Navigation.parentItem: root diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml index bac1b7d423..314221d021 100644 --- a/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml +++ b/modules/gui/qt/medialibrary/qml/MusicArtistsAlbums.qml @@ -250,7 +250,7 @@ FocusScope { EmptyLabelButton { anchors.fill: parent - visible: !artistModel.hasContent + visible: artistModel.isReady && (artistModel.count <= 0) focus: visible text: I18n.qtr("No artists found\nPlease try adding sources, by going to the Browse tab") Navigation.parentItem: root diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml index 90c0848ed9..edab9b0fb2 100644 --- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml +++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml @@ -342,7 +342,7 @@ FocusScope { EmptyLabelButton { anchors.fill: parent - visible: !genreModel.hasContent + visible: genreModel.isReady && (genreModel.count <= 0) focus: visible text: I18n.qtr("No genres found\nPlease try adding sources, by going to the Browse tab") Navigation.parentItem: root diff --git a/modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml index 9ef5b88b24..2afebe974d 100644 --- a/modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml +++ b/modules/gui/qt/medialibrary/qml/MusicTracksDisplay.qml @@ -74,7 +74,7 @@ FocusScope { EmptyLabelButton { anchors.fill: parent - visible: !tracklistdisplay_id.model.hasContent + visible: tracklistdisplay_id.model.isReady && (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 diff --git a/modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml b/modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml index 095d2eccb8..176062ea68 100644 --- a/modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml +++ b/modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml @@ -197,7 +197,7 @@ FocusScope { EmptyLabelButton { anchors.fill: parent - visible: !model.hasContent + visible: model.isReady && (model.count <= 0) focus: visible diff --git a/modules/gui/qt/medialibrary/qml/VideoAll.qml b/modules/gui/qt/medialibrary/qml/VideoAll.qml index 581c30c028..0d8873e900 100644 --- a/modules/gui/qt/medialibrary/qml/VideoAll.qml +++ b/modules/gui/qt/medialibrary/qml/VideoAll.qml @@ -379,7 +379,7 @@ FocusScope { coverWidth : VLCStyle.dp(182, VLCStyle.scale) coverHeight: VLCStyle.dp(114, VLCStyle.scale) - visible: !model.hasContent + visible: model.isReady && (model.count <= 0) focus: visible