profilesservices/ProfileEngine/WrapperSrc/CProEngAlertToneSeekerImpl.cpp
changeset 0 8c5d936e5675
child 24 8ee96d21d9bf
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Implementation of CProEngAlertToneSeekerImpl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CProEngAlertToneSeekerImpl.h"
       
    22 #include    <MCLFItemListModel.h>
       
    23 #include    <MCLFContentListingEngine.h>
       
    24 #include    <MCLFItem.h>
       
    25 #include    <ContentListingFactory.h>
       
    26 #include    <f32file.h>  // RFs, TParse
       
    27 #include    <pathinfo.h>
       
    28 #include    <MProEngAlertToneSeekerObserver.h>
       
    29 #include    "CProEngPostFilter.h"
       
    30 
       
    31 namespace
       
    32     {
       
    33     // Constants
       
    34     const TInt KProEngRomFileArrayGranularity( 40 );
       
    35     const TInt KProEngToneListGranularity( 80 );
       
    36     }
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CProEngAlertToneSeekerImpl::CProEngAlertToneSeekerImpl
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CProEngAlertToneSeekerImpl::CProEngAlertToneSeekerImpl()
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CProEngAlertToneSeekerImpl::ConstructL
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CProEngAlertToneSeekerImpl::ConstructL()
       
    53     {
       
    54     iContentListingEngine = ContentListingFactory::NewContentListingEngineLC(); // CSI: 49 # iContentLisingEngine is popped out of the stack immediately
       
    55     CleanupStack::Pop(); // iContentListingEngine
       
    56     iPostFilter = CProEngPostFilter::NewL();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CProEngAlertToneSeekerImpl::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CProEngAlertToneSeekerImpl* CProEngAlertToneSeekerImpl::NewL()
       
    65     {
       
    66     CProEngAlertToneSeekerImpl* self =
       
    67         new ( ELeave ) CProEngAlertToneSeekerImpl();
       
    68 
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72 
       
    73     return self;
       
    74     }
       
    75 
       
    76 // Destructor
       
    77 CProEngAlertToneSeekerImpl::~CProEngAlertToneSeekerImpl()
       
    78     {
       
    79     delete iPostFilter;
       
    80     delete iRomFiles;
       
    81     delete iModel;
       
    82     delete iContentListingEngine;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CProEngAlertToneSeekerImpl::FetchAlertToneListL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CProEngAlertToneSeekerImpl::FetchAlertToneListL(
       
    90         MProEngAlertToneSeekerObserver& aObserver )
       
    91     {
       
    92     iObserver = &aObserver;
       
    93 
       
    94     if( !iRomFiles )
       
    95         {
       
    96         CreateRomFileListL();
       
    97         }
       
    98 
       
    99     CreateListModelL();
       
   100 
       
   101     iModel->RefreshL(); // asynchronous
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CProEngAlertToneSeekerImpl::CancelFetch
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CProEngAlertToneSeekerImpl::CancelFetch()
       
   109     {
       
   110     if( iModel )
       
   111         {
       
   112         iModel->CancelRefresh();
       
   113         }
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CProEngAlertToneSeekerImpl::FetchAlertToneListL
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CProEngAlertToneSeekerImpl::HandleOperationEventL(
       
   121         TCLFOperationEvent aOperationEvent,
       
   122         TInt aError )
       
   123     {
       
   124     // We are only interested of refresh complete, ignore other events:
       
   125     if( aOperationEvent != ECLFRefreshComplete )
       
   126         {
       
   127         return;
       
   128         }
       
   129 
       
   130     if( aError != KErrNone )
       
   131         {
       
   132         iObserver->HandleError( aError );
       
   133         return;
       
   134         }
       
   135 
       
   136     CDesCArray* toneList =
       
   137         new ( ELeave ) CDesCArraySeg( KProEngToneListGranularity );
       
   138     CleanupStack::PushL( toneList );
       
   139 
       
   140     // copy the files in ROM
       
   141     TInt count( iRomFiles->Count() );
       
   142     for( TInt i( 0 ); i<count; ++i )
       
   143         {
       
   144         toneList->AppendL( ( *iRomFiles )[i] );
       
   145         }
       
   146 
       
   147     // copy the files found by Content Listing Framework
       
   148     count = iModel->ItemCount();
       
   149     for( TInt i( 0 ); i<count; ++i )
       
   150         {
       
   151         TPtrC fileNameAndPath;
       
   152         aError = iModel->Item( i ).GetField( ECLFFieldIdFileNameAndPath,
       
   153                                              fileNameAndPath );
       
   154         if( aError )
       
   155             {
       
   156             break;
       
   157             }
       
   158 
       
   159         toneList->AppendL( fileNameAndPath );
       
   160         }
       
   161 
       
   162     if( aError != KErrNone )
       
   163         {
       
   164         CleanupStack::PopAndDestroy( toneList );
       
   165         iObserver->HandleError( aError );
       
   166         return;
       
   167         }
       
   168 
       
   169     CleanupStack::Pop( toneList );
       
   170 
       
   171     TRAP( aError,
       
   172           iObserver->HandleAlertToneListCompletedL( toneList ) );
       
   173     if( aError != KErrNone )
       
   174         {
       
   175         iObserver->HandleError( aError );
       
   176         }
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CProEngAlertToneSeekerImpl::CreateListModelL
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CProEngAlertToneSeekerImpl::CreateListModelL()
       
   184     {
       
   185     if( iModel )
       
   186         {
       
   187         delete iModel;
       
   188         iModel = NULL;
       
   189         }
       
   190 
       
   191     iModel = iContentListingEngine->CreateListModelLC( *this );
       
   192     CleanupStack::Pop(); // iModel
       
   193 
       
   194     // array for wanted media types
       
   195     RArray<TInt> array;
       
   196     CleanupClosePushL( array );
       
   197 
       
   198     array.AppendL( ECLFMediaTypeMusic );
       
   199     array.AppendL( ECLFMediaTypeSound );
       
   200 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   201     array.AppendL( ECLFMediaTypeVideo );
       
   202 #endif  // RD_VIDEO_AS_RINGING_TONE
       
   203 
       
   204     iModel->SetWantedMediaTypesL( array.Array() );
       
   205     iModel->SetPostFilter( iPostFilter );
       
   206 
       
   207     CleanupStack::PopAndDestroy( &array );
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CProEngAlertToneSeekerImpl::CreateRomFileListL
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CProEngAlertToneSeekerImpl::CreateRomFileListL()
       
   215     {
       
   216     iRomFiles = new ( ELeave ) CDesCArraySeg( KProEngRomFileArrayGranularity );
       
   217 
       
   218     RFs fs;
       
   219     User::LeaveIfError( fs.Connect() );
       
   220     CleanupClosePushL( fs );
       
   221 
       
   222     RBuf pathBuf;
       
   223     CleanupClosePushL( pathBuf );
       
   224     pathBuf.CreateL( KMaxFileName );
       
   225     pathBuf.Append( PathInfo::RomRootPath() );
       
   226     TInt rootPathLength( pathBuf.Length() );
       
   227 
       
   228     TParse* parse = new ( ELeave ) TParse;
       
   229     CleanupStack::PushL( parse );
       
   230 
       
   231     pathBuf.Append( PathInfo::DigitalSoundsPath() );
       
   232     AppendRomFilesL( fs, pathBuf, *parse );
       
   233 
       
   234     pathBuf.SetLength( rootPathLength );
       
   235     pathBuf.Append( PathInfo::SimpleSoundsPath() );
       
   236     AppendRomFilesL( fs, pathBuf, *parse );
       
   237     
       
   238     CleanupStack::PopAndDestroy( 3, &fs );
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CProEngAlertToneSeekerImpl::AppendRomFilesL
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CProEngAlertToneSeekerImpl::AppendRomFilesL( RFs& aFs, const TDesC& aPath,
       
   246                                                   TParse& aParse )
       
   247     {
       
   248     CDir* dir;
       
   249     TInt err( aFs.GetDir( aPath, KEntryAttNormal, ESortNone, dir ) );
       
   250 
       
   251     if( ( err != KErrNone ) && ( err != KErrPathNotFound ) )
       
   252         {
       
   253         User::Leave( err );
       
   254         }
       
   255 
       
   256     if( err == KErrNone )
       
   257         {
       
   258         CleanupStack::PushL( dir );
       
   259 
       
   260         TInt count( dir->Count() );
       
   261         for( TInt i( 0 ); i<count; ++i )
       
   262             {
       
   263             // concatenate the directory path and the file name
       
   264             aParse.Set( aPath, &( ( *dir )[i].iName ), NULL );
       
   265 
       
   266             iRomFiles->AppendL( aParse.FullName() );
       
   267             }
       
   268 
       
   269         CleanupStack::PopAndDestroy( dir );
       
   270         }
       
   271     }
       
   272 
       
   273 //  End of File
       
   274