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