profilesservices/FileList/Src/CFLDFileListContainer.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     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: 
       
    15 *     A wrapper class, which is part of an example implementation of tone
       
    16 *     selection list. It owns the list box, the model, and the controller,
       
    17 *     and it is used to launch the popup list.
       
    18 *     If you need to use a different list box style or a different file,
       
    19 *     processor replace this class with your own container.
       
    20 *
       
    21 *
       
    22 */
       
    23 
       
    24 
       
    25 // CLASS HEADER
       
    26 #include "CFLDFileListContainer.h"
       
    27 
       
    28 // INTERNAL INCLUDES
       
    29 #include "CFLDPopupList.h"
       
    30 #include "CFLDDRMImplementation.h"
       
    31 #include "CFLDBrowserLauncher.h"
       
    32 #include "CFLDSingleGraphicEntryFormatter.h"
       
    33 #include "FLDListBoxTemplate.h"
       
    34 #include "CFLDController.h"
       
    35 #include "CFLDFileListModel.h"
       
    36 
       
    37 // EXTERNAL INCLUDES
       
    38 #include <ConeResLoader.h>
       
    39 #include <StringLoader.h>
       
    40 #include <filelist.rsg>
       
    41 #include <featmgr.h>
       
    42 #include <pathinfo.h>
       
    43 #include <centralrepository.h>
       
    44 #include <ProfileEngineInternalCRKeys.h> // Profiles engine internal Central Repository keys
       
    45 #include <aknlists.h>
       
    46 
       
    47 // CONSTANTS
       
    48 namespace
       
    49 	{
       
    50 	// MIME types
       
    51 	_LIT( KFLDAMRMimeType, "audio/amr" );
       
    52 #ifndef __WMA
       
    53 	_LIT( KFLDAudioWMA, "audio/x-ms-wma" );
       
    54 #endif
       
    55 
       
    56     _LIT( KFLDResourceFileName, "FileList.RSC" );
       
    57 
       
    58 	// Default delay 1000000 = 1sec
       
    59 	const TInt KDefaultDelay( 1000000 );
       
    60 	}
       
    61 
       
    62 // ============================ MEMBER FUNCTIONS ===============================
       
    63 
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CFLDFileListContainer::NewL
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C CFLDFileListContainer* CFLDFileListContainer::NewL()
       
    71     {
       
    72     CFLDFileListContainer* self = CFLDFileListContainer::NewLC();
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CFLDFileListContainer::NewLC
       
    79 // Two-phased constructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C CFLDFileListContainer* CFLDFileListContainer::NewLC()
       
    83     {
       
    84     CFLDFileListContainer* self =
       
    85         new( ELeave ) CFLDFileListContainer();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL( R_FLD_LIST_MODEL, R_FLD_DIRECTORIES );
       
    88     return self;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CFLDFileListContainer::NewL
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C CFLDFileListContainer* CFLDFileListContainer::NewL(
       
    97     const TInt aResourceId )
       
    98     {
       
    99     CFLDFileListContainer* self = CFLDFileListContainer::NewLC(
       
   100         aResourceId, R_FLD_DIRECTORIES );
       
   101     CleanupStack::Pop( self );
       
   102     return self;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CFLDFileListContainer::NewLC
       
   107 // Two-phased constructor.
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C CFLDFileListContainer* CFLDFileListContainer::NewLC(
       
   111     const TInt aResourceId )
       
   112     {
       
   113     CFLDFileListContainer* self =
       
   114         new( ELeave ) CFLDFileListContainer();
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL( aResourceId, R_FLD_DIRECTORIES );
       
   117     return self;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CFLDFileListContainer::NewL
       
   122 // Two-phased constructor.
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 EXPORT_C CFLDFileListContainer* CFLDFileListContainer::NewL(
       
   126     const TInt aResourceId, const TInt aDirectoriesResourceId )
       
   127     {
       
   128     CFLDFileListContainer* self = CFLDFileListContainer::NewLC(
       
   129         aResourceId, aDirectoriesResourceId );
       
   130     CleanupStack::Pop( self );
       
   131     return self;
       
   132     }
       
   133     
       
   134 // -----------------------------------------------------------------------------
       
   135 // CFLDFileListContainer::NewLC
       
   136 // Two-phased constructor.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C CFLDFileListContainer* CFLDFileListContainer::NewLC(
       
   140     const TInt aResourceId, const TInt aDirectoriesResourceId )
       
   141     {
       
   142     CFLDFileListContainer* self =
       
   143         new( ELeave ) CFLDFileListContainer();
       
   144     CleanupStack::PushL( self );
       
   145     self->ConstructL( aResourceId, aDirectoriesResourceId );
       
   146     return self;
       
   147     }
       
   148     
       
   149 // Destructor
       
   150 EXPORT_C CFLDFileListContainer::~CFLDFileListContainer()
       
   151     {
       
   152     iResourceLoader.Close();
       
   153     
       
   154     delete iDRMImplementation;
       
   155     delete iModel;
       
   156     delete iController;
       
   157     FeatureManager::UnInitializeLib();
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CFLDFileListContainer::CFLDFileListContainer
       
   162 // C++ constructor can NOT contain any code, that might leave.
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 CFLDFileListContainer::CFLDFileListContainer()
       
   166 	: iResourceLoader( *( CCoeEnv::Static() ) )
       
   167     {
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CFLDFileListContainer::ConstructL
       
   172 // Symbian 2nd phase constructor can leave.
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CFLDFileListContainer::ConstructL(
       
   176  const TInt aResourceId, const TInt aDirectoriesResourceId )
       
   177     {
       
   178     // Open Filelist default resource
       
   179 	TFileName* fn = new (ELeave) TFileName
       
   180 		( TParsePtrC( PathInfo::RomRootPath() ).Drive() );
       
   181 	CleanupStack::PushL( fn );
       
   182 
       
   183 	fn->Append( KDC_RESOURCE_FILES_DIR );
       
   184 	fn->Append( KFLDResourceFileName );
       
   185 	iResourceLoader.OpenL( *fn );
       
   186 	CleanupStack::PopAndDestroy( fn );
       
   187 
       
   188     iModel = CFLDFileListModel::NewL( aResourceId, aDirectoriesResourceId );
       
   189     CFLDSingleGraphicEntryFormatter* entryFormatter =
       
   190     	new ( ELeave ) CFLDSingleGraphicEntryFormatter();
       
   191     iModel->SetEntryFormatter( entryFormatter );
       
   192 
       
   193 	// Add 'download tones' item to model
       
   194     FeatureManager::InitializeLibL();
       
   195  	if( FeatureManager::FeatureSupported( KFeatureIdSeamlessLinks ) )
       
   196         {
       
   197         // Load 'download tones' text and format it
       
   198 		HBufC* text = StringLoader::LoadLC(
       
   199 			R_FLD_QTN_PROFILES_DOWNLOAD_TONES );
       
   200 		_LIT( KIconIndexAndTab, "1\t" );
       
   201         HBufC* newText =
       
   202             text->ReAllocL( text->Length() + KIconIndexAndTab().Length() );
       
   203         CleanupStack::Pop( text );
       
   204         CleanupStack::PushL( newText );
       
   205         TPtr des( newText->Des() );
       
   206         des.Insert( 0, KIconIndexAndTab );
       
   207 		// Insert formatted 'download tones' text to model
       
   208         iModel->InsertNullItemL( des, KNullDesC );
       
   209         CleanupStack::PopAndDestroy( newText );
       
   210         }
       
   211 
       
   212 	iDRMImplementation = CFLDDRMImplementation::NewL( iModel );
       
   213 
       
   214 	TBool showErrorMsgs( ETrue );
       
   215     iController = CFLDController::NewL( showErrorMsgs, KDefaultDelay );
       
   216  	iController->SetFileObserver( iDRMImplementation );
       
   217 
       
   218 	// Following implementation enables disabling recordable ringing tones.
       
   219 	TInt recEnable( 0 );
       
   220 	CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine );
       
   221     CleanupStack::PushL( cenrep );
       
   222     User::LeaveIfError( cenrep->Get( KProEngRecordedRingingTones, recEnable ) );
       
   223     CleanupStack::PopAndDestroy( cenrep );
       
   224 
       
   225     if( !recEnable )
       
   226         {
       
   227         // Recorded tones as ringing tones should be disabled.
       
   228         // Exclude AMR files.
       
   229         iModel->AddExclusiveMimeTypeL( KFLDAMRMimeType );
       
   230         }
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CFLDFileListContainer::SetAutomatedType()
       
   235 // (other items were commented in a header).
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C void CFLDFileListContainer::SetAutomatedType(
       
   239  CDRMHelper::TDRMHelperAutomatedType aAutomatedType )
       
   240 	{
       
   241 	iDRMImplementation->SetAutomatedType( aAutomatedType );
       
   242 	}
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CFLDFileListContainer::LaunchL()
       
   246 // (other items were commented in a header).
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C TBool CFLDFileListContainer::LaunchL( TDes& aFileName, const TDesC& aPopupTitle )
       
   250     {
       
   251     // Update the list
       
   252 	iModel->RefreshEntryListL();
       
   253 
       
   254     CEikFormattedCellListBox* listBox = NULL;
       
   255         listBox = new( ELeave ) FLDListBoxTemplate
       
   256         	<CAknSingleGraphicBtPopupMenuStyleListBox>( *iController, *iModel );
       
   257     CleanupStack::PushL( listBox );
       
   258 
       
   259     // Create the popup list
       
   260     CFLDPopupList* popup = CFLDPopupList::NewL( listBox,
       
   261         R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT,
       
   262         *iDRMImplementation, iController,
       
   263         *iModel, AknPopupLayouts::EMenuGraphicWindow );
       
   264     // EMenuGraphicWindow for CAknSingleGraphicBtPopupMenuStyleListBox
       
   265     CleanupStack::PushL( popup );
       
   266 
       
   267 	static_cast<FLDListBoxTemplate
       
   268 		 <CAknSingleGraphicBtPopupMenuStyleListBox> *>( listBox )
       
   269 		 ->SetListBox( popup );
       
   270 
       
   271 	// Video player can be fully constructed only when popup list
       
   272 	// is constructed
       
   273 	iController->CompleteConstructionL( popup->PopupListWindow() );
       
   274 
       
   275 	// Set popup to Model
       
   276 	iModel->SetPopupList( popup );
       
   277 
       
   278     popup->SetTitleL( aPopupTitle );
       
   279 
       
   280     listBox->ConstructL( popup,
       
   281         EAknListBoxSelectionList | EAknListBoxLoopScrolling );
       
   282 
       
   283     // Create the scroll indicator
       
   284     listBox->CreateScrollBarFrameL( ETrue );
       
   285     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   286         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   287 
       
   288     // Set the listbox to use the the file list model
       
   289     listBox->Model()->SetItemTextArray( iModel );
       
   290     listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   291 
       
   292     // Refresh the listbox due to model change
       
   293     listBox->HandleItemAdditionL();
       
   294 
       
   295 	popup->PopulateIconArrayL();
       
   296 
       
   297     // If a filename was given, set focus on it
       
   298     if ( aFileName != KNullDesC )
       
   299         {
       
   300         TInt index = iModel->FindFileL( aFileName );
       
   301         if ( index != KErrNotFound )
       
   302             {
       
   303             listBox->SetCurrentItemIndex( index );
       
   304             }
       
   305         }
       
   306 
       
   307     popup->ListBox()->DisableSingleClick(ETrue);
       
   308     TBool result = popup->ExecuteLD();
       
   309 	// Note, CAknPopupList must NOT be popped out
       
   310 	// before ExecuteLD (like dialogs do) but after.
       
   311     CleanupStack::Pop( popup );
       
   312 
       
   313 	// Reset popup pointer
       
   314 	iModel->SetPopupList( NULL );
       
   315 
       
   316     if ( result )
       
   317         {
       
   318         TInt selectedIndex( listBox->CurrentItemIndex() );
       
   319 
       
   320 		// Check if the selected item is 'Download tones' or regular ringingtone
       
   321 		TFileName selectedFileName( KNullDesC );
       
   322 		iModel->GetFileName( selectedFileName, selectedIndex );
       
   323 
       
   324         // If there is such a model that has no 'Download tones' item but
       
   325         // seamless links are supported, we have to check that selectedFileName
       
   326         // is really ringingtone (it is not a null item)
       
   327         if( selectedIndex == 0 &&
       
   328             FeatureManager::FeatureSupported( KFeatureIdSeamlessLinks ) &&
       
   329             selectedFileName.Length() == 0 )
       
   330             {
       
   331             // User selected the first item "Download tones". Launch browser.
       
   332             CFLDBrowserLauncher* launcher = CFLDBrowserLauncher::NewLC();
       
   333             launcher->LaunchBrowserL();
       
   334             CleanupStack::PopAndDestroy(); // launcher
       
   335             result = EFalse; // No tone was selected
       
   336             }
       
   337         else
       
   338             {
       
   339             // Any other choice. Copy selected file name to aFileName.
       
   340             iModel->GetFileName( aFileName, selectedIndex );
       
   341             }
       
   342         }
       
   343 
       
   344     CleanupStack::PopAndDestroy(); // listBox
       
   345 
       
   346     return result;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CFLDFileListContainer::InsertNullItemL()
       
   351 // (other items were commented in a header).
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 EXPORT_C void CFLDFileListContainer::InsertNullItemL(
       
   355  const TDesC& aItemText )
       
   356     {
       
   357     iModel->InsertNullItemL( aItemText );
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CFLDFileListContainer::InsertNullItemL()
       
   362 // (other items were commented in a header).
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 EXPORT_C void CFLDFileListContainer::InsertNullItemL(
       
   366  const TDesC& aItemText, const TDesC& aFileName )
       
   367     {
       
   368     iModel->InsertNullItemL( aItemText, aFileName );
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CFLDFileListContainer::InsertEndNullItemL()
       
   373 // (other items were commented in a header).
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 EXPORT_C void CFLDFileListContainer::InsertEndNullItemL(
       
   377  const TDesC& aItemText )
       
   378     {
       
   379     iModel->InsertEndNullItemL( aItemText );
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CFLDFileListContainer::InsertEndNullItemL()
       
   384 // (other items were commented in a header).
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 EXPORT_C void CFLDFileListContainer::InsertEndNullItemL(
       
   388  const TDesC& aItemText, const TDesC& aFileName )
       
   389     {
       
   390     iModel->InsertEndNullItemL( aItemText, aFileName );
       
   391     }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CFLDFileListContainer::SetDelay()
       
   395 // (other items were commented in a header).
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 EXPORT_C void CFLDFileListContainer::SetDelay( TTimeIntervalMicroSeconds32 aDelay )
       
   399     {
       
   400     iController->SetDelay( aDelay );
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CFLDFileListContainer::SetVolume()
       
   405 // (other items were commented in a header).
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 EXPORT_C void CFLDFileListContainer::SetVolume( TInt aVolume )
       
   409     {
       
   410     iController->SetVolume( aVolume );
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CFLDFileListContainer::SetRingingType()
       
   415 // (other items were commented in a header).
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 EXPORT_C void CFLDFileListContainer::SetRingingType( TInt aRingingType )
       
   419     {
       
   420     iController->SetRingingType( aRingingType );
       
   421     }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CFLDFileListContainer::SetVibra()
       
   425 // (other items were commented in a header).
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 EXPORT_C void CFLDFileListContainer::SetVibra( TBool aVibra )
       
   429     {
       
   430     iController->SetVibra( aVibra );
       
   431     }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // CFLDFileListContainer::Set3dEffects()
       
   435 // (other items were commented in a header).
       
   436 // -----------------------------------------------------------------------------
       
   437 //    
       
   438 EXPORT_C void CFLDFileListContainer::Set3dEffects( TBool a3dEffects )
       
   439 	{
       
   440 	iController->Set3dEffects( a3dEffects );
       
   441 	}
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // CFLDFileListContainer::AddExclusiveMimeTypeL()
       
   445 // (other items were commented in a header).
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 EXPORT_C void CFLDFileListContainer::AddExclusiveMimeTypeL( const TDesC& aMimeType )
       
   449 	{
       
   450 	iModel->AddExclusiveMimeTypeL( aMimeType );
       
   451 	}
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CFLDFileListContainer::AddExclusiveMediaTypeL()
       
   455 // (other items were commented in a header).
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 EXPORT_C void CFLDFileListContainer::AddExclusiveMediaTypeL( const TInt32 aMediaType )
       
   459 	{
       
   460 	iModel->AddExclusiveMediaTypeL( aMediaType );
       
   461 	}
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CFLDFileListContainer::SetWantedMimeTypesL()
       
   465 // (other items were commented in a header).
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 EXPORT_C void CFLDFileListContainer::SetWantedMimeTypesL( const MDesCArray& aMimeTypes )
       
   469 	{
       
   470 	iModel->SetWantedMimeTypesL( aMimeTypes );
       
   471 	}
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // CFLDFileListContainer::SetWantedMediaTypesL()
       
   475 // (other items were commented in a header).
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 EXPORT_C void CFLDFileListContainer::SetWantedMediaTypesL( const TArray<TCLFMediaType>& aMediaTypes )
       
   479 	{
       
   480 	iModel->SetWantedMediaTypesL( aMediaTypes );
       
   481 	}
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CFLDFileListContainer::SetWantedMimeTypesL()
       
   485 // (other items were commented in a header).
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 EXPORT_C void CFLDFileListContainer::ResetExclusiveMimeTypes()
       
   489 	{
       
   490 	iModel->ResetExclusiveMimeTypes();
       
   491 	}
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CFLDFileListContainer::SetWantedMimeTypesL()
       
   495 // (other items were commented in a header).
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 EXPORT_C void CFLDFileListContainer::ResetExclusiveMediaTypes()
       
   499 	{
       
   500 	iModel->ResetExclusiveMediaTypes();
       
   501 	}
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CFLDFileListContainer::SetMaxFileSize()
       
   505 // (other items were commented in a header).
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 EXPORT_C void CFLDFileListContainer::SetMaxFileSize( const TInt aMaxFileSize )
       
   509     {
       
   510     iModel->SetMaxFileSize( aMaxFileSize );
       
   511     }	
       
   512 
       
   513 
       
   514 //  End of File