[vlc-devel] [PATCH 04/14] qt: retreive the artwork when available in network models

Pierre Lamot pierre at videolabs.io
Thu Feb 6 13:56:41 CET 2020


---
 modules/gui/qt/network/networkdevicemodel.cpp | 11 +++++++++++
 modules/gui/qt/network/networkdevicemodel.hpp |  1 +
 modules/gui/qt/network/networkmediamodel.cpp  | 11 +++++++++++
 modules/gui/qt/network/networkmediamodel.hpp  |  1 +
 4 files changed, 24 insertions(+)

diff --git a/modules/gui/qt/network/networkdevicemodel.cpp b/modules/gui/qt/network/networkdevicemodel.cpp
index c82740921d..c71d99ce80 100644
--- a/modules/gui/qt/network/networkdevicemodel.cpp
+++ b/modules/gui/qt/network/networkdevicemodel.cpp
@@ -31,6 +31,7 @@ enum Role {
     NETWORK_PROTOCOL,
     NETWORK_SOURCE,
     NETWORK_TREE,
+    NETWORK_ARTWORK
 };
 
 }
@@ -63,6 +64,8 @@ QVariant NetworkDeviceModel::data( const QModelIndex& index, int role ) const
             return item.mediaSource->description;
         case NETWORK_TREE:
             return QVariant::fromValue( NetworkTreeItem(item.mediaSource, item.inputItem.get()) );
+        case NETWORK_ARTWORK:
+            return item.artworkUrl;
         default:
             return {};
     }
@@ -77,6 +80,7 @@ QHash<int, QByteArray> NetworkDeviceModel::roleNames() const
         { NETWORK_PROTOCOL, "protocol" },
         { NETWORK_SOURCE, "source" },
         { NETWORK_TREE, "tree" },
+        { NETWORK_ARTWORK, "artwork" },
     };
 }
 
@@ -294,6 +298,13 @@ void NetworkDeviceModel::refreshDeviceList( MediaSourcePtr mediaSource, input_it
             item.mediaSource = mediaSource;
             item.inputItem = InputItemPtr(p_item);
 
+            char* artwork = input_item_GetArtworkURL( p_item.get() );
+            if (artwork)
+            {
+                item.artworkUrl = QUrl::fromEncoded(artwork);
+                free(artwork);
+            }
+
             auto it = std::upper_bound(begin( m_items ), end( m_items ), item, [](const Item& a, const Item& b) {
                 int comp =  QString::compare(a.name , b.name, Qt::CaseInsensitive );
                 if (comp == 0)
diff --git a/modules/gui/qt/network/networkdevicemodel.hpp b/modules/gui/qt/network/networkdevicemodel.hpp
index 0eb115ead3..e53c6a96d6 100644
--- a/modules/gui/qt/network/networkdevicemodel.hpp
+++ b/modules/gui/qt/network/networkdevicemodel.hpp
@@ -106,6 +106,7 @@ private:
         ItemType type;
         MediaSourcePtr mediaSource;
         InputItemPtr inputItem;
+        QUrl artworkUrl;
     };
 
     bool initializeMediaSources();
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index 5d27ab8eb6..06422667b4 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -34,6 +34,7 @@ enum Role {
     NETWORK_PROTOCOL,
     NETWORK_TREE,
     NETWORK_SOURCE,
+    NETWORK_ARTWORK,
 };
 
 }
@@ -82,6 +83,8 @@ QVariant NetworkMediaModel::data( const QModelIndex& index, int role ) const
             return QVariant::fromValue( item.tree );
         case NETWORK_SOURCE:
             return item.mediaSource->description;
+        case NETWORK_ARTWORK:
+            return item.artworkUrl;
         default:
             return {};
     }
@@ -98,6 +101,7 @@ QHash<int, QByteArray> NetworkMediaModel::roleNames() const
         { NETWORK_PROTOCOL, "protocol" },
         { NETWORK_TREE, "tree" },
         { NETWORK_SOURCE, "source" },
+        { NETWORK_ARTWORK, "artwork" },
     };
 }
 
@@ -397,6 +401,13 @@ void NetworkMediaModel::refreshMediaList( MediaSourcePtr mediaSource,
         item.canBeIndexed = canBeIndexed( item.mainMrl , item.type );
         item.mediaSource = mediaSource;
 
+        char* artwork = input_item_GetArtworkURL(it.get());
+        if (artwork)
+        {
+            item.artworkUrl = QUrl::fromEncoded(artwork);
+            free(artwork);
+        }
+
         if ( item.canBeIndexed == true )
         {
             if ( vlc_ml_is_indexed( m_ml, qtu( item.mainMrl.toString( QUrl::FullyEncoded ) ),
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index 59dae326e6..08c5c64512 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -153,6 +153,7 @@ private:
         bool canBeIndexed;
         NetworkTreeItem tree;
         MediaSourcePtr mediaSource;
+        QUrl artworkUrl;
     };
 
 
-- 
2.17.1



More information about the vlc-devel mailing list