[vlc-commits] qt/qml_menu_wrapper: Add group support

Benjamin Arnaud git at videolan.org
Tue Apr 20 12:49:07 UTC 2021


vlc | branch: master | Benjamin Arnaud <benjamin.arnaud at videolabs.io> | Fri Mar 26 16:18:55 2021 +0100| [3c74d42baf33708118f55d71881aac4c9af21a67] | committer: Pierre Lamot

qt/qml_menu_wrapper: Add group support

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

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

 modules/gui/qt/menus/qml_menu_wrapper.cpp | 45 +++++++++++++++++++++++++++++++
 modules/gui/qt/menus/qml_menu_wrapper.hpp | 21 +++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/modules/gui/qt/menus/qml_menu_wrapper.cpp b/modules/gui/qt/menus/qml_menu_wrapper.cpp
index 1e7b1eaa3b..0e2f30f74f 100644
--- a/modules/gui/qt/menus/qml_menu_wrapper.cpp
+++ b/modules/gui/qt/menus/qml_menu_wrapper.cpp
@@ -20,6 +20,7 @@
 #include "util/qml_main_context.hpp"
 #include "medialibrary/medialib.hpp"
 #include "medialibrary/mlvideomodel.hpp"
+#include "medialibrary/mlgrouplistmodel.hpp"
 #include "medialibrary/mlplaylistlistmodel.hpp"
 #include "medialibrary/mlplaylistmodel.hpp"
 #include "medialibrary/mlalbummodel.hpp"
@@ -392,6 +393,50 @@ void VideoContextMenu::popup(const QModelIndexList& selected, QPoint pos, QVaria
     m_menu->popup(pos);
 }
 
+//=================================================================================================
+// GroupListContextMenu
+//=================================================================================================
+
+GroupListContextMenu::GroupListContextMenu(QObject * parent) : QObject(parent) {}
+
+GroupListContextMenu::~GroupListContextMenu() /* override */
+{
+    if (m_menu)
+        delete m_menu;
+}
+
+void GroupListContextMenu::popup(const QModelIndexList & selected, QPoint pos, QVariantMap)
+{
+    if (m_model == nullptr)
+        return;
+
+    if (m_menu)
+        delete m_menu;
+
+    QVariantList ids;
+
+    for (const QModelIndex & modelIndex : selected)
+        ids.push_back(m_model->data(modelIndex, MLGroupListModel::GROUP_ID));
+
+    m_menu = new QMenu();
+
+    MediaLib * ml = m_model->ml();
+
+    QAction * action = m_menu->addAction(qtr("Add and play"));
+
+    connect(action, &QAction::triggered, [ml, ids]() {
+        ml->addAndPlay(ids);
+    });
+
+    action = m_menu->addAction(qtr("Enqueue"));
+
+    connect(action, &QAction::triggered, [ml, ids]() {
+        ml->addToPlaylist(ids);
+    });
+
+    m_menu->popup(pos);
+}
+
 //=================================================================================================
 // PlaylistListContextMenu
 //=================================================================================================
diff --git a/modules/gui/qt/menus/qml_menu_wrapper.hpp b/modules/gui/qt/menus/qml_menu_wrapper.hpp
index 8481839189..cb96e441e1 100644
--- a/modules/gui/qt/menus/qml_menu_wrapper.hpp
+++ b/modules/gui/qt/menus/qml_menu_wrapper.hpp
@@ -32,6 +32,8 @@ class MLArtistModel;
 class MLAlbumTrackModel;
 class MLUrlModel;
 class MLVideoModel;
+class MLGroupListModel;
+class MLGroupModel;
 class MLPlaylistListModel;
 class MLPlaylistModel;
 class NetworkDeviceModel;
@@ -216,6 +218,25 @@ private:
     QMenu* m_menu = nullptr;
 };
 
+//-------------------------------------------------------------------------------------------------
+// Groups
+//-------------------------------------------------------------------------------------------------
+
+class GroupListContextMenu : public QObject {
+    Q_OBJECT
+    SIMPLE_MENU_PROPERTY(MLGroupListModel *, model, nullptr)
+public:
+    GroupListContextMenu(QObject * parent = nullptr);
+    ~GroupListContextMenu() /* override */;
+
+public slots:
+    void popup(const QModelIndexList & selected, QPoint pos, QVariantMap options = {});
+private:
+    QMenu* m_menu = nullptr;
+};
+
+//-------------------------------------------------------------------------------------------------
+
 class PlaylistListContextMenu : public QObject {
     Q_OBJECT
     SIMPLE_MENU_PROPERTY(MLPlaylistListModel *, model, nullptr)



More information about the vlc-commits mailing list