[vlc-devel] [PATCH 4/7] qt: play media using input item rather than the mrl when browsing networks.
Pierre Lamot
pierre at videolabs.io
Mon Oct 21 18:08:56 CEST 2019
using the input item discovered by the Media Tree may provide more properties
than using the mrl, such as attached subtitles.
NetworkMediaModel and NetworkDeviceModel now expose an
addToPlaylist and addAndPlay method like the media library
---
.../mediacenter/mlnetworkdevicemodel.cpp | 55 ++++++++++++++++++
.../mediacenter/mlnetworkdevicemodel.hpp | 5 ++
.../mediacenter/mlnetworkmediamodel.cpp | 56 +++++++++++++++++++
.../mediacenter/mlnetworkmediamodel.hpp | 5 ++
.../mediacenter/MCNetworkBrowseDisplay.qml | 2 +-
.../MCNetworksSectionSelectableDM.qml | 16 +++---
6 files changed, 130 insertions(+), 9 deletions(-)
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp
index e2eb5f9ba2..7fa57c7813 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp
@@ -111,6 +111,61 @@ void MLNetworkDeviceModel::setSdSource(SDCatType s)
emit sdSourceChanged();
}
+
+bool MLNetworkDeviceModel::addToPlaylist(int index)
+{
+ if (!(m_ctx && m_sdSource != CAT_MYCOMPUTER))
+ return false;
+ if (index < 0 || index >= m_items.size() )
+ return false;
+ auto item = m_items[index];
+ vlc::playlist::Media media{ item.inputItem.get() };
+ return true;
+}
+
+bool MLNetworkDeviceModel::addToPlaylist(const QVariantList &itemIdList)
+{
+ bool ret = false;
+ for (const QVariant& varValue: itemIdList)
+ {
+ if (varValue.canConvert<int>())
+ {
+ auto index = varValue.value<int>();
+ ret |= addToPlaylist(index);
+ }
+ }
+ return ret;
+}
+
+bool MLNetworkDeviceModel::addAndPlay(int index)
+{
+ if (!(m_ctx && m_sdSource != CAT_MYCOMPUTER))
+ return false;
+ if (index < 0 || index >= m_items.size() )
+ return false;
+ auto item = m_items[index];
+ vlc::playlist::Media media{ item.inputItem.get() };
+ m_ctx->getIntf()->p_sys->p_mainPlaylistController->append( { media }, true);
+ return true;
+}
+
+bool MLNetworkDeviceModel::addAndPlay(const QVariantList& itemIdList)
+{
+ bool ret = false;
+ for (const QVariant& varValue: itemIdList)
+ {
+ if (varValue.canConvert<int>())
+ {
+ auto index = varValue.value<int>();
+ if (!ret)
+ ret |= addAndPlay(index);
+ else
+ ret |= addToPlaylist(index);
+ }
+ }
+ return ret;
+}
+
bool MLNetworkDeviceModel::initializeMediaSources()
{
auto libvlc = vlc_object_instance(m_ctx->getIntf());
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.hpp b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.hpp
index a1d354c3a3..df142402c7 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.hpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.hpp
@@ -80,6 +80,11 @@ public:
inline QmlMainContext* getCtx() { return m_ctx; }
inline SDCatType getSdSource() { return m_sdSource; }
+ Q_INVOKABLE bool addToPlaylist( int index );
+ Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
+ Q_INVOKABLE bool addAndPlay( int index );
+ Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
+
signals:
void ctxChanged();
void sdSourceChanged();
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.cpp b/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.cpp
index 53b9cab2d8..f1a15d020f 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.cpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.cpp
@@ -166,6 +166,62 @@ void MLNetworkMediaModel::setTree(QVariant parentTree)
emit treeChanged();
}
+bool MLNetworkMediaModel::addToPlaylist(int index)
+{
+ if (!(m_ctx && m_hasTree))
+ return false;
+ if (index < 0 || index >= m_items.size() )
+ return false;
+ auto item = m_items[index];
+ vlc::playlist::Media media{ item.tree.media.get() };
+ m_ctx->getIntf()->p_sys->p_mainPlaylistController->append( { media }, false);
+ return true;
+}
+
+bool MLNetworkMediaModel::addToPlaylist(const QVariantList &itemIdList)
+{
+ bool ret = false;
+ for (const QVariant& varValue: itemIdList)
+ {
+ if (varValue.canConvert<int>())
+ {
+ auto index = varValue.value<int>();
+ ret |= addToPlaylist(index);
+ }
+ }
+ return ret;
+}
+
+bool MLNetworkMediaModel::addAndPlay(int index)
+{
+ if (!(m_ctx && m_hasTree))
+ return false;
+ if (index < 0 || index >= m_items.size() )
+ return false;
+ auto item = m_items[index];
+ vlc::playlist::Media media{ item.tree.media.get() };
+ m_ctx->getIntf()->p_sys->p_mainPlaylistController->append( { media }, true);
+ return true;
+}
+
+bool MLNetworkMediaModel::addAndPlay(const QVariantList& itemIdList)
+{
+ bool ret = false;
+ for (const QVariant& varValue: itemIdList)
+ {
+ if (varValue.canConvert<int>())
+ {
+ auto index = varValue.value<int>();
+ if (!ret)
+ ret |= addAndPlay(index);
+ else
+ ret |= addToPlaylist(index);
+ }
+ }
+ return ret;
+}
+
+
bool MLNetworkMediaModel::initializeMediaSources()
{
auto libvlc = vlc_object_instance(m_ctx->getIntf());
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.hpp b/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.hpp
index e7d84ba326..c21f44577e 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.hpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkmediamodel.hpp
@@ -118,6 +118,11 @@ public:
inline bool isIndexed() const { return m_indexed; }
inline bool canBeIndexed() const { return m_canBeIndexed; }
+ Q_INVOKABLE bool addToPlaylist( int index );
+ Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
+ Q_INVOKABLE bool addAndPlay( int index );
+ Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
+
signals:
void nameChanged();
void urlChanged();
diff --git a/modules/gui/qt/qml/mediacenter/MCNetworkBrowseDisplay.qml b/modules/gui/qt/qml/mediacenter/MCNetworkBrowseDisplay.qml
index c8881c86e7..d3831bb52c 100644
--- a/modules/gui/qt/qml/mediacenter/MCNetworkBrowseDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MCNetworkBrowseDisplay.qml
@@ -176,7 +176,7 @@ Utils.NavigableFocusScope {
if (model.type === MLNetworkMediaModel.TYPE_NODE || model.type === MLNetworkMediaModel.TYPE_DIRECTORY)
history.push( ["mc", "network", { tree: model.tree } ], History.Go)
else
- medialib.addAndPlay( model.mrl )
+ delegateModel.model.addAndPlay( index )
}
onContextMenuButtonClicked: {
diff --git a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
index 72eca97391..09ba11f34e 100644
--- a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
+++ b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
@@ -48,7 +48,7 @@ Utils.SelectableDelegateModel {
if (model.type === MLNetworkMediaModel.TYPE_NODE || model.type === MLNetworkMediaModel.TYPE_DIRECTORY)
history.push( ["mc", "network", { tree: model.tree } ], History.Go)
else
- medialib.addAndPlay( model.mrl )
+ delegateModel.model.addAndPlay( index )
}
onContextMenuButtonClicked: {
@@ -73,7 +73,7 @@ Utils.SelectableDelegateModel {
if (model.type === MLNetworkMediaModel.TYPE_NODE || model.type === MLNetworkMediaModel.TYPE_DIRECTORY)
history.push( ["mc", "network", { tree: model.tree } ], History.Go)
else
- medialib.addAndPlay( model.mrl )
+ delegateModel.model.addAndPlay( index )
}
onContextMenuButtonClicked: {
@@ -101,19 +101,19 @@ Utils.SelectableDelegateModel {
function playSelection() {
var list = []
for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
- var mrl = delegateModel.selectedGroup.get(i).model.mrl;
- list.push(mrl)
+ var index = delegateModel.selectedGroup.get(i).itemsIndex;
+ list.push(index)
}
- medialib.addAndPlay( list )
+ delegateModel.model.addAndPlay( list )
}
function enqueueSelection() {
var list = []
for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
- var mrl = delegateModel.selectedGroup.get(i).model.mrl;
- list.push(mrl)
+ var index = delegateModel.selectedGroup.get(i).itemsIndex;
+ list.push(index)
}
- medialib.addToPlaylist( list )
+ delegateModel.model.addToPlaylist( list )
}
function actionAtIndex(index) {
--
2.17.1
More information about the vlc-devel
mailing list