[vlc-devel] [PATCH 21/49] qml: unify list views in network

Pierre Lamot pierre at videolabs.io
Fri Oct 11 15:17:45 CEST 2019


---
 modules/gui/qt/Makefile.am                    |  2 -
 .../MCNetworksSectionSelectableDM.qml         | 29 ++++--
 .../qml/mediacenter/NetworkDriveDisplay.qml   | 67 -------------
 .../qt/qml/mediacenter/NetworkFileDisplay.qml | 67 -------------
 .../qt/qml/mediacenter/NetworkListItem.qml    | 93 +++++++------------
 modules/gui/qt/qml/utils/ListItem.qml         |  5 +-
 modules/gui/qt/vlc.qrc                        |  2 -
 7 files changed, 58 insertions(+), 207 deletions(-)
 delete mode 100644 modules/gui/qt/qml/mediacenter/NetworkDriveDisplay.qml
 delete mode 100644 modules/gui/qt/qml/mediacenter/NetworkFileDisplay.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 094073774c..2559f58f08 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -633,8 +633,6 @@ libqt_plugin_la_QML = \
 	gui/qt/qml/mediacenter/MusicGenresDisplay.qml \
 	gui/qt/qml/mediacenter/MusicTracksDisplay.qml \
 	gui/qt/qml/mediacenter/MusicTrackListDisplay.qml \
-	gui/qt/qml/mediacenter/NetworkDriveDisplay.qml \
-	gui/qt/qml/mediacenter/NetworkFileDisplay.qml \
 	gui/qt/qml/mediacenter/NetworkGridItem.qml \
 	gui/qt/qml/mediacenter/NetworkListItem.qml \
 	gui/qt/qml/mediacenter/VideoExpandableGrid.qml \
diff --git a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
index b398838acd..6faa74fd79 100644
--- a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
+++ b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
@@ -55,16 +55,29 @@ Utils.SelectableDelegateModel {
             }
         }
 
-        Loader {
-            id: delegateLoader
+        NetworkListItem {
+            id: delegateList
             focus: true
             Package.name: "list"
-            source: model.type == MLNetworkModel.TYPE_FILE ?
-                        "qrc:///mediacenter/NetworkFileDisplay.qml" :
-                        "qrc:///mediacenter/NetworkDriveDisplay.qml";
-        }
-        Connections {
-            target: delegateLoader.item
+
+            onItemClicked : {
+                delegateModel.updateSelection( modifier, view[viewIndexPropertyName], index )
+                view[viewIndexPropertyName] = index
+                delegateList.forceActiveFocus()
+            }
+
+            onItemDoubleClicked: {
+                if (model.type === MLNetworkModel.TYPE_NODE || model.type === MLNetworkModel.TYPE_DIRECTORY)
+                    history.push( ["mc", "network", { tree: model.tree } ], History.Go)
+                else
+                    medialib.addAndPlay( model.mrl )
+            }
+
+            onContextMenuButtonClicked: {
+                contextMenu.model = model
+                contextMenu.popup(menuParent)
+            }
+
             onActionLeft: root.navigationLeft(0)
             onActionRight: root.navigationRight(0)
         }
diff --git a/modules/gui/qt/qml/mediacenter/NetworkDriveDisplay.qml b/modules/gui/qt/qml/mediacenter/NetworkDriveDisplay.qml
deleted file mode 100644
index 9522c90365..0000000000
--- a/modules/gui/qt/qml/mediacenter/NetworkDriveDisplay.qml
+++ /dev/null
@@ -1,67 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2019 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 QtQuick 2.11
-import QtQuick.Controls 2.4
-import QtQml.Models 2.2
-
-import org.videolan.vlc 0.1
-import org.videolan.medialib 0.1
-
-import "qrc:///utils/" as Utils
-import "qrc:///style/"
-
-Utils.ListItem {
-    id: item
-
-    width: root.width
-    height: VLCStyle.icon_normal + VLCStyle.margin_small
-
-    focus: true
-
-    color: VLCStyle.colors.getBgColor(element.DelegateModel.inSelected, this.hovered, this.activeFocus)
-
-    cover: Image {
-        id: cover_obj
-        fillMode: Image.PreserveAspectFit
-        source: "qrc:///type/directory_black.svg";
-    }
-    line1: model.name || qsTr("Unknown share")
-    line2: model.mrl
-    imageText: (model.type !== MLNetworkModel.TYPE_DIRECTORY && model.type !== MLNetworkModel.TYPE_NODE) ? model.protocol : ""
-
-    showContextButton: true
-    onContextMenuButtonClicked: {
-        contextMenu.model = model
-        contextMenu.popup(menuParent,contextMenu.width,0)
-    }
-
-    onItemClicked : {
-        if (key == Qt.RightButton){
-            contextMenu.model = model
-            contextMenu.popup(this)
-        }
-        delegateModel.updateSelection( modifier, view.currentIndex, index )
-        view[viewIndexPropertyName] = index
-        this.forceActiveFocus()
-    }
-    onItemDoubleClicked: {
-        history.push( ["mc", "network", { tree: model.tree } ], History.Go)
-    }
-
-    actionButtons: []
-}
diff --git a/modules/gui/qt/qml/mediacenter/NetworkFileDisplay.qml b/modules/gui/qt/qml/mediacenter/NetworkFileDisplay.qml
deleted file mode 100644
index c2d77bc927..0000000000
--- a/modules/gui/qt/qml/mediacenter/NetworkFileDisplay.qml
+++ /dev/null
@@ -1,67 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2019 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 QtQuick 2.11
-import QtQuick.Controls 2.4
-import QtQml.Models 2.2
-
-import org.videolan.medialib 0.1
-
-import "qrc:///utils/" as Utils
-import "qrc:///style/"
-
-Utils.ListItem {
-    width: root.width
-    height: VLCStyle.icon_normal + VLCStyle.margin_small
-
-    focus: true
-
-    color: VLCStyle.colors.getBgColor(element.DelegateModel.inSelected, this.hovered, this.activeFocus)
-
-    cover: Image {
-        id: cover_obj
-        fillMode: Image.PreserveAspectFit
-        source: "qrc:///type/file_black.svg"
-    }
-    line1: model.name || qsTr("Unknown share")
-    line2: model.mrl
-
-    showContextButton: true
-    onContextMenuButtonClicked: {
-        contextMenu.model = model
-        contextMenu.popup(menuParent,contextMenu.width,0)
-    }
-
-    onItemClicked : {
-        if (key == Qt.RightButton){
-            contextMenu.model = model
-            contextMenu.popup(this)
-        }
-        delegateModel.updateSelection( modifier, view[viewIndexPropertyName], index )
-        view[viewIndexPropertyName] = index
-        this.forceActiveFocus()
-    }
-    onItemDoubleClicked: {
-        medialib.addAndPlay( model.mrl )
-    }
-    onPlayClicked: {
-        medialib.addAndPlay( model.mrl )
-    }
-    onAddToPlaylistClicked: {
-        medialib.addToPlaylist( model.mrl );
-    }
-}
diff --git a/modules/gui/qt/qml/mediacenter/NetworkListItem.qml b/modules/gui/qt/qml/mediacenter/NetworkListItem.qml
index 30628cc77d..f0ecc2c418 100644
--- a/modules/gui/qt/qml/mediacenter/NetworkListItem.qml
+++ b/modules/gui/qt/qml/mediacenter/NetworkListItem.qml
@@ -16,77 +16,50 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 import QtQuick 2.11
-import QtQuick.Layouts 1.3
 import QtQuick.Controls 2.4
+import QtQml.Models 2.2
+
+import org.videolan.vlc 0.1
+import org.videolan.medialib 0.1
 
 import "qrc:///utils/" as Utils
 import "qrc:///style/"
 
-Rectangle {
-    id: root
-    signal indexClicked
-    signal itemClicked(int keys, int modifier)
-    signal itemDoubleClicked(int keys, int modifier)
+Utils.ListItem {
+    id: item
 
-    property alias hovered: mouse.containsMouse
+    width: root.width
+    height: VLCStyle.icon_normal + VLCStyle.margin_small
 
-    property Component cover: Item {}
-    property alias line1: line1_text.text
-    property alias line2: line2_text.text
+    focus: true
 
-    MouseArea {
-        id: mouse
-        anchors.fill: parent
-        hoverEnabled: true
-        onClicked: {
-            root.itemClicked(mouse.buttons, mouse.modifiers);
-        }
-        onDoubleClicked: {
-            root.itemDoubleClicked(mouse.buttons, mouse.modifiers);
-        }
-    }
+    color: VLCStyle.colors.getBgColor(element.DelegateModel.inSelected, this.hovered, this.activeFocus)
 
-    RowLayout {
-        anchors.fill: parent
-        Loader {
-            Layout.preferredWidth: VLCStyle.icon_normal
-            Layout.preferredHeight: VLCStyle.icon_normal
-            sourceComponent: root.cover
-        }
-        Column {
-            Text{
-                id: line1_text
-                font.bold: true
-                elide: Text.ElideRight
-                color: VLCStyle.colors.text
-                font.pixelSize: VLCStyle.fontSize_normal
-                enabled: text !== ""
-            }
-            Text{
-                id: line2_text
-                text: ""
-                elide: Text.ElideRight
-                color: VLCStyle.colors.text
-                font.pixelSize: VLCStyle.fontSize_xsmall
-                enabled: text !== ""
+    cover: Image {
+        id: cover_obj
+        fillMode: Image.PreserveAspectFit
+        source: {
+            switch (model.type) {
+            case MLNetworkModel.TYPE_DISC:
+                return  "qrc:///type/disc.svg"
+            case MLNetworkModel.TYPE_CARD:
+                return  "qrc:///type/capture-card.svg"
+            case MLNetworkModel.TYPE_STREAM:
+                return  "qrc:///type/stream.svg"
+            case MLNetworkModel.TYPE_PLAYLIST:
+                return  "qrc:///type/playlist.svg"
+            case MLNetworkModel.TYPE_FILE:
+                return  "qrc:///type/file_black.svg"
+            default:
+                return "qrc:///type/directory_black.svg"
             }
         }
+    }
+    line1: model.name || qsTr("Unknown share")
+    line2: model.mrl
+    imageText: (model.type !== MLNetworkModel.TYPE_DIRECTORY && model.type !== MLNetworkModel.TYPE_NODE) ? model.protocol : ""
 
-        Item {
-            Layout.fillWidth: true
-        }
+    showContextButton: true
 
-        Utils.ImageToolButton {
-            id: indexButton
-            visible: model.can_index
-            Layout.preferredHeight: VLCStyle.icon_normal
-            Layout.preferredWidth: VLCStyle.icon_normal
-            imageSource: !model.indexed ? "qrc:///buttons/playlist/playlist_add.svg" :
-                                          ((mouse.containsMouse || activeFocus) ? "qrc:///toolbar/clear.svg" :
-                                                                                  "qrc:///valid.svg" )
-            onClicked: {
-                root.indexClicked(mouse.buttons, mouse.modifiers);
-            }
-        }
-    }
+    actionButtons: []
 }
diff --git a/modules/gui/qt/qml/utils/ListItem.qml b/modules/gui/qt/qml/utils/ListItem.qml
index 15d4c082da..b4332c0bb2 100644
--- a/modules/gui/qt/qml/utils/ListItem.qml
+++ b/modules/gui/qt/qml/utils/ListItem.qml
@@ -89,7 +89,10 @@ NavigableFocusScope {
             hoverEnabled: true
             acceptedButtons: Qt.LeftButton | Qt.RightButton
             onClicked: {
-                root.itemClicked(mouse.button, mouse.modifiers);
+                if (mouse.button === Qt.RightButton)
+                    contextMenuButtonClicked(root);
+                else
+                    root.itemClicked(mouse.button, mouse.modifiers);
             }
             onDoubleClicked: {
                 root.itemDoubleClicked(mouse.buttons, mouse.modifiers);
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 7863aa59cd..6132f4bd6a 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -222,8 +222,6 @@
         <file alias="MusicTrackListDisplay.qml">qml/mediacenter/MusicTrackListDisplay.qml</file>
         <file alias="ArtistTopBanner.qml">qml/mediacenter/ArtistTopBanner.qml</file>
         <file alias="MCMainDisplay.qml">qml/mediacenter/MCMainDisplay.qml</file>
-        <file alias="NetworkDriveDisplay.qml">qml/mediacenter/NetworkDriveDisplay.qml</file>
-        <file alias="NetworkFileDisplay.qml">qml/mediacenter/NetworkFileDisplay.qml</file>
         <file alias="NetworkGridItem.qml">qml/mediacenter/NetworkGridItem.qml</file>
         <file alias="NetworkListItem.qml">qml/mediacenter/NetworkListItem.qml</file>
         <file alias="VideoExpandableGrid.qml">qml/mediacenter/VideoExpandableGrid.qml</file>
-- 
2.20.1



More information about the vlc-devel mailing list