wvuing/wvuiave/AppSrc/CCAToneSettingItem.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  IM Alert Tone setting item
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CCAToneSettingItem.h"
       
    22 #include    "IMDialogUtils.h"
       
    23 #include    "imutils.h"
       
    24 #include    "imprivatecrkeys.h"
       
    25 #include    "imvariant.hrh"
       
    26 
       
    27 #include    <CFLDFileListContainer.h>
       
    28 #include    <stringloader.h>
       
    29 #include	<chatNG.rsg>
       
    30 #include    <data_caging_path_literals.hrh>
       
    31 #include    <centralrepository.h>
       
    32 #include    <mediafilelist.h>
       
    33 
       
    34 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    35 // so the enums for keys and central repository header is added here
       
    36 #include 	"VariantKeys.h"
       
    37 
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 namespace
       
    41     {
       
    42     // CONSTANTS
       
    43     _LIT( KIgnoredExtension, ".RNG" );
       
    44     _LIT( KProfileSilentTone,     "Z:No_Sound.wav" );
       
    45     }
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCAToneSettingItem::CCAToneSettingItem
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CCAToneSettingItem::CCAToneSettingItem( TInt aIdentifier, TDes& aToneName,
       
    56                                         CRepository& aCenRep, TBool aBranding ):
       
    57         CAknSettingItem( aIdentifier ),
       
    58         iExternalToneFileName( aToneName ),
       
    59         iBranding( aBranding ),
       
    60         iCenRep( aCenRep )
       
    61     {
       
    62     }
       
    63 
       
    64 // Destructor
       
    65 CCAToneSettingItem::~CCAToneSettingItem()
       
    66     {
       
    67     delete iNoSoundText;
       
    68     delete iNoSoundFileName;
       
    69     delete iTitle;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CCAToneSettingItem::StoreL
       
    74 // (other items were commented in a header).
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CCAToneSettingItem::StoreL()
       
    78     {
       
    79     if ( iInternalToneFileName.Length() == 0 )
       
    80         {
       
    81         // use the default sound file
       
    82         DefaultSoundFile( iInternalToneFileName );
       
    83         }
       
    84     iExternalToneFileName.Copy( iInternalToneFileName.Left( iExternalToneFileName.MaxLength() ) );
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CCAToneSettingItem::LoadL
       
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CCAToneSettingItem::LoadL()
       
    93     {
       
    94     iInternalToneFileName.Copy( iExternalToneFileName.Left( iInternalToneFileName.MaxLength() ) );
       
    95     if ( iInternalToneFileName.Length() == 0 )
       
    96         {
       
    97         // use the default sound file
       
    98         DefaultSoundFile( iInternalToneFileName );
       
    99         }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CCAToneSettingItem::EditItemL
       
   104 // (other items were commented in a header).
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CCAToneSettingItem::EditItemL( TBool /* aCalledFromMenu */ )
       
   108     {
       
   109     // BrandaleToneList
       
   110     CFLDFileListContainer* fl;
       
   111     
       
   112     // New mediafilelist API
       
   113     CMediaFileList* mfl;
       
   114     TInt nullItem = KErrNotFound;
       
   115     
       
   116     // Add "Off" as first item in tone selection list.
       
   117     // Launch File List Dialog
       
   118     HBufC* currentTone = iInternalToneFileName.AllocLC();
       
   119     TBool cancel( EFalse );
       
   120     TBool valid( EFalse );
       
   121     while ( !cancel && !valid )
       
   122         {
       
   123 
       
   124 #ifdef RD_30_COMPATIBILITY_MODE
       
   125         // S60 3.0
       
   126         if ( !iBranding )
       
   127             {
       
   128             fl = CFLDFileListContainer::NewLC();
       
   129             fl->InsertNullItemL( *iNoSoundText, *iNoSoundFileName );
       
   130             }
       
   131         else
       
   132             {
       
   133             fl = CFLDFileListContainer::NewLC( R_AUDIO_FILELIST_MODEL, ETrue );
       
   134             fl->InsertNullItemL( *iNoSoundText, *iNoSoundFileName );
       
   135             }
       
   136 
       
   137 #else // S60 COMMON
       
   138 
       
   139         // Branding functionality depends on CR variation (iBrandableToneList)
       
   140         if ( iBranding && iBrandableToneList )
       
   141             {
       
   142             // Use branded tone list
       
   143             fl = CFLDFileListContainer::NewLC( R_AUDIO_CLF_LIST_MODEL,
       
   144                                                R_AUDIO_FLDIRECTORIES );
       
   145             fl->InsertNullItemL( *iNoSoundText, *iNoSoundFileName );
       
   146             }
       
   147         else
       
   148             {
       
   149             // Use default tone list when iBrandableToneList is EFalse
       
   150             mfl = CMediaFileList::NewL();
       
   151             CleanupStack::PushL( mfl );
       
   152             mfl->SetAttrL( CMediaFileList::EAttrTitle, iTitle );
       
   153             mfl->SetNullItemL(
       
   154             		*iNoSoundText, 
       
   155             		*iNoSoundFileName,
       
   156             		CMediaFileList::EMediaFileTypeAudio,
       
   157                     CMediaFileList::ENullItemIconNone
       
   158                     );
       
   159 
       
   160             // Exclude the video folder
       
   161             mfl->SetAttrL( CMediaFileList::EAttrExcludeFolder, CMediaFileList::EMediaFileTypeVideo );
       
   162             }
       
   163 #endif //RD_30_COMPATIBILITY_MODE
       
   164 
       
   165         // loop until we get cancel or valid tone file
       
   166         if ( iBranding && iBrandableToneList )
       
   167         	{
       
   168         	// launch the filelist
       
   169         	cancel = !fl->LaunchL( iInternalToneFileName, *iTitle );
       
   170         	}
       
   171         else
       
   172         	{
       
   173         	// launch the mediafilelist
       
   174         	cancel = !mfl->ShowMediaFileListL( &iInternalToneFileName, &nullItem, NULL, NULL );
       
   175         	}
       
   176         
       
   177         if ( !cancel && iInternalToneFileName.Length() > 0 )
       
   178             {
       
   179             // check validity (== is it DRM protected)
       
   180             valid = !IMUtils::FileProtectedL( iInternalToneFileName );
       
   181 
       
   182             if ( !valid )
       
   183                 {
       
   184                 HBufC* text = CCoeEnv::Static()->AllocReadResourceLC(
       
   185                                   R_QTN_CHAT_SETTINGS_TONE_INVALID );
       
   186                 IMDialogUtils::DisplayErrorConfirmationNoteL( *text );
       
   187                 CleanupStack::PopAndDestroy( text );
       
   188                 
       
   189                 if ( iBranding && iBrandableToneList )
       
   190                 	{
       
   191                 if ( fl )
       
   192                     {
       
   193                     //delete it as it is constructed again.
       
   194                     CleanupStack::PopAndDestroy( fl );
       
   195                 		}
       
   196                 	}
       
   197                 else
       
   198                 	{
       
   199                 	if ( mfl )
       
   200                 		{
       
   201                 		//delete it as it is constructed again.
       
   202                 		CleanupStack::PopAndDestroy( mfl );
       
   203                 		}
       
   204                 	}
       
   205                 }
       
   206             else
       
   207                 {
       
   208                 if ( iBranding && iBrandableToneList )
       
   209                 	{
       
   210                 	CleanupStack::PopAndDestroy( fl );
       
   211                 	}
       
   212                 else
       
   213                 	{
       
   214                 	CleanupStack::PopAndDestroy( mfl );
       
   215                 	}
       
   216                 }
       
   217             }
       
   218         else
       
   219             {
       
   220             // no tone => valid
       
   221             valid = ETrue;
       
   222             if ( iBranding && iBrandableToneList )
       
   223             	{
       
   224             	CleanupStack::PopAndDestroy( fl );
       
   225             	}
       
   226             else
       
   227             	{
       
   228             	CleanupStack::PopAndDestroy( mfl );
       
   229             	}
       
   230             }
       
   231         }
       
   232 
       
   233     if ( cancel )
       
   234         {
       
   235         // cancelled, reset filename
       
   236         iInternalToneFileName.Copy( ( *currentTone ).Left( iInternalToneFileName.MaxLength() ) );
       
   237         }
       
   238 
       
   239     CleanupStack::PopAndDestroy( currentTone ); // currentTone, fl
       
   240     UpdateListBoxTextL();
       
   241 
       
   242     // trick for notifying the appsetting dialog of cancel.
       
   243     if ( cancel )
       
   244         {
       
   245         User::Leave( KErrCancel );
       
   246         }
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CCAToneSettingItem::SettingTextL
       
   251 // (other items were commented in a header).
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 const TDesC& CCAToneSettingItem::SettingTextL()
       
   255     {
       
   256     if ( iInternalToneFileName.Length() > 0 )
       
   257         {
       
   258         // FLD has returned a filename
       
   259         if ( iInternalToneFileName.CompareF( *iNoSoundFileName ) == 0 )
       
   260             {
       
   261             // Filename is "No_Sound", return localized text "None"
       
   262             iSettingText.Set( *iNoSoundText );
       
   263             }
       
   264         else
       
   265             {
       
   266             // Filename is something else
       
   267             TParsePtrC parse( iInternalToneFileName );
       
   268             if ( parse.Ext().CompareF( KIgnoredExtension ) == 0 )
       
   269                 {
       
   270                 iSettingText.Set( parse.Name() );
       
   271                 }
       
   272             else
       
   273                 {
       
   274                 iSettingText.Set( parse.NameAndExt() );
       
   275                 }
       
   276             }
       
   277         }
       
   278     else
       
   279         {
       
   280         // Filename is an empty descriptor, return localised text "None"
       
   281         iSettingText.Set( *iNoSoundText );
       
   282         }
       
   283     return iSettingText;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CCAToneSettingItem::CompleteConstructionL
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CCAToneSettingItem::CompleteConstructionL()
       
   292     {
       
   293     iNoSoundText =
       
   294         StringLoader::LoadL( R_CHAT_AUDIO_TEXT_NONE );
       
   295 
       
   296     TFileName fileName;
       
   297     TParse* fp = new ( ELeave ) TParse();
       
   298     fp->Set( KProfileSilentTone, &KDC_RESOURCE_FILES_DIR, NULL );
       
   299     fileName.Copy( fp->FullName().Left( fileName.MaxLength() ) );
       
   300     delete fp;
       
   301     iNoSoundFileName = fileName.AllocL();
       
   302     iTitle = StringLoader::LoadL( R_CHAT_AUDIO_TEXT_SELECT_TONE );
       
   303 
       
   304     // Read CR variation flag
       
   305     iBrandableToneList = ( IMUtils::CRKeyL( KCRUidIMVariation, KIMVariationKey )
       
   306                            & EIMFeatBrandableTones );
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // CCAToneSettingItem::DefaultSoundFile
       
   311 // Attention: This same function exists also in CCAAudioManager,
       
   312 // because IMUtils cannot be used there. So if changing here, change also
       
   313 // there.
       
   314 // (other items were commented in a header).
       
   315 // ---------------------------------------------------------
       
   316 //
       
   317 void CCAToneSettingItem::DefaultSoundFile( TDes& aSoundFileName )
       
   318     {
       
   319     TInt err = KErrNone;
       
   320     TBool overRide = EFalse;
       
   321     TRAP( err, overRide =
       
   322               IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_OVERRIDE_DEFAULT_TONE ) )
       
   323 
       
   324     if ( overRide && !err )
       
   325         {
       
   326         // Get overridden default tone from brand package
       
   327         HBufC* temp = NULL;
       
   328         TRAP( err, temp = StringLoader::LoadL( R_DEFAULT_TONE ) );
       
   329         if ( temp )
       
   330             {
       
   331             aSoundFileName = *temp;
       
   332             delete temp;
       
   333             }
       
   334         }
       
   335     else if ( !err )
       
   336         {
       
   337         // Get default tone from CenRep
       
   338         err = iCenRep.Get( KIMAlertTone, aSoundFileName );
       
   339         }
       
   340 
       
   341     if ( err )
       
   342         {
       
   343         CActiveScheduler::Current()->Error( err );
       
   344         }
       
   345     }
       
   346 
       
   347 //  End of File