|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: Declares CUpnpIcon class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "upnpicon.h" |
|
22 #include "upnpstring.h" |
|
23 #include "upnpargument.h" |
|
24 #include "upnpserviceimplementation.h" |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CUpnpIcon::CUpnpIcon |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CUpnpIcon::CUpnpIcon():iSendBufferPtr(0,0) |
|
36 { |
|
37 |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CUpnpIcon::ConstructL |
|
42 // Symbian 2nd phase constructor can leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 void CUpnpIcon::ConstructL( ) |
|
46 { |
|
47 iFilename.Zero(); |
|
48 |
|
49 iSendBuffer = ToDes8L(); |
|
50 iSendBufferPtr.Set(iSendBuffer->Des()); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CUpnpIcon::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CUpnpIcon::ConstructL(const TDesC16& aPath, const TDesC8& aUrl, const TInt aWidth, const TInt aHeight, const TInt aDepth, const TDesC8& aMimeType) |
|
59 { |
|
60 iFilename.Zero(); |
|
61 SetBitmapFilename(aPath); |
|
62 SetUrlL(aUrl); |
|
63 SetWidthL(aWidth); |
|
64 SetHeightL(aHeight); |
|
65 SetDepthL(aDepth); |
|
66 SetMimeTypeL(aMimeType); |
|
67 |
|
68 iSendBuffer = ToDes8L(); |
|
69 iSendBufferPtr.Set(iSendBuffer->Des()); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CUpnpIcon::ConstructL |
|
74 // Symbian 2nd phase constructor can leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CUpnpIcon::ConstructL(const TDesC16& aPath, const TInt aWidth, const TInt aHeight, const TInt aDepth, const TDesC8& aMimeType) |
|
78 { |
|
79 iFilename.Zero(); |
|
80 SetBitmapFilename(aPath); |
|
81 SetWidthL(aWidth); |
|
82 SetHeightL(aHeight); |
|
83 SetDepthL(aDepth); |
|
84 SetMimeTypeL(aMimeType); |
|
85 |
|
86 iSendBuffer = ToDes8L(); |
|
87 iSendBufferPtr.Set(iSendBuffer->Des()); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CUpnpIcon::NewL |
|
92 // Two-phased constructor. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CUpnpIcon* CUpnpIcon::NewL( ) |
|
96 { |
|
97 CUpnpIcon* self = new (ELeave) CUpnpIcon(); |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL( ); |
|
100 CleanupStack::Pop( self ); |
|
101 return self; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CUpnpIcon::NewL |
|
106 // Two-phased constructor. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C CUpnpIcon* CUpnpIcon::NewL(const TDesC16& aPath, const TDesC8& aUrl, const TInt aWidth, const TInt aHeight, const TInt aDepth, const TDesC8& aMimeType) |
|
110 { |
|
111 CUpnpIcon* self = new (ELeave) CUpnpIcon(); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL( aPath, aUrl, aWidth, aHeight, aDepth, aMimeType ); |
|
114 CleanupStack::Pop( self ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CUpnpIcon::NewL |
|
120 // Two-phased constructor. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C CUpnpIcon* CUpnpIcon::NewL(const TDesC16& aPath, const TInt aWidth, const TInt aHeight, const TInt aDepth, const TDesC8& aMimeType) |
|
124 { |
|
125 CUpnpIcon* self = new (ELeave) CUpnpIcon(); |
|
126 CleanupStack::PushL( self ); |
|
127 self->ConstructL( aPath, aWidth, aHeight, aDepth, aMimeType ); |
|
128 CleanupStack::Pop( self ); |
|
129 return self; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CUpnpIcon::~CUpnpIcon |
|
134 // Destructor |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C CUpnpIcon::~CUpnpIcon() |
|
138 { |
|
139 iProperties.ResetAndDestroy(); |
|
140 iProperties.Close(); |
|
141 |
|
142 if(iSendBuffer) |
|
143 { |
|
144 delete iSendBuffer; |
|
145 } |
|
146 //TRAP_IGNORE( DeleteIconFromFsL()); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CUpnpIcon::Url |
|
151 // |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 EXPORT_C const TPtrC8 CUpnpIcon::Url() const |
|
155 { |
|
156 TInt index = 0; |
|
157 |
|
158 while ( index < iProperties.Count() ) |
|
159 { |
|
160 CUpnpDescriptionProperty* var = iProperties[index]; |
|
161 |
|
162 if ( KUrl().Compare( var->Name() ) == KErrNone ) |
|
163 { |
|
164 return var->Value(); |
|
165 } |
|
166 |
|
167 index++; |
|
168 } |
|
169 |
|
170 return KNullDesC8(); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CUpnpIcon::SetUrlL |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C void CUpnpIcon::SetUrlL(const TDesC8& aUrl) |
|
179 { |
|
180 TInt index = 0; |
|
181 |
|
182 while ( index < iProperties.Count() ) |
|
183 { |
|
184 CUpnpDescriptionProperty* var = iProperties[index]; |
|
185 |
|
186 if ( KUrl().Compare( var->Name() ) == KErrNone ) |
|
187 { |
|
188 var->SetValueL(aUrl); |
|
189 return; |
|
190 } |
|
191 |
|
192 index++; |
|
193 } |
|
194 CUpnpDescriptionProperty* prop = CUpnpDescriptionProperty::NewL(KUrl, aUrl); |
|
195 iProperties.AppendL(prop); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CUpnpIcon::GetIconBufferPtr |
|
200 // |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 EXPORT_C const TPtr8& CUpnpIcon::GetIconBufferPtr() const |
|
204 { |
|
205 return iSendBufferPtr; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CUpnpIcon::BitmapFilename |
|
210 // |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C TFileName CUpnpIcon::BitmapFilename() const |
|
214 { |
|
215 return iFilename; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CUpnpIcon::SetBitmapFilename |
|
220 // |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 EXPORT_C void CUpnpIcon::SetBitmapFilename( const TDesC& aName ) |
|
224 { |
|
225 iFilename.Zero(); |
|
226 iFilename.Append( aName ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CUpnpIcon::Width |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C TInt CUpnpIcon::Width() const |
|
235 { |
|
236 TInt index = 0; |
|
237 |
|
238 while ( index < iProperties.Count() ) |
|
239 { |
|
240 CUpnpDescriptionProperty* var = iProperties[index]; |
|
241 |
|
242 if ( KWidth().Compare( var->Name() ) == KErrNone ) |
|
243 { |
|
244 TLex8 val(var->Value()); |
|
245 TInt ret(0); |
|
246 TInt err = val.Val( ret ); |
|
247 if(err == KErrNone) |
|
248 return ret; |
|
249 else |
|
250 return err; |
|
251 } |
|
252 |
|
253 index++; |
|
254 } |
|
255 |
|
256 return KErrNotFound; |
|
257 } |
|
258 |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CUpnpIcon::WidthTPtrC8 |
|
262 // |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 TPtrC8 CUpnpIcon::WidthTPtrC8() const |
|
266 { |
|
267 TInt index = 0; |
|
268 |
|
269 while ( index < iProperties.Count() ) |
|
270 { |
|
271 CUpnpDescriptionProperty* var = iProperties[index]; |
|
272 |
|
273 if ( KWidth().Compare( var->Name() ) == KErrNone ) |
|
274 { |
|
275 return var->Value(); |
|
276 } |
|
277 |
|
278 index++; |
|
279 } |
|
280 |
|
281 return KNullDesC8(); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CUpnpIcon::SetWidthL |
|
286 // |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 void CUpnpIcon::SetWidthL(TInt aWidth) |
|
290 { |
|
291 TInt index = 0; |
|
292 TBuf8<KMaxNumberPropertySize> nbuf; |
|
293 nbuf.Num(aWidth); |
|
294 |
|
295 while ( index < iProperties.Count() ) |
|
296 { |
|
297 CUpnpDescriptionProperty* var = iProperties[index]; |
|
298 |
|
299 if ( KWidth().Compare( var->Name() ) == KErrNone ) |
|
300 { |
|
301 var->SetValueL(nbuf); |
|
302 return; |
|
303 } |
|
304 |
|
305 index++; |
|
306 } |
|
307 CUpnpDescriptionProperty* prop = CUpnpDescriptionProperty::NewL(KWidth, nbuf); |
|
308 iProperties.AppendL(prop); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CUpnpIcon::Depth |
|
313 // |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C TInt CUpnpIcon::Depth() const |
|
317 { |
|
318 TInt index = 0; |
|
319 |
|
320 while ( index < iProperties.Count() ) |
|
321 { |
|
322 CUpnpDescriptionProperty* var = iProperties[index]; |
|
323 |
|
324 if ( KDepth().Compare( var->Name() ) == KErrNone ) |
|
325 { |
|
326 TLex8 val(var->Value()); |
|
327 TInt ret(0); |
|
328 TInt err = val.Val( ret ); |
|
329 if(err == KErrNone) |
|
330 return ret; |
|
331 else |
|
332 return err; |
|
333 } |
|
334 |
|
335 index++; |
|
336 } |
|
337 |
|
338 return KErrNotFound; |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CUpnpIcon::DepthTPtrC8 |
|
343 // |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 TPtrC8 CUpnpIcon::DepthTPtrC8() const |
|
347 { |
|
348 TInt index = 0; |
|
349 |
|
350 while ( index < iProperties.Count() ) |
|
351 { |
|
352 CUpnpDescriptionProperty* var = iProperties[index]; |
|
353 |
|
354 if ( KDepth().Compare( var->Name() ) == KErrNone ) |
|
355 { |
|
356 return var->Value(); |
|
357 } |
|
358 |
|
359 index++; |
|
360 } |
|
361 |
|
362 return KNullDesC8(); |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CUpnpIcon::SetDepthL |
|
367 // |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 void CUpnpIcon::SetDepthL(TInt aDepth) |
|
371 { |
|
372 TInt index = 0; |
|
373 TBuf8<KMaxNumberPropertySize> nbuf; |
|
374 nbuf.Num(aDepth); |
|
375 |
|
376 while ( index < iProperties.Count() ) |
|
377 { |
|
378 CUpnpDescriptionProperty* var = iProperties[index]; |
|
379 |
|
380 if ( KDepth().Compare( var->Name() ) == KErrNone ) |
|
381 { |
|
382 var->SetValueL(nbuf); |
|
383 return; |
|
384 } |
|
385 |
|
386 index++; |
|
387 } |
|
388 CUpnpDescriptionProperty* prop = CUpnpDescriptionProperty::NewL(KDepth, nbuf); |
|
389 iProperties.AppendL(prop); |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CUpnpIcon::Height |
|
394 // |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 EXPORT_C TInt CUpnpIcon::Height() const |
|
398 { |
|
399 TInt index = 0; |
|
400 |
|
401 while ( index < iProperties.Count() ) |
|
402 { |
|
403 CUpnpDescriptionProperty* var = iProperties[index]; |
|
404 |
|
405 if ( KHeight().Compare( var->Name() ) == KErrNone ) |
|
406 { |
|
407 TLex8 val(var->Value()); |
|
408 TInt ret(0); |
|
409 TInt err = val.Val( ret ); |
|
410 if(err == KErrNone) |
|
411 return ret; |
|
412 else |
|
413 return err; |
|
414 } |
|
415 |
|
416 index++; |
|
417 } |
|
418 |
|
419 return KErrNotFound; |
|
420 } |
|
421 |
|
422 // ----------------------------------------------------------------------------- |
|
423 // CUpnpIcon::HeightTPtrC8 |
|
424 // |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 TPtrC8 CUpnpIcon::HeightTPtrC8() const |
|
428 { |
|
429 TInt index = 0; |
|
430 |
|
431 while ( index < iProperties.Count() ) |
|
432 { |
|
433 CUpnpDescriptionProperty* var = iProperties[index]; |
|
434 |
|
435 if ( KHeight().Compare( var->Name() ) == KErrNone ) |
|
436 { |
|
437 return var->Value(); |
|
438 } |
|
439 |
|
440 index++; |
|
441 } |
|
442 |
|
443 return KNullDesC8(); |
|
444 } |
|
445 |
|
446 // ----------------------------------------------------------------------------- |
|
447 // CUpnpIcon::SetHeightL |
|
448 // |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 void CUpnpIcon::SetHeightL(TInt aHeight) |
|
452 { |
|
453 TInt index = 0; |
|
454 TBuf8<KMaxNumberPropertySize> nbuf; |
|
455 nbuf.Num(aHeight); |
|
456 |
|
457 while ( index < iProperties.Count() ) |
|
458 { |
|
459 CUpnpDescriptionProperty* var = iProperties[index]; |
|
460 |
|
461 if ( KHeight().Compare( var->Name() ) == KErrNone ) |
|
462 { |
|
463 var->SetValueL(nbuf); |
|
464 return; |
|
465 } |
|
466 |
|
467 index++; |
|
468 } |
|
469 CUpnpDescriptionProperty* prop = CUpnpDescriptionProperty::NewL(KHeight, nbuf); |
|
470 iProperties.AppendL(prop); |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CUpnpIcon::MimeType |
|
475 // |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 EXPORT_C const TPtrC8 CUpnpIcon::MimeType() const |
|
479 { |
|
480 TInt index = 0; |
|
481 |
|
482 while ( index < iProperties.Count() ) |
|
483 { |
|
484 CUpnpDescriptionProperty* var = iProperties[index]; |
|
485 |
|
486 if ( KMimeType().Compare( var->Name() ) == KErrNone ) |
|
487 { |
|
488 return var->Value(); |
|
489 } |
|
490 |
|
491 index++; |
|
492 } |
|
493 |
|
494 return KNullDesC8(); |
|
495 } |
|
496 |
|
497 // ----------------------------------------------------------------------------- |
|
498 // CUpnpIcon::SetMimeTypeL |
|
499 // |
|
500 // ----------------------------------------------------------------------------- |
|
501 // |
|
502 void CUpnpIcon::SetMimeTypeL(const TDesC8& aMimeType) |
|
503 { |
|
504 |
|
505 TInt index = 0; |
|
506 |
|
507 while ( index < iProperties.Count() ) |
|
508 { |
|
509 CUpnpDescriptionProperty* var = iProperties[index]; |
|
510 |
|
511 if ( KMimeType().Compare( var->Name() ) == KErrNone ) |
|
512 { |
|
513 var->SetValueL(aMimeType); |
|
514 return; |
|
515 } |
|
516 |
|
517 index++; |
|
518 } |
|
519 CUpnpDescriptionProperty* prop = CUpnpDescriptionProperty::NewL(KMimeType, aMimeType); |
|
520 iProperties.AppendL(prop); |
|
521 } |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // CUpnpIcon::DeleteIconFromFsL |
|
525 // |
|
526 // ----------------------------------------------------------------------------- |
|
527 // |
|
528 void CUpnpIcon::DeleteIconFromFsL() |
|
529 { |
|
530 RFs fs; |
|
531 User::LeaveIfError( fs.Connect() ); |
|
532 fs.Delete(iFilename); |
|
533 fs.Close(); |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CUpnpIcon::AddPropertyL |
|
538 // |
|
539 // ----------------------------------------------------------------------------- |
|
540 // |
|
541 void CUpnpIcon::AddPropertyL( CUpnpDescriptionProperty* aProperty ) |
|
542 { |
|
543 iProperties.AppendL( aProperty); |
|
544 } |
|
545 |
|
546 // ----------------------------------------------------------------------------- |
|
547 // CUpnpIcon::ExternalizeL |
|
548 // |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 void CUpnpIcon::ExternalizeL( RWriteStream& aStream ) const |
|
552 { |
|
553 aStream << BitmapFilename(); |
|
554 aStream << Url(); |
|
555 aStream.WriteInt8L(Width()); |
|
556 aStream.WriteInt8L(Height()); |
|
557 aStream.WriteInt8L(Depth()); |
|
558 aStream << MimeType(); |
|
559 } |
|
560 |
|
561 // ----------------------------------------------------------------------------- |
|
562 // CUpnpIcon::InternalizeL |
|
563 // |
|
564 // ----------------------------------------------------------------------------- |
|
565 // |
|
566 EXPORT_C void CUpnpIcon::InternalizeL( RReadStream& aStream ) |
|
567 { |
|
568 SetBitmapFilename(HBufC16::NewLC( aStream, KMaxFileName)->Des()); |
|
569 SetUrlL(HBufC8::NewLC( aStream, KMaxFileName)->Des()); |
|
570 SetWidthL(aStream.ReadInt8L()); |
|
571 SetHeightL(aStream.ReadInt8L()); |
|
572 SetDepthL(aStream.ReadInt8L()); |
|
573 SetMimeTypeL(HBufC8::NewLC( aStream, KMaxMimeTypeSize)->Des()); |
|
574 |
|
575 CleanupStack::PopAndDestroy(3); |
|
576 } |
|
577 |
|
578 // ----------------------------------------------------------------------------- |
|
579 // CUpnpIcon::ToDes8L |
|
580 // |
|
581 // ----------------------------------------------------------------------------- |
|
582 // |
|
583 EXPORT_C HBufC8* CUpnpIcon::ToDes8L() const |
|
584 { |
|
585 // serialize object |
|
586 CBufFlat* buf = CBufFlat::NewL(KDefBuffer); |
|
587 CleanupStack::PushL(buf); |
|
588 RBufWriteStream stream(*buf); |
|
589 CleanupClosePushL(stream); |
|
590 |
|
591 stream << *this; |
|
592 |
|
593 // create heap descriptor |
|
594 HBufC8* hbuf = HBufC8::NewLC(buf->Size()); |
|
595 TPtr8 ptr(hbuf->Des()); |
|
596 buf->Read(0, ptr, buf->Size()); |
|
597 |
|
598 // clean up |
|
599 CleanupStack::Pop(hbuf); |
|
600 CleanupStack::PopAndDestroy(&stream); |
|
601 CleanupStack::PopAndDestroy(buf); |
|
602 |
|
603 return hbuf; |
|
604 |
|
605 } |
|
606 // End of File |