MythTV master
upnpcdsobjects.h
Go to the documentation of this file.
1
2// Program Name: UPnpCDSObjects.h
3// Created : Oct. 24, 2005
4//
5// Purpose : uPnp Content Directory Service Object Definitions
6//
7// Copyright (c) 2005 David Blain <dblain@mythtv.org>
8//
9// Licensed under the GPL v2 or later, see LICENSE for details
10//
12
13#ifndef UPNPCDSOBJECTS_H
14#define UPNPCDSOBJECTS_H
15
16#include <cstdint>
17#include <utility>
18
19#include <QChar> // Fix Qt6 GCC SFINAE warning
20#include <QDateTime>
21#include <QList>
22#include <QMap>
23#include <QString>
24#include <QUrl>
25
27
28#include "upnpexp.h"
29#include "upnputil.h"
30
31class CDSObject;
32class QTextStream;
33
35//
37
38enum ObjectTypes : std::uint8_t
39{
43 OT_Res = 3
44};
45
47//
49
51{
52 public:
53
54 QString m_sName;
55 QString m_sNameSpace;
56 bool m_bRequired {false};
57 bool m_bMultiValue {false};
59
60 public:
61
62 explicit Property( QString sName,
63 QString sNameSpace = "",
64 bool bRequired = false,
65 const QString &sValue = "",
66 bool bMultiValue = false
67 )
68 : m_sName(std::move(sName)),
69 m_sNameSpace(std::move(sNameSpace)),
70 m_bRequired(bRequired),
71 m_bMultiValue(bMultiValue),
72 m_sValue(QUrl::toPercentEncoding(sValue))
73 {
74 }
75
76 void SetValue(const QString &value)
77 {
78 m_sValue = value;
79 }
80
81 QString GetValue(void) const
82 {
83 return m_sValue;
84 }
85
86 QString GetEncodedValue(void) const
87 {
88 return QUrl::toPercentEncoding(m_sValue);
89 }
90
91 void AddAttribute( const QString &sName,
92 const QString &sValue )
93 {
94 m_lstAttributes.push_back(NameValue(sName,
95 QString::fromUtf8(QUrl::toPercentEncoding(sValue))));
96 }
97
98 protected:
99 QString m_sValue;
100};
101
102using Properties = QMultiMap<QString,Property*>;
103using CDSObjects = QList<CDSObject*>;
104
106//
108
110{
111 public:
112
114 QString m_sURI;
115
117
118 public:
119
120 Resource(QString sProtocolInfo, const QString &sURI) :
121 m_sProtocolInfo(std::move(sProtocolInfo)),
122 m_sURI(QUrl::toPercentEncoding(sURI))
123 {
124 }
125
126 void AddAttribute( const QString &sName,
127 const QString &sValue )
128 {
129 m_lstAttributes.push_back(NameValue(sName,
130 QString::fromUtf8(QUrl::toPercentEncoding(sValue))));
131 }
132};
133
134using Resources = QList<Resource*>;
135
137//
139
141{
142 public:
143
144 QString m_sClass;
145 QString m_sName;
147
148 public:
149
150 ContainerClass( QString sClass,
151 QString sName,
152 bool bIncludeDerived )
153 : m_sClass(std::move(sClass)),
154 m_sName(std::move(sName)),
155 m_bIncludeDerived(bIncludeDerived)
156 {
157 }
158};
159
160using Classes = QList<ContainerClass*>;
161
186using FilterMap = QStringList;
187
189
191{
192 public:
193 short m_nUpdateId {1};
194
196
197 // Required
198
199 QString m_sId;
200 QString m_sParentId;
201 QString m_sTitle;
202 QString m_sClass;
203 bool m_bRestricted {true};
204 bool m_bSearchable {false};
205
206 // Optional
207
208 QString m_sCreator;
209 QString m_sWriteStatus {"PROTECTED"};
210
211 // Only appropriate for Container Classes
212
215
216 //
217
220 uint32_t m_nChildCount {0};
221 uint32_t m_nChildContainerCount {0};
222
224
225
226 public:
227
228 explicit CDSObject( const QString &sId = "-1",
229 const QString &sTitle = "",
230 const QString &sParentId = "-1" );
231 ~CDSObject() override;
232
233 Property *AddProperty( Property *pProp );
234 QList<Property*> GetProperties( const QString &sName );
235 CDSObject *AddChild ( CDSObject *pChild );
236 CDSObjects GetChildren( void ) const { return m_children; }
237 CDSObject *GetChild ( const QString &sID );
238
241
242 void SetPropValue( const QString &sName, const QString &sValue,
243 const QString &type = "" );
244 QString GetPropValue( const QString &sName ) const;
245 QString toXml ( FilterMap &filter,
246 bool ignoreChildren = false ) const;
247 void toXml ( QTextStream &os, FilterMap &filter,
248 bool ignoreChildren = false ) const;
249
250 uint32_t GetChildCount( void ) const;
251 void SetChildCount( uint32_t nCount );
252
253 uint32_t GetChildContainerCount( void ) const;
254 void SetChildContainerCount( uint32_t nCount );
255
256 Resource *AddResource( const QString& sProtocol, const QString& sURI );
257
258 public:
259
260 static CDSObject *CreateItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
261 static CDSObject *CreateContainer ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
262 static CDSObject *CreateAudioItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
263 static CDSObject *CreateMusicTrack ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
264 static CDSObject *CreateAudioBroadcast ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
265 static CDSObject *CreateAudioBook ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
266 static CDSObject *CreateVideoItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
267 static CDSObject *CreateMovie ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
268 static CDSObject *CreateVideoBroadcast ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
269 static CDSObject *CreateMusicVideoClip ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
270 static CDSObject *CreateImageItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
271 static CDSObject *CreatePhoto ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
272 static CDSObject *CreatePlaylistItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
273 static CDSObject *CreateTextItem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
274 static CDSObject *CreateAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
275 static CDSObject *CreateMusicAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
276 static CDSObject *CreatePhotoAlbum ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
277 static CDSObject *CreateGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
278 static CDSObject *CreateMusicGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
279 static CDSObject *CreateMovieGenre ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
280 static CDSObject *CreatePlaylistContainer( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
281 static CDSObject *CreatePerson ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
282 static CDSObject *CreateMusicArtist ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
283 static CDSObject *CreateStorageSystem ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
284 static CDSObject *CreateStorageVolume ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
285 static CDSObject *CreateStorageFolder ( const QString& sId, const QString& sTitle, const QString& sParentId, CDSObject *pObject = nullptr );
286
287 private:
288 static bool FilterContains( const FilterMap &filter, const QString &name ) ;
289
290};
291
292#endif // UPNPCDSOBJECTS_H
QMap< uint, int > FilterMap
Classes m_SearchClass
CDSObjects m_children
ContainerClass * AddCreateClass(ContainerClass *pClass)
QString m_sParentId
Resources m_resources
ContainerClass * AddSearchClass(ContainerClass *pClass)
CDSObjects GetChildren(void) const
QString m_sClass
QString m_sTitle
QString m_sCreator
QString m_sId
Properties m_properties
Classes m_CreateClass
ContainerClass(QString sClass, QString sName, bool bIncludeDerived)
Property(QString sName, QString sNameSpace="", bool bRequired=false, const QString &sValue="", bool bMultiValue=false)
QString GetEncodedValue(void) const
NameValues m_lstAttributes
void AddAttribute(const QString &sName, const QString &sValue)
bool m_bMultiValue
QString m_sNameSpace
QString m_sName
bool m_bRequired
QString GetValue(void) const
void SetValue(const QString &value)
QString m_sValue
General purpose reference counter.
NameValues m_lstAttributes
QString m_sProtocolInfo
Resource(QString sProtocolInfo, const QString &sURI)
void AddAttribute(const QString &sName, const QString &sValue)
QString m_sURI
QList< Resource * > Resources
QMultiMap< QString, Property * > Properties
QList< ContainerClass * > Classes
QList< CDSObject * > CDSObjects
ObjectTypes
@ OT_Undefined
@ OT_Item
@ OT_Container
@ OT_Res
#define UPNP_PUBLIC
Definition: upnpexp.h:9