[vlc-devel] [PATCH 09/17] qt/menus: Add playlist support
Benjamin Arnaud
benjamin.arnaud at videolabs.io
Fri Feb 19 10:25:33 UTC 2021
---
modules/gui/qt/maininterface/mainui.cpp | 1 +
modules/gui/qt/menus/qml_menu_wrapper.cpp | 141 ++++++++++++++++++++++
modules/gui/qt/menus/qml_menu_wrapper.hpp | 30 +++++
3 files changed, 172 insertions(+)
diff --git a/modules/gui/qt/maininterface/mainui.cpp b/modules/gui/qt/maininterface/mainui.cpp
index 146f0967fd..fd5c4a1302 100644
--- a/modules/gui/qt/maininterface/mainui.cpp
+++ b/modules/gui/qt/maininterface/mainui.cpp
@@ -196,6 +196,7 @@ void MainUI::registerQMLTypes()
qmlRegisterType<AlbumTrackContextMenu>( "org.videolan.medialib", 0, 1, "AlbumTrackContextMenu" );
qmlRegisterType<URLContextMenu>( "org.videolan.medialib", 0, 1, "URLContextMenu" );
qmlRegisterType<VideoContextMenu>( "org.videolan.medialib", 0, 1, "VideoContextMenu" );
+ qmlRegisterType<PlaylistListContextMenu>( "org.videolan.medialib", 0, 1, "PlaylistListContextMenu" );
qmlRegisterType<PlaylistMediaContextMenu>( "org.videolan.medialib", 0, 1, "PlaylistMediaContextMenu" );
}
diff --git a/modules/gui/qt/menus/qml_menu_wrapper.cpp b/modules/gui/qt/menus/qml_menu_wrapper.cpp
index 259b10c877..03eba1477d 100644
--- a/modules/gui/qt/menus/qml_menu_wrapper.cpp
+++ b/modules/gui/qt/menus/qml_menu_wrapper.cpp
@@ -20,6 +20,8 @@
#include "util/qml_main_context.hpp"
#include "medialibrary/medialib.hpp"
#include "medialibrary/mlvideomodel.hpp"
+#include "medialibrary/mlplaylistlistmodel.hpp"
+#include "medialibrary/mlplaylistmodel.hpp"
#include "medialibrary/mlalbummodel.hpp"
#include "medialibrary/mlartistmodel.hpp"
#include "medialibrary/mlgenremodel.hpp"
@@ -259,6 +261,11 @@ void BaseMedialibMenu::medialibAudioContextMenu(MediaLib* ml, const QVariantList
ml->addToPlaylist(mlId);
});
+ action = m_menu->addAction( qtr("Add to playlist") );
+ connect(action, &QAction::triggered, [mlId]( ) {
+ DialogsProvider::getInstance()->playlistsDialog(mlId);
+ });
+
if (options.contains("information") && options["information"].type() == QVariant::Int) {
action = m_menu->addAction( qtr("Information") );
@@ -359,6 +366,11 @@ void VideoContextMenu::popup(const QModelIndexList& selected, QPoint pos, QVaria
ml->addToPlaylist(itemIdList);
});
+ action = m_menu->addAction( qtr("Add to playlist") );
+ connect(action, &QAction::triggered, [itemIdList]( ) {
+ DialogsProvider::getInstance()->playlistsDialog(itemIdList);
+ });
+
action = m_menu->addAction( qtr("Play as audio") );
connect(action, &QAction::triggered, [ml, itemIdList]( ) {
QStringList options({":no-video"});
@@ -380,6 +392,135 @@ void VideoContextMenu::popup(const QModelIndexList& selected, QPoint pos, QVaria
m_menu->popup(pos);
}
+//=================================================================================================
+// PlaylistListContextMenu
+//=================================================================================================
+
+PlaylistListContextMenu::PlaylistListContextMenu(QObject * parent)
+ : QObject(parent)
+{}
+
+PlaylistListContextMenu::~PlaylistListContextMenu() /* override */
+{
+ if (m_menu)
+ delete m_menu;
+}
+
+void PlaylistListContextMenu::popup(const QModelIndexList & selected, QPoint pos, QVariantMap)
+{
+ if (!m_model)
+ return;
+
+ if (m_menu)
+ delete m_menu;
+
+ QVariantList ids;
+
+ for (const QModelIndex & modelIndex : selected)
+ ids.push_back(m_model->data(modelIndex, MLPlaylistListModel::PLAYLIST_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);
+ });
+
+ action = m_menu->addAction(qtr("Delete"));
+
+ connect(action, &QAction::triggered, [this, ids]() {
+ m_model->deletePlaylists(ids);
+ });
+
+ m_menu->popup(pos);
+}
+
+//=================================================================================================
+// PlaylistMediaContextMenu
+//=================================================================================================
+
+PlaylistMediaContextMenu::PlaylistMediaContextMenu(QObject * parent) : QObject(parent) {}
+
+PlaylistMediaContextMenu::~PlaylistMediaContextMenu() /* override */
+{
+ if (m_menu)
+ delete m_menu;
+}
+
+void PlaylistMediaContextMenu::popup(const QModelIndexList & selected, QPoint pos,
+ QVariantMap options)
+{
+ if (!m_model)
+ return;
+
+ if (m_menu)
+ delete m_menu;
+
+ QVariantList ids;
+
+ for (const QModelIndex& modelIndex : selected)
+ ids.push_back(m_model->data(modelIndex, MLPlaylistModel::MEDIA_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);
+ });
+
+ action = m_menu->addAction(qtr("Add to playlist"));
+
+ connect(action, &QAction::triggered, [ml, ids]() {
+ DialogsProvider::getInstance()->playlistsDialog(ids);
+ });
+
+ action = m_menu->addAction(qtr("Play as audio"));
+
+ connect(action, &QAction::triggered, [ml, ids]() {
+ QStringList options({":no-video"});
+ ml->addAndPlay(ids, &options);
+ });
+
+ if (options.contains("information") && options["information"].type() == QVariant::Int) {
+ action = m_menu->addAction(qtr("Information"));
+
+ QSignalMapper * mapper = new QSignalMapper(m_menu);
+
+ connect(action, &QAction::triggered, mapper, QOverload<>::of(&QSignalMapper::map));
+
+ mapper->setMapping(action, options["information"].toInt());
+#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+ connect(mapper, &QSignalMapper::mappedInt, this,
+ &PlaylistMediaContextMenu::showMediaInformation);
+#else
+ connect(mapper, QOverload<int>::of(&QSignalMapper::mapped), this,
+ &PlaylistMediaContextMenu::showMediaInformation);
+#endif
+ }
+
+ m_menu->popup(pos);
+}
+
+//=================================================================================================
+
NetworkMediaContextMenu::NetworkMediaContextMenu(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 d9a87ddb7a..8481839189 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 MLPlaylistListModel;
+class MLPlaylistModel;
class NetworkDeviceModel;
class NetworkMediaModel;
class QmlMainContext;
@@ -214,6 +216,34 @@ private:
QMenu* m_menu = nullptr;
};
+class PlaylistListContextMenu : public QObject {
+ Q_OBJECT
+ SIMPLE_MENU_PROPERTY(MLPlaylistListModel *, model, nullptr)
+public:
+ PlaylistListContextMenu(QObject * parent = nullptr);
+ ~PlaylistListContextMenu() /* override */;
+
+public slots:
+ void popup(const QModelIndexList & selected, QPoint pos, QVariantMap options = {});
+private:
+ QMenu* m_menu = nullptr;
+};
+
+class PlaylistMediaContextMenu : public QObject {
+ Q_OBJECT
+ SIMPLE_MENU_PROPERTY(MLPlaylistModel *, model, nullptr)
+public:
+ PlaylistMediaContextMenu(QObject * parent = nullptr);
+ ~PlaylistMediaContextMenu() /* override */;
+
+public slots:
+ void popup(const QModelIndexList & selected, QPoint pos, QVariantMap options = {});
+signals:
+ void showMediaInformation(int index);
+private:
+ QMenu* m_menu = nullptr;
+};
+
class NetworkMediaContextMenu : public QObject {
Q_OBJECT
SIMPLE_MENU_PROPERTY(NetworkMediaModel*, model, nullptr)
--
2.25.1
More information about the vlc-devel
mailing list