|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of CStreamingLinkModel |
|
15 * |
|
16 */ |
|
17 |
|
18 // Version : %version: 4 % |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <utf.h> |
|
24 #include <e32std.h> |
|
25 #include <bautils.h> |
|
26 #include <sysutil.h> |
|
27 #include <pathinfo.h> |
|
28 #include <mediarecognizer.h> |
|
29 #include <streaminglinkmodel.h> |
|
30 |
|
31 #ifdef RD_MULTIPLE_DRIVE |
|
32 #include <driveinfo.h> |
|
33 #endif //RD_MULTIPLE_DRIVE |
|
34 |
|
35 #include "playbackhelper_log.h" |
|
36 |
|
37 // CONSTANTS |
|
38 const TInt KLocalFileIdLength(5); |
|
39 const TInt KMaxLinkFileSize(5120); //5kB |
|
40 const TInt KBothSlashes(2); |
|
41 #ifndef RD_MULTIPLE_DRIVE |
|
42 const TInt KDriveLetter(2); |
|
43 #endif //RD_MULTIPLE_DRIVE |
|
44 |
|
45 _LIT( KLocalFileId, "file:"); |
|
46 _LIT( KSlash, "/" ); |
|
47 _LIT( KDoubleSlash, "//" ); |
|
48 _LIT( KBackSlash, "\\" ); |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =================================================== |
|
51 |
|
52 // ------------------------------------------------------------------------------------------------- |
|
53 // CStreamingLinkModel::CStreamingLinkModel |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ------------------------------------------------------------------------------------------------- |
|
57 // |
|
58 CStreamingLinkModel::CStreamingLinkModel() |
|
59 { |
|
60 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::CStreamingLinkModel()")); |
|
61 } |
|
62 |
|
63 // ------------------------------------------------------------------------------------------------- |
|
64 // CStreamingLinkModel::ConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // ------------------------------------------------------------------------------------------------- |
|
67 // |
|
68 void CStreamingLinkModel::ConstructL() |
|
69 { |
|
70 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::ConstructL()")); |
|
71 |
|
72 User::LeaveIfError( iFs.Connect() ); |
|
73 } |
|
74 |
|
75 // ------------------------------------------------------------------------------------------------- |
|
76 // CStreamingLinkModel::NewL |
|
77 // Two-phased constructor. |
|
78 // ------------------------------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C CStreamingLinkModel* CStreamingLinkModel::NewL() |
|
81 { |
|
82 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::NewL()")); |
|
83 |
|
84 CStreamingLinkModel* self = new( ELeave ) CStreamingLinkModel(); |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 CleanupStack::Pop(); |
|
88 return self; |
|
89 } |
|
90 |
|
91 // ------------------------------------------------------------------------------------------------- |
|
92 // CStreamingLinkModel::~CStreamingLinkModel |
|
93 // Destructor |
|
94 // ------------------------------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C CStreamingLinkModel::~CStreamingLinkModel() |
|
97 { |
|
98 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::~CStreamingLinkModel()")); |
|
99 |
|
100 for ( TInt i = 0 ; i < iLinkArray.Count() ; i++ ) |
|
101 { |
|
102 delete iLinkArray[i]->link; |
|
103 } |
|
104 |
|
105 iLinkArray.ResetAndDestroy(); |
|
106 |
|
107 iFileHandle.Close(); |
|
108 iFs.Close(); |
|
109 } |
|
110 |
|
111 // ------------------------------------------------------------------------------------------------- |
|
112 // CStreamingLinkModel::OpenLinkFileL |
|
113 // ------------------------------------------------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C TInt CStreamingLinkModel::OpenLinkFileL( const TDesC& aLinkFileName, |
|
116 TBool aEnableFiltering ) |
|
117 { |
|
118 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::OpenLinkFileL()")); |
|
119 |
|
120 // |
|
121 // exit if file is not found |
|
122 // |
|
123 if ( !BaflUtils::FileExists( iFs, aLinkFileName ) ) |
|
124 { |
|
125 User::Leave( KErrNotFound ); |
|
126 } |
|
127 |
|
128 // |
|
129 // open via file name |
|
130 // |
|
131 RFile ramFile; |
|
132 TInt err = ramFile.Open( iFs, aLinkFileName, EFileRead | EFileShareReadersOnly ); |
|
133 |
|
134 if( err ) |
|
135 { |
|
136 err = ramFile.Open( iFs, aLinkFileName, EFileRead | EFileShareAny ); |
|
137 } |
|
138 |
|
139 CleanupClosePushL( ramFile ); |
|
140 |
|
141 // |
|
142 // populate the links |
|
143 // |
|
144 TInt result = PopulateRamLinksL( ramFile, aEnableFiltering ); |
|
145 |
|
146 CleanupStack::PopAndDestroy(); //ramFile |
|
147 |
|
148 return result; |
|
149 } |
|
150 |
|
151 // ------------------------------------------------------------------------------------------------- |
|
152 // CStreamingLinkModel::OpenLinkFileL |
|
153 // ------------------------------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C TInt CStreamingLinkModel::OpenLinkFileL( RFile& aFile, |
|
156 TBool aEnableFiltering ) |
|
157 { |
|
158 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::OpenLinkFileL()")); |
|
159 |
|
160 RFile ramFile; |
|
161 |
|
162 if ( FileHandleExists(aFile) ) |
|
163 { |
|
164 iFileHandle.Close(); |
|
165 User::LeaveIfError( iFileHandle.Duplicate( aFile ) ); |
|
166 User::LeaveIfError( ramFile.Duplicate( iFileHandle ) ); |
|
167 CleanupClosePushL( ramFile ); |
|
168 } |
|
169 else |
|
170 { |
|
171 User::Leave( KErrNotFound ); |
|
172 } |
|
173 |
|
174 // |
|
175 // populate the links |
|
176 // |
|
177 TInt result = PopulateRamLinksL( ramFile, aEnableFiltering ); |
|
178 |
|
179 CleanupStack::PopAndDestroy(); //ramFile |
|
180 |
|
181 return result; |
|
182 } |
|
183 |
|
184 // ------------------------------------------------------------------------------------------------- |
|
185 // CStreamingLinkModel::MaxLinkLength |
|
186 // ------------------------------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C TInt CStreamingLinkModel::MaxLinkLength() |
|
189 { |
|
190 TInt length = 0; |
|
191 |
|
192 for ( TInt index = 0; index < iLinkArray.Count(); index++) |
|
193 { |
|
194 length = length + iLinkArray[index]->link->Length(); |
|
195 } |
|
196 |
|
197 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::MaxLinkLength() max length = [%d] "), length ); |
|
198 |
|
199 return length; |
|
200 } |
|
201 |
|
202 // ------------------------------------------------------------------------------------------------- |
|
203 // CStreamingLinkModel::GetNextLinkL |
|
204 // ------------------------------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C TInt CStreamingLinkModel::GetNextLinkL( TDes& aLink, TBool& aLocalFile, TBool aParse ) |
|
207 { |
|
208 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::GetNextLinkL()") ); |
|
209 |
|
210 aLocalFile = EFalse; |
|
211 TInt ret = KErrNone; |
|
212 |
|
213 if ( iLinkCount < iLinkArray.Count() ) |
|
214 { |
|
215 aLink = iLinkArray[iLinkCount]->link->Des(); |
|
216 iLinkCount++; |
|
217 |
|
218 // local file --> parse it. |
|
219 if ( aParse && !aLink.Left( KLocalFileIdLength ).CompareF( KLocalFileId ) ) |
|
220 { |
|
221 // remove "file:" |
|
222 aLocalFile = ETrue; |
|
223 aLink = aLink.Mid( KLocalFileIdLength ); |
|
224 |
|
225 // remove extra '/' from begin |
|
226 while ( !aLink.Left( 1 ).CompareF( KSlash ) ) |
|
227 { |
|
228 aLink = aLink.Mid( 1 ); |
|
229 } |
|
230 |
|
231 // change "//" and "/" inside body to "\" |
|
232 TInt index = aLink.FindF( KDoubleSlash ); |
|
233 while ( index != KErrNotFound ) |
|
234 { |
|
235 aLink.Replace( index, KBothSlashes, KBackSlash ); |
|
236 index = aLink.FindF( KDoubleSlash ); |
|
237 } |
|
238 |
|
239 index = aLink.FindF( KSlash ); |
|
240 |
|
241 while ( index != KErrNotFound ) |
|
242 { |
|
243 aLink.Replace( index, 1, KBackSlash ); |
|
244 index = aLink.FindF( KSlash ); |
|
245 } |
|
246 } |
|
247 } |
|
248 else |
|
249 { |
|
250 ret = KErrNotFound; |
|
251 } |
|
252 |
|
253 return ret; |
|
254 } |
|
255 |
|
256 // ------------------------------------------------------------------------------------------------- |
|
257 // CStreamingLinkModel::IsSeekable |
|
258 // ------------------------------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C TBool CStreamingLinkModel::IsSeekable() |
|
261 { |
|
262 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::IsSeekable()") ); |
|
263 |
|
264 TBool ret = ETrue; |
|
265 |
|
266 // link count has been incremented in the GetNextlink |
|
267 if ( iLinkCount <= iLinkArray.Count() ) |
|
268 { |
|
269 ret = iLinkArray[iLinkCount-1]->seek; |
|
270 } |
|
271 |
|
272 return ( ret ); |
|
273 } |
|
274 |
|
275 // ------------------------------------------------------------------------------------------------- |
|
276 // CStreamingLinkModel::ReadNextLine |
|
277 // ------------------------------------------------------------------------------------------------- |
|
278 // |
|
279 TInt CStreamingLinkModel::ReadNextLine( TDes& aLine ) |
|
280 { |
|
281 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::ReadNextLine()")); |
|
282 |
|
283 TInt ret = KErrNone; |
|
284 TInt lineChange = iBufferPtr.LocateF( EKeyLineFeed ); |
|
285 |
|
286 if ( lineChange == KErrNotFound ) |
|
287 { |
|
288 // No line change was found --> last line had no line change |
|
289 // Copy last line to (unicode) aLink |
|
290 CnvUtfConverter::ConvertToUnicodeFromUtf8( aLine, iBufferPtr ); |
|
291 ret = KErrEof; |
|
292 } |
|
293 else |
|
294 { |
|
295 //Found line change |
|
296 TInt length = lineChange; |
|
297 if ( ( length > 0 ) && ( iBufferPtr[length-1] == EKeyEnter ) ) |
|
298 { |
|
299 length--; |
|
300 } |
|
301 |
|
302 // Copy line to (unicode) aLink |
|
303 CnvUtfConverter::ConvertToUnicodeFromUtf8( aLine, iBufferPtr.Left( length ) ); |
|
304 |
|
305 // Move past the line feed |
|
306 iBufferPtr.Set( iBufferPtr.Mid( ++lineChange ) ); |
|
307 |
|
308 if ( !iBufferPtr.Length() ) |
|
309 { |
|
310 // File end reached. |
|
311 ret = KErrEof; |
|
312 } |
|
313 } |
|
314 |
|
315 return ret; |
|
316 } |
|
317 |
|
318 // ------------------------------------------------------------------------------------------------- |
|
319 // CStreamingLinkModel::CreateNewLinkFileL |
|
320 // ------------------------------------------------------------------------------------------------- |
|
321 // |
|
322 EXPORT_C TInt CStreamingLinkModel::CreateNewLinkFileL( const TDesC& aNewLinkFileName, |
|
323 MDesCArray* aLinkArray, |
|
324 TBool aOverWrite ) |
|
325 { |
|
326 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::CreateNewLinkFileL()")); |
|
327 |
|
328 TInt result = KErrNone; |
|
329 |
|
330 // check if file exists already |
|
331 if ( !aOverWrite && BaflUtils::FileExists( iFs, aNewLinkFileName ) ) |
|
332 { |
|
333 result = KErrAlreadyExists; |
|
334 } |
|
335 else |
|
336 { |
|
337 //check disk space |
|
338 TInt bytesRequired = 0; |
|
339 TInt index = 0; |
|
340 |
|
341 for ( index = 0; index < aLinkArray->MdcaCount(); index++ ) |
|
342 { |
|
343 bytesRequired = bytesRequired + aLinkArray->MdcaPoint( index ).Size(); |
|
344 } |
|
345 |
|
346 TParsePtrC parse(aNewLinkFileName); |
|
347 |
|
348 #ifdef RD_MULTIPLE_DRIVE |
|
349 DriveInfo::TDriveArray driveArray; |
|
350 TInt drive = 0; |
|
351 |
|
352 RFs::CharToDrive( parse.Drive()[0], drive ); |
|
353 |
|
354 //check disk space |
|
355 if( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, bytesRequired, drive ) ) |
|
356 { |
|
357 result = KErrDiskFull; |
|
358 } |
|
359 #else //RD_MULTIPLE_DRIVE |
|
360 if( parse.Drive().CompareF( PathInfo::MemoryCardRootPath().Left( KDriveLetter ) ) == 0 ) |
|
361 { |
|
362 if ( SysUtil::MMCSpaceBelowCriticalLevelL( &iFs, bytesRequired ) ) |
|
363 { |
|
364 result = KErrDiskFull; |
|
365 } |
|
366 } |
|
367 else if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, bytesRequired ) ) |
|
368 { |
|
369 User::Leave( KErrDiskFull ); |
|
370 } |
|
371 #endif //RD_MULTIPLE_DRIVE |
|
372 |
|
373 if ( result == KErrNone ) |
|
374 { |
|
375 // save |
|
376 RFile file; |
|
377 User::LeaveIfError( file.Replace( iFs, aNewLinkFileName, EFileWrite ) ); |
|
378 CleanupClosePushL( file ); |
|
379 |
|
380 for ( index = 0; result == KErrNone && index < aLinkArray->MdcaCount(); index++ ) |
|
381 { |
|
382 // Convert to ascii. Some special marks like '? might take 1-3 letters. |
|
383 HBufC8* link = HBufC8::NewLC( aLinkArray->MdcaPoint( index ).Length() * 3 + 1 ); |
|
384 TPtr8 ptr = link->Des(); |
|
385 CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr, aLinkArray->MdcaPoint( index ) ); |
|
386 ptr.Append( EKeyLineFeed ); |
|
387 |
|
388 // write to file |
|
389 result = file.Write( ptr ); |
|
390 |
|
391 CleanupStack::PopAndDestroy( link ); |
|
392 } |
|
393 |
|
394 file.Flush(); |
|
395 CleanupStack::PopAndDestroy(); // file |
|
396 |
|
397 } |
|
398 } |
|
399 |
|
400 return result; |
|
401 } |
|
402 |
|
403 // ------------------------------------------------------------------------------------------------- |
|
404 // CStreamingLinkModel::FreeFilehandle |
|
405 // ------------------------------------------------------------------------------------------------- |
|
406 // |
|
407 EXPORT_C void CStreamingLinkModel::FreeFilehandle() |
|
408 { |
|
409 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::FreeFilehandle()")); |
|
410 |
|
411 iFileHandle.Close(); |
|
412 } |
|
413 |
|
414 // ------------------------------------------------------------------------------------------------- |
|
415 // CStreamingLinkModel::FileHandleExists |
|
416 // ------------------------------------------------------------------------------------------------- |
|
417 // |
|
418 TBool CStreamingLinkModel::FileHandleExists( RFile& aFile ) |
|
419 { |
|
420 TInt size = 0; |
|
421 TInt err = KErrNone; |
|
422 TBool exist = EFalse; |
|
423 |
|
424 if ( aFile.SubSessionHandle() ) |
|
425 { |
|
426 err = aFile.Size( size ); |
|
427 } |
|
428 |
|
429 if ( !err && size ) |
|
430 { |
|
431 exist = ETrue; |
|
432 } |
|
433 |
|
434 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::FileHandleExists() exist = [%d]"), exist); |
|
435 |
|
436 return exist; |
|
437 } |
|
438 |
|
439 // ------------------------------------------------------------------------------------------------- |
|
440 // CStreamingLinkModel::MaxLinkLength |
|
441 // ------------------------------------------------------------------------------------------------- |
|
442 // |
|
443 EXPORT_C TInt CStreamingLinkModel::MultiLinksCount() |
|
444 { |
|
445 TInt cnt = iLinkArray.Count(); |
|
446 |
|
447 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::MultiLinksCount() count = [%d]"), cnt); |
|
448 |
|
449 return cnt; |
|
450 } |
|
451 |
|
452 // ------------------------------------------------------------------------------------------------- |
|
453 // CStreamingLinkModel::ResetLinkCount |
|
454 // ------------------------------------------------------------------------------------------------- |
|
455 // |
|
456 EXPORT_C void CStreamingLinkModel::ResetLinkCount() |
|
457 { |
|
458 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::ResetLinkCount()")); |
|
459 |
|
460 iLinkCount = 0; |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CStreamingLinkModel::OpenAsxFileL |
|
465 // ----------------------------------------------------------------------------- |
|
466 // |
|
467 EXPORT_C TInt CStreamingLinkModel::OpenAsxFileL( const TDesC& aLinkFileName, |
|
468 TBool aEnableFiltering ) |
|
469 { |
|
470 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::OpenAsxFileL(%S,%d)"), |
|
471 &aLinkFileName,aEnableFiltering); |
|
472 TInt result = KErrNone; |
|
473 |
|
474 #ifdef __WINDOWS_MEDIA |
|
475 |
|
476 CAsxParser* asxParser = NULL; |
|
477 TRAPD( err, |
|
478 { |
|
479 asxParser = CAsxParser::NewL( aLinkFileName ); |
|
480 } ); //TRAPD |
|
481 |
|
482 if ( err ) |
|
483 { |
|
484 result = KErrNotSupported; |
|
485 } |
|
486 else |
|
487 { |
|
488 CleanupStack::PushL( asxParser ); |
|
489 result = PopulateAsxLinksL( asxParser, aEnableFiltering ); |
|
490 CleanupStack::PopAndDestroy(); // asxParser |
|
491 } |
|
492 |
|
493 |
|
494 #else // __WINDOWS_MEDIA |
|
495 |
|
496 result = KErrNotSupported; |
|
497 |
|
498 #endif // __WINDOWS_MEDIA |
|
499 |
|
500 return result; |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // CStreamingLinkModel::OpenAsxFileL |
|
505 // ----------------------------------------------------------------------------- |
|
506 // |
|
507 EXPORT_C TInt CStreamingLinkModel::OpenAsxFileL( RFile& aFile, |
|
508 TBool aEnableFiltering ) |
|
509 { |
|
510 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::OpenAsxFileL(aFile,%d)"),aEnableFiltering); |
|
511 |
|
512 TInt result = KErrNone; |
|
513 |
|
514 #ifdef __WINDOWS_MEDIA |
|
515 |
|
516 CAsxParser* asxParser = NULL; |
|
517 TRAPD( err, |
|
518 { |
|
519 asxParser = CAsxParser::NewL( aFile ); |
|
520 } ); //TRAPD |
|
521 |
|
522 if ( err ) |
|
523 { |
|
524 result = KErrNotSupported; |
|
525 } |
|
526 else |
|
527 { |
|
528 CleanupStack::PushL( asxParser ); |
|
529 result = PopulateAsxLinksL( asxParser, aEnableFiltering ); |
|
530 CleanupStack::PopAndDestroy(); // asxParser |
|
531 } |
|
532 |
|
533 |
|
534 #else // __WINDOWS_MEDIA |
|
535 |
|
536 result = KErrNotSupported; |
|
537 |
|
538 #endif // __WINDOWS_MEDIA |
|
539 |
|
540 return result; |
|
541 } |
|
542 |
|
543 // ----------------------------------------------------------------------------- |
|
544 // CStreamingLinkModel::PopulateRamLinksL |
|
545 // ----------------------------------------------------------------------------- |
|
546 // |
|
547 TInt CStreamingLinkModel::PopulateRamLinksL( RFile aRamFile, |
|
548 TBool aEnableFiltering ) |
|
549 { |
|
550 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::PopulateRamLinksL()")); |
|
551 |
|
552 for ( TInt i = 0 ; i < iLinkArray.Count() ; i++ ) |
|
553 { |
|
554 delete iLinkArray[i]->link; |
|
555 } |
|
556 |
|
557 iLinkArray.ResetAndDestroy(); |
|
558 iLinkCount = 0; |
|
559 |
|
560 TInt size = 0; |
|
561 TInt result = KErrNone; |
|
562 |
|
563 if ( aRamFile.Size( size ) == KErrNone && size <= KMaxLinkFileSize ) |
|
564 { |
|
565 HBufC8* buffer = HBufC8::NewLC( size ); |
|
566 TPtr8 ptr = buffer->Des(); |
|
567 TInt ret = KErrNone; |
|
568 |
|
569 // read file to buffer |
|
570 User::LeaveIfError( aRamFile.Read( ptr ) ); |
|
571 iBufferPtr.Set( ptr ); |
|
572 |
|
573 CMediaRecognizer* recognizer = CMediaRecognizer::NewL(); |
|
574 CleanupStack::PushL( recognizer ); |
|
575 |
|
576 // Get links from buffer |
|
577 while ( ret == KErrNone ) |
|
578 { |
|
579 // Create a linkitem ptr |
|
580 LinkStruct* linkItem = new( ELeave ) LinkStruct; |
|
581 CleanupStack::PushL( linkItem ); |
|
582 |
|
583 linkItem->seek = ETrue; |
|
584 |
|
585 linkItem->link = HBufC::NewLC( buffer->Length() ); |
|
586 TPtr ptr2 = linkItem->link->Des(); |
|
587 ret = ReadNextLine( ptr2 ); |
|
588 |
|
589 if ( aEnableFiltering ) |
|
590 { |
|
591 // check if line is link or not |
|
592 if ( recognizer->IsValidUrlPrefix( ptr2 ) ) |
|
593 { |
|
594 ptr2.TrimRight(); |
|
595 iLinkArray.Append( linkItem ); |
|
596 } |
|
597 } |
|
598 else |
|
599 { |
|
600 iLinkArray.Append( linkItem ); |
|
601 } |
|
602 |
|
603 CleanupStack::Pop(2); // pop the linkItem and the HbufC created for linkItem->link |
|
604 } |
|
605 |
|
606 CleanupStack::PopAndDestroy(2); // buffer, recognizer |
|
607 |
|
608 if ( iLinkArray.Count() == 0 ) |
|
609 { |
|
610 result = KErrNotFound; |
|
611 } |
|
612 } |
|
613 else |
|
614 { |
|
615 result = KErrNotSupported; |
|
616 } |
|
617 |
|
618 return result; |
|
619 } |
|
620 |
|
621 // ----------------------------------------------------------------------------- |
|
622 // CStreamingLinkModel::PopulateAsxLinksL |
|
623 // ----------------------------------------------------------------------------- |
|
624 // |
|
625 TInt CStreamingLinkModel::PopulateAsxLinksL( CAsxParser* aAsxParser, |
|
626 TBool aEnableFiltering ) |
|
627 { |
|
628 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::PopulateAsxLinksL()")); |
|
629 |
|
630 for ( TInt i = 0 ; i < iLinkArray.Count() ; i++ ) |
|
631 { |
|
632 delete iLinkArray[i]->link; |
|
633 } |
|
634 |
|
635 iLinkArray.ResetAndDestroy(); |
|
636 iLinkCount = 0; |
|
637 |
|
638 TInt ret = KErrNone; |
|
639 |
|
640 if ( aAsxParser ) |
|
641 { |
|
642 TUint urlCount = 0; |
|
643 AsxStruct* asxItem; |
|
644 |
|
645 aAsxParser->GetUrlCount( urlCount ); |
|
646 if ( urlCount ) |
|
647 { |
|
648 CMediaRecognizer* recognizer = CMediaRecognizer::NewL(); |
|
649 CleanupStack::PushL( recognizer ); |
|
650 |
|
651 for (TInt i=1; i <= urlCount; i++) |
|
652 { |
|
653 // Get the asx struct from the parser |
|
654 asxItem = aAsxParser->GetUrl(i); |
|
655 // Set the url to the bufferptr |
|
656 iBufferPtr.Set(asxItem->url->Des()); |
|
657 |
|
658 // Create a linkitem ptr |
|
659 LinkStruct* linkItem = new( ELeave ) LinkStruct; |
|
660 // push onto the cleanup stack |
|
661 CleanupStack::PushL( linkItem ); |
|
662 |
|
663 // Allocate heap mem for the link |
|
664 linkItem->link = HBufC::NewLC( asxItem->url->Length() ); |
|
665 //Get the ptr to the link |
|
666 TPtr ptr2 = linkItem->link->Des(); |
|
667 // read the asx url into the link ptr |
|
668 ReadNextLine( ptr2 ); |
|
669 |
|
670 // Get the additional attibutes from the asx item |
|
671 linkItem->seek = asxItem->seek; |
|
672 |
|
673 if ( aEnableFiltering ) |
|
674 { |
|
675 // check if line is link or not |
|
676 if ( recognizer->IsValidUrlPrefix( ptr2 ) ) |
|
677 { |
|
678 ptr2.TrimRight(); |
|
679 iLinkArray.Append( linkItem ); |
|
680 } |
|
681 } |
|
682 else |
|
683 { |
|
684 iLinkArray.Append( linkItem ); |
|
685 } |
|
686 |
|
687 CleanupStack::Pop(2); // pop the linkItem and the HbufC created for linkItem->link |
|
688 |
|
689 } |
|
690 |
|
691 CleanupStack::PopAndDestroy(); //recognizer |
|
692 } |
|
693 else |
|
694 { |
|
695 ret = KErrNotFound; |
|
696 } |
|
697 |
|
698 if ( iLinkArray.Count() == 0 ) |
|
699 { |
|
700 ret = KErrNotFound; |
|
701 } |
|
702 } |
|
703 else |
|
704 { |
|
705 ret = KErrNotSupported; |
|
706 } |
|
707 |
|
708 return ret; |
|
709 } |
|
710 |
|
711 // ------------------------------------------------------------------------------------------------- |
|
712 // CStreamingLinkModel::AreAllLinksLocal |
|
713 // returns true if all the links are local |
|
714 // ------------------------------------------------------------------------------------------------- |
|
715 // |
|
716 EXPORT_C TBool CStreamingLinkModel::AreAllLinksLocal() |
|
717 { |
|
718 PLAYBACKHELPER_DEBUG(_L("CStreamingLinkModel::AreAllLinksLocal()") ); |
|
719 |
|
720 TBool ret = ETrue; |
|
721 |
|
722 if ( iLinkArray.Count() ) |
|
723 { |
|
724 for ( TInt linkCount = 0 ; linkCount < iLinkArray.Count() ; linkCount++ ) |
|
725 { |
|
726 TPtr aLink = ( iLinkArray[linkCount]->link )->Des(); |
|
727 |
|
728 if ( aLink.Left( KLocalFileIdLength ).CompareF( KLocalFileId ) ) |
|
729 { |
|
730 ret = EFalse; |
|
731 break; |
|
732 } |
|
733 } |
|
734 } |
|
735 |
|
736 return ret; |
|
737 } |
|
738 |
|
739 // End of File |