[vlc-commits] [Git][videolan/vlc][master] qml: improve handling of defaultPage

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Apr 7 16:57:28 UTC 2022



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


Commits:
76119529 by Prince Gupta at 2022-04-07T16:32:40+00:00
qml: improve handling of defaultPage

delegate History update to the parent, instead of directly handling it
in PageLoader.

- - - - -


11 changed files:

- modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
- modules/gui/qt/medialibrary/qml/MusicDisplay.qml
- modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
- modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoAllDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
- modules/gui/qt/network/qml/DiscoverDisplay.qml
- modules/gui/qt/network/qml/NetworkDisplay.qml
- modules/gui/qt/network/qml/ServicesHomeDisplay.qml
- modules/gui/qt/widgets/qml/PageLoader.qml


Changes:

=====================================
modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
=====================================
@@ -34,7 +34,6 @@ Widgets.PageLoader {
 
     property MLModel model
 
-    defaultPage: "all"
     pageModel: [{
         name: "all",
         component: allArtistsComponent
@@ -43,6 +42,11 @@ Widgets.PageLoader {
         component: artistAlbumsComponent
     }]
 
+    loadDefaultView: function () {
+        History.update(["mc", "music", "artists", "all"])
+        loadPage("all")
+    }
+
     onCurrentItemChanged: {
         model = currentItem.model
     }


=====================================
modules/gui/qt/medialibrary/qml/MusicDisplay.qml
=====================================
@@ -33,7 +33,6 @@ Widgets.PageLoader {
     property var contentModel
     property bool isViewMultiView: true
 
-    defaultPage: "artists"
     pageModel: [{
             displayText: I18n.qtr("Artists"),
             name: "artists",
@@ -57,6 +56,11 @@ Widgets.PageLoader {
         }
     ]
 
+    loadDefaultView: function () {
+        History.update(["mc", "music", "artists"])
+        loadPage("artists")
+    }
+
     onCurrentItemChanged: {
         sortModel = currentItem.sortModel
         contentModel = currentItem.model


=====================================
modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
=====================================
@@ -28,7 +28,9 @@ import "qrc:///style/"
 Widgets.PageLoader {
     id: root
 
-    defaultPage: "all"
+    property var sortModel
+    property var model
+
     pageModel: [{
         name: "all",
         component: genresComponent
@@ -37,8 +39,10 @@ Widgets.PageLoader {
         component: albumGenreComponent
     }]
 
-    property var sortModel
-    property var model
+    loadDefaultView: function () {
+        History.update(["mc", "music", "genres", "all"])
+        loadPage("all")
+    }
 
     onCurrentItemChanged: {
         sortModel = currentItem.sortModel


=====================================
modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
=====================================
@@ -43,8 +43,6 @@ Widgets.PageLoader {
     // Settings
     //---------------------------------------------------------------------------------------------
 
-    defaultPage: "all"
-
     pageModel: [{
         name: "all",
         component: componentAll
@@ -53,6 +51,11 @@ Widgets.PageLoader {
         component: componentList
     }]
 
+    loadDefaultView: function () {
+        History.update(["mc", "music", "playlists", "all"])
+        loadPage("all")
+    }
+
     //---------------------------------------------------------------------------------------------
     // Events
     //---------------------------------------------------------------------------------------------


=====================================
modules/gui/qt/medialibrary/qml/VideoAllDisplay.qml
=====================================
@@ -38,8 +38,6 @@ Widgets.PageLoader {
 
     // Settings
 
-    defaultPage: "base"
-
     pageModel: [{
         name: "base",
         component: componentBase
@@ -48,6 +46,11 @@ Widgets.PageLoader {
         component: componentGroup
     }]
 
+    loadDefaultView: function () {
+        History.update(["mc", "video", "all", "base"])
+        loadPage("base")
+    }
+
     // Events
 
     onCurrentItemChanged: {


=====================================
modules/gui/qt/medialibrary/qml/VideoDisplay.qml
=====================================
@@ -64,8 +64,6 @@ Widgets.PageLoader {
     // Settings
     //---------------------------------------------------------------------------------------------
 
-    defaultPage: "all"
-
     pageModel: [{
             name: "all",
             displayText: I18n.qtr("All"),
@@ -77,6 +75,11 @@ Widgets.PageLoader {
         }
     ]
 
+    loadDefaultView: function () {
+        History.update(["mc", "video", "all"])
+        loadPage("all")
+    }
+
     onCurrentItemChanged: {
         isViewMultiView = (currentItem.isViewMultiView === undefined
                            ||


=====================================
modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
=====================================
@@ -43,8 +43,6 @@ Widgets.PageLoader {
     // Settings
     //---------------------------------------------------------------------------------------------
 
-    defaultPage: "all"
-
     pageModel: [{
         name: "all",
         component: componentAll
@@ -53,6 +51,11 @@ Widgets.PageLoader {
         component: componentList
     }]
 
+    loadDefaultView: function () {
+        History.update(["mc", "video", "playlists", "all"])
+        loadPage("all")
+    }
+
     //---------------------------------------------------------------------------------------------
     // Events
     //---------------------------------------------------------------------------------------------


=====================================
modules/gui/qt/network/qml/DiscoverDisplay.qml
=====================================
@@ -33,9 +33,6 @@ Widgets.PageLoader {
     property var contentModel
     property bool isViewMultiView: false
 
-    //name and properties of the tab to be initially loaded
-    defaultPage: "services"
-
     pageModel: [{
             displayText: I18n.qtr("Services"),
             name: "services",
@@ -47,6 +44,11 @@ Widgets.PageLoader {
         }
     ]
 
+    loadDefaultView: function () {
+        History.update(["mc", "discover", "services"])
+        loadPage("services")
+    }
+
     onCurrentItemChanged: {
         sortModel = currentItem.sortModel
         contentModel = currentItem.model


=====================================
modules/gui/qt/network/qml/NetworkDisplay.qml
=====================================
@@ -38,8 +38,6 @@ Widgets.PageLoader {
 
     // Settings
 
-    defaultPage: "home"
-
     pageModel: [{
         name: "home",
         url: "qrc:///network/NetworkHomeDisplay.qml"
@@ -49,6 +47,11 @@ Widgets.PageLoader {
         guard: function (prop) { return !!prop.tree }
     }]
 
+    loadDefaultView: function() {
+        History.update(["mc", "network", "home"])
+        loadPage("home")
+    }
+
     // Events
     onCurrentItemChanged: {
         sortModel = currentItem.sortModel;


=====================================
modules/gui/qt/network/qml/ServicesHomeDisplay.qml
=====================================
@@ -36,7 +36,6 @@ Widgets.PageLoader {
     property var model
     property Component localMenuDelegate: null
 
-    defaultPage: "all"
     pageModel: [{
         name: "all",
         component: allSourcesComponent
@@ -52,6 +51,11 @@ Widgets.PageLoader {
         guard: function (prop) { return !!prop.tree }
     }]
 
+    loadDefaultView: function() {
+        History.update(["mc", "discover", "services", "all"])
+        loadPage("all")
+    }
+
     onCurrentItemChanged: {
         sortModel = currentItem.sortModel
         model = currentItem.model


=====================================
modules/gui/qt/widgets/qml/PageLoader.qml
=====================================
@@ -22,10 +22,15 @@ FocusScope {
     id: root
 
     property var view: null
-    property string defaultPage: ""
 
     property var pageModel: []
 
+    // loadDefaultView - function ()
+    // a function that loads the default page,
+    // must be implemented by the user of the class
+    // one may use `loadPage(string pageName)` to load the page from 'pageModel'
+    property var loadDefaultView: null
+
     property alias stackView: stackView
 
     signal pageChanged(string page)
@@ -36,17 +41,12 @@ FocusScope {
         loadView()
     }
 
-    // loads the 'defaultPage'
-    // this will also apend History.current with the 'defaultPage' entry
-    function loadDefaultView() {
-        view = null
-    }
-
     function loadView() {
         if (view === null) {
-            var defaultView = {"name": defaultPage, "properties": {}}
-            History.addLeaf({"view": defaultView})
-            root.view = defaultView
+            if (!loadDefaultView)
+                console.error("both 'view' and 'loadDefaultView' is null, history -", JSON.stringify(History.current))
+            else
+                loadDefaultView()
             return
         }
 
@@ -68,6 +68,10 @@ FocusScope {
         root.currentItemChanged(stackView.currentItem)
     }
 
+    function loadPage(page) {
+        view = {"name": page, "properties": {}}
+    }
+
     function setCurrentItemFocus(reason) {
         stackView.setCurrentItemFocus(reason);
     }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/7611952912da91406696b38ce5d7f111df6f9a0d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/7611952912da91406696b38ce5d7f111df6f9a0d
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