[vlc-devel] [PATCH v2 1/4] qml: fix context menu for NetworkBrowseDisplay
Prince Gupta
guptaprince8832 at gmail.com
Tue Sep 29 20:34:52 CEST 2020
---
modules/gui/qt/maininterface/mainui.cpp | 1 +
modules/gui/qt/menus/qml_menu_wrapper.cpp | 28 +++++++++++++++++++
modules/gui/qt/menus/qml_menu_wrapper.hpp | 10 +++++++
.../qt/network/qml/NetworkBrowseDisplay.qml | 6 +---
modules/gui/qt/network/qml/NetworkDisplay.qml | 8 +++++-
.../qt/network/qml/ServicesHomeDisplay.qml | 15 ++++++++++
6 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/modules/gui/qt/maininterface/mainui.cpp b/modules/gui/qt/maininterface/mainui.cpp
index c2d5460126..a44f2da909 100644
--- a/modules/gui/qt/maininterface/mainui.cpp
+++ b/modules/gui/qt/maininterface/mainui.cpp
@@ -213,6 +213,7 @@ void MainUI::registerQMLTypes()
qmlRegisterType<QmlGlobalMenu>( "org.videolan.vlc", 0, 1, "QmlGlobalMenu" );
qmlRegisterType<NetworkMediaContextMenu>( "org.videolan.vlc", 0, 1, "NetworkMediaContextMenu" );
+ qmlRegisterType<NetworkDeviceContextMenu>( "org.videolan.vlc", 0, 1, "NetworkDeviceContextMenu" );
qmlRegisterType<PlaylistContextMenu>( "org.videolan.vlc", 0, 1, "PlaylistContextMenu" );
}
diff --git a/modules/gui/qt/menus/qml_menu_wrapper.cpp b/modules/gui/qt/menus/qml_menu_wrapper.cpp
index f42e31572a..ebf1e91394 100644
--- a/modules/gui/qt/menus/qml_menu_wrapper.cpp
+++ b/modules/gui/qt/menus/qml_menu_wrapper.cpp
@@ -25,6 +25,7 @@
#include "medialibrary/mlgenremodel.hpp"
#include "medialibrary/mlalbumtrackmodel.hpp"
#include "medialibrary/mlurlmodel.hpp"
+#include "network/networkdevicemodel.hpp"
#include "network/networkmediamodel.hpp"
#include "playlist/playlist_controller.hpp"
#include "playlist/playlist_model.hpp"
@@ -278,6 +279,33 @@ void NetworkMediaContextMenu::popup(const QModelIndexList& selected, QPoint pos)
menu->popup(pos);
}
+NetworkDeviceContextMenu::NetworkDeviceContextMenu(QObject* parent)
+ : QObject(parent)
+{}
+
+void NetworkDeviceContextMenu::popup(const QModelIndexList& selected, QPoint pos)
+{
+ if (!m_model)
+ return;
+
+ QMenu* menu = new QMenu();
+ QAction* action;
+
+ menu->setAttribute(Qt::WA_DeleteOnClose);
+
+ action = menu->addAction( qtr("Add and play") );
+ connect(action, &QAction::triggered, [this, selected]( ) {
+ m_model->addAndPlay(selected);
+ });
+
+ action = menu->addAction( qtr("Enqueue") );
+ connect(action, &QAction::triggered, [this, selected]( ) {
+ m_model->addToPlaylist(selected);
+ });
+
+ menu->popup(pos);
+}
+
PlaylistContextMenu::PlaylistContextMenu(QObject* parent)
: QObject(parent)
{}
diff --git a/modules/gui/qt/menus/qml_menu_wrapper.hpp b/modules/gui/qt/menus/qml_menu_wrapper.hpp
index 369817d8ca..36c8ad5665 100644
--- a/modules/gui/qt/menus/qml_menu_wrapper.hpp
+++ b/modules/gui/qt/menus/qml_menu_wrapper.hpp
@@ -32,6 +32,7 @@ class MLArtistModel;
class MLAlbumTrackModel;
class MLUrlModel;
class MLVideoModel;
+class NetworkDeviceModel;
class NetworkMediaModel;
class QmlMainContext;
namespace vlc {
@@ -156,6 +157,15 @@ public slots:
void popup(const QModelIndexList& selected, QPoint pos );
};
+class NetworkDeviceContextMenu : public QObject {
+ Q_OBJECT
+ SIMPLE_MENU_PROPERTY(NetworkDeviceModel*, model, nullptr)
+public:
+ NetworkDeviceContextMenu(QObject* parent = nullptr);
+public slots:
+ void popup(const QModelIndexList& selected, QPoint pos );
+};
+
class PlaylistContextMenu : public QObject {
Q_OBJECT
diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index 98774c40d8..0d860df2ca 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -33,6 +33,7 @@ Widgets.NavigableFocusScope {
id: root
property var providerModel
+ property var contextMenu
property var tree
onTreeChanged: providerModel.tree = tree
readonly property var currentIndex: view.currentItem.currentIndex
@@ -48,11 +49,6 @@ Widgets.NavigableFocusScope {
model: providerModel
}
- NetworkMediaContextMenu {
- id: contextMenu
- model: providerModel
- }
-
function resetFocus() {
var initialIndex = root.initialIndex
if (initialIndex >= providerModel.count)
diff --git a/modules/gui/qt/network/qml/NetworkDisplay.qml b/modules/gui/qt/network/qml/NetworkDisplay.qml
index 574d0d2150..f445cad47f 100644
--- a/modules/gui/qt/network/qml/NetworkDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkDisplay.qml
@@ -47,7 +47,7 @@ Widgets.NavigableFocusScope {
page ="qrc:///network/NetworkHomeDisplay.qml"
else {
page = "qrc:///network/NetworkBrowseDisplay.qml"
- props = { providerModel: mediaModel, tree: root.tree }
+ props = { providerModel: mediaModel, contextMenu: mediaContextMenu, tree: root.tree }
}
view.replace(page, props)
}
@@ -58,6 +58,12 @@ Widgets.NavigableFocusScope {
ctx: mainctx
}
+ NetworkMediaContextMenu {
+ id: mediaContextMenu
+
+ model: mediaModel
+ }
+
Widgets.StackViewExt {
id: view
anchors.fill:parent
diff --git a/modules/gui/qt/network/qml/ServicesHomeDisplay.qml b/modules/gui/qt/network/qml/ServicesHomeDisplay.qml
index cc8c7135f4..88b3bd1971 100644
--- a/modules/gui/qt/network/qml/ServicesHomeDisplay.qml
+++ b/modules/gui/qt/network/qml/ServicesHomeDisplay.qml
@@ -21,6 +21,7 @@ import QtQml.Models 2.2
import QtQuick.Layouts 1.11
import QtQuick.Shapes 1.0
+import org.videolan.vlc 0.1
import org.videolan.medialib 0.1
import "qrc:///widgets/" as Widgets
@@ -76,6 +77,7 @@ Widgets.NavigableFocusScope {
property alias source_name: deviceModel.source_name
providerModel: deviceModel
+ contextMenu: contextMenu
function changeTree(new_tree) {
history.push(["mc", "discover", "services", "source_browse", { tree: new_tree }]);
@@ -87,6 +89,12 @@ Widgets.NavigableFocusScope {
ctx: mainctx
sd_source: NetworkDeviceModel.CAT_INTERNET
}
+
+ NetworkDeviceContextMenu {
+ id: contextMenu
+
+ model: deviceModel
+ }
}
}
@@ -95,6 +103,7 @@ Widgets.NavigableFocusScope {
NetworkBrowseDisplay {
providerModel: mediaModel
+ contextMenu: contextMenu
function changeTree(new_tree) {
history.push(["mc", "discover", "services", "source_browse", { tree: new_tree }]);
@@ -105,6 +114,12 @@ Widgets.NavigableFocusScope {
ctx: mainctx
}
+
+ NetworkMediaContextMenu {
+ id: contextMenu
+
+ model: mediaModel
+ }
}
}
--
2.25.1
More information about the vlc-devel
mailing list