[vlc-commits] [Git][videolan/vlc][master] qml: instantiate video models on demand
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Tue Mar 29 08:28:47 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
460cd3d4 by Pierre Lamot at 2022-03-29T08:11:20+00:00
qml: instantiate video models on demand
having the three models always present, means that the data (at least the first
chuck) is loaded 3 times, and will be reloaded 3 times every time a database
event triggers a refresh of the model.
- - - - -
1 changed file:
- modules/gui/qt/medialibrary/qml/VideoAllSubDisplay.qml
Changes:
=====================================
modules/gui/qt/medialibrary/qml/VideoAllSubDisplay.qml
=====================================
@@ -40,16 +40,7 @@ VideoAll {
// Private
- property var _meta: {
- var grouping = MainCtx.grouping;
-
- if (grouping === MainCtx.GROUPING_NONE)
- return metaVideo
- else if (grouping === MainCtx.GROUPING_NAME)
- return metaGroup
- else if (grouping === MainCtx.GROUPING_FOLDER)
- return metaFolder
- }
+ property var _meta: null
// Signals
@@ -59,12 +50,25 @@ VideoAll {
anchors.fill: parent
- model: _meta.model
+ model: !!_meta ? _meta.model : null
- contextMenu: _meta.contextMenu
+ contextMenu: !!_meta ? _meta.contextMenu : null
// Functions
+ function _updateMetaModel(groupping) {
+ if (root._meta)
+ root._meta.destroy()
+
+ if (groupping === MainCtx.GROUPING_NAME) {
+ root._meta = groupComponent.createObject(root)
+ } else if (groupping === MainCtx.GROUPING_FOLDER) {
+ root._meta = folderComponent.createObject(root)
+ } else {
+ root._meta = videoComponent.createObject(root)
+ }
+ }
+
function getLabelGroup(model, string) {
if (!model) return ""
@@ -100,90 +104,109 @@ VideoAll {
// Children
- QtObject {
- id: metaVideo
+ Connections {
+ target: MainCtx
+ onGroupingChanged: root._updateMetaModel(MainCtx.grouping)
+ }
- property var model: MLVideoModel { ml: MediaLib }
+ Component.onCompleted: root._updateMetaModel(MainCtx.grouping)
- property var contextMenu: VideoContextMenu { model: metaVideo.model }
+ Component {
+ id: videoComponent
- function onAction(indexes) {
- g_mainDisplay.showPlayer()
+ QtObject {
+ id: metaVideo
- MediaLib.addAndPlay(model.getIdsForIndexes(indexes))
- }
+ property var model: MLVideoModel { ml: MediaLib }
- function onDoubleClick(object) { g_mainDisplay.play(MediaLib, object.id) }
+ property var contextMenu: VideoContextMenu { model: metaVideo.model }
- function onLabelGrid(object) { return root.getLabel(object) }
- function onLabelList(object) { return root.getLabel(object) }
+ function onAction(indexes) {
+ g_mainDisplay.showPlayer()
+
+ MediaLib.addAndPlay(model.getIdsForIndexes(indexes))
+ }
+
+ function onDoubleClick(object) { g_mainDisplay.play(MediaLib, object.id) }
+
+ function onLabelGrid(object) { return root.getLabel(object) }
+ function onLabelList(object) { return root.getLabel(object) }
+ }
}
- QtObject {
- id: metaGroup
+ Component {
+ id: groupComponent
- property var model: MLVideoGroupsModel { ml: MediaLib }
+ QtObject {
+ id: metaGroup
- property var contextMenu: VideoGroupsContextMenu { model: metaGroup.model }
+ property var model: MLVideoGroupsModel { ml: MediaLib }
- function onAction(indexes) {
- var index = indexes[0]
+ property var contextMenu: VideoGroupsContextMenu { model: metaGroup.model }
- var object = model.getDataAt(index);
+ function onAction(indexes) {
+ var index = indexes[0]
- if (object.isVideo) {
- g_mainDisplay.showPlayer()
+ var object = model.getDataAt(index);
- MediaLib.addAndPlay(model.getIdsForIndexes(indexes))
+ if (object.isVideo) {
+ g_mainDisplay.showPlayer()
- return
+ MediaLib.addAndPlay(model.getIdsForIndexes(indexes))
+
+ return
+ }
+
+ root.showList(object, Qt.TabFocusReason)
}
- root.showList(object, Qt.TabFocusReason)
- }
+ function onDoubleClick(object) {
+ if (object.isVideo) {
+ g_mainDisplay.play(MediaLib, object.id)
- function onDoubleClick(object) {
- if (object.isVideo) {
- g_mainDisplay.play(MediaLib, object.id)
+ return
+ }
- return
+ root.showList(object, Qt.MouseFocusReason)
}
- root.showList(object, Qt.MouseFocusReason)
- }
-
- function onLabelGrid(object) {
- return root.getLabelGroup(object, I18n.qtr("%1 Videos"))
- }
+ function onLabelGrid(object) {
+ return root.getLabelGroup(object, I18n.qtr("%1 Videos"))
+ }
- function onLabelList(object) {
- return root.getLabelGroup(object, I18n.qtr("%1"))
+ function onLabelList(object) {
+ return root.getLabelGroup(object, I18n.qtr("%1"))
+ }
}
}
- QtObject {
- id: metaFolder
+ Component {
+ id: folderComponent
- property var model: MLVideoFoldersModel { ml: MediaLib }
+ QtObject {
+ id: metaFolder
- property var contextMenu: VideoFoldersContextMenu { model: metaFolder.model }
+ property var model: MLVideoFoldersModel { ml: MediaLib }
- function onAction(indexes) {
- var index = indexes[0]
+ property var contextMenu: VideoFoldersContextMenu { model: metaFolder.model }
- root.showList(model.getDataAt(index), Qt.TabFocusReason)
- }
+ function onAction(indexes) {
+ var index = indexes[0]
- function onDoubleClick(object) {
- root.showList(object, Qt.MouseFocusReason)
- }
+ root.showList(model.getDataAt(index), Qt.TabFocusReason)
+ }
- function onLabelGrid(object) {
- return root.getLabelGroup(object, I18n.qtr("%1 Videos"))
- }
+ function onDoubleClick(object) {
+ root.showList(object, Qt.MouseFocusReason)
+ }
+
+ function onLabelGrid(object) {
+ return root.getLabelGroup(object, I18n.qtr("%1 Videos"))
+ }
- function onLabelList(object) {
- return root.getLabelGroup(object, I18n.qtr("%1"))
+ function onLabelList(object) {
+ return root.getLabelGroup(object, I18n.qtr("%1"))
+ }
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/460cd3d44260af5076bc9589f756a3f6d2dd3c0c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/460cd3d44260af5076bc9589f756a3f6d2dd3c0c
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