|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "audiofetcherfilehandler.h" |
|
21 #include "audiofetcherlog.h" |
|
22 |
|
23 #include <pathinfo.h> |
|
24 #include <bautils.h> |
|
25 |
|
26 |
|
27 /****************************************************************************** |
|
28 * class CAudioFetcherFileHandler |
|
29 ******************************************************************************/ |
|
30 |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CAudioFetcherFileHandler::NewL |
|
35 // |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CAudioFetcherFileHandler* CAudioFetcherFileHandler::NewL() |
|
39 { |
|
40 CAudioFetcherFileHandler* self = new (ELeave) CAudioFetcherFileHandler(); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop( self ); |
|
44 |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // Destructor |
|
51 // |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CAudioFetcherFileHandler::~CAudioFetcherFileHandler() |
|
55 { |
|
56 WLOG("CAudioFetcherFileHandler::~CAudioFetcherFileHandler >"); |
|
57 |
|
58 if ( iSearchList ) |
|
59 { |
|
60 iSearchList->Reset(); |
|
61 } |
|
62 delete iSearchList; |
|
63 delete iQueryCaller; |
|
64 delete iObjectNotificationCaller; |
|
65 |
|
66 delete iDriveUtil; |
|
67 WLOG("CAudioFetcherFileHandler::~CAudioFetcherFileHandler before iQuery"); |
|
68 if ( iQuery ) |
|
69 { |
|
70 iQuery->Cancel(); |
|
71 } |
|
72 delete iQuery; |
|
73 WLOG("CAudioFetcherFileHandler::~CAudioFetcherFileHandler after iQuery"); |
|
74 delete iSession; |
|
75 WLOG("CAudioFetcherFileHandler::~CAudioFetcherFileHandler <"); |
|
76 } |
|
77 |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CAudioFetcherFileHandler::CAudioFetcherFileHandler |
|
81 // |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CAudioFetcherFileHandler::CAudioFetcherFileHandler() |
|
85 { |
|
86 iSessionOpen = EFalse; |
|
87 iObserverCallEnabled = ETrue; |
|
88 |
|
89 iMaxFileSize = KErrNotFound; |
|
90 iQueryId = KErrNotFound; |
|
91 iQueryType = KErrNotFound; |
|
92 iQueryError = KErrNone; |
|
93 iQueryEvent = KErrNotFound; |
|
94 } |
|
95 |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CAudioFetcherFileHandler::ConstructL |
|
99 // |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CAudioFetcherFileHandler::ConstructL() |
|
103 { |
|
104 WLOG("CAudioFetcherFileHandler::ConstructL >"); |
|
105 |
|
106 iSession = CMdESession::NewL( *this ); |
|
107 iSearchList = CSearchList::NewL(); |
|
108 |
|
109 iQueryCaller = CActiveCaller::NewL( this ); |
|
110 iObjectNotificationCaller = CActiveCaller::NewL( this ); |
|
111 |
|
112 iDriveUtil = CDriveUtil::NewL(); |
|
113 |
|
114 WLOG("CAudioFetcherFileHandler::ConstructL <"); |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CAudioFetcherFileHandler::HandleSessionOpened (from MMdESessionObserver) |
|
123 // |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CAudioFetcherFileHandler::HandleSessionOpened( CMdESession& /*aSession*/, TInt aError ) |
|
127 { |
|
128 WLOG("CAudioFetcherFileHandler::HandleSessionOpened >"); |
|
129 if ( aError != KErrNone ) |
|
130 { |
|
131 delete iSession; |
|
132 iSession = NULL; |
|
133 iSessionOpen = EFalse; |
|
134 } |
|
135 else |
|
136 { |
|
137 iSessionOpen = ETrue; |
|
138 |
|
139 TRAP_IGNORE( AddObjectObserverL() ); |
|
140 } |
|
141 |
|
142 CallObserver( MAudioFetcherFileHandlerObserver::EInitComplete, aError ); |
|
143 WLOG("CAudioFetcherFileHandler::HandleSessionOpened <"); |
|
144 } |
|
145 |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CAudioFetcherFileHandler::AddObjectObserverL |
|
149 // |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CAudioFetcherFileHandler::AddObjectObserverL() |
|
153 { |
|
154 WLOG("CAudioFetcherFileHandler::AddObjectObserverL >"); |
|
155 if ( iSessionOpen ) |
|
156 { |
|
157 TUint32 notificationType = ENotifyAdd | ENotifyModify | ENotifyRemove; |
|
158 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
159 iSession->AddObjectObserverL( *this, NULL, notificationType, &defNS ); |
|
160 |
|
161 iSession->AddObjectPresentObserverL( *this ); |
|
162 } |
|
163 WLOG("CAudioFetcherFileHandler::AddObjectObserverL <"); |
|
164 } |
|
165 |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CAudioFetcherFileHandler::HandleSessionError (from MMdESessionObserver) |
|
169 // |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CAudioFetcherFileHandler::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
|
173 { |
|
174 WLOG("CAudioFetcherFileHandler::HandleSessionError >"); |
|
175 if ( aError == KErrNone ) |
|
176 { |
|
177 return; |
|
178 } |
|
179 |
|
180 delete iSession; |
|
181 iSession = NULL; |
|
182 iSessionOpen = EFalse; |
|
183 |
|
184 CallObserver( MAudioFetcherFileHandlerObserver::EError, aError ); |
|
185 WLOG("CAudioFetcherFileHandler::HandleSessionError <"); |
|
186 } |
|
187 |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CAudioFetcherFileHandler::HandleQueryNewResults (from MMdEQueryObserver) |
|
191 // |
|
192 // This observer function is called during query. Calling frequency is defined |
|
193 // in second parameter of CMdEQuery::FindL. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CAudioFetcherFileHandler::HandleQueryNewResults( CMdEQuery& /*aQuery*/, |
|
197 TInt /*aFirstNewItemIndex*/, |
|
198 TInt /*aNewItemCount*/ ) |
|
199 { |
|
200 } |
|
201 |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CAudioFetcherFileHandler::HandleObjectNotification (MMdEObjectObserver) |
|
205 // |
|
206 // Called when metadata database changes. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CAudioFetcherFileHandler::HandleObjectNotification( CMdESession& /*aSession*/, |
|
210 TObserverNotificationType aType, |
|
211 const RArray<TItemId>& aObjectIdArray ) |
|
212 { |
|
213 WLOG("CAudioFetcherFileHandler::HandleObjectNotification >"); |
|
214 if ( aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove ) |
|
215 { |
|
216 if ( iObserver ) |
|
217 { |
|
218 TInt count = aObjectIdArray.Count(); |
|
219 WLOG1("CAudioFetcherFileHandler::HandleObjectNotification: count is %d", count ); |
|
220 |
|
221 // delayed call to avoid many consecutive observer calls |
|
222 CallObserverWithDelay(); |
|
223 } |
|
224 } |
|
225 WLOG("CAudioFetcherFileHandler::HandleObjectNotification <"); |
|
226 } |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CAudioFetcherFileHandler::HandleObjectPresentNotification (MMdEObjectPresentObserver) |
|
231 // |
|
232 // Called when previously used memory card is inserted and hidden |
|
233 // metadata files are made present again. |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CAudioFetcherFileHandler::HandleObjectPresentNotification( CMdESession& /*aSession*/, |
|
237 TBool /*aPresent*/, const RArray<TItemId>& aObjectIdArray ) |
|
238 { |
|
239 WLOG("CAudioFetcherFileHandler::HandleObjectPresentNotification >"); |
|
240 if ( iObserver ) |
|
241 { |
|
242 TInt count = aObjectIdArray.Count(); |
|
243 WLOG1("CAudioFetcherFileHandler::HandleObjectPresentNotification: count is %d", count ); |
|
244 |
|
245 // delayed call to avoid many consecutive observer calls |
|
246 CallObserverWithDelay(); |
|
247 } |
|
248 WLOG("CAudioFetcherFileHandler::HandleObjectPresentNotification <"); |
|
249 } |
|
250 |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CAudioFetcherFileHandler::HandleQueryCompleted (MMdEQueryObserver) |
|
254 // |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CAudioFetcherFileHandler::HandleQueryCompleted( CMdEQuery& aQuery, TInt aError ) |
|
258 { |
|
259 WLOG("CAudioFetcherFileHandler::HandleQueryCompleted >"); |
|
260 TInt err = KErrNone; |
|
261 TRAP( err, HandleQueryCompletedL( aQuery, aError ) ); |
|
262 |
|
263 if ( err == KErrCancel ) |
|
264 { |
|
265 CallObserver( MAudioFetcherFileHandlerObserver::EQueryCanceled, KErrNone ); |
|
266 } |
|
267 else if ( err != KErrNone ) |
|
268 { |
|
269 iSearchList->Reset(); |
|
270 CallObserver( MAudioFetcherFileHandlerObserver::EError, err ); |
|
271 } |
|
272 WLOG("CAudioFetcherFileHandler::HandleQueryCompleted <"); |
|
273 } |
|
274 |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CAudioFetcherFileHandler::HandleQueryCompletedL |
|
278 // |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CAudioFetcherFileHandler::HandleQueryCompletedL( CMdEQuery& /*aQuery*/, TInt aError ) |
|
282 { |
|
283 WLOG("CAudioFetcherFileHandler::HandleQueryCompletedL >"); |
|
284 TInt err = aError; |
|
285 |
|
286 if ( !iQuery ) |
|
287 { |
|
288 err = KErrGeneral; |
|
289 } |
|
290 if ( err == KErrCancel ) |
|
291 { |
|
292 iSearchList->Reset(); |
|
293 return; |
|
294 // User::Leave( err ); |
|
295 } |
|
296 if ( err != KErrNone ) |
|
297 { |
|
298 User::Leave( err ); |
|
299 } |
|
300 |
|
301 iSearchList->SetSession( iSession ); |
|
302 TQueryResultMode resultMode = iQuery->ResultMode(); |
|
303 |
|
304 if ( resultMode == EQueryResultModeCount ) |
|
305 { |
|
306 // EQueryResultModeCount currently not used |
|
307 CallObserver( MAudioFetcherFileHandlerObserver::EUnknownQueryComplete, KErrNone ); |
|
308 } |
|
309 else if ( resultMode == EQueryResultModeItem ) |
|
310 { |
|
311 if ( iQueryType == ESearchAudio ) |
|
312 { |
|
313 // ESearchAudio currently not used |
|
314 iSearchList->Reset(); |
|
315 iSearchList->TakeResultL( iQuery, EMediaTypeMusic ); |
|
316 } |
|
317 else if ( iQueryType == ESearchMusic ) |
|
318 { |
|
319 // search is done in 3 steps (music, tones and videos) |
|
320 iSearchList->Reset(); |
|
321 iSearchList->TakeResultL( iQuery, EMediaTypeMusic ); |
|
322 } |
|
323 else if ( iQueryType == ESearchTones ) |
|
324 { |
|
325 iSearchList->TakeResultL( iQuery, EMediaTypeTone ); |
|
326 } |
|
327 else if ( iQueryType == EQueryUnknown ) |
|
328 { |
|
329 iSearchList->Reset(); |
|
330 iSearchList->TakeResultL( iQuery, EMediaTypeMusic ); |
|
331 iSearchList->SetSearchId( iQueryId ); |
|
332 |
|
333 CallObserver( MAudioFetcherFileHandlerObserver::EUnknownQueryComplete, KErrNone ); |
|
334 } |
|
335 else |
|
336 { |
|
337 TInt mediaType = MediaType( iQueryType ); |
|
338 iSearchList->TakeResultL( iQuery, mediaType ); |
|
339 iSearchList->SetSearchId( iQueryId ); |
|
340 iSearchList->Sort(); |
|
341 |
|
342 CallObserver( MAudioFetcherFileHandlerObserver::EQueryComplete, KErrNone ); |
|
343 } |
|
344 } |
|
345 else |
|
346 { |
|
347 CallObserver( MAudioFetcherFileHandlerObserver::EError, KErrNotSupported ); |
|
348 } |
|
349 WLOG("CAudioFetcherFileHandler::HandleQueryCompletedL <"); |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CAudioFetcherFileHandler::EQueryImage |
|
354 // |
|
355 // Finds image files. |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 void CAudioFetcherFileHandler::QueryImageL() |
|
359 { |
|
360 WLOG("CAudioFetcherFileHandler::EQueryImageL >"); |
|
361 |
|
362 LeaveIfSessionClosedL(); |
|
363 |
|
364 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
365 CMdEObjectDef& imageObjectDef = |
|
366 defNS.GetObjectDefL( MdeConstants::Image::KImageObject ); |
|
367 |
|
368 delete iQuery; |
|
369 iQuery = NULL; |
|
370 iQuery = iSession->NewObjectQueryL( defNS, imageObjectDef, this ); |
|
371 |
|
372 // set attributes that are included in query result |
|
373 CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName ); |
|
374 iQuery->AddPropertyFilterL( &namePropertyDef ); |
|
375 CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType ); |
|
376 iQuery->AddPropertyFilterL( &fileTypePropertyDef ); |
|
377 |
|
378 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
379 ExcludeRomFilesL( conditions ); |
|
380 |
|
381 iQuery->SetResultMode( EQueryResultModeItem ); |
|
382 iQuery->FindL(); |
|
383 |
|
384 iQueryType = EMediaTypeImage; |
|
385 |
|
386 WLOG("CAudioFetcherFileHandler::QueryImageL <"); |
|
387 } |
|
388 |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CAudioFetcherFileHandler::QueryAudioL |
|
392 // |
|
393 // Finds music files. |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 void CAudioFetcherFileHandler::QueryAudioL() |
|
397 { |
|
398 WLOG("CAudioFetcherFileHandler::QueryAudioL >"); |
|
399 |
|
400 LeaveIfSessionClosedL(); |
|
401 |
|
402 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
403 CMdEObjectDef& musicObjectDef = |
|
404 defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
405 |
|
406 delete iQuery; |
|
407 iQuery = NULL; |
|
408 iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this ); |
|
409 |
|
410 // set attributes that are included in query result |
|
411 CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName ); |
|
412 iQuery->AddPropertyFilterL( &namePropertyDef ); |
|
413 CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType ); |
|
414 iQuery->AddPropertyFilterL( &fileTypePropertyDef ); |
|
415 |
|
416 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
417 ExcludeRomFilesL( conditions ); |
|
418 |
|
419 // define sort order |
|
420 // iQuery->AppendOrderRuleL( TMdEOrderRule( namePropertyDef, ESortAscending ) ); |
|
421 |
|
422 iQuery->SetResultMode( EQueryResultModeItem ); |
|
423 iQuery->FindL(); |
|
424 |
|
425 iQueryType = EMediaTypeMusic; |
|
426 |
|
427 WLOG("CAudioFetcherFileHandler::QueryAudioL <"); |
|
428 } |
|
429 |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // CAudioFetcherFileHandler::QueryAudioL |
|
433 // |
|
434 // Finds music files. |
|
435 // ----------------------------------------------------------------------------- |
|
436 // |
|
437 void CAudioFetcherFileHandler::QueryVideoL() |
|
438 { |
|
439 WLOG("CAudioFetcherFileHandler::QueryVideoL >"); |
|
440 |
|
441 LeaveIfSessionClosedL(); |
|
442 |
|
443 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
444 CMdEObjectDef& videoObjectDef = |
|
445 defNS.GetObjectDefL( MdeConstants::Video::KVideoObject ); |
|
446 |
|
447 delete iQuery; |
|
448 iQuery = NULL; |
|
449 iQuery = iSession->NewObjectQueryL( defNS, videoObjectDef, this ); |
|
450 |
|
451 // set attributes that are included in query result |
|
452 CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName ); |
|
453 iQuery->AddPropertyFilterL( &namePropertyDef ); |
|
454 CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType ); |
|
455 iQuery->AddPropertyFilterL( &fileTypePropertyDef ); |
|
456 |
|
457 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
458 ExcludeRomFilesL( conditions ); |
|
459 |
|
460 iQuery->SetResultMode( EQueryResultModeItem ); |
|
461 iQuery->FindL(); |
|
462 |
|
463 iQueryType = EMediaTypeVideo; |
|
464 |
|
465 WLOG("CAudioFetcherFileHandler::QueryVideoL <"); |
|
466 } |
|
467 |
|
468 // ----------------------------------------------------------------------------- |
|
469 // CAudioFetcherFileHandler::ResultCount |
|
470 // |
|
471 // ----------------------------------------------------------------------------- |
|
472 // |
|
473 TInt CAudioFetcherFileHandler::ResultCount() |
|
474 { |
|
475 WLOG("CAudioFetcherFileHandler::ResultCount"); |
|
476 if ( !iSessionOpen ) |
|
477 { |
|
478 return 0; |
|
479 } |
|
480 |
|
481 return iSearchList->Count(); |
|
482 } |
|
483 |
|
484 |
|
485 // ----------------------------------------------------------------------------- |
|
486 // CAudioFetcherFileHandler::CancelQuery |
|
487 // |
|
488 // Cancels ongoing query. |
|
489 // ----------------------------------------------------------------------------- |
|
490 // |
|
491 void CAudioFetcherFileHandler::CancelQuery() |
|
492 { |
|
493 WLOG("CAudioFetcherFileHandler::CancelQuery >"); |
|
494 if ( !iSessionOpen || !iQuery ) |
|
495 { |
|
496 return; |
|
497 } |
|
498 |
|
499 if ( !iQuery->IsComplete() ) |
|
500 { |
|
501 iQuery->Cancel(); // this calls HandleQueryCompleted synchronously |
|
502 } |
|
503 WLOG("CAudioFetcherFileHandler::CancelQuery <"); |
|
504 } |
|
505 |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // CAudioFetcherFileHandler::LeaveIfSessionClosedL |
|
509 // |
|
510 // ----------------------------------------------------------------------------- |
|
511 // |
|
512 void CAudioFetcherFileHandler::LeaveIfSessionClosedL() |
|
513 { |
|
514 WLOG("CAudioFetcherFileHandler::LeaveIfSessionClosedL >"); |
|
515 if ( !iSession || !iSessionOpen ) |
|
516 { |
|
517 User::Leave( KErrDisconnected ); |
|
518 } |
|
519 WLOG("CAudioFetcherFileHandler::LeaveIfSessionClosedL <"); |
|
520 } |
|
521 |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // CAudioFetcherFileHandler::SetObserver |
|
525 // |
|
526 // ----------------------------------------------------------------------------- |
|
527 // |
|
528 void CAudioFetcherFileHandler::SetObserver( MAudioFetcherFileHandlerObserver* aObserver ) |
|
529 { |
|
530 iObserver = aObserver; |
|
531 } |
|
532 |
|
533 |
|
534 // ----------------------------------------------------------------------------- |
|
535 // CAudioFetcherFileHandler::GetAttributeL |
|
536 // |
|
537 // NOTE: GetAttributeL only gets full name or file name |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 void CAudioFetcherFileHandler::GetAttributeL( TInt aIndex, TInt aAttr, |
|
541 TDes& aValue, TInt aQueryId ) |
|
542 { |
|
543 WLOG("CAudioFetcherFileHandler::GetAttributeL"); |
|
544 aValue = KNullDesC; |
|
545 |
|
546 if ( !iSessionOpen ) |
|
547 { |
|
548 return; |
|
549 } |
|
550 |
|
551 TInt id = iSearchList->SearchId(); |
|
552 if ( id != aQueryId ) |
|
553 { |
|
554 return; // search list and UI do not match |
|
555 } |
|
556 |
|
557 iSearchList->SetSession( iSession ); |
|
558 iSearchList->GetAttributeL( aIndex, aAttr, aValue ); |
|
559 } |
|
560 |
|
561 |
|
562 |
|
563 // ----------------------------------------------------------------------------- |
|
564 // CAudioFetcherFileHandler::GetAttribute |
|
565 // |
|
566 // ----------------------------------------------------------------------------- |
|
567 // |
|
568 void CAudioFetcherFileHandler::GetAttribute( TInt aIndex, TInt aAttr, |
|
569 TDes& aValue, TInt aQueryId ) |
|
570 { |
|
571 WLOG("CAudioFetcherFileHandler::GetAttribute"); |
|
572 TRAP_IGNORE( GetAttributeL( aIndex, aAttr, aValue, aQueryId ) ); |
|
573 } |
|
574 |
|
575 |
|
576 // ----------------------------------------------------------------------------- |
|
577 // CAudioFetcherFileHandler::Attribute |
|
578 // |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 TInt CAudioFetcherFileHandler::Attribute( TInt aIndex, TInt aAttr, TInt aQueryId ) |
|
582 { |
|
583 WLOG("CAudioFetcherFileHandler::Attribute"); |
|
584 if ( !iSessionOpen ) |
|
585 { |
|
586 return KErrNotFound; |
|
587 } |
|
588 |
|
589 TInt id = iSearchList->SearchId(); |
|
590 if ( id != aQueryId ) |
|
591 { |
|
592 return KErrNotFound; |
|
593 } |
|
594 |
|
595 return iSearchList->Attribute( aIndex, aAttr ); |
|
596 } |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 // ----------------------------------------------------------------------------- |
|
602 // CAudioFetcherFileHandler::PropertyDefL |
|
603 // |
|
604 // ----------------------------------------------------------------------------- |
|
605 // |
|
606 CMdEPropertyDef& CAudioFetcherFileHandler::PropertyDefL( TInt aAttr ) |
|
607 { |
|
608 WLOG("CAudioFetcherFileHandler::PropertyDefL"); |
|
609 return PropertyDefL( iSession, aAttr ); |
|
610 } |
|
611 |
|
612 |
|
613 // ----------------------------------------------------------------------------- |
|
614 // CAudioFetcherFileHandler::PropertyDefL |
|
615 // |
|
616 // ----------------------------------------------------------------------------- |
|
617 // |
|
618 CMdEPropertyDef& CAudioFetcherFileHandler::PropertyDefL( CMdESession* aSession, TInt aAttr ) |
|
619 { |
|
620 WLOG("CAudioFetcherFileHandler::PropertyDefL"); |
|
621 CMdENamespaceDef& defNS = aSession->GetDefaultNamespaceDefL(); |
|
622 |
|
623 CMdEObjectDef& objectDef = |
|
624 defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
625 |
|
626 if ( aAttr == EAttrFileSize ) |
|
627 { |
|
628 return objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty ); |
|
629 } |
|
630 else if ( aAttr == EAttrMediaType ) |
|
631 { |
|
632 return objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty ); |
|
633 } |
|
634 else if ( aAttr == EAttrSongName || aAttr == EAttrFileName ) |
|
635 { |
|
636 return objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty ); |
|
637 } |
|
638 else if ( aAttr == EAttrArtist ) |
|
639 { |
|
640 return objectDef.GetPropertyDefL( MdeConstants::MediaObject::KArtistProperty ); |
|
641 } |
|
642 else if ( aAttr == EAttrAlbum ) |
|
643 { |
|
644 return objectDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty ); |
|
645 } |
|
646 else if ( aAttr == EAttrGenre ) |
|
647 { |
|
648 return objectDef.GetPropertyDefL( MdeConstants::MediaObject::KGenreProperty ); |
|
649 } |
|
650 else if ( aAttr == EAttrComposer ) |
|
651 { |
|
652 return objectDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty ); |
|
653 } |
|
654 else |
|
655 { |
|
656 User::Leave( KErrNotSupported ); |
|
657 } |
|
658 |
|
659 return objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty ); |
|
660 } |
|
661 |
|
662 |
|
663 // ----------------------------------------------------------------------------- |
|
664 // CAudioFetcherFileHandler::QueryReady |
|
665 // |
|
666 // ----------------------------------------------------------------------------- |
|
667 // |
|
668 TBool CAudioFetcherFileHandler::QueryReady() |
|
669 { |
|
670 WLOG("CAudioFetcherFileHandler::QueryReady"); |
|
671 |
|
672 TBool isWaitingObserverCall = iQueryCaller->IsActive(); |
|
673 if ( isWaitingObserverCall ) |
|
674 { |
|
675 return EFalse; // query is ready but observer not called yet |
|
676 } |
|
677 |
|
678 if ( iQuery ) |
|
679 { |
|
680 return iQuery->IsComplete(); |
|
681 } |
|
682 |
|
683 return ETrue; |
|
684 } |
|
685 |
|
686 |
|
687 // ----------------------------------------------------------------------------- |
|
688 // CAudioFetcherFileHandler::ExcludeRomFilesL |
|
689 // |
|
690 // Exclude audio files that are in rom (default tones). |
|
691 // ----------------------------------------------------------------------------- |
|
692 // |
|
693 void CAudioFetcherFileHandler::ExcludeRomFilesL( CMdELogicCondition& aCondition ) |
|
694 { |
|
695 WLOG("CAudioFetcherFileHandler::ExcludeRomFilesL"); |
|
696 _LIT( KDriveZ, "z:\\" ); |
|
697 |
|
698 CMdEObjectCondition& cond = aCondition.AddObjectConditionL( |
|
699 EObjectConditionCompareUriBeginsWith, KDriveZ ); |
|
700 cond.SetNegate( ETrue ); |
|
701 } |
|
702 |
|
703 |
|
704 // ------------------------------------------------------------------------------- |
|
705 // CAudioFetcherFileHandler::StrCopy |
|
706 // |
|
707 // String copy with lenght check. |
|
708 // ------------------------------------------------------------------------------- |
|
709 // |
|
710 void CAudioFetcherFileHandler::StrCopy( TDes& aTarget, const TDesC& aSource ) |
|
711 { |
|
712 WLOG("CAudioFetcherFileHandler::StrCopy"); |
|
713 TInt len = aTarget.MaxLength(); |
|
714 if( len < aSource.Length() ) |
|
715 { |
|
716 aTarget.Copy( aSource.Left( len ) ); |
|
717 return; |
|
718 } |
|
719 aTarget.Copy( aSource ); |
|
720 } |
|
721 |
|
722 |
|
723 // ----------------------------------------------------------------------------- |
|
724 // CAudioFetcherFileHandler::EnableObserverCall |
|
725 // |
|
726 // ----------------------------------------------------------------------------- |
|
727 // |
|
728 void CAudioFetcherFileHandler::EnableObserverCall( TBool aEnable ) |
|
729 { |
|
730 iObserverCallEnabled = aEnable; |
|
731 } |
|
732 |
|
733 |
|
734 // ----------------------------------------------------------------------------- |
|
735 // CAudioFetcherFileHandler::CallObserver |
|
736 // |
|
737 // ----------------------------------------------------------------------------- |
|
738 // |
|
739 void CAudioFetcherFileHandler::CallObserver( TInt aEvent, TInt aError ) |
|
740 { |
|
741 WLOG("CAudioFetcherFileHandler::CallObserver"); |
|
742 const TInt KDelay = 100; // milliseconds |
|
743 |
|
744 if ( !iObserverCallEnabled ) |
|
745 { |
|
746 return; |
|
747 } |
|
748 |
|
749 iQueryError = aError; |
|
750 iQueryEvent = aEvent; |
|
751 |
|
752 iQueryCaller->Start( 0, KDelay ); |
|
753 } |
|
754 |
|
755 |
|
756 // ----------------------------------------------------------------------------- |
|
757 // CAudioFetcherFileHandler::CallObserverWithDelay |
|
758 // |
|
759 // ----------------------------------------------------------------------------- |
|
760 // |
|
761 void CAudioFetcherFileHandler::CallObserverWithDelay() |
|
762 { |
|
763 WLOG("CAudioFetcherFileHandler::CallObserverWithDelay"); |
|
764 const TInt KOneSecond = 1000; |
|
765 |
|
766 if ( !iObserverCallEnabled ) |
|
767 { |
|
768 return; |
|
769 } |
|
770 |
|
771 iObjectNotificationCaller->Start( 1, KOneSecond ); |
|
772 } |
|
773 |
|
774 |
|
775 // ----------------------------------------------------------------------------- |
|
776 // CAudioFetcherFileHandler::HandleActiveCallL (from MActiveCallerObserver) |
|
777 // |
|
778 // ----------------------------------------------------------------------------- |
|
779 // |
|
780 void CAudioFetcherFileHandler::HandleActiveCallL( TInt aCallId ) |
|
781 { |
|
782 WLOG("CAudioFetcherFileHandler::HandleActiveCallL"); |
|
783 if ( !iObserver ) |
|
784 { |
|
785 return; |
|
786 } |
|
787 |
|
788 // inform observer that query is ready |
|
789 if ( aCallId == 0 ) |
|
790 { |
|
791 TRAP_IGNORE( iObserver->HandleFileEventL( iQueryEvent, iQueryError ) ); |
|
792 } |
|
793 |
|
794 // inform observer that database has changed |
|
795 if ( aCallId == 1 ) |
|
796 { |
|
797 if ( QueryReady() ) |
|
798 { |
|
799 TRAP_IGNORE( iObserver->HandleFileEventL( MAudioFetcherFileHandlerObserver::EMediaFileChanged, KErrNone ) ); |
|
800 } |
|
801 } |
|
802 } |
|
803 |
|
804 |
|
805 // ----------------------------------------------------------------------------- |
|
806 // CAudioFetcherFileHandler::SetQueryId |
|
807 // |
|
808 // ----------------------------------------------------------------------------- |
|
809 // |
|
810 void CAudioFetcherFileHandler::SetQueryId( TInt aId ) |
|
811 { |
|
812 // this id is passed to CSearchList after successful database search |
|
813 iQueryId = aId; |
|
814 } |
|
815 |
|
816 |
|
817 // ----------------------------------------------------------------------------- |
|
818 // CAudioFetcherFileHandler::Panic |
|
819 // |
|
820 // ----------------------------------------------------------------------------- |
|
821 // |
|
822 void CAudioFetcherFileHandler::Panic( TInt aReason ) |
|
823 { |
|
824 _LIT( KPanicCategory, "CAudioFetcherFileHandler" ); |
|
825 |
|
826 User::Panic( KPanicCategory, aReason ); |
|
827 } |
|
828 |
|
829 |
|
830 // ----------------------------------------------------------------------------- |
|
831 // CAudioFetcherFileHandler::MediaType |
|
832 // |
|
833 // ----------------------------------------------------------------------------- |
|
834 // |
|
835 TInt CAudioFetcherFileHandler::MediaType( TInt aQueryType ) |
|
836 { |
|
837 TInt mediaType = EMediaTypeAny; |
|
838 |
|
839 if ( aQueryType == EMediaTypeMusic ) |
|
840 { |
|
841 mediaType = EMediaTypeMusic; |
|
842 } |
|
843 else if ( aQueryType == EMediaTypeImage ) |
|
844 { |
|
845 mediaType = EMediaTypeImage; |
|
846 } |
|
847 else if ( aQueryType == EMediaTypeVideo ) |
|
848 { |
|
849 mediaType = EMediaTypeVideo; |
|
850 } |
|
851 return mediaType; |
|
852 } |
|
853 |
|
854 // ----------------------------------------------------------------------------- |
|
855 // CAudioFetcherFileHandler::QueryType |
|
856 // |
|
857 // ----------------------------------------------------------------------------- |
|
858 // |
|
859 TInt CAudioFetcherFileHandler::QueryType() |
|
860 { |
|
861 return iQueryType; |
|
862 } |
|
863 |
|
864 |
|
865 /****************************************************************************** |
|
866 * class CSearchListItem |
|
867 ******************************************************************************/ |
|
868 |
|
869 |
|
870 // ----------------------------------------------------------------------------- |
|
871 // CSearchListItem::NewL |
|
872 // |
|
873 // ----------------------------------------------------------------------------- |
|
874 // |
|
875 CSearchListItem* CSearchListItem::NewLC() |
|
876 { |
|
877 CSearchListItem* self = new (ELeave) CSearchListItem(); |
|
878 CleanupStack::PushL( self ); |
|
879 self->ConstructL(); |
|
880 |
|
881 return self; |
|
882 } |
|
883 |
|
884 |
|
885 // ----------------------------------------------------------------------------- |
|
886 // Destructor |
|
887 // |
|
888 // ----------------------------------------------------------------------------- |
|
889 // |
|
890 CSearchListItem::~CSearchListItem() |
|
891 { |
|
892 delete iTitle; |
|
893 } |
|
894 |
|
895 |
|
896 // ----------------------------------------------------------------------------- |
|
897 // CSearchListItem::CSearchListItem |
|
898 // |
|
899 // ----------------------------------------------------------------------------- |
|
900 // |
|
901 CSearchListItem::CSearchListItem() |
|
902 { |
|
903 iId = KErrNotFound; |
|
904 iMediaType = KErrNotFound; |
|
905 iStorageType = KErrNotFound; |
|
906 iTitle = NULL; |
|
907 } |
|
908 |
|
909 |
|
910 // ----------------------------------------------------------------------------- |
|
911 // CSearchListItem::ConstructL |
|
912 // |
|
913 // ----------------------------------------------------------------------------- |
|
914 // |
|
915 void CSearchListItem::ConstructL() |
|
916 { |
|
917 } |
|
918 |
|
919 // ----------------------------------------------------------------------------- |
|
920 // CSearchListItem::SetTitleL |
|
921 // |
|
922 // ----------------------------------------------------------------------------- |
|
923 // |
|
924 |
|
925 void CSearchListItem::SetTitleL( const TDesC& aText, TBool aFullName ) |
|
926 { |
|
927 delete iTitle; |
|
928 iTitle = NULL; |
|
929 |
|
930 if ( aFullName ) |
|
931 { |
|
932 TParsePtrC parse( aText ); |
|
933 iTitle = parse.Name().AllocL(); |
|
934 } |
|
935 else |
|
936 { |
|
937 iTitle = aText.AllocL(); |
|
938 } |
|
939 } |
|
940 |
|
941 |
|
942 // ----------------------------------------------------------------------------- |
|
943 // CSearchListItem::Title |
|
944 // |
|
945 // ----------------------------------------------------------------------------- |
|
946 // |
|
947 |
|
948 const TDesC& CSearchListItem::Title() const |
|
949 { |
|
950 return *iTitle; |
|
951 } |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 /****************************************************************************** |
|
957 * class CSearchList |
|
958 ******************************************************************************/ |
|
959 |
|
960 |
|
961 // ----------------------------------------------------------------------------- |
|
962 // CSearchList::NewL |
|
963 // |
|
964 // ----------------------------------------------------------------------------- |
|
965 // |
|
966 CSearchList* CSearchList::NewL() |
|
967 { |
|
968 CSearchList* self = new (ELeave) CSearchList(); |
|
969 CleanupStack::PushL( self ); |
|
970 self->ConstructL(); |
|
971 CleanupStack::Pop( self ); |
|
972 |
|
973 return self; |
|
974 } |
|
975 |
|
976 |
|
977 // ----------------------------------------------------------------------------- |
|
978 // Destructor |
|
979 // |
|
980 // ----------------------------------------------------------------------------- |
|
981 // |
|
982 CSearchList::~CSearchList() |
|
983 { |
|
984 WLOG("CSearchList::~CSearchList >"); |
|
985 iList.ResetAndDestroy(); |
|
986 delete iDriveUtil; |
|
987 WLOG("CSearchList::~CSearchList <"); |
|
988 } |
|
989 |
|
990 |
|
991 // ----------------------------------------------------------------------------- |
|
992 // CSearchList::CSearchList |
|
993 // |
|
994 // ----------------------------------------------------------------------------- |
|
995 // |
|
996 CSearchList::CSearchList() |
|
997 { |
|
998 iSearchId = KErrNotFound; |
|
999 } |
|
1000 |
|
1001 |
|
1002 // ----------------------------------------------------------------------------- |
|
1003 // CSearchList::ConstructL |
|
1004 // |
|
1005 // ----------------------------------------------------------------------------- |
|
1006 // |
|
1007 void CSearchList::ConstructL() |
|
1008 { |
|
1009 WLOG("CSearchList::ConstructL >"); |
|
1010 iDriveUtil = CDriveUtil::NewL(); |
|
1011 WLOG("CSearchList::ConstructL"); |
|
1012 } |
|
1013 |
|
1014 |
|
1015 // ----------------------------------------------------------------------------- |
|
1016 // CSearchList::SetSession |
|
1017 // |
|
1018 // ----------------------------------------------------------------------------- |
|
1019 // |
|
1020 void CSearchList::SetSession( CMdESession* aSession ) |
|
1021 { |
|
1022 iSession = aSession; |
|
1023 } |
|
1024 |
|
1025 |
|
1026 // ----------------------------------------------------------------------------- |
|
1027 // CSearchList::SetSearchId |
|
1028 // |
|
1029 // ----------------------------------------------------------------------------- |
|
1030 // |
|
1031 void CSearchList::SetSearchId( TInt aSearchId ) |
|
1032 { |
|
1033 iSearchId = aSearchId; |
|
1034 } |
|
1035 |
|
1036 |
|
1037 // ----------------------------------------------------------------------------- |
|
1038 // CSearchList::SearchId |
|
1039 // |
|
1040 // ----------------------------------------------------------------------------- |
|
1041 // |
|
1042 TInt CSearchList::SearchId() |
|
1043 { |
|
1044 return iSearchId; |
|
1045 } |
|
1046 |
|
1047 |
|
1048 // ----------------------------------------------------------------------------- |
|
1049 // CSearchList::TakeResultL |
|
1050 // |
|
1051 // ----------------------------------------------------------------------------- |
|
1052 // |
|
1053 void CSearchList::TakeResultL( CMdEObjectQuery* aQuery, TInt aMediaType ) |
|
1054 { |
|
1055 WLOG("CSearchList::TakeResultL >"); |
|
1056 if ( !aQuery ) |
|
1057 { |
|
1058 return; |
|
1059 } |
|
1060 |
|
1061 TInt count = aQuery->Count(); |
|
1062 |
|
1063 for ( TInt i=0; i<count; i++ ) |
|
1064 { |
|
1065 CMdEObject* object = (CMdEObject*) aQuery->TakeOwnershipOfResult( i ); |
|
1066 CleanupStack::PushL( object ); |
|
1067 AddItemL( *object, aMediaType ); |
|
1068 CleanupStack::PopAndDestroy( object ); |
|
1069 } |
|
1070 WLOG("CSearchList::TakeResultL <"); |
|
1071 } |
|
1072 |
|
1073 // ----------------------------------------------------------------------------- |
|
1074 // CSearchList::TakeDistinctResultL |
|
1075 // |
|
1076 // ----------------------------------------------------------------------------- |
|
1077 // |
|
1078 void CSearchList::TakeDistinctResultL( CMdEObjectQuery* aQuery, |
|
1079 TInt /*aMediaType*/ ) |
|
1080 { |
|
1081 if ( !aQuery ) |
|
1082 { |
|
1083 return; |
|
1084 } |
|
1085 |
|
1086 TInt count = aQuery->Count(); |
|
1087 |
|
1088 for ( TInt i=0; i<count; i++ ) |
|
1089 { |
|
1090 TPtrC ptr = aQuery->ResultDistinctValue( i ); |
|
1091 |
|
1092 CSearchListItem* item = CSearchListItem::NewLC(); |
|
1093 |
|
1094 item->SetTitleL( ptr, EFalse ); |
|
1095 item->iMediaType = KErrNotFound; |
|
1096 item->iStorageType = KErrNotFound; |
|
1097 |
|
1098 iList.AppendL( item ); |
|
1099 |
|
1100 CleanupStack::Pop( item ); |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 |
|
1105 // ----------------------------------------------------------------------------- |
|
1106 // CSearchList::AddItemL |
|
1107 // |
|
1108 // ----------------------------------------------------------------------------- |
|
1109 // |
|
1110 void CSearchList::AddItemL( CMdEObject& aObject, TInt aMediaType ) |
|
1111 { |
|
1112 WLOG("CSearchList::AddItemL >"); |
|
1113 CSearchListItem* item = CSearchListItem::NewLC(); |
|
1114 |
|
1115 TPtrC songName = TextL( aObject, CAudioFetcherFileHandler::EAttrSongName ); |
|
1116 |
|
1117 if ( songName.Length() > 0 ) |
|
1118 { |
|
1119 item->SetTitleL( songName, EFalse ); |
|
1120 } |
|
1121 else |
|
1122 { |
|
1123 item->SetTitleL( aObject.Uri(), ETrue ); |
|
1124 } |
|
1125 |
|
1126 |
|
1127 item->iId = aObject.Id(); |
|
1128 item->iMediaType = aMediaType; |
|
1129 |
|
1130 TInt storageType = CAudioFetcherFileHandler::EPhoneMemory; |
|
1131 if ( iDriveUtil->IsMemoryCard( aObject.Uri() ) ) |
|
1132 { |
|
1133 storageType = CAudioFetcherFileHandler::EMemoryCard; |
|
1134 } |
|
1135 else if ( iDriveUtil->IsMassStorage( aObject.Uri() ) ) |
|
1136 { |
|
1137 storageType = CAudioFetcherFileHandler::EMassStorage; |
|
1138 } |
|
1139 item->iStorageType = storageType; |
|
1140 |
|
1141 iList.AppendL( item ); |
|
1142 |
|
1143 CleanupStack::Pop( item ); |
|
1144 WLOG("CSearchList::AddItemL <"); |
|
1145 } |
|
1146 |
|
1147 |
|
1148 // ----------------------------------------------------------------------------- |
|
1149 // CSearchList::AddAlbumItemL |
|
1150 // |
|
1151 // ----------------------------------------------------------------------------- |
|
1152 // |
|
1153 void CSearchList::AddAlbumItemL( const TDesC& aAlbum ) |
|
1154 { |
|
1155 TLinearOrder<CSearchListItem> sortFunction( CSearchList::Compare ); |
|
1156 |
|
1157 CSearchListItem* item = CSearchListItem::NewLC(); |
|
1158 |
|
1159 item->SetTitleL( aAlbum, EFalse ); |
|
1160 |
|
1161 CleanupStack::Pop( item ); |
|
1162 |
|
1163 item->iMediaType = KErrNotFound; |
|
1164 item->iStorageType = KErrNotFound; |
|
1165 item->iId = KErrNotFound; |
|
1166 |
|
1167 TInt err = iList.InsertInOrder( item, sortFunction ); |
|
1168 if ( err != KErrNone ) |
|
1169 { |
|
1170 delete item; |
|
1171 } |
|
1172 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
1173 { |
|
1174 User::Leave( err ); |
|
1175 } |
|
1176 } |
|
1177 |
|
1178 |
|
1179 // ----------------------------------------------------------------------------- |
|
1180 // CSearchList::AddArtistItemL |
|
1181 // |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // |
|
1184 void CSearchList::AddArtistItemL( CMdEObject& aObject, |
|
1185 TInt aQueryType, const TDesC& aAlbum ) |
|
1186 { |
|
1187 // all songs for one artist |
|
1188 if ( aQueryType == CAudioFetcherFileHandler::EQueryArtistAll ) |
|
1189 { |
|
1190 AddItemL( aObject, CAudioFetcherFileHandler::EMediaTypeMusic ); |
|
1191 return; |
|
1192 } |
|
1193 |
|
1194 TPtrC album = TextL( aObject, CAudioFetcherFileHandler::EAttrAlbum ); |
|
1195 |
|
1196 // unknown songs (no album metadata) for one artist |
|
1197 if ( aQueryType == CAudioFetcherFileHandler::EQueryArtistUnknown ) |
|
1198 { |
|
1199 if ( album.Length() == 0 ) |
|
1200 { |
|
1201 AddItemL( aObject, CAudioFetcherFileHandler::EMediaTypeMusic ); |
|
1202 } |
|
1203 } |
|
1204 |
|
1205 // all albums for one artist |
|
1206 if ( aQueryType == CAudioFetcherFileHandler::EQueryArtist ) |
|
1207 { |
|
1208 if ( album.Length() > 0 ) |
|
1209 { |
|
1210 AddAlbumItemL( album ); |
|
1211 } |
|
1212 } |
|
1213 |
|
1214 // songs in one album |
|
1215 if ( aQueryType == CAudioFetcherFileHandler::EQueryArtistAlbum ) |
|
1216 { |
|
1217 if ( album.Length() > 0 ) |
|
1218 { |
|
1219 if ( album.Compare( aAlbum ) == 0 ) |
|
1220 { |
|
1221 AddItemL( aObject, CAudioFetcherFileHandler::EMediaTypeMusic ); |
|
1222 } |
|
1223 } |
|
1224 } |
|
1225 } |
|
1226 |
|
1227 |
|
1228 // ----------------------------------------------------------------------------- |
|
1229 // CSearchList::Sort |
|
1230 // |
|
1231 // ----------------------------------------------------------------------------- |
|
1232 // |
|
1233 void CSearchList::Sort() |
|
1234 { |
|
1235 iList.Sort( TLinearOrder<CSearchListItem>(CSearchList::Compare) ); |
|
1236 } |
|
1237 |
|
1238 |
|
1239 // ----------------------------------------------------------------------------- |
|
1240 // CSearchList::Reset |
|
1241 // |
|
1242 // ----------------------------------------------------------------------------- |
|
1243 // |
|
1244 void CSearchList::Reset() |
|
1245 { |
|
1246 iSearchId = KErrNotFound; |
|
1247 iList.ResetAndDestroy(); |
|
1248 } |
|
1249 |
|
1250 |
|
1251 // ----------------------------------------------------------------------------- |
|
1252 // CSearchList::Count |
|
1253 // |
|
1254 // ----------------------------------------------------------------------------- |
|
1255 // |
|
1256 TInt CSearchList::Count() |
|
1257 { |
|
1258 WLOG("CSearchList::Count"); |
|
1259 return iList.Count(); |
|
1260 } |
|
1261 |
|
1262 |
|
1263 // ----------------------------------------------------------------------------- |
|
1264 // CSearchList::GetAttributeL |
|
1265 // |
|
1266 // ----------------------------------------------------------------------------- |
|
1267 // |
|
1268 void CSearchList::GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue ) |
|
1269 { |
|
1270 WLOG("CSearchList::GetAttributeL"); |
|
1271 aValue = KNullDesC; |
|
1272 |
|
1273 if ( !iSession ) |
|
1274 { |
|
1275 return; |
|
1276 } |
|
1277 |
|
1278 if ( aIndex == KErrNotFound ) |
|
1279 { |
|
1280 return; |
|
1281 } |
|
1282 |
|
1283 TInt count = iList.Count(); |
|
1284 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1285 |
|
1286 if ( aAttr == CAudioFetcherFileHandler::EAttrFullName ) |
|
1287 { |
|
1288 CSearchListItem* item = iList[aIndex]; |
|
1289 CMdEObject* object = iSession->GetFullObjectL( item->iId ); |
|
1290 CleanupStack::PushL( object ); |
|
1291 StrCopy( aValue, object->Uri() ); |
|
1292 CleanupStack::PopAndDestroy( object ); |
|
1293 } |
|
1294 |
|
1295 else if ( aAttr == CAudioFetcherFileHandler::EAttrSongName || |
|
1296 aAttr == CAudioFetcherFileHandler::EAttrFileName ) |
|
1297 { |
|
1298 CSearchListItem* item = iList[aIndex]; |
|
1299 StrCopy( aValue, item->Title() ); |
|
1300 if ( aValue.Length() == 0 ) |
|
1301 { |
|
1302 CMdEObject* object = iSession->GetFullObjectL( item->iId ); |
|
1303 CleanupStack::PushL( object ); |
|
1304 TParsePtrC parse( object->Uri() ); |
|
1305 StrCopy( aValue, parse.Name() ); |
|
1306 CleanupStack::PopAndDestroy( object ); |
|
1307 } |
|
1308 } |
|
1309 } |
|
1310 |
|
1311 |
|
1312 // ----------------------------------------------------------------------------- |
|
1313 // CSearchList::Attribute |
|
1314 // |
|
1315 // ----------------------------------------------------------------------------- |
|
1316 // |
|
1317 TInt CSearchList::Attribute( TInt aIndex, TInt aAttr ) |
|
1318 { |
|
1319 WLOG("CSearchList::Attribute"); |
|
1320 if ( aIndex == KErrNotFound ) |
|
1321 { |
|
1322 return KErrNotFound; |
|
1323 } |
|
1324 |
|
1325 TInt count = iList.Count(); |
|
1326 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1327 |
|
1328 |
|
1329 TInt ret = KErrNotFound; |
|
1330 if ( aAttr == CAudioFetcherFileHandler::EAttrMediaType ) |
|
1331 { |
|
1332 CSearchListItem* item = iList[aIndex]; |
|
1333 ret = item->iMediaType; |
|
1334 } |
|
1335 |
|
1336 else if ( aAttr == CAudioFetcherFileHandler::EAttrStorageType ) |
|
1337 { |
|
1338 CSearchListItem* item = iList[aIndex]; |
|
1339 ret = item->iStorageType; |
|
1340 } |
|
1341 else if ( aAttr == CAudioFetcherFileHandler::EAttrMediaFileId ) |
|
1342 { |
|
1343 CSearchListItem* item = iList[aIndex]; |
|
1344 ret = item->iId; |
|
1345 } |
|
1346 |
|
1347 return ret; |
|
1348 } |
|
1349 |
|
1350 |
|
1351 // ----------------------------------------------------------------------------- |
|
1352 // CSearchList::Compare |
|
1353 // |
|
1354 // ----------------------------------------------------------------------------- |
|
1355 // |
|
1356 TInt CSearchList::Compare( const CSearchListItem& aFirst, |
|
1357 const CSearchListItem& aSecond ) |
|
1358 { |
|
1359 TPtrC first = aFirst.Title(); |
|
1360 TPtrC second = aSecond.Title(); |
|
1361 |
|
1362 return first.Compare( second ); |
|
1363 } |
|
1364 |
|
1365 // ----------------------------------------------------------------------------- |
|
1366 // CSearchList::StrCopy |
|
1367 // |
|
1368 // ----------------------------------------------------------------------------- |
|
1369 // |
|
1370 void CSearchList::StrCopy( TDes& aTarget, const TDesC& aSource ) |
|
1371 { |
|
1372 WLOG("CSearchList::StrCopy >"); |
|
1373 TInt len = aTarget.MaxLength(); |
|
1374 if( len < aSource.Length() ) |
|
1375 { |
|
1376 aTarget.Copy( aSource.Left(len) ); |
|
1377 return; |
|
1378 } |
|
1379 aTarget.Copy( aSource ); |
|
1380 WLOG("CSearchList::StrCopy <"); |
|
1381 } |
|
1382 |
|
1383 // ----------------------------------------------------------------------------- |
|
1384 // CSearchList::Panic |
|
1385 // |
|
1386 // ----------------------------------------------------------------------------- |
|
1387 // |
|
1388 void CSearchList::Panic( TInt aReason ) |
|
1389 { |
|
1390 _LIT( KPanicCategory, "CSearchList" ); |
|
1391 |
|
1392 User::Panic( KPanicCategory, aReason ); |
|
1393 } |
|
1394 |
|
1395 |
|
1396 // ----------------------------------------------------------------------------- |
|
1397 // CSearchList::TextL |
|
1398 // |
|
1399 // ----------------------------------------------------------------------------- |
|
1400 // |
|
1401 const TDesC& CSearchList::TextL( CMdEObject& aObject, TInt aId ) |
|
1402 { |
|
1403 WLOG("CSearchList::TextL"); |
|
1404 CMdEPropertyDef& propDef = |
|
1405 CAudioFetcherFileHandler::PropertyDefL( iSession, aId ); |
|
1406 |
|
1407 CMdEProperty* property = NULL; |
|
1408 TInt err = aObject.Property( propDef, property, 0 ); |
|
1409 |
|
1410 if ( err != KErrNotFound && property ) |
|
1411 { |
|
1412 return property->TextValueL(); |
|
1413 } |
|
1414 |
|
1415 return KNullDesC; |
|
1416 } |
|
1417 |
|
1418 |
|
1419 // End of File |