profilesservices/MediaFileList/Src/mediafilehandler.cpp
branchRCL_3
changeset 54 7e0eff37aedb
child 57 e78c61e77b1a
equal deleted inserted replaced
53:8ee96d21d9bf 54:7e0eff37aedb
       
     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:   Used to interact with the MDE.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mediafilehandler.h"
       
    22 #include "mediafilelistdebug.h"
       
    23 #include "mediafiledialogstate.h"
       
    24 #include "mediafilelist.h"
       
    25 
       
    26 #include <pathinfo.h>
       
    27 #include <bautils.h>
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 /******************************************************************************
       
    33  * class CMediaFileData
       
    34  ******************************************************************************/
       
    35 
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMediaFileData::NewL
       
    40 // 
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CMediaFileData* CMediaFileData::NewL()
       
    44     {
       
    45     CMediaFileData* self = new (ELeave) CMediaFileData();
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49 
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // Destructor
       
    56 // 
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMediaFileData::~CMediaFileData()
       
    60     {
       
    61     delete iFullName;
       
    62     delete iName;
       
    63     delete iArtist;
       
    64     delete iAlbum;
       
    65     delete iGenre;
       
    66     delete iComposer;
       
    67     }
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMediaFileData::CMediaFileData
       
    72 // 
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CMediaFileData::CMediaFileData()
       
    76     {
       
    77     iMediaFileType = KErrNotFound;
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CMediaFileData::ConstructL
       
    83 // 
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CMediaFileData::ConstructL()
       
    87     {
       
    88     iFullName  = HBufC::NewL( 0 );
       
    89     iName      = HBufC::NewL( 0 );
       
    90     iArtist    = HBufC::NewL( 0 );
       
    91     iAlbum     = HBufC::NewL( 0 );
       
    92     iGenre     = HBufC::NewL( 0 );
       
    93     iComposer  = HBufC::NewL( 0 );
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CMediaFileData::Attr
       
    99 // 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 const TDesC& CMediaFileData::Attr( TInt aAttr )
       
   103     {
       
   104     if ( aAttr == CMediaFileHandler::EAttrFullName )
       
   105         {
       
   106         return *iFullName;
       
   107         }
       
   108     if ( aAttr == CMediaFileHandler::EAttrSongName )
       
   109         {
       
   110         return *iName;
       
   111         }
       
   112     if ( aAttr == CMediaFileHandler::EAttrArtist )
       
   113         {
       
   114         return *iArtist;
       
   115         }
       
   116     if ( aAttr == CMediaFileHandler::EAttrAlbum )
       
   117         {
       
   118         return *iAlbum;
       
   119         }
       
   120     if ( aAttr == CMediaFileHandler::EAttrGenre )
       
   121         {
       
   122         return *iGenre;
       
   123         }
       
   124     if ( aAttr == CMediaFileHandler::EAttrComposer )
       
   125         {
       
   126         return *iComposer;
       
   127         }
       
   128 
       
   129     return KNullDesC;
       
   130     }
       
   131 
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMediaFileData::SetAttrL
       
   135 // 
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CMediaFileData::SetAttrL( TInt aAttr, const TDesC& aValue )
       
   139     {
       
   140     if ( aAttr == CMediaFileHandler::EAttrFullName )
       
   141         {
       
   142         delete iFullName;
       
   143         iFullName = NULL;
       
   144         iFullName = aValue.AllocL();
       
   145         }
       
   146     if ( aAttr == CMediaFileHandler::EAttrSongName )
       
   147         {
       
   148         delete iName;
       
   149         iName = NULL;
       
   150         iName = aValue.AllocL();
       
   151  
       
   152         }
       
   153     if ( aAttr == CMediaFileHandler::EAttrArtist )
       
   154         {
       
   155         delete iArtist;
       
   156         iArtist = NULL;
       
   157         iArtist = aValue.AllocL();
       
   158         }
       
   159     if ( aAttr == CMediaFileHandler::EAttrAlbum )
       
   160         {
       
   161         delete iAlbum;
       
   162         iAlbum = NULL;
       
   163         iAlbum = aValue.AllocL();
       
   164         }
       
   165     if ( aAttr == CMediaFileHandler::EAttrGenre )
       
   166         {
       
   167         delete iGenre;
       
   168         iGenre = NULL;
       
   169         iGenre = aValue.AllocL();
       
   170         }
       
   171     if ( aAttr == CMediaFileHandler::EAttrComposer )
       
   172         {
       
   173         delete iComposer;
       
   174         iComposer = NULL;
       
   175         iComposer = aValue.AllocL();
       
   176         }
       
   177     }
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CMediaFileData::GetAttr
       
   182 // 
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CMediaFileData::GetAttr( TInt aAttr, TDes& aValue )
       
   186     {
       
   187     if ( aAttr == CMediaFileHandler::EAttrFullName )
       
   188         {
       
   189         TMFDialogUtil::StrCopy( aValue, iFullName->Des() );
       
   190         }
       
   191     else if ( aAttr == CMediaFileHandler::EAttrSongName )
       
   192         {
       
   193         TMFDialogUtil::StrCopy( aValue, iName->Des() );
       
   194         }
       
   195     else if ( aAttr == CMediaFileHandler::EAttrArtist )
       
   196         {
       
   197         TMFDialogUtil::StrCopy( aValue, iArtist->Des() );
       
   198         }
       
   199     else if ( aAttr == CMediaFileHandler::EAttrAlbum )
       
   200         {
       
   201         TMFDialogUtil::StrCopy( aValue, iAlbum->Des() );
       
   202         }
       
   203     else if ( aAttr == CMediaFileHandler::EAttrGenre )
       
   204         {
       
   205         TMFDialogUtil::StrCopy( aValue, iGenre->Des() );
       
   206         }
       
   207     else if ( aAttr == CMediaFileHandler::EAttrComposer )
       
   208         {
       
   209         TMFDialogUtil::StrCopy( aValue, iComposer->Des() );
       
   210         }
       
   211     else
       
   212         {
       
   213         aValue = KNullDesC;
       
   214         }
       
   215     }
       
   216     
       
   217 
       
   218 /******************************************************************************
       
   219  * class CMediaFileHandler
       
   220  ******************************************************************************/
       
   221 
       
   222 
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CMediaFileHandler::NewL
       
   226 // 
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 CMediaFileHandler* CMediaFileHandler::NewL()
       
   230     {
       
   231     CMediaFileHandler* self = new (ELeave) CMediaFileHandler();
       
   232 	CleanupStack::PushL( self );
       
   233 	self->ConstructL();
       
   234 	CleanupStack::Pop( self );
       
   235 
       
   236 	return self;
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // Destructor
       
   242 // 
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 CMediaFileHandler::~CMediaFileHandler()
       
   246     {
       
   247     delete iSearchList;
       
   248     
       
   249     delete iQueryCaller;
       
   250     delete iObjectNotificationCaller;
       
   251     
       
   252     delete iDriveUtil;
       
   253     delete iExcludedMimeTypes;
       
   254     delete iIdle;
       
   255     
       
   256     delete iQuery;
       
   257     delete iArtistQuery;
       
   258     delete iSession;
       
   259     
       
   260     delete iRomFileList;
       
   261     }
       
   262 
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CMediaFileHandler::CMediaFileHandler
       
   266 // 
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 CMediaFileHandler::CMediaFileHandler()
       
   270     {
       
   271     iSessionOpen = EFalse;
       
   272     iObserverCallEnabled = ETrue;
       
   273     
       
   274     iMaxFileSize = KErrNotFound;
       
   275     iQueryId = KErrNotFound;
       
   276     iQueryType = KErrNotFound;
       
   277     iQueryError = KErrNone;
       
   278     iQueryEvent = KErrNotFound;
       
   279     iVideoSearchDisabled = EFalse;
       
   280     
       
   281     iMediaFileCounter = 0;
       
   282     }
       
   283 
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CMediaFileHandler::ConstructL
       
   287 // 
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CMediaFileHandler::ConstructL()
       
   291     {
       
   292     iSession = CMdESession::NewL( *this );
       
   293     iSearchList = CSearchList::NewL();
       
   294     
       
   295     iQueryCaller = CMFActiveCaller::NewL( this );
       
   296     iObjectNotificationCaller = CMFActiveCaller::NewL( this );
       
   297     
       
   298     iDriveUtil = CDriveUtil::NewL();
       
   299     iArtistQuery = CArtistQuery::NewL();
       
   300     iExcludedMimeTypes = CMimeTypeList::NewL();
       
   301     
       
   302     iRomFileList = CRomFileList::NewL();
       
   303     iQueryinProgress = EFalse;
       
   304     iRomScanState = MMediaFileHandlerObserver::ENoneRomScan;
       
   305     }
       
   306 
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CMediaFileHandler::SetAttr
       
   310 // 
       
   311 // -----------------------------------------------------------------------------
       
   312 void CMediaFileHandler::SetAttrL( TInt aAttr, TInt aValue )
       
   313     {
       
   314     switch ( aAttr )
       
   315         {
       
   316         case CMediaFileList::EAttrFileSize:
       
   317             {
       
   318             iMaxFileSize = aValue;
       
   319             break;
       
   320             }
       
   321         case CMediaFileList::EAttrExcludeFolder:
       
   322             {
       
   323             if ( aValue == CMediaFileList::EFolderVideos )
       
   324                 {
       
   325                 iVideoSearchDisabled = ETrue;
       
   326                 }
       
   327             break;
       
   328             }
       
   329         default:
       
   330             {
       
   331             break;
       
   332             }
       
   333         }
       
   334     }
       
   335 
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CMediaFileHandler::SetAttrL
       
   339 // 
       
   340 // -----------------------------------------------------------------------------
       
   341 void CMediaFileHandler::SetAttrL( TInt aAttr, const TDesC& aValue )
       
   342     {
       
   343     if ( aAttr == CMediaFileList::EAttrExcludeMimeType )
       
   344         {
       
   345         iExcludedMimeTypes->AddMimeTypeL( aValue );
       
   346         }
       
   347     }
       
   348 
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CMediaFileHandler::SetAttr
       
   352 // 
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 void CMediaFileHandler::SetAttrL( TInt /*aAttr*/, TAny* /*aValue*/ )
       
   356     {
       
   357     }
       
   358 
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CMediaFileHandler::HandleSessionOpened (from MMdESessionObserver)
       
   362 // 
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CMediaFileHandler::HandleSessionOpened( CMdESession& /*aSession*/, TInt aError )
       
   366     {
       
   367     if ( aError != KErrNone )
       
   368         {
       
   369         delete iSession;
       
   370         iSession = NULL;
       
   371         iSessionOpen = EFalse;
       
   372         }
       
   373     else
       
   374         {
       
   375         iSessionOpen = ETrue;
       
   376 
       
   377         TRAP_IGNORE( AddObjectObserverL() );
       
   378         }
       
   379 
       
   380     CallObserver( MMediaFileHandlerObserver::EInitComplete, aError );
       
   381     }
       
   382 
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CMediaFileHandler::AddObjectObserverL
       
   386 // 
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 void CMediaFileHandler::AddObjectObserverL()
       
   390     {
       
   391     if ( iSessionOpen )
       
   392         {
       
   393         TUint32 notificationType = ENotifyAdd | ENotifyModify | ENotifyRemove;
       
   394         CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   395         iSession->AddObjectObserverL( *this, NULL, notificationType, &defNS );
       
   396         
       
   397         iSession->AddObjectPresentObserverL( *this );
       
   398         }
       
   399     }
       
   400 
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CMediaFileHandler::HandleSessionError (from MMdESessionObserver)
       
   404 // 
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 void CMediaFileHandler::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
       
   408     {
       
   409     if ( aError == KErrNone )
       
   410         {
       
   411         return;
       
   412         }
       
   413         
       
   414     delete iSession;
       
   415     iSession = NULL;
       
   416     iSessionOpen = EFalse;
       
   417 
       
   418     CallObserver( MMediaFileHandlerObserver::EError, aError );
       
   419     }
       
   420 
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // CMediaFileHandler::HandleQueryNewResults (from MMdEQueryObserver)
       
   424 // 
       
   425 // This observer function is called during query. Calling frequency is defined
       
   426 // in second parameter of CMdEQuery::FindL.
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CMediaFileHandler::HandleQueryNewResults( CMdEQuery& /*aQuery*/, 
       
   430                                                TInt /*aFirstNewItemIndex*/,
       
   431                                                TInt /*aNewItemCount*/ )
       
   432     {
       
   433     }
       
   434 
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CMediaFileHandler::HandleObjectNotification (MMdEObjectObserver)
       
   438 // 
       
   439 // Called when metadata database changes.
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 void CMediaFileHandler::HandleObjectNotification( CMdESession& /*aSession*/, 
       
   443 			                 			TObserverNotificationType aType,
       
   444 						                const RArray<TItemId>& aObjectIdArray )
       
   445     {
       
   446     const TInt KObserverCallStep = 100;
       
   447     
       
   448     if ( aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove )
       
   449         {
       
   450         if ( iObserver )
       
   451             {
       
   452             TInt count = aObjectIdArray.Count();
       
   453             FLOG( _L("CMediaFileHandler::HandleObjectNotification: count is %d"), count );
       
   454             
       
   455             iMediaFileCounter = iMediaFileCounter + count;
       
   456             if ( iMediaFileCounter >= KObserverCallStep )
       
   457                 {
       
   458                 iMediaFileCounter = 0;
       
   459                 TRAP_IGNORE( iObserver->HandleMFEventL(
       
   460                              MMediaFileHandlerObserver::EMediaFileChanged, KErrNone ) );
       
   461                 }
       
   462             else 
       
   463                 {
       
   464                 // delayed call to avoid many consecutive observer calls
       
   465                 CallObserverWithDelay();
       
   466                 }
       
   467             }
       
   468         }
       
   469     }
       
   470 
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CMediaFileHandler::HandleObjectPresentNotification (MMdEObjectPresentObserver)
       
   474 // 
       
   475 // Called when previously used memory card is inserted and hidden
       
   476 // metadata files are made present again.
       
   477 // -----------------------------------------------------------------------------
       
   478 //
       
   479 void CMediaFileHandler::HandleObjectPresentNotification( CMdESession& /*aSession*/, 
       
   480 			             TBool /*aPresent*/, const RArray<TItemId>& aObjectIdArray )
       
   481     {
       
   482     if ( iObserver )
       
   483         {
       
   484         TInt count = aObjectIdArray.Count();
       
   485         FLOG( _L("CMediaFileHandler::HandleObjectPresentNotification: count is %d"), count );
       
   486 
       
   487         // delayed call to avoid many consecutive observer calls
       
   488         CallObserverWithDelay();
       
   489         }
       
   490     }
       
   491 
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CMediaFileHandler::HandleQueryCompleted (MMdEQueryObserver)
       
   495 // 
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 void CMediaFileHandler::HandleQueryCompleted( CMdEQuery& aQuery, TInt aError )
       
   499     {
       
   500    
       
   501     TInt err = KErrNone;
       
   502     TRAP( err, HandleQueryCompletedL( aQuery, aError ) );
       
   503     
       
   504     if ( err == KErrCancel )
       
   505         {
       
   506         CallObserver( MMediaFileHandlerObserver::EQueryCanceled, KErrNone );
       
   507         }
       
   508     else if ( err != KErrNone )
       
   509         {
       
   510         iSearchList->Reset();
       
   511         TRAP_IGNORE( iArtistQuery->ResetL() );
       
   512 
       
   513         CallObserver( MMediaFileHandlerObserver::EError, err );
       
   514         }
       
   515     }
       
   516 
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CMediaFileHandler::HandleQueryCompletedL
       
   520 // 
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void CMediaFileHandler::HandleQueryCompletedL( CMdEQuery& /*aQuery*/, TInt aError )
       
   524     {
       
   525     TInt err = aError;
       
   526     
       
   527     if ( !iQuery && ( iRomScanState != MMediaFileHandlerObserver::ERomScanComplete 
       
   528     		&& (iQueryType == EQueryTone || iQueryType == ESearchTones )) )
       
   529         {
       
   530         err = KErrGeneral;
       
   531         }
       
   532     if ( err == KErrCancel )
       
   533         {
       
   534         if ( iQueryType == ESearchAudio || iQueryType == ESearchMusic || 
       
   535              iQueryType == ESearchTones || iQueryType == ESearchVideo )
       
   536             {
       
   537             iSearchList->Reset();
       
   538             }
       
   539         User::Leave( err );
       
   540         }
       
   541     if ( err != KErrNone )
       
   542         {
       
   543         User::Leave( err );
       
   544         }
       
   545     
       
   546     
       
   547     iSearchList->SetSession( iSession );
       
   548     
       
   549     TQueryResultMode resultMode = EQueryResultModeItem;
       
   550     if ( iQuery )
       
   551     	{
       
   552         resultMode = iQuery->ResultMode();
       
   553     	}
       
   554 
       
   555     
       
   556     if ( resultMode == EQueryResultModeDistinctValues )
       
   557         {
       
   558         iSearchList->Reset();
       
   559         iSearchList->TakeDistinctResultL( iQuery, KErrNotFound );
       
   560         iSearchList->SetSearchId( iQueryId );
       
   561         iSearchList->Sort();
       
   562 
       
   563         CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   564         }
       
   565     else if ( resultMode == EQueryResultModeCount )
       
   566         {
       
   567         // EQueryResultModeCount currently not used
       
   568         CallObserver( MMediaFileHandlerObserver::EUnknownQueryComplete, KErrNone );
       
   569         }
       
   570     else if ( resultMode == EQueryResultModeItem )
       
   571         {
       
   572         if ( iQueryType == ESearchAudio )
       
   573             {
       
   574             // ESearchAudio currently not used
       
   575             iSearchList->Reset();
       
   576             iSearchList->TakeResultL( iQuery, EMediaTypeMusic );
       
   577             iSearchList->Sort();
       
   578             iSearchList->SetSearchId( iQueryId );
       
   579             
       
   580             CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   581 
       
   582             /*
       
   583             // ESearchAudio currently not used
       
   584             iSearchList->Reset();
       
   585             iSearchList->TakeResultL( iQuery, EMediaTypeMusic );
       
   586             
       
   587             delete iIdle;
       
   588             iIdle = NULL;
       
   589             iIdle = CIdle::NewL( CActive::EPriorityIdle );                
       
   590             if ( iIdle )
       
   591                 {
       
   592                 iIdle->Start( TCallBack( SearchVideo, this ) );
       
   593                 }
       
   594             */
       
   595             }
       
   596         else if ( iQueryType == ESearchMusic )
       
   597             {
       
   598             // search is done in 3 steps (music, tones and videos)
       
   599             iSearchList->Reset();
       
   600             iSearchList->TakeResultL( iQuery, EMediaTypeMusic );
       
   601             
       
   602             // call SearchTonesL after short delay (iQuery cannot
       
   603             // be deleted in this function)
       
   604             delete iIdle;
       
   605             iIdle = NULL;
       
   606             iIdle = CIdle::NewL( CActive::EPriorityIdle );                
       
   607             if ( iIdle )
       
   608                 {
       
   609                 iIdle->Start( TCallBack( SearchTones, this ) );
       
   610                 }
       
   611             else
       
   612                 {
       
   613             	  User::Leave( KErrNoMemory );
       
   614                 }
       
   615             }
       
   616         else if ( iQueryType == ESearchTones )
       
   617             {
       
   618             iSearchList->SearchInToneL( iRomFileList, iSearchText );
       
   619             iQueryinProgress = EFalse;
       
   620             // call SearchVideosL after short delay (iQuery cannot
       
   621             // be deleted in this function)
       
   622             delete iIdle;
       
   623             iIdle = NULL;
       
   624             iIdle = CIdle::NewL( CActive::EPriorityIdle );                
       
   625             if ( iIdle )
       
   626                 {
       
   627                 iIdle->Start( TCallBack( SearchVideo, this ) );
       
   628                 }
       
   629             else
       
   630                 {
       
   631             	  User::Leave( KErrNoMemory );
       
   632                 }
       
   633             }
       
   634         else if ( iQueryType == ESearchVideo )
       
   635             {
       
   636             iSearchList->TakeResultL( iQuery, EMediaTypeVideo );
       
   637             iSearchList->VideoSearchInRomL( iRomFileList, iSearchText ); 
       
   638             iSearchList->Sort();
       
   639             iSearchList->SetSearchId( iQueryId );
       
   640             
       
   641             CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   642             }
       
   643         
       
   644         else if ( iQueryType == EQueryArtist )
       
   645             {
       
   646             // store CMdEObjectQuery to avoid multiple queries for one artist
       
   647             iArtistQuery->SetQuery( iQuery );
       
   648             iQuery = NULL;
       
   649            
       
   650             iSearchList->Reset();
       
   651             iSearchList->TakeArtistResultL( iArtistQuery );
       
   652             iSearchList->Sort();
       
   653             iSearchList->SetSearchId( iQueryId );
       
   654             
       
   655             CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   656             }
       
   657         else if ( iQueryType == EQueryArtistEmpty )
       
   658             {
       
   659             // use previously stored CMdEObjectQuery for artist query
       
   660             iSearchList->Reset();
       
   661             iSearchList->TakeArtistResultL( iArtistQuery );
       
   662             iSearchList->Sort();
       
   663             iSearchList->SetSearchId( iQueryId );
       
   664             
       
   665             CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   666             }
       
   667         else if ( iQueryType == EQueryEmpty )
       
   668             {
       
   669             iSearchList->Reset();
       
   670             iSearchList->SetSearchId( iQueryId );
       
   671                 
       
   672             CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   673             }
       
   674         else if ( iQueryType == EQueryUnknown )
       
   675             {
       
   676             iSearchList->Reset();
       
   677             iSearchList->TakeResultL( iQuery, EMediaTypeMusic );
       
   678             iSearchList->SetSearchId( iQueryId );     
       
   679             
       
   680             CallObserver( MMediaFileHandlerObserver::EUnknownQueryComplete, KErrNone );
       
   681             }
       
   682         else
       
   683             {
       
   684             TInt mediaType = MediaType( iQueryType );
       
   685             iSearchList->Reset();
       
   686             if ( mediaType == EMediaTypeTone )
       
   687             	{
       
   688             	iSearchList->AddRomItemL( iRomFileList, mediaType );
       
   689             	}
       
   690             else
       
   691             	{
       
   692             	iSearchList->TakeResultL( iQuery, mediaType );
       
   693             	if ( mediaType == EMediaTypeVideo )
       
   694             	    {
       
   695             	    iSearchList->AddRomItemL( iRomFileList, mediaType );
       
   696             	    }
       
   697             	}
       
   698             iQueryinProgress = EFalse;
       
   699             iSearchList->SetSearchId( iQueryId );
       
   700             iSearchList->Sort();
       
   701         
       
   702             CallObserver( MMediaFileHandlerObserver::EQueryComplete, KErrNone );
       
   703             }
       
   704         }
       
   705     else
       
   706         {
       
   707         CallObserver( MMediaFileHandlerObserver::EError, KErrNotSupported );
       
   708         }
       
   709     }
       
   710 
       
   711 
       
   712 // -----------------------------------------------------------------------------
       
   713 // CMediaFileHandler::QueryArtistL
       
   714 // 
       
   715 // Finds all music files for one artist. Query results are placed in
       
   716 // CArtistQuery.
       
   717 // CArtistQuery can then be used for artist subqueries (all albums, one album, 
       
   718 // all songs, unknown songs). 
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 void CMediaFileHandler::QueryArtistL( TInt aAttr, const TDesC& aArtist, 
       
   722                                       const TDesC& aAlbum, TBool aRefresh )
       
   723     {
       
   724     LeaveIfSessionClosedL();
       
   725 
       
   726     if ( aAttr != EQueryArtist && aAttr != EQueryArtistAlbum && 
       
   727          aAttr != EQueryArtistAll && aAttr != EQueryArtistUnknown )
       
   728         {
       
   729         User::Leave( KErrNotSupported );
       
   730         }
       
   731 
       
   732     TBool updateFromDatabase = aRefresh;
       
   733     if ( iArtistQuery->Artist().Compare( aArtist ) != 0 )
       
   734         {
       
   735         updateFromDatabase = ETrue;
       
   736         }
       
   737     
       
   738     if ( updateFromDatabase )
       
   739         {
       
   740         CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   741         CMdEObjectDef& objectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   742     
       
   743         delete iQuery;
       
   744         iQuery = NULL;
       
   745         iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
   746     
       
   747         // set attributes that are included in query result  
       
   748         CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
   749         iQuery->AddPropertyFilterL( &namePropertyDef );
       
   750         CMdEPropertyDef& albumPropertyDef = PropertyDefL( EAttrAlbum );
       
   751         iQuery->AddPropertyFilterL( &albumPropertyDef );
       
   752 
       
   753         CMdELogicCondition& conditions = iQuery->Conditions();
       
   754         CMdEPropertyDef& propertyDef = PropertyDefL( EAttrArtist );
       
   755         conditions.AddPropertyConditionL( propertyDef, 
       
   756                             ETextPropertyConditionCompareEquals, aArtist );
       
   757 
       
   758         iQuery->SetResultMode( EQueryResultModeItem );
       
   759     
       
   760         iArtistQuery->SetArtistL( aArtist );
       
   761         iArtistQuery->SetAlbumL( aAlbum );
       
   762         iQuery->FindL();
       
   763         iQueryType = EQueryArtist;
       
   764         }
       
   765     else
       
   766         {
       
   767         iArtistQuery->SetAlbumL( aAlbum );
       
   768         QueryArtistEmptyL();
       
   769         iQueryType = EQueryArtistEmpty;
       
   770         }
       
   771    
       
   772     iArtistQuery->SetQueryType( aAttr );
       
   773     }
       
   774 
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // CMediaFileHandler::QueryArtistEmptyL
       
   778 // 
       
   779 // Makes empty query. Query results were previously placed into CArtistQuery.
       
   780 // -----------------------------------------------------------------------------
       
   781 //
       
   782 void CMediaFileHandler::QueryArtistEmptyL()
       
   783     {
       
   784     LeaveIfSessionClosedL();
       
   785 
       
   786     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   787     CMdEObjectDef& objectDef = 
       
   788     defNS.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
   789     
       
   790     delete iQuery;
       
   791     iQuery = NULL;
       
   792     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
   793     
       
   794     iQuery->SetResultMode( EQueryResultModeItem );
       
   795  
       
   796     iQuery->FindL( 1 );
       
   797     
       
   798     iQueryType = EQueryArtistEmpty;
       
   799     }
       
   800 
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // CMediaFileHandler::QueryMusicL
       
   804 // 
       
   805 // Finds music files.
       
   806 // -----------------------------------------------------------------------------
       
   807 //
       
   808 void CMediaFileHandler::QueryMusicL( TInt /*aAttr*/ )
       
   809     {
       
   810     LeaveIfSessionClosedL();
       
   811        
       
   812     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   813     CMdEObjectDef& musicObjectDef =
       
   814     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   815   
       
   816     delete iQuery;
       
   817     iQuery = NULL;
       
   818     iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this );
       
   819     
       
   820     // set attributes that are included in query result  
       
   821     CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
   822     iQuery->AddPropertyFilterL( &namePropertyDef );
       
   823     CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType );
       
   824     iQuery->AddPropertyFilterL( &fileTypePropertyDef );
       
   825     
       
   826     
       
   827     CMdELogicCondition& conditions = iQuery->Conditions();
       
   828     
       
   829     // include properties that identify music
       
   830     IncludeMusicPropertiesL( conditions );
       
   831         
       
   832     //
       
   833     // example of defining sort order
       
   834     //
       
   835     // iQuery->AppendOrderRuleL( TMdEOrderRule( namePropertyDef, ESortAscending ) );
       
   836    
       
   837     iQuery->SetResultMode( EQueryResultModeItem );
       
   838    
       
   839     iQuery->FindL();
       
   840     
       
   841     iQueryType = EQueryMusic;
       
   842     }
       
   843 
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CMediaFileHandler::QueryMusicL
       
   847 // 
       
   848 // Finds music files with attibute that matches aFindText. Supported attributes
       
   849 // are EAttrArtist, EAttrAlbum, EAttrGenre and EAttrComposer.
       
   850 // -----------------------------------------------------------------------------
       
   851 //
       
   852 void CMediaFileHandler::QueryMusicL( TInt aAttr, const TDesC& aFindText )
       
   853     {
       
   854     LeaveIfSessionClosedL();
       
   855     CheckAttrL( aAttr );
       
   856     
       
   857     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   858     CMdEObjectDef& objectDef =
       
   859     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   860     
       
   861     delete iQuery;
       
   862     iQuery = NULL;
       
   863     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
   864     
       
   865     // set attributes that are included in query result  
       
   866     CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
   867     iQuery->AddPropertyFilterL( &namePropertyDef );
       
   868     
       
   869     CMdELogicCondition& conditions = iQuery->Conditions();
       
   870     CMdEPropertyDef& propertyDef = PropertyDefL( aAttr );
       
   871     conditions.AddPropertyConditionL( propertyDef, 
       
   872                             ETextPropertyConditionCompareEquals, aFindText );
       
   873     IncludeMusicPropertiesL( conditions );
       
   874     iQuery->SetResultMode( EQueryResultModeItem );
       
   875     
       
   876     iQuery->FindL();
       
   877     
       
   878     iQueryType = EQueryMusic;
       
   879     }
       
   880 
       
   881 
       
   882 // -----------------------------------------------------------------------------
       
   883 // CMediaFileHandler::QueryVideosL
       
   884 // 
       
   885 // Finds all video files.
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 void CMediaFileHandler::QueryVideosL( TInt /*aAttr*/ )
       
   889     {
       
   890     LeaveIfSessionClosedL();
       
   891 
       
   892     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   893     CMdEObjectDef& videoObjectDef =
       
   894     defNS.GetObjectDefL( MdeConstants::Video::KVideoObject );
       
   895    
       
   896     delete iQuery;
       
   897     iQuery = NULL;
       
   898     iQuery = iSession->NewObjectQueryL( defNS, videoObjectDef, this );
       
   899     
       
   900     // set attributes that are included in query result  
       
   901     CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
   902     iQuery->AddPropertyFilterL( &namePropertyDef );
       
   903     
       
   904     iQuery->SetResultMode( EQueryResultModeItem );
       
   905     
       
   906     iQuery->FindL();
       
   907     
       
   908     iQueryType = EQueryVideo;
       
   909     }
       
   910 
       
   911 
       
   912 // -----------------------------------------------------------------------------
       
   913 // CMediaFileHandler::QueryAttributeValuesL
       
   914 // 
       
   915 // Finds all different values for aAttr (all artists, albums, genres,
       
   916 // or composers).
       
   917 // -----------------------------------------------------------------------------
       
   918 //
       
   919 void CMediaFileHandler::QueryAttributeValuesL( TInt aAttr )
       
   920     {
       
   921     LeaveIfSessionClosedL();
       
   922     CheckAttrL( aAttr );
       
   923     
       
   924     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   925     CMdEObjectDef& objectDef =
       
   926     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   927  
       
   928     delete iQuery;
       
   929     iQuery = NULL;
       
   930     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
   931     
       
   932     iQuery->SetResultMode( EQueryResultModeDistinctValues );
       
   933     
       
   934     CMdEPropertyDef& propertyDef = PropertyDefL( aAttr );
       
   935     
       
   936     // distinct query requires exactly one property filter
       
   937     // (eg. attribute that is included in query result)
       
   938     CMdELogicCondition& conditions = iQuery->Conditions();
       
   939     conditions.AddPropertyConditionL( propertyDef );
       
   940     iQuery->AddPropertyFilterL( &propertyDef );
       
   941     IncludeMusicPropertiesL( conditions );
       
   942     iQuery->FindL();
       
   943     
       
   944     iQueryType = EQueryMusic;
       
   945     }
       
   946 
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // CMediaFileHandler::QueryMusicUnknownL
       
   950 // 
       
   951 // Find music files that do not have attribute aAttr (eg find all files without 
       
   952 // album attribute).
       
   953 // -----------------------------------------------------------------------------
       
   954 //
       
   955 void CMediaFileHandler::QueryMusicUnknownL( TInt aAttr )
       
   956     {
       
   957     LeaveIfSessionClosedL();
       
   958     CheckAttrL( aAttr );
       
   959  
       
   960     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
   961     CMdEObjectDef& objectDef =
       
   962     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   963 
       
   964     delete iQuery;
       
   965     iQuery = NULL;
       
   966     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
   967     
       
   968     iQuery->SetResultMode( EQueryResultModeItem );
       
   969     
       
   970     CMdEPropertyDef& propertyDef = PropertyDefL( aAttr );
       
   971     CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
   972     
       
   973     
       
   974     CMdELogicCondition& conditions = iQuery->Conditions();
       
   975     
       
   976     // include properties that identify music
       
   977     IncludeMusicPropertiesL( conditions );
       
   978     
       
   979     // add condition: get music that do not have aAttr attribute
       
   980     CMdELogicCondition& condition = 
       
   981         conditions.AddLogicConditionL( ELogicConditionOperatorAnd );
       
   982     condition.AddPropertyConditionL( propertyDef );
       
   983     condition.SetNegate( ETrue );
       
   984     
       
   985     // set attributes that are included in query result  
       
   986     iQuery->AddPropertyFilterL( &namePropertyDef );
       
   987     
       
   988     iQuery->FindL();
       
   989     
       
   990     iQueryType = EQueryMusic;
       
   991     }
       
   992 
       
   993 
       
   994 // -----------------------------------------------------------------------------
       
   995 // CMediaFileHandler::QueryMusicUnknownCountL
       
   996 // 
       
   997 // Find whether there are music files that do not have attribute aAttr
       
   998 // (eg files without album attribute)
       
   999 //
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 void CMediaFileHandler::QueryMusicUnknownCountL( TInt aAttr )
       
  1003     {
       
  1004     LeaveIfSessionClosedL();
       
  1005     CheckAttrL( aAttr );
       
  1006  
       
  1007     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1008     CMdEObjectDef& objectDef =
       
  1009     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1010 
       
  1011     delete iQuery;
       
  1012     iQuery = NULL;
       
  1013     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1014     
       
  1015     iQuery->SetResultMode( EQueryResultModeItem );
       
  1016     
       
  1017     CMdEPropertyDef& propertyDef = PropertyDefL( aAttr );
       
  1018     
       
  1019     CMdELogicCondition& conditions = iQuery->Conditions();
       
  1020 
       
  1021     // include properties that identify music
       
  1022     IncludeMusicPropertiesL( conditions );
       
  1023 
       
  1024     // add condition: get music that do not have aAttr attribute
       
  1025     CMdELogicCondition& condition = 
       
  1026         conditions.AddLogicConditionL( ELogicConditionOperatorAnd );
       
  1027     condition.AddPropertyConditionL( propertyDef );
       
  1028     condition.SetNegate( ETrue );
       
  1029       
       
  1030     
       
  1031     // count 0 or 1 is enough for UI
       
  1032     iQuery->FindL( 1 );     
       
  1033     iQueryType = EQueryUnknown;
       
  1034     }
       
  1035 
       
  1036 
       
  1037 // -----------------------------------------------------------------------------
       
  1038 // CMediaFileHandler::QueryEmptyL
       
  1039 // 
       
  1040 // Makes empty query.
       
  1041 // -----------------------------------------------------------------------------
       
  1042 //
       
  1043 void CMediaFileHandler::QueryEmptyL()
       
  1044     {
       
  1045     LeaveIfSessionClosedL();
       
  1046     iQueryType = EQueryEmpty;
       
  1047     if ( iQuery )
       
  1048     	{
       
  1049     	iQuery->SetResultMode( EQueryResultModeItem );
       
  1050     	HandleQueryCompleted( *iQuery , KErrNone);
       
  1051     	}
       
  1052     else
       
  1053     	{
       
  1054         CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1055         CMdEObjectDef& objectDef =
       
  1056         defNS.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
  1057         
       
  1058         delete iQuery;
       
  1059         iQuery = NULL;
       
  1060         iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1061 
       
  1062         iQuery->SetResultMode( EQueryResultModeItem );
       
  1063         iQuery->FindL( 0 );
       
  1064         
       
  1065     	}
       
  1066     }
       
  1067 
       
  1068 // -----------------------------------------------------------------------------
       
  1069 // CMediaFileHandler::QueryRomEmptyL( TInt aQueryType )
       
  1070 // 
       
  1071 // Makes empty query.
       
  1072 // -----------------------------------------------------------------------------
       
  1073 //
       
  1074 void CMediaFileHandler::QueryRomEmptyL( TInt aQueryType )
       
  1075     {
       
  1076     LeaveIfSessionClosedL();
       
  1077     if ( iQuery )
       
  1078     	{
       
  1079     	iQueryType = aQueryType;
       
  1080     	HandleQueryCompleted( *iQuery , KErrNone);
       
  1081     	}
       
  1082     else
       
  1083     	{
       
  1084         CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1085         CMdEObjectDef& objectDef =
       
  1086         defNS.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
  1087         
       
  1088         delete iQuery;
       
  1089         iQuery = NULL;
       
  1090         iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1091 
       
  1092         iQuery->SetResultMode( EQueryResultModeItem );
       
  1093         iQuery->FindL( 0 );
       
  1094         
       
  1095         iQueryType = aQueryType;
       
  1096     	}
       
  1097     }
       
  1098 
       
  1099 
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // CMediaFileHandler::QueryRecordingsL
       
  1102 // 
       
  1103 // Finds all recordings.
       
  1104 //
       
  1105 // Note: File is considered a recording if file extension is "amr" or "wav" and
       
  1106 //       file is not in rom.
       
  1107 // -----------------------------------------------------------------------------
       
  1108 //
       
  1109 void CMediaFileHandler::QueryRecordingsL( TInt /*aAttr*/ )
       
  1110     {
       
  1111     LeaveIfSessionClosedL();
       
  1112         
       
  1113     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1114     CMdEObjectDef& musicObjectDef =
       
  1115     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1116   
       
  1117     delete iQuery;
       
  1118     iQuery = NULL;
       
  1119     iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this );    
       
  1120     
       
  1121     
       
  1122     // set attributes that are included in query result  
       
  1123     CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
  1124     iQuery->AddPropertyFilterL( &namePropertyDef );
       
  1125     
       
  1126     iQuery->SetResultMode( EQueryResultModeItem );
       
  1127     
       
  1128     CMdEPropertyDef& fileTypeDef = PropertyDefL( EAttrMediaType );
       
  1129     
       
  1130     
       
  1131     CMdELogicCondition& conditions = iQuery->Conditions();
       
  1132     CMdEObjectCondition& cond = conditions.AddObjectConditionL(
       
  1133                                 EObjectConditionCompareUriBeginsWith, KDriveZ );
       
  1134     cond.SetNegate( ETrue );
       
  1135     
       
  1136     
       
  1137     CMdELogicCondition& condition = 
       
  1138         conditions.AddLogicConditionL( ELogicConditionOperatorOr );
       
  1139     condition.AddPropertyConditionL( fileTypeDef, 
       
  1140             ETextPropertyConditionCompareContains, KMimeTypeAMR );
       
  1141     condition.AddPropertyConditionL( fileTypeDef, 
       
  1142             ETextPropertyConditionCompareContains, KMimeTypeWAV );
       
  1143     
       
  1144     iQuery->FindL();
       
  1145     
       
  1146     iQueryType = EQueryRecording;
       
  1147     }
       
  1148 
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // CMediaFileHandler::QueryTonesL
       
  1152 // 
       
  1153 // Finds all tones.
       
  1154 // Note: Audio file is considered a tone if it is not music or video.
       
  1155 // -----------------------------------------------------------------------------
       
  1156 //
       
  1157 void CMediaFileHandler::QueryTonesL( TInt /*aAttr*/ )
       
  1158     {
       
  1159     LeaveIfSessionClosedL();
       
  1160         
       
  1161     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1162     CMdEObjectDef& musicObjectDef =
       
  1163     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1164   
       
  1165     delete iQuery;
       
  1166     iQuery = NULL;
       
  1167     iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this );    
       
  1168     
       
  1169     
       
  1170     // set attributes that are included in query result  
       
  1171     CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
  1172     iQuery->AddPropertyFilterL( &namePropertyDef );
       
  1173     
       
  1174     iQuery->SetResultMode( EQueryResultModeItem );
       
  1175     
       
  1176     CMdELogicCondition& conditions = iQuery->Conditions();
       
  1177     ExcludeMusicPropertiesL( conditions );
       
  1178 
       
  1179     iQuery->FindL();
       
  1180     
       
  1181     iQueryType = EQueryTone;
       
  1182     }
       
  1183 
       
  1184 
       
  1185 // -----------------------------------------------------------------------------
       
  1186 // CMediaFileHandler::QueryDefaultTonesL
       
  1187 // 
       
  1188 // Finds all sound files from rom (nokia default tones).
       
  1189 // -----------------------------------------------------------------------------
       
  1190 //
       
  1191 void CMediaFileHandler::QueryDefaultTonesL( TInt /*aAttr*/ )
       
  1192     {
       
  1193     
       
  1194     if ( iRomScanState == MMediaFileHandlerObserver::ERomScanComplete )
       
  1195     	{
       
  1196     	QueryRomEmptyL( EQueryTone );
       
  1197     	}
       
  1198     else if ( iRomScanState == MMediaFileHandlerObserver::ERomScanInProgress )
       
  1199     	{
       
  1200     	iQueryinProgress = ETrue;
       
  1201     	}
       
  1202     else
       
  1203     	{
       
  1204     	//Rom scan not start or failed for some reason
       
  1205     	iQueryinProgress = ETrue;
       
  1206     	StartRomScaning( EQueryTone );
       
  1207     	}
       
  1208     }
       
  1209 
       
  1210 // -----------------------------------------------------------------------------
       
  1211 // CMediaFileHandler::QueryDefaultTTonessL
       
  1212 // 
       
  1213 // Finds all sound files from rom (nokia default tones).
       
  1214 // -----------------------------------------------------------------------------
       
  1215 //
       
  1216 //void CMediaFileHandler::QueryDefaultTonesL( TInt /*aAttr*/ )
       
  1217 //    {
       
  1218 //    LeaveIfSessionClosedL();
       
  1219 //        
       
  1220 //    CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1221 //    CMdEObjectDef& musicObjectDef =
       
  1222 //    defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1223 //  
       
  1224 //    delete iQuery;
       
  1225 //    iQuery = NULL;
       
  1226 //    iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this );    
       
  1227 //    
       
  1228 //    
       
  1229 //    // set attributes that are included in query result  
       
  1230 //    CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName );
       
  1231 //    iQuery->AddPropertyFilterL( &namePropertyDef );
       
  1232 //    
       
  1233 //    iQuery->SetResultMode( EQueryResultModeItem );
       
  1234 //    
       
  1235 //    CMdELogicCondition& conditions = iQuery->Conditions();
       
  1236 //    CMdEObjectCondition& cond = conditions.AddObjectConditionL(
       
  1237 //                                EObjectConditionCompareUriBeginsWith, KDriveZ );
       
  1238 //
       
  1239 //    iQuery->FindL();
       
  1240 //    
       
  1241 //    iQueryType = EQueryTone;
       
  1242 //    }
       
  1243 
       
  1244 // -----------------------------------------------------------------------------
       
  1245 // CMediaFileHandler::SearchL
       
  1246 // 
       
  1247 // Finds all music, tone and video files with any attibute that
       
  1248 // matches aFindText.
       
  1249 // -----------------------------------------------------------------------------
       
  1250 //
       
  1251 void CMediaFileHandler::SearchL( const TDesC& aSearchText )
       
  1252     {
       
  1253     //
       
  1254     // search is done in 3 steps, SearchTonesL and SearchVideoL are
       
  1255     // called after SearchMusicL is done. Search results are collected
       
  1256     // in iSearchList.
       
  1257     //
       
  1258     
       
  1259     if ( aSearchText.Length() == 0 )
       
  1260         {
       
  1261         iSearchText = KNullDesC;
       
  1262         QueryEmptyL();
       
  1263         }
       
  1264     else
       
  1265         {
       
  1266         StrCopy( iSearchText, aSearchText );
       
  1267         SearchMusicL( iSearchText );
       
  1268         }
       
  1269     }
       
  1270 
       
  1271 
       
  1272 // -----------------------------------------------------------------------------
       
  1273 // CMediaFileHandler::SearchAudioL
       
  1274 // 
       
  1275 // Finds all audio files with attibute that matches aFindText.
       
  1276 // Searched attributes are name, artist, album, genre, composer.
       
  1277 // -----------------------------------------------------------------------------
       
  1278 //
       
  1279 void CMediaFileHandler::SearchAudioL( const TDesC& aSearchText )
       
  1280     {
       
  1281     SearchMusicL( aSearchText );
       
  1282     iQueryType = ESearchAudio;
       
  1283     
       
  1284     /*
       
  1285     LeaveIfSessionClosedL();
       
  1286 
       
  1287     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1288     CMdEObjectDef& objectDef =
       
  1289     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1290 
       
  1291     delete iQuery;
       
  1292     iQuery = NULL;
       
  1293     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1294     
       
  1295     // set attributes that are included in query result  
       
  1296     CMdEPropertyDef& song = PropertyDefL( EAttrSongName );
       
  1297     iQuery->AddPropertyFilterL( &song );
       
  1298     
       
  1299     CMdEPropertyDef& artist = PropertyDefL( EAttrArtist );
       
  1300     iQuery->AddPropertyFilterL( &artist );
       
  1301     CMdEPropertyDef& album = PropertyDefL( EAttrAlbum );
       
  1302     iQuery->AddPropertyFilterL( &album );
       
  1303     CMdEPropertyDef& genre = PropertyDefL( EAttrGenre );
       
  1304     iQuery->AddPropertyFilterL( &genre );
       
  1305     CMdEPropertyDef& composer = PropertyDefL( EAttrComposer );
       
  1306     iQuery->AddPropertyFilterL( &composer );
       
  1307   
       
  1308     CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType );
       
  1309     iQuery->AddPropertyFilterL( &fileTypePropertyDef );
       
  1310 
       
  1311     
       
  1312     CMdELogicCondition& conditions = iQuery->Conditions();
       
  1313     conditions.SetOperator( ELogicConditionOperatorAnd );
       
  1314     
       
  1315     IncludeMusicSearchConditionL( conditions, aSearchText );
       
  1316     
       
  1317     
       
  1318 
       
  1319     // iQuery->AppendOrderRuleL( TMdEOrderRule( song, ESortAscending ) );                            
       
  1320     iQuery->SetResultMode( EQueryResultModeItem );
       
  1321     iQuery->FindL();
       
  1322     
       
  1323     iQueryType = ESearchAudio;
       
  1324     */
       
  1325     }
       
  1326 
       
  1327 
       
  1328 // -----------------------------------------------------------------------------
       
  1329 // CMediaFileHandler::SearchMusicL
       
  1330 // 
       
  1331 // Finds all music with attibute that matches aFindText.
       
  1332 // Searched attributes are name, artist, album, genre, composer.
       
  1333 // -----------------------------------------------------------------------------
       
  1334 //
       
  1335 void CMediaFileHandler::SearchMusicL( const TDesC& aSearchText )
       
  1336     {
       
  1337     LeaveIfSessionClosedL();
       
  1338 
       
  1339     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1340     CMdEObjectDef& objectDef =
       
  1341     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1342 
       
  1343     delete iQuery;
       
  1344     iQuery = NULL;
       
  1345     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1346     
       
  1347     // set attributes that are included in query result  
       
  1348     CMdEPropertyDef& songName = PropertyDefL( EAttrSongName );
       
  1349     iQuery->AddPropertyFilterL( &songName );
       
  1350     CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType );
       
  1351     iQuery->AddPropertyFilterL( &fileTypePropertyDef );
       
  1352 
       
  1353     
       
  1354     CMdELogicCondition& conditions = iQuery->Conditions();
       
  1355     conditions.SetOperator( ELogicConditionOperatorAnd );
       
  1356     
       
  1357     //IncludeMusicPropertiesL( conditions );
       
  1358     IncludeMusicSearchConditionL( conditions, aSearchText );
       
  1359 
       
  1360     iQuery->SetResultMode( EQueryResultModeItem );
       
  1361     iQuery->FindL();
       
  1362     
       
  1363     iQueryType = ESearchMusic;
       
  1364     }
       
  1365 
       
  1366 
       
  1367 // -----------------------------------------------------------------------------
       
  1368 // CMediaFileHandler::SearchTonesL
       
  1369 // 
       
  1370 // Finds all tones with attibute that matches aFindText.
       
  1371 // Searched attribute is file name.
       
  1372 // -----------------------------------------------------------------------------
       
  1373 //
       
  1374 void CMediaFileHandler::SearchTonesL( const TDesC& /*aSearchText */)
       
  1375     {
       
  1376     if ( iRomScanState == MMediaFileHandlerObserver::ERomScanComplete )
       
  1377     	{
       
  1378     	QueryRomEmptyL( ESearchTones );
       
  1379     	}
       
  1380     else if ( iRomScanState == MMediaFileHandlerObserver::ERomScanInProgress )
       
  1381     	{
       
  1382     	iQueryinProgress = ETrue;
       
  1383     	}
       
  1384     else
       
  1385     	{
       
  1386     	//Rom scan not start or failed for some reason
       
  1387     	iQueryinProgress = ETrue;
       
  1388     	StartRomScaning( ESearchTones );
       
  1389     	}
       
  1390     }
       
  1391 
       
  1392 //
       
  1393 //// -----------------------------------------------------------------------------
       
  1394 //// CMediaFileHandler::SearchTonesL
       
  1395 //// 
       
  1396 //// Finds all tones with attibute that matches aFindText.
       
  1397 //// Searched attribute is file name.
       
  1398 //// -----------------------------------------------------------------------------
       
  1399 ////
       
  1400 //void CMediaFileHandler::SearchTonesL( const TDesC& aSearchText )
       
  1401 //    {
       
  1402 //    LeaveIfSessionClosedL();
       
  1403 //
       
  1404 //    CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1405 //    CMdEObjectDef& objectDef =
       
  1406 //    defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1407 //
       
  1408 //    delete iQuery;
       
  1409 //    iQuery = NULL;
       
  1410 //    iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1411 //    
       
  1412 //    // set attributes that are included in query result  
       
  1413 //    CMdEPropertyDef& songName = PropertyDefL( EAttrSongName );
       
  1414 //    iQuery->AddPropertyFilterL( &songName );
       
  1415 //    CMdEPropertyDef& fileTypePropertyDef = PropertyDefL( EAttrMediaType );
       
  1416 //    iQuery->AddPropertyFilterL( &fileTypePropertyDef );
       
  1417 //
       
  1418 //    
       
  1419 //    CMdELogicCondition& conditions = iQuery->Conditions();
       
  1420 //    conditions.SetOperator( ELogicConditionOperatorAnd );
       
  1421 //    
       
  1422 //    //ExcludeMusicPropertiesL( conditions );
       
  1423 //    CMdEObjectCondition& cond = conditions.AddObjectConditionL(
       
  1424 //                                EObjectConditionCompareUriBeginsWith, KDriveZ );
       
  1425 //    
       
  1426 //    IncludeToneSearchConditionL( conditions, aSearchText );
       
  1427 //
       
  1428 //    iQuery->SetResultMode( EQueryResultModeItem );
       
  1429 //    iQuery->FindL();
       
  1430 //    
       
  1431 //    iQueryType = ESearchTones;
       
  1432 //    }
       
  1433 
       
  1434 
       
  1435 
       
  1436 // -----------------------------------------------------------------------------
       
  1437 // CMediaFileHandler::SearchVideoL
       
  1438 //
       
  1439 // Finds all videos with attibute that matches aFindText.
       
  1440 // Searched attributes are name, artist, genre.
       
  1441 // -----------------------------------------------------------------------------
       
  1442 //
       
  1443 void CMediaFileHandler::SearchVideoL( const TDesC& aSearchText )
       
  1444     {
       
  1445     LeaveIfSessionClosedL();
       
  1446     if ( iRomScanState != MMediaFileHandlerObserver::ERomScanComplete )
       
  1447         {
       
  1448         
       
  1449         StartRomScaning( ESearchVideo );
       
  1450         }
       
  1451     
       
  1452     CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL();
       
  1453     CMdEObjectDef& objectDef =
       
  1454     defNS.GetObjectDefL( MdeConstants::Video::KVideoObject );
       
  1455 
       
  1456     delete iQuery;
       
  1457     iQuery = NULL;
       
  1458     iQuery = iSession->NewObjectQueryL( defNS, objectDef, this );
       
  1459     
       
  1460     // set attributes that are included in query result  
       
  1461     CMdEPropertyDef& songName = PropertyDefL( EAttrSongName );
       
  1462     iQuery->AddPropertyFilterL( &songName );
       
  1463     
       
  1464     CMdELogicCondition& conditions = iQuery->Conditions();
       
  1465     IncludeVideoSearchConditionL( conditions, aSearchText );
       
  1466    
       
  1467     iQuery->SetResultMode( EQueryResultModeItem );
       
  1468     
       
  1469     if ( iVideoSearchDisabled )
       
  1470         {
       
  1471         iQuery->FindL( 0 );
       
  1472         }
       
  1473     else
       
  1474         {
       
  1475         iQuery->FindL();    
       
  1476         }
       
  1477     
       
  1478     iQueryType = ESearchVideo;
       
  1479     }
       
  1480 
       
  1481 
       
  1482 // -----------------------------------------------------------------------------
       
  1483 // CMediaFileDialog::SearchVideo
       
  1484 //
       
  1485 // -----------------------------------------------------------------------------
       
  1486 //
       
  1487 TInt CMediaFileHandler::SearchVideo( TAny *aObj )
       
  1488     {    
       
  1489     CMediaFileHandler* handler = (CMediaFileHandler*) aObj;
       
  1490     
       
  1491     TInt err = KErrNone;
       
  1492     TRAP( err, handler->SearchVideoL( handler->iSearchText ) );
       
  1493     
       
  1494     if ( err != KErrNone )
       
  1495         {
       
  1496         handler->CallObserver( MMediaFileHandlerObserver::EError, err );
       
  1497         }
       
  1498     
       
  1499     return 0;
       
  1500     }
       
  1501 
       
  1502 
       
  1503 // -----------------------------------------------------------------------------
       
  1504 // CMediaFileDialog::SearchTones
       
  1505 //
       
  1506 // -----------------------------------------------------------------------------
       
  1507 //
       
  1508 TInt CMediaFileHandler::SearchTones( TAny *aObj )
       
  1509     {    
       
  1510     CMediaFileHandler* handler = (CMediaFileHandler*) aObj;
       
  1511     
       
  1512     TInt err = KErrNone;
       
  1513     TRAP( err, handler->SearchTonesL( handler->iSearchText ) );
       
  1514     
       
  1515     if ( err != KErrNone )
       
  1516         {
       
  1517         handler->CallObserver( MMediaFileHandlerObserver::EError, err );
       
  1518         }
       
  1519     
       
  1520     return 0;
       
  1521     }
       
  1522 
       
  1523 
       
  1524 // -----------------------------------------------------------------------------
       
  1525 // CMediaFileHandler::ResultCount
       
  1526 // 
       
  1527 // -----------------------------------------------------------------------------
       
  1528 //
       
  1529 TInt CMediaFileHandler::ResultCount()
       
  1530     {
       
  1531     if ( !iSessionOpen )
       
  1532         {
       
  1533         return 0;
       
  1534         }
       
  1535     
       
  1536     return iSearchList->Count();
       
  1537     }
       
  1538 
       
  1539 // -----------------------------------------------------------------------------
       
  1540 // CMediaFileHandler::Remove
       
  1541 // Remove an item from list of search reuslt
       
  1542 // -----------------------------------------------------------------------------
       
  1543 //
       
  1544 void CMediaFileHandler::Remove( TInt aIndex )
       
  1545     {
       
  1546     if( aIndex >= ResultCount() )
       
  1547         {
       
  1548         // Invalid index
       
  1549         return;
       
  1550         }
       
  1551     iSearchList->Remove( aIndex );    
       
  1552     }
       
  1553     
       
  1554 // -----------------------------------------------------------------------------
       
  1555 // CMediaFileHandler::UnknownArtistCount
       
  1556 // 
       
  1557 // Returns 1 if artist has at least one music file without album attribute,
       
  1558 // 0 otherwise.
       
  1559 // -----------------------------------------------------------------------------
       
  1560 //
       
  1561 TInt CMediaFileHandler::UnknownArtistCount()
       
  1562     {
       
  1563     TInt ret = 0;
       
  1564     
       
  1565     TInt err = KErrNone;
       
  1566     TRAP( err, ret = UnknownArtistCountL() );
       
  1567     if ( err != KErrNone )
       
  1568         {
       
  1569         ret = 0;
       
  1570         }
       
  1571     return ret;
       
  1572     }
       
  1573 
       
  1574 
       
  1575 // -----------------------------------------------------------------------------
       
  1576 // CMediaFileHandler::UnknownArtistCountL
       
  1577 // 
       
  1578 // Returns 1 if artist has at least one music file without album attribute,
       
  1579 // 0 otherwise.
       
  1580 // -----------------------------------------------------------------------------
       
  1581 //
       
  1582 TInt CMediaFileHandler::UnknownArtistCountL()
       
  1583     {
       
  1584     CMdEObjectQuery* artistQuery = iArtistQuery->Query();
       
  1585     if ( !artistQuery )
       
  1586         {
       
  1587         return 0;
       
  1588         }
       
  1589 
       
  1590     TInt count = artistQuery->Count();
       
  1591     for ( TInt i=0; i<count; i++ )
       
  1592         {
       
  1593         CMdEObject& object = artistQuery->Result( i );
       
  1594         
       
  1595         CMdEPropertyDef& propDef = 
       
  1596         CMediaFileHandler::PropertyDefL( iSession, CMediaFileHandler::EAttrAlbum );
       
  1597         
       
  1598         CMdEProperty* property = NULL;
       
  1599         TInt ret = object.Property( propDef, property, 0 );
       
  1600         if ( ret == KErrNotFound )
       
  1601             {
       
  1602             return 1;
       
  1603             }
       
  1604         }    
       
  1605     
       
  1606     return 0;
       
  1607     }
       
  1608 // -----------------------------------------------------------------------------
       
  1609 // void CMediaFileHandler::StartRomScaning()
       
  1610 // 
       
  1611 // Start rom scanning
       
  1612 // -----------------------------------------------------------------------------
       
  1613 //
       
  1614 
       
  1615 void CMediaFileHandler::StartRomScaning( TInt aQueryType )
       
  1616     {
       
  1617     
       
  1618     if ( iRomScanState != MMediaFileHandlerObserver::ERomScanComplete )
       
  1619         {
       
  1620         iRomScanState = MMediaFileHandlerObserver::ERomScanInProgress;
       
  1621         iRomFileList->Reset();
       
  1622         TRAPD( err , iRomFileList->ReadRomFilesL() );
       
  1623         if ( err != KErrNone )
       
  1624             {
       
  1625             iRomScanState = MMediaFileHandlerObserver::ERomScanError;
       
  1626             }
       
  1627         else
       
  1628             {
       
  1629             iRomScanState = MMediaFileHandlerObserver::ERomScanComplete;
       
  1630             }
       
  1631         }
       
  1632     
       
  1633     iSearchList->SetRomFileList( iRomFileList );
       
  1634     
       
  1635     if ( iQueryinProgress )
       
  1636         {
       
  1637         QueryRomEmptyL( aQueryType );
       
  1638     	}
       
  1639     
       
  1640     CallObserver( MMediaFileHandlerObserver::EScanRomComplete, KErrNone );
       
  1641     }
       
  1642 
       
  1643 // -----------------------------------------------------------------------------
       
  1644 // CMediaFileHandler::CancelQuery
       
  1645 // 
       
  1646 // Cancels ongoing query.
       
  1647 // -----------------------------------------------------------------------------
       
  1648 //
       
  1649 void CMediaFileHandler::CancelQuery()
       
  1650     {
       
  1651     if ( !iSessionOpen || !iQuery )
       
  1652         {
       
  1653         return;
       
  1654         }
       
  1655     
       
  1656     if ( !iQuery->IsComplete() )
       
  1657         {
       
  1658         iQuery->Cancel(); // this calls HandleQueryCompleted synchronously
       
  1659         }
       
  1660     }
       
  1661 
       
  1662 
       
  1663 // -----------------------------------------------------------------------------
       
  1664 // CMediaFileHandler::LeaveIfSessionClosedL
       
  1665 // 
       
  1666 // -----------------------------------------------------------------------------
       
  1667 //
       
  1668 void CMediaFileHandler::LeaveIfSessionClosedL()
       
  1669     {
       
  1670     if ( !iSession || !iSessionOpen )
       
  1671         {
       
  1672         User::Leave( KErrDisconnected );
       
  1673         }
       
  1674     }
       
  1675 
       
  1676 
       
  1677 // -----------------------------------------------------------------------------
       
  1678 // CMediaFileHandler::SetObserver
       
  1679 // 
       
  1680 // -----------------------------------------------------------------------------
       
  1681 //
       
  1682 void CMediaFileHandler::SetObserver( MMediaFileHandlerObserver* aObserver )
       
  1683     {
       
  1684     iObserver = aObserver;
       
  1685     }
       
  1686 
       
  1687 
       
  1688 // -----------------------------------------------------------------------------
       
  1689 // CMediaFileHandler::CheckAttrL
       
  1690 // 
       
  1691 // -----------------------------------------------------------------------------
       
  1692 //
       
  1693 void CMediaFileHandler::CheckAttrL( TInt aAttr )
       
  1694     {
       
  1695     if ( aAttr != EAttrArtist && aAttr != EAttrAlbum &&
       
  1696          aAttr != EAttrGenre && aAttr != EAttrComposer )
       
  1697         {
       
  1698         User::Leave( KErrNotSupported );
       
  1699         }
       
  1700     }
       
  1701 
       
  1702 
       
  1703 // -----------------------------------------------------------------------------
       
  1704 // CMediaFileHandler::GetAttributeL
       
  1705 // 
       
  1706 // NOTE: GetAttributeL only gets full name or file name
       
  1707 // -----------------------------------------------------------------------------
       
  1708 //
       
  1709 void CMediaFileHandler::GetAttributeL( TInt aIndex, TInt aAttr, 
       
  1710                                        TDes& aValue, TInt aQueryId )
       
  1711     {
       
  1712     aValue = KNullDesC;
       
  1713     
       
  1714     if ( !iSessionOpen )
       
  1715          {
       
  1716          return;
       
  1717          }
       
  1718     
       
  1719     TInt id = iSearchList->SearchId();
       
  1720     if ( id != aQueryId )
       
  1721         {
       
  1722         return; // search list and UI do not match
       
  1723         }
       
  1724     
       
  1725     iSearchList->SetSession( iSession );
       
  1726     iSearchList->GetAttributeL( aIndex, aAttr, aValue );
       
  1727     }
       
  1728 
       
  1729 
       
  1730     
       
  1731 // -----------------------------------------------------------------------------
       
  1732 // CMediaFileHandler::GetAttribute
       
  1733 // 
       
  1734 // -----------------------------------------------------------------------------
       
  1735 //
       
  1736 void CMediaFileHandler::GetAttribute( TInt aIndex, TInt aAttr,
       
  1737                                       TDes& aValue, TInt aQueryId  )
       
  1738     {
       
  1739     TRAP_IGNORE( GetAttributeL( aIndex, aAttr, aValue, aQueryId ) );
       
  1740     }
       
  1741 
       
  1742 
       
  1743 // -----------------------------------------------------------------------------
       
  1744 // CMediaFileHandler::Attribute
       
  1745 // 
       
  1746 // -----------------------------------------------------------------------------
       
  1747 //
       
  1748 TInt CMediaFileHandler::Attribute( TInt aIndex, TInt aAttr, TInt aQueryId )
       
  1749     {
       
  1750     if ( !iSessionOpen )
       
  1751          {
       
  1752          return KErrNotFound;
       
  1753          }
       
  1754      
       
  1755     TInt id = iSearchList->SearchId();
       
  1756     if ( id != aQueryId )
       
  1757         {
       
  1758         return KErrNotFound;
       
  1759         }
       
  1760     
       
  1761     return iSearchList->Attribute( aIndex, aAttr );
       
  1762     }
       
  1763 
       
  1764 
       
  1765 // -----------------------------------------------------------------------------
       
  1766 // CMediaFileHandler::ItemIndex
       
  1767 // 
       
  1768 // -----------------------------------------------------------------------------
       
  1769 //
       
  1770 TInt CMediaFileHandler::ItemIndex( TInt aItemId, TInt aIndex )
       
  1771     {
       
  1772     return iSearchList->ItemIndex( aItemId, aIndex );
       
  1773     }
       
  1774 
       
  1775 
       
  1776 // -----------------------------------------------------------------------------
       
  1777 // CMediaFileHandler::ItemIndex
       
  1778 // 
       
  1779 // -----------------------------------------------------------------------------
       
  1780 //
       
  1781 TInt CMediaFileHandler::ItemIndex( const TDesC& aItemText, TInt aIndex )
       
  1782     {
       
  1783     return iSearchList->ItemIndex( aItemText, aIndex );
       
  1784     }
       
  1785 
       
  1786 
       
  1787 // -----------------------------------------------------------------------------
       
  1788 // CMediaFileHandler::ReadMediaFileDataL
       
  1789 // 
       
  1790 // -----------------------------------------------------------------------------
       
  1791 //
       
  1792 CMediaFileData* CMediaFileHandler::ReadMediaFileDataL( TInt aId )
       
  1793     {
       
  1794     if ( !iSessionOpen )
       
  1795         {
       
  1796         User::Leave( KErrNotFound );
       
  1797         }
       
  1798     
       
  1799     CMdEObject* object = iSession->GetFullObjectL( aId );
       
  1800     CleanupStack::PushL( object );
       
  1801     
       
  1802     CMediaFileData* data = CMediaFileData::NewL();
       
  1803     CleanupStack::PushL( data );
       
  1804     
       
  1805     data->SetAttrL( EAttrFullName, object->Uri() );
       
  1806     
       
  1807     CMdEProperty* property = NULL;
       
  1808     TInt ret = object->Property( PropertyDefL( EAttrSongName ), property, 0 );
       
  1809     if ( ret != KErrNotFound )
       
  1810         {
       
  1811         data->SetAttrL( EAttrSongName, property->TextValueL() );
       
  1812         }
       
  1813     
       
  1814     ret = object->Property( PropertyDefL( EAttrArtist ), property, 0 );
       
  1815     if ( ret != KErrNotFound )
       
  1816         {
       
  1817         data->SetAttrL( EAttrArtist, property->TextValueL() );
       
  1818         }
       
  1819     
       
  1820     ret = object->Property( PropertyDefL( EAttrAlbum ), property, 0 );
       
  1821     if ( ret != KErrNotFound )
       
  1822         {
       
  1823         data->SetAttrL( EAttrAlbum, property->TextValueL() );
       
  1824         }
       
  1825     
       
  1826     ret = object->Property( PropertyDefL( EAttrGenre ), property, 0 );
       
  1827     if ( ret != KErrNotFound )
       
  1828         {
       
  1829         data->SetAttrL( EAttrGenre, property->TextValueL() );
       
  1830         }
       
  1831     
       
  1832     ret = object->Property( PropertyDefL( EAttrComposer ), property, 0 );
       
  1833     if ( ret != KErrNotFound )
       
  1834         {
       
  1835         data->SetAttrL( EAttrComposer, property->TextValueL() );
       
  1836         }
       
  1837 
       
  1838     CleanupStack::Pop( data );
       
  1839     CleanupStack::PopAndDestroy( object );
       
  1840     
       
  1841     return data;
       
  1842     }
       
  1843 
       
  1844 // -----------------------------------------------------------------------------
       
  1845 // CMediaFileHandler::ReadMediaFileDataL
       
  1846 // 
       
  1847 // -----------------------------------------------------------------------------
       
  1848 //
       
  1849 CMediaFileData* CMediaFileHandler::RomMediaFileDataL( TInt aId ,TInt aMediaType )
       
  1850     {
       
  1851     if (!iRomFileList)
       
  1852         {
       
  1853         User::Leave(KErrNotFound);
       
  1854         }
       
  1855 
       
  1856     TBuf<KBufSize128> buf;
       
  1857     CMediaFileData* data = CMediaFileData::NewL();
       
  1858     CleanupStack::PushL(data);
       
  1859 
       
  1860     if (aMediaType == EMediaTypeTone)
       
  1861         {
       
  1862         data->SetAttrL(EAttrFullName, iRomFileList->Item(aId, 0));
       
  1863         iRomFileList->GetRomFileName(aId, 0, buf);
       
  1864         data->SetAttrL(EAttrSongName, buf);
       
  1865         }
       
  1866 
       
  1867     if (aMediaType == EMediaTypeVideo)
       
  1868         {
       
  1869         data->SetAttrL(EAttrFullName, iRomFileList->Item(aId, 1));
       
  1870         iRomFileList->GetRomFileName(aId, 1, buf);
       
  1871         data->SetAttrL(EAttrSongName, buf);
       
  1872         }
       
  1873 
       
  1874     CleanupStack::Pop(data);
       
  1875 
       
  1876     return data;
       
  1877     }
       
  1878 
       
  1879 
       
  1880 // -----------------------------------------------------------------------------
       
  1881 // CMediaFileHandler::PropertyDefL
       
  1882 // 
       
  1883 // -----------------------------------------------------------------------------
       
  1884 //
       
  1885 CMdEPropertyDef& CMediaFileHandler::PropertyDefL( TInt aAttr )
       
  1886     {
       
  1887     return PropertyDefL( iSession, aAttr );
       
  1888     }
       
  1889 
       
  1890 
       
  1891 // -----------------------------------------------------------------------------
       
  1892 // CMediaFileHandler::PropertyDefL
       
  1893 // 
       
  1894 // -----------------------------------------------------------------------------
       
  1895 //
       
  1896 CMdEPropertyDef& CMediaFileHandler::PropertyDefL( CMdESession* aSession, TInt aAttr )
       
  1897     {
       
  1898     CMdENamespaceDef& defNS = aSession->GetDefaultNamespaceDefL();
       
  1899     
       
  1900     CMdEObjectDef& objectDef =
       
  1901     defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
  1902    
       
  1903     if ( aAttr == EAttrFileSize )
       
  1904         {
       
  1905         return objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
       
  1906         }
       
  1907     else if ( aAttr == EAttrMediaType )
       
  1908         {
       
  1909         return objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
       
  1910         }
       
  1911     else if ( aAttr == EAttrSongName || aAttr == EAttrFileName )
       
  1912         {
       
  1913         return objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
  1914         }
       
  1915     else if ( aAttr == EAttrArtist )
       
  1916         {
       
  1917         return objectDef.GetPropertyDefL( MdeConstants::MediaObject::KArtistProperty );
       
  1918         }
       
  1919     else if ( aAttr == EAttrAlbum )
       
  1920         {
       
  1921         return objectDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty );
       
  1922         }
       
  1923     else if ( aAttr == EAttrGenre )
       
  1924         {
       
  1925         return objectDef.GetPropertyDefL( MdeConstants::MediaObject::KGenreProperty );
       
  1926         }
       
  1927     else if ( aAttr == EAttrComposer )
       
  1928         {
       
  1929         return objectDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty );
       
  1930         }
       
  1931     else
       
  1932         {
       
  1933         User::Leave( KErrNotSupported );
       
  1934         }
       
  1935     
       
  1936     return objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
  1937     }
       
  1938 
       
  1939 
       
  1940 // -----------------------------------------------------------------------------
       
  1941 // CMediaFileHandler::QueryReady
       
  1942 //
       
  1943 // -----------------------------------------------------------------------------
       
  1944 //
       
  1945 TBool CMediaFileHandler::QueryReady() 
       
  1946     {
       
  1947     if ( iIdle )
       
  1948         {
       
  1949         TBool isSearching = iIdle->IsActive();
       
  1950         if ( isSearching )
       
  1951             {
       
  1952             return EFalse; // we are between audio, tone and and video search
       
  1953             }
       
  1954         }
       
  1955     
       
  1956     TBool isWaitingObserverCall = iQueryCaller->IsActive();
       
  1957     if ( isWaitingObserverCall )
       
  1958         {
       
  1959         return EFalse; // query is ready but observer not called yet
       
  1960         }
       
  1961     
       
  1962     if ( iQuery )
       
  1963         {
       
  1964         return iQuery->IsComplete();    
       
  1965         }
       
  1966      
       
  1967     return ETrue;
       
  1968     }
       
  1969 
       
  1970 
       
  1971 // -----------------------------------------------------------------------------
       
  1972 // CMediaFileHandler::ExcludeMimeTypesL
       
  1973 // 
       
  1974 // Exclude mime types from query. 
       
  1975 // -----------------------------------------------------------------------------
       
  1976 //
       
  1977 void CMediaFileHandler::ExcludeMimeTypesL( CMdELogicCondition& aCondition, 
       
  1978                                            TInt /*aAttr*/ )
       
  1979     {
       
  1980     TInt count = iExcludedMimeTypes->Count();
       
  1981     
       
  1982     if ( count == 0 )
       
  1983         {
       
  1984         return;
       
  1985         }
       
  1986 
       
  1987     CMdEPropertyDef& fileTypeDef = PropertyDefL( EAttrMediaType );
       
  1988     CMdELogicCondition& condition = 
       
  1989                         aCondition.AddLogicConditionL( ELogicConditionOperatorAnd );
       
  1990 
       
  1991     for ( TInt i=0; i<count; i++ )
       
  1992         {
       
  1993         TPtrC ptr = iExcludedMimeTypes->MimeType( i );
       
  1994         condition.AddPropertyConditionL( fileTypeDef, 
       
  1995                              ETextPropertyConditionCompareEquals, ptr );
       
  1996         }
       
  1997     condition.SetNegate( ETrue );
       
  1998     }
       
  1999 
       
  2000 
       
  2001 // -----------------------------------------------------------------------------
       
  2002 // CMediaFileHandler::IncludeMusicPropertiesL
       
  2003 // 
       
  2004 // Adds properties that are used to find out whether media file is music.
       
  2005 // File is considered music if:
       
  2006 // 1. it has metadata artist or album or genre or composer
       
  2007 // 2. its mime type is 'music' mime type (eg mp3)
       
  2008 // -----------------------------------------------------------------------------
       
  2009 //
       
  2010 void CMediaFileHandler::IncludeMusicPropertiesL( CMdELogicCondition& aCondition )
       
  2011     {
       
  2012     ExcludeRomFilesL( aCondition );
       
  2013 //    CMdEObjectCondition& cond = aCondition.AddObjectConditionL(
       
  2014 //                                EObjectConditionCompareUriBeginsWith, KDriveZ );
       
  2015 //    cond.SetNegate( ETrue );
       
  2016     
       
  2017 //    CMdELogicCondition& condition = 
       
  2018 //                        aCondition.AddLogicConditionL( ELogicConditionOperatorAnd );
       
  2019     ExcludeRecordingsL( aCondition );
       
  2020 //    CMdEPropertyDef& fileTypeDef = PropertyDefL( EAttrMediaType );
       
  2021 //    condition.AddPropertyConditionL( fileTypeDef, 
       
  2022 //            ETextPropertyConditionCompareContains, KMimeTypeAMR );
       
  2023 //    condition.AddPropertyConditionL( fileTypeDef, 
       
  2024 //            ETextPropertyConditionCompareContains, KMimeTypeWAV );
       
  2025 //    condition.SetNegate( ETrue );
       
  2026     }
       
  2027 
       
  2028 
       
  2029 
       
  2030 // -----------------------------------------------------------------------------
       
  2031 // CMediaFileHandler::IncludeMusicPropertiesL
       
  2032 // 
       
  2033 // Adds properties that are used to find out whether media file is music.
       
  2034 // File is considered music if:
       
  2035 // 1. it has metadata artist or album or genre or composer
       
  2036 // 2. its mime type is 'music' mime type (eg mp3)
       
  2037 // -----------------------------------------------------------------------------
       
  2038 //
       
  2039 /*
       
  2040 void CMediaFileHandler::IncludeMusicPropertiesL( CMdELogicCondition& aCondition )
       
  2041     {
       
  2042     //aLogicCondition.SetOperator( ELogicConditionOperatorAnd );
       
  2043     
       
  2044     CMdEPropertyDef& mimeTypeDef = PropertyDefL( EAttrMediaType );
       
  2045     CMdEPropertyDef& artistTypeDef = PropertyDefL( EAttrArtist );
       
  2046     CMdEPropertyDef& albumTypeDef = PropertyDefL( EAttrAlbum );
       
  2047     CMdEPropertyDef& genreTypeDef = PropertyDefL( EAttrGenre );
       
  2048     CMdEPropertyDef& composerTypeDef = PropertyDefL( EAttrComposer );
       
  2049     
       
  2050     CMdELogicCondition& condition = 
       
  2051                         aCondition.AddLogicConditionL( ELogicConditionOperatorOr );
       
  2052 
       
  2053     condition.AddPropertyConditionL( mimeTypeDef, 
       
  2054             ETextPropertyConditionCompareContains, KMimeMp3 );
       
  2055     condition.AddPropertyConditionL( artistTypeDef );
       
  2056     condition.AddPropertyConditionL( albumTypeDef );
       
  2057     condition.AddPropertyConditionL( genreTypeDef );
       
  2058     condition.AddPropertyConditionL( composerTypeDef );
       
  2059     }
       
  2060 */
       
  2061 
       
  2062 
       
  2063 
       
  2064 // -----------------------------------------------------------------------------
       
  2065 // CMediaFileHandler::ExcludeMusicPropertiesL
       
  2066 // 
       
  2067 // -----------------------------------------------------------------------------
       
  2068 //
       
  2069 void CMediaFileHandler::ExcludeMusicPropertiesL( CMdELogicCondition& aCondition )
       
  2070     {
       
  2071     CMdEPropertyDef& mimeTypeDef = PropertyDefL( EAttrMediaType );
       
  2072     CMdEPropertyDef& artistTypeDef = PropertyDefL( EAttrArtist );
       
  2073     CMdEPropertyDef& albumTypeDef = PropertyDefL( EAttrAlbum );
       
  2074     CMdEPropertyDef& genreTypeDef = PropertyDefL( EAttrGenre );
       
  2075     CMdEPropertyDef& composerTypeDef = PropertyDefL( EAttrComposer );
       
  2076     
       
  2077     CMdELogicCondition& condition = 
       
  2078                         aCondition.AddLogicConditionL( ELogicConditionOperatorAnd );
       
  2079 
       
  2080     condition.AddPropertyConditionL( mimeTypeDef, 
       
  2081             ETextPropertyConditionCompareContains, KMimeMp3 );
       
  2082     condition.AddPropertyConditionL( artistTypeDef );
       
  2083     condition.AddPropertyConditionL( albumTypeDef );
       
  2084     condition.AddPropertyConditionL( genreTypeDef );
       
  2085     condition.AddPropertyConditionL( composerTypeDef );
       
  2086     
       
  2087     condition.SetNegate( ETrue );
       
  2088     }
       
  2089 
       
  2090 
       
  2091 // -----------------------------------------------------------------------------
       
  2092 // CMediaFileHandler::IncludeMusicSearchConditionL
       
  2093 // 
       
  2094 // -----------------------------------------------------------------------------
       
  2095 //
       
  2096 void CMediaFileHandler::IncludeMusicSearchConditionL( CMdELogicCondition& aCondition,
       
  2097                                                       const TDesC& aSearchText )
       
  2098                                     
       
  2099     {
       
  2100     _LIT( KFormat, "%S%S" );
       
  2101     
       
  2102     CMdELogicCondition& condition = 
       
  2103     aCondition.AddLogicConditionL( ELogicConditionOperatorOr );
       
  2104         
       
  2105     CMdEPropertyDef& songName = PropertyDefL( EAttrSongName );
       
  2106     CMdEPropertyDef& artist = PropertyDefL( EAttrArtist );
       
  2107     CMdEPropertyDef& album = PropertyDefL( EAttrAlbum );    
       
  2108     CMdEPropertyDef& genre = PropertyDefL( EAttrGenre );
       
  2109     CMdEPropertyDef& composer = PropertyDefL( EAttrComposer );
       
  2110     
       
  2111     // first find from the start of the property
       
  2112     condition.AddPropertyConditionL( songName,
       
  2113             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2114 
       
  2115     condition.AddPropertyConditionL( artist, 
       
  2116             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2117  
       
  2118 
       
  2119     condition.AddPropertyConditionL( album, 
       
  2120             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2121 
       
  2122     
       
  2123     condition.AddPropertyConditionL( genre, 
       
  2124             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2125 
       
  2126     
       
  2127     condition.AddPropertyConditionL( composer, 
       
  2128             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2129     
       
  2130     
       
  2131     // then find from the start of property words
       
  2132     TBuf<KBufSize128> buf;
       
  2133     if ( aSearchText.Length() < KBufSize128-1 )
       
  2134         {
       
  2135         buf.Format( KFormat, &KSpace, &aSearchText );
       
  2136     
       
  2137         condition.AddPropertyConditionL( songName, 
       
  2138              ETextPropertyConditionCompareContains, buf );
       
  2139         condition.AddPropertyConditionL( artist, 
       
  2140              ETextPropertyConditionCompareContains, buf );
       
  2141         condition.AddPropertyConditionL( album, 
       
  2142              ETextPropertyConditionCompareContains, buf );
       
  2143         condition.AddPropertyConditionL( genre, 
       
  2144              ETextPropertyConditionCompareContains, buf );
       
  2145         condition.AddPropertyConditionL( composer, 
       
  2146              ETextPropertyConditionCompareContains, buf );
       
  2147         }
       
  2148     }
       
  2149 
       
  2150 
       
  2151 // -----------------------------------------------------------------------------
       
  2152 // CMediaFileHandler::IncludeVideoConditionL
       
  2153 // 
       
  2154 // -----------------------------------------------------------------------------
       
  2155 //
       
  2156 void CMediaFileHandler::IncludeVideoSearchConditionL(
       
  2157                   CMdELogicCondition& aCondition, const TDesC& aSearchText )
       
  2158                                     
       
  2159     {
       
  2160     _LIT( KFormat, "%S%S" );
       
  2161     
       
  2162     CMdELogicCondition& condition = 
       
  2163     aCondition.AddLogicConditionL( ELogicConditionOperatorOr );
       
  2164         
       
  2165     CMdEPropertyDef& songName = PropertyDefL( EAttrSongName );
       
  2166     CMdEPropertyDef& artist = PropertyDefL( EAttrArtist );
       
  2167     CMdEPropertyDef& genre = PropertyDefL( EAttrGenre );
       
  2168     
       
  2169     // first find from the start of the property
       
  2170     condition.AddPropertyConditionL( songName,
       
  2171             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2172     condition.AddPropertyConditionL( artist, 
       
  2173             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2174     condition.AddPropertyConditionL( genre, 
       
  2175             ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2176     
       
  2177     // then find from the start of property words
       
  2178     TBuf<KBufSize128> buf;
       
  2179     if ( aSearchText.Length() < KBufSize128-1 )
       
  2180         {
       
  2181         buf.Format( KFormat, &KSpace, &aSearchText );
       
  2182     
       
  2183         condition.AddPropertyConditionL( songName, 
       
  2184              ETextPropertyConditionCompareContains, buf );
       
  2185         condition.AddPropertyConditionL( artist, 
       
  2186              ETextPropertyConditionCompareContains, buf );
       
  2187         condition.AddPropertyConditionL( genre, 
       
  2188              ETextPropertyConditionCompareContains, buf );
       
  2189         }
       
  2190     }
       
  2191 
       
  2192 
       
  2193 // -----------------------------------------------------------------------------
       
  2194 // CMediaFileHandler::IncludeToneSearchConditionL
       
  2195 // 
       
  2196 // -----------------------------------------------------------------------------
       
  2197 //
       
  2198 void CMediaFileHandler::IncludeToneSearchConditionL( CMdELogicCondition& aCondition,
       
  2199                                                      const TDesC& aSearchText )
       
  2200                                     
       
  2201     {
       
  2202     _LIT( KFormat, "%S%S" );
       
  2203     
       
  2204     CMdELogicCondition& condition = 
       
  2205     aCondition.AddLogicConditionL( ELogicConditionOperatorOr );
       
  2206         
       
  2207     CMdEPropertyDef& songName = PropertyDefL( EAttrSongName );
       
  2208     
       
  2209     // first find from the start of the property
       
  2210     condition.AddPropertyConditionL( songName,
       
  2211               ETextPropertyConditionCompareBeginsWith, aSearchText );
       
  2212     
       
  2213     // then find from the start of property words
       
  2214     TBuf<KBufSize128> buf;
       
  2215     if ( aSearchText.Length() < KBufSize128-1 )
       
  2216         {
       
  2217         buf.Format( KFormat, &KSpace, &aSearchText );
       
  2218     
       
  2219         condition.AddPropertyConditionL( songName, 
       
  2220              ETextPropertyConditionCompareContains, buf );
       
  2221         }
       
  2222     }
       
  2223 
       
  2224 
       
  2225 // -----------------------------------------------------------------------------
       
  2226 // CMediaFileHandler::ExcludeRecordingsL
       
  2227 // 
       
  2228 // Exclude recording mime types from query (.amr and .wav).
       
  2229 // -----------------------------------------------------------------------------
       
  2230 //
       
  2231 void CMediaFileHandler::ExcludeRecordingsL( CMdELogicCondition& aCondition )
       
  2232     {
       
  2233     CMdEPropertyDef& mimeTypeDef = PropertyDefL( EAttrMediaType );
       
  2234     CMdELogicCondition& condition = 
       
  2235                         aCondition.AddLogicConditionL( ELogicConditionOperatorAnd );
       
  2236     condition.AddPropertyConditionL( mimeTypeDef, 
       
  2237                              ETextPropertyConditionCompareEquals, KMimeTypeAMR );
       
  2238     condition.AddPropertyConditionL( mimeTypeDef, 
       
  2239                               ETextPropertyConditionCompareEquals, KMimeTypeWAV );
       
  2240     condition.SetNegate( ETrue );
       
  2241     }
       
  2242 
       
  2243 
       
  2244 // -----------------------------------------------------------------------------
       
  2245 // CMediaFileHandler::ExcludeRomFilesL
       
  2246 // 
       
  2247 // Exclude music files that are in rom (default tones).
       
  2248 // -----------------------------------------------------------------------------
       
  2249 //
       
  2250 void CMediaFileHandler::ExcludeRomFilesL( CMdELogicCondition& aCondition )
       
  2251     {
       
  2252     _LIT( KDriveZ, "z:\\" );
       
  2253    
       
  2254     CMdEObjectCondition& cond = aCondition.AddObjectConditionL(
       
  2255                                 EObjectConditionCompareUriBeginsWith, KDriveZ );
       
  2256     cond.SetNegate( ETrue );
       
  2257     }
       
  2258 
       
  2259 
       
  2260 // -------------------------------------------------------------------------------
       
  2261 // CMediaFileHandler::StrCopy
       
  2262 //
       
  2263 // String copy with lenght check.
       
  2264 // -------------------------------------------------------------------------------
       
  2265 //
       
  2266 void CMediaFileHandler::StrCopy( TDes& aTarget, const TDesC& aSource )
       
  2267     {
       
  2268 	TInt len = aTarget.MaxLength();
       
  2269     if( len < aSource.Length() ) 
       
  2270 	    {
       
  2271 		aTarget.Copy( aSource.Left( len ) );
       
  2272 		return;
       
  2273 	    }
       
  2274 	aTarget.Copy( aSource );
       
  2275     }
       
  2276 
       
  2277 
       
  2278 // -----------------------------------------------------------------------------
       
  2279 // CMediaFileHandler::EnableObserverCall
       
  2280 // 
       
  2281 // -----------------------------------------------------------------------------
       
  2282 //
       
  2283 void CMediaFileHandler::EnableObserverCall( TBool aEnable )
       
  2284     {
       
  2285     iObserverCallEnabled = aEnable;
       
  2286     }
       
  2287 
       
  2288 
       
  2289 // -----------------------------------------------------------------------------
       
  2290 // CMediaFileHandler::CallObserver
       
  2291 // 
       
  2292 // -----------------------------------------------------------------------------
       
  2293 //
       
  2294 void CMediaFileHandler::CallObserver( TInt aEvent, TInt aError )
       
  2295     {
       
  2296     const TInt KDelay = 100;  // milliseconds
       
  2297     
       
  2298     if ( !iObserverCallEnabled )
       
  2299         {
       
  2300         return;    
       
  2301         }
       
  2302 
       
  2303     iQueryError = aError;
       
  2304     iQueryEvent = aEvent;
       
  2305     
       
  2306     iQueryCaller->Start( 0, KDelay );
       
  2307     }
       
  2308 
       
  2309 
       
  2310 // -----------------------------------------------------------------------------
       
  2311 // CMediaFileHandler::CallObserverWithDelay
       
  2312 // 
       
  2313 // -----------------------------------------------------------------------------
       
  2314 //
       
  2315 void CMediaFileHandler::CallObserverWithDelay()
       
  2316     {
       
  2317     const TInt KOneSecond = 1000;
       
  2318     
       
  2319     if ( !iObserverCallEnabled )
       
  2320         {
       
  2321         return;    
       
  2322         }
       
  2323 
       
  2324     iObjectNotificationCaller->Start( 1, 2*KOneSecond );
       
  2325     }
       
  2326 
       
  2327 
       
  2328 // -----------------------------------------------------------------------------
       
  2329 // CMediaFileHandler::HandleActiveCallL (from MMFActiveCallerObserver)
       
  2330 //
       
  2331 // -----------------------------------------------------------------------------
       
  2332 //
       
  2333 void CMediaFileHandler::HandleActiveCallL( TInt aCallId )
       
  2334     {
       
  2335     if ( !iObserver )
       
  2336         {
       
  2337         return;
       
  2338         }
       
  2339     
       
  2340     // inform observer that query is ready
       
  2341     if ( aCallId ==  0 )
       
  2342         {
       
  2343         TRAP_IGNORE( iObserver->HandleMFEventL( iQueryEvent, iQueryError ) );
       
  2344         }
       
  2345 
       
  2346     // inform observer that database has changed
       
  2347     if ( aCallId == 1 )
       
  2348         {
       
  2349         if ( QueryReady() )
       
  2350             {
       
  2351             TRAP_IGNORE( iObserver->HandleMFEventL( MMediaFileHandlerObserver::EMediaFileChanged, KErrNone ) );
       
  2352             }
       
  2353         }
       
  2354     }
       
  2355 
       
  2356 
       
  2357 // -----------------------------------------------------------------------------
       
  2358 // CMediaFileHandler::SetQueryId
       
  2359 //
       
  2360 // -----------------------------------------------------------------------------
       
  2361 //
       
  2362 void CMediaFileHandler::SetQueryId( TInt aId ) 
       
  2363     {
       
  2364     // this id is passed to CSearchList after successful database search
       
  2365     iQueryId = aId;
       
  2366     }
       
  2367 
       
  2368 
       
  2369 // -----------------------------------------------------------------------------
       
  2370 // CMediaFileHandler::Panic
       
  2371 //
       
  2372 // -----------------------------------------------------------------------------
       
  2373 //
       
  2374 void CMediaFileHandler::Panic( TInt aReason ) 
       
  2375     {
       
  2376     _LIT( KPanicCategory, "CMediaFileHandler" );
       
  2377     
       
  2378     User::Panic( KPanicCategory, aReason ); 
       
  2379     }
       
  2380 
       
  2381 
       
  2382 // -----------------------------------------------------------------------------
       
  2383 // CMediaFileHandler::MediaType
       
  2384 // 
       
  2385 // -----------------------------------------------------------------------------
       
  2386 //
       
  2387 TInt CMediaFileHandler::MediaType( TInt aQueryType )
       
  2388     {
       
  2389     TInt mediaType = EMediaTypeMusic;
       
  2390     if ( aQueryType == EQueryVideo )
       
  2391         {
       
  2392         mediaType = EMediaTypeVideo;
       
  2393         }
       
  2394     if ( aQueryType == EQueryRecording )
       
  2395         {
       
  2396         mediaType = EMediaTypeRecording;
       
  2397         }
       
  2398     if ( aQueryType == EQueryTone )
       
  2399         {
       
  2400         mediaType = EMediaTypeTone;
       
  2401         }
       
  2402 
       
  2403     return mediaType;
       
  2404     }
       
  2405 
       
  2406 
       
  2407 
       
  2408 /******************************************************************************
       
  2409  * class CSearchListItem
       
  2410  ******************************************************************************/
       
  2411 
       
  2412 
       
  2413 // -----------------------------------------------------------------------------
       
  2414 // CSearchListItem::NewL
       
  2415 // 
       
  2416 // -----------------------------------------------------------------------------
       
  2417 //
       
  2418 CSearchListItem* CSearchListItem::NewLC()
       
  2419     {
       
  2420     CSearchListItem* self = new (ELeave) CSearchListItem();
       
  2421     CleanupStack::PushL( self );
       
  2422     self->ConstructL();
       
  2423 
       
  2424     return self;
       
  2425     }
       
  2426 
       
  2427 
       
  2428 // -----------------------------------------------------------------------------
       
  2429 // CSearchListItem::NewL
       
  2430 // 
       
  2431 // -----------------------------------------------------------------------------
       
  2432 //
       
  2433 CSearchListItem* CSearchListItem::NewL()
       
  2434     {
       
  2435     CSearchListItem* self = new (ELeave) CSearchListItem();
       
  2436     CleanupStack::PushL( self );
       
  2437     self->ConstructL();
       
  2438     CleanupStack::Pop( self );
       
  2439     return self;
       
  2440     }
       
  2441 
       
  2442 
       
  2443 // -----------------------------------------------------------------------------
       
  2444 // Destructor
       
  2445 // 
       
  2446 // -----------------------------------------------------------------------------
       
  2447 //
       
  2448 CSearchListItem::~CSearchListItem()
       
  2449     {
       
  2450     delete iTitle;
       
  2451     }
       
  2452 
       
  2453 
       
  2454 // -----------------------------------------------------------------------------
       
  2455 // CSearchListItem::CSearchListItem
       
  2456 // 
       
  2457 // -----------------------------------------------------------------------------
       
  2458 //
       
  2459 CSearchListItem::CSearchListItem()
       
  2460     {
       
  2461     iId = KErrNotFound;
       
  2462     iMediaType = KErrNotFound;
       
  2463     iStorageType = KErrNotFound;
       
  2464     iTitle = NULL;
       
  2465     }
       
  2466 
       
  2467 
       
  2468 // -----------------------------------------------------------------------------
       
  2469 // CSearchListItem::ConstructL
       
  2470 // 
       
  2471 // -----------------------------------------------------------------------------
       
  2472 //
       
  2473 void CSearchListItem::ConstructL()
       
  2474     {
       
  2475     }
       
  2476 
       
  2477 // -----------------------------------------------------------------------------
       
  2478 // CSearchListItem::SetTitleL
       
  2479 // 
       
  2480 // -----------------------------------------------------------------------------
       
  2481 //
       
  2482 
       
  2483 void CSearchListItem::SetTitleL( const TDesC& aText, TBool aFullName )
       
  2484     {
       
  2485     delete iTitle;
       
  2486     iTitle = NULL;
       
  2487     
       
  2488     if ( aFullName )
       
  2489         {
       
  2490         TParsePtrC parse( aText );
       
  2491         iTitle = parse.Name().AllocL();
       
  2492         }
       
  2493     else
       
  2494         {
       
  2495         iTitle = aText.AllocL();    
       
  2496         }
       
  2497     }
       
  2498 
       
  2499 
       
  2500 // -----------------------------------------------------------------------------
       
  2501 // CSearchListItem::Title
       
  2502 // 
       
  2503 // -----------------------------------------------------------------------------
       
  2504 //
       
  2505 
       
  2506 const TDesC& CSearchListItem::Title() const
       
  2507     {
       
  2508     return *iTitle;
       
  2509     }
       
  2510 
       
  2511 
       
  2512 
       
  2513 
       
  2514 /******************************************************************************
       
  2515  * class CRomFileList
       
  2516  ******************************************************************************/
       
  2517 
       
  2518 
       
  2519 
       
  2520 // -----------------------------------------------------------------------------
       
  2521 // Static constructor function CRomFileList::NewL
       
  2522 // 
       
  2523 // -----------------------------------------------------------------------------
       
  2524 //
       
  2525 CRomFileList* CRomFileList::NewL()
       
  2526     {
       
  2527     CRomFileList* self = new (ELeave) CRomFileList();
       
  2528     CleanupStack::PushL( self );
       
  2529     self->ConstructL();
       
  2530     CleanupStack::Pop( self );
       
  2531 
       
  2532     return self;
       
  2533     }
       
  2534 
       
  2535 
       
  2536 // -----------------------------------------------------------------------------
       
  2537 // Destructor
       
  2538 // 
       
  2539 // -----------------------------------------------------------------------------
       
  2540 //
       
  2541 CRomFileList::~CRomFileList()
       
  2542     {
       
  2543     iRomToneList.ResetAndDestroy();
       
  2544     iRomVideoList.ResetAndDestroy();
       
  2545     iList.Reset();
       
  2546     iList.Close();
       
  2547     iVedioList.Reset();
       
  2548     iVedioList.Close();
       
  2549     }
       
  2550 
       
  2551 
       
  2552 // -----------------------------------------------------------------------------
       
  2553 // CRomFileList::CRomFileList
       
  2554 // 
       
  2555 // -----------------------------------------------------------------------------
       
  2556 //
       
  2557 CRomFileList::CRomFileList()
       
  2558     {
       
  2559     }
       
  2560 
       
  2561 
       
  2562 // -----------------------------------------------------------------------------
       
  2563 // CRomFileList::ConstructL
       
  2564 // 
       
  2565 // -----------------------------------------------------------------------------
       
  2566 //
       
  2567 void CRomFileList::ConstructL()
       
  2568     {
       
  2569     }
       
  2570 
       
  2571 // -----------------------------------------------------------------------------
       
  2572 // CRomFileList::RomFileItem( TInt aIndex )
       
  2573 // 
       
  2574 // -----------------------------------------------------------------------------
       
  2575 //
       
  2576 TInt CRomFileList::RomFileItem( CSearchListItem* aItem, TInt aIndex)
       
  2577     {
       
  2578     if( aIndex >= 0 && aIndex < iRomToneList.Count() )
       
  2579     	{
       
  2580     	aItem->iId = iRomToneList[aIndex]->iId;
       
  2581     	aItem->iMediaType = iRomToneList[aIndex]->iMediaType;
       
  2582     	aItem->iStorageType = iRomToneList[aIndex]->iStorageType;
       
  2583     	TPtrC title = iRomToneList[aIndex]->Title();
       
  2584     	aItem->SetTitleL( title, EFalse );
       
  2585     	return KErrNone;
       
  2586     	}
       
  2587     return KErrGeneral;
       
  2588      }
       
  2589 
       
  2590 // -----------------------------------------------------------------------------
       
  2591 // CRomFileList::RomVedioItem( TInt aIndex )
       
  2592 // 
       
  2593 // -----------------------------------------------------------------------------
       
  2594 //
       
  2595 TInt CRomFileList::RomVedioItem( CSearchListItem* aItem, TInt aIndex)
       
  2596     {
       
  2597     if( aIndex >= 0 && aIndex < iRomVideoList.Count() )
       
  2598         {
       
  2599         aItem->iId = iRomVideoList[aIndex]->iId;
       
  2600         aItem->iMediaType = iRomVideoList[aIndex]->iMediaType;
       
  2601         aItem->iStorageType = iRomVideoList[aIndex]->iStorageType;
       
  2602         TPtrC title = iRomVideoList[aIndex]->Title();
       
  2603         aItem->SetTitleL( title, EFalse );
       
  2604         return KErrNone;
       
  2605         }
       
  2606     return KErrGeneral;
       
  2607      }
       
  2608 // -----------------------------------------------------------------------------
       
  2609 // CRomFileList::Count()
       
  2610 // 
       
  2611 // -----------------------------------------------------------------------------
       
  2612 //
       
  2613 
       
  2614 TInt CRomFileList::Count(TInt aType )
       
  2615     {
       
  2616     if ( aType == 0 )
       
  2617         {
       
  2618         //Tone item count
       
  2619         return iRomToneList.Count();
       
  2620         }
       
  2621     else if ( aType == 1 )
       
  2622         {
       
  2623         // Video item count()
       
  2624         return iRomVideoList.Count();
       
  2625         }
       
  2626     return KErrNotSupported;
       
  2627     }
       
  2628 
       
  2629 // -----------------------------------------------------------------------------
       
  2630 // CRomFileList::Reset()
       
  2631 // 
       
  2632 // -----------------------------------------------------------------------------
       
  2633 //
       
  2634 
       
  2635 void CRomFileList::Reset()
       
  2636     {
       
  2637     iRomToneList.Reset();
       
  2638     iRomVideoList.Reset();
       
  2639     iList.Reset();
       
  2640     iVedioList.Reset();
       
  2641     }
       
  2642 // -----------------------------------------------------------------------------
       
  2643 // CRomFileList::ReadRomFilesL()
       
  2644 // 
       
  2645 // -----------------------------------------------------------------------------
       
  2646 //
       
  2647 
       
  2648 void CRomFileList::ReadRomFilesL()
       
  2649     {
       
  2650     _LIT( KFormat, "%S%S" );
       
  2651     
       
  2652     iRomToneList.ResetAndDestroy();
       
  2653     iList.Reset();
       
  2654     
       
  2655     iFileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::SoundsPath() );
       
  2656     TRAP_IGNORE( ReadDirectoryL( iFileName, iRomToneList ) );    
       
  2657     TRAP_IGNORE( ReadDirectoryL( iFileName, iList ) );
       
  2658     
       
  2659     iFileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::DigitalSoundsPath() );
       
  2660     TRAP_IGNORE( ReadDirectoryL( iFileName, iRomToneList ) );    
       
  2661     TRAP_IGNORE( ReadDirectoryL( iFileName, iList ) );
       
  2662 
       
  2663     iFileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::SimpleSoundsPath() );
       
  2664     TRAP_IGNORE( ReadDirectoryL( iFileName, iRomToneList ) );    
       
  2665     TRAP_IGNORE( ReadDirectoryL( iFileName, iList ) );
       
  2666 
       
  2667     TRAP_IGNORE( ReadRomVediosL() );
       
  2668     }
       
  2669 
       
  2670 
       
  2671 // -----------------------------------------------------------------------------
       
  2672 // CRomFileList::ReadRomFilesL()
       
  2673 // 
       
  2674 // -----------------------------------------------------------------------------
       
  2675 //
       
  2676 
       
  2677 void CRomFileList::ReadRomVediosL()
       
  2678     {
       
  2679     _LIT( KFormat, "%S%S" );
       
  2680     
       
  2681     iRomVideoList.Reset();
       
  2682     iVedioList.Reset();
       
  2683     
       
  2684     iFileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::VideosPath() );
       
  2685     TRAP_IGNORE( ReadDirectoryL( iFileName, iRomVideoList ) );    
       
  2686     TRAP_IGNORE( ReadDirectoryL( iFileName, iVedioList ) );
       
  2687     
       
  2688     if ( iRomVideoList.Count() > 0 )
       
  2689         {
       
  2690         for( TInt i(0); i < iRomVideoList.Count(); i++)
       
  2691             {
       
  2692             iRomVideoList[i]->iMediaType = CMediaFileHandler::EMediaTypeVideo;
       
  2693             }
       
  2694         }
       
  2695     
       
  2696     }
       
  2697 
       
  2698 
       
  2699 // -----------------------------------------------------------------------------
       
  2700 // TDesC& CRomFileList::Item( TInt aIndex )
       
  2701 // 
       
  2702 // -----------------------------------------------------------------------------
       
  2703 //
       
  2704 const TDesC& CRomFileList::Item(TInt aIndex, TInt aType)
       
  2705     {
       
  2706     TInt count = 0;
       
  2707     if ( aType == 0 )
       
  2708         {
       
  2709         count = iList.Count();
       
  2710         if (aIndex >= 0 && aIndex < count)
       
  2711             {
       
  2712             return iList[aIndex];
       
  2713             }
       
  2714         }
       
  2715     else if ( aType == 1 )
       
  2716         {
       
  2717         count = iVedioList.Count();
       
  2718         if (aIndex >= 0 && aIndex < count)
       
  2719             {
       
  2720             return iVedioList[aIndex];
       
  2721             }
       
  2722         }
       
  2723     return KNullDesC;
       
  2724     }
       
  2725 
       
  2726 
       
  2727 // -----------------------------------------------------------------------------
       
  2728 // CRomFileList::ReadDirectoryL( const TDesC& aDirectory, 
       
  2729 //                                      RPointerArray<CSearchListItem>& aList )
       
  2730 // 
       
  2731 // -----------------------------------------------------------------------------
       
  2732 //
       
  2733 
       
  2734 void CRomFileList::ReadDirectoryL( const TDesC& aDirectory, 
       
  2735                                    RPointerArray<CSearchListItem>& aList )
       
  2736     {
       
  2737     _LIT( KFormat, "%S%S" );
       
  2738     
       
  2739     CDir* dir = NULL;
       
  2740     RFs fsSession;
       
  2741     User::LeaveIfError( fsSession.Connect() ); 
       
  2742     CleanupClosePushL( fsSession );
       
  2743     
       
  2744     if ( !BaflUtils::FolderExists( fsSession, aDirectory ) )
       
  2745         {
       
  2746         User::Leave( KErrNotFound );
       
  2747         }
       
  2748     
       
  2749     TInt err = fsSession.GetDir( aDirectory, KEntryAttNormal, ESortByName, dir );
       
  2750     User::LeaveIfError( err );
       
  2751     CleanupStack::PushL( dir );
       
  2752     TInt index;
       
  2753     TInt count = dir->Count();
       
  2754     TFileName filename;
       
  2755     for ( TInt i=0; i<count; i++ )
       
  2756         {
       
  2757         const TEntry item = (*dir)[i];
       
  2758         filename.Format( KFormat, &aDirectory, &item.iName );
       
  2759         index = aList.Count();
       
  2760         CSearchListItem* item2 = SearchListItemFromRomL( filename, index );
       
  2761         aList.AppendL( item2 );
       
  2762         }
       
  2763 
       
  2764     CleanupStack::PopAndDestroy( dir );
       
  2765 
       
  2766     CleanupStack::PopAndDestroy(); // fsSession
       
  2767     }
       
  2768 
       
  2769 // -----------------------------------------------------------------------------
       
  2770 // CRomFileList::ReadDirectoryL( const TDesC& aDirectory, 
       
  2771 //                                      RPointerArray<CSearchListItem>& aList )
       
  2772 // 
       
  2773 // -----------------------------------------------------------------------------
       
  2774 //
       
  2775 
       
  2776 void CRomFileList::ReadDirectoryL( const TDesC& aDirectory, 
       
  2777 											RArray<TFileName>& aList )
       
  2778     {
       
  2779     _LIT( KFormat, "%S%S" );
       
  2780     
       
  2781     CDir* dir = NULL;
       
  2782     RFs fsSession;
       
  2783     User::LeaveIfError( fsSession.Connect() ); 
       
  2784     CleanupClosePushL( fsSession );
       
  2785     
       
  2786     if ( !BaflUtils::FolderExists( fsSession, aDirectory ) )
       
  2787         {
       
  2788         User::Leave( KErrNotFound );
       
  2789         }
       
  2790     
       
  2791     TInt err = fsSession.GetDir( aDirectory, KEntryAttNormal, ESortByName, dir );
       
  2792     User::LeaveIfError( err );
       
  2793     CleanupStack::PushL( dir );
       
  2794 
       
  2795     TInt count = dir->Count();
       
  2796     TFileName filename;
       
  2797     for ( TInt i=0; i<count; i++ )
       
  2798         {
       
  2799         const TEntry item = (*dir)[i];
       
  2800         filename.Format( KFormat, &aDirectory, &item.iName );
       
  2801         aList.AppendL( filename );
       
  2802         }
       
  2803 
       
  2804     CleanupStack::PopAndDestroy( dir );
       
  2805 
       
  2806     CleanupStack::PopAndDestroy(); // fsSession
       
  2807     }
       
  2808 // -----------------------------------------------------------------------------
       
  2809 // CRomFileList::SearchListItemFromRomL( const TDesC& aFileName )
       
  2810 // 
       
  2811 // -----------------------------------------------------------------------------
       
  2812 //
       
  2813 
       
  2814 CSearchListItem* CRomFileList::SearchListItemFromRomL( const TDesC& aFileName ,TInt aIndex )
       
  2815     {
       
  2816     TParsePtrC parsedName( aFileName );
       
  2817     
       
  2818     CSearchListItem* item  = CSearchListItem::NewLC();
       
  2819     
       
  2820     item->iId = aIndex;
       
  2821     item->SetTitleL( aFileName , ETrue);
       
  2822     item->iStorageType = CMediaFileHandler::ERomStorage;
       
  2823     item->iMediaType = CMediaFileHandler::EMediaTypeTone;
       
  2824 
       
  2825     CleanupStack::Pop();  // item
       
  2826 
       
  2827     return item;
       
  2828     }
       
  2829 
       
  2830 // -----------------------------------------------------------------------------
       
  2831 // CRomFileList::GetRomFileName
       
  2832 // 
       
  2833 // -----------------------------------------------------------------------------
       
  2834 //
       
  2835 TInt CRomFileList::GetRomFileName(TInt aIndex, TInt aType, TDes& aValue)
       
  2836 	{
       
  2837 	//return title of rom item;
       
  2838     if (aType == 0)
       
  2839         {
       
  2840         if (aIndex >= 0 && aIndex < Count(0))
       
  2841             {
       
  2842             aValue.Copy( iRomToneList[aIndex]->Title() );
       
  2843             return KErrNone;
       
  2844             }
       
  2845         return KErrGeneral;
       
  2846         }
       
  2847     else if (aType == 1)
       
  2848         {
       
  2849         if (aIndex >= 0 && aIndex < Count(1))
       
  2850             {
       
  2851             aValue.Copy(iRomVideoList[aIndex]->Title());
       
  2852             return KErrNone;
       
  2853             }
       
  2854         return KErrGeneral;
       
  2855         }
       
  2856     return KErrNotFound;
       
  2857     }
       
  2858 
       
  2859 
       
  2860 /******************************************************************************
       
  2861  * class CSearchList
       
  2862  ******************************************************************************/
       
  2863 
       
  2864 
       
  2865 // -----------------------------------------------------------------------------
       
  2866 // CSearchList::NewL
       
  2867 // 
       
  2868 // -----------------------------------------------------------------------------
       
  2869 //
       
  2870 CSearchList* CSearchList::NewL()
       
  2871     {
       
  2872     CSearchList* self = new (ELeave) CSearchList();
       
  2873     CleanupStack::PushL( self );
       
  2874     self->ConstructL();
       
  2875     CleanupStack::Pop( self );
       
  2876 
       
  2877     return self;
       
  2878     }
       
  2879 
       
  2880 
       
  2881 // -----------------------------------------------------------------------------
       
  2882 // Destructor
       
  2883 // 
       
  2884 // -----------------------------------------------------------------------------
       
  2885 //
       
  2886 CSearchList::~CSearchList()
       
  2887     {
       
  2888     iList.ResetAndDestroy();
       
  2889     delete iDriveUtil;
       
  2890     }
       
  2891 
       
  2892 
       
  2893 // -----------------------------------------------------------------------------
       
  2894 // CSearchList::CSearchList
       
  2895 // 
       
  2896 // -----------------------------------------------------------------------------
       
  2897 //
       
  2898 CSearchList::CSearchList()
       
  2899     {
       
  2900     iSearchId = KErrNotFound;
       
  2901     }
       
  2902 
       
  2903 
       
  2904 // -----------------------------------------------------------------------------
       
  2905 // CSearchList::ConstructL
       
  2906 // 
       
  2907 // -----------------------------------------------------------------------------
       
  2908 //
       
  2909 void CSearchList::ConstructL()
       
  2910     {
       
  2911     iDriveUtil = CDriveUtil::NewL();
       
  2912     }
       
  2913 
       
  2914 
       
  2915 // -----------------------------------------------------------------------------
       
  2916 // CSearchList::SetSession
       
  2917 // 
       
  2918 // -----------------------------------------------------------------------------
       
  2919 //
       
  2920 void CSearchList::SetSession( CMdESession* aSession )
       
  2921     {
       
  2922     iSession = aSession;
       
  2923     }
       
  2924 
       
  2925 // -----------------------------------------------------------------------------
       
  2926 // CSearchList::SetRomFileList
       
  2927 // 
       
  2928 // -----------------------------------------------------------------------------
       
  2929 //
       
  2930 void CSearchList::SetRomFileList( CRomFileList* aRomFileList )
       
  2931 	{
       
  2932 	iRomFileList = aRomFileList;
       
  2933 	}
       
  2934 
       
  2935 // -----------------------------------------------------------------------------
       
  2936 // CSearchList::SetSearchId
       
  2937 // 
       
  2938 // -----------------------------------------------------------------------------
       
  2939 //
       
  2940 void CSearchList::SetSearchId( TInt aSearchId )
       
  2941     {
       
  2942     iSearchId = aSearchId;
       
  2943     }
       
  2944 
       
  2945 
       
  2946 // -----------------------------------------------------------------------------
       
  2947 // CSearchList::SearchId
       
  2948 // 
       
  2949 // -----------------------------------------------------------------------------
       
  2950 //
       
  2951 TInt CSearchList::SearchId()
       
  2952     {
       
  2953     return iSearchId;
       
  2954     }
       
  2955 
       
  2956 // -----------------------------------------------------------------------------
       
  2957 // CSearchList::Remove
       
  2958 // Remove an item from the list of search results
       
  2959 // -----------------------------------------------------------------------------
       
  2960 //
       
  2961 void CSearchList::Remove( TInt aIndex )
       
  2962     {
       
  2963     iList.Remove( aIndex );
       
  2964     }
       
  2965 
       
  2966 // -----------------------------------------------------------------------------
       
  2967 // CSearchList::TakeResultL
       
  2968 // 
       
  2969 // -----------------------------------------------------------------------------
       
  2970 //
       
  2971 void CSearchList::TakeResultL( CMdEObjectQuery* aQuery, TInt aMediaType )
       
  2972     {
       
  2973     if ( !aQuery )
       
  2974         {
       
  2975         return;
       
  2976         }
       
  2977     CMdEObjectQuery* query = static_cast<CMdEObjectQuery*> (aQuery);
       
  2978     TInt count = query->Count();
       
  2979 
       
  2980     for (TInt i = 0; i < count; i++)
       
  2981         {
       
  2982         CMdEObject* object = (CMdEObject*) query->TakeOwnershipOfResult(i);
       
  2983         CleanupStack::PushL(object);
       
  2984         AddItemL(*object, aMediaType);
       
  2985         CleanupStack::PopAndDestroy(object);
       
  2986         }
       
  2987     }
       
  2988 
       
  2989 // -----------------------------------------------------------------------------
       
  2990 // CSearchList::SearchInToneL
       
  2991 // 
       
  2992 // -----------------------------------------------------------------------------
       
  2993 //
       
  2994 void CSearchList::SearchInToneL( CRomFileList* aQuery,  const TDesC& aSearchText )
       
  2995     {
       
  2996     if ( !aQuery )
       
  2997         {
       
  2998         return;
       
  2999         }
       
  3000     TInt error = KErrNone;
       
  3001     TInt count = aQuery->Count( 0 );    
       
  3002     for( int i = 0; i< count; i++ )
       
  3003     	{
       
  3004         CSearchListItem* item = CSearchListItem::NewL();
       
  3005         error = aQuery->RomFileItem( item, i );
       
  3006         if ( error == KErrNone )
       
  3007         	{
       
  3008             TPtrC title = item->Title();
       
  3009             TInt rt = title.FindF( aSearchText );
       
  3010             if ( rt != KErrNotFound )
       
  3011             	{
       
  3012             	iList.AppendL( item );
       
  3013             	}
       
  3014         	}
       
  3015     	}
       
  3016     }
       
  3017 
       
  3018 // -----------------------------------------------------------------------------
       
  3019 // CSearchList::VideoSearchInRomL
       
  3020 // 
       
  3021 // -----------------------------------------------------------------------------
       
  3022 //
       
  3023 void CSearchList::VideoSearchInRomL( CRomFileList* aQuery,  const TDesC& aSearchText )
       
  3024     {
       
  3025     if ( !aQuery )
       
  3026         {
       
  3027         return;
       
  3028         }
       
  3029     TInt error = KErrNone;
       
  3030     TInt count = aQuery->Count( 1 );    
       
  3031     for( int i = 0; i< count; i++ )
       
  3032         {
       
  3033         CSearchListItem* item = CSearchListItem::NewL();
       
  3034         error = aQuery->RomVedioItem( item, i );
       
  3035         if ( error == KErrNone )
       
  3036             {
       
  3037             TPtrC title = item->Title();
       
  3038             TInt rt = title.FindF( aSearchText );
       
  3039             if ( rt != KErrNotFound )
       
  3040                 {
       
  3041                 iList.AppendL( item );
       
  3042                 }
       
  3043             }
       
  3044         }
       
  3045     }
       
  3046 // -----------------------------------------------------------------------------
       
  3047 // CSearchList::TakeArtistResultL
       
  3048 // 
       
  3049 // -----------------------------------------------------------------------------
       
  3050 //
       
  3051 void CSearchList::TakeArtistResultL( CArtistQuery* aArtistQuery )
       
  3052     {
       
  3053     if ( !aArtistQuery )
       
  3054         {
       
  3055         return;
       
  3056         }
       
  3057     
       
  3058     CMdEObjectQuery* query = aArtistQuery->Query();
       
  3059     if ( !query )
       
  3060         {
       
  3061         return;
       
  3062         }
       
  3063     TInt queryType = aArtistQuery->QueryType();
       
  3064 
       
  3065     
       
  3066     TInt count = query->Count();
       
  3067     for ( TInt i=0; i<count; i++ )
       
  3068         {
       
  3069         CMdEObject& object = query->Result( i );
       
  3070         AddArtistItemL( object, queryType, aArtistQuery->Album() );
       
  3071         }    
       
  3072     }
       
  3073 
       
  3074 
       
  3075 // -----------------------------------------------------------------------------
       
  3076 // CSearchList::TakeDistinctResultL
       
  3077 // 
       
  3078 // -----------------------------------------------------------------------------
       
  3079 //
       
  3080 void CSearchList::TakeDistinctResultL( CMdEObjectQuery* aQuery, 
       
  3081                                        TInt /*aMediaType*/ )
       
  3082     {
       
  3083     if ( !aQuery )
       
  3084         {
       
  3085         return;
       
  3086         }
       
  3087 
       
  3088     TInt count = aQuery->Count();
       
  3089     
       
  3090     for ( TInt i=0; i<count; i++ )
       
  3091         {
       
  3092         TPtrC ptr = aQuery->ResultDistinctValue( i );
       
  3093         
       
  3094         CSearchListItem* item = CSearchListItem::NewLC();
       
  3095          
       
  3096         item->SetTitleL( ptr, EFalse );
       
  3097         item->iMediaType = KErrNotFound;
       
  3098         item->iStorageType = KErrNotFound;
       
  3099 
       
  3100         iList.AppendL( item );
       
  3101         
       
  3102         CleanupStack::Pop( item );
       
  3103         }
       
  3104     }
       
  3105 
       
  3106 
       
  3107 // -----------------------------------------------------------------------------
       
  3108 // CSearchList::AddItemL
       
  3109 // 
       
  3110 // -----------------------------------------------------------------------------
       
  3111 //
       
  3112 void CSearchList::AddItemL( CMdEObject& aObject, TInt aMediaType )
       
  3113     {
       
  3114     CSearchListItem* item = CSearchListItem::NewLC();
       
  3115     
       
  3116     TPtrC songName = TextL( aObject, CMediaFileHandler::EAttrSongName );
       
  3117     
       
  3118     if ( songName.Length() > 0 )
       
  3119         {
       
  3120         item->SetTitleL( songName, EFalse );
       
  3121         }
       
  3122     else
       
  3123         {
       
  3124         item->SetTitleL( aObject.Uri(), ETrue );    
       
  3125         }
       
  3126     
       
  3127 
       
  3128     item->iId = aObject.Id();
       
  3129     item->iMediaType = aMediaType;
       
  3130    
       
  3131     TInt storageType = CMediaFileHandler::EPhoneMemory;
       
  3132     if ( iDriveUtil->IsMemoryCard( aObject.Uri() ) )
       
  3133         {
       
  3134         storageType = CMediaFileHandler::EMemoryCard;
       
  3135         }
       
  3136     else if ( iDriveUtil->IsMassStorage( aObject.Uri() ) )
       
  3137         {
       
  3138         storageType = CMediaFileHandler::EMassStorage;
       
  3139         }
       
  3140     item->iStorageType = storageType;
       
  3141     
       
  3142     iList.AppendL( item );
       
  3143     
       
  3144     CleanupStack::Pop( item );
       
  3145     }
       
  3146 
       
  3147 // -----------------------------------------------------------------------------
       
  3148 // CSearchList::AddRomItemL
       
  3149 // 
       
  3150 // -----------------------------------------------------------------------------
       
  3151 //
       
  3152 void CSearchList::AddRomItemL( CRomFileList* aRomList, TInt aMediaType )
       
  3153     {
       
  3154     if ( !aRomList )
       
  3155         {
       
  3156         return;
       
  3157         }
       
  3158     
       
  3159     TInt count =0;
       
  3160     TInt error = KErrNone;
       
  3161     if ( aMediaType == CMediaFileHandler::EMediaTypeTone )
       
  3162         {
       
  3163         count = aRomList->Count( 0 );
       
  3164         for ( TInt i=0; i< count; i++ )
       
  3165             {
       
  3166             CSearchListItem* item = CSearchListItem::NewL();
       
  3167             error = aRomList->RomFileItem( item, i );
       
  3168             if ( error == KErrNone )
       
  3169                 {
       
  3170                 iList.AppendL( item );
       
  3171                 }
       
  3172             }
       
  3173         }
       
  3174     else if ( aMediaType == CMediaFileHandler::EMediaTypeVideo )
       
  3175         {
       
  3176         count = aRomList->Count( 1 );
       
  3177         for (TInt i = 0; i < count; i++)
       
  3178             {
       
  3179             CSearchListItem* item = CSearchListItem::NewL();
       
  3180             error = aRomList->RomVedioItem(item, i);
       
  3181             if (error == KErrNone)
       
  3182                 {
       
  3183                 iList.AppendL(item);
       
  3184                 }
       
  3185             }
       
  3186         }
       
  3187 
       
  3188     }
       
  3189 
       
  3190 // -----------------------------------------------------------------------------
       
  3191 // CSearchList::AddAlbumItemL
       
  3192 // 
       
  3193 // -----------------------------------------------------------------------------
       
  3194 //
       
  3195 void CSearchList::AddAlbumItemL( const TDesC& aAlbum )
       
  3196     {
       
  3197     TLinearOrder<CSearchListItem> sortFunction( CSearchList::Compare );
       
  3198        
       
  3199     CSearchListItem* item = CSearchListItem::NewLC();
       
  3200    
       
  3201     item->SetTitleL( aAlbum, EFalse );
       
  3202     
       
  3203     CleanupStack::Pop( item );
       
  3204     
       
  3205     item->iMediaType = KErrNotFound;
       
  3206     item->iStorageType = KErrNotFound;
       
  3207     item->iId = KErrNotFound;
       
  3208 
       
  3209     TInt err = iList.InsertInOrder( item, sortFunction );
       
  3210     if ( err != KErrNone )
       
  3211         {
       
  3212         delete item;
       
  3213         }
       
  3214     if ( err != KErrNone && err != KErrAlreadyExists )
       
  3215         {
       
  3216         User::Leave( err );
       
  3217         }
       
  3218     }
       
  3219 
       
  3220 
       
  3221 // -----------------------------------------------------------------------------
       
  3222 // CSearchList::AddArtistItemL
       
  3223 // 
       
  3224 // -----------------------------------------------------------------------------
       
  3225 //
       
  3226 void CSearchList::AddArtistItemL( CMdEObject& aObject, 
       
  3227                                   TInt aQueryType, const TDesC& aAlbum )
       
  3228     {
       
  3229     // all songs for one artist
       
  3230     if ( aQueryType == CMediaFileHandler::EQueryArtistAll )
       
  3231         {
       
  3232         AddItemL( aObject, CMediaFileHandler::EMediaTypeMusic );
       
  3233         return;
       
  3234         }
       
  3235 
       
  3236     TPtrC album = TextL( aObject, CMediaFileHandler::EAttrAlbum );
       
  3237 
       
  3238     // unknown songs (no album metadata) for one artist 
       
  3239     if ( aQueryType == CMediaFileHandler::EQueryArtistUnknown )
       
  3240         {
       
  3241         if ( album.Length() == 0 )
       
  3242             {
       
  3243             AddItemL( aObject, CMediaFileHandler::EMediaTypeMusic );
       
  3244             }
       
  3245         }
       
  3246 
       
  3247     // all albums for one artist
       
  3248     if ( aQueryType == CMediaFileHandler::EQueryArtist )
       
  3249         {
       
  3250         if ( album.Length() > 0 )
       
  3251             {
       
  3252             AddAlbumItemL( album );
       
  3253             }
       
  3254         }
       
  3255 
       
  3256     // songs in one album
       
  3257     if ( aQueryType == CMediaFileHandler::EQueryArtistAlbum )
       
  3258         {
       
  3259         if ( album.Length() > 0 )
       
  3260             {
       
  3261             if ( album.Compare( aAlbum ) == 0 )
       
  3262                 {
       
  3263                 AddItemL( aObject, CMediaFileHandler::EMediaTypeMusic );
       
  3264                 }
       
  3265             }
       
  3266         }
       
  3267     }
       
  3268 
       
  3269 
       
  3270 // -----------------------------------------------------------------------------
       
  3271 // CSearchList::Sort
       
  3272 // 
       
  3273 // -----------------------------------------------------------------------------
       
  3274 //
       
  3275 void CSearchList::Sort()
       
  3276     {
       
  3277     iList.Sort( TLinearOrder<CSearchListItem>(CSearchList::Compare) );
       
  3278     }
       
  3279 
       
  3280 
       
  3281 // -----------------------------------------------------------------------------
       
  3282 // CSearchList::Reset
       
  3283 // 
       
  3284 // -----------------------------------------------------------------------------
       
  3285 //
       
  3286 void CSearchList::Reset()
       
  3287     {
       
  3288     iSearchId = KErrNotFound;
       
  3289     iList.ResetAndDestroy();
       
  3290     }
       
  3291 
       
  3292 
       
  3293 // -----------------------------------------------------------------------------
       
  3294 // CSearchList::Count
       
  3295 // 
       
  3296 // -----------------------------------------------------------------------------
       
  3297 //
       
  3298 TInt CSearchList::Count()
       
  3299     {
       
  3300     return iList.Count();
       
  3301     }
       
  3302 
       
  3303 
       
  3304 // -----------------------------------------------------------------------------
       
  3305 // CSearchList::GetAttributeL
       
  3306 // 
       
  3307 // -----------------------------------------------------------------------------
       
  3308 //
       
  3309 void CSearchList::GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue )
       
  3310     {
       
  3311     aValue = KNullDesC;
       
  3312     
       
  3313     if ( !iSession )
       
  3314         {
       
  3315         return;
       
  3316         }
       
  3317 
       
  3318     if ( aIndex == KErrNotFound )
       
  3319         {
       
  3320         return;
       
  3321         }
       
  3322 
       
  3323     TInt count = iList.Count();
       
  3324     if ( aIndex < 0 || aIndex >= count )
       
  3325         {
       
  3326         return;
       
  3327         }
       
  3328    
       
  3329     if ( aAttr == CMediaFileHandler::EAttrFullName )
       
  3330         {
       
  3331         CSearchListItem* item = iList[aIndex];
       
  3332         if ( item->iStorageType == CMediaFileHandler::ERomStorage )
       
  3333             {
       
  3334             if ( item->iMediaType == CMediaFileHandler::EMediaTypeTone )
       
  3335                 {
       
  3336                 TPtrC name = iRomFileList->Item( item->iId , 0 );
       
  3337                 TMFDialogUtil::StrCopy( aValue, name );
       
  3338                 }
       
  3339             
       
  3340             if ( item->iMediaType == CMediaFileHandler::EMediaTypeVideo )
       
  3341                 {
       
  3342                 TPtrC name = iRomFileList->Item( item->iId , 1 );
       
  3343                 TMFDialogUtil::StrCopy( aValue, name );
       
  3344                 }            
       
  3345             }
       
  3346         else
       
  3347         	{
       
  3348             CMdEObject* object = iSession->GetFullObjectL( item->iId );
       
  3349             CleanupStack::PushL( object );
       
  3350             TMFDialogUtil::StrCopy( aValue, object->Uri() );
       
  3351             CleanupStack::PopAndDestroy( object );
       
  3352         	}
       
  3353         }
       
  3354     
       
  3355     else if ( aAttr == CMediaFileHandler::EAttrSongName ||
       
  3356               aAttr == CMediaFileHandler::EAttrFileName )
       
  3357         {
       
  3358         CSearchListItem* item = iList[aIndex];
       
  3359         TMFDialogUtil::StrCopy( aValue, item->Title() );
       
  3360         if ( aValue.Length() == 0 )
       
  3361             {
       
  3362             if ( item->iStorageType == CMediaFileHandler::ERomStorage )
       
  3363                 {
       
  3364                 if ( item->iMediaType == CMediaFileHandler::EMediaTypeTone )
       
  3365                     {
       
  3366                     TPtrC name = iRomFileList->Item( aIndex,0 );
       
  3367                     TMFDialogUtil::StrCopy( aValue, name );
       
  3368                     }
       
  3369                 
       
  3370                 if ( item->iMediaType == CMediaFileHandler::EMediaTypeVideo )
       
  3371                     {
       
  3372                     TPtrC name = iRomFileList->Item( aIndex,1 );
       
  3373                     TMFDialogUtil::StrCopy( aValue, name );
       
  3374                     }
       
  3375                 }
       
  3376             else
       
  3377             	{
       
  3378                 CMdEObject* object = iSession->GetFullObjectL( item->iId );
       
  3379                 CleanupStack::PushL( object );
       
  3380                 TParsePtrC parse( object->Uri() );
       
  3381                 TMFDialogUtil::StrCopy( aValue, parse.Name() );
       
  3382                 CleanupStack::PopAndDestroy( object );
       
  3383             	}
       
  3384             }
       
  3385         }
       
  3386     }
       
  3387 
       
  3388 
       
  3389 // -----------------------------------------------------------------------------
       
  3390 // CSearchList::Attribute
       
  3391 // 
       
  3392 // -----------------------------------------------------------------------------
       
  3393 //
       
  3394 TInt CSearchList::Attribute( TInt aIndex, TInt aAttr )
       
  3395     {
       
  3396     if ( aIndex == KErrNotFound )
       
  3397         {
       
  3398         return KErrNotFound;
       
  3399         }
       
  3400 
       
  3401     TInt count = iList.Count();   
       
  3402     if ( aIndex < 0 || aIndex >= count )
       
  3403         {
       
  3404         return KErrNotFound;
       
  3405         }
       
  3406     
       
  3407     
       
  3408     TInt ret = KErrNotFound;
       
  3409     if ( aAttr == CMediaFileHandler::EAttrMediaType )
       
  3410         {
       
  3411         CSearchListItem* item = iList[aIndex];
       
  3412         ret = item->iMediaType;
       
  3413         }
       
  3414     
       
  3415     else if ( aAttr == CMediaFileHandler::EAttrStorageType )
       
  3416         {
       
  3417         CSearchListItem* item = iList[aIndex];
       
  3418         ret = item->iStorageType;
       
  3419         }
       
  3420     else if ( aAttr == CMediaFileHandler::EAttrMediaFileId )
       
  3421         {
       
  3422         CSearchListItem* item = iList[aIndex];
       
  3423         ret = item->iId;
       
  3424         }
       
  3425 
       
  3426     return ret;
       
  3427     }
       
  3428 
       
  3429 
       
  3430 // -----------------------------------------------------------------------------
       
  3431 // CSearchList::Compare
       
  3432 // 
       
  3433 // -----------------------------------------------------------------------------
       
  3434 //
       
  3435 TInt CSearchList::Compare( const CSearchListItem& aFirst, 
       
  3436                            const CSearchListItem& aSecond )
       
  3437     {
       
  3438     TPtrC first = aFirst.Title();
       
  3439     TPtrC second = aSecond.Title();
       
  3440     
       
  3441     return first.Compare( second );    
       
  3442     }
       
  3443 
       
  3444 
       
  3445 // -----------------------------------------------------------------------------
       
  3446 // CSearchList::Panic
       
  3447 //
       
  3448 // -----------------------------------------------------------------------------
       
  3449 //
       
  3450 void CSearchList::Panic( TInt aReason ) 
       
  3451     {
       
  3452     TMFDialogUtil::Panic( aReason );
       
  3453     }
       
  3454 
       
  3455 
       
  3456 // -----------------------------------------------------------------------------
       
  3457 // CSearchList::TextL
       
  3458 // 
       
  3459 // -----------------------------------------------------------------------------
       
  3460 //
       
  3461 const TDesC& CSearchList::TextL( CMdEObject& aObject, TInt aId )
       
  3462     {
       
  3463     CMdEPropertyDef& propDef = 
       
  3464     CMediaFileHandler::PropertyDefL( iSession, aId );
       
  3465     
       
  3466     CMdEProperty* property = NULL;
       
  3467     TInt err = aObject.Property( propDef, property, 0 );
       
  3468     
       
  3469     if ( err != KErrNotFound && property )
       
  3470         {
       
  3471         return property->TextValueL();
       
  3472         }
       
  3473     
       
  3474     return KNullDesC;
       
  3475     }
       
  3476 
       
  3477 
       
  3478 
       
  3479 // -----------------------------------------------------------------------------
       
  3480 // CSearchList::ItemIndex
       
  3481 // 
       
  3482 // -----------------------------------------------------------------------------
       
  3483 //
       
  3484 TInt CSearchList::ItemIndex( TInt aId )
       
  3485     {
       
  3486     TInt count = iList.Count();
       
  3487     
       
  3488     for ( TInt i=0; i<count; i++ )
       
  3489         {
       
  3490         CSearchListItem* item = iList[i];
       
  3491         if ( item->iId == aId )
       
  3492             {
       
  3493             return i;
       
  3494             }
       
  3495         }
       
  3496         
       
  3497     return KErrNotFound;
       
  3498     }
       
  3499 
       
  3500 
       
  3501 // -----------------------------------------------------------------------------
       
  3502 // CSearchList::ItemIndex
       
  3503 // 
       
  3504 // -----------------------------------------------------------------------------
       
  3505 //
       
  3506 TInt CSearchList::ItemIndex( const TDesC& aText )
       
  3507     {
       
  3508     TInt count = iList.Count();
       
  3509     
       
  3510     for ( TInt i=0; i<count; i++ )
       
  3511         {
       
  3512         CSearchListItem* item = iList[i];
       
  3513         if ( aText.CompareF( item->Title() ) == 0 )
       
  3514             {
       
  3515             return i;
       
  3516             }
       
  3517         }
       
  3518     
       
  3519     
       
  3520 
       
  3521     return KErrNotFound;
       
  3522     }
       
  3523 
       
  3524 
       
  3525 // -----------------------------------------------------------------------------
       
  3526 // CSearchList::ItemIndex
       
  3527 // 
       
  3528 // -----------------------------------------------------------------------------
       
  3529 //
       
  3530 TInt CSearchList::ItemIndex( TInt aId, TInt aIndex )
       
  3531     {
       
  3532     TInt count = iList.Count();
       
  3533     if ( aIndex >= 0 && aIndex < count )
       
  3534         {
       
  3535         CSearchListItem* item = iList[aIndex];
       
  3536         if ( item->iId == aId )
       
  3537             {
       
  3538             return aIndex;
       
  3539             }
       
  3540         }
       
  3541     
       
  3542     return ItemIndex( aId );
       
  3543     }
       
  3544 
       
  3545 
       
  3546 // -----------------------------------------------------------------------------
       
  3547 // CSearchList::ItemIndex
       
  3548 // 
       
  3549 // -----------------------------------------------------------------------------
       
  3550 //
       
  3551 TInt CSearchList::ItemIndex( const TDesC& aText, TInt aIndex )
       
  3552     {
       
  3553     TInt count = iList.Count();
       
  3554     if ( aIndex >= 0 && aIndex < count )
       
  3555         {
       
  3556         CSearchListItem* item = iList[aIndex];
       
  3557         if ( aText.CompareF( item->Title() ) == 0 )
       
  3558             {
       
  3559             return aIndex;
       
  3560             }
       
  3561         }
       
  3562 
       
  3563     return ItemIndex( aText );
       
  3564     }
       
  3565 
       
  3566 
       
  3567 /******************************************************************************
       
  3568  * class CArtistQuery
       
  3569  ******************************************************************************/
       
  3570 
       
  3571 
       
  3572 
       
  3573 // -----------------------------------------------------------------------------
       
  3574 // CArtistQuery::NewL
       
  3575 // 
       
  3576 // -----------------------------------------------------------------------------
       
  3577 //
       
  3578 CArtistQuery* CArtistQuery::NewL()
       
  3579     {
       
  3580     CArtistQuery* self = new (ELeave) CArtistQuery();
       
  3581     CleanupStack::PushL( self );
       
  3582     self->ConstructL();
       
  3583     CleanupStack::Pop( self );
       
  3584 
       
  3585     return self;
       
  3586     }
       
  3587 
       
  3588 
       
  3589 // -----------------------------------------------------------------------------
       
  3590 // Destructor
       
  3591 // 
       
  3592 // -----------------------------------------------------------------------------
       
  3593 //
       
  3594 CArtistQuery::~CArtistQuery()
       
  3595     {
       
  3596     delete iArtist;
       
  3597     delete iAlbum;
       
  3598     delete iQuery;
       
  3599     }
       
  3600 
       
  3601 
       
  3602 // -----------------------------------------------------------------------------
       
  3603 // CArtistQuery::CArtistQuery
       
  3604 // 
       
  3605 // -----------------------------------------------------------------------------
       
  3606 //
       
  3607 CArtistQuery::CArtistQuery()
       
  3608     {
       
  3609     iQueryType = KErrNotFound;
       
  3610     }
       
  3611 
       
  3612 
       
  3613 // -----------------------------------------------------------------------------
       
  3614 // CArtistQuery::ConstructL
       
  3615 // 
       
  3616 // -----------------------------------------------------------------------------
       
  3617 //
       
  3618 void CArtistQuery::ConstructL()
       
  3619     {
       
  3620     iArtist = HBufC::NewL( 0 );
       
  3621     iAlbum = HBufC::NewL( 0 );
       
  3622     }
       
  3623 
       
  3624 // -----------------------------------------------------------------------------
       
  3625 // CArtistQuery::SetQueryType
       
  3626 // 
       
  3627 // -----------------------------------------------------------------------------
       
  3628 //
       
  3629 void CArtistQuery::SetQueryType( TInt aType )
       
  3630     {
       
  3631     iQueryType = aType;
       
  3632     }
       
  3633 
       
  3634 
       
  3635 // -----------------------------------------------------------------------------
       
  3636 // CArtistQuery::QueryType
       
  3637 // 
       
  3638 // -----------------------------------------------------------------------------
       
  3639 //
       
  3640 TInt CArtistQuery::QueryType()
       
  3641     {
       
  3642     return iQueryType;
       
  3643     }
       
  3644 
       
  3645 
       
  3646 // -----------------------------------------------------------------------------
       
  3647 // CArtistQuery::SetQuery
       
  3648 // 
       
  3649 // -----------------------------------------------------------------------------
       
  3650 //
       
  3651 void CArtistQuery::SetQuery( CMdEObjectQuery* aQuery )
       
  3652     {
       
  3653     delete iQuery;
       
  3654     iQuery = NULL;
       
  3655     iQuery = aQuery;
       
  3656     }
       
  3657 
       
  3658 
       
  3659 // -----------------------------------------------------------------------------
       
  3660 // CArtistQuery::Query
       
  3661 // 
       
  3662 // -----------------------------------------------------------------------------
       
  3663 //
       
  3664 CMdEObjectQuery* CArtistQuery::Query()
       
  3665     {
       
  3666     return iQuery;
       
  3667     }
       
  3668 
       
  3669 
       
  3670 // -----------------------------------------------------------------------------
       
  3671 // CArtistQuery::Artist
       
  3672 // 
       
  3673 // -----------------------------------------------------------------------------
       
  3674 //
       
  3675 const TDesC& CArtistQuery::Artist()
       
  3676     {
       
  3677     return *iArtist;
       
  3678     }
       
  3679 
       
  3680 
       
  3681 // -----------------------------------------------------------------------------
       
  3682 // CArtistQuery::Album
       
  3683 // 
       
  3684 // -----------------------------------------------------------------------------
       
  3685 //
       
  3686 const TDesC& CArtistQuery::Album()
       
  3687     {
       
  3688     return *iAlbum;
       
  3689     }
       
  3690 
       
  3691 
       
  3692 // -----------------------------------------------------------------------------
       
  3693 // CArtistQuery::SetAlbumL
       
  3694 // 
       
  3695 // -----------------------------------------------------------------------------
       
  3696 //
       
  3697 void CArtistQuery::SetAlbumL( const TDesC& aText )
       
  3698     {
       
  3699     delete iAlbum;
       
  3700     iAlbum = NULL;
       
  3701     iAlbum = aText.AllocL();
       
  3702     }
       
  3703 
       
  3704 // -----------------------------------------------------------------------------
       
  3705 // CArtistQuery::SetArtistL
       
  3706 // 
       
  3707 // -----------------------------------------------------------------------------
       
  3708 //
       
  3709 void CArtistQuery::SetArtistL( const TDesC& aText )
       
  3710     {
       
  3711     delete iArtist;
       
  3712     iArtist = NULL;
       
  3713     iArtist = aText.AllocL();
       
  3714     }
       
  3715 
       
  3716 
       
  3717 // -----------------------------------------------------------------------------
       
  3718 // CArtistQuery::ResetL
       
  3719 // 
       
  3720 // -----------------------------------------------------------------------------
       
  3721 //
       
  3722 void CArtistQuery::ResetL()
       
  3723     {
       
  3724     iQueryType = KErrNotFound;
       
  3725     
       
  3726     delete iArtist;
       
  3727     iArtist = NULL;
       
  3728 
       
  3729     delete iAlbum;
       
  3730     iAlbum = NULL;
       
  3731     
       
  3732     delete iQuery;
       
  3733     iQuery = NULL;
       
  3734     
       
  3735     iArtist = HBufC::NewL( 0 );
       
  3736     iAlbum = HBufC::NewL( 0 );
       
  3737     }
       
  3738 
       
  3739 
       
  3740 // End of File