[vlc-commits] [Git][videolan/vlc][master] 7 commits: qml: allow to restore all page properties when re-opening a tab

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Sep 16 16:44:40 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
78dfb346 by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: allow to restore all page properties when re-opening a tab

previous implementation was only restoring subview by overriding the
defaultPage of the subview. this caused some issues:

- default was overridden, this is not desirable as the default was no logner
  reliable from the POV of the subview

- the substate of the view wasn't restored, for instance if you opened the page
  of a particular artist, it would restore on the home page of the artists.

- - - - -
e20f0f11 by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: add gard property to the page model

This allows to set conditions that should be met before being allowed to load
a page

- - - - -
8b8ba5b6 by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: load default view when PageLoader fails

- - - - -
f59e7d7a by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: merge view and viewProperties as a single variable

those variables are usually changed simultaneously, qml would trigger an update
request for each variable updated and require detecting that the second call is
idempotent or making assumption regarding the call order to avoid the second
call.

this allows getting a single update point for the view.

- - - - -
86761948 by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: remove the usage of variant

variant is deprecated, var should be used instead

https://doc.qt.io/qt-5/qml-variant.html

- - - - -
00d2b8ed by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: ensure we have a tree when loading network browse view

- - - - -
ccfa4ed9 by Pierre Lamot at 2021-09-16T16:30:17+00:00
qml: use the default loadView implementation in NetworkDisplay

the custom implementation is no longer needed

- - - - -


19 changed files:

- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/maininterface/qml/MainInterface.qml
- modules/gui/qt/medialibrary/qml/MediaGroupList.qml
- modules/gui/qt/medialibrary/qml/MusicGenres.qml
- modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
- modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
- modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
- modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
- modules/gui/qt/medialibrary/qml/VideoGroupsDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
- modules/gui/qt/network/qml/NetworkDisplay.qml
- modules/gui/qt/network/qml/NetworkHomeDeviceListView.qml
- modules/gui/qt/network/qml/NetworkHomeDisplay.qml
- modules/gui/qt/network/qml/ServicesHomeDisplay.qml
- modules/gui/qt/util/navigation_history.cpp
- modules/gui/qt/util/navigation_history.hpp
- modules/gui/qt/widgets/qml/FrostedGlassEffect.qml
- modules/gui/qt/widgets/qml/PageLoader.qml
- modules/gui/qt/widgets/qml/StackViewExt.qml


Changes:

=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -33,19 +33,21 @@ FocusScope {
     id: root
 
     //name and properties of the tab to be initially loaded
-    property string view: ""
-    property var viewProperties: ({})
+    property var view: ({
+        "name": "",
+        "properties": {}
+    })
 
     property alias g_mainDisplay: root
     property bool _inhibitMiniPlayer: false
     property bool _showMiniPlayer: false
-    property var _defaultPages: ({}) // saves last page of view
+    property var _oldViewProperties: ({}) // saves last state of the views
 
     onViewChanged: {
-        viewProperties = _defaultPages[root.view] !== undefined ? ({"defaultPage": _defaultPages[root.view]}) : ({})
+        _oldViewProperties[view.name] = view.properties
         loadView()
     }
-    onViewPropertiesChanged: loadView()
+
     Component.onCompleted: {
         loadView()
         if (medialib && !mainInterface.hasFirstrun)
@@ -54,9 +56,7 @@ FocusScope {
     }
 
     function loadView() {
-        var found = stackView.loadView(root.pageModel, root.view, root.viewProperties)
-        if (stackView.currentItem.view !== undefined)
-            _defaultPages[root.view] = stackView.currentItem.view
+        var found = stackView.loadView(root.pageModel, root.view.name, root.view.properties)
 
         stackView.currentItem.Navigation.parentItem = medialibId
         stackView.currentItem.Navigation.upItem = sourcesBanner
@@ -199,7 +199,10 @@ FocusScope {
                     onItemClicked: {
                         var name = root.tabModel.get(index).name
                         selectedIndex = index
-                        history.push(["mc", name])
+                        if (_oldViewProperties[name] === undefined)
+                            history.push(["mc", name])
+                        else
+                            history.push(["mc", name, _oldViewProperties[name]])
                     }
 
                     Navigation.parentItem: medialibId


=====================================
modules/gui/qt/maininterface/qml/MainInterface.qml
=====================================
@@ -34,7 +34,7 @@ Rectangle {
     property bool _playlistReady: false
 
     property alias g_root: root
-    property variant g_dialogs: dialogsLoader.item
+    property var g_dialogs: dialogsLoader.item
 
     Binding {
         target: VLCStyle.self
@@ -79,11 +79,11 @@ Rectangle {
 
     function loadCurrentHistoryView() {
         var current = history.current
-        if ( !current || !current.view ) {
+        if ( !current || !current.name  || !current.properties ) {
             console.warn("unable to load requested view, undefined")
             return
         }
-        stackView.loadView(root.pageModel, current.view, current.viewProperties)
+        stackView.loadView(root.pageModel, current.name, current.properties)
     }
 
     Connections {
@@ -135,7 +135,7 @@ Rectangle {
                 target: player
                 onPlayingStateChanged: {
                     if (player.playingState === PlayerController.PLAYING_STATE_STOPPED
-                            && history.current.view === "player") {
+                            && history.current.name === "player") {
                         if (history.previousEmpty)
                         {
                             if (medialib)


=====================================
modules/gui/qt/medialibrary/qml/MediaGroupList.qml
=====================================
@@ -59,7 +59,7 @@ FocusScope {
     // Signals
     //---------------------------------------------------------------------------------------------
 
-    signal showList(variant model, int reason)
+    signal showList(var model, int reason)
 
     //---------------------------------------------------------------------------------------------
     // Events


=====================================
modules/gui/qt/medialibrary/qml/MusicGenres.qml
=====================================
@@ -39,7 +39,7 @@ FocusScope {
 
     property alias _currentView: view.currentItem
 
-    signal showAlbumView(variant id, string name, int reason)
+    signal showAlbumView(var id, string name, int reason)
 
     onInitialIndexChanged:  resetFocus()
 


=====================================
modules/gui/qt/medialibrary/qml/MusicPlaylistsDisplay.qml
=====================================
@@ -35,8 +35,8 @@ Widgets.PageLoader {
 
     property bool isViewMultiView: true
 
-    property variant model
-    property variant sortModel
+    property var model
+    property var sortModel
 
     //---------------------------------------------------------------------------------------------
     // Settings


=====================================
modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
=====================================
@@ -39,7 +39,7 @@ MainInterface.MainTableView {
     //---------------------------------------------------------------------------------------------
     // Private
 
-    property variant _item: null
+    property var _item: null
 
     property bool _before: true
 


=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaDisplay.qml
=====================================
@@ -39,7 +39,7 @@ FocusScope {
     readonly property int currentIndex: view.currentIndex
 
     property int     initialIndex: 0
-    property variant initialId
+    property var initialId
     property string  initialName
 
     // NOTE: Specify an optionnal header for the view.


=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
=====================================
@@ -71,7 +71,7 @@ FocusScope {
     // Signals
     //---------------------------------------------------------------------------------------------
 
-    signal showList(variant model, int reason)
+    signal showList(var model, int reason)
 
     //---------------------------------------------------------------------------------------------
     // Events


=====================================
modules/gui/qt/medialibrary/qml/VideoGroupsDisplay.qml
=====================================
@@ -37,8 +37,8 @@ Widgets.PageLoader {
 
     property bool isViewMultiView: true
 
-    property variant model
-    property variant sortModel
+    property var model
+    property var sortModel
 
     //---------------------------------------------------------------------------------------------
     // Settings


=====================================
modules/gui/qt/medialibrary/qml/VideoPlaylistsDisplay.qml
=====================================
@@ -35,8 +35,8 @@ Widgets.PageLoader {
 
     property bool isViewMultiView: true
 
-    property variant model
-    property variant sortModel
+    property var model
+    property var sortModel
 
     //---------------------------------------------------------------------------------------------
     // Settings


=====================================
modules/gui/qt/network/qml/NetworkDisplay.qml
=====================================
@@ -34,8 +34,6 @@ Widgets.PageLoader {
     property var contentModel
     property bool isViewMultiView: true
 
-    property var tree: undefined
-
     property Component localMenuDelegate
 
     // Settings
@@ -47,11 +45,11 @@ Widgets.PageLoader {
         url: "qrc:///network/NetworkHomeDisplay.qml"
     }, {
         name: "browse",
-        component: browseComponent
+        component: browseComponent,
+        guard: function (prop) { return !!prop.tree }
     }]
 
     // Events
-
     onCurrentItemChanged: {
         sortModel = currentItem.sortModel;
         contentModel = currentItem.model;
@@ -60,29 +58,10 @@ Widgets.PageLoader {
                            ||
                            currentItem.isViewMultiView);
 
-        if (tree) {
-            if (view == "home")
-                localMenuDelegate = null;
-            else
-                localMenuDelegate = componentBar;
-        } else {
-            localMenuDelegate = null;
-        }
-    }
-
-    // Functions
-    // PageLoader reimplementation
-
-    // FIXME: Maybe this could be done with a 'guard' mechanism on the pageModel.
-    function loadView() {
-        if (tree)
-            stackView.loadView(pageModel, view, viewProperties);
+        if (view.name === "browse")
+            localMenuDelegate = componentBar
         else
-            stackView.loadView(pageModel, "home", viewProperties);
-
-        stackView.currentItem.Navigation.parentItem = root;
-
-        currentItemChanged(stackView.currentItem);
+            localMenuDelegate = null
     }
 
     // Connections
@@ -91,10 +70,7 @@ Widgets.PageLoader {
         target: stackView.currentItem
 
         onBrowse: {
-            root.tree = tree;
-
             history.push(["mc", "network", "browse", { tree: tree }]);
-
             stackView.currentItem.setCurrentItemFocus(reason);
         }
     }
@@ -119,7 +95,7 @@ Widgets.PageLoader {
         id: componentBar
 
         NetworkAddressbar {
-            path: view === "browse" ? root.stackView.currentItem.providerModel.path : []
+            path: view.name === "browse" ? root.stackView.currentItem.providerModel.path : []
 
             onHomeButtonClicked: {
                 history.push(["mc", "network", "home"])


=====================================
modules/gui/qt/network/qml/NetworkHomeDeviceListView.qml
=====================================
@@ -37,7 +37,7 @@ FocusScope {
 
     property int _currentIndex: -1
 
-    signal browse(variant tree, int reason)
+    signal browse(var tree, int reason)
 
     on_CurrentIndexChanged: {
         deviceListView.currentIndex = _currentIndex


=====================================
modules/gui/qt/network/qml/NetworkHomeDisplay.qml
=====================================
@@ -33,7 +33,7 @@ FocusScope {
 
     readonly property bool isViewMultiView: false
 
-    signal browse(variant tree, int reason)
+    signal browse(var tree, int reason)
 
     Component.onCompleted: resetFocus()
     onActiveFocusChanged: resetFocus()


=====================================
modules/gui/qt/network/qml/ServicesHomeDisplay.qml
=====================================
@@ -48,7 +48,8 @@ Widgets.PageLoader {
         component: sourceRootComponent
     }, {
         name: "source_browse",
-        component: sourceBrowseComponent
+        component: sourceBrowseComponent,
+        guard: function (prop) { return !!prop.tree }
     }]
 
     onCurrentItemChanged: {


=====================================
modules/gui/qt/util/navigation_history.cpp
=====================================
@@ -32,10 +32,12 @@ static void pushListRec(QVariantMap& itemMap, QVariantList::const_iterator it, Q
         return;
     if(it->canConvert<QString>())
     {
-        itemMap["view"] = it->toString();
-        QVariantMap subMap;
-        pushListRec(subMap, ++it, end);
-        itemMap["viewProperties"] = subMap;
+        QVariantMap subViewMap;
+        subViewMap["name"] = it->toString();
+        QVariantMap subViewProperties;
+        pushListRec(subViewProperties, ++it, end);
+        subViewMap["properties"] = subViewProperties;
+        itemMap["view"] = subViewMap;
     }
     else if ( it->canConvert<QVariantMap>() )
     {
@@ -97,7 +99,12 @@ void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostActio
 {
     QVariantMap itemMap;
     pushListRec(itemMap, itemList.cbegin(), itemList.cend());
-    push(itemMap, postAction);
+    if (!itemMap.contains("view"))
+        return;
+    QVariant rootView = itemMap["view"];
+    if (!rootView.canConvert(QVariant::Map))
+        return;
+    push(rootView.toMap(), postAction);
 }
 
 
@@ -112,7 +119,12 @@ void NavigationHistory::update(QVariantList itemList)
 {
     QVariantMap itemMap;
     pushListRec(itemMap, itemList.cbegin(), itemList.cend());
-    update(itemMap);
+    if (!itemMap.contains("view"))
+        return;
+    QVariant rootView = itemMap["view"];
+    if (!rootView.canConvert(QVariant::Map))
+        return;
+    update(rootView.toMap());
 }
 
 void NavigationHistory::previous(PostAction postAction)


=====================================
modules/gui/qt/util/navigation_history.hpp
=====================================
@@ -34,11 +34,13 @@ public slots:
      *
      * \code
      * push({
-     *   view: "foo", //push the view foo
-     *   viewProperties: {
-     *      view : "bar",  //the sub view "bar"
-     *      viewProperties: {
-     *         baz: "plop" //the property baz will be set in the view "bar"
+     *   name: "foo", //push the view foo
+     *   properties: {
+     *      view: { //the sub view "bar"
+     *          name: "bar",
+     *          properties: {
+     *              baz: "plop" //the property baz will be set in the view "bar"
+     *          }
      *      }
      *   }
      * }, History.Go)


=====================================
modules/gui/qt/widgets/qml/FrostedGlassEffect.qml
=====================================
@@ -24,8 +24,8 @@ import "qrc:///style/"
 Rectangle {
     id: effect
 
-    property variant source
-    property variant sourceRect: undefined
+    property var source
+    property var sourceRect: undefined
 
     property bool active: true
 
@@ -59,7 +59,7 @@ Rectangle {
             ShaderEffect {
                 id: effect2
 
-                property variant source: ShaderEffectSource {
+                property var source: ShaderEffectSource {
                     sourceItem: effect1
                     visible: true
                 }


=====================================
modules/gui/qt/widgets/qml/PageLoader.qml
=====================================
@@ -21,9 +21,10 @@ import org.videolan.vlc 0.1
 FocusScope {
     id: root
 
-    property string view: defaultPage
-    property var viewProperties: ({})
-
+    property var view: ({
+        "name": defaultPage,
+        "properties": {}
+    })
     property string defaultPage: ""
 
     property var pageModel: []
@@ -35,18 +36,18 @@ FocusScope {
 
     Component.onCompleted: loadView()
     onViewChanged: {
-        viewProperties = {}
         loadView()
     }
-    onViewPropertiesChanged: loadView()
 
     function loadDefaultView() {
-        root.view = defaultPage
-        root.viewProperties = ({})
+        root.view = {
+            "name": defaultPage,
+            "properties": {}
+        }
     }
 
     function loadView() {
-        if (view === "") {
+        if (view.name === "") {
             console.error("view is not defined")
             return
         }
@@ -54,9 +55,11 @@ FocusScope {
             console.error("pageModel is not defined")
             return
         }
-        var found = stackView.loadView(root.pageModel, view, viewProperties)
-        if (!found)
-            stackView.replace(root.pageModel[0].component)
+        var found = stackView.loadView(root.pageModel, view.name, view.properties)
+        if (!found) {
+            loadDefaultView()
+            return
+        }
 
         stackView.currentItem.Navigation.parentItem = root
         root.currentItemChanged(stackView.currentItem)


=====================================
modules/gui/qt/widgets/qml/StackViewExt.qml
=====================================
@@ -79,6 +79,10 @@ StackView {
         {
             var model = viewModel[tab]
             if (model.name === view) {
+                if (model.guard !== undefined && typeof model.guard === "function" && !model.guard(viewProperties)) {
+                    continue //we're not allowed to load this page
+                }
+
                 //we can't use push(url, properties) as Qt interprets viewProperties
                 //as a second component to load
                 var component = undefined



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/be436e0ed29642489af90a1ca2cabbca38a511c6...ccfa4ed95c606f480ce45e128696edfe1338edd7

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




More information about the vlc-commits mailing list