-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcmoidomxmlparser.cpp
254 lines (240 loc) · 7 KB
/
cmoidomxmlparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*------------------------------ Information ---------------------------*//**
*
* $HeadURL$
*
* @file cmoidomxmlparser.cpp
*
* @author Jo2003
*
* @date 02.12.2013
*
* $Id$
*
*///------------------------- (c) 2013 by Jo2003 --------------------------
#include "cmoidomxmlparser.h"
// log file functions ...
extern CLogFile VlcLog;
//---------------------------------------------------------------------------
//
//! \brief constructs CMoiDomXmlParser object
//
//! \author Jo2003
//! \date 02.12.2013
//
//! \param parent (QObject*) pointer to parent object
//
//! \return --
//---------------------------------------------------------------------------
CMoiDomXmlParser::CMoiDomXmlParser(QObject *parent) :
CKartinaXMLParser(parent)
{
// nothing to do so far ...
}
//---------------------------------------------------------------------------
//
//! \brief destroys CMoiDomXmlParser object
//
//! \author Jo2003
//! \date 02.12.2013
//
//! \param --
//
//! \return --
//---------------------------------------------------------------------------
CMoiDomXmlParser::~CMoiDomXmlParser()
{
// and still nothing ...
}
//---------------------------------------------------------------------------
//
//! \brief parse channels from xml response
//
//! \author Jo2003
//! \date 02.12.2013
//
//! \param xml (QXmlStreamReader &) ref. to xml reader
//! \param chanList (QVector<cparser::SChan> &) ref. to channel list
//! \param bFixTime (bool) should we fix time if(true)
//
//! \return 0
//---------------------------------------------------------------------------
int CMoiDomXmlParser::parseChannels(QXmlStreamReader &xml, QVector<cparser::SChan> &chanList,
bool bFixTime)
{
QString sUnknown;
cparser::SChan chanEntry;
// while no end of channels ...
while (!((xml.readNext() == QXmlStreamReader::EndElement)
&& (xml.name() == "channels")))
{
if (xml.tokenType() == QXmlStreamReader::StartElement)
{
// item start -> init struct ...
if (xml.name() == "item")
{
initChanEntry(chanEntry);
}
else if (xml.name() == "name")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.sName = xml.text().toString();
}
}
else if (xml.name() == "id")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.iId = xml.text().toString().toInt();
}
}
else if (xml.name() == "is_video")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.bIsVideo = (xml.text().toString().toInt() == 1) ? true : false;
}
}
else if (xml.name() == "have_archive")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.bHasArchive = (xml.text().toString().toInt() == 1) ? true : false;
}
}
else if (xml.name() == "protected")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.bIsProtected = (xml.text().toString().toInt() == 1) ? true : false;
}
}
else if (xml.name() == "icon")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.sIcon = xml.text().toString();
}
}
else if (xml.name() == "epg_progname")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.sProgramm = xml.text().toString();
}
}
else if (xml.name() == "epg_start")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.uiStart = xml.text().toString().toUInt();
if (bFixTime)
{
fixTime(chanEntry.uiStart);
}
}
}
else if (xml.name() == "epg_end")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.uiEnd = xml.text().toString().toUInt();
if (bFixTime)
{
fixTime(chanEntry.uiEnd);
}
}
}
else if (xml.name() == "hide")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
chanEntry.bIsHidden = (xml.text().toString().toInt() == 1) ? true : false;
}
}
else if (xml.name() == "stream_params")
{
// go into next level ... parse stream params ...
parseStreamParams(xml, chanEntry.vTs);
}
else if (xml.name() == "audiotracks")
{
chanEntry.uiDefAud = parseATracks(xml);
}
else
{
// any unknown element shouldn't break our parser ...
sUnknown = xml.name().toString();
#ifndef QT_NO_DEBUG
mInfo(tr("Found unused element %1 ...").arg(sUnknown));
#endif
while (!((xml.readNext() == QXmlStreamReader::EndElement)
&& (xml.name().toString() == sUnknown)))
{
#ifndef QT_NO_DEBUG
mInfo(tr("Found unused child %1: %2 ...")
.arg(xml.name().toString()).arg(xml.text().toString()));
#endif
}
}
}
else if (xml.tokenType() == QXmlStreamReader::EndElement)
{
// item end -> save entry ...
if (xml.name() == "item")
{
chanList.push_back(chanEntry);
}
}
}
return 0;
}
//---------------------------------------------------------------------------
//
//! \brief get default audio stream index from xml response
//
//! \author Jo2003
//! \date 02.12.2013
//
//! \param xml (QXmlStreamReader &) ref. to xml reader
//
//! \return default index
//---------------------------------------------------------------------------
uint CMoiDomXmlParser::parseATracks(QXmlStreamReader &xml)
{
uint uiRet = 0;
QStringList sl;
QString sDef;
// while no end of audio track stuff ...
while (!((xml.readNext() == QXmlStreamReader::EndElement)
&& (xml.name() == "audiotrack_default")))
{
if (xml.tokenType() == QXmlStreamReader::StartElement)
{
// audio track item ...
if (xml.name() == "item")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
sl << xml.text().toString();
}
}
else if (xml.name() == "audiotrack_default")
{
if (xml.readNext() == QXmlStreamReader::Characters)
{
sDef = xml.text().toString();
}
}
}
}
if (!sl.isEmpty() && (sl.count() > 1))
{
uiRet = (uint)sl.indexOf(sDef);
if (uiRet == (uint)-1)
{
uiRet = 0;
}
}
return uiRet;
}