|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef T_RADIODATAPARSER_H |
|
19 #define T_RADIODATAPARSER_H |
|
20 |
|
21 // System includes |
|
22 #include <QScopedPointer> |
|
23 #include <QXxml> |
|
24 #include <QString> |
|
25 #include <QList> |
|
26 |
|
27 // Forward declarations |
|
28 class T_RadioDataParser; |
|
29 |
|
30 namespace RadioData |
|
31 { |
|
32 class SettingHolder; |
|
33 |
|
34 /** |
|
35 * Base class for all settings |
|
36 */ |
|
37 class Setting |
|
38 { |
|
39 public: |
|
40 |
|
41 virtual ~Setting() {} |
|
42 virtual void setValue( SettingHolder& holder, |
|
43 T_RadioDataParser& parser ) {}; |
|
44 |
|
45 }; |
|
46 |
|
47 /** |
|
48 * Holder to store a setting during parsing |
|
49 */ |
|
50 class SettingHolder : public Setting |
|
51 { |
|
52 public: |
|
53 |
|
54 SettingHolder(); |
|
55 ~SettingHolder(); |
|
56 |
|
57 QString mName; |
|
58 QString mValue; |
|
59 QList<SettingHolder*> mChildren; |
|
60 |
|
61 }; |
|
62 |
|
63 class RdsItem : public Setting |
|
64 { |
|
65 public: |
|
66 enum Type |
|
67 { |
|
68 Unknown |
|
69 ,RdsPsName |
|
70 ,RdsRadioText |
|
71 ,RdsRadioTextPlus |
|
72 ,RdsPty |
|
73 ,RdsPiCode |
|
74 }; |
|
75 |
|
76 RdsItem(); |
|
77 ~RdsItem(); |
|
78 |
|
79 void setValue( SettingHolder& holder, |
|
80 T_RadioDataParser& parser ); |
|
81 |
|
82 void initChildren( SettingHolder& holder, |
|
83 T_RadioDataParser& parser ); |
|
84 |
|
85 enum rtClass{ Title = 1, Artist = 4, Homepage = 39 }; |
|
86 |
|
87 class RtPlusHolder |
|
88 { |
|
89 public: |
|
90 |
|
91 RtPlusHolder(); |
|
92 |
|
93 int mDelay; |
|
94 int mRtClass; |
|
95 QString mRtItem; |
|
96 }; |
|
97 |
|
98 Type mType; |
|
99 QStringList mRdsItems; |
|
100 QList<RtPlusHolder*> mRtPlusItems; |
|
101 int mCurrentRtPlusIndex; |
|
102 |
|
103 }; |
|
104 |
|
105 class RdsGroup : public Setting |
|
106 { |
|
107 public: |
|
108 |
|
109 RdsGroup( const QXmlAttributes& atts, T_RadioDataParser& parser ); |
|
110 ~RdsGroup(); |
|
111 |
|
112 int mInterval; |
|
113 int mCount; |
|
114 QList<RdsItem*> mRdsItems; |
|
115 |
|
116 }; |
|
117 |
|
118 class Station : public Setting |
|
119 { |
|
120 public: |
|
121 |
|
122 Station(); |
|
123 ~Station(); |
|
124 |
|
125 void setValue( SettingHolder& holder, |
|
126 T_RadioDataParser& parser ); |
|
127 |
|
128 uint mFrequency; |
|
129 QList<RdsGroup*> mRdsArray; |
|
130 |
|
131 }; |
|
132 |
|
133 class EngineSettings : public Setting |
|
134 { |
|
135 public: |
|
136 |
|
137 EngineSettings(); |
|
138 |
|
139 void setValue( SettingHolder& holder, |
|
140 T_RadioDataParser& parser ); |
|
141 |
|
142 int mMaxVolume; |
|
143 int mFrequencyStepSize; |
|
144 int mRegionId; |
|
145 uint mMinFrequency; |
|
146 uint mMaxFrequency; |
|
147 |
|
148 }; |
|
149 |
|
150 typedef QList<Setting*> SettingArray; |
|
151 |
|
152 } |
|
153 |
|
154 class T_RadioDataParser : public QXmlDefaultHandler |
|
155 { |
|
156 public: |
|
157 |
|
158 T_RadioDataParser(); |
|
159 virtual ~T_RadioDataParser(); |
|
160 |
|
161 bool parse(); |
|
162 |
|
163 QString errorString() const; |
|
164 |
|
165 int parseInt( const QString& string, int defaultVal ); |
|
166 int parseTime( const QString& string, int defaultVal ); |
|
167 |
|
168 private: |
|
169 |
|
170 // from base class QXmlDefaultHandler |
|
171 |
|
172 bool startDocument(); |
|
173 bool endDocument(); |
|
174 bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts ); |
|
175 bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName ); |
|
176 bool characters( const QString& ch ); |
|
177 bool error( const QXmlParseException& exception ); |
|
178 bool fatalError( const QXmlParseException& exception ); |
|
179 |
|
180 // New functions |
|
181 |
|
182 void handleStartRadioSettings( const QXmlAttributes& atts ); |
|
183 void handleEndRadioSettings(); |
|
184 void handleStartSetting( const QXmlAttributes& atts ); |
|
185 void handleEndSetting(); |
|
186 void handleStartStation( const QXmlAttributes& atts ); |
|
187 void handleEndStation(); |
|
188 void handleStartRdsGroup( const QXmlAttributes& atts ); |
|
189 void handleEndRdsGroup(); |
|
190 void handleStartRdsData( const QXmlAttributes& atts ); |
|
191 void handleEndRdsData(); |
|
192 |
|
193 void pushToSettingStack( RadioData::Setting* setting, RadioData::SettingArray& array ); |
|
194 RadioData::Setting* topOfSettingStack( RadioData::SettingArray& array ); |
|
195 RadioData::Setting* popFromSettingStack( RadioData::SettingArray& array ); |
|
196 |
|
197 private: // data |
|
198 |
|
199 QScopedPointer<QXmlSimpleReader> mReader; |
|
200 QScopedPointer<QXmlInputSource> mSource; |
|
201 |
|
202 QString mErrorString; |
|
203 |
|
204 int mCurrentPresetIndex; |
|
205 |
|
206 RadioData::SettingArray mSettingStack; |
|
207 |
|
208 RadioData::SettingArray mSettingHolderStack; |
|
209 |
|
210 public: |
|
211 |
|
212 RadioData::EngineSettings mEngineSettings; |
|
213 |
|
214 QList<RadioData::Station*> mStations; |
|
215 |
|
216 }; |
|
217 |
|
218 #endif // T_RADIODATAPARSER_H |