diff --git a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp index e2eb5f9ba2d79c57c3daa33a42dcf513f518feaa..7fa57c781372a04ef683a248486d3207d9cf2628 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 a1d354c3a3ffb5d036b4f9cbca51aa6df2d51688..df142402c7c517b10d57522a373cd41ea76f44aa 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 53b9cab2d8808846dc8c72613201e9a21ca6fa49..f1a15d020fbf6aa9ac70d9002d0d0ad3ede9dfb1 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 e7d84ba326ab43d8afe9b350fff3f1a6773f94a5..c21f44577e94f5e4f3551d9c4fb69d4871725bd4 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 c8881c86e7eed51881c0ec22f3e7271858ddc60f..d3831bb52c96e2f65e61b065c9a9b46b025ceda7 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 72eca9739176dddc7a13d9a2866fa0b50cff53a4..09ba11f34e1d7bd7b36464ebe959ac1c3eb636ad 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) {