phonebookui/Phonebook2/CommonUI/src/CPbk2RingingToneFetch.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Provides methods for fetching ringing tones into Phonebook.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <CPbk2RingingToneFetch.h>
       
    21 
       
    22 // Phonebook 2
       
    23 #include <Pbk2CommonUi.rsg>
       
    24 
       
    25 // System includes
       
    26 #include <cntfldst.h>
       
    27 #include <coemain.h>
       
    28 #include <mediafilelist.h>
       
    29 #include <centralrepository.h>
       
    30 #include <ProfileEngineDomainCRKeys.h>
       
    31 #include <DRMHelper.h>
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 inline CPbk2RingingToneFetch::CPbk2RingingToneFetch()
       
    35     {
       
    36     }
       
    37 
       
    38 CPbk2RingingToneFetch::~CPbk2RingingToneFetch()
       
    39     {
       
    40     delete iNoSound;
       
    41     delete iTitle;
       
    42     }
       
    43 
       
    44 EXPORT_C CPbk2RingingToneFetch* CPbk2RingingToneFetch::NewL()
       
    45     {
       
    46     CPbk2RingingToneFetch* self = new ( ELeave ) CPbk2RingingToneFetch();
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 inline void CPbk2RingingToneFetch::ConstructL()
       
    54     {
       
    55     CCoeEnv* coeEnv = CCoeEnv::Static();
       
    56     iTitle = coeEnv->AllocReadResourceL( R_QTN_TC_POPUP_HEADING );
       
    57     iNoSound = coeEnv->AllocReadResourceL( R_QTN_PHOP_SELI_DEFAULT_RTONE );
       
    58     }
       
    59 
       
    60 EXPORT_C TBool CPbk2RingingToneFetch::FetchRingingToneL
       
    61         ( TFileName& aRingingToneFile )
       
    62     {
       
    63     // Fetch the DefaultToneFile from Profile
       
    64     TFileName   ringingToneFile;
       
    65 
       
    66     CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine );
       
    67     CleanupStack::PushL( cenrep );
       
    68 
       
    69     User::LeaveIfError( cenrep->Get( KProEngDefaultRingingTone,
       
    70     		                            ringingToneFile ) );
       
    71     CleanupStack::PopAndDestroy(); // cenrep
       
    72     
       
    73     CMediaFileList* list = CMediaFileList::NewL();
       
    74     CleanupStack::PushL( list );
       
    75     
       
    76     list->SetNullItemL( *iNoSound, ringingToneFile,  
       
    77             CMediaFileList::EMediaFileTypeAudio,
       
    78             CMediaFileList::ENullItemIconDefaultTone );
       
    79     list->SetAttrL( CMediaFileList::EAttrTitle, *iTitle );
       
    80     SetMaxToneFileSizeL( list );
       
    81     TInt nullItem = KErrNotFound;
       
    82     list->SetAttrL( CMediaFileList::EAttrAutomatedType,
       
    83             CDRMHelper::EAutomatedTypeRingingTone );
       
    84     TBool result = list->ShowMediaFileListL( &aRingingToneFile,
       
    85             &nullItem, NULL, NULL );
       
    86     CleanupStack::PopAndDestroy( list );
       
    87         
       
    88     // Set result to be ETrue if nullItem (like default tone) 
       
    89     // is selected in media file list.
       
    90     if ( KErrNotFound != nullItem )
       
    91         {
       
    92         //if DefaultTone is selected, then empty aRingingToneFile
       
    93         if( !ringingToneFile.Compare(aRingingToneFile) )
       
    94         	{
       
    95         	aRingingToneFile.Zero();
       
    96         	}
       
    97         result = ETrue;
       
    98         }
       
    99     return result;
       
   100     }
       
   101 
       
   102 // --------------------------------------------------------------------------
       
   103 // CPbk2RingingToneFetch::SetMaxToneFileSizeL
       
   104 // Limit the size of ringing tone files shown on the file list
       
   105 // according to cenrep key.
       
   106 //
       
   107 // @param aFL The ringing tone file list to limit
       
   108 // --------------------------------------------------------------------------
       
   109 //
       
   110 void CPbk2RingingToneFetch::SetMaxToneFileSizeL( CMediaFileList* aFl )
       
   111     {
       
   112     // Set file size limit if configured ON.
       
   113     TInt sizeLimitB( 0 );
       
   114     CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine );
       
   115     CleanupStack::PushL( cenrep );
       
   116 
       
   117     User::LeaveIfError( cenrep->Get( KProEngRingingToneMaxSize,
       
   118                                      sizeLimitB ) );
       
   119     CleanupStack::PopAndDestroy(); // cenrep
       
   120     if ( sizeLimitB < 0 )
       
   121         {
       
   122         sizeLimitB = 0;
       
   123         }
       
   124     sizeLimitB *= KKilo;
       
   125     if ( sizeLimitB )
       
   126         {
       
   127        aFl->SetAttrL( CMediaFileList::EAttrFileSize, sizeLimitB );
       
   128         }
       
   129     }
       
   130 
       
   131 //  End of File