calendarui/settings/settingsui/src/CalenFileListSettingItem.cpp
branchRCL_3
changeset 66 bd7edf625bdd
child 67 1539a383d7b6
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     1 /*
       
     2 * Copyright (c) 2002 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:   List of Setting Items for Tone selection.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //debug
       
    20 #include "calendarui_debug.h"
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include "CalenFileListSettingItem.h"
       
    25 
       
    26 #include "CalenPaths.h"
       
    27 #include "CalendarPrivateCRKeys.h"  // includes CalendarInternalCRKeys.h
       
    28 
       
    29 #include <Calendar.rsg>
       
    30 
       
    31 #include <centralrepository.h>
       
    32 #include <CFLDFileListContainer.h>
       
    33 #include <DRMHelper.h>
       
    34 #include <caf/caf.h>
       
    35 
       
    36 #include <ProfileEngineDomainConstants.h>
       
    37 #include <StringLoader.h>
       
    38 #include <featdiscovery.h> // CFeatureDiscovery
       
    39 #include <ProfileEngineDomainCRKeys.h> // KCRUidProfileEngine / KProEngRingingToneMaxSize
       
    40 
       
    41 // PathInfo for concatenating resource
       
    42 #include <pathinfo.h>
       
    43 // KDC_RESOURCE_DIR definition
       
    44 #include <data_caging_path_literals.hrh>
       
    45 #include <mediafilelist.h>
       
    46 
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CCalenFileListSettingItem::CCalenFileListSettingItem
       
    52 // C++ constructor can NOT contain any code, that might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CCalenFileListSettingItem::CCalenFileListSettingItem(TInt aIdentifier)
       
    56     : CAknSettingItem( aIdentifier )
       
    57     {
       
    58     TRACE_ENTRY_POINT;
       
    59     TRACE_EXIT_POINT;
       
    60     }
       
    61 
       
    62 // Destructor
       
    63 // -----------------------------------------------------------------------------
       
    64 // ?classname::?member_function
       
    65 // ?implementation_description
       
    66 // (other items were commented in a header).
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CCalenFileListSettingItem::~CCalenFileListSettingItem()
       
    70     {
       
    71     TRACE_ENTRY_POINT;
       
    72     
       
    73     if ( iToneNotifyHandler )
       
    74         {
       
    75         iToneNotifyHandler->StopListening();
       
    76         }
       
    77 
       
    78 
       
    79     delete iToneNotifyHandler;
       
    80     delete iRepository;
       
    81     delete iToneDefaultText;
       
    82     delete iToneOffText;
       
    83     delete iPopupHeader;
       
    84     
       
    85     TRACE_EXIT_POINT;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CCalenFileListSettingItem::CompleteConstructionL
       
    90 // ?implementation_description
       
    91 // (other items were commented in a header).
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CCalenFileListSettingItem::CompleteConstructionL()
       
    95     {
       
    96     TRACE_ENTRY_POINT;
       
    97     
       
    98     iToneDefaultText = StringLoader::LoadL( R_CALEN_FILELIST_DEFAULT );
       
    99     iToneOffText     = StringLoader::LoadL( R_CALEN_FILELIST_OFF );
       
   100     iPopupHeader     = StringLoader::LoadL( R_CALEN_FILELIST_HEADER );
       
   101 
       
   102     // Make off tone file name (z:\resource\No_sound.wav)
       
   103     // First, append ROM drive letter
       
   104     iOffToneFile = TParsePtrC( PathInfo::RomRootPath() ).Drive();
       
   105     // Then append off tone 
       
   106     iOffToneFile.Append( KProfileNoSoundPath );
       
   107 
       
   108     iRepository = CRepository::NewL( KCRUidCalendar );
       
   109 
       
   110     // Start listening for tone changes
       
   111     iToneNotifyHandler = CCenRepNotifyHandler::NewL( *this,
       
   112                                                      *iRepository,
       
   113                                                      CCenRepNotifyHandler::EStringKey,
       
   114                                                      KCalendarSoundFile );
       
   115     iToneNotifyHandler->StartListeningL();
       
   116 
       
   117     // Read tone setting from central repository
       
   118     TInt err = iRepository->Get( KCalendarDefaultSoundFile, iDefaultToneFile );
       
   119     if( err != KErrNone )
       
   120         {
       
   121         iDefaultToneFile = iOffToneFile;
       
   122         }
       
   123 
       
   124     TRACE_EXIT_POINT;
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CCalenFileListSettingItem::StoreL
       
   129 // ?implementation_description
       
   130 // (other items were commented in a header).
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CCalenFileListSettingItem::StoreL()
       
   134     {
       
   135     TRACE_ENTRY_POINT;
       
   136     
       
   137     if( iAlarmSoundChanged )
       
   138         {
       
   139         TFileName oldSound;
       
   140         User::LeaveIfError( iRepository->Get( KCalendarSoundFile, oldSound ) );
       
   141         UnRegisterSound( oldSound );  // unregister the old DRM sound file, new file was registered automatically by the filelist
       
   142         iAlarmSoundChanged = EFalse;
       
   143         }
       
   144     User::LeaveIfError( iRepository->Set( KCalendarSoundFile, iToneFile ) );
       
   145     
       
   146     TRACE_EXIT_POINT;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CCalenFileListSettingItem::LoadL
       
   151 // ?implementation_description
       
   152 // (other items were commented in a header).
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CCalenFileListSettingItem::LoadL()
       
   156     {
       
   157     TRACE_ENTRY_POINT;
       
   158     
       
   159     TInt error = iRepository->Get( KCalendarSoundFile, iToneFile );
       
   160     // There may not be any error in reading the property, but
       
   161     if(error)
       
   162         {
       
   163         iToneFile = iOffToneFile;
       
   164         }
       
   165         
       
   166     // check if we still have rights for this file.
       
   167     // But do not check for dummy 'Off' tone
       
   168     ASSERT(!IsEmpty(iToneFile)); // no error, but empty string
       
   169     if( ( !IsOffTone(iToneFile) && !HasPlayRights( iToneFile )) 
       
   170         || (IsEmpty(iToneFile)) )
       
   171         {
       
   172         // property may have empty string 
       
   173         // Alarm Tone = Default in UREL
       
   174         // panic in debug
       
   175         iToneFile = iDefaultToneFile;
       
   176         iAlarmSoundChanged = ETrue;
       
   177         }
       
   178     
       
   179     TRACE_EXIT_POINT;
       
   180     }
       
   181 
       
   182 void CCalenFileListSettingItem::HandleNotifyString( TUint32 aId, const TDesC16& aNewValue )
       
   183     {
       
   184     TRACE_ENTRY_POINT;
       
   185     
       
   186     PIM_TRAPD_HANDLE( DoHandleNotifyStringL(aId, aNewValue) );
       
   187     
       
   188     TRACE_EXIT_POINT;    
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CCalenFileListSettingItem::HandleNotifyString
       
   193 // ?implementation_description
       
   194 // (other items were commented in a header).
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CCalenFileListSettingItem::DoHandleNotifyStringL( TUint32 aId, const TDesC16& /* aNewValue */ )
       
   198     {
       
   199     TRACE_ENTRY_POINT;
       
   200     
       
   201     if ( aId == KCalendarSoundFile )
       
   202         {
       
   203         LoadL();
       
   204         UpdateListBoxTextL();
       
   205         }
       
   206     
       
   207     TRACE_EXIT_POINT;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CCalenFileListSettingItem::EditItemL
       
   212 // ?implementation_description
       
   213 // (other items were commented in a header).
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CCalenFileListSettingItem::EditItemL( TBool /*aCalledFromMenu*/ )
       
   217     {
       
   218     TRACE_ENTRY_POINT;
       
   219 
       
   220 #define NEW_MEDIA_FILE_LIST_API
       
   221 #ifndef NEW_MEDIA_FILE_LIST_API
       
   222     // Create instance of FileList using new FileList API
       
   223     CFLDFileListContainer* filelist = CFLDFileListContainer::NewLC();
       
   224 
       
   225     filelist->InsertNullItemL( *iToneDefaultText, iDefaultToneFile );
       
   226     filelist->InsertEndNullItemL( *iToneOffText, iOffToneFile );
       
   227     filelist->SetAutomatedType( CDRMHelper::EAutomatedTypeCalendarAlarm );
       
   228 
       
   229     // Do not show videos, use new FileList API
       
   230     filelist->AddExclusiveMediaTypeL( ECLFMediaTypeVideo );
       
   231     // Make sure that iOffToneFile is passed, in case iToneFile happens to be KNullDesC
       
   232     ASSERT(!IsEmpty(iToneFile));
       
   233     
       
   234     // Do not show items over the file size limit, if configured.
       
   235     if ( CFeatureDiscovery::IsFeatureSupportedL(
       
   236          KFeatureIdFfLimitedMessageAndAlarmToneSize ) )
       
   237         {
       
   238          // Max file size allowed (in KB).  0 == no limit.
       
   239         TInt fileSizeLimit = 0;
       
   240         CRepository* profilesCenRep = CRepository::NewLC( KCRUidProfileEngine );
       
   241 
       
   242         // Reading the repository should not fail, but if it does, the default
       
   243         // value we have for the file size limit is acceptable.
       
   244         profilesCenRep->Get( KProEngRingingToneMaxSize, fileSizeLimit ); // codescanner::crepository
       
   245         CleanupStack::PopAndDestroy( profilesCenRep );
       
   246 
       
   247         if ( fileSizeLimit > 0 )
       
   248             {
       
   249             filelist->SetMaxFileSize( fileSizeLimit * KKilo );
       
   250             }
       
   251         }
       
   252     TBool ok( filelist->LaunchL( iToneFile, *iPopupHeader ) );
       
   253 
       
   254     CleanupStack::PopAndDestroy( filelist ); // filelist
       
   255 #else
       
   256     CMediaFileList* list = CMediaFileList::NewL();
       
   257     CleanupStack::PushL(list);
       
   258     
       
   259     
       
   260     TInt nullItem = KErrNotFound;
       
   261     
       
   262     // off
       
   263     list->SetNullItemL(*iToneOffText, iOffToneFile,
       
   264             CMediaFileList::EMediaFileTypeAudio,
       
   265             CMediaFileList::ENullItemIconOff);
       
   266     
       
   267     // default tone
       
   268     list->SetNullItemL(*iToneDefaultText, iDefaultToneFile,
       
   269             CMediaFileList::EMediaFileTypeAudio,
       
   270             CMediaFileList::ENullItemIconDefaultTone);
       
   271     
       
   272     list->SetAttrL(CMediaFileList::EAttrExcludeFolder, CMediaFileList::EMediaFileTypeVideo);
       
   273     list->SetAttrL(CMediaFileList::EAttrAutomatedType, CDRMHelper::EAutomatedTypeCalendarAlarm);
       
   274 
       
   275     // Do not show items over the file size limit, if configured.
       
   276     if ( CFeatureDiscovery::IsFeatureSupportedL(
       
   277          KFeatureIdFfLimitedMessageAndAlarmToneSize ) )
       
   278         {
       
   279         // Max file size allowed (in KB).  0 == no limit.
       
   280         TInt fileSizeLimit = 0;
       
   281         CRepository* profilesCenRep = CRepository::NewLC( KCRUidProfileEngine );
       
   282 
       
   283         // Reading the repository should not fail, but if it does, the default
       
   284         // value we have for the file size limit is acceptable.
       
   285         profilesCenRep->Get( KProEngRingingToneMaxSize, fileSizeLimit ); // codescanner::crepository
       
   286         CleanupStack::PopAndDestroy( profilesCenRep );
       
   287 
       
   288         if ( fileSizeLimit > 0 )
       
   289             {
       
   290             list->SetAttrL( CMediaFileList::EAttrFileSize, fileSizeLimit );
       
   291             }
       
   292         }
       
   293     // Make sure that iOffToneFile is passed, in case iToneFile happens to be KNullDesC
       
   294     ASSERT(!IsEmpty(iToneFile));
       
   295     
       
   296     TBool ok = list->ShowMediaFileListL(&iToneFile, &nullItem,
       
   297                 NULL, NULL );
       
   298     
       
   299     
       
   300     CleanupStack::PopAndDestroy(list);    
       
   301 #endif
       
   302     if( ok )
       
   303         {
       
   304         iAlarmSoundChanged = ETrue;
       
   305         StoreL();
       
   306         UpdateListBoxTextL(); 
       
   307         }
       
   308 
       
   309     
       
   310     TRACE_EXIT_POINT;
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CCalenFileListSettingItem::SettingTextL
       
   315 // returns text for the setting item
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 const TDesC& CCalenFileListSettingItem::SettingTextL()
       
   320     {
       
   321     TRACE_ENTRY_POINT;
       
   322 
       
   323     // empty property string is an error
       
   324     ASSERT(!IsEmpty(iToneFile));
       
   325         
       
   326     if( IsOffTone(iToneFile) )  // no tone selected -> "OFF"
       
   327         {
       
   328         iSettingText.Set( *iToneOffText );
       
   329         }
       
   330     else if( iToneFile.Compare( iDefaultToneFile ) == 0 )  // default tone selected -> "DEFAULT TONE"
       
   331         {
       
   332         iSettingText.Set( *iToneDefaultText );
       
   333         }
       
   334     else  // all other selections
       
   335         {
       
   336         TParsePtrC parse( iToneFile );
       
   337         _LIT( KRngExtension, ".rng" );
       
   338 
       
   339         if( parse.Ext().CompareF( KRngExtension ) == 0 )  // is it a .RNG file
       
   340             {
       
   341             iSettingText.Set( parse.Name() );  // filename without extension
       
   342             } 
       
   343         else 
       
   344             {
       
   345             iSettingText.Set( parse.NameAndExt() );  // filename with extension
       
   346             }
       
   347         }
       
   348         
       
   349     TRACE_EXIT_POINT;
       
   350     return iSettingText;
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CCalenFileListSettingItem::HasPlayRights
       
   355 // ?implementation_description
       
   356 // (other items were commented in a header).
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 TBool CCalenFileListSettingItem::HasPlayRights(TFileName& aFile)
       
   360     {
       
   361     TRACE_ENTRY_POINT;
       
   362 
       
   363     TBool canPlay( ETrue );
       
   364     
       
   365     CData* data = NULL;
       
   366   
       
   367 
       
   368     TVirtualPathPtr virtualPath( aFile, KDefaultContentObject );
       
   369 
       
   370     TRAPD(err,data = CData::NewL( virtualPath, EPlay, EContentShareReadWrite ));
       
   371 
       
   372     if (err!=KErrNone)  
       
   373         {
       
   374         canPlay=EFalse;
       
   375         }
       
   376 
       
   377     delete data;
       
   378     TRACE_EXIT_POINT;
       
   379     return canPlay;
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CCalenFileListSettingItem::UnRegisterSound
       
   384 // ?implementation_description
       
   385 // (other items were commented in a header).
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void CCalenFileListSettingItem::UnRegisterSound(const TFileName& aFile)
       
   389     {
       
   390     TRACE_ENTRY_POINT;
       
   391     
       
   392     CDRMHelper* helper = NULL;
       
   393     TRAPD(err, helper = CDRMHelper::NewL());
       
   394     if(err)
       
   395         {
       
   396         // can't proceed with unregistering
       
   397         return;
       
   398         }
       
   399 
       
   400     // nothing down below leaves. So, no pushing 
       
   401     // helper obj to CS !!
       
   402     TBool automated( EFalse );
       
   403     err = helper->CanSetAutomated( aFile, automated );
       
   404 
       
   405     if( err == KErrNone && automated )
       
   406         {
       
   407         helper->RemoveAutomatedPassive( aFile );
       
   408         }
       
   409 
       
   410     delete helper;
       
   411     helper = NULL;
       
   412     
       
   413     TRACE_EXIT_POINT;
       
   414     }
       
   415 
       
   416 // ----------------------------------------------------
       
   417 // Check, if tone file represents 'Off' choice
       
   418 // We consider KNullDesC and iOffToneFile to be 'Off' choices
       
   419 // ----------------------------------------------------
       
   420 //
       
   421 TBool CCalenFileListSettingItem::IsOffTone(const TDesC& aToneFile) const
       
   422     {
       
   423     TRACE_ENTRY_POINT;
       
   424     
       
   425     TRACE_EXIT_POINT;
       
   426     return (aToneFile == iOffToneFile);
       
   427     }
       
   428 
       
   429 TBool CCalenFileListSettingItem::IsEmpty(const TDesC& aToneFile) const
       
   430     {
       
   431     TRACE_ENTRY_POINT;
       
   432     
       
   433     TRACE_EXIT_POINT;
       
   434     return (aToneFile == KNullDesC);
       
   435     }
       
   436 
       
   437 // End Of File