|
1 /* |
|
2 * Copyright (c) 2002 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: Capability resolver implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "BTServiceUtils.h" |
|
21 #include "BTSUCapabilityResolver.h" |
|
22 #include "BTSUDebug.h" |
|
23 #include <utf.h> |
|
24 |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 _LIT8( KBTSUImageTag, "image-formats" ); |
|
29 _LIT8( KBTSUAttributeEncoding, "encoding" ); |
|
30 _LIT8( KBTSUAttributePixel, "pixel" ); |
|
31 _LIT8( KBTSUAttributeMaxSize,"maxsize"); |
|
32 _LIT(minus,"-"); |
|
33 _LIT(star,"*"); |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 #define INVALIDVALUE -1 |
|
39 // ============================ MEMBER FUNCTIONS =============================== |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CBTSBIPController::NewL |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CBTSUCapabilityResolver* CBTSUCapabilityResolver::NewL(CDesCArrayFlat* aCapabilityList) |
|
47 { |
|
48 CBTSUCapabilityResolver* self = new( ELeave ) CBTSUCapabilityResolver( aCapabilityList ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( ); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CBTSBIPController::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CBTSUCapabilityResolver* CBTSUCapabilityResolver::NewL(RArray<TBTSUImageCap>* aCapabilityList) |
|
61 { |
|
62 CBTSUCapabilityResolver* self = new( ELeave ) CBTSUCapabilityResolver( aCapabilityList ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL( ); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CBTSUCapabilityResolver::CBTSUCapabilityResolver |
|
70 // C++ default constructor can NOT contain any code, that |
|
71 // might leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CBTSUCapabilityResolver::CBTSUCapabilityResolver( CDesCArrayFlat* aCapabilityList ) |
|
75 { |
|
76 aCapabilityList=aCapabilityList; |
|
77 } |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CBTSUCapabilityResolver::CBTSUCapabilityResolver |
|
80 // C++ default constructor can NOT contain any code, that |
|
81 // might leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CBTSUCapabilityResolver::CBTSUCapabilityResolver( |
|
85 RArray<TBTSUImageCap>* aCapabilityList ) : iCapabilityList( aCapabilityList ) |
|
86 { |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CBTSBIPController::ConstructL |
|
91 // Symbian 2nd phase constructor can leave. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CBTSUCapabilityResolver::ConstructL () |
|
95 { |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // Destructor |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CBTSUCapabilityResolver::~CBTSUCapabilityResolver() |
|
103 { |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CBTSUCapabilityResolver::StartDocument |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CBTSUCapabilityResolver::OnStartDocumentL(const Xml::RDocumentParameters& /*aDocParam*/, TInt aErrorCode) |
|
111 { |
|
112 FLOG(_L("[BTSU]\t CBTSUCapabilityResolver::OnStartDocumentL()")); |
|
113 if(aErrorCode!=KErrNone) |
|
114 { |
|
115 FLOG(_L("[BTSU]\t Error OnStartDocument")); |
|
116 } |
|
117 iCompleted=EFalse; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CBTSUCapabilityResolver::EndDocument |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CBTSUCapabilityResolver::OnEndDocumentL(TInt aErrorCode) |
|
125 { |
|
126 FLOG(_L("[BTSU]\t CBTSUCapabilityResolver::OnEndDocumentL()")); |
|
127 if(aErrorCode!=KErrNone) |
|
128 { |
|
129 FLOG(_L("[BTSU]\t Error EndDocument")); |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CBTSUCapabilityResolver::StartElement |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CBTSUCapabilityResolver::OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, |
|
138 TInt /*aErrorCode*/) |
|
139 { |
|
140 |
|
141 TBool status = EFalse; |
|
142 TBTSUImageCap param; |
|
143 TLex lex; |
|
144 TPtrC sizemaxwidth; |
|
145 TPtrC sizemaxheight; |
|
146 TPtrC sizeminwidth; |
|
147 TPtrC sizeminheight; |
|
148 TPtrC sizemin; |
|
149 TPtrC sizemax; |
|
150 TInt index; |
|
151 HBufC* enc; |
|
152 param.iMaxByteSize=0; |
|
153 |
|
154 TBuf<KBTSUMaxStringLength> conversionBuf; |
|
155 |
|
156 if( aElement.LocalName().DesC() != KBTSUImageTag ) |
|
157 { |
|
158 return; |
|
159 } |
|
160 |
|
161 |
|
162 if(aAttributes.Count()>0) |
|
163 { |
|
164 |
|
165 param.iEncoding=NULL; |
|
166 param.iMaxByteSize=-1; |
|
167 param.iMinPixelSize.iHeight=INVALIDVALUE; |
|
168 param.iMinPixelSize.iWidth=INVALIDVALUE; |
|
169 param.iMaxPixelSize.iWidth=INVALIDVALUE; |
|
170 param.iMaxPixelSize.iHeight=INVALIDVALUE; |
|
171 |
|
172 //Check and add to attribute list if there is encoding |
|
173 for ( TInt iCounter = 0 ; iCounter < aAttributes.Count() ; iCounter++ ) |
|
174 { |
|
175 if ( aAttributes[iCounter].Attribute().LocalName().DesC() == KBTSUAttributeEncoding ) |
|
176 { |
|
177 User::LeaveIfError( CnvUtfConverter::ConvertToUnicodeFromUtf8( conversionBuf, aAttributes[iCounter].Value().DesC())); |
|
178 |
|
179 if (conversionBuf.Length()>0) |
|
180 { |
|
181 enc=conversionBuf.Alloc(); |
|
182 TPtr rwdata(enc->Des()); |
|
183 rwdata.Copy(conversionBuf); |
|
184 param.iEncoding=enc; |
|
185 if (param.iEncoding!=NULL) |
|
186 { |
|
187 status=ETrue; |
|
188 } |
|
189 } |
|
190 } |
|
191 } |
|
192 conversionBuf = KNullDesC; |
|
193 for ( TInt iCounter = 0 ; iCounter < aAttributes.Count() ; iCounter++ ) |
|
194 { |
|
195 if ( aAttributes[iCounter].Attribute().LocalName().DesC() == KBTSUAttributePixel ) |
|
196 { ; |
|
197 User::LeaveIfError( CnvUtfConverter::ConvertToUnicodeFromUtf8( conversionBuf, aAttributes[iCounter].Value().DesC())); |
|
198 } |
|
199 } |
|
200 |
|
201 if(conversionBuf.Length()>1) |
|
202 { |
|
203 index=conversionBuf.Find(minus); |
|
204 if(index!=KErrNotFound) //max size is given |
|
205 { |
|
206 sizemin.Set(conversionBuf.Left(index)); |
|
207 sizemax.Set(conversionBuf.Right(conversionBuf.Length()-index-1)); |
|
208 //solve min size |
|
209 index=sizemin.Find(star); |
|
210 if(index!=KErrNotFound) |
|
211 { |
|
212 sizeminwidth.Set(sizemin.Left(index)); |
|
213 sizeminheight.Set(sizemin.Right(sizemin.Length()-index-1)); |
|
214 |
|
215 lex.Assign(sizeminwidth); |
|
216 lex.Val(param.iMinPixelSize.iHeight); |
|
217 |
|
218 lex.Assign(sizeminheight); |
|
219 lex.Val(param.iMinPixelSize.iWidth); |
|
220 } |
|
221 //solve max size |
|
222 index=sizemax.Find(star); |
|
223 if(index!=KErrNotFound) |
|
224 { |
|
225 sizemaxwidth.Set(sizemax.Left(index)); |
|
226 sizemaxheight.Set(sizemax.Right(sizemax.Length()-index-1)); |
|
227 |
|
228 lex.Assign(sizemaxwidth); |
|
229 lex.Val(param.iMaxPixelSize.iWidth); |
|
230 |
|
231 lex.Assign(sizemaxheight); |
|
232 lex.Val(param.iMaxPixelSize.iHeight); |
|
233 status=ETrue; |
|
234 } |
|
235 } |
|
236 else //if max size not given |
|
237 { |
|
238 index=conversionBuf.Find(star); |
|
239 if(index!=KErrNotFound) |
|
240 { |
|
241 //solve min size |
|
242 TPtrC sizeminwidth=conversionBuf.Left( index ); |
|
243 TPtrC sizeminheight=conversionBuf.Right( conversionBuf.Length() - index-1); |
|
244 |
|
245 lex.Assign(sizeminwidth); |
|
246 lex.Val(param.iMinPixelSize.iWidth); |
|
247 |
|
248 lex.Assign(sizeminheight); |
|
249 lex.Val(param.iMinPixelSize.iHeight); |
|
250 //set max size |
|
251 param.iMaxPixelSize.iWidth=param.iMinPixelSize.iWidth; |
|
252 param.iMaxPixelSize.iHeight=param.iMinPixelSize.iHeight; |
|
253 status=ETrue; |
|
254 } |
|
255 } |
|
256 } |
|
257 |
|
258 |
|
259 //Check and add to attribute list if there is maxsize |
|
260 TPtrC maxsizevalue; |
|
261 conversionBuf = KNullDesC; |
|
262 for ( TInt iCounter = 0 ; iCounter < aAttributes.Count() ; iCounter++ ) |
|
263 { |
|
264 if ( aAttributes[iCounter].Attribute().LocalName().DesC() == KBTSUAttributeMaxSize ) |
|
265 { |
|
266 User::LeaveIfError( CnvUtfConverter::ConvertToUnicodeFromUtf8( conversionBuf, aAttributes[iCounter].Value().DesC())); |
|
267 } |
|
268 } |
|
269 |
|
270 |
|
271 if (conversionBuf.Length()>0) |
|
272 { |
|
273 lex.Assign(conversionBuf); |
|
274 lex.Val(param.iMaxByteSize); |
|
275 } |
|
276 |
|
277 if(status) |
|
278 { |
|
279 iCapabilityList->Append(param); //add to list |
|
280 } |
|
281 |
|
282 } |
|
283 |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CBTSUCapabilityResolver::OnEndElementL |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CBTSUCapabilityResolver::OnEndElementL(const Xml::RTagInfo& /*aElement*/, TInt aErrorCode) |
|
291 { |
|
292 FLOG(_L("[BTSU]\t CBTSUCapabilityResolver::EndElement()")); |
|
293 if(aErrorCode==KErrNone) |
|
294 { |
|
295 iCompleted=ETrue; |
|
296 } |
|
297 FLOG(_L("[BTSU]\t CBTSUCapabilityResolver::EndElement()")); |
|
298 |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CBTSUCapabilityResolver::OnContentL |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CBTSUCapabilityResolver::OnContentL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
306 { |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CBTSUCapabilityResolver::OnStartPrefixMappingL |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CBTSUCapabilityResolver::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, |
|
314 TInt /*aErrorCode*/) |
|
315 { |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CBTSUCapabilityResolver::OnEndPrefixMappingL |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 void CBTSUCapabilityResolver::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
323 { |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CBTSUCapabilityResolver::OnIgnorableWhiteSpaceL |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CBTSUCapabilityResolver::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
331 { |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CBTSUCapabilityResolver::OnSkippedEntityL |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 void CBTSUCapabilityResolver::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/) |
|
339 { |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // CBTSUCapabilityResolver::OnProcessingInstructionL |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 void CBTSUCapabilityResolver::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, |
|
347 TInt /*aErrorCode*/) |
|
348 { |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CBTSUCapabilityResolver::OnError |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 void CBTSUCapabilityResolver::OnError(TInt /*aErrorCode*/) |
|
356 { |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CBTSUCapabilityResolver::GetExtendedInterface |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 TAny* CBTSUCapabilityResolver::GetExtendedInterface(const TInt32 /*aUid*/) |
|
364 { |
|
365 return NULL; |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CBTSUCapabilityResolver::IsCompleted |
|
370 // ----------------------------------------------------------------------------- |
|
371 |
|
372 TBool CBTSUCapabilityResolver::IsCompleted() |
|
373 { |
|
374 return iCompleted; |
|
375 } |
|
376 |
|
377 // End of File |