15#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
16#include <QStringConverter>
25inline QString
GetBool(
bool bVal ) {
return( (bVal) ?
"1" :
"0" ); }
36 const QString &sTitle,
37 const QString &sParentId )
98 QList<Property*> props;
115 const QString &sType )
120 if ((*it)->m_bMultiValue)
122 LOG(VB_UPNP, LOG_WARNING,
123 QString(
"SetPropValue(%1) called on property with bAllowMulti. "
124 "Only the last inserted property will be updated.").arg(sName));
126 (*it)->SetValue(sValue);
128 if (!sType.isEmpty())
129 (*it)->AddAttribute(
"type", sType );
133 LOG(VB_UPNP, LOG_WARNING,
134 QString(
"SetPropValue(%1) called with non-existent property.").arg(sName));
144 Properties::const_iterator it =
m_properties.find(sName);
148 if ((*it)->m_bMultiValue)
150 LOG(VB_UPNP, LOG_WARNING,
151 QString(
"GetPropValue(%1) called on property with bAllowMulti. "
152 "Only the last inserted property will be return."));
154 return (*it)->GetValue().toUtf8();
186 CDSObjects::iterator it;
193 if (pChild->
m_sId == sID)
206 auto *pRes =
new Resource( sProtocol, sURI );
264 bool ignoreChildren )
const
267 QTextStream os( &sXML, QIODevice::WriteOnly );
268#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
269 os.setCodec(QTextCodec::codecForName(
"UTF-8"));
271 os.setEncoding(QStringConverter::Utf8);
273 toXml(os, filter, ignoreChildren);
283 bool ignoreChildren )
const
285 QString sEndTag =
"";
313 if (filter.contains(
"*"))
320 if (bFilter && filter.contains(
"container#"))
323 os <<
"<container id=\"" <<
m_sId
327 if (!bFilter || filter.contains(
"@searchable"))
330 if (!bFilter || filter.contains(
"@childCount"))
333 if (!bFilter || filter.contains(
"@childContainerCount"))
336 os <<
"\" >" << Qt::endl;
338 sEndTag =
"</container>";
344 if (bFilter && filter.contains(
"item#"))
347 os <<
"<item id=\"" <<
m_sId
350 <<
"\" >" << Qt::endl;
359 os <<
"<dc:title>" <<
m_sTitle <<
"</dc:title>" << Qt::endl;
360 os <<
"<upnp:class>" <<
m_sClass <<
"</upnp:class>" << Qt::endl;
368 if (pProp->m_bRequired || (!pProp->GetValue().isEmpty()))
372 if (!pProp->m_sNameSpace.isEmpty())
373 sName = pProp->m_sNameSpace +
':' + pProp->m_sName;
375 sName = pProp->m_sName;
377 if (pProp->m_bRequired ||
381 bool filterAttributes =
true;
382 if (!bFilter || filter.contains(QString(
"%1#").arg(sName)))
383 filterAttributes =
false;
387 for (
const auto & attr : std::as_const(pProp->m_lstAttributes))
389 QString filterName = QString(
"%1@%2").arg(sName,
391 if (attr.m_bRequired || !filterAttributes ||
392 filter.contains(filterName))
393 os <<
" " << attr.m_sName <<
"=\"" << attr.m_sValue <<
"\"";
397 os << pProp->GetEncodedValue();
398 os <<
"</" << sName <<
">" << Qt::endl;
407 if (!bFilter || filter.contains(
"res"))
409 bool filterAttributes =
true;
410 if (!bFilter || filter.contains(
"res#"))
411 filterAttributes =
false;
414 os <<
"<res protocolInfo=\"" << resource->m_sProtocolInfo <<
"\" ";
417 for (
const auto & attr : std::as_const(resource->m_lstAttributes))
419 filterName = QString(
"res@%1").arg(attr.m_sName);
420 if (attr.m_bRequired || !filterAttributes ||
421 filter.contains(filterName))
422 os << attr.m_sName <<
"=\"" << attr.m_sValue <<
"\" ";
425 os <<
">" << resource->m_sURI;
426 os <<
"</res>" << Qt::endl;
437 cit->toXml(os, filter);
444 os << sEndTag << Qt::endl;
455 if (pObject ==
nullptr)
457 pObject =
new CDSObject( sId, sTitle, sParentId );
473 if (pObject ==
nullptr)
475 pObject =
new CDSObject( sId, sTitle, sParentId );
476 pObject->
m_sClass =
"object.container";
500 if (pObject ==
nullptr)
502 pObject =
new CDSObject( sId, sTitle, sParentId );
503 pObject->
m_sClass =
"object.item.audioItem";
506 CreateItem( sId, sTitle, sParentId, pObject );
526 if (pObject ==
nullptr)
528 pObject =
new CDSObject( sId, sTitle, sParentId );
529 pObject->
m_sClass =
"object.item.audioItem.musicTrack";
568 if (pObject ==
nullptr)
570 pObject =
new CDSObject( sId, sTitle, sParentId );
571 pObject->
m_sClass =
"object.item.audioItem.audioBroadcast";
589 if (pObject ==
nullptr)
591 pObject =
new CDSObject( sId, sTitle, sParentId );
592 pObject->
m_sClass =
"object.item.audioItem.audioBook";
608 if (pObject ==
nullptr)
610 pObject =
new CDSObject( sId, sTitle, sParentId );
611 pObject->
m_sClass =
"object.item.videoItem";
614 CreateItem( sId, sTitle, sParentId, pObject );
666 if (pObject ==
nullptr)
668 pObject =
new CDSObject( sId, sTitle, sParentId );
669 pObject->
m_sClass =
"object.item.videoItem.movie";
684 if (pObject ==
nullptr)
686 pObject =
new CDSObject( sId, sTitle, sParentId );
687 pObject->
m_sClass =
"object.item.videoItem.videoBroadcast";
702 if (pObject ==
nullptr)
704 pObject =
new CDSObject( sId, sTitle, sParentId );
705 pObject->
m_sClass =
"object.item.videoItem.musicVideoClip";
722 if (pObject ==
nullptr)
724 pObject =
new CDSObject( sId, sTitle, sParentId );
725 pObject->
m_sClass =
"object.item.imageItem";
728 CreateItem( sId, sTitle, sParentId, pObject );
747 if (pObject ==
nullptr)
749 pObject =
new CDSObject( sId, sTitle, sParentId );
750 pObject->
m_sClass =
"object.item.imageItem.photo";
764 if (pObject ==
nullptr)
766 pObject =
new CDSObject( sId, sTitle, sParentId );
767 pObject->
m_sClass =
"object.item.playlistItem";
770 CreateItem( sId, sTitle, sParentId, pObject );
786 if (pObject ==
nullptr)
788 pObject =
new CDSObject( sId, sTitle, sParentId );
789 pObject->
m_sClass =
"object.item.textItem";
792 CreateItem( sId, sTitle, sParentId, pObject );
813 if (pObject ==
nullptr)
815 pObject =
new CDSObject( sId, sTitle, sParentId );
816 pObject->
m_sClass =
"object.container.album";
840 if (pObject ==
nullptr)
842 pObject =
new CDSObject( sId, sTitle, sParentId );
843 pObject->
m_sClass =
"object.container.album.musicAlbum";
860 if (pObject ==
nullptr)
862 pObject =
new CDSObject( sId, sTitle, sParentId );
863 pObject->
m_sClass =
"object.container.album.photoAlbum";
875 if (pObject ==
nullptr)
877 pObject =
new CDSObject( sId, sTitle, sParentId );
878 pObject->
m_sClass =
"object.container.genre";
890 if (pObject ==
nullptr)
892 pObject =
new CDSObject( sId, sTitle, sParentId );
893 pObject->
m_sClass =
"object.container.genre.musicGenre";
905 if (pObject ==
nullptr)
907 pObject =
new CDSObject( sId, sTitle, sParentId );
908 pObject->
m_sClass =
"object.container.genre.movieGenre";
920 if (pObject ==
nullptr)
922 pObject =
new CDSObject( sId, sTitle, sParentId );
923 pObject->
m_sClass =
"object.container.playlistContainer";
943 if (pObject ==
nullptr)
945 pObject =
new CDSObject( sId, sTitle, sParentId );
946 pObject->
m_sClass =
"object.container.person";
960 if (pObject ==
nullptr)
962 pObject =
new CDSObject( sId, sTitle, sParentId );
963 pObject->
m_sClass =
"object.container.person.musicArtist";
978 if (pObject ==
nullptr)
980 pObject =
new CDSObject( sId, sTitle, sParentId );
981 pObject->
m_sClass =
"object.container.storageSystem";
999 if (pObject ==
nullptr)
1001 pObject =
new CDSObject( sId, sTitle, sParentId );
1002 pObject->
m_sClass =
"object.container.storageVolume";
1019 if (pObject ==
nullptr)
1021 pObject =
new CDSObject( sId, sTitle, sParentId );
1022 pObject->
m_sClass =
"object.container.storageFolder";
1038 if (filter.contains(name, Qt::CaseInsensitive))
1045 QString dependentAttribute = QString(
"%1@").arg(name);
1046 QStringList matches = filter.filter(name, Qt::CaseInsensitive);
1047 QStringList::iterator it;
1048 for (it = matches.begin(); it != matches.end(); ++it)
1050 if ((*it).startsWith(dependentAttribute))
QMap< uint, int > FilterMap
static CDSObject * CreateContainer(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
uint32_t GetChildCount(void) const
Return the number of children in this container.
static CDSObject * CreateVideoBroadcast(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateMusicArtist(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateImageItem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
CDSObject(const QString &sId="-1", const QString &sTitle="", const QString &sParentId="-1")
void SetChildCount(uint32_t nCount)
Allows the caller to set childCount without having to load children.
static CDSObject * CreateVideoItem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateMovie(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreatePhoto(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateMusicTrack(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateAudioItem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
QString toXml(FilterMap &filter, bool ignoreChildren=false) const
static CDSObject * CreatePerson(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateGenre(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateMusicVideoClip(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
Resource * AddResource(const QString &sProtocol, const QString &sURI)
CDSObject * AddChild(CDSObject *pChild)
static CDSObject * CreatePhotoAlbum(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateAlbum(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateTextItem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateItem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
uint32_t m_nChildContainerCount
static CDSObject * CreateMovieGenre(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
CDSObject * GetChild(const QString &sID)
static CDSObject * CreateAudioBook(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
uint32_t GetChildContainerCount(void) const
Return the number of child containers in this container.
void SetPropValue(const QString &sName, const QString &sValue, const QString &type="")
QList< Property * > GetProperties(const QString &sName)
static CDSObject * CreateAudioBroadcast(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
Property * AddProperty(Property *pProp)
QString GetPropValue(const QString &sName) const
static bool FilterContains(const FilterMap &filter, const QString &name)
void SetChildContainerCount(uint32_t nCount)
Allows the caller to set childContainerCount without having to load children.
static CDSObject * CreatePlaylistContainer(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreatePlaylistItem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateStorageVolume(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateMusicGenre(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateMusicAlbum(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateStorageSystem(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
static CDSObject * CreateStorageFolder(const QString &sId, const QString &sTitle, const QString &sParentId, CDSObject *pObject=nullptr)
General purpose reference counter.
virtual int IncrRef(void)
Increments reference count.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QString GetBool(bool bVal)