|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Plugin for Multi-Media information search. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //SYSTEM INCLUDES |
|
21 #include <e32cmn.h> |
|
22 #include <e32def.h> |
|
23 #include<barsc.h> |
|
24 #include <e32des8.h> |
|
25 #include <cntdef.h> |
|
26 #include <e32std.h> |
|
27 #include <e32base.h> |
|
28 #include <bautils.h> |
|
29 #include <utf.h> |
|
30 #include <searchcondition.h> |
|
31 #include <searchtextsearcher.h> |
|
32 #include <searchdocumentid.h> |
|
33 #include <searchlightresult.h> |
|
34 #include <searchresult.h> |
|
35 #include <searchcommon.h> |
|
36 #include <ContentListingFactory.h> |
|
37 #include <MCLFItem.h> |
|
38 #include <CLFContentListing.hrh> |
|
39 #include <searchpluginobserver.h> |
|
40 #include <data_caging_path_literals.hrh> |
|
41 |
|
42 //USER INCLUDES |
|
43 #include "multimediasearchresource.rsg" |
|
44 #include "multimediasearcher.h" |
|
45 #include "multimediasearchplugindefines.h" |
|
46 |
|
47 |
|
48 //Constants |
|
49 _LIT( KKiloBytes, " KB" ); |
|
50 _LIT( KBytes, " B" ); |
|
51 |
|
52 // --------------------------------------------------------------------------------- |
|
53 // 1st phase constructor |
|
54 // --------------------------------------------------------------------------------- |
|
55 // |
|
56 CMultimediaSearcher* CMultimediaSearcher::NewL( const RArray<TUid>& aContentIdArray, |
|
57 const CSearchCondition& aCondition, |
|
58 const TUid& aPluginId, |
|
59 MSearchPluginObserver& aObserver ) |
|
60 { |
|
61 CMultimediaSearcher* self = new ( ELeave ) CMultimediaSearcher( aPluginId ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aContentIdArray, aCondition ,aObserver); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------------- |
|
70 // Destructor |
|
71 // --------------------------------------------------------------------------------- |
|
72 // |
|
73 CMultimediaSearcher::~CMultimediaSearcher() |
|
74 { |
|
75 |
|
76 ifSession.Close(); |
|
77 CleanUp(); |
|
78 |
|
79 if(iHeavyResultsArray.Count()) |
|
80 { |
|
81 iHeavyResultsArray.ResetAndDestroy(); |
|
82 } |
|
83 |
|
84 if(iCompleteFilePathArray.Count()) |
|
85 { |
|
86 iCompleteFilePathArray.ResetAndDestroy(); |
|
87 } |
|
88 if( iTextSearcher ) |
|
89 { |
|
90 delete iTextSearcher; |
|
91 iTextSearcher = NULL; |
|
92 } |
|
93 |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // Sets the value of iCurrentContentClassUid |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void CMultimediaSearcher::SetContentClassUid(const TUid aSearchClassUid) |
|
101 { |
|
102 |
|
103 iCurrentContentClassUid.iUid = aSearchClassUid.iUid; |
|
104 |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Sets the value of iCurrentContentClassUid |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CMultimediaSearcher::SetMediaType(TCLFMediaType aMediaType) |
|
112 { |
|
113 |
|
114 iCurrentMediaTypeToBeUsed = aMediaType; |
|
115 |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // Gets the complete file path of the item in the iCompleteFilePathArray |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 HBufC* CMultimediaSearcher::GetFilePathArrayIndexValue(TInt aIndex) |
|
123 { |
|
124 return iCompleteFilePathArray[aIndex] ; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------------- |
|
128 // should be called before deleting this object |
|
129 // --------------------------------------------------------------------------------- |
|
130 // |
|
131 void CMultimediaSearcher::Destroy() |
|
132 { |
|
133 |
|
134 if(IsActive()) |
|
135 { |
|
136 CActive::Cancel(); |
|
137 } |
|
138 else |
|
139 { |
|
140 CleanUp(); |
|
141 } |
|
142 |
|
143 |
|
144 if(iHeavyResultsArray.Count()) |
|
145 { |
|
146 iHeavyResultsArray.ResetAndDestroy(); |
|
147 } |
|
148 |
|
149 |
|
150 if(iCompleteFilePathArray.Count()) |
|
151 { |
|
152 iCompleteFilePathArray.ResetAndDestroy(); |
|
153 } |
|
154 delete this; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------------- |
|
158 // Starts the search |
|
159 // --------------------------------------------------------------------------------- |
|
160 // |
|
161 void CMultimediaSearcher::SearchL( void ) |
|
162 { |
|
163 |
|
164 //Reset all the flags |
|
165 iCancelSearch = EFalse; |
|
166 iAllMultimediaFilesSearched = EFalse; |
|
167 iRefreshStarted = EFalse; |
|
168 iRefreshDone = EFalse; |
|
169 |
|
170 if( 0 < iHeavyResultsArray.Count() ) |
|
171 iHeavyResultsArray.ResetAndDestroy(); |
|
172 |
|
173 |
|
174 |
|
175 if( 0 < iCompleteFilePathArray.Count() ) |
|
176 iCompleteFilePathArray.Reset(); |
|
177 |
|
178 |
|
179 // Create the content listing framework engine |
|
180 iCLFengine = ContentListingFactory::NewContentListingEngineLC(); |
|
181 CleanupStack::Pop(); |
|
182 iCLFmodel = iCLFengine->CreateListModelLC( *this ); |
|
183 CleanupStack::Pop(); |
|
184 |
|
185 |
|
186 //Create the WantedMediaTypes array and set it to CLF Engine |
|
187 RArray<TInt> array; |
|
188 CleanupClosePushL( array ); |
|
189 array.AppendL( iCurrentMediaTypeToBeUsed ); |
|
190 iCLFmodel->SetWantedMediaTypesL( array.Array() ); |
|
191 |
|
192 CleanupStack::PopAndDestroy( &array ); |
|
193 //Create the MimeTypeArray array and set it to CLF Engine |
|
194 |
|
195 if ( iMimeTypeArray ) |
|
196 { |
|
197 iMimeTypeArray->Reset(); |
|
198 delete iMimeTypeArray; |
|
199 iMimeTypeArray = NULL; |
|
200 } |
|
201 iMimeTypeArray = new (ELeave) CDesCArrayFlat(KArrayLength ); |
|
202 iMimeTypeArray->AppendL( KAllMimeTypeMatchString ); |
|
203 iCLFmodel->SetWantedMimeTypesL( *iMimeTypeArray ); |
|
204 |
|
205 |
|
206 TRequestStatus* status = &iStatus; |
|
207 User::RequestComplete( status, KErrNone ); |
|
208 SetActive(); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------------- |
|
212 // Returns TRUE if search is in progress |
|
213 // --------------------------------------------------------------------------------- |
|
214 TBool CMultimediaSearcher::IsSearching() |
|
215 { |
|
216 return IsActive(); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------------- |
|
220 // Cancels the search |
|
221 // --------------------------------------------------------------------------------- |
|
222 // |
|
223 void CMultimediaSearcher::CancelSearch() |
|
224 { |
|
225 iCancelSearch = ETrue; |
|
226 |
|
227 // If the iCLFmodel refresh has started and not complete yet, |
|
228 // then cancel the refresh |
|
229 if(iRefreshStarted && !iRefreshDone) |
|
230 { |
|
231 iCLFmodel->CancelRefresh(); |
|
232 } |
|
233 CActive::Cancel(); |
|
234 CleanUp(); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------------- |
|
238 // Gets the results |
|
239 // --------------------------------------------------------------------------------- |
|
240 // |
|
241 void CMultimediaSearcher::GetResultsL( |
|
242 const RPointerArray<CSearchDocumentId>& aDocumentIdArray ) |
|
243 { |
|
244 |
|
245 // Check the aDocumentIdArray |
|
246 // For all the matching documentIds, fetch the corresponding |
|
247 // Heavy Result from iHeavyResultsArray and append it to heavyResultResponse |
|
248 RPointerArray<CSearchResult> heavyResultResponse; |
|
249 for( TInt j = 0; j < aDocumentIdArray.Count(); j++ ) |
|
250 { |
|
251 |
|
252 if (( aDocumentIdArray[j]->PluginId() == iPluginId ) && |
|
253 (iCurrentContentClassUid.iUid == aDocumentIdArray[j]->RepositoryId()) |
|
254 ) |
|
255 { |
|
256 TInt myArrayIndex = aDocumentIdArray[j]->DocumentId(); |
|
257 heavyResultResponse.AppendL(iHeavyResultsArray[myArrayIndex]); |
|
258 } |
|
259 } |
|
260 |
|
261 // Results retrival complete |
|
262 iObserver->ResultsRetrieveCompleteL( heavyResultResponse ); |
|
263 heavyResultResponse.Reset(); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------------- |
|
267 // Cancels the result retrieval |
|
268 // --------------------------------------------------------------------------------- |
|
269 // |
|
270 void CMultimediaSearcher::CancelResultsRetrieve() |
|
271 { |
|
272 |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------------- |
|
276 // Returns the search progress |
|
277 // --------------------------------------------------------------------------------- |
|
278 // |
|
279 void CMultimediaSearcher::GetSearchProgressL( TUid& /*aContentClassId*/, |
|
280 TInt& /*aCurrentDocument*/, |
|
281 TInt& /*aTotalDocuments*/ ) |
|
282 { |
|
283 |
|
284 } |
|
285 |
|
286 |
|
287 // --------------------------------------------------------------------------------- |
|
288 // Called when a result is found matching the search criteria |
|
289 // --------------------------------------------------------------------------------- |
|
290 // |
|
291 void CMultimediaSearcher::HitL( TInt /*aResult*/ ) |
|
292 { |
|
293 |
|
294 |
|
295 CSearchDocumentId* searchDocId = NULL; |
|
296 |
|
297 TBuf8<KBufferLength> tempDes; |
|
298 |
|
299 searchDocId = CSearchDocumentId::NewL( iTotalHits,iPluginId ); |
|
300 |
|
301 searchDocId->SetRepositoryIdL( iCurrentContentClassUid.iUid ); |
|
302 |
|
303 // Set the repository id |
|
304 searchDocId->SetRepositoryIdL( iCurrentContentClassUid.iUid ); |
|
305 |
|
306 |
|
307 CSearchLightResult* searchLightResult = CSearchLightResult::NewL( searchDocId ); |
|
308 searchLightResult->SetContentClassId( iCurrentContentClassUid ); |
|
309 searchLightResult->SetServiceId( KNullUid ); |
|
310 |
|
311 // Append iCompletefilePath to the iCompleteFilePathArray. |
|
312 // This is needed for launching the specific media item. |
|
313 if( iCompletefilePath ) |
|
314 { |
|
315 HBufC* string1 = iCompletefilePath->Des().AllocL(); |
|
316 iCompleteFilePathArray.AppendL(string1); |
|
317 } |
|
318 |
|
319 TParse fileParse; |
|
320 fileParse.Set( iCompletefilePath->Des(), NULL, NULL ); |
|
321 TPtrC driveLetter = fileParse.Drive(); |
|
322 _LIT(KMemoryCard, "E:"); |
|
323 //If found at 0th position file is in mem card |
|
324 if ( 0 == driveLetter.Find( KMemoryCard ) ) |
|
325 { |
|
326 searchLightResult->SetSubContentId( KSearchCSubContentMMCUid.iUid ); |
|
327 } |
|
328 // Form the heavy result and append it to the iHeavyResultsArray |
|
329 CSearchResult* tmpHeavyRes = NULL; |
|
330 tmpHeavyRes = CSearchResult::NewL(searchLightResult); |
|
331 |
|
332 //Set the title of the result |
|
333 if ( iCurrentTitle ) |
|
334 { |
|
335 tmpHeavyRes->SetTitleL( *iCurrentTitle ); |
|
336 delete iCurrentTitle; iCurrentTitle = NULL; |
|
337 } |
|
338 else |
|
339 { |
|
340 // The title is not set. Set it to null string |
|
341 TPtr ptr( iCurrentTitle->Des() ); |
|
342 ptr.Append( KNullDesC ); |
|
343 tmpHeavyRes->SetTitleL( *iCurrentTitle ); |
|
344 delete iCurrentTitle; iCurrentTitle = NULL; |
|
345 } |
|
346 |
|
347 //Set the snippet |
|
348 if ( iCurrentSnippet ) |
|
349 { |
|
350 tmpHeavyRes->SetSnippetL(*iCurrentSnippet); |
|
351 delete iCurrentSnippet;iCurrentSnippet = NULL; |
|
352 } |
|
353 else |
|
354 { |
|
355 // The Snippet is not set. Set it to null string |
|
356 iCurrentSnippet =HBufC8::NewL(KSpace().Length()); |
|
357 iCurrentSnippet->Des().Append( KSpace ); |
|
358 tmpHeavyRes->SetSnippetL(*iCurrentSnippet); |
|
359 delete iCurrentSnippet;iCurrentSnippet = NULL; |
|
360 } |
|
361 |
|
362 //Set the SetSnippetFormatL |
|
363 HBufC8 *snippetFormat = HBufC8::NewL( KBufferLength ) ; |
|
364 snippetFormat->Des().Append(KSpace); |
|
365 tmpHeavyRes->SetSnippetFormatL( snippetFormat->Des() ); |
|
366 delete snippetFormat; |
|
367 snippetFormat = NULL; |
|
368 |
|
369 |
|
370 iHeavyResultsArray.AppendL(tmpHeavyRes); |
|
371 //Delete the iDataToSearch, since already searched |
|
372 if ( iDataToSearch ) |
|
373 { |
|
374 delete iDataToSearch; |
|
375 iDataToSearch = NULL; |
|
376 |
|
377 } |
|
378 |
|
379 |
|
380 // Increment the iTotalHits and call ResultFoundL() |
|
381 iTotalHits++; |
|
382 iObserver->ResultFoundL( searchLightResult, iTotalHits, iTotalNumOfItemsSearched ); |
|
383 |
|
384 } |
|
385 |
|
386 |
|
387 HBufC8* CMultimediaSearcher::LaunchInfoL( const CSearchDocumentId& aDocumentID ) |
|
388 { |
|
389 if((aDocumentID.PluginId() == iPluginId) && |
|
390 (aDocumentID.RepositoryId() == iCurrentContentClassUid.iUid)) |
|
391 { |
|
392 |
|
393 TInt myArrayIndex = aDocumentID.DocumentId(); |
|
394 TBuf8<KBufferLength> tempDes; |
|
395 HBufC8* launchData = HBufC8::NewL( KBufferLength ) ; |
|
396 |
|
397 |
|
398 |
|
399 CnvUtfConverter::ConvertFromUnicodeToUtf8( tempDes,*iCompleteFilePathArray[myArrayIndex] ); |
|
400 launchData->Des().Append(tempDes); |
|
401 return launchData; |
|
402 } |
|
403 |
|
404 return NULL; |
|
405 |
|
406 |
|
407 } |
|
408 |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // Callback method of MCLFOperationObserver for refresh . |
|
412 // Called when the refersh operation is complete |
|
413 // --------------------------------------------------------------------------- |
|
414 // |
|
415 void CMultimediaSearcher::HandleOperationEventL( TCLFOperationEvent aOperationEvent, |
|
416 TInt /*aError*/ ) |
|
417 { |
|
418 if( aOperationEvent == ECLFRefreshComplete ) |
|
419 { |
|
420 // The refresh is complete, so set the iRefreshDone flag to true |
|
421 iRefreshDone = ETrue; |
|
422 } |
|
423 TRequestStatus* status = &iStatus; |
|
424 User::RequestComplete( status, KErrNone ); |
|
425 SetActive(); |
|
426 } |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 // --------------------------------------------------------------------------------- |
|
432 // Implements cancellation of an outstanding request. |
|
433 // --------------------------------------------------------------------------------- |
|
434 // |
|
435 void CMultimediaSearcher::DoCancel() |
|
436 { |
|
437 iCancelSearch = ETrue; |
|
438 CleanUp(); |
|
439 |
|
440 } |
|
441 |
|
442 |
|
443 // --------------------------------------------------------------------------------- |
|
444 // The function is called by the active scheduler |
|
445 // --------------------------------------------------------------------------------- |
|
446 // |
|
447 void CMultimediaSearcher::RunL() |
|
448 { |
|
449 if( !DoActualSearchL() ) |
|
450 { |
|
451 |
|
452 ReportFinishedL(); |
|
453 |
|
454 } |
|
455 |
|
456 } |
|
457 |
|
458 // --------------------------------------------------------------------------------- |
|
459 // Called if there are any leaves in the RunL() |
|
460 // --------------------------------------------------------------------------------- |
|
461 // |
|
462 TInt CMultimediaSearcher::RunError(TInt /*aError*/) |
|
463 { |
|
464 return KErrNone; |
|
465 } |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 // --------------------------------------------------------------------------------- |
|
473 // Constructor |
|
474 // --------------------------------------------------------------------------------- |
|
475 // |
|
476 CMultimediaSearcher::CMultimediaSearcher( const TUid& aPluginId ) : |
|
477 CActive( CActive::EPriorityStandard ), |
|
478 iPluginId( aPluginId ), |
|
479 iTotalNumOfItemsSearched(0), |
|
480 iTotalHits(0), |
|
481 iAllMultimediaFilesSearched(EFalse), |
|
482 iSearchAlreadyStarted(EFalse), |
|
483 iRefreshStarted (EFalse), |
|
484 iRefreshDone(EFalse) |
|
485 { |
|
486 CActiveScheduler::Add( this ); |
|
487 } |
|
488 // --------------------------------------------------------------------------------- |
|
489 // CMultimediaSearcher::ConstructL() |
|
490 // 2nd phase constructor |
|
491 // --------------------------------------------------------------------------------- |
|
492 // |
|
493 void CMultimediaSearcher::ConstructL( const RArray<TUid>& /*aContentIdArray*/, |
|
494 const CSearchCondition& aCondition,MSearchPluginObserver& aObserver ) |
|
495 { |
|
496 iObserver = &aObserver; |
|
497 User::LeaveIfError( ifSession.Connect() ); |
|
498 SetPriority( EPriorityStandard ); |
|
499 //Create the text searcher and set the parameters |
|
500 iTextSearcher = CSearchTextSearcher::NewL( *this ); |
|
501 iTextSearcher->SetParametersL( aCondition ); |
|
502 |
|
503 } |
|
504 |
|
505 // --------------------------------------------------------------------------------- |
|
506 // Called when search is finished |
|
507 // --------------------------------------------------------------------------------- |
|
508 // |
|
509 void CMultimediaSearcher::ReportFinishedL() |
|
510 { |
|
511 iObserver->SearchCompletedL( iTotalHits, iTotalNumOfItemsSearched ); |
|
512 |
|
513 } |
|
514 |
|
515 // --------------------------------------------------------------------------------- |
|
516 // Will be called when the CActive::Cancel() is called.. by DoCancel() |
|
517 // --------------------------------------------------------------------------------- |
|
518 // |
|
519 void CMultimediaSearcher::CleanUp() |
|
520 { |
|
521 //Clean up the resources |
|
522 |
|
523 if(iCLFmodel) |
|
524 { |
|
525 delete iCLFmodel; |
|
526 iCLFmodel = NULL; |
|
527 } |
|
528 if ( iCLFengine ) |
|
529 { |
|
530 delete iCLFengine; |
|
531 iCLFengine = NULL; |
|
532 } |
|
533 |
|
534 if ( iMimeTypeArray ) |
|
535 { |
|
536 iMimeTypeArray->Reset(); |
|
537 delete iMimeTypeArray; |
|
538 iMimeTypeArray = NULL; |
|
539 } |
|
540 |
|
541 if ( iCurrentTitle ) |
|
542 { |
|
543 delete iCurrentTitle; |
|
544 iCurrentTitle = NULL; |
|
545 } |
|
546 |
|
547 if ( iCurrentSnippet ) |
|
548 { |
|
549 delete iCurrentSnippet; |
|
550 iCurrentSnippet = NULL; |
|
551 } |
|
552 |
|
553 if ( iCompletefilePath ) |
|
554 { |
|
555 delete iCompletefilePath; |
|
556 iCompletefilePath = NULL; |
|
557 } |
|
558 |
|
559 if ( iDataToSearch ) |
|
560 { |
|
561 delete iDataToSearch; |
|
562 iDataToSearch = NULL; |
|
563 } |
|
564 |
|
565 if(iSizeBytes) |
|
566 { |
|
567 delete iSizeBytes; |
|
568 iSizeBytes = NULL; |
|
569 } |
|
570 |
|
571 if(iSizeKiloBytes ) |
|
572 { |
|
573 |
|
574 delete iSizeKiloBytes; |
|
575 iSizeKiloBytes = NULL; |
|
576 |
|
577 } |
|
578 |
|
579 |
|
580 } |
|
581 |
|
582 // --------------------------------------------------------------------------------- |
|
583 // Does the search for the file. Called from RunL. |
|
584 // Return: ETrue: if more note items need to be searched. |
|
585 // EFalse: otherwise. |
|
586 // --------------------------------------------------------------------------------- |
|
587 // |
|
588 TBool CMultimediaSearcher::DoActualSearchL() |
|
589 { |
|
590 if(iCancelSearch) |
|
591 { |
|
592 //If the search has been cancelled, return EFalse |
|
593 return EFalse; |
|
594 } |
|
595 |
|
596 |
|
597 if (iAllMultimediaFilesSearched) |
|
598 { |
|
599 // If all the files have been serched, then return EFalse |
|
600 return EFalse; |
|
601 } |
|
602 |
|
603 // If Refresh not yet done, then do it |
|
604 if(!iRefreshStarted) |
|
605 { |
|
606 |
|
607 iRefreshStarted = ETrue; |
|
608 iCLFmodel->RefreshL(); |
|
609 } |
|
610 if(iRefreshDone) |
|
611 { |
|
612 // IF refresh done, then start the search |
|
613 |
|
614 if(!iSearchAlreadyStarted) |
|
615 { |
|
616 //Start searching if already not started |
|
617 iSearchAlreadyStarted = ETrue; |
|
618 SearchMediaL(); |
|
619 } |
|
620 |
|
621 } |
|
622 |
|
623 return ETrue; |
|
624 |
|
625 |
|
626 } |
|
627 |
|
628 // --------------------------------------------------------------------------- |
|
629 // Search Media (Images, Videos. Music) from the list of multimedia items |
|
630 // --------------------------------------------------------------------------- |
|
631 // |
|
632 |
|
633 void CMultimediaSearcher::SearchMediaL(void) |
|
634 { |
|
635 |
|
636 TInt count( iCLFmodel->ItemCount() ); |
|
637 TBool ret = EFalse; |
|
638 for( TInt i( 0 ); i < count; ++i ) |
|
639 { |
|
640 if(iCancelSearch) |
|
641 { |
|
642 return; |
|
643 } |
|
644 const MCLFItem& myItem = iCLFmodel->Item( i ); |
|
645 TInt32 mediaType( 0 ); |
|
646 if( myItem.GetField( ECLFFieldIdMediaType, mediaType ) == KErrNone ) |
|
647 { |
|
648 // If media type is not same as current, |
|
649 // then continue with the next item |
|
650 if( iCurrentMediaTypeToBeUsed != mediaType) |
|
651 { |
|
652 continue; |
|
653 } |
|
654 } |
|
655 |
|
656 // Get the data for music, video , images |
|
657 // depending on the media type |
|
658 ret = EFalse; |
|
659 if(ECLFMediaTypeMusic ==mediaType) |
|
660 { |
|
661 // Music |
|
662 ret = FetchSearchDataForMusicL(myItem); |
|
663 } |
|
664 else if (ECLFMediaTypeImage == mediaType) |
|
665 { |
|
666 //Images |
|
667 ret = FetchSearchDataForImagesL(myItem); |
|
668 } |
|
669 |
|
670 else if(ECLFMediaTypeVideo ==mediaType) |
|
671 { |
|
672 //Videos |
|
673 ret = FetchSearchDataForVideosL(myItem); |
|
674 } |
|
675 |
|
676 |
|
677 // Send the data for searching only if the |
|
678 // return value is ETrue(i.e valid multimedia item) |
|
679 if(ret) |
|
680 { |
|
681 iTextSearcher->SearchL( *iDataToSearch ); |
|
682 } |
|
683 |
|
684 } |
|
685 |
|
686 // All data searched, set the iAllMultimediaFilesSearched flag and complete the request |
|
687 iAllMultimediaFilesSearched = ETrue; |
|
688 TRequestStatus* status = &iStatus; |
|
689 User::RequestComplete( status, KErrNone ); |
|
690 SetActive(); |
|
691 } |
|
692 |
|
693 |
|
694 // --------------------------------------------------------------------------- |
|
695 // Creates Search Data for Videos for one Media Gallery item |
|
696 // --------------------------------------------------------------------------- |
|
697 // |
|
698 TBool CMultimediaSearcher::FetchSearchDataForVideosL(const MCLFItem& aItem) |
|
699 { |
|
700 //Get the file name of the Images item. |
|
701 TPtrC fileName; |
|
702 TInt error( aItem.GetField( ECLFFieldIdFileName, fileName ) ); |
|
703 |
|
704 if(fileName.Length()) |
|
705 { |
|
706 // The file exists, get the complete path of the file |
|
707 iTotalNumOfItemsSearched++; |
|
708 delete iCompletefilePath; |
|
709 iCompletefilePath = NULL; |
|
710 TPtrC filePath; |
|
711 TInt error( aItem.GetField( ECLFFieldIdFileNameAndPath, filePath ) ); |
|
712 iCompletefilePath = HBufC::NewL(filePath.Length()); |
|
713 TPtr ptr( iCompletefilePath->Des() ); |
|
714 ptr.Append(filePath); |
|
715 } |
|
716 else |
|
717 { |
|
718 //The file name length is <= 0. So return false |
|
719 return EFalse; |
|
720 } |
|
721 delete iDataToSearch; |
|
722 iDataToSearch = NULL; |
|
723 iDataToSearch = HBufC::NewL( fileName.Length()); |
|
724 TPtr ptr1( iDataToSearch->Des() ); |
|
725 ptr1.Append(fileName); |
|
726 |
|
727 //set the title |
|
728 delete iCurrentTitle;iCurrentTitle = NULL; |
|
729 iCurrentTitle =HBufC::NewL(fileName.Length()); |
|
730 iCurrentTitle->Des().Append( fileName ); |
|
731 |
|
732 //Set the Snippet |
|
733 delete iCurrentSnippet;iCurrentSnippet = NULL; |
|
734 if(fileName.Length()) |
|
735 { |
|
736 //Get the file size, to be set for the snippet |
|
737 TInt32 fileSize ; |
|
738 aItem.GetField( ECLFFieldIdFileSize,fileSize); |
|
739 iCurrentSnippet =HBufC8::NewL(KBufferLength); |
|
740 |
|
741 if( fileSize / KKiloByteDivisor ) |
|
742 { |
|
743 // If the filesize > 1024, then append "KB" (for kilobytes) |
|
744 iCurrentSnippet->Des().AppendNum( fileSize / KKiloByteDivisor ); |
|
745 iCurrentSnippet->Des().Append(KBytes); |
|
746 } |
|
747 else |
|
748 { |
|
749 // Filesize < 1024, so just append "B" (for bytes) |
|
750 iCurrentSnippet->Des().AppendNum( fileSize ); |
|
751 iCurrentSnippet->Des().Append( KKiloBytes ); |
|
752 } |
|
753 |
|
754 } |
|
755 |
|
756 return ETrue; |
|
757 } |
|
758 |
|
759 // --------------------------------------------------------------------------- |
|
760 // Creates Search Data for Images for one Media Gallery item |
|
761 // --------------------------------------------------------------------------- |
|
762 // |
|
763 TBool CMultimediaSearcher::FetchSearchDataForImagesL(const MCLFItem& aItem) |
|
764 { |
|
765 //Get the file name of the Images item. |
|
766 TPtrC fileName; |
|
767 TInt error( aItem.GetField( ECLFFieldIdFileName, fileName ) ); |
|
768 if(fileName.Length()) |
|
769 { |
|
770 // The file exists, get the complete path of the file |
|
771 iTotalNumOfItemsSearched++; |
|
772 delete iCompletefilePath; |
|
773 iCompletefilePath = NULL; |
|
774 TPtrC filePath; |
|
775 TInt error( aItem.GetField( ECLFFieldIdFileNameAndPath, filePath ) ); |
|
776 iCompletefilePath = HBufC::NewL(filePath.Length()); |
|
777 TPtr ptr( iCompletefilePath->Des() ); |
|
778 ptr.Append(filePath); |
|
779 } |
|
780 else |
|
781 { |
|
782 //The file name length is <= 0. So return false |
|
783 return EFalse; |
|
784 } |
|
785 |
|
786 delete iDataToSearch; |
|
787 iDataToSearch = NULL; |
|
788 iDataToSearch = HBufC::NewL( fileName.Length()); |
|
789 TPtr ptr( iDataToSearch->Des() ); |
|
790 if(fileName.Length()) ptr.Append(fileName); |
|
791 |
|
792 //Set the title |
|
793 delete iCurrentTitle;iCurrentTitle = NULL; |
|
794 iCurrentTitle =HBufC::NewL(fileName.Length()); |
|
795 iCurrentTitle->Des().Append( fileName ); |
|
796 |
|
797 //Set the Snippet |
|
798 delete iCurrentSnippet;iCurrentSnippet = NULL; |
|
799 if(fileName.Length()) |
|
800 { |
|
801 TInt32 fileSize ; |
|
802 //Get the file size, to be set for the snippet |
|
803 aItem.GetField( ECLFFieldIdFileSize,fileSize); |
|
804 iCurrentSnippet =HBufC8::NewL(KBufferLength); |
|
805 |
|
806 if( fileSize / KKiloByteDivisor ) |
|
807 { |
|
808 // If the filesize > 1024, then append "KB" (for kilobytes) |
|
809 iCurrentSnippet->Des().AppendNum( fileSize / KKiloByteDivisor ); |
|
810 iCurrentSnippet->Des().Append( KBytes ); |
|
811 } |
|
812 else |
|
813 { |
|
814 // Filesize < 1024, so just append "B" (for bytes) |
|
815 iCurrentSnippet->Des().AppendNum( fileSize ); |
|
816 iCurrentSnippet->Des().Append( KKiloBytes ); |
|
817 |
|
818 } |
|
819 |
|
820 |
|
821 } |
|
822 |
|
823 return ETrue; |
|
824 } |
|
825 |
|
826 |
|
827 // --------------------------------------------------------------------------- |
|
828 // Creates Search Data for Music for one Media Gallery item |
|
829 // --------------------------------------------------------------------------- |
|
830 // |
|
831 TBool CMultimediaSearcher::FetchSearchDataForMusicL(const MCLFItem& aItem) |
|
832 { |
|
833 //Get the file name of the music item. |
|
834 TPtrC fileName; |
|
835 TInt error( aItem.GetField( ECLFFieldIdFileName, fileName ) ); |
|
836 delete iDataToSearch; |
|
837 iDataToSearch = NULL; |
|
838 iDataToSearch = HBufC::NewL(fileName.Length()); |
|
839 |
|
840 if(fileName.Length()) |
|
841 { |
|
842 // The file exists, get the complete path of the file |
|
843 iTotalNumOfItemsSearched++; |
|
844 delete iCompletefilePath; |
|
845 iCompletefilePath = NULL; |
|
846 TPtrC filePath; |
|
847 TInt error( aItem.GetField( ECLFFieldIdFileNameAndPath, filePath ) ); |
|
848 iCompletefilePath = HBufC::NewL(filePath.Length()); |
|
849 TPtr ptr( iCompletefilePath->Des() ); |
|
850 ptr.Append(filePath); |
|
851 } |
|
852 else |
|
853 { |
|
854 //The file name length is <= 0. So return false |
|
855 return EFalse; |
|
856 } |
|
857 //Get the other fileds of the music item. |
|
858 // (songname,artistname,album name, genrename, composername) |
|
859 TPtrC songName, artistName,albumName,genreName,composerName; |
|
860 aItem.GetField( ECLFFieldIdSongName, songName); |
|
861 aItem.GetField(ECLFFieldIdArtist,artistName); |
|
862 aItem.GetField(ECLFFieldIdAlbum,albumName); |
|
863 aItem.GetField(ECLFFieldIdGenre,genreName); |
|
864 aItem.GetField(ECLFFieldIdComposer,composerName); |
|
865 |
|
866 // Create the iDataToSearch buffer big enough to hold the |
|
867 // data ((songname,artistname,album name, genrename, composername), |
|
868 // all separated by spaces |
|
869 delete iDataToSearch; |
|
870 iDataToSearch = NULL; |
|
871 |
|
872 iDataToSearch = HBufC::NewL( fileName.Length() + KSpace().Length() + |
|
873 songName.Length() + KSpace().Length() + |
|
874 artistName.Length()+KSpace().Length() + |
|
875 albumName.Length()+KSpace().Length() + |
|
876 genreName.Length()+KSpace().Length() + |
|
877 composerName.Length() + KSpace().Length() |
|
878 ); |
|
879 // Append the data to the iDataToSearch |
|
880 TPtr ptr( iDataToSearch->Des() ); |
|
881 if(fileName.Length()) |
|
882 { |
|
883 ptr.Append(fileName); |
|
884 ptr.Append( KSpace ); |
|
885 } |
|
886 if(songName.Length()) |
|
887 { |
|
888 ptr.Append(songName); |
|
889 ptr.Append( KSpace ); |
|
890 } |
|
891 if(artistName.Length()) |
|
892 { |
|
893 ptr.Append(artistName); |
|
894 ptr.Append( KSpace ); |
|
895 } |
|
896 if(albumName.Length()) |
|
897 { |
|
898 ptr.Append(albumName); |
|
899 ptr.Append( KSpace ); |
|
900 } |
|
901 if(genreName.Length()) |
|
902 { |
|
903 ptr.Append(genreName); |
|
904 ptr.Append( KSpace ); |
|
905 } |
|
906 |
|
907 if(composerName.Length()) |
|
908 { |
|
909 ptr.Append(composerName); |
|
910 ptr.Append( KSpace ); |
|
911 } |
|
912 //Set the title |
|
913 delete iCurrentTitle;iCurrentTitle = NULL; |
|
914 if(artistName.Length()) |
|
915 { |
|
916 iCurrentTitle =HBufC::NewL(artistName.Length()); |
|
917 iCurrentTitle->Des().Append( artistName ); |
|
918 |
|
919 } |
|
920 else |
|
921 { |
|
922 // The artist name does not exits, set it to "Unknown Artist" |
|
923 _LIT( unnamed, "Unknown Artist" ); |
|
924 iCurrentTitle =HBufC::NewL(unnamed().Length()); |
|
925 iCurrentTitle->Des().Append( unnamed ); |
|
926 } |
|
927 |
|
928 //Set the Snippet |
|
929 delete iCurrentSnippet;iCurrentSnippet = NULL; |
|
930 if(songName.Length()) |
|
931 { |
|
932 iCurrentSnippet =HBufC8::NewL(songName.Length()); |
|
933 iCurrentSnippet->Des().Append( songName ); |
|
934 } |
|
935 else |
|
936 { |
|
937 // Songname does not exist, set the file name as the snippet |
|
938 iCurrentSnippet =HBufC8::NewL(fileName.Length()); |
|
939 iCurrentSnippet->Des().Append( fileName ); |
|
940 } |
|
941 |
|
942 return ETrue; |
|
943 |
|
944 } |
|
945 |
|
946 |
|
947 |
|
948 // End of file |