|
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: parameter list implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "BTServiceUtils.h" |
|
21 #include "BTServiceParameterList.h" |
|
22 #include "BTSUImageConverter.h" |
|
23 #include "BTSUXmlParser.h" |
|
24 #include "BTSUDebug.h" |
|
25 |
|
26 #include <apgcli.h> // RApaLSession |
|
27 #include <apmstd.h> // TDataType |
|
28 #include <imageconversion.h> //´Type solving |
|
29 #include <caf/content.h> |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 _LIT( KBIPImageTypes, "JPEGBMPGIFWBMPPNGJPEG2000" ); |
|
34 |
|
35 |
|
36 const TInt KBIPImageTypesLength = 30; |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CBTServiceParameterList::CBTServiceParameterList |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CBTServiceParameterList::CBTServiceParameterList() |
|
47 { |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CBTServiceParameterList::ConstructL |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CBTServiceParameterList::ConstructL() |
|
56 { |
|
57 FLOG(_L("[BTSU]\t CBTServiceParameterList::ConstructL()")); |
|
58 iRemovedImageCount=0; |
|
59 User::LeaveIfError( iFileSession.Connect() ); |
|
60 iFileSession.ShareProtected(); |
|
61 |
|
62 FLOG(_L("[BTSU]\t CBTServiceParameterList::ConstructL() completed")); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CBTServiceParameterList::NewL |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CBTServiceParameterList* CBTServiceParameterList::NewL() |
|
71 { |
|
72 CBTServiceParameterList* self = new( ELeave ) CBTServiceParameterList; |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CBTServiceParameterList::NewLC |
|
81 // Two-phased constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C CBTServiceParameterList* CBTServiceParameterList::NewLC() |
|
85 { |
|
86 CBTServiceParameterList* self = new( ELeave ) CBTServiceParameterList; |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL(); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // Destructor |
|
93 CBTServiceParameterList::~CBTServiceParameterList() |
|
94 { |
|
95 FLOG(_L("[BTSU]\t CBTServiceParameterList::~CBTServiceParameterList()")); |
|
96 |
|
97 TInt index = 0; |
|
98 |
|
99 for ( ; index < iXhtmlList.Count(); index++ ) |
|
100 { |
|
101 delete iXhtmlList[index].iFileName; |
|
102 delete iXhtmlList[index].iRefObjectList; |
|
103 } |
|
104 |
|
105 for ( index = 0; index < iImageList.Count(); index++ ) |
|
106 { |
|
107 |
|
108 delete iImageList[index].iMimeType; |
|
109 delete iImageList[index].iDisplayName; |
|
110 if(iImageList[index].iFile.SubSessionHandle()) |
|
111 { |
|
112 iImageList[index].iFile.Close(); |
|
113 } |
|
114 |
|
115 } |
|
116 |
|
117 for ( index = 0; index < iObjectList.Count(); index++ ) |
|
118 { |
|
119 if(iObjectList[index].SubSessionHandle()) |
|
120 { |
|
121 iObjectList[index].Close(); |
|
122 } |
|
123 } |
|
124 |
|
125 iXhtmlList.Close(); |
|
126 iImageList.Close(); |
|
127 iObjectList.Close(); |
|
128 iFileSession.Close(); |
|
129 |
|
130 FLOG(_L("[BTSU]\t CBTServiceParameterList::~CBTServiceParameterList() completed")); |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CBTServiceParameterList::AddXhtmlL |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C void CBTServiceParameterList::AddXhtmlL( const TDesC& aFilePath ) |
|
138 { |
|
139 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddXhtmlL()")); |
|
140 |
|
141 if ( &aFilePath == NULL || |
|
142 aFilePath.Length() == 0 || |
|
143 aFilePath.Length() > KMaxFileName ) |
|
144 { |
|
145 User::Leave( KErrArgument ); |
|
146 } |
|
147 |
|
148 // Allocate memory for filename |
|
149 // |
|
150 HBufC* file = aFilePath.AllocL(); |
|
151 CleanupStack::PushL( file ); |
|
152 |
|
153 // Resolve referenced objects |
|
154 // |
|
155 CBTSUXmlParser* parser = CBTSUXmlParser::NewL(); |
|
156 CleanupStack::PushL( parser ); |
|
157 |
|
158 CDesCArrayFlat* list = parser->GetRefObjectListL( aFilePath ); |
|
159 CleanupStack::PushL( list ); |
|
160 |
|
161 // Store parameter into list |
|
162 // |
|
163 TBTSUXhtmlParam param; |
|
164 param.iFileName = file; |
|
165 param.iRefObjectList = list; |
|
166 User::LeaveIfError( iXhtmlList.Append( param ) ); |
|
167 |
|
168 CleanupStack::Pop( 3 ); // list, parser, file |
|
169 delete parser; |
|
170 |
|
171 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddXhtmlL() completed")); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CBTServiceParameterList::AddImageL |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C void CBTServiceParameterList::AddImageL( const TDesC& aFilePath ) |
|
179 { |
|
180 if ( &aFilePath == NULL || |
|
181 aFilePath.Length() == 0 || |
|
182 aFilePath.Length() > KMaxFileName ) |
|
183 { |
|
184 User::Leave( KErrArgument ); |
|
185 } |
|
186 RFile file; |
|
187 User::LeaveIfError( file.Open( iFileSession, aFilePath, EFileShareReadersOnly) ); |
|
188 AddImageL(file); |
|
189 file.Close(); |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CBTServiceParameterList::AddImageL |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C void CBTServiceParameterList::AddImageL( RFile aFile ) |
|
197 { |
|
198 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddImageL()")); |
|
199 TBool found; |
|
200 TInt retVal; |
|
201 TBool isprotected = EFalse; |
|
202 |
|
203 //chekc that file handle is correct |
|
204 if(!aFile.SubSessionHandle()) |
|
205 { |
|
206 User::Leave( KErrArgument ); |
|
207 } |
|
208 |
|
209 //check if files are drm protected |
|
210 |
|
211 ContentAccess::CContent* drm = ContentAccess::CContent::NewL(aFile); |
|
212 drm->GetAttribute(ContentAccess::EIsProtected, isprotected); |
|
213 delete drm; |
|
214 |
|
215 |
|
216 if(isprotected) |
|
217 { |
|
218 User::Leave( KErrNotSupported ); |
|
219 } |
|
220 |
|
221 |
|
222 CBTSUImageConverter * imageConverter = CBTSUImageConverter::NewL(); |
|
223 CleanupStack::PushL( imageConverter ); |
|
224 |
|
225 // Allocate memory for filename |
|
226 // |
|
227 |
|
228 |
|
229 // Resolve MIME type |
|
230 // |
|
231 RApaLsSession session; |
|
232 HBufC8* mimeType = NULL; |
|
233 TDataType type; |
|
234 |
|
235 TUid uid; |
|
236 |
|
237 User::LeaveIfError( session.Connect() ); |
|
238 CleanupClosePushL( session ); |
|
239 |
|
240 User::LeaveIfError( session.AppForDocument( aFile, uid, type ) ); |
|
241 mimeType = type.Des8().AllocL(); |
|
242 |
|
243 CleanupStack::Pop(); // session |
|
244 session.Close(); |
|
245 |
|
246 CleanupStack::PushL( mimeType ); |
|
247 |
|
248 // Resolve Display name |
|
249 // |
|
250 HBufC* displayName = imageConverter->GetDisplayNameL( *mimeType ); |
|
251 CleanupStack::PushL( displayName ); |
|
252 |
|
253 RFileExtensionMIMETypeArray fileExtensions; |
|
254 |
|
255 //Resolve what format are suported |
|
256 TRAP( retVal, CImageDecoder::GetFileTypesL( fileExtensions ) ); |
|
257 if( retVal != KErrNone ) |
|
258 { |
|
259 fileExtensions.ResetAndDestroy(); |
|
260 User::Leave( retVal ); |
|
261 } |
|
262 |
|
263 found=EFalse; |
|
264 TBuf<KBIPImageTypesLength> types = KBIPImageTypes(); |
|
265 |
|
266 for( TInt index = 0; index < fileExtensions.Count(); index++ ) |
|
267 { |
|
268 retVal=displayName->Compare((*fileExtensions[index]).DisplayName()); |
|
269 if(retVal==0 && types.Find((*fileExtensions[index]).DisplayName())!=KErrNotFound ) |
|
270 { |
|
271 found=ETrue; |
|
272 } |
|
273 } |
|
274 fileExtensions.ResetAndDestroy(); |
|
275 if(found==EFalse) |
|
276 { |
|
277 User::Leave(KErrNotSupported); |
|
278 } |
|
279 |
|
280 |
|
281 // Resolve file size |
|
282 // |
|
283 TInt fileSize = 0; |
|
284 User::LeaveIfError( aFile.Size( fileSize ) ); |
|
285 |
|
286 |
|
287 // Resolve width and height |
|
288 // |
|
289 TSize decodeSize = imageConverter->GetImageSizeL( aFile ); |
|
290 |
|
291 |
|
292 // Store parameter into list |
|
293 // |
|
294 TBTSUImageParam param; |
|
295 |
|
296 param.iFile.Duplicate(aFile); |
|
297 param.iMimeType = mimeType; |
|
298 param.iDisplayName = displayName; |
|
299 param.iFileSize = fileSize; |
|
300 param.iPixelSize = decodeSize; |
|
301 param.iSend=EFalse; |
|
302 |
|
303 |
|
304 User::LeaveIfError( iImageList.Append( param ) ); |
|
305 |
|
306 CleanupStack::Pop( 3 ); // displayName, mimeType, imageConverter |
|
307 delete imageConverter; |
|
308 |
|
309 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddImageL() completed")); |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CBTServiceParameterList::AddObjectL |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C void CBTServiceParameterList::AddObjectL( const TDesC& aFilePath ) |
|
317 { |
|
318 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddObjectL()")); |
|
319 |
|
320 if ( &aFilePath == NULL || |
|
321 aFilePath.Length() == 0 || |
|
322 aFilePath.Length() > KMaxFileName ) |
|
323 { |
|
324 User::Leave( KErrArgument ); |
|
325 } |
|
326 |
|
327 RFile file; |
|
328 User::LeaveIfError( file.Open( iFileSession, aFilePath, EFileShareReadersOnly) ); |
|
329 AddObjectL(file); |
|
330 file.Close(); |
|
331 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddObjectL() completed")); |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CBTServiceParameterList::AddObjectL |
|
336 // ----------------------------------------------------------------------------- |
|
337 // |
|
338 EXPORT_C void CBTServiceParameterList::AddObjectL( RFile aFile ) |
|
339 { |
|
340 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddObjectL()")); |
|
341 |
|
342 //chekc that file handle is correct |
|
343 if(!aFile.SubSessionHandle()) |
|
344 { |
|
345 User::Leave( KErrArgument ); |
|
346 } |
|
347 RFile file; |
|
348 |
|
349 file.Duplicate(aFile); |
|
350 |
|
351 iObjectList.AppendL( file ); |
|
352 |
|
353 FLOG(_L("[BTSU]\t CBTServiceParameterList::AddObjectL() completed")); |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CBTServiceParameterList::XhtmlCount |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 TInt CBTServiceParameterList::XhtmlCount() const |
|
361 { |
|
362 return iXhtmlList.Count(); |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CBTServiceParameterList::ImageCount |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 TInt CBTServiceParameterList::ImageCount() const |
|
370 { |
|
371 return iImageList.Count(); |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CBTServiceParameterList::ObjectCount |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 TInt CBTServiceParameterList::ObjectCount() const |
|
379 { |
|
380 return iObjectList.Count(); |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CBTServiceParameterList::XhtmlAt |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 TBTSUXhtmlParam CBTServiceParameterList::XhtmlAt( TInt aIndex ) const |
|
388 { |
|
389 FLOG(_L("[BTSU]\t CBTServiceParameterList::XhtmlAt()")); |
|
390 __ASSERT_DEBUG( aIndex >= 0 && aIndex < XhtmlCount(), BTSUPanic( EBTSUPanicOutOfRange ) ); |
|
391 |
|
392 TBTSUXhtmlParam param; |
|
393 param.iFileName = iXhtmlList[ aIndex].iFileName; |
|
394 param.iRefObjectList = iXhtmlList[ aIndex].iRefObjectList; |
|
395 |
|
396 FLOG(_L("[BTSU]\t CBTServiceParameterList::XhtmlAt() completed")); |
|
397 |
|
398 return param; |
|
399 } |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CBTServiceParameterList::ImageAt |
|
403 // ----------------------------------------------------------------------------- |
|
404 // |
|
405 TBTSUImageParam CBTServiceParameterList::ImageAtL( TInt aIndex ) const |
|
406 { |
|
407 FLOG(_L("[BTSU]\t CBTServiceParameterList::ImageAt()")); |
|
408 |
|
409 TBTSUImageParam param; |
|
410 |
|
411 if(aIndex<0 || aIndex> ImageCount() ) |
|
412 { |
|
413 User::Leave(KErrGeneral); |
|
414 } |
|
415 |
|
416 param.iFile = iImageList[aIndex].iFile; |
|
417 param.iMimeType = iImageList[aIndex].iMimeType; |
|
418 param.iDisplayName = iImageList[aIndex].iDisplayName; |
|
419 param.iPixelSize = iImageList[aIndex].iPixelSize; |
|
420 param.iFileSize = iImageList[aIndex].iFileSize; |
|
421 param.iSend = iImageList[aIndex].iSend; |
|
422 |
|
423 |
|
424 FLOG(_L("[BTSU]\t CBTServiceParameterList::ImageAt() completed")); |
|
425 |
|
426 return param; |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CBTServiceParameterList::ObjectAt |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 RFile& CBTServiceParameterList::ObjectAtL( TInt aIndex ) |
|
434 { |
|
435 FLOG(_L("[BTSU]\t CBTServiceParameterList::ObjectAt()")); |
|
436 |
|
437 if(aIndex<0 || aIndex> iObjectList.Count() ) |
|
438 { |
|
439 User::Leave(KErrGeneral); |
|
440 } |
|
441 return iObjectList[aIndex]; |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // CBTServiceParameterList::HasAnyReferencedObjects |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 TBool CBTServiceParameterList::HasAnyReferencedObjects() const |
|
449 { |
|
450 FLOG(_L("[BTSU]\t CBTServiceParameterList::HasAnyReferencedObjects()")); |
|
451 |
|
452 TBool result = EFalse; |
|
453 |
|
454 for ( TInt index = 0; index < iXhtmlList.Count(); index++ ) |
|
455 { |
|
456 if ( iXhtmlList[index].iRefObjectList->Count() > 0 ) |
|
457 { |
|
458 result = ETrue; |
|
459 break; |
|
460 } |
|
461 } |
|
462 |
|
463 FTRACE(FPrint(_L("[BTSU]\t CBTServiceParameterList::HasAnyReferencedObjects() completed with %d"), result )); |
|
464 |
|
465 return result; |
|
466 } |
|
467 |
|
468 // ----------------------------------------------------------------------------- |
|
469 // CBTServiceParameterList::ObjectListSizeL |
|
470 // ----------------------------------------------------------------------------- |
|
471 // |
|
472 TInt CBTServiceParameterList::ObjectListSizeL() const |
|
473 { |
|
474 FLOG(_L("[BTSU]\t CBTServiceParameterList::ObjectListSizeL()")); |
|
475 |
|
476 TInt totalFileSize = 0; |
|
477 |
|
478 for ( TInt index = 0; index < iObjectList.Count(); index++ ) |
|
479 { |
|
480 TInt fileSize = 0; |
|
481 iObjectList[index].Size( fileSize ); |
|
482 totalFileSize += fileSize; |
|
483 } |
|
484 return totalFileSize; |
|
485 } |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // CBTServiceParameterList::ImageListSize |
|
489 // ----------------------------------------------------------------------------- |
|
490 // |
|
491 TInt CBTServiceParameterList::ImageListSize() const |
|
492 { |
|
493 FLOG(_L("[BTSU]\t CBTServiceParameterList::ImageListSize()")); |
|
494 |
|
495 TInt totalFileSize = 0; |
|
496 for ( TInt index = 0; index < iImageList.Count(); index++ ) |
|
497 { |
|
498 totalFileSize += iImageList[index].iFileSize; |
|
499 } |
|
500 |
|
501 FTRACE(FPrint(_L("[BTSU]\t CBTServiceParameterList::ImageListSize %d"), totalFileSize )); |
|
502 return totalFileSize; |
|
503 } |
|
504 // ----------------------------------------------------------------------------- |
|
505 // CBTServiceParameterList::RemoveImageL |
|
506 // ----------------------------------------------------------------------------- |
|
507 // |
|
508 |
|
509 void CBTServiceParameterList::RemoveImageL(TInt aIndex) |
|
510 { |
|
511 if(aIndex<0 || aIndex> iImageList.Count() ) |
|
512 { |
|
513 User::Leave(KErrGeneral); |
|
514 } |
|
515 |
|
516 delete iImageList[aIndex].iMimeType; |
|
517 delete iImageList[aIndex].iDisplayName; |
|
518 iImageList.Remove(aIndex); |
|
519 iRemovedImageCount++; |
|
520 } |
|
521 |
|
522 // ----------------------------------------------------------------------------- |
|
523 // CBTServiceParameterList::RemovedImageCount |
|
524 // ----------------------------------------------------------------------------- |
|
525 // |
|
526 TInt CBTServiceParameterList::RemovedImageCount() |
|
527 { |
|
528 return iRemovedImageCount; |
|
529 } |
|
530 |
|
531 // ----------------------------------------------------------------------------- |
|
532 // CBTServiceParameterList::ResetImageHandleL |
|
533 // ----------------------------------------------------------------------------- |
|
534 // |
|
535 void CBTServiceParameterList::ResetImageHandleL(TInt aIndex) |
|
536 { |
|
537 if(aIndex<0 || aIndex> iImageList.Count() ) |
|
538 { |
|
539 User::Leave(KErrGeneral); |
|
540 } |
|
541 iImageList[aIndex].iFile=RFile(); |
|
542 } |
|
543 // ----------------------------------------------------------------------------- |
|
544 // CBTServiceParameterList::ResetObjectHandleL |
|
545 // ----------------------------------------------------------------------------- |
|
546 // |
|
547 void CBTServiceParameterList::ResetObjectHandleL(TInt aIndex) |
|
548 { |
|
549 if(aIndex<0 || aIndex> iObjectList.Count() ) |
|
550 { |
|
551 User::Leave(KErrGeneral); |
|
552 } |
|
553 iObjectList[aIndex]=RFile(); |
|
554 } |
|
555 |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CBTServiceParameterList::ResetObjectHandleL |
|
559 // ----------------------------------------------------------------------------- |
|
560 // |
|
561 void CBTServiceParameterList::MarkAsSendL(TInt aIndex) |
|
562 { |
|
563 if(aIndex<0 || aIndex> iImageList.Count() ) |
|
564 { |
|
565 User::Leave(KErrGeneral); |
|
566 } |
|
567 iImageList[aIndex].iSend=ETrue; |
|
568 } |
|
569 |
|
570 |
|
571 // End of File |