profilesservices/MediaFileList/Src/mediafiledialog.cpp
changeset 0 8c5d936e5675
child 1 b5888e2aa472
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     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:   Class of Mediafiledialog. UI control of mediafilelist
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "mediafiledialog.h"
       
    24 #include "mediafiledialogutils.h"
       
    25 #include "mediafilelist.h"
       
    26 #include "mediafilehandler.h"
       
    27 #include "mediafilelistdebug.h"
       
    28 #include "mediafileprotection.h"
       
    29 #include "mediafilevideopreviewdialog.h"
       
    30 #include "mediafiletest.h"  // test code
       
    31 
       
    32 #include <eikclbd.h>        // for CColumnListBoxData
       
    33 #include <coecobs.h>        // MCoeControlObserver
       
    34 #include <AknUtils.h>       // AknTextUtils AknFind
       
    35 #include <AknIconArray.h>   // for GulArray
       
    36 #include <AknWaitDialog.h>
       
    37 #include <textresolver.h>
       
    38 #include <StringLoader.h>
       
    39 #include <akninputblock.h>      // CAknInputBlock
       
    40 #include <mmferrors.h> 
       
    41 // search field
       
    42 #include <aknselectionlist.h>  // AknSelectionList.cpp
       
    43 #include <aknsfld.h>           // CAknSearchField
       
    44 #include <eikcapc.h>         // CEikCaptionedControl
       
    45 
       
    46 #include <aknconsts.h>         // KAvkonBitmapFile, KAvkonVariatedBitmapsFile
       
    47 #include <AknsConstants.h>     // icon constants
       
    48 #include <aknmemorycardui.mbg> // memory card icon
       
    49 #include <avkon.mbg>
       
    50 
       
    51 #include <avkon.loc>
       
    52 #include <mediafilelist.rsg>
       
    53 #include <mediafilelist.mbg>
       
    54 #include <data_caging_path_literals.hrh> // KDC_APP_RESOURCE_DIR
       
    55 
       
    56 
       
    57 
       
    58 
       
    59 
       
    60 /******************************************************************************
       
    61  * class CMediaFileDialog
       
    62  ******************************************************************************/
       
    63 
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMediaFileDialog::NewL
       
    68 //
       
    69 // -----------------------------------------------------------------------------
       
    70 CMediaFileDialog* CMediaFileDialog::NewL()
       
    71     {
       
    72     FLOG( _L("CMediaFileDialog::NewL START") );
       
    73 
       
    74     CMediaFileDialog* self = new (ELeave) CMediaFileDialog();
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78 
       
    79     FLOG( _L("CMediaFileDialog::NewL END") );
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CMediaFileDialog::CMediaFileDialog
       
    86 // 
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CMediaFileDialog::CMediaFileDialog()
       
    90 	{
       
    91 	FLOG( _L("CMediaFileDialog::CMediaFileDialog START") );
       
    92     
       
    93 	iResourceFileId = KErrNotFound;
       
    94     iForeGround = ETrue;
       
    95     iDatabaseOpen = EFalse;
       
    96     iPeninputActive = EFalse;
       
    97     
       
    98     iNullItemFileTypeOne = KErrNotFound;
       
    99     iNullItemFileTypeTwo = KErrNotFound;
       
   100     iDialogTitle = KNullDesC;
       
   101     iIsDoubleClicked = EFalse;
       
   102    
       
   103     FLOG( _L("CMediaFileDialog::CMediaFileDialog END") );
       
   104     }
       
   105 
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // Destructor
       
   109 //
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 CMediaFileDialog::~CMediaFileDialog()
       
   113     {
       
   114     FLOG( _L("CMediaFileDialog::~CMediaFileDialog START") );
       
   115 
       
   116     if ( iResourceFileId != KErrNotFound )
       
   117         {
       
   118         CEikonEnv::Static()->DeleteResourceFile( iResourceFileId );
       
   119         }
       
   120  	
       
   121     delete iStatusPaneHandler;
       
   122  	delete iMFListHandler;
       
   123  	delete iMediaFileHandler;
       
   124  	delete iState;
       
   125 	
       
   126     delete iFindCtrl;
       
   127     delete iCaller;
       
   128     delete iSearchCaller;
       
   129     
       
   130     delete iAudioPreviewHandler;
       
   131     delete iVideoPreviewHandler;
       
   132     
       
   133     delete iNullItemFileNameOne;
       
   134     delete iNullItemFileNameTwo;
       
   135     
       
   136     if ( iAvkonAppUi )
       
   137     	{
       
   138     	iAvkonAppUi->RemoveFromStack(this);
       
   139     	}
       
   140     	
       
   141     CCoeEnv::Static()->RemoveForegroundObserver( *this );
       
   142     
       
   143     if ( iPopupNote )
       
   144         {
       
   145         iPopupNote->HideInfoPopupNote();
       
   146         delete iPopupNote;
       
   147         }
       
   148     
       
   149     delete iWaitNote;
       
   150     if ( AknLayoutUtils::PenEnabled() )
       
   151         {
       
   152         iPeninputServer.RemovePenUiActivationHandler();
       
   153         iPeninputServer.Close();
       
   154         }
       
   155     
       
   156     delete iIdle;
       
   157     
       
   158     delete iProtectionHandler;
       
   159     
       
   160     delete iInputBlock;
       
   161    
       
   162 #ifdef _DEBUG    
       
   163     delete iTest;  // test code
       
   164 #endif
       
   165 	
       
   166     FLOG( _L("CMediaFileDialog::~CMediaFileDialog END") );
       
   167     }
       
   168 
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CMediaFileDialog::ConstructL
       
   172 //
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CMediaFileDialog::ConstructL()
       
   176     {
       
   177     FLOG( _L("CMediaFileDialog::ConstructL START") );
       
   178 	
       
   179     iResourceFileId = TMFDialogUtil::AddResFileL();
       
   180     
       
   181     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   182     coeEnv->AddForegroundObserverL( *this );
       
   183 
       
   184 	CAknDialog::ConstructL( R_MEDIA_FILE_DIALOG_MENU );
       
   185 	
       
   186     if ( iMenuBar )
       
   187         {
       
   188     	iMenuBar->SetContextMenuTitleResourceId(
       
   189 		R_MEDIA_FILE_DIALOG_CONTEXT_MENU );
       
   190 	    }
       
   191 	
       
   192 	// get previous title so it can be restored
       
   193 	iStatusPaneHandler = CStatusPaneHandler::NewL( iAvkonAppUi );
       
   194 	iStatusPaneHandler->StoreOriginalTitleL();
       
   195 	
       
   196 	iMediaFileHandler = CMediaFileHandler::NewL();
       
   197 	iMediaFileHandler->SetObserver( this );
       
   198 	
       
   199     iState = CMediaFileDialogState::NewL();
       
   200     
       
   201 #ifndef RD_VIDEO_AS_RINGING_TONE    
       
   202     iState->HideRootFolder( EEFolderVideos, ETrue,
       
   203                             KNullDesC, KErrNotFound );
       
   204     
       
   205     iMediaFileHandler->SetAttrL( CMediaFileList::EAttrExcludeFolder, CMediaFileList::EFolderVideos );
       
   206 #endif
       
   207  
       
   208     iMFListHandler = CMFListHandler::NewL();
       
   209     iMFListHandler->SetObserver( this );
       
   210     
       
   211     iCaller = CMFActiveCaller::NewL( this );
       
   212     iSearchCaller = CMFActiveCaller::NewL( this );
       
   213     
       
   214     iAudioPreviewHandler = CMFAudioPreviewHandler::NewL();
       
   215     iVideoPreviewHandler = CMFVideoPreviewHandler::NewL();
       
   216     
       
   217     iAudioPreviewHandler->SetObserver( this );
       
   218     
       
   219     iPopupNote = CAknInfoPopupNoteController::NewL();
       
   220     
       
   221     iWaitNote = CMediaFileWaitNote::NewL( this );
       
   222     
       
   223     if ( AknLayoutUtils::PenEnabled() )
       
   224         { 
       
   225         User::LeaveIfError( iPeninputServer.Connect() ); 
       
   226         iPeninputServer.AddPenUiActivationHandler( this, EPluginInputModeAll );
       
   227         }
       
   228     
       
   229     iProtectionHandler = CMFProtectionHandler::NewL();
       
   230     
       
   231 #ifdef _DEBUG    
       
   232     iTest = CMFDialogTest::NewL( this );  // test code
       
   233 #endif
       
   234    
       
   235 	FLOG( _L("CMediaFileDialog::ConstructL END") );
       
   236     }
       
   237 
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CMediaFileDialog::ShowDialogL
       
   241 // 
       
   242 // -----------------------------------------------------------------------------
       
   243 TBool CMediaFileDialog::ShowDialogL( TDes* aFileName, TInt* aNullItem,
       
   244                                      TInt* aInfo, TDes* aDesInfo )
       
   245 	{
       
   246 	__ASSERT_ALWAYS( aFileName, Panic( KErrGeneral ) );
       
   247 	__ASSERT_ALWAYS( aNullItem, Panic( KErrGeneral ) );
       
   248 	
       
   249 	iFileName = aFileName;
       
   250 	
       
   251 	iNullItem = aNullItem;
       
   252 	*iNullItem = KErrNotFound;
       
   253 	
       
   254 	iInfo = aInfo;
       
   255 	iDesInfo = aDesInfo;
       
   256 	
       
   257 	TBool ret = ExecuteLD( R_MEDIA_FILE_DIALOG );
       
   258 	
       
   259 	return ret;
       
   260 	}
       
   261 
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CMediaFileDialog::SetAttrL
       
   265 // 
       
   266 // -----------------------------------------------------------------------------
       
   267 void CMediaFileDialog::SetAttrL( TInt aAttr, TInt aValue )
       
   268 	{
       
   269 	iAudioPreviewHandler->SetAttrL( aAttr, aValue );
       
   270 	iVideoPreviewHandler->SetAttrL( aAttr, aValue );
       
   271 	iMediaFileHandler->SetAttrL( aAttr, aValue );
       
   272 	iProtectionHandler->SetAttrL( aAttr, aValue );
       
   273 
       
   274     if ( aAttr == CMediaFileList::EAttrExcludeFolder )
       
   275         {
       
   276         if ( aValue  == CMediaFileList::EFolderDownload )
       
   277             {
       
   278             iState->HideRootFolder( EEFolderDownload, ETrue,
       
   279                                     KNullDesC, KErrNotFound );
       
   280             }
       
   281         if ( aValue  == CMediaFileList::EFolderVideos )
       
   282             {
       
   283             iState->HideRootFolder( EEFolderVideos, ETrue,
       
   284                                     KNullDesC, KErrNotFound );
       
   285             }
       
   286         }
       
   287 	}
       
   288 
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CMediaFileDialog::SetAttrL
       
   292 // 
       
   293 // -----------------------------------------------------------------------------
       
   294 void CMediaFileDialog::SetAttrL( TInt aAttr, const TDesC& aValue )
       
   295 	{
       
   296 	iAudioPreviewHandler->SetAttrL( aAttr, aValue );
       
   297 	iVideoPreviewHandler->SetAttrL( aAttr, aValue );
       
   298 	iMediaFileHandler->SetAttrL( aAttr, aValue );
       
   299     iProtectionHandler->SetAttrL( aAttr, aValue );
       
   300 	
       
   301 	if ( aAttr == CMediaFileList::EAttrTitle )
       
   302 	    {
       
   303 	    TMFDialogUtil::StrCopy( iDialogTitle, aValue );
       
   304 	    }
       
   305 	}
       
   306 
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CMediaFileDialog::SetAttrL
       
   310 // 
       
   311 // -----------------------------------------------------------------------------
       
   312 void CMediaFileDialog::SetAttrL( TInt aAttr, TAny* aValue )
       
   313     {
       
   314     iAudioPreviewHandler->SetAttrL( aAttr, aValue );
       
   315     iVideoPreviewHandler->SetAttrL( aAttr, aValue );
       
   316     iMediaFileHandler->SetAttrL( aAttr, aValue );
       
   317     }
       
   318 
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CMediaFileDialog::SetNullItemL
       
   322 //
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CMediaFileDialog::SetNullItemL( const TDesC& aText, 
       
   326                                      const TDesC& aMediaFile,
       
   327                                      TInt aMediaFileType, TInt aIconId )
       
   328     {
       
   329     TInt iconId = EEIconEmpty;
       
   330     if ( aIconId == CMediaFileList::ENullItemIconDefaultTone )
       
   331         {
       
   332         iconId = EEIconTone;
       
   333         }
       
   334     else if ( aIconId == CMediaFileList::ENullItemIconOff )
       
   335         {
       
   336         iconId = EEIconNullItemOff;
       
   337         }
       
   338         
       
   339     TInt mediaType = CMediaFileList::EMediaFileTypeAudio;
       
   340     if ( aMediaFileType == CMediaFileList::EMediaFileTypeVideo )
       
   341         {
       
   342         mediaType = CMediaFileList::EMediaFileTypeVideo;
       
   343         }
       
   344         
       
   345         
       
   346     if ( !iNullItemFileNameOne )
       
   347         {
       
   348         iNullItemFileNameOne = aMediaFile.AllocL();
       
   349         iNullItemFileTypeOne = mediaType;
       
   350         
       
   351         iState->EnableNullItemL( EEFolderNullItemOne, aText, iconId );
       
   352         }
       
   353     else if ( !iNullItemFileNameTwo )
       
   354         {
       
   355         iNullItemFileNameTwo = aMediaFile.AllocL();
       
   356         iNullItemFileTypeTwo = mediaType;
       
   357         
       
   358         iState->EnableNullItemL( EEFolderNullItemTwo, aText, iconId );
       
   359         }
       
   360     else
       
   361         {
       
   362         User::Leave( KErrNotSupported ); // two null items supported
       
   363         }
       
   364     }
       
   365 
       
   366 
       
   367 
       
   368 //------------------------------------------------------------------------------
       
   369 // CMediaFileDialog::ActivateL
       
   370 //
       
   371 // Called by system when dialog is activated.
       
   372 //------------------------------------------------------------------------------
       
   373 //
       
   374 void CMediaFileDialog::ActivateL()
       
   375 	{
       
   376     CAknDialog::ActivateL();
       
   377 
       
   378 	// this cannot be in ConstructL which is executed before dialog is launched
       
   379 	iAvkonAppUi->AddToStackL( this );
       
   380 	AknFind::HandleFixedFindSizeChanged( this, iListBox, FindBox() );
       
   381 	DrawNow();
       
   382     }
       
   383 
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CMediaFileDialog::PreLayoutDynInitL
       
   387 // 
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CMediaFileDialog::PreLayoutDynInitL()
       
   391     {
       
   392     const TInt KFindBoxLength = 20;
       
   393     
       
   394     iListBox = (CAknSingleGraphicStyleListBox*) (ControlOrNull(1));
       
   395     
       
   396    	__ASSERT_ALWAYS( iListBox, TMFDialogUtil::Panic( KErrGeneral ) );
       
   397     
       
   398     iListBox->Model()->SetItemTextArray( iMFListHandler );
       
   399     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   400     
       
   401 	iListBox->SetListBoxObserver( this );
       
   402 	iListBox->CreateScrollBarFrameL( ETrue );
       
   403 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   404 	                 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
       
   405 	
       
   406 	iListBox->SetContainerWindowL( *this );
       
   407 	
       
   408 	SetIconsL();
       
   409 	
       
   410 	iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   411 
       
   412 
       
   413     iState->Init();
       
   414     
       
   415     if ( iDialogTitle.Length() > 0 )
       
   416         {
       
   417         iStatusPaneHandler->SetTitleL( iDialogTitle );
       
   418         }
       
   419     else
       
   420         {
       
   421 	    iStatusPaneHandler->SetTitleL( R_QTN_MEDIA_FILE_DIALOG_TITLE );
       
   422         }
       
   423 	iStatusPaneHandler->SetNaviPaneTitleL( KNullDesC );
       
   424 	
       
   425 	
       
   426     //
       
   427     // create find box. NOTE: findbox functionality is quite complex and
       
   428 	// is implemented by copy pasting code from other apps.
       
   429     //
       
   430 	
       
   431     CFindControl* control = ( CFindControl* )ControlOrNull( EFindControl );
       
   432     if ( control )
       
   433         {
       
   434         CAknSearchField::TSearchFieldStyle flags = CAknSearchField::EFixed;
       
   435         control->iFind = CAknSearchField::NewL( 
       
   436                                    *control, flags, 0, KFindBoxLength );
       
   437         //control->iFind = searchField;
       
   438         control->SetContainerWindowL( *this );
       
   439         CEikEdwin& edwin = control->iFind->Editor(); 
       
   440         control->iFind->AddAdaptiveSearchTextObserverL( this );
       
   441         }	
       
   442 
       
   443      if ( FindBox() )
       
   444         {
       
   445         CAknFilteredTextListBoxModel* model = 
       
   446         STATIC_CAST( CAknFilteredTextListBoxModel*, iListBox->Model() );
       
   447        
       
   448         FindBox()->MakeVisible( EFalse );
       
   449         }
       
   450         
       
   451       
       
   452     UpdateListBoxL();
       
   453     
       
   454     DrawDeferred();
       
   455     }
       
   456 
       
   457 
       
   458 //------------------------------------------------------------------------------
       
   459 // CMediaFileDialog::ProcessCommandL
       
   460 //
       
   461 // Handle commands from menu. NOTE: Current implemntation does not use menu.
       
   462 // Menu handling code is here for (possible) future use.
       
   463 //------------------------------------------------------------------------------
       
   464 //
       
   465 void CMediaFileDialog::ProcessCommandL( TInt aCommandId )
       
   466     {
       
   467     HideMenu();
       
   468     
       
   469     switch (aCommandId)
       
   470         {
       
   471         case EAknCmdHelp:
       
   472             {
       
   473             break;
       
   474             }
       
   475 
       
   476         case EAknSoftkeySelect:
       
   477             {
       
   478             TBool ret = HandleOKL( EAttrSelect );
       
   479             if ( ret )
       
   480                 {
       
   481                 TryExitL( EEikCmdExit );
       
   482                 }
       
   483             break;
       
   484             }
       
   485             
       
   486         case EAknSoftkeyView:
       
   487             {
       
   488             PreviewL( CMediaFileList::EMediaFileTypeVideo );
       
   489             break;
       
   490             }
       
   491         case EAknCmdOpen:
       
   492             {
       
   493             HandleOKL( EAttrOpen );
       
   494             break;
       
   495             }
       
   496 
       
   497         case EAknCmdExit:
       
   498         case EEikCmdExit:
       
   499             {
       
   500             // close dialog and exit calling application
       
   501             iAvkonAppUi->ProcessCommandL( EAknCmdExit );
       
   502             break;
       
   503             }
       
   504 
       
   505         default:            
       
   506             break;
       
   507         }
       
   508     }
       
   509 
       
   510 
       
   511 //------------------------------------------------------------------------------
       
   512 // CMediaFileDialog::OkToExitL
       
   513 //
       
   514 // Hanlde commands from cba.
       
   515 //------------------------------------------------------------------------------
       
   516 //
       
   517 TBool CMediaFileDialog::OkToExitL(TInt aButtonId)
       
   518     {
       
   519     if ( aButtonId == EEikBidCancel )
       
   520         {
       
   521         return ETrue;  // close dialog
       
   522         }
       
   523 
       
   524     if ( aButtonId == EEikBidOk )
       
   525         {
       
   526         TBool ret = HandleOKL( EAttrSelect );
       
   527         return ret;
       
   528         }
       
   529 
       
   530     if ( aButtonId == EAknSoftkeyBack )
       
   531         {
       
   532         if ( !HandleBackL() )
       
   533             {
       
   534 #ifdef _DEBUG            
       
   535             // start test code
       
   536             TInt currentIndex = CurrentItemListIndex();
       
   537             if ( iState->FolderId( currentIndex ) == EEFolderRecordings )
       
   538                 {
       
   539                 if ( !iTest->TestL( 0 ) )
       
   540                     {
       
   541                     return ETrue; // test canceled
       
   542                     }
       
   543                 return EFalse;  // test accepted
       
   544                 }
       
   545             // end test code
       
   546 #endif            
       
   547             
       
   548             return ETrue; // Back pressed in top level folder
       
   549             }
       
   550             
       
   551         return EFalse; // leave dialog open
       
   552         }
       
   553 
       
   554     if ( aButtonId == EAknSoftkeyContextOptions )
       
   555         {
       
   556         ShowContextMenuL( R_MEDIA_FILE_DIALOG_CONTEXT_MENU );
       
   557         return EFalse;
       
   558         }
       
   559 
       
   560     if ( aButtonId == EAknSoftkeyOpen )
       
   561         {
       
   562         TBool ret = HandleOKL( EAttrOpen );
       
   563         return ret;
       
   564         }
       
   565     
       
   566     if ( aButtonId == EAknSoftkeySelect )
       
   567         {
       
   568         TBool ret = HandleOKL( EAttrSelect );
       
   569         return ret;
       
   570         }
       
   571     
       
   572     if ( aButtonId == EAknSoftkeyView )
       
   573         {
       
   574         PreviewL( CMediaFileList::EMediaFileTypeVideo );
       
   575         return EFalse;
       
   576         }
       
   577 
       
   578     if ( aButtonId == EAknSoftkeyEmpty )
       
   579         {
       
   580         return EFalse;
       
   581         }
       
   582 
       
   583     return CAknDialog::OkToExitL( aButtonId );
       
   584     }
       
   585 
       
   586 
       
   587 // ----------------------------------------------------------------------------
       
   588 // CMediaFileDialog::OfferKeyEventL
       
   589 // 
       
   590 // ----------------------------------------------------------------------------
       
   591 //
       
   592 TKeyResponse CMediaFileDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   593                                                       TEventCode aType)
       
   594     {
       
   595     // must pass escape event to dialog - findbox and listbox "eat" escape events
       
   596     TKeyResponse res = EKeyWasNotConsumed;
       
   597     if ( aType == EEventKey && aKeyEvent.iCode == EKeyEscape )
       
   598         {
       
   599         res = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   600         }
       
   601     if ( res == EKeyWasConsumed ) 
       
   602         {
       
   603         return res;
       
   604         }
       
   605         
       
   606 
       
   607     TBool backSpace = EFalse;
       
   608     
       
   609     if (aType == EEventKey)
       
   610         {
       
   611         switch (aKeyEvent.iCode)
       
   612             {
       
   613             case EKeyEnter:
       
   614                 {
       
   615                 break;
       
   616                 }
       
   617             case EKeyUpArrow:
       
   618             case EKeyDownArrow:
       
   619                 {
       
   620                 TInt itemCount = iListBox->Model()->NumberOfItems();
       
   621                 if ( itemCount == 1 )
       
   622                     {
       
   623                     PreviewL( CMediaFileList::EMediaFileTypeAudio );    
       
   624                     }
       
   625                 break;
       
   626                 }
       
   627 
       
   628             case EKeyLeftArrow:
       
   629                 {
       
   630                 if (FindBox() && FindBox()->IsVisible()
       
   631                         && FindBox()->TextLength() != 0)
       
   632                     {
       
   633                     FindBoxCursorMoveL( 0 );
       
   634                     res = EKeyWasConsumed;
       
   635                     }
       
   636                 else
       
   637                     {
       
   638                     HandleBackL();
       
   639                     return EKeyWasConsumed;
       
   640                     }
       
   641                 break;
       
   642                 }
       
   643 
       
   644             case EKeyRightArrow:
       
   645                 {
       
   646                 if (FindBox() && FindBox()->IsVisible()
       
   647                         && FindBox()->TextLength() != 0)
       
   648                     {
       
   649                     FindBoxCursorMoveL( 1 );
       
   650                     res = EKeyWasConsumed;
       
   651                     }
       
   652                 else
       
   653                     {
       
   654                     HandleOKL( EAttrOpen );
       
   655                     return EKeyWasConsumed;
       
   656                     }
       
   657                 break;
       
   658                 }
       
   659 
       
   660             case EKeyBackspace:
       
   661                 {  
       
   662                 backSpace = ETrue;
       
   663                 break;
       
   664                 }
       
   665 
       
   666             default:
       
   667                 {
       
   668                 break;
       
   669                 }
       
   670             }
       
   671         
       
   672     if ( FindBox() && FindBox()->IsVisible() )
       
   673         {
       
   674         res = FindBox()->OfferKeyEventL( aKeyEvent, aType );
       
   675         
       
   676         if ( backSpace && FindBox()->TextLength() == 0 &&
       
   677              ( iState->CurrentFolder() == EEFolderSearch ||
       
   678              iState->CurrentFolder() == EEFolderSearchMusic ) && !iPeninputActive )
       
   679             {
       
   680             // user cleared search field - go back to main view
       
   681             HandleBackL();
       
   682             return EKeyWasConsumed;
       
   683             }
       
   684         }
       
   685         }
       
   686         
       
   687   
       
   688     if ( res == EKeyWasNotConsumed )
       
   689          {
       
   690          res = CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   691          }
       
   692     return res;
       
   693     }
       
   694 
       
   695 
       
   696 // -----------------------------------------------------------------------------
       
   697 // CMediaFileDialog::FindBoxCursorMoveL( TInt aType )
       
   698 //
       
   699 // NOTE: This function is used to move the cursor of the find box.
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 void CMediaFileDialog::FindBoxCursorMoveL( TInt aType )
       
   703     {
       
   704     if ( FindBox() && FindBox()->IsVisible() )
       
   705         {
       
   706         TInt pos = FindBox()->Editor().CursorPos();
       
   707         TInt textLength = FindBox()->Editor().TextLength();
       
   708         if ( aType == 0 )//left
       
   709             {
       
   710             pos = pos - 1;
       
   711             if ( pos < 0 )
       
   712                 {
       
   713                 pos = textLength;
       
   714                 }
       
   715             }
       
   716         else if ( aType == 1 )
       
   717             {
       
   718             pos = pos + 1;
       
   719             if ( pos > textLength )
       
   720                 {
       
   721                 pos = 0;
       
   722                 }
       
   723             }
       
   724         else
       
   725             {
       
   726             pos = textLength;
       
   727             }
       
   728         FindBox()->Editor().SetCursorPosL( pos ,EFalse );
       
   729         }
       
   730     }
       
   731 // -----------------------------------------------------------------------------
       
   732 // CMediaFileDialog::SetSizeAndPosition (from CAknDialog)
       
   733 //
       
   734 // NOTE: This code is copy paste from elsewhere.
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 void CMediaFileDialog::SetSizeAndPosition( const TSize& /*aSize*/ )
       
   738     {
       
   739     TRect mainPane;
       
   740     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
   741     
       
   742     SetRect( mainPane );
       
   743 
       
   744     if ( FindBox() && FindBox()->IsVisible() )
       
   745         {
       
   746         AknFind::HandleFixedFindSizeChanged( this, iListBox, FindBox() );
       
   747         }
       
   748 
       
   749     Line( ESelectionListControl)->SetRect( iListBox->Rect() );
       
   750     if ( FindBox() ) 
       
   751         {
       
   752         Line( EFindControl )->SetRect( iListBox->Rect() );
       
   753         }    
       
   754     }
       
   755 
       
   756 
       
   757 // ----------------------------------------------------------------------------
       
   758 // CMediaFileDialog::HandleResourceChange
       
   759 // 
       
   760 // ----------------------------------------------------------------------------
       
   761 //
       
   762 void CMediaFileDialog::HandleResourceChange(TInt aType)
       
   763     {   
       
   764     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   765         {
       
   766         // handle change in layout orientation
       
   767         CAknDialog::HandleResourceChange( aType );
       
   768          if ( FindBox() && FindBox()->IsVisible() )
       
   769 	        {
       
   770 	        AknFind::HandleFixedFindSizeChanged( this, iListBox, FindBox() );
       
   771 	        }
       
   772         return;
       
   773         }
       
   774         
       
   775     if (aType == KAknsMessageSkinChange)
       
   776         {
       
   777         TRAP_IGNORE( SetIconsL() );
       
   778         }
       
   779         
       
   780     CCoeControl::HandleResourceChange( aType );
       
   781     }
       
   782 
       
   783 
       
   784 //------------------------------------------------------------------------------
       
   785 // CMediaFileDialog::DynInitMenuPaneL
       
   786 //
       
   787 // Called by system before menu is shown. NOTE: Menu currently not used. 
       
   788 //------------------------------------------------------------------------------
       
   789 //
       
   790 void CMediaFileDialog::DynInitMenuPaneL(TInt aResourceID, CEikMenuPane* aMenuPane )
       
   791     {
       
   792     TInt menu1 = R_MEDIA_FILE_DIALOG_MENU_PANE;
       
   793     TInt menu2 = R_MEDIA_FILE_DIALOG_CONTEXT_MENU_PANE;
       
   794     
       
   795     if ( aResourceID != menu1 && aResourceID != menu2 )
       
   796         {
       
   797         return; // not one of our menus
       
   798         }
       
   799 
       
   800     TInt itemCount = iListBox->Model()->NumberOfItems();
       
   801     TInt currentIndex = iListBox->CurrentItemIndex();
       
   802     TInt folderId = iState->FolderId( currentIndex );
       
   803     TInt currentFolderId = iState->CurrentFolder();
       
   804 
       
   805 
       
   806     // context menu only used in video folder
       
   807     if ( aResourceID == R_MEDIA_FILE_DIALOG_CONTEXT_MENU_PANE )
       
   808         {
       
   809         if ( itemCount == 0 )
       
   810             {
       
   811             // folder is empty
       
   812             DeleteMenuItem( aMenuPane, EAknSoftkeySelect );
       
   813             DeleteMenuItem( aMenuPane, EAknSoftkeyView );
       
   814             }
       
   815         return;
       
   816         }
       
   817 
       
   818     
       
   819     if ( itemCount == 0 )
       
   820         {
       
   821         // list has no items
       
   822         DeleteMenuItem( aMenuPane, EAknCmdOpen );
       
   823         DeleteMenuItem( aMenuPane, EAknSoftkeySelect );
       
   824         DeleteMenuItem( aMenuPane, EAknSoftkeyView );
       
   825         return;
       
   826         }
       
   827     
       
   828     if ( folderId == EEFolderDownload || folderId == EEFolderNullItemOne || 
       
   829          folderId == EEFolderNullItemTwo )
       
   830         {
       
   831         // selected item is null item
       
   832         DeleteMenuItem( aMenuPane, EAknCmdOpen );
       
   833         DeleteMenuItem( aMenuPane, EAknSoftkeyView );
       
   834         }
       
   835     else if ( folderId != KErrNotFound )
       
   836         {
       
   837         // selected item is folder
       
   838         DeleteMenuItem( aMenuPane, EAknSoftkeySelect );
       
   839         DeleteMenuItem( aMenuPane, EAknSoftkeyView );
       
   840         }
       
   841     else
       
   842         {
       
   843         // selected item is file
       
   844         if ( iState->CurrentFolder() == EEFolderVideos )
       
   845             {
       
   846             DeleteMenuItem( aMenuPane, EAknCmdOpen );
       
   847             }
       
   848         else if ( iState->CurrentFolder() == EEFolderSearch )
       
   849             {
       
   850             DeleteMenuItem( aMenuPane, EAknCmdOpen );
       
   851         
       
   852             if ( !IsVideoFile( currentIndex ) )
       
   853                 {
       
   854                 DeleteMenuItem( aMenuPane, EAknSoftkeyView );
       
   855                 }
       
   856             }
       
   857         else
       
   858             {
       
   859             DeleteMenuItem( aMenuPane, EAknCmdOpen );
       
   860             DeleteMenuItem( aMenuPane, EAknSoftkeyView );    
       
   861             }
       
   862         }
       
   863     }
       
   864 
       
   865 
       
   866 // ---------------------------------------------------------------------------
       
   867 // CMediaFileDialog::CountComponentControls
       
   868 //
       
   869 // Gets the number of controls contained in a compound control.
       
   870 // ---------------------------------------------------------------------------
       
   871 //
       
   872 TInt CMediaFileDialog::CountComponentControls() const
       
   873     {
       
   874     TInt newitems = 0;
       
   875     if ( FindBox() )
       
   876         {
       
   877         newitems++;
       
   878         }
       
   879     return CAknDialog::CountComponentControls() + newitems;
       
   880     }
       
   881 
       
   882 
       
   883 // ---------------------------------------------------------------------------
       
   884 // CMediaFileDialog::CountComponentControls
       
   885 //
       
   886 // ---------------------------------------------------------------------------
       
   887 //
       
   888 CCoeControl* CMediaFileDialog::ComponentControl( TInt aIndex ) const
       
   889     {
       
   890     if ( aIndex == CAknDialog::CountComponentControls() )
       
   891         {
       
   892         return FindBox();
       
   893         }
       
   894     return CAknDialog::ComponentControl( aIndex );
       
   895     }
       
   896 
       
   897 
       
   898 // -----------------------------------------------------------------------------
       
   899 // CMediaFileDialog::FindBox
       
   900 //
       
   901 // -----------------------------------------------------------------------------
       
   902 //
       
   903 CAknSearchField* CMediaFileDialog::FindBox() const
       
   904      {
       
   905      CFindControl* control = ( CFindControl* )ControlOrNull( EFindControl );
       
   906      if ( control )
       
   907          {
       
   908          return control->iFind;
       
   909          }
       
   910      else
       
   911          {
       
   912          return NULL;
       
   913          }
       
   914      }
       
   915 
       
   916 // ---------------------------------------------------------------------------
       
   917 // CMediaFileDialog::ResetFindBoxL
       
   918 //
       
   919 // ---------------------------------------------------------------------------
       
   920 //
       
   921 void CMediaFileDialog::ResetFindBoxL()
       
   922     {
       
   923     if ( !FindBox() )
       
   924         {
       
   925         return;
       
   926         }
       
   927    
       
   928     CAknFilteredTextListBoxModel* model = 
       
   929     STATIC_CAST( CAknFilteredTextListBoxModel*, iListBox->Model() );
       
   930     CAknListBoxFilterItems* filter = model->Filter();
       
   931     TInt currentFolder = iState->CurrentFolder();
       
   932     
       
   933     // reset find box
       
   934     if ( filter )
       
   935         {
       
   936         filter->ResetFilteringL();
       
   937         filter->SetObserver( NULL );
       
   938         model->RemoveFilter();
       
   939         
       
   940         // CreateFilterL sets CAknSearchField to observe filter
       
   941         // (CAknListBoxFilterItems) but RemoveFilter does not remove observer
       
   942         FindBox()->SetObserver( NULL );
       
   943         }
       
   944     
       
   945     if (FindBox()->TextLength() > 0 && (currentFolder != EEFolderSearch
       
   946             && currentFolder != EEFolderSearchMusic))
       
   947         {
       
   948         FindBox()->SetSearchTextL( KNullDesC );    
       
   949         }
       
   950     
       
   951  
       
   952     // show/hide find box
       
   953     if ( iState->FindBoxNeeded() )
       
   954         {
       
   955         if ( currentFolder != EEFolderSearch && 
       
   956              currentFolder != EEFolderSearchMusic &&
       
   957              currentFolder != EEFolderRoot &&
       
   958              currentFolder != EEFolderMusic )
       
   959             {
       
   960             // normal find only finds matches from listbox item texts
       
   961             model->CreateFilterL( iListBox, FindBox() );
       
   962             filter = model->Filter();
       
   963             filter->ResetFilteringL();
       
   964             filter->SetObserver( this );     // MCoeControlObserver
       
   965             }
       
   966         else
       
   967             {
       
   968             // search and root folders have custom find that makes
       
   969             // database search
       
   970             FindBox()->SetObserver( this );  // MCoeControlObserver
       
   971             }
       
   972 //        if ( currentFolder == EEFolderSearch || 
       
   973 //             currentFolder == EEFolderSearchMusic )
       
   974 //            {
       
   975 //            FindBox()->SetSearchTextL( iSearchText );
       
   976 //            }
       
   977  
       
   978         FindBox()->MakeVisible( ETrue );
       
   979         }
       
   980     else
       
   981         {
       
   982         FindBox()->MakeVisible( EFalse );
       
   983         }
       
   984             
       
   985     TSize size;
       
   986     SetSizeAndPosition( size );
       
   987     }
       
   988 
       
   989 
       
   990 // -----------------------------------------------------------------------------
       
   991 // CMediaFileDialog::CreateCustomControlL (from CAknDialog)
       
   992 //
       
   993 // Create find control.
       
   994 // -----------------------------------------------------------------------------
       
   995 //
       
   996 SEikControlInfo CMediaFileDialog::CreateCustomControlL( TInt aControlType )
       
   997     {
       
   998     if ( aControlType != EAknCtSelectionListPopupFind &&
       
   999          aControlType != EAknCtSelectionListFixedFind )
       
  1000         {
       
  1001         SEikControlInfo info;
       
  1002         info.iControl = NULL;
       
  1003         info.iFlags = 0;
       
  1004         info.iTrailerTextId = 0;
       
  1005         return info;
       
  1006         }
       
  1007 
       
  1008     CCoeControl* findControl = NULL;
       
  1009     findControl = new (ELeave) CFindControl;
       
  1010 
       
  1011     SEikControlInfo info;
       
  1012     info.iControl = findControl;
       
  1013     info.iFlags = 0;
       
  1014     info.iTrailerTextId = 0;
       
  1015     return info;
       
  1016     }
       
  1017 
       
  1018     
       
  1019 // ----------------------------------------------------------------------------
       
  1020 // CMediaFileDialog::SetIconsL
       
  1021 //
       
  1022 // ----------------------------------------------------------------------------
       
  1023 //
       
  1024 void CMediaFileDialog::SetIconsL()
       
  1025     {
       
  1026     _LIT( KBitmapFile, "mediafilelist.mbm" );
       
  1027     
       
  1028         
       
  1029     if ( !iListBox )
       
  1030         {
       
  1031         return;
       
  1032         }
       
  1033     
       
  1034     TMFDialogUtil::SetIconFileNameL( KBitmapFile, iIconFileName );
       
  1035     
       
  1036     CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(1);
       
  1037     CleanupStack::PushL( icons );
       
  1038 
       
  1039     
       
  1040     //
       
  1041     // NOTE: append order must match TMediaFileListIcons
       
  1042     //
       
  1043     
       
  1044     // music item icon
       
  1045     icons->AppendL( IconL( KAknsIIDQgnIndiAiNtMusic, iIconFileName,
       
  1046                            EMbmMediafilelistQgn_indi_ai_nt_music,
       
  1047                            EMbmMediafilelistQgn_indi_ai_nt_music_mask ) );
       
  1048 
       
  1049     // tone item icon, default tone icon
       
  1050     icons->AppendL( IconL( KAknsIIDQgnPropMupAudio, iIconFileName,
       
  1051                            EMbmMediafilelistQgn_prop_mup_audio,
       
  1052                            EMbmMediafilelistQgn_prop_mup_audio_mask ) );
       
  1053 
       
  1054     // video item icon
       
  1055     icons->AppendL( IconL( KAknsIIDQgnPropFmgrFileVideo, iIconFileName,
       
  1056                            EMbmMediafilelistQgn_prop_fmgr_file_video,
       
  1057                            EMbmMediafilelistQgn_prop_fmgr_file_video_mask ) );
       
  1058 
       
  1059     // recording item icon
       
  1060     icons->AppendL( IconL( KAknsIIDQgnPropFmgrFileVoicerec, iIconFileName,
       
  1061                            EMbmMediafilelistQgn_prop_fmgr_file_voicerec,
       
  1062                            EMbmMediafilelistQgn_prop_fmgr_file_voicerec_mask ) );
       
  1063 
       
  1064     // artist icon
       
  1065     icons->AppendL( IconL( KAknsIIDQgnPropMupArtist, iIconFileName,
       
  1066                            EMbmMediafilelistQgn_prop_mup_artist,
       
  1067                            EMbmMediafilelistQgn_prop_mup_artist_mask ) );
       
  1068 
       
  1069     // album icon
       
  1070     icons->AppendL( IconL( KAknsIIDQgnPropMupAlbum, iIconFileName,
       
  1071                            EMbmMediafilelistQgn_prop_mup_album,
       
  1072                            EMbmMediafilelistQgn_prop_mup_album_mask ) );
       
  1073 
       
  1074     // genre icon
       
  1075     icons->AppendL( IconL( KAknsIIDQgnPropMupGenre, iIconFileName,
       
  1076                            EMbmMediafilelistQgn_prop_mup_genre,
       
  1077                            EMbmMediafilelistQgn_prop_mup_genre_mask ) );
       
  1078 
       
  1079     // composer icon
       
  1080     icons->AppendL( IconL( KAknsIIDQgnPropMupComposer, iIconFileName,
       
  1081                            EMbmMediafilelistQgn_prop_mup_composer,
       
  1082                            EMbmMediafilelistQgn_prop_mup_composer_mask ) );
       
  1083 
       
  1084     // folder icon (tones, music, videos, recordings, all music, artist,
       
  1085     // album, genre, composer, artist all)
       
  1086     icons->AppendL( IconL( KAknsIIDQgnPropFolderSmall, iIconFileName,
       
  1087                            EMbmMediafilelistQgn_prop_folder_small,
       
  1088                            EMbmMediafilelistQgn_prop_folder_small_mask ) );
       
  1089 
       
  1090     // unknown folder icon
       
  1091     icons->AppendL( IconL( KAknsIIDQgnPropMceUnknownRead, iIconFileName,
       
  1092                            EMbmMediafilelistQgn_prop_mce_unknown_read,
       
  1093                            EMbmMediafilelistQgn_prop_mce_unknown_read ) );
       
  1094 
       
  1095     // download item icon (null item)
       
  1096     icons->AppendL( IconL( KAknsIIDQgnPropLinkEmbdSmall, iIconFileName,
       
  1097                            EMbmMediafilelistQgn_prop_link_embd_small,
       
  1098                            EMbmMediafilelistQgn_prop_link_embd_small_mask ) );
       
  1099 
       
  1100     // off item icon (null item)
       
  1101     icons->AppendL( IconL( KAknsIIDQgnPropSmlSyncOff, iIconFileName,
       
  1102                            EMbmMediafilelistQgn_prop_sml_sync_off,
       
  1103                            EMbmMediafilelistQgn_prop_sml_sync_off_mask ) );
       
  1104 
       
  1105     // memory card icon
       
  1106     icons->AppendL( IconL( KAknsIIDQgnIndiMmcAdd, iIconFileName,
       
  1107                            EMbmMediafilelistQgn_indi_mmc_add,
       
  1108                            EMbmMediafilelistQgn_indi_mmc_add_mask ) );
       
  1109 
       
  1110      // mass storage icon
       
  1111     icons->AppendL( IconL( KAknsIIDQgnPropLinkEmbdSmall, iIconFileName,
       
  1112                            EMbmMediafilelistQgn_indi_fmgr_ms_add,
       
  1113                            EMbmMediafilelistQgn_indi_fmgr_ms_add_mask ) );
       
  1114 
       
  1115     // empty icon
       
  1116     icons->AppendL( IconL( KAknsIIDQgnPropEmpty, KAvkonBitmapFile,
       
  1117                            EMbmAvkonQgn_prop_empty,
       
  1118                            EMbmAvkonQgn_prop_empty_mask ) );
       
  1119     
       
  1120     // delete old icons
       
  1121     CArrayPtr<CGulIcon>* arr = iListBox->ItemDrawer()->ColumnData()->IconArray();
       
  1122     if ( arr )
       
  1123         {
       
  1124         arr->ResetAndDestroy();
       
  1125         delete arr;
       
  1126         arr = NULL;
       
  1127         }
       
  1128 
       
  1129     iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
  1130     CleanupStack::Pop( icons );
       
  1131     }
       
  1132 
       
  1133 
       
  1134 // -----------------------------------------------------------------------------
       
  1135 // CMediaFileDialog::IconL
       
  1136 // 
       
  1137 // -----------------------------------------------------------------------------
       
  1138 //
       
  1139 CGulIcon* CMediaFileDialog::IconL(TAknsItemID aId, const TDesC& aFileName,
       
  1140                                    TInt aFileIndex, TInt aFileMaskIndex)
       
  1141 	{
       
  1142     CGulIcon* icon = AknsUtils::CreateGulIconL(AknsUtils::SkinInstance(), aId,
       
  1143                                 aFileName, aFileIndex, aFileMaskIndex);
       
  1144 	return icon;	
       
  1145 	}
       
  1146 
       
  1147 
       
  1148 // ----------------------------------------------------------------------------
       
  1149 // CMediaFileDialog::ShowContextMenuL
       
  1150 // 
       
  1151 // ----------------------------------------------------------------------------
       
  1152 //
       
  1153 void CMediaFileDialog::ShowContextMenuL( TInt /*aResource*/ )
       
  1154 	{
       
  1155 	// Switch to Context specific options menu,
       
  1156 	if ( iMenuBar )
       
  1157 	    {
       
  1158 	    TRAP_IGNORE( iMenuBar->TryDisplayContextMenuBarL() );    
       
  1159 	    }
       
  1160 	}
       
  1161 
       
  1162 
       
  1163 //------------------------------------------------------------------------------
       
  1164 // CMediaFileDialog::HandleBackL
       
  1165 //
       
  1166 //------------------------------------------------------------------------------
       
  1167 //
       
  1168 TBool CMediaFileDialog::HandleBackL()
       
  1169 	{
       
  1170 	TInt err = KErrNone;
       
  1171 	TBool ret = ETrue;
       
  1172 
       
  1173 	TRAP( err, ret = DoHandleBackL() );
       
  1174 	
       
  1175     if ( err != KErrNone )
       
  1176         {
       
  1177         FLOG( _L("### CMediaFileDialog::HandleBackL (%d) ###"), err );
       
  1178         
       
  1179         ResetDialogL( err );
       
  1180         return ETrue;
       
  1181         }
       
  1182         
       
  1183     return ret;
       
  1184 	}
       
  1185 
       
  1186 
       
  1187 //------------------------------------------------------------------------------
       
  1188 // CMediaFileDialog::DoHandleBackL
       
  1189 //
       
  1190 //------------------------------------------------------------------------------
       
  1191 //
       
  1192 TBool CMediaFileDialog::DoHandleBackL()
       
  1193 	{
       
  1194     if ( iState->CurrentFolder() == EEFolderRoot )
       
  1195         {
       
  1196         // return EFalse only when called from root folder
       
  1197         return EFalse;    
       
  1198         }
       
  1199 
       
  1200 	if ( !iMediaFileHandler->QueryReady() )
       
  1201 	    {
       
  1202 	    FLOG( _L("### CMediaFileDialog::DoHandleBackL: query in progress ###") );
       
  1203 	    return ETrue;  // query in progress
       
  1204 	    }
       
  1205   
       
  1206     TInt folderId = iState->NextFolderUp();
       
  1207     TInt currentIndex = CurrentItemListIndex();
       
  1208     
       
  1209     iState->SetQueryInfo( folderId, KNullDesC, currentIndex, EEQueryUp );
       
  1210     QueryL( folderId );
       
  1211     
       
  1212     return ETrue;
       
  1213     }
       
  1214 
       
  1215 
       
  1216 //------------------------------------------------------------------------------
       
  1217 // CMediaFileDialog::HandleOKL
       
  1218 //
       
  1219 //------------------------------------------------------------------------------
       
  1220 //
       
  1221 TBool CMediaFileDialog::HandleOKL( TInt aAttr )
       
  1222 	{
       
  1223     TInt err = KErrNone;
       
  1224     TBool ret = EFalse;
       
  1225     
       
  1226     TRAP( err, ret = DoHandleOKL( aAttr ) );
       
  1227     
       
  1228     if ( err != KErrNone )
       
  1229         {
       
  1230         FLOG( _L("### CMediaFileDialog::HandleOKL (%d) ###"), err );
       
  1231         
       
  1232         ResetDialogL( err );
       
  1233         return EFalse;
       
  1234         }
       
  1235         
       
  1236     return ret;
       
  1237     }
       
  1238 
       
  1239 
       
  1240 //------------------------------------------------------------------------------
       
  1241 // CMediaFileDialog::DoHandleOKL
       
  1242 //
       
  1243 // Selects file or opens folder. If file is selected (ie dialog can
       
  1244 // be closed) return value is ETrue.
       
  1245 //------------------------------------------------------------------------------
       
  1246 //
       
  1247 TBool CMediaFileDialog::DoHandleOKL( TInt aAttr )
       
  1248 	{
       
  1249 	if ( !iMediaFileHandler->QueryReady() )
       
  1250 	    {
       
  1251 	    FLOG( _L("### CMediaFileDialog::DoHandleOKL: query in progress ###") );
       
  1252 	    return EFalse;  // query in progress
       
  1253 	    }
       
  1254 	    
       
  1255     TInt currentIndex = CurrentItemListIndex();
       
  1256     if ( currentIndex == KErrNotFound )
       
  1257         {
       
  1258         return EFalse; // empty folder
       
  1259         }
       
  1260         
       
  1261     TBool isPersistent = EFalse;
       
  1262     TInt iconId = EEIconEmpty;
       
  1263     TInt folderId = KErrNotFound;
       
  1264     iState->GetFolderInfo( currentIndex, folderId, iBuf,
       
  1265                                          isPersistent, iconId );
       
  1266 
       
  1267     if ( folderId == EEFolderDownload || folderId == EEFolderNullItemOne ||
       
  1268          folderId == EEFolderNullItemTwo || folderId == KErrNotFound )
       
  1269         {
       
  1270         if ( aAttr == EAttrOpen )
       
  1271             {
       
  1272             return EFalse;  // these can only be selected, not opened    
       
  1273             }
       
  1274         }
       
  1275         
       
  1276 
       
  1277     if ( folderId == EEFolderDownload )
       
  1278         {
       
  1279         *iNullItem = 0;
       
  1280          // user selected 'Download' item - launch browser
       
  1281          CWebBrowserLauncher* launcher = CWebBrowserLauncher::NewLC();
       
  1282          launcher->LaunchBrowserL();
       
  1283          CleanupStack::PopAndDestroy( launcher );
       
  1284          return EFalse;
       
  1285         }
       
  1286 
       
  1287     if ( folderId == EEFolderNullItemOne )
       
  1288         {
       
  1289         if ( iNullItemFileNameOne )
       
  1290             {
       
  1291             TMFDialogUtil::StrCopy( *iFileName, *iNullItemFileNameOne );
       
  1292             }
       
  1293         *iNullItem = 1;
       
  1294         return ETrue;
       
  1295         }
       
  1296 
       
  1297     if ( folderId == EEFolderNullItemTwo )
       
  1298         {
       
  1299         if ( iNullItemFileNameTwo )
       
  1300             {
       
  1301             TMFDialogUtil::StrCopy( *iFileName, *iNullItemFileNameTwo );
       
  1302             }
       
  1303         *iNullItem = 2;
       
  1304         return ETrue;
       
  1305         }
       
  1306 
       
  1307     if ( folderId == KErrNotFound )
       
  1308         {
       
  1309         // user has selected some media file
       
  1310 	    GetSelectedItemFileName( currentIndex, iBuf );
       
  1311 	    
       
  1312 	    TBool ret = ETrue;
       
  1313 	    
       
  1314 	    // protection check not done when item is double checked
       
  1315 	   // if ( aAttr != EAttrDoubleClicked )
       
  1316 	   if (!ifilevalid)
       
  1317 	        {
       
  1318 	    	iFileisvalid = iProtectionHandler->IsFileValid( iBuf, 
       
  1319 	                                        CMFProtectionHandler::ESelect );
       
  1320 	    ifilevalid=ETrue;
       
  1321 	        }
       
  1322 	    
       
  1323   	   if ( !iFileisvalid)
       
  1324 		   {
       
  1325 		   ifilevalid=EFalse; 
       
  1326 		   }
       
  1327 	    if ( iFileisvalid )
       
  1328 	        {
       
  1329 	        TMFDialogUtil::StrCopy( *iFileName, iBuf );
       
  1330 	        }
       
  1331 	    
       
  1332 	    return iFileisvalid;  // ret is ETrue is selected file's drm is OK
       
  1333         }
       
  1334 
       
  1335     
       
  1336     if ( folderId != KErrNotFound && aAttr != EAttrSelect )
       
  1337         {
       
  1338         iBuf = KNullDesC;
       
  1339         // selected list item is folder
       
  1340          if ( !isPersistent )
       
  1341             {
       
  1342             // read non-persistent folder text from database
       
  1343             GetListItemText( currentIndex, iBuf );
       
  1344             }
       
  1345       
       
  1346         iState->SetQueryInfo( folderId, iBuf, currentIndex, EEQueryDown );
       
  1347         QueryL( folderId );
       
  1348         }
       
  1349 
       
  1350     return EFalse;
       
  1351     }
       
  1352 
       
  1353 
       
  1354 //------------------------------------------------------------------------------
       
  1355 // CMediaFileDialog::SearchL
       
  1356 //
       
  1357 //------------------------------------------------------------------------------
       
  1358 //
       
  1359 void CMediaFileDialog::SearchL()
       
  1360     {
       
  1361     TInt err = KErrNone;
       
  1362     
       
  1363     TRAP( err, DoSearchL() );
       
  1364     
       
  1365     if ( err != KErrNone )
       
  1366         {
       
  1367         ResetDialogL( err );
       
  1368         }
       
  1369     }
       
  1370 
       
  1371 
       
  1372 //------------------------------------------------------------------------------
       
  1373 // CMediaFileDialog::DoSearchL
       
  1374 //
       
  1375 //------------------------------------------------------------------------------
       
  1376 //
       
  1377 void CMediaFileDialog::DoSearchL()
       
  1378     {
       
  1379     if ( !FindBox() )
       
  1380         {
       
  1381         return;
       
  1382         }
       
  1383     
       
  1384     if ( iPeninputActive)
       
  1385         {
       
  1386       return;
       
  1387         }
       
  1388     if ( !iMediaFileHandler->QueryReady() )
       
  1389         {
       
  1390         FLOG( _L("### CMediaFileDialog::DoSearchL: query in progress ###") );
       
  1391         return;  // query in progress
       
  1392         }
       
  1393     
       
  1394     TInt currentFolder = iState->CurrentFolder();
       
  1395     
       
  1396     if ( FindBox()->TextLength() == 0 )
       
  1397         {
       
  1398         return;
       
  1399         }
       
  1400     FindBox()->GetSearchText( iSearchText );
       
  1401     
       
  1402     _LIT(KSpecialChar, "%");
       
  1403     _LIT(KReplaceChar, "\\%" );
       
  1404     TBuf<10> buf;
       
  1405     buf.Copy( KSpecialChar );
       
  1406     TInt position = iSearchText.FindF( buf );
       
  1407     if ( position != KErrNotFound )
       
  1408         {
       
  1409         buf.Copy( KReplaceChar );
       
  1410         iSearchText.Replace( position,1,buf );
       
  1411         }
       
  1412 
       
  1413     
       
  1414     if ( currentFolder == EEFolderRoot || currentFolder == EEFolderSearch )
       
  1415         {
       
  1416         TInt currentIndex = iListBox->CurrentItemIndex();
       
  1417         iState->SetQueryInfo( EEFolderSearch, KNullDesC, currentIndex, EEQueryDown );
       
  1418         
       
  1419         QueryL( EEFolderSearch );
       
  1420         }
       
  1421     else if ( currentFolder == EEFolderMusic || currentFolder == EEFolderSearchMusic )
       
  1422         {
       
  1423         TInt currentIndex = iListBox->CurrentItemIndex();
       
  1424         iState->SetQueryInfo( EEFolderSearchMusic, KNullDesC, currentIndex, EEQueryDown );
       
  1425         
       
  1426         QueryL( EEFolderSearchMusic );
       
  1427         }
       
  1428     }
       
  1429 
       
  1430 
       
  1431 //------------------------------------------------------------------------------
       
  1432 // CMediaFileDialog::ResetDialogL
       
  1433 //
       
  1434 //------------------------------------------------------------------------------
       
  1435 //
       
  1436 void CMediaFileDialog::ResetDialogL( TInt aError)
       
  1437     {
       
  1438     iMediaFileHandler->EnableObserverCall( EFalse );
       
  1439     iMediaFileHandler->CancelQuery();
       
  1440     iMediaFileHandler->EnableObserverCall( ETrue );
       
  1441     
       
  1442     iState->Init();  
       
  1443     UpdateListBoxL();
       
  1444 
       
  1445     if ( aError != KErrNone )
       
  1446         {
       
  1447         ShowErrorNoteL( aError );
       
  1448         }
       
  1449     }
       
  1450 
       
  1451 
       
  1452 //------------------------------------------------------------------------------
       
  1453 // CMediaFileDialog::QueryL
       
  1454 //
       
  1455 //------------------------------------------------------------------------------
       
  1456 //
       
  1457 void CMediaFileDialog::QueryL( TInt aFolderId, TBool aDatabaseChanged )
       
  1458     {
       
  1459     if ( !iMediaFileHandler->QueryReady() || !iDatabaseOpen )
       
  1460         {
       
  1461         FLOG( _L("### CMediaFileDialog::QueryL: query in progress ###") );
       
  1462         return;
       
  1463         }
       
  1464 
       
  1465     iMediaFileHandler->EnableObserverCall( ETrue );
       
  1466     
       
  1467     TInt folderId = aFolderId;
       
  1468     
       
  1469     iMediaFileHandler->SetQueryId( folderId );
       
  1470     
       
  1471     if ( folderId == EEFolderAllMusic )
       
  1472         {
       
  1473         iMediaFileHandler->QueryMusicL( 0 );
       
  1474         }
       
  1475         
       
  1476     else if ( folderId == EEFolderVideos )
       
  1477         {
       
  1478         iMediaFileHandler->QueryVideosL( 0 );
       
  1479         }
       
  1480 
       
  1481     else if ( folderId == EEFolderArtistRoot ||
       
  1482               folderId == EEFolderAlbumRoot  ||
       
  1483               folderId == EEFolderGenreRoot  || 
       
  1484               folderId == EEFolderComposerRoot )
       
  1485         {
       
  1486         if ( iState->UnknownCount( folderId ) == KErrNotFound )
       
  1487             {
       
  1488             TInt attr = MapAttribute( folderId );
       
  1489             iMediaFileHandler->QueryMusicUnknownCountL( attr );
       
  1490             }
       
  1491         else
       
  1492             {
       
  1493             TInt attr = MapAttribute( folderId );
       
  1494             iMediaFileHandler->QueryAttributeValuesL( attr );
       
  1495             }
       
  1496         }
       
  1497     
       
  1498     else if ( folderId == EEFolderAlbum || folderId == EEFolderGenre ||
       
  1499               folderId == EEFolderComposer )
       
  1500         {
       
  1501         TInt attr = MapAttribute( folderId );
       
  1502         iState->GetText( folderId, iBuf );
       
  1503         iMediaFileHandler->QueryMusicL( attr, iBuf );
       
  1504         }
       
  1505     
       
  1506     else if ( folderId == EEFolderArtistUnknown || folderId == EEFolderAlbumUnknown ||
       
  1507               folderId == EEFolderGenreUnknown ||folderId == EEFolderComposerUnknown )
       
  1508         {
       
  1509         TInt attr = MapAttribute( folderId );
       
  1510         iMediaFileHandler->QueryMusicUnknownL( attr );
       
  1511         }
       
  1512     
       
  1513     else if ( folderId == EEFolderArtist )
       
  1514         {
       
  1515         iState->GetText( EEFolderArtist, iBuf );
       
  1516         iMediaFileHandler->QueryArtistL( CMediaFileHandler::EQueryArtist,
       
  1517                            iBuf, KNullDesC, aDatabaseChanged );
       
  1518         }
       
  1519 
       
  1520     else if ( folderId == EEFolderArtistAll )
       
  1521         {
       
  1522         iState->GetText( EEFolderArtist, iBuf );
       
  1523         iMediaFileHandler->QueryArtistL( CMediaFileHandler::EQueryArtistAll,
       
  1524                                          iBuf, KNullDesC, aDatabaseChanged );
       
  1525         }
       
  1526 
       
  1527     else if ( folderId == EEFolderArtistAlbum )
       
  1528         {
       
  1529         TBuf<KBufSize128> buf;
       
  1530         iState->GetText( EEFolderArtistAlbum, buf );
       
  1531         iState->GetText( EEFolderArtist, iBuf );
       
  1532         iMediaFileHandler->QueryArtistL( CMediaFileHandler::EQueryArtistAlbum,
       
  1533                            iBuf, buf, aDatabaseChanged );
       
  1534         }
       
  1535 
       
  1536     else if ( folderId == EEFolderArtistAlbumUnknown )
       
  1537         {
       
  1538         iState->GetText( EEFolderArtist, iBuf );
       
  1539         iMediaFileHandler->QueryArtistL( CMediaFileHandler::EQueryArtistUnknown,
       
  1540                            iBuf, KNullDesC, aDatabaseChanged );
       
  1541         }
       
  1542 
       
  1543     else if ( folderId == EEFolderTones )
       
  1544         {
       
  1545         //iMediaFileHandler->QueryTonesL( 0 );
       
  1546         iMediaFileHandler->QueryDefaultTonesL( 0 );
       
  1547         ShowWaitNoteL( EFalse );
       
  1548         }
       
  1549     
       
  1550     else if ( folderId == EEFolderRecordings )
       
  1551         {
       
  1552         iMediaFileHandler->QueryRecordingsL( 0 );
       
  1553         }
       
  1554 
       
  1555     else if ( folderId == EEFolderSearch )
       
  1556         {
       
  1557         if ( iSearchText.Length() > 0 )
       
  1558             {
       
  1559             iMediaFileHandler->SearchL( iSearchText );    
       
  1560             }
       
  1561         else
       
  1562             {
       
  1563             iMediaFileHandler->QueryEmptyL();
       
  1564             }
       
  1565         }
       
  1566     else if ( folderId == EEFolderSearchMusic )
       
  1567         {
       
  1568         if ( iSearchText.Length() > 0 )
       
  1569             {
       
  1570             iMediaFileHandler->SearchAudioL( iSearchText );    
       
  1571             }
       
  1572         else
       
  1573             {
       
  1574             iMediaFileHandler->QueryEmptyL();
       
  1575             }
       
  1576         }
       
  1577     else
       
  1578         {
       
  1579         // make empty query
       
  1580         iMediaFileHandler->QueryEmptyL();
       
  1581         }
       
  1582     
       
  1583     if ( !iMediaFileHandler->QueryReady() )
       
  1584         {
       
  1585         // query is running - show wait note with delay. wait note is
       
  1586         // removed in HandleMFEventL
       
  1587         ShowWaitNoteL( aDatabaseChanged );
       
  1588         }
       
  1589     
       
  1590 #ifdef _DEBUG    
       
  1591     iTest->SetTime();
       
  1592 #endif    
       
  1593     }
       
  1594 
       
  1595 
       
  1596 // -----------------------------------------------------------------------------
       
  1597 // CMediaFileDialog::MapAttribute
       
  1598 // 
       
  1599 // -----------------------------------------------------------------------------
       
  1600 //
       
  1601 TInt CMediaFileDialog::MapAttribute( TInt aFolderId )
       
  1602     {
       
  1603     TInt attr = KErrNotFound;
       
  1604     
       
  1605     switch ( aFolderId )
       
  1606         {
       
  1607         case EEFolderArtistRoot:
       
  1608         case EEFolderArtist:
       
  1609         case EEFolderArtistUnknown:
       
  1610             {
       
  1611             attr = CMediaFileHandler::EAttrArtist;
       
  1612             break;
       
  1613             }
       
  1614         case EEFolderAlbumRoot:
       
  1615         case EEFolderAlbum:
       
  1616         case EEFolderAlbumUnknown:
       
  1617             {
       
  1618             attr = CMediaFileHandler::EAttrAlbum;
       
  1619             break;
       
  1620             }
       
  1621         case EEFolderGenreRoot:
       
  1622         case EEFolderGenre:
       
  1623         case EEFolderGenreUnknown:
       
  1624             {
       
  1625             attr = CMediaFileHandler::EAttrGenre;
       
  1626             break;
       
  1627             }
       
  1628         case EEFolderComposerRoot:
       
  1629         case EEFolderComposer:
       
  1630         case EEFolderComposerUnknown:
       
  1631             {
       
  1632             attr = CMediaFileHandler::EAttrComposer;
       
  1633             break;
       
  1634             }
       
  1635         default:
       
  1636             {
       
  1637             break;
       
  1638             }
       
  1639         }
       
  1640         
       
  1641     return attr;
       
  1642     }
       
  1643 
       
  1644 
       
  1645 // -----------------------------------------------------------------------------
       
  1646 // CMediaFileDialog::ShowDetailsPopupL
       
  1647 //
       
  1648 // -----------------------------------------------------------------------------
       
  1649 //
       
  1650 void CMediaFileDialog::ShowDetailsPopupL()
       
  1651     {
       
  1652     if ( !iMediaFileHandler->QueryReady() )
       
  1653         {
       
  1654         return;  // query in progress
       
  1655         }
       
  1656         
       
  1657     TInt currentIndex = CurrentItemListIndex();
       
  1658     TInt folderId = iState->CurrentFolder();
       
  1659     
       
  1660     if ( folderId != EEFolderSearch && folderId != EEFolderSearchMusic )
       
  1661         {
       
  1662         return;
       
  1663         }
       
  1664     if ( currentIndex < 0 )
       
  1665         {
       
  1666         return;
       
  1667         }
       
  1668     
       
  1669     TInt id = iMediaFileHandler->Attribute( currentIndex, 
       
  1670                                             CMediaFileHandler::EAttrMediaFileId,
       
  1671                                             iState->CurrentFolder() );
       
  1672     if ( id == KErrNotFound )
       
  1673         {
       
  1674         return;
       
  1675         }
       
  1676     
       
  1677     TInt mediaType = iMediaFileHandler->Attribute( currentIndex, 
       
  1678             CMediaFileHandler::EAttrMediaType,
       
  1679             iState->CurrentFolder() );
       
  1680     
       
  1681     TInt storageType = iMediaFileHandler->Attribute( currentIndex, 
       
  1682             CMediaFileHandler::EAttrStorageType,
       
  1683             iState->CurrentFolder() );
       
  1684     
       
  1685     CMediaFileData* data = NULL;
       
  1686 
       
  1687     if ( storageType == CMediaFileHandler::ERomStorage )
       
  1688         {
       
  1689         if ( mediaType == CMediaFileHandler::EMediaTypeTone )
       
  1690             {
       
  1691             data = iMediaFileHandler->RomMediaFileDataL( id , CMediaFileHandler::EMediaTypeTone );
       
  1692             }
       
  1693         if ( mediaType == CMediaFileHandler::EMediaTypeVideo )
       
  1694             {
       
  1695             data = iMediaFileHandler->RomMediaFileDataL( id , CMediaFileHandler::EMediaTypeVideo );
       
  1696             }
       
  1697         }
       
  1698     else
       
  1699     	{
       
  1700     	data = iMediaFileHandler->ReadMediaFileDataL( id );
       
  1701     	}
       
  1702 
       
  1703     CleanupStack::PushL( data );
       
  1704 
       
  1705     GetPopupText( data, iPopupText );
       
  1706     
       
  1707     CleanupStack::PopAndDestroy( data );
       
  1708     
       
  1709     if ( iPopupText.Length() > 0 )
       
  1710         {
       
  1711         ShowPopupNoteL( iPopupText );
       
  1712         }
       
  1713     }
       
  1714 
       
  1715 
       
  1716 // -----------------------------------------------------------------------------
       
  1717 // CMediaFileDialog::GetPopupText
       
  1718 //
       
  1719 // -----------------------------------------------------------------------------
       
  1720 //
       
  1721 void CMediaFileDialog::GetPopupText( CMediaFileData* aData, TDes& aText )
       
  1722     {
       
  1723     TBuf<KBufSize64> searchText;
       
  1724     TBuf<KBufSize64> attributeName;
       
  1725     
       
  1726     aText = KNullDesC;
       
  1727     
       
  1728     if ( FindBox()->TextLength() >= KBufSize64 )
       
  1729         {
       
  1730         return;
       
  1731         }
       
  1732     FindBox()->GetSearchText( searchText );
       
  1733    
       
  1734     aData->GetAttr( CMediaFileHandler::EAttrSongName, aText );
       
  1735     if ( MatchFound( aText, searchText ) )
       
  1736         {
       
  1737         aText = KNullDesC;
       
  1738         return;
       
  1739         }
       
  1740     
       
  1741     aData->GetAttr( CMediaFileHandler::EAttrArtist, aText );
       
  1742     if ( MatchFound( aText, searchText ) )
       
  1743         {
       
  1744         StringLoader::Load( attributeName, R_QTN_PREVIEW_POPUP_ARTIST );
       
  1745         aText.Insert( 0, attributeName );
       
  1746         return;
       
  1747         }
       
  1748 
       
  1749     aData->GetAttr( CMediaFileHandler::EAttrAlbum, aText );
       
  1750     if ( MatchFound( aText, searchText ) )
       
  1751         {
       
  1752         StringLoader::Load( attributeName, R_QTN_PREVIEW_POPUP_ALBUM );
       
  1753         aText.Insert( 0, attributeName );
       
  1754         return;
       
  1755         }
       
  1756 
       
  1757     aData->GetAttr( CMediaFileHandler::EAttrGenre, aText );
       
  1758     if ( MatchFound( aText, searchText ) )
       
  1759         {
       
  1760         StringLoader::Load( attributeName, R_QTN_PREVIEW_POPUP_GENRE );
       
  1761         aText.Insert( 0, attributeName );
       
  1762         return;
       
  1763         }
       
  1764 
       
  1765     aData->GetAttr( CMediaFileHandler::EAttrComposer, aText );
       
  1766     if ( MatchFound( aText, searchText ) )
       
  1767         {
       
  1768         StringLoader::Load( attributeName, R_QTN_PREVIEW_POPUP_COMPOSER );
       
  1769         aText.Insert( 0, attributeName );
       
  1770         return;
       
  1771         }
       
  1772     
       
  1773     aText = KNullDesC;
       
  1774     }
       
  1775 
       
  1776 
       
  1777 // -----------------------------------------------------------------------------
       
  1778 // CMediaFileDialog::MatchFound
       
  1779 //
       
  1780 // -----------------------------------------------------------------------------
       
  1781 //
       
  1782 TBool CMediaFileDialog::MatchFound( const TDesC& aAttribute, 
       
  1783                                     const TDesC& aText )
       
  1784     {
       
  1785     _LIT( KSpace, " " );
       
  1786     
       
  1787     if ( aText.Length() >= KBufSize64 )
       
  1788         {
       
  1789         return EFalse; // too long search text
       
  1790         }
       
  1791 
       
  1792     if ( aAttribute.FindC( aText ) == 0 )
       
  1793         {
       
  1794         // match found from the beginning of the first word
       
  1795         return ETrue; 
       
  1796         }
       
  1797 
       
  1798     TBuf<KBufSize64> buf;
       
  1799     buf = aText;
       
  1800     buf.Insert( 0, KSpace );
       
  1801     
       
  1802     if ( aAttribute.FindC( buf ) != KErrNotFound )
       
  1803         {
       
  1804         // match found from the beginning of the word
       
  1805         return ETrue; 
       
  1806         }
       
  1807     
       
  1808     return EFalse;
       
  1809     }
       
  1810 
       
  1811 
       
  1812 // -----------------------------------------------------------------------------
       
  1813 // CMediaFileDialog::PreviewL
       
  1814 //
       
  1815 // -----------------------------------------------------------------------------
       
  1816 //
       
  1817 void CMediaFileDialog::PreviewL( TInt aMediaType )
       
  1818     {
       
  1819     //FLOG( _L("CMediaFileDialog::PreviewL START") );
       
  1820     
       
  1821     if ( !iMediaFileHandler->QueryReady() )
       
  1822         {
       
  1823         FLOG( _L("### CMediaFileDialog::PreviewL: query in progress ###") );
       
  1824         return;  // query in progress
       
  1825         }
       
  1826 
       
  1827     if ( !iForeGround )
       
  1828         {
       
  1829         return;  // dialog is not visible
       
  1830         }
       
  1831         
       
  1832     TInt currentIndex = CurrentItemListIndex();
       
  1833     if ( currentIndex == KErrNotFound )
       
  1834         {
       
  1835         return;  // list is empty 
       
  1836         }
       
  1837     
       
  1838     TInt folderId = iState->FolderId( currentIndex );
       
  1839     if ( folderId == EEFolderNullItemOne || folderId == EEFolderNullItemTwo )
       
  1840         {
       
  1841         PreviewNullItemL( folderId );
       
  1842         return;
       
  1843         }
       
  1844     
       
  1845     if ( folderId != KErrNotFound )
       
  1846         {
       
  1847         return; // focused list item is folder
       
  1848         }
       
  1849      
       
  1850      
       
  1851     if ( iState->CurrentFolder() == EEFolderVideos  &&
       
  1852          aMediaType != CMediaFileList::EMediaFileTypeVideo )
       
  1853         {
       
  1854         return;
       
  1855         }
       
  1856     
       
  1857     GetSelectedItemFileName( currentIndex, iBuf );
       
  1858     if ( iBuf.Length() == 0 )
       
  1859         {
       
  1860         return;
       
  1861         }
       
  1862         
       
  1863     if ( aMediaType == CMediaFileList::EMediaFileTypeVideo )
       
  1864         {
       
  1865         PreviewVideoL( iBuf );
       
  1866         return;
       
  1867         }
       
  1868     
       
  1869     if ( iState->CurrentFolder() == EEFolderSearch )
       
  1870         {
       
  1871         if ( IsVideoFile( currentIndex ) )
       
  1872             {
       
  1873             return; // search folder may contain videos - no automatic preview                
       
  1874             }
       
  1875         }
       
  1876         
       
  1877     if ( !iProtectionHandler->IsFileValid( iBuf, CMFProtectionHandler::EPlay  ) )
       
  1878         {
       
  1879         return;
       
  1880         }
       
  1881         
       
  1882     iAudioPreviewHandler->SetAttrL( TMFDialogUtil::EAttrFileName, iBuf );
       
  1883     iAudioPreviewHandler->PlayL();
       
  1884     
       
  1885     //FLOG( _L("CMediaFileDialog::PreviewL END") );
       
  1886     }
       
  1887 
       
  1888 
       
  1889 // -----------------------------------------------------------------------------
       
  1890 // CMediaFileDialog::PreviewVideoL
       
  1891 //
       
  1892 // -----------------------------------------------------------------------------
       
  1893 //
       
  1894 void CMediaFileDialog::PreviewVideoL( const TDesC& aFileName )
       
  1895     {
       
  1896     if ( !iProtectionHandler->IsVideoValid( aFileName, CMFProtectionHandler::EPlay ) )
       
  1897          {
       
  1898          return;
       
  1899          }
       
  1900 
       
  1901     // in case "Beep once" one audio beep is played before showing video
       
  1902     TInt type = iAudioPreviewHandler->Attr( CMediaFileList::EAttrRingingType );
       
  1903     if ( type == CMFPreviewHandlerBase::ERingingTypeBeepOnce )
       
  1904         {
       
  1905         iAudioPreviewHandler->SetAttrL( TMFDialogUtil::EAttrFileName, aFileName );
       
  1906         iAudioPreviewHandler->PlayL();
       
  1907         }
       
  1908      
       
  1909     iVideoPreviewHandler->SetAttrL( TMFDialogUtil::EAttrFileName, aFileName );
       
  1910     TInt err = KErrNone;
       
  1911     if ( iVideoPreviewDlg && iVideoPreviewHandler->IsPlaying() )
       
  1912         {
       
  1913         iVideoPreviewDlg->CloseDialogL();
       
  1914         iVideoPreviewDlg = NULL;
       
  1915         }
       
  1916     iVideoPreviewDlg = CVideoPreviewDialog::NewL( iVideoPreviewHandler );
       
  1917     TBool ret = iVideoPreviewDlg->ShowDialogLD( &err );
       
  1918 
       
  1919     if ( err != KErrNone )
       
  1920         {
       
  1921         FLOG( _L("### CVideoPreviewDialog::ShowDialogLD (%d) ###"), err );
       
  1922         }
       
  1923      
       
  1924     ShowPreviewErrorNoteL( err, CMediaFileHandler::EMediaTypeVideo );
       
  1925     
       
  1926     if ( ret )
       
  1927         {
       
  1928         CloseDialogWithDelayL();
       
  1929         }
       
  1930     }
       
  1931 
       
  1932 
       
  1933 // -----------------------------------------------------------------------------
       
  1934 // CMediaFileDialog::PreviewLNullItemL
       
  1935 //
       
  1936 // -----------------------------------------------------------------------------
       
  1937 //
       
  1938 void CMediaFileDialog::PreviewNullItemL( TInt aFolderId )
       
  1939     {
       
  1940     HBufC* fileName = NULL;
       
  1941     TInt fileType = KErrNotFound;
       
  1942     
       
  1943     if ( aFolderId == EEFolderNullItemOne )
       
  1944         {
       
  1945         fileType = iNullItemFileTypeOne;
       
  1946         fileName = iNullItemFileNameOne; 
       
  1947         }
       
  1948     if ( aFolderId == EEFolderNullItemTwo )
       
  1949         {
       
  1950         fileType = iNullItemFileTypeTwo;
       
  1951         fileName = iNullItemFileNameTwo; 
       
  1952         }
       
  1953 
       
  1954     if ( fileType != CMediaFileList::EMediaFileTypeAudio && 
       
  1955          fileType != CMediaFileList::EMediaFileTypeVideo )
       
  1956         {
       
  1957         return;
       
  1958         }
       
  1959     if ( !fileName )
       
  1960         {
       
  1961         return;
       
  1962         }
       
  1963         
       
  1964     if ( fileType == CMediaFileList::EMediaFileTypeAudio )
       
  1965         {
       
  1966         iAudioPreviewHandler->SetAttrL( TMFDialogUtil::EAttrFileName, *fileName );
       
  1967         iAudioPreviewHandler->PlayL();
       
  1968         }
       
  1969     if ( fileType == CMediaFileList::EMediaFileTypeVideo )
       
  1970         {
       
  1971         // null item file type cannot be video
       
  1972         }
       
  1973     }
       
  1974 
       
  1975 
       
  1976 //------------------------------------------------------------------------------
       
  1977 // CMediaFileDialog::CancelPreview
       
  1978 //
       
  1979 //------------------------------------------------------------------------------
       
  1980 //
       
  1981 void CMediaFileDialog::CancelPreview()
       
  1982     {
       
  1983     iAudioPreviewHandler->Stop();
       
  1984     iCaller->Cancel();
       
  1985     }
       
  1986 
       
  1987 
       
  1988 // -----------------------------------------------------------------------------
       
  1989 // CMediaFileDialog::StartPreviewWithDelay
       
  1990 // 
       
  1991 // -----------------------------------------------------------------------------
       
  1992 //
       
  1993 void CMediaFileDialog::StartPreviewWithDelay()
       
  1994     {
       
  1995 	const TInt KOneSecond = 1000;
       
  1996 	
       
  1997 	iAudioPreviewHandler->Stop();
       
  1998 
       
  1999     // automatic preview starts after delay. see HandleActiveCallL.
       
  2000     iCaller->Start( EAttrPreview, KOneSecond );
       
  2001     }
       
  2002 
       
  2003 
       
  2004 // -----------------------------------------------------------------------------
       
  2005 // CMediaFileDialog::StartSearchWithDelay
       
  2006 // 
       
  2007 // -----------------------------------------------------------------------------
       
  2008 //
       
  2009 void CMediaFileDialog::StartSearchWithDelay()
       
  2010     {
       
  2011     if ( iPeninputActive )
       
  2012         {
       
  2013         // search does not start automatically in pen input mode
       
  2014         return;
       
  2015         }
       
  2016     
       
  2017     const TInt KOneSecond = 1000;
       
  2018     
       
  2019     // search starts after delay. see HandleActiveCallL.
       
  2020     iSearchCaller->Start( EAttrSearch, KOneSecond );
       
  2021     }
       
  2022 
       
  2023 
       
  2024 // -----------------------------------------------------------------------------
       
  2025 // CMediaFileDialog::StartRomScan()
       
  2026 // 
       
  2027 // -----------------------------------------------------------------------------
       
  2028 //
       
  2029 void CMediaFileDialog::StartRomScan()
       
  2030     {
       
  2031     delete iIdle;
       
  2032     iIdle = NULL;
       
  2033     iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
  2034     
       
  2035     if ( iIdle )
       
  2036         {                    
       
  2037         iIdle->Start( TCallBack( StartRomScaning, iMediaFileHandler ) );
       
  2038         }
       
  2039     }
       
  2040 
       
  2041 // -----------------------------------------------------------------------------
       
  2042 // CMediaFileDialog::StartRomScaning()
       
  2043 // 
       
  2044 // -----------------------------------------------------------------------------
       
  2045 //
       
  2046 
       
  2047 TInt CMediaFileDialog::StartRomScaning( TAny* aInstance )
       
  2048     {
       
  2049     CMediaFileHandler* handler = static_cast<CMediaFileHandler*> ( aInstance );
       
  2050     handler->StartRomScaning( CMediaFileHandler::EQueryTone );
       
  2051     return 0;
       
  2052     }
       
  2053 
       
  2054 // -----------------------------------------------------------------------------
       
  2055 // CMediaFileDialog::IsVideoFile
       
  2056 // 
       
  2057 // -----------------------------------------------------------------------------
       
  2058 //
       
  2059 TBool CMediaFileDialog::IsVideoFile( TInt aCurrentIndex )
       
  2060     {
       
  2061     if ( aCurrentIndex < 0 )
       
  2062         {
       
  2063         return EFalse;
       
  2064         }
       
  2065     
       
  2066     TInt current = iState->CurrentFolder();
       
  2067     
       
  2068     if ( current == EEFolderVideos )
       
  2069         {
       
  2070         return ETrue;
       
  2071         }
       
  2072     
       
  2073     if ( current != EEFolderSearch )
       
  2074         {
       
  2075         return EFalse;
       
  2076         }
       
  2077     
       
  2078     TInt mediaType = iMediaFileHandler->Attribute( aCurrentIndex,
       
  2079                                         CMediaFileHandler::EAttrMediaType,
       
  2080                                         current );
       
  2081 
       
  2082     if ( mediaType == CMediaFileHandler::EMediaTypeVideo )
       
  2083         {
       
  2084         return ETrue;
       
  2085         }
       
  2086     
       
  2087     return EFalse;           
       
  2088     }
       
  2089     
       
  2090 
       
  2091 // -----------------------------------------------------------------------------
       
  2092 // CMediaFileDialog::IsValidVideoFileL
       
  2093 // 
       
  2094 // -----------------------------------------------------------------------------
       
  2095 //
       
  2096 TBool CMediaFileDialog::IsValidVideoFileL( TInt aCurrentIndex, TInt aIntention )
       
  2097     {
       
  2098     TBuf<KBufSize128> buf;
       
  2099     
       
  2100     if ( !IsVideoFile( aCurrentIndex ) )
       
  2101         {
       
  2102         return EFalse;
       
  2103         }
       
  2104     
       
  2105     CMFProtectionHandler::TIntention intention;
       
  2106     if ( aIntention == CMFProtectionHandler::EPlay )
       
  2107         {
       
  2108         intention = CMFProtectionHandler::EPlay;
       
  2109         }
       
  2110     else
       
  2111         {
       
  2112         intention = CMFProtectionHandler::ESelect;
       
  2113         }
       
  2114     GetSelectedItemFileName( aCurrentIndex, buf );
       
  2115     
       
  2116     if ( iProtectionHandler->IsVideoValid( buf, intention ) )
       
  2117         {
       
  2118         return ETrue;    
       
  2119         }
       
  2120     return EFalse;
       
  2121     }
       
  2122 
       
  2123 
       
  2124 
       
  2125 // ----------------------------------------------------------------------------
       
  2126 // CMediaFileDialog::UpdateListBoxL
       
  2127 // 
       
  2128 // Update listbox contents (currently open folder items).
       
  2129 // ----------------------------------------------------------------------------
       
  2130 //
       
  2131 void CMediaFileDialog::UpdateListBoxL( TBool aRestFindBox )
       
  2132     {
       
  2133     // prevent flickering during listbox update. ResetFindBoxL seems
       
  2134     // to draw listbox many times
       
  2135     iListBox->MakeVisible( EFalse );
       
  2136 
       
  2137     TRAP_IGNORE( DoUpdateListBoxL( aRestFindBox ) );
       
  2138     
       
  2139     iListBox->MakeVisible( ETrue );
       
  2140     }
       
  2141 
       
  2142 
       
  2143 // ----------------------------------------------------------------------------
       
  2144 // CMediaFileDialog::DoUpdateListBoxL
       
  2145 // 
       
  2146 // Update listbox contents (currently open folder items).
       
  2147 // ----------------------------------------------------------------------------
       
  2148 //
       
  2149 void CMediaFileDialog::DoUpdateListBoxL( TBool aRestFindBox )
       
  2150     {
       
  2151     iState->SetUnknownFolderPosition( iMediaFileHandler->ResultCount() );
       
  2152     
       
  2153     // check current item index in case media file database has changed
       
  2154     CheckListboxIndex();
       
  2155     if ( aRestFindBox )
       
  2156     	{
       
  2157     	ResetFindBoxL();
       
  2158     	iListBox->HandleItemAdditionL();
       
  2159     	}
       
  2160     
       
  2161     TInt index = iState->CurrentItemIndex();
       
  2162     if ( index >= 0 && index < iListBox->Model()->NumberOfItems() )
       
  2163         {
       
  2164         iListBox->SetCurrentItemIndex( index );
       
  2165         }
       
  2166     else
       
  2167         {
       
  2168         iListBox->SetCurrentItemIndex( 0 );    
       
  2169         }
       
  2170     
       
  2171     TBuf<KBufSize128> buf;
       
  2172     if ( iState->CurrentFolder() == EEFolderSearch || 
       
  2173          iState->CurrentFolder() == EEFolderSearchMusic )
       
  2174         {
       
  2175         TInt count = iListBox->Model()->NumberOfItems();
       
  2176         iState->GetSearchTitle( buf, count );
       
  2177         }
       
  2178     else
       
  2179         {
       
  2180         iState->GetTitle( iState->CurrentFolder(), buf );
       
  2181 //#ifdef _DEBUG
       
  2182         TInt folder = iState->CurrentFolder();
       
  2183         if ( iState->FindBoxNeeded() && folder != EEFolderMusic && 
       
  2184              folder != EEFolderRoot )
       
  2185             {
       
  2186             TBuf<KBufSize128> buf2( buf );
       
  2187             TInt count = iListBox->Model()->NumberOfItems();
       
  2188             buf.Format( _L("%S  (%d)"), &buf2, count );
       
  2189             }
       
  2190 //#endif
       
  2191         }
       
  2192     
       
  2193     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( buf );
       
  2194     iStatusPaneHandler->SetNaviPaneTitle( buf );
       
  2195    
       
  2196     UpdateCbaL( 0 );
       
  2197     
       
  2198     DrawNow();
       
  2199     
       
  2200     if ( iState->QueryDirection() != EEQueryUpdate )
       
  2201         {
       
  2202         CancelPreview();
       
  2203         }
       
  2204     
       
  2205     ShowDetailsPopupL();       // for search view info popup
       
  2206     }
       
  2207 
       
  2208 
       
  2209 // -----------------------------------------------------------------------------
       
  2210 // CMediaFileDialog::UpdateCbaL
       
  2211 // 
       
  2212 // Update cba. NOTE: Commented code (menu cba) is for (possible) future use.
       
  2213 // -----------------------------------------------------------------------------
       
  2214 //
       
  2215 void CMediaFileDialog::UpdateCbaL( TInt /*aAttr*/ )
       
  2216     {
       
  2217     TInt itemCount = iListBox->Model()->NumberOfItems();
       
  2218     TInt currentIndex = CurrentItemListIndex();
       
  2219     TInt folderId = iState->FolderId( currentIndex );
       
  2220     TInt currentFolderId = iState->CurrentFolder();
       
  2221   	  	
       
  2222 	
       
  2223 	CEikButtonGroupContainer& cba = ButtonGroupContainer(); // from eikbtgpc.h
       
  2224 	
       
  2225 
       
  2226 	// Videos folder
       
  2227     if ( currentFolderId == EEFolderVideos )
       
  2228         {
       
  2229         if ( itemCount == 0 )
       
  2230             {
       
  2231             cba.SetCommandSetL( R_AVKON_SOFTKEYS_BACK );
       
  2232             //cba.SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  2233             }
       
  2234         else
       
  2235             {
       
  2236             if ( IsValidVideoFileL( currentIndex, CMFProtectionHandler::EPlay ) )
       
  2237                 {
       
  2238                 cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_PREVIEW_SELECT_BACK );    
       
  2239                 }
       
  2240             else
       
  2241                 {
       
  2242                 cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_SELECT_SELECT_BACK );
       
  2243                 }
       
  2244             
       
  2245             //cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPTIONS_CONTEXT_BACK );
       
  2246             }
       
  2247         return;
       
  2248         }
       
  2249 
       
  2250     
       
  2251     // Search folder
       
  2252     if ( currentFolderId == EEFolderSearch || 
       
  2253          currentFolderId == EEFolderSearchMusic )
       
  2254         {
       
  2255         if ( itemCount == 0 )
       
  2256             {
       
  2257             cba.SetCommandSetL( R_AVKON_SOFTKEYS_BACK );
       
  2258             // cba.SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  2259             }
       
  2260         else
       
  2261             {
       
  2262             if ( IsValidVideoFileL( currentIndex, CMFProtectionHandler::EPlay ) )
       
  2263                 {
       
  2264                 cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_PREVIEW_SELECT_BACK );
       
  2265                 }
       
  2266             else
       
  2267                 {
       
  2268                 cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_SELECT_SELECT_BACK );
       
  2269                 }
       
  2270                 //cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPTIONS_SELECT_BACK );
       
  2271             }
       
  2272         return;
       
  2273         }
       
  2274     
       
  2275     
       
  2276 	// Root folder
       
  2277 	if ( currentFolderId == EEFolderRoot )
       
  2278 	    {
       
  2279 	    if ( folderId == EEFolderDownload || folderId == EEFolderNullItemOne ||
       
  2280 	         folderId == EEFolderNullItemTwo )
       
  2281 	        {
       
  2282 	        //cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPTIONS_SELECT_BACK );
       
  2283 	        cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_SELECT_SELECT_BACK );
       
  2284 	        }
       
  2285 	    else
       
  2286 	        {
       
  2287 	        //cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPTIONS_OPEN_BACK );
       
  2288 	        cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPEN_OPEN_BACK );
       
  2289 	        }
       
  2290 	    return;
       
  2291 	    }
       
  2292 	
       
  2293 	
       
  2294 	// other folders
       
  2295     if ( itemCount == 0 )
       
  2296 	    {
       
  2297 	    // folder is empty
       
  2298 	    cba.SetCommandSetL( R_AVKON_SOFTKEYS_BACK );
       
  2299         //cba.SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  2300         }
       
  2301 	else if ( folderId != KErrNotFound )
       
  2302 	    {
       
  2303 	    // list items are folders
       
  2304         cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPEN_OPEN_BACK );
       
  2305         //cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPTIONS_OPEN_BACK );
       
  2306 	    }
       
  2307 	else
       
  2308 	    {
       
  2309 	    // list items are files
       
  2310         cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_SELECT_SELECT_BACK );
       
  2311         //cba.SetCommandSetL( R_MEDIA_FILE_DIALOG_CBA_OPTIONS_SELECT_BACK );
       
  2312 	    }
       
  2313     }
       
  2314     
       
  2315     
       
  2316 // -----------------------------------------------------------------------------
       
  2317 // CMediaFileDialog::Panic
       
  2318 //
       
  2319 // -----------------------------------------------------------------------------
       
  2320 //
       
  2321 void CMediaFileDialog::Panic( TInt aReason ) 
       
  2322     {
       
  2323 	_LIT( KPanicCategory, "CMediaFileDialog" );
       
  2324 	
       
  2325 	User::Panic( KPanicCategory, aReason ); 
       
  2326     }
       
  2327     
       
  2328 
       
  2329 // -----------------------------------------------------------------------------
       
  2330 // CMediaFileDialog::ShowErrorNoteL
       
  2331 //
       
  2332 // -----------------------------------------------------------------------------
       
  2333 //
       
  2334 void CMediaFileDialog::ShowErrorNoteL( TInt aError )
       
  2335 	{
       
  2336     TInt err = aError;
       
  2337     
       
  2338     if ( err == KErrNone )
       
  2339         {
       
  2340         return;
       
  2341         }
       
  2342 
       
  2343     iBuf = KNullDesC;
       
  2344     CTextResolver* tr = CTextResolver::NewLC();
       
  2345 	iBuf = tr->ResolveErrorString( err, CTextResolver::ECtxNoCtxNoSeparator );
       
  2346   	CleanupStack::PopAndDestroy( tr );
       
  2347 	
       
  2348 	if ( iBuf.Length() > 0 )
       
  2349 	    {
       
  2350   	    TMFDialogUtil::ShowErrorNoteL( iBuf );
       
  2351 	    }
       
  2352 	}
       
  2353 
       
  2354 
       
  2355 // -----------------------------------------------------------------------------
       
  2356 // CMediaFileDialog::ShowPreviewErrorNoteL
       
  2357 //
       
  2358 // -----------------------------------------------------------------------------
       
  2359 //
       
  2360 void CMediaFileDialog::ShowPreviewErrorNoteL( TInt aError, TInt aMediaType )
       
  2361     {
       
  2362     TInt err = KErrNone;
       
  2363     
       
  2364     if ( aError == KErrNoMemory || aError == KErrDiskFull )
       
  2365         {
       
  2366         CTextResolver* tr = CTextResolver::NewLC();
       
  2367         iBuf = tr->ResolveErrorString( aError, CTextResolver::ECtxNoCtxNoSeparator );
       
  2368         CleanupStack::PopAndDestroy( tr );
       
  2369         err = aError;
       
  2370         }
       
  2371     else if ( aError == KErrNotSupported || aError == KErrCorrupt ||aError == KErrMMPartialPlayback)
       
  2372         {
       
  2373         if ( aMediaType == CMediaFileHandler::EMediaTypeVideo )
       
  2374             {
       
  2375             StringLoader::Load( iBuf, R_QTN_INFO_CLIP_FORMAT_ERROR );
       
  2376             }
       
  2377         else
       
  2378             {
       
  2379             StringLoader::Load( iBuf, R_QTN_INFO_FILE_FORMAT_ERROR );
       
  2380             }
       
  2381         err = aError;
       
  2382         }
       
  2383     
       
  2384     if ( err == KErrNone )
       
  2385         {
       
  2386         return;
       
  2387         }
       
  2388     
       
  2389 #ifdef _DEBUG
       
  2390     TMFDialogUtil::ShowErrorNoteL( iBuf, aError );
       
  2391 #else
       
  2392     TMFDialogUtil::ShowErrorNoteL( iBuf );
       
  2393 #endif
       
  2394     
       
  2395     }
       
  2396 
       
  2397 
       
  2398 //------------------------------------------------------------------------------
       
  2399 // CMediaFileDialog::ShowWaitNoteL
       
  2400 //
       
  2401 //------------------------------------------------------------------------------
       
  2402 //
       
  2403 void CMediaFileDialog::ShowWaitNoteL( TBool aDatabaseChanged )
       
  2404     {
       
  2405     TBuf<KBufSize128> buf;
       
  2406     
       
  2407     if ( aDatabaseChanged )
       
  2408         {
       
  2409         StringLoader::Load( buf, R_QTN_WAIT_NOTE_UPDATE );
       
  2410         //buf = _L("Refreshing");
       
  2411         }
       
  2412     else if ( iState->QueryFolder() == EEFolderSearch ||
       
  2413               iState->QueryFolder() == EEFolderSearchMusic )
       
  2414         {
       
  2415         StringLoader::Load( buf, R_QTN_WAIT_NOTE_SEARCH );
       
  2416         }
       
  2417     else
       
  2418         {
       
  2419         StringLoader::Load( buf, R_QTN_WAIT_NOTE_OPEN );
       
  2420         }
       
  2421     
       
  2422     iWaitNote->LaunchL( buf );     
       
  2423     }
       
  2424 
       
  2425 
       
  2426 // -----------------------------------------------------------------------------
       
  2427 // CMediaFileDialog::DeleteMenuItem
       
  2428 //
       
  2429 // -----------------------------------------------------------------------------
       
  2430 //
       
  2431 void CMediaFileDialog::DeleteMenuItem( CEikMenuPane* aMenuPane, TInt aCommandId )
       
  2432 	{
       
  2433 	TInt pos = KErrNotFound;
       
  2434     if ( aMenuPane->MenuItemExists( aCommandId, pos ) )
       
  2435 		{
       
  2436 		aMenuPane->DeleteMenuItem( aCommandId );
       
  2437 		}
       
  2438 	}
       
  2439 
       
  2440 
       
  2441 // -----------------------------------------------------------------------------
       
  2442 // CMediaFileDialog::ShowPopupNote
       
  2443 //
       
  2444 // -----------------------------------------------------------------------------
       
  2445 //
       
  2446 void CMediaFileDialog::ShowPopupNoteL( const TDesC& aText ) 
       
  2447     {
       
  2448     const TInt KPopupDisplayTime = 3*1000;
       
  2449     const TInt KPopupDelayTime = 500;
       
  2450     
       
  2451     iPopupNote->SetTextL( aText );
       
  2452     iPopupNote->SetTimeDelayBeforeShow( KPopupDelayTime );
       
  2453     iPopupNote->SetTimePopupInView( KPopupDisplayTime );    
       
  2454     iPopupNote->ShowInfoPopupNote();    
       
  2455     }
       
  2456 
       
  2457 
       
  2458 // -----------------------------------------------------------------------------
       
  2459 // CMediaFileDialog::CurrentItemListIndex
       
  2460 // 
       
  2461 // -----------------------------------------------------------------------------
       
  2462 //
       
  2463 TInt CMediaFileDialog::CurrentItemListIndex()
       
  2464     {
       
  2465     TInt itemCount = iListBox->Model()->NumberOfItems();
       
  2466     TInt currentIndex = iListBox->CurrentItemIndex();
       
  2467      
       
  2468     if ( itemCount == 0 || currentIndex < 0 )
       
  2469         {
       
  2470         return KErrNotFound; // list or find box is empty
       
  2471         }
       
  2472      
       
  2473     // convert from findbox index into original list index
       
  2474     if ( FindBox() && FindBox()->IsVisible() )
       
  2475         {
       
  2476         TInt tempIndex = currentIndex;
       
  2477         CAknFilteredTextListBoxModel* model =
       
  2478         STATIC_CAST(CAknFilteredTextListBoxModel*, iListBox->Model());
       
  2479         
       
  2480         if ( model->Filter() )
       
  2481             {
       
  2482             currentIndex = model->Filter()->FilteredItemIndex( tempIndex );
       
  2483             }
       
  2484         }
       
  2485      
       
  2486     return currentIndex;
       
  2487     }
       
  2488 
       
  2489 
       
  2490 //------------------------------------------------------------------------------
       
  2491 // CMediaFileDialog::GetSelectedItemFileName
       
  2492 //
       
  2493 //------------------------------------------------------------------------------
       
  2494 //
       
  2495 void CMediaFileDialog::GetSelectedItemFileName( TInt aListboxIndex, TDes& aFileName )
       
  2496     {
       
  2497     aFileName = KNullDesC;
       
  2498     
       
  2499     __ASSERT_DEBUG( iState->QueryNeeded(), Panic( KErrGeneral ) );
       
  2500             
       
  2501     TInt id = iState->CurrentFolder();
       
  2502         
       
  2503     // read selected list item text from metadata    
       
  2504     TInt extraIndexes = iState->LeadingPersistentFolderCount();
       
  2505     TInt queryIndex = aListboxIndex - extraIndexes;
       
  2506 
       
  2507     iMediaFileHandler->GetAttribute( queryIndex, CMediaFileHandler::EAttrFullName, 
       
  2508                                      aFileName, id );
       
  2509     }
       
  2510 
       
  2511 
       
  2512 // -----------------------------------------------------------------------------
       
  2513 // CMediaFileDialog::ConstructListboxItem
       
  2514 // 
       
  2515 // -----------------------------------------------------------------------------
       
  2516 //
       
  2517 TPtrC CMediaFileDialog::ConstructListboxItem( TInt aListboxIndex )
       
  2518     {
       
  2519     _LIT( KFormat2, "%d\t%S\t%d" );
       
  2520   
       
  2521     TBool isPersistent = EFalse;
       
  2522     TInt mediaTypeIcon = EEIconEmpty;
       
  2523     TInt storageTypeIcon = EEIconEmpty;
       
  2524     TInt folderId = KErrNotFound;
       
  2525     iState->GetFolderInfo( aListboxIndex, folderId, iListboxItemText1,
       
  2526                                           isPersistent, mediaTypeIcon );
       
  2527     if ( folderId != KErrNotFound )
       
  2528         {
       
  2529         if ( !isPersistent )
       
  2530             {
       
  2531             GetListItemText( aListboxIndex, iListboxItemText1 );
       
  2532             }
       
  2533         }
       
  2534     else
       
  2535         {
       
  2536         GetListItemText( aListboxIndex, iListboxItemText1 );
       
  2537         mediaTypeIcon = MediaTypeIcon( aListboxIndex );
       
  2538         storageTypeIcon = StorageTypeIcon( aListboxIndex );
       
  2539         }
       
  2540 
       
  2541     iListboxItemText2.Format( KFormat2, mediaTypeIcon, &iListboxItemText1, storageTypeIcon );
       
  2542     return iListboxItemText2;
       
  2543     }
       
  2544 
       
  2545 
       
  2546 // -----------------------------------------------------------------------------
       
  2547 // CMediaFileDialog::MediaTypeIcon
       
  2548 // 
       
  2549 // -----------------------------------------------------------------------------
       
  2550 //
       
  2551 TInt CMediaFileDialog::MediaTypeIcon( TInt aListboxIndex )
       
  2552     {
       
  2553     if ( aListboxIndex < 0 )
       
  2554         {
       
  2555         return EEIconEmpty;
       
  2556         }
       
  2557 
       
  2558     TInt mediaType = iMediaFileHandler->Attribute( aListboxIndex,
       
  2559                                         CMediaFileHandler::EAttrMediaType,
       
  2560                                         iState->CurrentFolder() );
       
  2561     
       
  2562     TInt iconId = EEIconMusic;
       
  2563     if ( mediaType == CMediaFileHandler::EMediaTypeTone )
       
  2564         {
       
  2565         iconId = EEIconTone;
       
  2566         }
       
  2567     else if ( mediaType == CMediaFileHandler::EMediaTypeVideo )
       
  2568         {
       
  2569         iconId = EEIconVideo;
       
  2570         }
       
  2571     else if ( mediaType == CMediaFileHandler::EMediaTypeRecording )
       
  2572         {
       
  2573         iconId = EEIconRecording;
       
  2574         }
       
  2575     
       
  2576     return iconId;
       
  2577     }
       
  2578 
       
  2579 
       
  2580 // -----------------------------------------------------------------------------
       
  2581 // CMediaFileDialog::StorageTypeIcon
       
  2582 // 
       
  2583 // -----------------------------------------------------------------------------
       
  2584 //
       
  2585 TInt CMediaFileDialog::StorageTypeIcon( TInt aListboxIndex )
       
  2586     {
       
  2587     if ( aListboxIndex < 0 )
       
  2588         {
       
  2589         return EEIconEmpty;
       
  2590         }
       
  2591 
       
  2592     TInt storageType = iMediaFileHandler->Attribute( aListboxIndex,
       
  2593                                         CMediaFileHandler::EAttrStorageType,
       
  2594                                         iState->CurrentFolder() );
       
  2595     TInt iconId = EEIconEmpty;
       
  2596     if ( storageType == CMediaFileHandler::EMassStorage )
       
  2597         {
       
  2598         iconId = EEIconMassStorage;
       
  2599         }
       
  2600     
       
  2601     if ( storageType == CMediaFileHandler::EMemoryCard )
       
  2602         {
       
  2603         iconId = EEIconMemoryCard;
       
  2604         }
       
  2605 
       
  2606     return iconId;
       
  2607     }
       
  2608 
       
  2609 
       
  2610 // -----------------------------------------------------------------------------
       
  2611 // CMediaFileDialog::GetListItemText
       
  2612 // 
       
  2613 // -----------------------------------------------------------------------------
       
  2614 //
       
  2615 void CMediaFileDialog::GetListItemText( TInt aListboxIndex, TDes& aText )
       
  2616     {
       
  2617     __ASSERT_DEBUG( iState->QueryNeeded(), Panic( KErrGeneral ) );
       
  2618 
       
  2619     TInt id = iState->CurrentFolder();
       
  2620     
       
  2621     // read selected list item text from metadata    
       
  2622     TInt extraIndexes = iState->LeadingPersistentFolderCount();
       
  2623     TInt queryIndex = aListboxIndex - extraIndexes;
       
  2624     
       
  2625     iMediaFileHandler->GetAttribute( queryIndex, 
       
  2626                        CMediaFileHandler::EAttrSongName, aText, id );
       
  2627     }
       
  2628 
       
  2629 
       
  2630 
       
  2631 // -----------------------------------------------------------------------------
       
  2632 // CMediaFileDialog::ListboxItemCount (from CMFListHandlerObserver)
       
  2633 // 
       
  2634 // -----------------------------------------------------------------------------
       
  2635 //
       
  2636 TInt CMediaFileDialog::ListboxItemCount()
       
  2637     {
       
  2638     TInt count1 = iState->PersistentFolderCount();
       
  2639     TInt count2 = 0;
       
  2640     
       
  2641     if ( iState->QueryNeeded() )
       
  2642         {
       
  2643         count2 = iMediaFileHandler->ResultCount();
       
  2644         }
       
  2645     return count1 + count2;
       
  2646     }
       
  2647 
       
  2648 
       
  2649 // -----------------------------------------------------------------------------
       
  2650 // CMediaFileDialog::HandleMFEventL (from MMediaFileHandlerObserver)
       
  2651 // 
       
  2652 // -----------------------------------------------------------------------------
       
  2653 //
       
  2654 void CMediaFileDialog::HandleMFEventL( TInt aEvent, TInt aError )
       
  2655     {
       
  2656     //
       
  2657     // handle cancel button
       
  2658     //
       
  2659     if ( aEvent == MMediaFileHandlerObserver::EQueryCanceled )
       
  2660         {
       
  2661         iWaitNote->CancelProgressDialogL();
       
  2662         iSearchText = KNullDesC;
       
  2663         UpdateListBoxL();
       
  2664         return;
       
  2665         }
       
  2666     
       
  2667     //
       
  2668     // handle error
       
  2669     //
       
  2670     if ( aError != KErrNone )
       
  2671         {
       
  2672         iWaitNote->CancelProgressDialogL();
       
  2673         ResetDialogL( aError );
       
  2674 
       
  2675         FLOG( _L("### CMediaFileDialog::HandleMFEventL (%d) ###"), aError );
       
  2676         return;
       
  2677         }
       
  2678 
       
  2679     
       
  2680     if ( aEvent != MMediaFileHandlerObserver::EUnknownQueryComplete )
       
  2681         {
       
  2682         // unknown query is always followed by another query
       
  2683         iWaitNote->CancelProgressDialogL();    
       
  2684         }
       
  2685     
       
  2686     
       
  2687     if ( aEvent == MMediaFileHandlerObserver::EUnknownQueryComplete )
       
  2688         {
       
  2689         TInt count = iMediaFileHandler->ResultCount();
       
  2690         TInt folderId = iState->QueryFolder();
       
  2691         iState->SetUnknownCount( folderId, count );
       
  2692         
       
  2693         TInt err = KErrNone;
       
  2694         TRAP( err, QueryL( folderId ) );
       
  2695         if ( err != KErrNone )
       
  2696             {
       
  2697             iWaitNote->CancelProgressDialogL();
       
  2698             User::Leave( err );
       
  2699             }
       
  2700         }
       
  2701 
       
  2702     if ( aEvent == MMediaFileHandlerObserver::EQueryComplete )
       
  2703         {
       
  2704         // query was successful - update dialog state
       
  2705         iState->SetStateAfterQuery();
       
  2706        
       
  2707         TInt count = iMediaFileHandler->ResultCount();
       
  2708         
       
  2709         if ( iState->CurrentFolder() == EEFolderArtist )
       
  2710             {
       
  2711             TInt count = iMediaFileHandler->UnknownArtistCount();
       
  2712             iState->SetUnknownCount( EEFolderArtist, count );
       
  2713             }
       
  2714         iState->HideUnknownFolders();
       
  2715         UpdateListBoxL();
       
  2716         
       
  2717 #ifdef _DEBUG
       
  2718         iTest->PrintTimeL( _L("query took") );  // test code
       
  2719 #endif        
       
  2720         }
       
  2721 
       
  2722     if ( aEvent == MMediaFileHandlerObserver::EMediaFileChanged )
       
  2723         {
       
  2724         HandleMediaFileChanged();
       
  2725         }
       
  2726     
       
  2727     if (  aEvent == MMediaFileHandlerObserver::EScanRomComplete )
       
  2728         {
       
  2729         iWaitNote->CancelProgressDialogL(); 
       
  2730         }
       
  2731     
       
  2732     if ( aEvent == MMediaFileHandlerObserver::EInitComplete )
       
  2733         {
       
  2734         iDatabaseOpen = ETrue;
       
  2735     	
       
  2736     	StartRomScan();
       
  2737         }
       
  2738     }
       
  2739 
       
  2740 
       
  2741 // -----------------------------------------------------------------------------
       
  2742 // CMediaFileDialog::HandleMediaFileChanged
       
  2743 // 
       
  2744 // Handle situation where file system changes and media files are added /
       
  2745 // removed. This function makes a query to update current folder and
       
  2746 // stores name or id of the currently selected item. Current item info
       
  2747 // is needed to restore current item after query. 
       
  2748 // -----------------------------------------------------------------------------
       
  2749 //
       
  2750 void CMediaFileDialog::HandleMediaFileChanged()
       
  2751     {
       
  2752     // query is ongoing - ignore this file change event
       
  2753     if ( !iMediaFileHandler->QueryReady() )
       
  2754          {
       
  2755          FLOG( _L("### CMediaFileDialog::HandleMediaFileChanged: query in progress ###") );
       
  2756          return;
       
  2757          }
       
  2758     
       
  2759     iState->ResetUnknownCount();
       
  2760     TMFCurrentItemInfo& info = iState->CurrentItemInfo();
       
  2761     info.Reset();
       
  2762     info.iIndexCheckNeeded = ETrue; //  set to false when dialog is opened
       
  2763         
       
  2764     TInt currentFolder = iState->CurrentFolder();
       
  2765     TInt currentIndex = CurrentItemListIndex();
       
  2766          
       
  2767     TBool isPersistent = EFalse;
       
  2768     TInt iconId = EEIconEmpty;
       
  2769     TInt id = KErrNotFound;
       
  2770     TBuf<KBufSize64> buf;
       
  2771     iState->GetFolderInfo( currentIndex, id, buf,
       
  2772                                          isPersistent, iconId );
       
  2773     if ( id == KErrNotFound )
       
  2774         {
       
  2775         // get media file id
       
  2776         info.iMediaFileId = iMediaFileHandler->Attribute( currentIndex, 
       
  2777                  CMediaFileHandler::EAttrMediaFileId, currentFolder );
       
  2778         }
       
  2779     else if ( !isPersistent )
       
  2780         {
       
  2781         // get non-persistent folder name (eg some album name)
       
  2782         GetListItemText( currentIndex, info.iFolderText );
       
  2783         }
       
  2784     else
       
  2785         {
       
  2786         // get persistent folder id (eg "Unknown" folder)
       
  2787         info.iFolderId = id;
       
  2788         }
       
  2789 
       
  2790     info.iItemIndex = currentIndex;
       
  2791        
       
  2792     iState->SetQueryInfo( 0, KNullDesC, 0, EEQueryUpdate );
       
  2793         
       
  2794     TBool databaseChanged = ETrue;
       
  2795     QueryL( currentFolder, databaseChanged );
       
  2796     }
       
  2797 
       
  2798 
       
  2799 // -----------------------------------------------------------------------------
       
  2800 // CMediaFileDialog::CheckListboxIndex
       
  2801 // 
       
  2802 // Check that current item selection is correct. Function is used in case
       
  2803 // file system has changed (media files added / removed.
       
  2804 // -----------------------------------------------------------------------------
       
  2805 //
       
  2806 void CMediaFileDialog::CheckListboxIndex()
       
  2807     {
       
  2808     TMFCurrentItemInfo& info = iState->CurrentItemInfo();
       
  2809     if ( !info.iIndexCheckNeeded )
       
  2810         {
       
  2811         return;
       
  2812         }
       
  2813     
       
  2814     TInt direction = iState->QueryDirection();
       
  2815     TInt newListIndex = KErrNotFound;
       
  2816     
       
  2817     if ( direction == EEQueryUp )
       
  2818         {
       
  2819         FLOG( _L("query up") );
       
  2820         TInt prevId = iState->PreviousFolderId();
       
  2821         TInt listIndex = iState->ListIndex( prevId );
       
  2822         if ( !iState->IsPersistent( prevId ) )
       
  2823             {
       
  2824             iState->GetText( prevId, info.iFolderText );
       
  2825             TInt num = iState->LeadingPersistentFolderCount();
       
  2826             newListIndex = iMediaFileHandler->ItemIndex(
       
  2827                            info.iFolderText, listIndex );
       
  2828             iState->SetCurrentItemIndex( newListIndex + num );
       
  2829             }
       
  2830         else
       
  2831             {
       
  2832             iState->SetCurrentItemIndex( listIndex );
       
  2833             }
       
  2834         }
       
  2835 
       
  2836     if ( direction == EEQueryUpdate )
       
  2837         {
       
  2838         if ( info.iMediaFileId != KErrNotFound )
       
  2839             {
       
  2840             newListIndex = iMediaFileHandler->ItemIndex(
       
  2841                            info.iMediaFileId, info.iItemIndex );
       
  2842             }
       
  2843         else if ( info.iFolderText.Length() > 0 )
       
  2844             {
       
  2845             newListIndex = iMediaFileHandler->ItemIndex(
       
  2846                     info.iFolderText, info.iItemIndex );
       
  2847             TInt num = iState->LeadingPersistentFolderCount();
       
  2848             newListIndex = newListIndex + num;
       
  2849             }
       
  2850         else if ( info.iFolderId != KErrNotFound )
       
  2851             {
       
  2852             newListIndex = iState->ListIndex( info.iFolderId );
       
  2853             }
       
  2854         
       
  2855         iState->SetCurrentItemIndex( newListIndex );
       
  2856         }
       
  2857     }
       
  2858 
       
  2859 
       
  2860 // -----------------------------------------------------------------------------
       
  2861 // CMediaFileDialog::HandlePreviewEventL (from MPreviewHandlerObserver)
       
  2862 // 
       
  2863 // -----------------------------------------------------------------------------
       
  2864 //
       
  2865 void CMediaFileDialog::HandlePreviewEventL( TInt aEvent, TInt aError )
       
  2866     {
       
  2867     if ( aEvent == MPreviewHandlerObserver::EAudioPreviewComplete )
       
  2868         {
       
  2869         ShowPreviewErrorNoteL( aError, CMediaFileHandler::EMediaTypeMusic );
       
  2870         }
       
  2871 
       
  2872     if ( aEvent == MPreviewHandlerObserver::EVideoPreviewComplete )
       
  2873         {
       
  2874         ShowPreviewErrorNoteL( aError, CMediaFileHandler::EMediaTypeVideo );        
       
  2875         }
       
  2876 
       
  2877     if ( aEvent == MPreviewHandlerObserver::EPreviewError )
       
  2878         {
       
  2879         FLOG( _L("### CMediaFileDialog::HandlePreviewEventL (%d) ###"), aError );
       
  2880         
       
  2881         ShowPreviewErrorNoteL( aError, CMediaFileHandler::EMediaTypeMusic );        
       
  2882         }
       
  2883     }
       
  2884 
       
  2885 
       
  2886 // -----------------------------------------------------------------------------
       
  2887 // CMediaFileDialog::HandleLosingForeground (from MCoeForegroundObserver)
       
  2888 //
       
  2889 // -----------------------------------------------------------------------------
       
  2890 //
       
  2891 void CMediaFileDialog::HandleLosingForeground()
       
  2892     {
       
  2893     iForeGround = EFalse;
       
  2894     //Record the current item info
       
  2895     if ( iState && iListBox)
       
  2896     	{
       
  2897     	iState->SetCurrentItemIndex( CurrentItemListIndex() );
       
  2898     	}
       
  2899     
       
  2900     CancelPreview();
       
  2901     }
       
  2902 
       
  2903 
       
  2904 // -----------------------------------------------------------------------------
       
  2905 // CMediaFileDialog::HandleGainingForeground (from MCoeForegroundObserver)
       
  2906 //
       
  2907 // -----------------------------------------------------------------------------
       
  2908 //
       
  2909 void CMediaFileDialog::HandleGainingForeground()
       
  2910     {
       
  2911     iForeGround = ETrue;
       
  2912     if ( iListBox )
       
  2913     	{
       
  2914     	UpdateListBoxL( EFalse );
       
  2915    	 	}
       
  2916     }
       
  2917 
       
  2918 
       
  2919 // -----------------------------------------------------------------------------
       
  2920 // CMediaFileDialog::HandleControlEventL (from MCoeControlObserver)
       
  2921 // 
       
  2922 // -----------------------------------------------------------------------------
       
  2923 //
       
  2924 void CMediaFileDialog::HandleControlEventL( CCoeControl* aControl,
       
  2925                                                       TCoeEvent aEventType )
       
  2926      {
       
  2927      TInt currentFolderId = iState->CurrentFolder();
       
  2928      
       
  2929      if ( aEventType == EEventStateChanged )
       
  2930          {
       
  2931          CancelPreview();
       
  2932          if ( aControl == iListBox )
       
  2933              {
       
  2934              if ( currentFolderId == EEFolderRoot   ||
       
  2935                   currentFolderId == EEFolderSearch || 
       
  2936                   currentFolderId == EEFolderVideos )
       
  2937                 {
       
  2938                 UpdateCbaL( 0 );  // only these folders need dynamic cba update
       
  2939                 }
       
  2940              StartPreviewWithDelay();
       
  2941              ShowDetailsPopupL();   // show search details in Search view
       
  2942    
       
  2943              // forward listbox state change events to this control's
       
  2944              // observers
       
  2945              ReportEventL( MCoeControlObserver::EEventStateChanged );
       
  2946              }
       
  2947            
       
  2948          if ( FindBox() && aControl == FindBox() )
       
  2949              {
       
  2950              User::InfoPrint(_L("find box  event arrived"));
       
  2951               
       
  2952              // this event is received when user enters or deletes
       
  2953              // chars in find box. Backspace key in empty find box does not
       
  2954              // generate this event.
       
  2955 
       
  2956              if ( currentFolderId == EEFolderSearch ||
       
  2957                   currentFolderId == EEFolderRoot ||
       
  2958                   currentFolderId == EEFolderMusic ||
       
  2959                   currentFolderId == EEFolderSearchMusic )
       
  2960                  {
       
  2961                  StartSearchWithDelay();
       
  2962                  return;
       
  2963                  }
       
  2964             
       
  2965              // StartPreviewWithDelay();
       
  2966              
       
  2967              UpdateCbaL( 0 );
       
  2968              
       
  2969 //#ifdef _DEBUG
       
  2970              TBuf<KBufSize128> buf;
       
  2971              iState->GetTitle( iState->CurrentFolder(), buf );
       
  2972              TBuf<KBufSize128> buf2( buf );
       
  2973              TInt count = iListBox->Model()->NumberOfItems();
       
  2974              buf.Format( _L("%S  (%d)"), &buf2, count );
       
  2975              iStatusPaneHandler->SetNaviPaneTitle( buf );
       
  2976 //#endif
       
  2977             
       
  2978              // Forward listbox state change events to this control's
       
  2979              // observers
       
  2980              ReportEventL( MCoeControlObserver::EEventStateChanged );
       
  2981              }
       
  2982          }
       
  2983      }
       
  2984 
       
  2985 
       
  2986 // -----------------------------------------------------------------------------
       
  2987 // CMediaFileDialog::HandleWaitNoteL (from MMediaFileWaitNoteObserver)
       
  2988 // 
       
  2989 // -----------------------------------------------------------------------------
       
  2990 //
       
  2991 void CMediaFileDialog::HandleWaitNoteL( TInt /*aButtonId*/ )
       
  2992     {
       
  2993     iMediaFileHandler->CancelQuery();
       
  2994     }
       
  2995 
       
  2996 
       
  2997 // -----------------------------------------------------------------------------
       
  2998 // CMediaFileDialog::AdaptiveSearchTextChanged (from MAdaptiveSearchTextObserver)
       
  2999 // 
       
  3000 // -----------------------------------------------------------------------------
       
  3001 //
       
  3002 void CMediaFileDialog::AdaptiveSearchTextChanged( CAknSearchField* /*aSearchField*/ )
       
  3003     {
       
  3004     // not used
       
  3005     }
       
  3006 
       
  3007 
       
  3008 // -----------------------------------------------------------------------------
       
  3009 // CMediaFileDialog::OnPeninputUiDeactivated
       
  3010 // 
       
  3011 // -----------------------------------------------------------------------------
       
  3012 //
       
  3013 void CMediaFileDialog::OnPeninputUiDeactivated()
       
  3014     {
       
  3015     iPeninputActive = EFalse;
       
  3016     
       
  3017     if ( FindBox()->TextLength() == 0 && 
       
  3018           ( iState->CurrentFolder() == EEFolderSearch ||
       
  3019             iState->CurrentFolder() == EEFolderSearchMusic ) )
       
  3020         {
       
  3021         HandleBackL();
       
  3022         }
       
  3023     else
       
  3024         {
       
  3025         // search starts immediately after user closes pen input
       
  3026         TRAP_IGNORE( StartSearchWithDelay() );
       
  3027         }
       
  3028     }
       
  3029 
       
  3030 
       
  3031 // -----------------------------------------------------------------------------
       
  3032 // CMediaFileDialog::OnPeninputUiActivated
       
  3033 // 
       
  3034 // -----------------------------------------------------------------------------
       
  3035 //
       
  3036 void CMediaFileDialog::OnPeninputUiActivated()
       
  3037     {
       
  3038     iPeninputActive = ETrue;
       
  3039     CancelPreview();
       
  3040     }
       
  3041 
       
  3042 
       
  3043 // -----------------------------------------------------------------------------
       
  3044 // CMediaFileDialog::HandleListBoxEventL (from MEikListBoxObserver)
       
  3045 // 
       
  3046 // -----------------------------------------------------------------------------
       
  3047 //
       
  3048 void CMediaFileDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
  3049                                              TListBoxEvent aEventType )
       
  3050     {
       
  3051     TInt current = iState->CurrentFolder();
       
  3052     if ( aEventType == EEventPenDownOnItem)
       
  3053          {
       
  3054          iListBox->View()->ItemDrawer()->SetFlags( CListItemDrawer::EPressedDownState );
       
  3055          return;
       
  3056          }
       
  3057     
       
  3058     if ( aEventType == EEventItemClicked )
       
  3059         {
       
  3060         	  iIsDoubleClicked = EFalse;
       
  3061         if ( current != KErrNotFound )
       
  3062             {
       
  3063             HandleOKL( EAttrOpen );  // open folder item
       
  3064             }
       
  3065         return;
       
  3066         }
       
  3067 
       
  3068     if ( aEventType == EEventItemDoubleClicked || aEventType == EEventEnterKeyPressed )
       
  3069         {
       
  3070         TBool closeDialog = HandleOKL( EAttrDoubleClicked );
       
  3071         
       
  3072         if ( closeDialog )
       
  3073             {
       
  3074             // close after short delay (dialog cannot be closed from this function)
       
  3075             CloseDialogWithDelayL();
       
  3076             }
       
  3077         iIsDoubleClicked = ETrue;
       
  3078         }
       
  3079     if ( aEventType == EEventItemDraggingActioned )
       
  3080     	{
       
  3081     	UpdateCbaL( KErrNone );
       
  3082     	DrawNow();
       
  3083     	}
       
  3084     }
       
  3085 
       
  3086 
       
  3087 // -----------------------------------------------------------------------------
       
  3088 // CMediaFileDialog::CloseDialogWithDelayL
       
  3089 //
       
  3090 // -----------------------------------------------------------------------------
       
  3091 //
       
  3092 void CMediaFileDialog::CloseDialogWithDelayL()
       
  3093     {    
       
  3094     delete iIdle;
       
  3095     iIdle = NULL;
       
  3096     iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
  3097     
       
  3098     if ( iIdle )
       
  3099         {                    
       
  3100         iIdle->Start( TCallBack( CloseDialog, this ) );
       
  3101         }
       
  3102     delete iInputBlock;
       
  3103     iInputBlock = NULL;
       
  3104     iInputBlock = CAknInputBlock::NewLC();
       
  3105     CleanupStack::Pop( iInputBlock );
       
  3106     }
       
  3107 
       
  3108 
       
  3109 // -----------------------------------------------------------------------------
       
  3110 // CMediaFileDialog::CloseDialog
       
  3111 //
       
  3112 // -----------------------------------------------------------------------------
       
  3113 //
       
  3114 TInt CMediaFileDialog::CloseDialog( TAny *aObj )
       
  3115     {    
       
  3116     CMediaFileDialog *dlg = (CMediaFileDialog*) aObj;
       
  3117     delete dlg->iInputBlock;
       
  3118     dlg->iInputBlock = NULL;
       
  3119     
       
  3120     TRAP_IGNORE( dlg->TryExitL( EAknSoftkeyOk ) );
       
  3121     
       
  3122     return 0;
       
  3123     }
       
  3124 
       
  3125 
       
  3126 // -----------------------------------------------------------------------------
       
  3127 // CMediaFileDialog::HandleActiveCallL (from MMFActiveCallerObserver)
       
  3128 //
       
  3129 // -----------------------------------------------------------------------------
       
  3130 //
       
  3131 void CMediaFileDialog::HandleActiveCallL( TInt aCallId )
       
  3132     {
       
  3133     if ( aCallId == EAttrPreview )
       
  3134         {
       
  3135         //double click the item of the listbox to select the tones, do not preview it.
       
  3136         if ( iIsDoubleClicked )
       
  3137         	{
       
  3138         	iIsDoubleClicked = EFalse;
       
  3139         	}
       
  3140         else
       
  3141         	{
       
  3142             // start preview after delay
       
  3143             PreviewL( CMediaFileList::EMediaFileTypeAudio ); 
       
  3144         	}
       
  3145         }
       
  3146 
       
  3147     if ( aCallId == EAttrSearch )
       
  3148         {
       
  3149         // start search after delay
       
  3150         SearchL();    
       
  3151         }
       
  3152     }
       
  3153 
       
  3154 
       
  3155 
       
  3156 
       
  3157 /******************************************************************************
       
  3158  *  class CMFListHandler
       
  3159  ******************************************************************************/
       
  3160 
       
  3161 // -----------------------------------------------------------------------------
       
  3162 // CMFListHandler::NewL
       
  3163 // 
       
  3164 // -----------------------------------------------------------------------------
       
  3165 //
       
  3166 CMFListHandler* CMFListHandler::NewL()
       
  3167     {
       
  3168 	CMFListHandler* self = new (ELeave) CMFListHandler();
       
  3169     CleanupStack::PushL(self);
       
  3170 	self->ConstructL();
       
  3171     CleanupStack::Pop(self);
       
  3172 	return self;
       
  3173     }
       
  3174 
       
  3175 
       
  3176 // -----------------------------------------------------------------------------
       
  3177 // CMFListHandler::~CMFListHandler
       
  3178 // 
       
  3179 // -----------------------------------------------------------------------------
       
  3180 //
       
  3181 CMFListHandler::~CMFListHandler()
       
  3182     {
       
  3183     }
       
  3184 
       
  3185 
       
  3186 // -----------------------------------------------------------------------------
       
  3187 // CMFListHandler::ConstructL
       
  3188 // 
       
  3189 // -----------------------------------------------------------------------------
       
  3190 //
       
  3191 void CMFListHandler::ConstructL( void )
       
  3192     {
       
  3193     }
       
  3194 
       
  3195 
       
  3196 // -----------------------------------------------------------------------------
       
  3197 // CMFListHandler::CMFListHandler
       
  3198 // 
       
  3199 // -----------------------------------------------------------------------------
       
  3200 //
       
  3201 CMFListHandler::CMFListHandler()
       
  3202     {
       
  3203     }
       
  3204 
       
  3205 
       
  3206 // -----------------------------------------------------------------------------
       
  3207 // CMFListHandler::SetObserver
       
  3208 // 
       
  3209 // -----------------------------------------------------------------------------
       
  3210 //
       
  3211 void CMFListHandler::SetObserver( CMFListHandlerObserver* aObserver )
       
  3212     {
       
  3213     iObserver = aObserver;
       
  3214     }
       
  3215     
       
  3216     
       
  3217 // -----------------------------------------------------------------------------
       
  3218 // CMFListHandler::MdcaCount (from MDesCArray)
       
  3219 // 
       
  3220 // -----------------------------------------------------------------------------
       
  3221 //
       
  3222 TInt CMFListHandler::MdcaCount() const
       
  3223     {
       
  3224     return iObserver->ListboxItemCount();
       
  3225     }
       
  3226 
       
  3227 
       
  3228 // -----------------------------------------------------------------------------
       
  3229 // CMFListHandler::MdcaPoint (from MDesCArray)
       
  3230 //
       
  3231 // CEikListBox calls this function just before it draws list box item.
       
  3232 // -----------------------------------------------------------------------------
       
  3233 //
       
  3234 TPtrC16 CMFListHandler::MdcaPoint( TInt aIndex ) const
       
  3235     {
       
  3236     return iObserver->ConstructListboxItem( aIndex );
       
  3237     }
       
  3238 
       
  3239 
       
  3240 // -----------------------------------------------------------------------------
       
  3241 // CMFListHandler::Panic
       
  3242 //
       
  3243 // -----------------------------------------------------------------------------
       
  3244 //
       
  3245 void CMFListHandler::Panic( TInt aReason ) 
       
  3246     {
       
  3247 	_LIT( KPanicCategory, "CMFListHandler" );
       
  3248 	
       
  3249 	User::Panic( KPanicCategory, aReason ); 
       
  3250     }
       
  3251 
       
  3252 
       
  3253 
       
  3254 
       
  3255 
       
  3256 
       
  3257 
       
  3258 
       
  3259 //  End of File