[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt/mlbasemodel: Fix the 'isReady' comment

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jun 19 12:09:07 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
2bfed6f2 by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qt/mlbasemodel: Fix the 'isReady' comment

- - - - -
3ba4dbfe by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qml/MainViewLoader: Fix the 'currentComponent' property

- - - - -
8fa90e89 by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qml/MediaGroupDisplay: Remove unnecessary 'parentId' setting

- - - - -
ad2e5526 by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qml/VideoAll: Code cleanup

No functional changes.

- - - - -
75c1c778 by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qt/navigation_history: Add the focus reason support

- - - - -
f58bcdfc by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qml/PageLoader: Apply the history focus reason

- - - - -
7b115a86 by Benjamin Arnaud at 2023-06-19T11:38:07+00:00
qml: Pass the focus reason to the history

- - - - -


14 changed files:

- modules/gui/qt/maininterface/qml/MainInterface.qml
- modules/gui/qt/maininterface/qml/MainViewLoader.qml
- modules/gui/qt/medialibrary/mlbasemodel.hpp
- modules/gui/qt/medialibrary/qml/MediaGroupDisplay.qml
- modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
- modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoAll.qml
- modules/gui/qt/medialibrary/qml/VideoAllDisplay.qml
- modules/gui/qt/network/qml/BrowseDisplay.qml
- modules/gui/qt/network/qml/ServicesHomeDisplay.qml
- modules/gui/qt/network/qml/ServicesSources.qml
- modules/gui/qt/util/navigation_history.cpp
- modules/gui/qt/util/navigation_history.hpp
- modules/gui/qt/widgets/qml/PageLoader.qml


Changes:

=====================================
modules/gui/qt/maininterface/qml/MainInterface.qml
=====================================
@@ -154,9 +154,11 @@ Item {
         const loadPlayer = !mainPlaylistController.empty;
 
         if (MainCtx.mediaLibraryAvailable)
-            History.push(["mc", "video"], loadPlayer ? History.Stay : History.Go)
+            History.push(["mc", "video"],
+                         Qt.OtherFocusReason, loadPlayer ? History.Stay : History.Go)
         else
-            History.push(["mc", "home"], loadPlayer ? History.Stay : History.Go)
+            History.push(["mc", "home"],
+                         Qt.OtherFocusReason, loadPlayer ? History.Stay : History.Go)
 
         if (loadPlayer)
             History.push(["player"])


=====================================
modules/gui/qt/maininterface/qml/MainViewLoader.qml
=====================================
@@ -72,7 +72,7 @@ Widgets.StackViewExt {
     property var currentComponent: {
         if (typeof model === "undefined" || !model)
             return null // invalid state
-        if (!model.ready && model.count === 0)
+        if (model.isReady && model.count === 0)
             return emptyLabel
         else if (MainCtx.gridView)
             return grid


=====================================
modules/gui/qt/medialibrary/mlbasemodel.hpp
=====================================
@@ -57,7 +57,7 @@ class MLBaseModel : public QAbstractListModel
 
     Q_PROPERTY(unsigned int count READ getCount NOTIFY countChanged FINAL)
 
-    // isReady is true when ml is not null pointer and cache count is not uninitialized
+    // isReady is true when the ml object is not null and the cache count is initialized
     Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged FINAL)
 
 public:


=====================================
modules/gui/qt/medialibrary/qml/MediaGroupDisplay.qml
=====================================
@@ -45,8 +45,6 @@ VideoAll {
         id: modelVideo
 
         ml: MediaLib
-
-        parentId: initialId
     }
 
     contextMenu: Util.MLContextMenu { model: modelVideo; showPlayAsAudioAction: true }


=====================================
modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
=====================================
@@ -68,12 +68,8 @@ Widgets.PageLoader {
         MusicAllArtists {
             onCurrentIndexChanged: _updateArtistsAllHistory(currentIndex)
 
-            onRequestArtistAlbumView: {
-                History.push(["mc", "music", "artists", "albums",
-                              { initialIndex: currentIndex } ]);
-
-                stackView.currentItem.setCurrentItemFocus(reason);
-            }
+            onRequestArtistAlbumView: History.push(["mc", "music", "artists", "albums",
+                                                    { initialIndex: currentIndex }], reason)
         }
     }
 


=====================================
modules/gui/qt/medialibrary/qml/MusicGenresDisplay.qml
=====================================
@@ -68,12 +68,8 @@ Widgets.PageLoader {
         MusicGenres {
             onCurrentIndexChanged: _updateGenresAllHistory(currentIndex)
 
-            onShowAlbumView: {
-                History.push(["mc", "music", "genres", "albums",
-                             { parentId: id, genreName: name }]);
-
-                stackView.currentItem.setCurrentItemFocus(reason);
-            }
+            onShowAlbumView: History.push(["mc", "music", "genres", "albums",
+                                           { parentId: id, genreName: name }], reason)
         }
     }
 


=====================================
modules/gui/qt/medialibrary/qml/VideoAll.qml
=====================================
@@ -52,17 +52,22 @@ MainInterface.MainViewLoader {
         { text: I18n.qtr("Duration"),   criteria: "duration" }
     ]
 
-    property alias dragItem: dragItem
-
     // function(model) -> [strings....]
     // used to get grid labels per model item
     property var gridLabels: getLabel
     property var listLabels: getLabel
 
+    // Aliases
+
+    property alias dragItem: dragItem
+
+    // Settings
+
     list: list
     grid: grid
     emptyLabel: emptylabel
 
+    // Functions
 
     function getLabel(model) {
         if (!model) return ""


=====================================
modules/gui/qt/medialibrary/qml/VideoAllDisplay.qml
=====================================
@@ -80,12 +80,8 @@ Widgets.PageLoader {
         VideoAllSubDisplay {
             // Events
 
-            onShowList: {
-                History.push(["mc", "video", "all", "group",
-                             { parentId: model.id, title: model.title }])
-
-                root.stackView.currentItem.setCurrentItemFocus(reason)
-            }
+            onShowList: History.push(["mc", "video", "all", "group",
+                                      { parentId: model.id, title: model.title }], reason)
 
             // NOTE: The model can change over time.
             onModelChanged: root.model = model


=====================================
modules/gui/qt/network/qml/BrowseDisplay.qml
=====================================
@@ -84,22 +84,17 @@ Widgets.PageLoader {
 
         onSeeAll: {
             if (sd_source === -1)
-                History.push(["mc", "network", "folders", { title: title }])
+                History.push(["mc", "network", "folders", { title: title }], reason)
             else
-                History.push(["mc", "network", "device", { title: title, sd_source: sd_source }])
-
-            stackViewItem.setCurrentItemFocus(reason)
+                History.push(["mc", "network", "device", { title: title, sd_source: sd_source }],
+                             reason)
         }
     }
 
     Connections {
         target: stackViewItem
 
-        onBrowse: {
-            History.push(["mc", "network", "browse", { tree: tree }])
-
-            stackViewItem.setCurrentItemFocus(reason)
-        }
+        onBrowse: History.push(["mc", "network", "browse", { tree: tree }], reason)
     }
 
     // Children
@@ -160,9 +155,7 @@ Widgets.PageLoader {
             }
 
             Navigation.cancelAction: function() {
-                History.previous()
-
-                stackViewItem.setCurrentItemFocus(Qt.BacktabFocusReason)
+                History.previous(Qt.BacktabFocusReason)
             }
         }
     }
@@ -173,17 +166,9 @@ Widgets.PageLoader {
         NetworkAddressbar {
             path: view.name === "browse" ? root.stackViewItem.providerModel.path : []
 
-            onHomeButtonClicked: {
-                History.push(["mc", "network", "home"])
+            onHomeButtonClicked: History.push(["mc", "network", "home"], reason)
 
-                stackViewItem.setCurrentItemFocus(reason)
-            }
-
-            onBrowse: {
-                History.push(["mc", "network", "browse", { "tree": tree }])
-
-                stackViewItem.setCurrentItemFocus(reason)
-            }
+            onBrowse: History.push(["mc", "network", "browse", { "tree": tree }], reason)
         }
     }
 }


=====================================
modules/gui/qt/network/qml/ServicesHomeDisplay.qml
=====================================
@@ -75,23 +75,15 @@ Widgets.PageLoader {
             property Component addressBar: NetworkAddressbar {
                 path: [{display: deviceModel.name, tree: {}}]
 
-                onHomeButtonClicked: {
-                    History.push(["mc", "discover", "services"]);
-
-                    root.setCurrentItemFocus(reason);
-                }
+                onHomeButtonClicked: History.push(["mc", "discover", "services"], reason)
             }
 
             providerModel: deviceModel
             contextMenu: contextMenu
 
-            onBrowse: {
-                History.push(["mc", "discover", "services", "source_browse",
-                              { tree: tree, "root_name": deviceModel.name,
-                                "source_name": source_name }]);
-
-                root.setCurrentItemFocus(reason);
-            }
+            onBrowse: History.push(["mc", "discover", "services", "source_browse",
+                                    { tree: tree, "root_name": deviceModel.name,
+                                      "source_name": source_name }], reason)
 
             NetworkDeviceModel {
                 id: deviceModel
@@ -122,30 +114,20 @@ Widgets.PageLoader {
                     return _path
                 }
 
-                onHomeButtonClicked: {
-                    History.push(["mc", "discover", "services"]);
-
-                    root.setCurrentItemFocus(reason);
-                }
+                onHomeButtonClicked: History.push(["mc", "discover", "services"], reason)
 
                 onBrowse: {
                     if (!!tree.isRoot)
                         History.push(["mc", "discover", "services", "source_root",
-                                      { source_name: tree.source_name }]);
+                                      { source_name: tree.source_name }], reason)
                     else
                         History.push(["mc", "discover", "services", "source_browse",
-                                      { tree: tree, "root": root_name }]);
-
-                    root.setCurrentItemFocus(reason);
+                                      { tree: tree, "root": root_name }], reason)
                 }
             }
 
-            onBrowse: {
-                History.push(["mc", "discover", "services", "source_browse",
-                              { tree: tree, "root": root_name }]);
-
-                root.setCurrentItemFocus(reason);
-            }
+            onBrowse: History.push(["mc", "discover", "services", "source_browse",
+                                    { tree: tree, "root": root_name }], reason)
 
             providerModel: NetworkMediaModel {
                 ctx: MainCtx


=====================================
modules/gui/qt/network/qml/ServicesSources.qml
=====================================
@@ -81,12 +81,11 @@ MainInterface.MainGridView {
 
         onItemDoubleClicked: {
             if (is_dummy)
-                History.push(["mc", "discover", "services", "services_manage"]);
+                History.push(["mc", "discover", "services", "services_manage"],
+                             Qt.MouseFocusReason)
             else
                 History.push(["mc", "discover", "services", "source_root",
-                              { source_name: model.name }]);
-
-            root.setCurrentItemFocus(Qt.MouseFocusReason);
+                              { source_name: model.name }], Qt.MouseFocusReason)
         }
 
         onItemClicked : {
@@ -100,20 +99,16 @@ MainInterface.MainGridView {
         const itemData = sourcesFilterModel.getDataAt(index);
 
         if (itemData.type === NetworkSourcesModel.TYPE_DUMMY)
-            History.push(["mc", "discover", "services", "services_manage"]);
+            History.push(["mc", "discover", "services", "services_manage"], Qt.TabFocusReason)
         else
             History.push(["mc", "discover", "services", "source_root",
-                          { source_name: itemData.name }]);
-
-        root.setCurrentItemFocus(Qt.TabFocusReason);
+                          { source_name: itemData.name }], Qt.TabFocusReason)
     }
 
     Navigation.parentItem: root
 
     Navigation.cancelAction: function() {
-        History.previous();
-
-        root.setCurrentItemFocus(Qt.TabFocusReason);
+        History.previous(Qt.TabFocusReason)
     }
 
     NetworkSourcesModel {


=====================================
modules/gui/qt/util/navigation_history.cpp
=====================================
@@ -5,7 +5,8 @@
 
 
 NavigationHistory::NavigationHistory(QObject *parent)
-    : QObject(parent)
+    : QObject(parent),
+      m_reason(Qt::OtherFocusReason)
 {
 }
 
@@ -21,13 +22,16 @@ bool NavigationHistory::isPreviousEmpty()
     return m_history.count() <= 1;
 }
 
-void NavigationHistory::push(QVariantMap item, PostAction postAction)
+void NavigationHistory::push(QVariantMap item, Qt::FocusReason reason, PostAction postAction)
 {
     m_history.push_back(item);
     emit previousEmptyChanged(false);
     if (postAction == PostAction::Go)
     {
         updateViewPath();
+
+        m_reason = reason;
+
         emit currentChanged(m_history.back());
     }
 }
@@ -143,7 +147,8 @@ static QString getViewPath(QVariantMap map)
     return r;
 }
 
-void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostAction postAction)
+void NavigationHistory::push(QVariantList itemList, Qt::FocusReason reason,
+                             NavigationHistory::PostAction postAction)
 {
     QVariantMap itemMap;
     pushListRec(itemMap, itemList.cbegin(), itemList.cend());
@@ -152,7 +157,7 @@ void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostActio
     QVariant rootView = itemMap["view"];
     if (!rootView.canConvert(QVariant::Map))
         return;
-    push(rootView.toMap(), postAction);
+    push(rootView.toMap(), reason, postAction);
 }
 
 
@@ -182,7 +187,7 @@ void NavigationHistory::addLeaf(QVariantMap itemMap)
     updateViewPath();
 }
 
-void NavigationHistory::previous(PostAction postAction)
+void NavigationHistory::previous(Qt::FocusReason reason, PostAction postAction)
 {
     if (m_history.count() == 1)
         return;
@@ -197,8 +202,11 @@ void NavigationHistory::previous(PostAction postAction)
     if (m_history.count() == 1)
         emit previousEmptyChanged(true);
 
-    if (postAction == PostAction::Go)
+    if (postAction == PostAction::Go) {
+        m_reason = reason;
+
         emit currentChanged( m_history.back() );
+    }
 }
 
 void NavigationHistory::updateViewPath()
@@ -215,3 +223,12 @@ QString NavigationHistory::viewPath() const
 {
     return m_viewPath;
 }
+
+Qt::FocusReason NavigationHistory::takeFocusReason()
+{
+    Qt::FocusReason reason = m_reason;
+
+    m_reason = Qt::OtherFocusReason;
+
+    return reason;
+}


=====================================
modules/gui/qt/util/navigation_history.hpp
=====================================
@@ -25,6 +25,9 @@ public:
     bool isPreviousEmpty();
     QString viewPath() const;
 
+    // NOTE: The first item to call this takes ownership over the focus reason.
+    Q_INVOKABLE Qt::FocusReason takeFocusReason();
+
 signals:
     void currentChanged(QVariant current);
     void previousEmptyChanged(bool empty);
@@ -48,7 +51,8 @@ public slots:
      * }, History.Go)
      * \endcode
      */
-    Q_INVOKABLE void push( QVariantMap, PostAction = PostAction::Go );
+    Q_INVOKABLE void push( QVariantMap, Qt::FocusReason = Qt::OtherFocusReason,
+                           PostAction = PostAction::Go );
 
     /**
      * provide a short version of the history push({k:v}), which implicitly create a dictonnary tree from the input list
@@ -65,7 +69,8 @@ public slots:
      *  push(["foo", "bar", {baz: "plop"} ], History.Go)
      * \endcode
      */
-    Q_INVOKABLE void push(QVariantList itemList, PostAction = PostAction::Go );
+    Q_INVOKABLE void push(QVariantList itemList, Qt::FocusReason = Qt::OtherFocusReason,
+                          PostAction = PostAction::Go );
 
 
     /**
@@ -91,13 +96,15 @@ public slots:
 
 
     // Go to previous page
-    void previous( PostAction = PostAction::Go );
+    void previous( Qt::FocusReason = Qt::OtherFocusReason, PostAction = PostAction::Go );
 
 private:
     void updateViewPath();
 
     QVariantList m_history;
     QString m_viewPath;
+
+    Qt::FocusReason m_reason;
 };
 
 #endif // NAVIGATION_HISTORY_HPP


=====================================
modules/gui/qt/widgets/qml/PageLoader.qml
=====================================
@@ -84,6 +84,9 @@ FocusScope {
             console.error("pageModel is not defined")
             return
         }
+
+        const reason = History.takeFocusReason()
+
         const found = stackView.loadView(root.pageModel, view.name, view.properties)
         if (!found) {
             console.error("failed to load", JSON.stringify(History.current))
@@ -91,6 +94,10 @@ FocusScope {
         }
 
         stackView.currentItem.Navigation.parentItem = root
+
+        if (reason !== Qt.OtherFocusReason)
+            setCurrentItemFocus(reason)
+
         root.currentItemChanged(stackView.currentItem)
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5471b7c8513d9c5633224a0c7368c3fa92c42f35...7b115a86e8a7bf8be7fe75dfb78964841d1dde89

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5471b7c8513d9c5633224a0c7368c3fa92c42f35...7b115a86e8a7bf8be7fe75dfb78964841d1dde89
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