[vlc-commits] qt: move gridView mode property to MainInterface

Pierre Lamot git at videolan.org
Mon Sep 28 09:37:53 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Tue Sep 15 17:07:28 2020 +0200| [ce14f2b3aa3d09494ae06fb3064486ee21b4d987] | committer: Pierre Lamot

qt: move gridView mode property to MainInterface

  grid/list mode is not restricted to medialibrary views

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce14f2b3aa3d09494ae06fb3064486ee21b4d987
---

 modules/gui/qt/maininterface/main_interface.cpp         |  8 ++++++++
 modules/gui/qt/maininterface/main_interface.hpp         |  9 ++++++++-
 modules/gui/qt/maininterface/qml/BannerSources.qml      |  6 +++---
 modules/gui/qt/medialibrary/medialib.cpp                | 14 --------------
 modules/gui/qt/medialibrary/medialib.hpp                |  5 -----
 modules/gui/qt/medialibrary/qml/MusicAlbums.qml         |  8 ++++----
 modules/gui/qt/medialibrary/qml/MusicArtist.qml         | 12 ++++++------
 modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml |  6 +++---
 modules/gui/qt/medialibrary/qml/MusicGenres.qml         |  4 ++--
 modules/gui/qt/medialibrary/qml/VideoDisplay.qml        |  8 ++++----
 modules/gui/qt/menus/qml/ViewMenu.qml                   | 14 ++++++--------
 modules/gui/qt/network/qml/NetworkBrowseDisplay.qml     |  6 +++---
 12 files changed, 47 insertions(+), 53 deletions(-)

diff --git a/modules/gui/qt/maininterface/main_interface.cpp b/modules/gui/qt/maininterface/main_interface.cpp
index bfe239e4e1..dfbae7a259 100644
--- a/modules/gui/qt/maininterface/main_interface.cpp
+++ b/modules/gui/qt/maininterface/main_interface.cpp
@@ -147,6 +147,7 @@ MainInterface::MainInterface(intf_thread_t *_p_intf , QWidget* parent, Qt::Windo
     b_playlistDocked = getSettings()->value( "MainWindow/pl-dock-status", true ).toBool();
     playlistVisible  = getSettings()->value( "MainWindow/playlist-visible", false ).toBool();
     playlistWidthFactor = getSettings()->value( "MainWindow/playlist-width-factor", 4.0 ).toDouble();
+    m_gridView = getSettings()->value( "MainWindow/grid-view", true).toBool();
 
     m_showRemainingTime = getSettings()->value( "MainWindow/ShowRemainingTime", false ).toBool();
 
@@ -234,6 +235,7 @@ MainInterface::~MainInterface()
     settings->setValue( "playlist-visible", playlistVisible );
     settings->setValue( "playlist-width-factor", playlistWidthFactor);
 
+    settings->setValue( "grid-view", m_gridView );
     /* Save the stackCentralW sizes */
     settings->endGroup();
 
@@ -371,6 +373,12 @@ void MainInterface::setShowRemainingTime( bool show )
     emit showRemainingTimeChanged(show);
 }
 
+void MainInterface::setGridView(bool asGrid)
+{
+    m_gridView = asGrid;
+    emit gridViewChanged( asGrid );
+}
+
 void MainInterface::setInterfaceAlwaysOnTop( bool on_top )
 {
     b_interfaceOnTop = on_top;
diff --git a/modules/gui/qt/maininterface/main_interface.hpp b/modules/gui/qt/maininterface/main_interface.hpp
index e9c834c120..e99011dff9 100644
--- a/modules/gui/qt/maininterface/main_interface.hpp
+++ b/modules/gui/qt/maininterface/main_interface.hpp
@@ -149,6 +149,7 @@ class MainInterface : public QVLCMW
     Q_PROPERTY(VLCVarChoiceModel* extraInterfaces READ getExtraInterfaces CONSTANT)
     Q_PROPERTY(float intfScaleFactor READ getIntfScaleFactor NOTIFY intfScaleFactorChanged)
     Q_PROPERTY(bool mediaLibraryAvailable READ hasMediaLibrary CONSTANT)
+    Q_PROPERTY(bool gridView READ hasGridView WRITE setGridView NOTIFY gridViewChanged)
 
 public:
     /* tors */
@@ -183,6 +184,7 @@ public:
     inline bool isShowRemainingTime() const  { return m_showRemainingTime; }
     inline float getIntfScaleFactor() const { return m_intfScaleFactor; }
     inline bool hasMediaLibrary() const { return b_hasMedialibrary; }
+    inline bool hasGridView() const { return m_gridView; }
 
     bool hasEmbededVideo() const;
     VideoSurfaceProvider* getVideoSurfaceProvider() const;
@@ -243,11 +245,14 @@ protected:
 #ifdef QT5_HAS_WAYLAND
     bool                 b_hasWayland;
 #endif
-    bool                 b_hasMedialibrary = false;
+    bool                 b_hasMedialibrary;
+    bool                 m_gridView;
+
     /* States */
     bool                 playlistVisible;       ///< Is the playlist visible ?
     double               playlistWidthFactor;   ///< playlist size: root.width / playlistScaleFactor
 
+
     static const Qt::Key kc[10]; /* easter eggs */
     int i_kc_offset;
 
@@ -263,6 +268,7 @@ public slots:
     void setPlaylistWidthFactor( double );
     void setInterfaceAlwaysOnTop( bool );
     void setShowRemainingTime( bool );
+    void setGridView( bool );
     void incrementIntfUserScaleFactor( bool increment);
 
     void emitBoss();
@@ -305,6 +311,7 @@ signals:
     void hasEmbededVideoChanged(bool);
     void toolBarConfUpdated();
     void showRemainingTimeChanged(bool);
+    void gridViewChanged( bool );
 
     void intfScaleFactorChanged();
 };
diff --git a/modules/gui/qt/maininterface/qml/BannerSources.qml b/modules/gui/qt/maininterface/qml/BannerSources.qml
index 9ccde2034a..b2115c3f6c 100644
--- a/modules/gui/qt/maininterface/qml/BannerSources.qml
+++ b/modules/gui/qt/maininterface/qml/BannerSources.qml
@@ -50,7 +50,7 @@ Widgets.NavigableFocusScope {
 
     // Triggered when the toogleView button is selected
     function toggleView () {
-        medialib.gridView = !medialib.gridView
+        mainInterface.gridView = !mainInterface.gridView
     }
 
     function search() {
@@ -185,10 +185,10 @@ Widgets.NavigableFocusScope {
                         Widgets.IconToolButton {
                             id: list_grid_btn
                             size: VLCStyle.banner_icon_size
-                            iconText: medialib.gridView ? VLCIcons.list : VLCIcons.grid
+                            iconText: mainInterface.gridView ? VLCIcons.list : VLCIcons.grid
                             text: i18n.qtr("List/Grid")
                             height: localToolbar.height
-                            onClicked: medialib.gridView = !medialib.gridView
+                            onClicked: mainInterface.gridView = !mainInterface.gridView
                             enabled: true
                         }
 
diff --git a/modules/gui/qt/medialibrary/medialib.cpp b/modules/gui/qt/medialibrary/medialib.cpp
index 5d1aa1fcae..f92ef54e1b 100644
--- a/modules/gui/qt/medialibrary/medialib.cpp
+++ b/modules/gui/qt/medialibrary/medialib.cpp
@@ -29,7 +29,6 @@
 MediaLib::MediaLib(intf_thread_t *_intf, QObject *_parent)
     : QObject( _parent )
     , m_intf( _intf )
-    , m_gridView ( m_intf->p_sys->mainSettings->value("medialib-gridView",true).toBool() )
     , m_ml( vlcMl() )
     , m_event_cb( nullptr, [this](vlc_ml_event_callback_t* cb ) {
         vlc_ml_event_unregister_callback( m_ml, cb );
@@ -39,19 +38,6 @@ MediaLib::MediaLib(intf_thread_t *_intf, QObject *_parent)
                                                       this ) );
 }
 
-// Should the items be displayed as a grid or as list ?
-bool MediaLib::isGridView() const
-{
-    return m_gridView;
-}
-
-void MediaLib::setGridView(bool state)
-{
-    m_gridView = state;
-    m_intf->p_sys->mainSettings->setValue("medialib-gridView",state);
-    emit gridViewChanged();
-}
-
 void MediaLib::openMRLFromMedia(const vlc_ml_media_t& media, bool start )
 {
     if (!media.p_files)
diff --git a/modules/gui/qt/medialibrary/medialib.hpp b/modules/gui/qt/medialibrary/medialib.hpp
index 1b4eb708e9..0db9f5ee3f 100644
--- a/modules/gui/qt/medialibrary/medialib.hpp
+++ b/modules/gui/qt/medialibrary/medialib.hpp
@@ -38,7 +38,6 @@ class MediaLib : public QObject
 {
     Q_OBJECT
 
-    Q_PROPERTY(bool gridView READ isGridView WRITE setGridView NOTIFY gridViewChanged)
     Q_PROPERTY(bool discoveryPending READ discoveryPending NOTIFY discoveryPendingChanged)
     Q_PROPERTY(int  parsingProgress READ parsingProgress NOTIFY parsingProgressChanged)
     Q_PROPERTY(QString discoveryEntryPoint READ discoveryEntryPoint NOTIFY discoveryEntryPointChanged)
@@ -67,7 +66,6 @@ public:
     vlc_medialibrary_t* vlcMl();
 
 signals:
-    void gridViewChanged();
     void reloadStarted();
     void reloadCompleted();
     void discoveryStarted();
@@ -78,8 +76,6 @@ signals:
     void idleChanged();
 
 private:
-    bool isGridView() const;
-    void setGridView(bool);
     static void onMediaLibraryEvent( void* data, const vlc_ml_event_t* event );
 
 private:
@@ -87,7 +83,6 @@ private:
 
     intf_thread_t* m_intf;
 
-    bool m_gridView;
     bool m_idle = false;
     bool m_discoveryPending = false;
     int m_parsingProgress = 0;
diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index 4f12c7cb1d..aed8e25a1b 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -42,7 +42,7 @@ Widgets.NavigableFocusScope {
     //the index to "go to" when the view is loaded
     property var initialIndex: 0
     property int gridViewMarginTop: VLCStyle.margin_large
-    property var gridViewRowX: medialib.gridView ? view.currentItem.rowX : undefined
+    property var gridViewRowX: mainInterface.gridView ? view.currentItem.rowX : undefined
 
     navigationCancel: function() {
         if (view.currentItem.currentIndex <= 0) {
@@ -241,12 +241,12 @@ Widgets.NavigableFocusScope {
         anchors.fill: parent
         focus: albumModelId.count !== 0
 
-        initialItem: medialib.gridView ? gridComponent : tableComponent
+        initialItem: mainInterface.gridView ? gridComponent : tableComponent
 
         Connections {
-            target: medialib
+            target: mainInterface
             onGridViewChanged: {
-                if (medialib.gridView)
+                if (mainInterface.gridView)
                     view.replace(gridComponent)
                 else
                     view.replace(tableComponent)
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtist.qml b/modules/gui/qt/medialibrary/qml/MusicArtist.qml
index 9b91bd0fbc..c5a8125a63 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtist.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtist.qml
@@ -71,7 +71,7 @@ Widgets.NavigableFocusScope {
             Loader {
                 id: albumsLoader
 
-                active: !medialib.gridView
+                active: !mainInterface.gridView
                 focus: true
                 sourceComponent: Column {
                     property alias albumsListView: albumsList
@@ -164,7 +164,7 @@ Widgets.NavigableFocusScope {
     onActiveFocusChanged: {
         if (activeFocus && albumModel.count > 0 && !albumSelectionModel.hasSelection) {
             var initialIndex = 0
-            var albumsListView = medialib.gridView ? view.currentItem : headerItem.albumsListView
+            var albumsListView = mainInterface.gridView ? view.currentItem : headerItem.albumsListView
             if (albumsListView.currentIndex !== -1)
                 initialIndex = albumsListView.currentIndex
             albumSelectionModel.select(albumModel.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
@@ -180,7 +180,7 @@ Widgets.NavigableFocusScope {
         if (initialIndex >= albumModel.count)
             initialIndex = 0
         albumSelectionModel.select(albumModel.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
-        var albumsListView = medialib.gridView ? view.currentItem : headerItem.albumsListView
+        var albumsListView = mainInterface.gridView ? view.currentItem : headerItem.albumsListView
         if (albumsListView) {
             albumsListView.currentIndex = initialIndex
             albumsListView.positionViewAtIndex(initialIndex, ItemView.Contain)
@@ -365,12 +365,12 @@ Widgets.NavigableFocusScope {
 
         anchors.fill: parent
         focus: albumModel.count !== 0
-        initialItem: medialib.gridView ? gridComponent : tableComponent
+        initialItem: mainInterface.gridView ? gridComponent : tableComponent
 
         Connections {
-            target: medialib
+            target: mainInterface
             onGridViewChanged: {
-                if (medialib.gridView)
+                if (mainInterface.gridView)
                     view.replace(gridComponent)
                 else
                     view.replace(tableComponent)
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index 772af3f9f2..afe183c1b8 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -250,13 +250,13 @@ Widgets.NavigableFocusScope {
 
                 anchors.fill: parent
                 focus: true
-                initialItem: medialib.gridView ? gridComponent : tableComponent
+                initialItem: mainInterface.gridView ? gridComponent : tableComponent
             }
 
             Connections {
-                target: medialib
+                target: mainInterface
                 onGridViewChanged: {
-                    if (medialib.gridView) {
+                    if (mainInterface.gridView) {
                         view.replace(gridComponent)
                     } else {
                         view.replace(tableComponent)
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index 0bf1ce0d21..e8d67d7630 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -48,7 +48,7 @@ Widgets.NavigableFocusScope {
     Component.onCompleted: loadView()
 
     function loadView() {
-        if (medialib.gridView) {
+        if (mainInterface.gridView) {
             view.replace(gridComponent)
         } else {
             view.replace(tableComponent)
@@ -272,7 +272,7 @@ Widgets.NavigableFocusScope {
     Widgets.StackViewExt {
         id: view
 
-        initialItem: medialib.gridView ? gridComponent : tableComponent
+        initialItem: mainInterface.gridView ? gridComponent : tableComponent
 
         anchors.fill: parent
         focus: genreModel.count !== 0
diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index 0318b80210..d277a61f74 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -94,7 +94,7 @@ Widgets.NavigableFocusScope {
             onTriggered: medialib.addToPlaylist( contextMenu.model.id )
         }
         Widgets.MenuItemExt {
-            enabled: medialib.gridView
+            enabled: mainInterface.gridView
             text: "Information"
             onTriggered: {
                 view.currentItem.switchExpandItem(contextMenu.itemIndex)
@@ -236,11 +236,11 @@ Widgets.NavigableFocusScope {
         anchors.fill:parent
         clip: true
         focus: videoModel.count !== 0
-        initialItem: medialib.gridView ? gridComponent : listComponent
+        initialItem: mainInterface.gridView ? gridComponent : listComponent
         Connections {
-            target: medialib
+            target: mainInterface
             onGridViewChanged: {
-                if (medialib.gridView)
+                if (mainInterface.gridView)
                     view.replace(gridComponent)
                 else
                     view.replace(listComponent)
diff --git a/modules/gui/qt/menus/qml/ViewMenu.qml b/modules/gui/qt/menus/qml/ViewMenu.qml
index 67e6b26516..62cd24e9e1 100644
--- a/modules/gui/qt/menus/qml/ViewMenu.qml
+++ b/modules/gui/qt/menus/qml/ViewMenu.qml
@@ -47,14 +47,12 @@ Widgets.MenuExt {
         onTriggered: mainInterface.interfaceFullScreen = !mainInterface.interfaceFullScreen
     }
 
-    Loader {
-        active: medialib !== null
-        sourceComponent:  Widgets.MenuItemExt {
-            text: i18n.qtr("&View Items as Grid")
-            checkable: true
-            checked: medialib.gridView
-            onTriggered: medialib.gridView = !medialib.gridView
-        }
+
+    Widgets.MenuItemExt {
+        text: i18n.qtr("&View Items as Grid")
+        checkable: true
+        checked: mainInterface.gridView
+        onTriggered: mainInterface.gridView = !mainInterface.gridView
     }
 
     Widgets.MenuExt {
diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index 3a730f2476..aff74a58e2 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -410,12 +410,12 @@ Widgets.NavigableFocusScope {
         anchors.fill:parent
         clip: true
         focus: true
-        initialItem: medialib.gridView ? gridComponent : tableComponent
+        initialItem: mainInterface.gridView ? gridComponent : tableComponent
 
         Connections {
-            target: medialib
+            target: mainInterface
             onGridViewChanged: {
-                if (medialib.gridView)
+                if (mainInterface.gridView)
                     view.replace(gridComponent)
                 else
                     view.replace(tableComponent)



More information about the vlc-commits mailing list