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 )
39 m_sId(QUrl::toPercentEncoding(sId)),
40 m_sParentId(QUrl::toPercentEncoding(sParentId)),
41 m_sTitle(QUrl::toPercentEncoding(sTitle))
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#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
268 QTextStream os( &sXML, QIODevice::WriteOnly );
269 os.setCodec(QTextCodec::codecForName(
"UTF-8"));
271 QTextStream os(&sXML, QIODeviceBase::WriteOnly);
272 os.setEncoding(QStringConverter::Utf8);
274 toXml(os, filter, ignoreChildren);
284 bool ignoreChildren )
const
286 QString sEndTag =
"";
314 if (filter.contains(
"*"))
321 if (bFilter && filter.contains(
"container#"))
324 os <<
"<container id=\"" <<
m_sId
328 if (!bFilter || filter.contains(
"@searchable"))
331 if (!bFilter || filter.contains(
"@childCount"))
334 if (!bFilter || filter.contains(
"@childContainerCount"))
337 os <<
"\" >" << Qt::endl;
339 sEndTag =
"</container>";
345 if (bFilter && filter.contains(
"item#"))
348 os <<
"<item id=\"" <<
m_sId
351 <<
"\" >" << Qt::endl;
360 os <<
"<dc:title>" <<
m_sTitle <<
"</dc:title>" << Qt::endl;
361 os <<
"<upnp:class>" <<
m_sClass <<
"</upnp:class>" << Qt::endl;
369 if (pProp->m_bRequired || (!pProp->GetValue().isEmpty()))
373 if (!pProp->m_sNameSpace.isEmpty())
374 sName = pProp->m_sNameSpace +
':' + pProp->m_sName;
376 sName = pProp->m_sName;
378 if (pProp->m_bRequired ||
382 bool filterAttributes =
true;
383 if (!bFilter || filter.contains(QString(
"%1#").arg(sName)))
384 filterAttributes =
false;
388 for (
const auto & attr : std::as_const(pProp->m_lstAttributes))
390 QString filterName = QString(
"%1@%2").arg(sName,
392 if (attr.m_bRequired || !filterAttributes ||
393 filter.contains(filterName))
394 os <<
" " << attr.m_sName <<
"=\"" << attr.m_sValue <<
"\"";
398 os << pProp->GetEncodedValue();
399 os <<
"</" << sName <<
">" << Qt::endl;
408 if (!bFilter || filter.contains(
"res"))
410 bool filterAttributes =
true;
411 if (!bFilter || filter.contains(
"res#"))
412 filterAttributes =
false;
415 os <<
"<res protocolInfo=\"" << resource->m_sProtocolInfo <<
"\" ";
418 for (
const auto & attr : std::as_const(resource->m_lstAttributes))
420 filterName = QString(
"res@%1").arg(attr.m_sName);
421 if (attr.m_bRequired || !filterAttributes ||
422 filter.contains(filterName))
423 os << attr.m_sName <<
"=\"" << attr.m_sValue <<
"\" ";
426 os <<
">" << resource->m_sURI;
427 os <<
"</res>" << Qt::endl;
438 cit->toXml(os, filter);
445 os << sEndTag << Qt::endl;
456 if (pObject ==
nullptr)
458 pObject =
new CDSObject( sId, sTitle, sParentId );
474 if (pObject ==
nullptr)
476 pObject =
new CDSObject( sId, sTitle, sParentId );
477 pObject->
m_sClass =
"object.container";
501 if (pObject ==
nullptr)
503 pObject =
new CDSObject( sId, sTitle, sParentId );
504 pObject->
m_sClass =
"object.item.audioItem";
507 CreateItem( sId, sTitle, sParentId, pObject );
527 if (pObject ==
nullptr)
529 pObject =
new CDSObject( sId, sTitle, sParentId );
530 pObject->
m_sClass =
"object.item.audioItem.musicTrack";
569 if (pObject ==
nullptr)
571 pObject =
new CDSObject( sId, sTitle, sParentId );
572 pObject->
m_sClass =
"object.item.audioItem.audioBroadcast";
590 if (pObject ==
nullptr)
592 pObject =
new CDSObject( sId, sTitle, sParentId );
593 pObject->
m_sClass =
"object.item.audioItem.audioBook";
609 if (pObject ==
nullptr)
611 pObject =
new CDSObject( sId, sTitle, sParentId );
612 pObject->
m_sClass =
"object.item.videoItem";
615 CreateItem( sId, sTitle, sParentId, pObject );
667 if (pObject ==
nullptr)
669 pObject =
new CDSObject( sId, sTitle, sParentId );
670 pObject->
m_sClass =
"object.item.videoItem.movie";
685 if (pObject ==
nullptr)
687 pObject =
new CDSObject( sId, sTitle, sParentId );
688 pObject->
m_sClass =
"object.item.videoItem.videoBroadcast";
703 if (pObject ==
nullptr)
705 pObject =
new CDSObject( sId, sTitle, sParentId );
706 pObject->
m_sClass =
"object.item.videoItem.musicVideoClip";
723 if (pObject ==
nullptr)
725 pObject =
new CDSObject( sId, sTitle, sParentId );
726 pObject->
m_sClass =
"object.item.imageItem";
729 CreateItem( sId, sTitle, sParentId, pObject );
748 if (pObject ==
nullptr)
750 pObject =
new CDSObject( sId, sTitle, sParentId );
751 pObject->
m_sClass =
"object.item.imageItem.photo";
765 if (pObject ==
nullptr)
767 pObject =
new CDSObject( sId, sTitle, sParentId );
768 pObject->
m_sClass =
"object.item.playlistItem";
771 CreateItem( sId, sTitle, sParentId, pObject );
787 if (pObject ==
nullptr)
789 pObject =
new CDSObject( sId, sTitle, sParentId );
790 pObject->
m_sClass =
"object.item.textItem";
793 CreateItem( sId, sTitle, sParentId, pObject );
814 if (pObject ==
nullptr)
816 pObject =
new CDSObject( sId, sTitle, sParentId );
817 pObject->
m_sClass =
"object.container.album";
841 if (pObject ==
nullptr)
843 pObject =
new CDSObject( sId, sTitle, sParentId );
844 pObject->
m_sClass =
"object.container.album.musicAlbum";
861 if (pObject ==
nullptr)
863 pObject =
new CDSObject( sId, sTitle, sParentId );
864 pObject->
m_sClass =
"object.container.album.photoAlbum";
876 if (pObject ==
nullptr)
878 pObject =
new CDSObject( sId, sTitle, sParentId );
879 pObject->
m_sClass =
"object.container.genre";
891 if (pObject ==
nullptr)
893 pObject =
new CDSObject( sId, sTitle, sParentId );
894 pObject->
m_sClass =
"object.container.genre.musicGenre";
906 if (pObject ==
nullptr)
908 pObject =
new CDSObject( sId, sTitle, sParentId );
909 pObject->
m_sClass =
"object.container.genre.movieGenre";
921 if (pObject ==
nullptr)
923 pObject =
new CDSObject( sId, sTitle, sParentId );
924 pObject->
m_sClass =
"object.container.playlistContainer";
944 if (pObject ==
nullptr)
946 pObject =
new CDSObject( sId, sTitle, sParentId );
947 pObject->
m_sClass =
"object.container.person";
961 if (pObject ==
nullptr)
963 pObject =
new CDSObject( sId, sTitle, sParentId );
964 pObject->
m_sClass =
"object.container.person.musicArtist";
979 if (pObject ==
nullptr)
981 pObject =
new CDSObject( sId, sTitle, sParentId );
982 pObject->
m_sClass =
"object.container.storageSystem";
1000 if (pObject ==
nullptr)
1002 pObject =
new CDSObject( sId, sTitle, sParentId );
1003 pObject->
m_sClass =
"object.container.storageVolume";
1020 if (pObject ==
nullptr)
1022 pObject =
new CDSObject( sId, sTitle, sParentId );
1023 pObject->
m_sClass =
"object.container.storageFolder";
1039 if (filter.contains(name, Qt::CaseInsensitive))
1046 QString dependentAttribute = QString(
"%1@").arg(name);
1047 QStringList matches = filter.filter(name, Qt::CaseInsensitive);
1048 QStringList::iterator it;
1049 for (it = matches.begin(); it != matches.end(); ++it)
1051 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)