|
1 /* |
|
2 * Copyright (c) 2004 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: WV Status content attribute implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngWVAttributeConstructBase.h" |
|
20 #include "CPEngWVAttributeModelBase.h" |
|
21 #include "CPEngWVStatusContentModel.h" |
|
22 #include "CAsync2Sync.h" |
|
23 #include "PEngWVAttributeModelDataHelper.h" |
|
24 |
|
25 |
|
26 |
|
27 #include "MPEngXMLSerializer.h" |
|
28 #include "MPEngXMLParser.h" |
|
29 |
|
30 #include <MPEngPresenceAttrModel2.h> |
|
31 #include <E32Base.h> |
|
32 #include <S32Strm.h> |
|
33 #include <imcvcodc.h> |
|
34 |
|
35 |
|
36 |
|
37 //LOCAL constants |
|
38 namespace |
|
39 { |
|
40 _LIT( KPEngMyLogoModelPanic, "MyLogoMod" ); |
|
41 enum TPEngMyLogoModelPanicReasons |
|
42 { |
|
43 EModAlreadyHasNwStatusContent, |
|
44 EModInvalidParamsHandleNewMyLogo |
|
45 }; |
|
46 |
|
47 void PanicStatusContModel( TPEngMyLogoModelPanicReasons aPanicReason ) |
|
48 { |
|
49 User::Panic( KPEngMyLogoModelPanic, aPanicReason ); |
|
50 } |
|
51 } |
|
52 |
|
53 |
|
54 // ================= CPEngWVStatusContentModel MEMBER FUNCTIONS ================= |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CPEngWVStatusContentModel |
|
58 // C++ constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CPEngWVStatusContentModel::CPEngWVStatusContentModel( TBool aUserOwnAttribute ) |
|
63 : CPEngWVAttributeModelBase( aUserOwnAttribute ) |
|
64 { |
|
65 } |
|
66 |
|
67 |
|
68 // Destructor |
|
69 CPEngWVStatusContentModel::~CPEngWVStatusContentModel() |
|
70 { |
|
71 delete iMyLogoData; |
|
72 delete iMyLogoMimeType; |
|
73 delete iMyLogoSoureFileName; |
|
74 |
|
75 delete iStatusContentNW; |
|
76 delete iMyLogoConverter; //cancels the active convert if any |
|
77 } |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CPEngWVStatusContentModel::GetData() |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 TBool CPEngWVStatusContentModel::GetData( TInt* /*aIntData*/, |
|
87 TPtrC8* a8Data, |
|
88 TPtrC16* a16Data, |
|
89 TInt aField, |
|
90 TInt aGroup ) const |
|
91 { |
|
92 TBool handled = EFalse; |
|
93 |
|
94 if ( aGroup == KPEngDefaultAttrValueGroup ) |
|
95 { |
|
96 if ( a16Data && ( aField == EPEngMyLogoDirectContentSourceFileName ) ) |
|
97 { |
|
98 DoGetDesc( iMyLogoSoureFileName, *a16Data ); |
|
99 handled = ETrue; |
|
100 } |
|
101 |
|
102 |
|
103 if ( a8Data && ( aField == EPEngMyLogoDirectContentBuffer ) ) |
|
104 { |
|
105 DoGetDesc( iMyLogoData, *a8Data ); |
|
106 handled = ETrue; |
|
107 } |
|
108 } |
|
109 |
|
110 return handled; |
|
111 } |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CPEngWVStatusContentModel::SetDataL() |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TBool CPEngWVStatusContentModel::SetDataL( TInt* /*aIntData*/, |
|
121 const TDesC8* a8Data, |
|
122 const TDesC16* a16Data, |
|
123 TInt aField, |
|
124 TInt aGroup ) |
|
125 { |
|
126 CAsync2Sync* wait = CAsync2Sync::NewLC(); |
|
127 |
|
128 TBool handled = CPEngWVStatusContentModel::SetDataAsyncL( a8Data, |
|
129 a16Data, |
|
130 wait->RequestStatus(), |
|
131 aField, |
|
132 aGroup ); |
|
133 if ( handled ) |
|
134 { |
|
135 wait->WaitToComplete(); |
|
136 |
|
137 //handle all other errors than the cancel by leaving |
|
138 TInt status = wait->RequestStatus().Int(); |
|
139 User::LeaveIfError( status ); |
|
140 } |
|
141 |
|
142 CleanupStack::PopAndDestroy( wait ); |
|
143 |
|
144 return handled; |
|
145 } |
|
146 |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CPEngWVStatusContentModel::SetDataAsyncL() |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 TBool CPEngWVStatusContentModel::SetDataAsyncL( const TDesC8* a8Data, |
|
153 const TDesC16* a16Data, |
|
154 TRequestStatus& aRequestStatus, |
|
155 TInt aField, |
|
156 TInt aGroup ) |
|
157 { |
|
158 TBool handled = EFalse; |
|
159 |
|
160 if ( aGroup == KPEngDefaultAttrValueGroup ) |
|
161 { |
|
162 if ( a16Data && ( aField == EPEngMakeMyLogoDirectContentFromFile ) ) |
|
163 { |
|
164 __ASSERT_ALWAYS( !iMyLogoConverter, User::Leave( KErrInUse ) ); |
|
165 iMyLogoConverter = CPEngMyLogoConverter::FileNewL( *a16Data, *this ); |
|
166 iMyLogoConverter->IssueConvert( aRequestStatus ); |
|
167 handled = ETrue; |
|
168 } |
|
169 |
|
170 |
|
171 else if ( a8Data && ( aField == EPEngMakeMyLogoDirectContentFromBuffer ) ) |
|
172 { |
|
173 __ASSERT_ALWAYS( !iMyLogoConverter, User::Leave( KErrInUse ) ); |
|
174 iMyLogoConverter = CPEngMyLogoConverter::DataNewL( *a8Data, *this ); |
|
175 iMyLogoConverter->IssueConvert( aRequestStatus ); |
|
176 handled = ETrue; |
|
177 } |
|
178 } |
|
179 |
|
180 return handled; |
|
181 } |
|
182 |
|
183 |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPEngWVStatusContentModel::CancelSetDataAsync() |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CPEngWVStatusContentModel::CancelSetDataAsync() |
|
190 { |
|
191 delete iMyLogoConverter; //Deleting converter cancels it |
|
192 iMyLogoConverter = NULL; |
|
193 } |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CPEngWVStatusContentModel::EncodeDataToXmlL() |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void CPEngWVStatusContentModel::EncodeDataToXmlL( |
|
201 MPEngXMLSerializer& aSerializer ) const |
|
202 { |
|
203 TPtrC8 logoData( NULL, 0 ); |
|
204 TPtrC8 logoMimeType( NULL, 0 ); |
|
205 |
|
206 DoGetDesc( iMyLogoData, logoData ); |
|
207 DoGetDesc( iMyLogoMimeType, logoMimeType ); |
|
208 |
|
209 |
|
210 if ( ( logoData.Length() > 0 ) && ( logoMimeType.Length() > 0 ) ) |
|
211 { |
|
212 //Image & mime type for image are available |
|
213 //==>serialize them to XML |
|
214 aSerializer.StartTagL( KDirectContentXMLTag ). |
|
215 Base64DataL( logoData ). |
|
216 EndTagL( KDirectContentXMLTag ); |
|
217 |
|
218 aSerializer.StartTagL( KContentTypeXMLTag ) |
|
219 .RawValueL( logoMimeType ) |
|
220 .EndTagL( KContentTypeXMLTag ); |
|
221 } |
|
222 |
|
223 else |
|
224 { |
|
225 //write empty data |
|
226 aSerializer.StartTagL( KDirectContentXMLTag ).EndTagL( KDirectContentXMLTag ); |
|
227 aSerializer.StartTagL( KContentTypeXMLTag ).EndTagL( KContentTypeXMLTag ); |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CPEngWVStatusContentModel::DecodeDataFromXmlL() |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CPEngWVStatusContentModel::DecodeDataFromXmlL( MPEngXMLParser& aParser, |
|
238 const TDesC8& aValueBlock ) |
|
239 { |
|
240 __ASSERT_ALWAYS( !iStatusContentNW , |
|
241 PanicStatusContModel( EModAlreadyHasNwStatusContent ) ); |
|
242 |
|
243 |
|
244 TPtrC8 mimeType( NULL, 0 ); |
|
245 TPtrC8 statusContent( NULL, 0 ); |
|
246 |
|
247 if ( aParser.DecodeL( aValueBlock, KContentTypeXMLTag, EFalse ) ) |
|
248 { |
|
249 mimeType.Set( aParser.ResultL() ); |
|
250 |
|
251 if ( aParser.DecodeL( aValueBlock, KDirectContentXMLTag, EFalse ) ) |
|
252 { |
|
253 statusContent.Set( aParser.ResultL() ); |
|
254 } |
|
255 } |
|
256 |
|
257 //Is status content MyLogo? |
|
258 if ( ( mimeType.CompareF( KPEngWVMyLogoMimeJpeg ) == 0 ) || |
|
259 ( mimeType.CompareF( KPEngWVMyLogoMimeImageGif ) == 0 ) ) |
|
260 { |
|
261 |
|
262 //statusContent length is big enough for decoded image |
|
263 //data, because in BASE64 decoding the result shrinks |
|
264 iStatusContentNW = HBufC8::NewL( statusContent.Length() ); |
|
265 TPtr8 imageDataNW = iStatusContentNW->Des(); |
|
266 |
|
267 TImCodecB64 base64Decoder; |
|
268 base64Decoder.Initialise(); |
|
269 |
|
270 // Decode returns EFalse, if no more data is needed for decoding |
|
271 //==> in that case the decoding was succesful |
|
272 TBool decodeOk = !base64Decoder.Decode( statusContent, imageDataNW ); |
|
273 if ( decodeOk ) |
|
274 { |
|
275 iStatusContentNW = iStatusContentNW->ReAllocL( iStatusContentNW->Length() ); |
|
276 } |
|
277 else |
|
278 { |
|
279 delete iStatusContentNW; |
|
280 iStatusContentNW = NULL; |
|
281 } |
|
282 } |
|
283 |
|
284 |
|
285 if ( !iStatusContentNW ) |
|
286 { |
|
287 ResetDataL(); |
|
288 } |
|
289 else |
|
290 { |
|
291 //there is some raw content. Verify & convert it to valid MyLogo |
|
292 TRAPD( err, CheckReceivedStatusContentL() ); |
|
293 if ( err == KErrNoMemory ) |
|
294 { |
|
295 User::Leave( KErrNoMemory ); |
|
296 } |
|
297 |
|
298 else if ( ( err != KErrNone ) && |
|
299 ( err != KErrCancel ) ) |
|
300 { |
|
301 ResetDataL(); |
|
302 } |
|
303 } |
|
304 |
|
305 delete iStatusContentNW; |
|
306 iStatusContentNW = NULL; |
|
307 } |
|
308 |
|
309 |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CPEngWVStatusContentModel::ResetDataL() |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CPEngWVStatusContentModel::ResetDataL() |
|
316 { |
|
317 delete iMyLogoSoureFileName; |
|
318 delete iMyLogoMimeType; |
|
319 delete iMyLogoData; |
|
320 |
|
321 iMyLogoSoureFileName = NULL; |
|
322 iMyLogoMimeType = NULL; |
|
323 iMyLogoData = NULL; |
|
324 } |
|
325 |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CPEngWVStatusContentModel::DataExternalizeSize() |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CPEngWVStatusContentModel::DataExternalizeSize() const |
|
332 { |
|
333 TInt size = DoGetBufExtSize( iMyLogoData ); |
|
334 size += DoGetBufExtSize( iMyLogoMimeType ); |
|
335 size += DoGetBufExtSize( iMyLogoSoureFileName ); |
|
336 |
|
337 return size; |
|
338 } |
|
339 |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CPEngWVStatusContentModel::ExternalizeDataL() |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CPEngWVStatusContentModel::ExternalizeDataL( RWriteStream& aStream ) const |
|
346 { |
|
347 DoExtrBufL( iMyLogoData, aStream ); |
|
348 DoExtrBufL( iMyLogoMimeType, aStream ); |
|
349 DoExtrBufL( iMyLogoSoureFileName, aStream ); |
|
350 } |
|
351 |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CPEngWVStatusContentModel::InternalizeDataL() |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CPEngWVStatusContentModel::InternalizeDataL( RReadStream& aStream ) |
|
358 { |
|
359 TPtr8 typeStrait8( NULL, 0 ); |
|
360 DoIntrBufL( iMyLogoData, typeStrait8, aStream ); |
|
361 DoIntrBufL( iMyLogoMimeType, typeStrait8, aStream ); |
|
362 |
|
363 TPtr16 typeStrait16( NULL, 0 ); |
|
364 DoIntrBufL( iMyLogoSoureFileName, typeStrait16, aStream ); |
|
365 } |
|
366 |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CPEngWVStatusContentModel::CheckReceivedStatusContentL() |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 void CPEngWVStatusContentModel::CheckReceivedStatusContentL() |
|
373 { |
|
374 CAsync2Sync* wait = CAsync2Sync::NewLC(); |
|
375 iMyLogoConverter = CPEngMyLogoConverter::DataNewL( *iStatusContentNW, *this ); |
|
376 iMyLogoConverter->IssueConvert( wait->RequestStatus() ); |
|
377 wait->WaitToComplete(); |
|
378 User::LeaveIfError( wait->RequestStatus().Int() ); |
|
379 CleanupStack::PopAndDestroy( wait ); |
|
380 } |
|
381 |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CPEngWVStatusContentModel::HandleNewMyLogo() |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 void CPEngWVStatusContentModel::HandleNewMyLogo( HBufC8* aImageData, |
|
388 HBufC8* aImageMimeType, |
|
389 HBufC* aImageSoureFileName ) |
|
390 { |
|
391 __ASSERT_ALWAYS( aImageData && aImageMimeType && aImageSoureFileName, |
|
392 PanicStatusContModel( EModInvalidParamsHandleNewMyLogo ) ); |
|
393 |
|
394 //This must take ownership of the given HBufC's in all cases |
|
395 //so no leaving allowed |
|
396 delete iMyLogoData; |
|
397 delete iMyLogoMimeType; |
|
398 delete iMyLogoSoureFileName; |
|
399 |
|
400 iMyLogoData = aImageData; |
|
401 iMyLogoMimeType = aImageMimeType; |
|
402 iMyLogoSoureFileName = aImageSoureFileName; |
|
403 } |
|
404 |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CPEngWVStatusContentModel::HandleConverterDestroy() |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 void CPEngWVStatusContentModel::HandleConverterDestroy() |
|
411 { |
|
412 iMyLogoConverter = NULL; |
|
413 } |
|
414 |
|
415 |
|
416 |
|
417 // End of File |
|
418 |
|
419 |