[vlc-devel] [PATCH 25/49] qt: allow accessing properties of the current tree node in MLNetworkModel
Pierre Lamot
pierre at videolabs.io
Fri Oct 11 15:17:49 CEST 2019
---
.../components/mediacenter/mlnetworkmodel.cpp | 33 +++++++++++++++++
.../components/mediacenter/mlnetworkmodel.hpp | 35 ++++++++++++++++---
2 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkmodel.cpp b/modules/gui/qt/components/mediacenter/mlnetworkmodel.cpp
index 0b8901241c..a12fb90983 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkmodel.cpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkmodel.cpp
@@ -119,6 +119,22 @@ bool MLNetworkModel::setData( const QModelIndex& idx, const QVariant& value, int
return res == VLC_SUCCESS;
}
+void MLNetworkModel::setIndexed(bool indexed)
+{
+ if (indexed == m_indexed || !m_canBeIndexed)
+ return;
+ int res;
+ if ( indexed )
+ res = vlc_ml_add_folder( m_ml, qtu( m_url.toString( QUrl::None ) ) );
+ else
+ res = vlc_ml_remove_folder( m_ml, qtu( m_url.toString( QUrl::None ) ) );
+
+ if (res == VLC_SUCCESS) {
+ m_indexed = indexed;
+ emit isIndexedChanged();
+ }
+}
+
void MLNetworkModel::setCtx(QmlMainContext* ctx)
{
if (ctx) {
@@ -213,6 +229,23 @@ bool MLNetworkModel::initializeMediaSources()
std::unique_ptr<SourceListener> l{ new SourceListener( m_treeItem.source, this ) };
if ( l->listener == nullptr )
return false;
+
+ if (m_treeItem.media)
+ {
+ m_name = m_treeItem.media->psz_name;
+ emit nameChanged();
+ m_url = QUrl::fromEncoded( QByteArray{ m_treeItem.media->psz_uri }.append( '/' ) );
+ emit urlChanged();
+ m_type = static_cast<ItemType>(m_treeItem.media->i_type);
+ emit typeChanged();
+ m_canBeIndexed = canBeIndexed( m_url, m_type );
+ emit canBeIndexedChanged();
+ if ( vlc_ml_is_indexed( m_ml, QByteArray(m_treeItem.media->psz_uri).append('/').constData(), &m_indexed ) != VLC_SUCCESS ) {
+ m_indexed = false;
+ }
+ emit isIndexedChanged();
+ }
+
vlc_media_tree_Preparse( tree, libvlc, m_treeItem.media.get() );
m_listeners.push_back( std::move( l ) );
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkmodel.hpp b/modules/gui/qt/components/mediacenter/mlnetworkmodel.hpp
index a2ffc15d03..6e26605dde 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkmodel.hpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkmodel.hpp
@@ -85,6 +85,12 @@ public:
Q_PROPERTY(bool is_on_provider_list READ getIsOnProviderList WRITE setIsOnProviderList NOTIFY isOnProviderListChanged)
Q_PROPERTY(QString sd_source READ getSdSource WRITE setSdSource NOTIFY sdSourceChanged)
+ Q_PROPERTY(QString name READ getName NOTIFY nameChanged)
+ Q_PROPERTY(QUrl url READ getUrl NOTIFY urlChanged)
+ Q_PROPERTY(ItemType type READ getType NOTIFY typeChanged)
+ Q_PROPERTY(bool indexed READ isIndexed WRITE setIndexed NOTIFY isIndexedChanged)
+ Q_PROPERTY(bool canBeIndexed READ canBeIndexed NOTIFY canBeIndexedChanged)
+
explicit MLNetworkModel(QObject* parent = nullptr);
MLNetworkModel( QmlMainContext* ctx, QString parentMrl, QObject* parent = nullptr );
@@ -95,17 +101,31 @@ public:
Qt::ItemFlags flags( const QModelIndex& idx ) const override;
bool setData( const QModelIndex& idx,const QVariant& value, int role ) override;
+
+ void setIndexed(bool indexed);
void setCtx(QmlMainContext* ctx);
void setTree(QVariant tree);
void setIsOnProviderList(bool b);
void setSdSource(QString s);
- inline QmlMainContext* getCtx() { return m_ctx; }
- inline QVariant getTree() { return QVariant::fromValue( m_treeItem); }
- inline bool getIsOnProviderList() { return m_isOnProviderList; }
- inline QString getSdSource() { return m_sdSource; }
+ inline QString getName() const { return m_name; }
+ inline QUrl getUrl() const { return m_url; }
+ inline ItemType getType() const { return m_type; }
+ inline bool isIndexed() const { return m_indexed; }
+ inline bool canBeIndexed() const { return m_canBeIndexed; }
+
+ inline QmlMainContext* getCtx() const { return m_ctx; }
+ inline QVariant getTree() const { return QVariant::fromValue( m_treeItem); }
+ inline bool getIsOnProviderList() const { return m_isOnProviderList; }
+ inline QString getSdSource() const { return m_sdSource; }
signals:
+ void nameChanged();
+ void urlChanged();
+ void typeChanged();
+ void isIndexedChanged();
+ void canBeIndexedChanged();
+
void ctxChanged();
void treeChanged();
void isOnProviderListChanged();
@@ -176,6 +196,13 @@ private:
MLNetworkModel *model;
};
+ //properties of the current node
+ QString m_name;
+ QUrl m_url;
+ ItemType m_type = ItemType::TYPE_UNKNOWN;
+ bool m_indexed = false;
+ bool m_canBeIndexed = false;
+
std::vector<Item> m_items;
QmlMainContext* m_ctx = nullptr;
vlc_medialibrary_t* m_ml;
--
2.20.1
More information about the vlc-devel
mailing list