[vlc-commits] [Git][videolan/vlc][master] 6 commits: qml/MainCtx: allow modification and quering of setting values

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Mar 14 08:50:19 UTC 2022



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


Commits:
9cc3f302 by Prince Gupta at 2022-03-14T08:31:16+00:00
qml/MainCtx: allow modification and quering of setting values

- - - - -
2347cf71 by Prince Gupta at 2022-03-14T08:31:16+00:00
qt: implement addLeaf function in navigation

- - - - -
9457692d by Prince Gupta at 2022-03-14T08:31:16+00:00
qml: update History when loading defaultPage of PageLoader

- - - - -
4ab7a510 by Prince Gupta at 2022-03-14T08:31:16+00:00
qt: implement viewPath property in History

- - - - -
fa5af22c by Prince Gupta at 2022-03-14T08:31:16+00:00
qml: implement ModelSortSettinghandler

- - - - -
40a81eee by Prince Gupta at 2022-03-14T08:31:16+00:00
qml: preserve sort criteria and order of views

- - - - -


10 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/util/navigation_history.cpp
- modules/gui/qt/util/navigation_history.hpp
- + modules/gui/qt/util/qml/ModelSortSettingHandler.qml
- modules/gui/qt/vlc.qrc
- modules/gui/qt/widgets/qml/PageLoader.qml
- modules/gui/qt/widgets/qml/StackViewExt.qml


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -866,6 +866,7 @@ libqt_plugin_la_QML = \
 	gui/qt/style/qmldir \
 	gui/qt/util/qml/Helpers.js \
 	gui/qt/util/qml/SelectableDelegateModel.qml \
+	gui/qt/util/qml/ModelSortSettingHandler.qml \
 	gui/qt/util/qml/MultipleBinding.qml \
 	gui/qt/util/qml/FlickableScrollHandler.qml \
 	gui/qt/util/qml/ViewDragAutoScrollHandler.qml \


=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -843,3 +843,13 @@ QWindow *MainCtx::intfMainWindow() const
     else
         return nullptr;
 }
+
+QVariant MainCtx::settingValue(const QString &key, const QVariant &defaultValue) const
+{
+    return settings->value(key, defaultValue);
+}
+
+void MainCtx::setSettingValue(const QString &key, const QVariant &value)
+{
+    settings->setValue(key, value);
+}


=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -282,6 +282,9 @@ public:
     
     QWindow *intfMainWindow() const;
 
+    Q_INVOKABLE QVariant settingValue(const QString &key, const QVariant &defaultValue) const;
+    Q_INVOKABLE void setSettingValue(const QString &key, const QVariant &value);
+
 protected:
     /* Systray */
     void createSystray();


=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -28,6 +28,7 @@ import "qrc:///widgets/" as Widgets
 import "qrc:///playlist/" as PL
 import "qrc:///player/" as P
 
+import "qrc:///util/" as Util
 import "qrc:///util/Helpers.js" as Helpers
 
 FocusScope {
@@ -187,6 +188,16 @@ FocusScope {
         backend.addAndPlay(ids);
     }
 
+    Util.ModelSortSettingHandler {
+        id: modelSortSettingHandler
+    }
+
+    Connections {
+        target: sourcesBanner
+
+        onContentModelChanged: modelSortSettingHandler.set(sourcesBanner.contentModel, History.viewPath)
+    }
+
     Rectangle {
         color: VLCStyle.colors.bg
         anchors.fill: parent


=====================================
modules/gui/qt/util/navigation_history.cpp
=====================================
@@ -3,6 +3,7 @@
 #include "network/networkmediamodel.hpp"
 #include "medialibrary/mlqmltypes.hpp"
 
+
 NavigationHistory::NavigationHistory(QObject *parent)
     : QObject(parent)
 {
@@ -23,7 +24,10 @@ void NavigationHistory::push(QVariantMap item, PostAction postAction)
     m_history.push_back(item);
     emit previousEmptyChanged(false);
     if (postAction == PostAction::Go)
+    {
+        updateViewPath();
         emit currentChanged(m_history.back());
+    }
 }
 
 static void pushListRec(QVariantMap& itemMap, QVariantList::const_iterator it, QVariantList::const_iterator end )
@@ -48,6 +52,39 @@ static void pushListRec(QVariantMap& itemMap, QVariantList::const_iterator it, Q
     }
 }
 
+static void addLeafRec(QVariant &item, const QVariantMap &leaf)
+{
+    auto itemMap = item.toMap();
+    if (itemMap.contains("view"))
+    {
+        QVariant viewProps = itemMap.value("view");
+        addLeafRec(viewProps, leaf);
+        itemMap["view"] = viewProps;
+    }
+    else if (itemMap.contains("properties"))
+    {
+        QVariant propsVar = itemMap.value("properties");
+        const auto propsMap = propsVar.toMap();
+        if (propsMap.empty())
+        {
+            itemMap["properties"] = leaf;
+        }
+        else
+        {
+            addLeafRec(propsVar, leaf);
+            itemMap["properties"] = propsVar;
+        }
+    }
+    else
+    {
+        // invalid node?
+        return;
+    }
+
+    //overwrite item QVariant
+    item = itemMap;
+}
+
 
 static bool isNodeValid(QVariant& value)
 {
@@ -94,6 +131,15 @@ static bool isNodeValid(QVariant& value)
     return false;
 }
 
+static QString getViewPath(QVariantMap map)
+{
+    QString r;
+    if (map.contains("view"))
+        r = getViewPath(map.value("view").toMap());
+    else if (map.contains("name"))
+        r = "/" + map.value("name").toString() + getViewPath(map.value("properties").toMap());
+    return r;
+}
 
 void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostAction postAction)
 {
@@ -113,6 +159,7 @@ void NavigationHistory::update(QVariantMap item)
     int length = m_history.length();
     assert(length >= 1);
     m_history.back() = item;
+    updateViewPath();
 }
 
 void NavigationHistory::update(QVariantList itemList)
@@ -127,6 +174,13 @@ void NavigationHistory::update(QVariantList itemList)
     update(rootView.toMap());
 }
 
+void NavigationHistory::addLeaf(QVariantMap itemMap)
+{
+    assert(m_history.size() >= 1);
+    addLeafRec(m_history.back(), itemMap);
+    updateViewPath();
+}
+
 void NavigationHistory::previous(PostAction postAction)
 {
     if (m_history.count() == 1)
@@ -145,3 +199,18 @@ void NavigationHistory::previous(PostAction postAction)
     if (postAction == PostAction::Go)
         emit currentChanged( m_history.back() );
 }
+
+void NavigationHistory::updateViewPath()
+{
+    const auto viewPath = getViewPath(getCurrent().toMap());
+    if (viewPath == m_viewPath)
+        return;
+
+    m_viewPath = viewPath;
+    emit viewPathChanged( m_viewPath );
+}
+
+QString NavigationHistory::viewPath() const
+{
+    return m_viewPath;
+}


=====================================
modules/gui/qt/util/navigation_history.hpp
=====================================
@@ -10,6 +10,7 @@ class NavigationHistory : public QObject
 public:
     Q_PROPERTY(QVariant current READ getCurrent NOTIFY currentChanged FINAL)
     Q_PROPERTY(bool previousEmpty READ isPreviousEmpty NOTIFY previousEmptyChanged FINAL)
+    Q_PROPERTY(QString viewPath READ viewPath NOTIFY viewPathChanged FINAL)
 
     enum class PostAction{
         Stay,
@@ -22,10 +23,12 @@ public:
 
     QVariant getCurrent();
     bool isPreviousEmpty();
+    QString viewPath() const;
 
 signals:
     void currentChanged(QVariant current);
     void previousEmptyChanged(bool empty);
+    void viewPathChanged(QString viewPath);
 
 public slots:
     /**
@@ -79,11 +82,22 @@ public slots:
      */
     Q_INVOKABLE void update(QVariantList itemList);
 
+    /**
+     * @brief same as @a push(QVariantList) but modify the last (current) item's tail instead of insterting a new one
+     *
+     * @see push
+     */
+    Q_INVOKABLE void addLeaf(QVariantMap itemMap);
+
+
     // Go to previous page
     void previous( PostAction = PostAction::Go );
 
 private:
+    void updateViewPath();
+
     QVariantList m_history;
+    QString m_viewPath;
 };
 
 #endif // NAVIGATION_HISTORY_HPP


=====================================
modules/gui/qt/util/qml/ModelSortSettingHandler.qml
=====================================
@@ -0,0 +1,66 @@
+
+/*****************************************************************************
+ * Copyright (C) 2022 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+import QtQml 2.11
+
+import org.videolan.vlc 0.1
+
+QtObject {
+    id: root
+
+    property var _model: null
+    property string _key: ""
+
+    readonly property string _sortCriteriaKey: "sortCriteria/" + _key
+    readonly property string _sortOrderKey: "sortOrder/" + _key
+
+    property var _sortCriteriaConnection: Connections {
+        target: !!root._model ? root._model : null
+
+        enabled: !!root._model && root._model.hasOwnProperty("sortCriteria")
+
+        onSortCriteriaChanged: {
+            MainCtx.setSettingValue(root._sortCriteriaKey, _model.sortCriteria)
+        }
+    }
+
+    property var _sortOrderConnection: Connections {
+        target: !!root._model ? root._model : null
+
+        enabled: !!root._model && root._model.hasOwnProperty("sortOrder")
+
+        onSortOrderChanged: {
+            MainCtx.setSettingValue(root._sortOrderKey, root._model.sortOrder)
+        }
+    }
+
+    function set(model, key) {
+        _model = model
+        _key = key
+
+        if (!_model)
+            return
+
+        if (_model.hasOwnProperty("sortCriteria"))
+            _model.sortCriteria = MainCtx.settingValue(_sortCriteriaKey, _model.sortCriteria)
+
+        // MainCtx.settingValue seems to change int -> string
+        if (_model.hasOwnProperty("sortOrder"))
+            _model.sortOrder = parseInt(MainCtx.settingValue(_sortOrderKey, _model.sortOrder))
+    }
+}


=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -27,6 +27,7 @@
         <file alias="SelectableDelegateModel.qml">util/qml/SelectableDelegateModel.qml</file>
         <file alias="Helpers.js">util/qml/Helpers.js</file>
         <file alias="MultipleBinding.qml">util/qml/MultipleBinding.qml</file>
+        <file alias="ModelSortSettingHandler.qml">util/qml/ModelSortSettingHandler.qml</file>
         <file alias="FlickableScrollHandler.qml">util/qml/FlickableScrollHandler.qml</file>
         <file alias="ViewDragAutoScrollHandler.qml">util/qml/ViewDragAutoScrollHandler.qml</file>
         <file alias="BindingRev8.qml">util/qml/BindingRev8.qml</file>


=====================================
modules/gui/qt/widgets/qml/PageLoader.qml
=====================================
@@ -21,10 +21,7 @@ import org.videolan.vlc 0.1
 FocusScope {
     id: root
 
-    property var view: ({
-        "name": defaultPage,
-        "properties": {}
-    })
+    property var view: null
     property string defaultPage: ""
 
     property var pageModel: []
@@ -39,14 +36,14 @@ FocusScope {
         loadView()
     }
 
-    function loadDefaultView() {
-        root.view = {
-            "name": defaultPage,
-            "properties": {}
+    function loadView() {
+        if (view === null) {
+            var defaultView = {"name": defaultPage, "properties": {}}
+            History.addLeaf({"view": defaultView})
+            root.view = defaultView
+            return
         }
-    }
 
-    function loadView() {
         if (view.name === "") {
             console.error("view is not defined")
             return
@@ -57,7 +54,7 @@ FocusScope {
         }
         var found = stackView.loadView(root.pageModel, view.name, view.properties)
         if (!found) {
-            loadDefaultView()
+            console.error("failed to load", JSON.stringify(History.current))
             return
         }
 


=====================================
modules/gui/qt/widgets/qml/StackViewExt.qml
=====================================
@@ -62,13 +62,9 @@ StackView {
             root.currentItem.dismiss()
 
         if (view === _currentView) {
-            if (Object.keys(viewProperties).length === 0 && root.currentItem.hasOwnProperty("loadDefaultView") ) {
-                root.currentItem.loadDefaultView()
-            } else {
-                for ( var viewProp in viewProperties ) {
-                    if ( root.currentItem.hasOwnProperty(viewProp) ) {
-                        root.currentItem[viewProp] = viewProperties[viewProp]
-                    }
+            for ( var viewProp in viewProperties ) {
+                if ( root.currentItem.hasOwnProperty(viewProp) ) {
+                    root.currentItem[viewProp] = viewProperties[viewProp]
                 }
             }
             return true



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6f82cea3b7f542d557d4ea53adcd2d65aab9f002...40a81eeef817447d601d0f031e06eca6a8e609c9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6f82cea3b7f542d557d4ea53adcd2d65aab9f002...40a81eeef817447d601d0f031e06eca6a8e609c9
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