profilesservices/FileList/Src/CFLDFileListContainer.cpp
changeset 0 8c5d936e5675
child 25 3b47783fdf16
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     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     TBool result = popup->ExecuteLD();
       
   308 	// Note, CAknPopupList must NOT be popped out
       
   309 	// before ExecuteLD (like dialogs do) but after.
       
   310     CleanupStack::Pop( popup );
       
   311 
       
   312 	// Reset popup pointer
       
   313 	iModel->SetPopupList( NULL );
       
   314 
       
   315     if ( result )
       
   316         {
       
   317         TInt selectedIndex( listBox->CurrentItemIndex() );
       
   318 
       
   319 		// Check if the selected item is 'Download tones' or regular ringingtone
       
   320 		TFileName selectedFileName( KNullDesC );
       
   321 		iModel->GetFileName( selectedFileName, selectedIndex );
       
   322 
       
   323         // If there is such a model that has no 'Download tones' item but
       
   324         // seamless links are supported, we have to check that selectedFileName
       
   325         // is really ringingtone (it is not a null item)
       
   326         if( selectedIndex == 0 &&
       
   327             FeatureManager::FeatureSupported( KFeatureIdSeamlessLinks ) &&
       
   328             selectedFileName.Length() == 0 )
       
   329             {
       
   330             // User selected the first item "Download tones". Launch browser.
       
   331             CFLDBrowserLauncher* launcher = CFLDBrowserLauncher::NewLC();
       
   332             launcher->LaunchBrowserL();
       
   333             CleanupStack::PopAndDestroy(); // launcher
       
   334             result = EFalse; // No tone was selected
       
   335             }
       
   336         else
       
   337             {
       
   338             // Any other choice. Copy selected file name to aFileName.
       
   339             iModel->GetFileName( aFileName, selectedIndex );
       
   340             }
       
   341         }
       
   342 
       
   343     CleanupStack::PopAndDestroy(); // listBox
       
   344 
       
   345     return result;
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CFLDFileListContainer::InsertNullItemL()
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C void CFLDFileListContainer::InsertNullItemL(
       
   354  const TDesC& aItemText )
       
   355     {
       
   356     iModel->InsertNullItemL( aItemText );
       
   357     }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // CFLDFileListContainer::InsertNullItemL()
       
   361 // (other items were commented in a header).
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 EXPORT_C void CFLDFileListContainer::InsertNullItemL(
       
   365  const TDesC& aItemText, const TDesC& aFileName )
       
   366     {
       
   367     iModel->InsertNullItemL( aItemText, aFileName );
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CFLDFileListContainer::InsertEndNullItemL()
       
   372 // (other items were commented in a header).
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 EXPORT_C void CFLDFileListContainer::InsertEndNullItemL(
       
   376  const TDesC& aItemText )
       
   377     {
       
   378     iModel->InsertEndNullItemL( aItemText );
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CFLDFileListContainer::InsertEndNullItemL()
       
   383 // (other items were commented in a header).
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 EXPORT_C void CFLDFileListContainer::InsertEndNullItemL(
       
   387  const TDesC& aItemText, const TDesC& aFileName )
       
   388     {
       
   389     iModel->InsertEndNullItemL( aItemText, aFileName );
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CFLDFileListContainer::SetDelay()
       
   394 // (other items were commented in a header).
       
   395 // -----------------------------------------------------------------------------
       
   396 //
       
   397 EXPORT_C void CFLDFileListContainer::SetDelay( TTimeIntervalMicroSeconds32 aDelay )
       
   398     {
       
   399     iController->SetDelay( aDelay );
       
   400     }
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CFLDFileListContainer::SetVolume()
       
   404 // (other items were commented in a header).
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 EXPORT_C void CFLDFileListContainer::SetVolume( TInt aVolume )
       
   408     {
       
   409     iController->SetVolume( aVolume );
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CFLDFileListContainer::SetRingingType()
       
   414 // (other items were commented in a header).
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 EXPORT_C void CFLDFileListContainer::SetRingingType( TInt aRingingType )
       
   418     {
       
   419     iController->SetRingingType( aRingingType );
       
   420     }
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // CFLDFileListContainer::SetVibra()
       
   424 // (other items were commented in a header).
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 EXPORT_C void CFLDFileListContainer::SetVibra( TBool aVibra )
       
   428     {
       
   429     iController->SetVibra( aVibra );
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CFLDFileListContainer::Set3dEffects()
       
   434 // (other items were commented in a header).
       
   435 // -----------------------------------------------------------------------------
       
   436 //    
       
   437 EXPORT_C void CFLDFileListContainer::Set3dEffects( TBool a3dEffects )
       
   438 	{
       
   439 	iController->Set3dEffects( a3dEffects );
       
   440 	}
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CFLDFileListContainer::AddExclusiveMimeTypeL()
       
   444 // (other items were commented in a header).
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 EXPORT_C void CFLDFileListContainer::AddExclusiveMimeTypeL( const TDesC& aMimeType )
       
   448 	{
       
   449 	iModel->AddExclusiveMimeTypeL( aMimeType );
       
   450 	}
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CFLDFileListContainer::AddExclusiveMediaTypeL()
       
   454 // (other items were commented in a header).
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 EXPORT_C void CFLDFileListContainer::AddExclusiveMediaTypeL( const TInt32 aMediaType )
       
   458 	{
       
   459 	iModel->AddExclusiveMediaTypeL( aMediaType );
       
   460 	}
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CFLDFileListContainer::SetWantedMimeTypesL()
       
   464 // (other items were commented in a header).
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 EXPORT_C void CFLDFileListContainer::SetWantedMimeTypesL( const MDesCArray& aMimeTypes )
       
   468 	{
       
   469 	iModel->SetWantedMimeTypesL( aMimeTypes );
       
   470 	}
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CFLDFileListContainer::SetWantedMediaTypesL()
       
   474 // (other items were commented in a header).
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 EXPORT_C void CFLDFileListContainer::SetWantedMediaTypesL( const TArray<TCLFMediaType>& aMediaTypes )
       
   478 	{
       
   479 	iModel->SetWantedMediaTypesL( aMediaTypes );
       
   480 	}
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // CFLDFileListContainer::SetWantedMimeTypesL()
       
   484 // (other items were commented in a header).
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 EXPORT_C void CFLDFileListContainer::ResetExclusiveMimeTypes()
       
   488 	{
       
   489 	iModel->ResetExclusiveMimeTypes();
       
   490 	}
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CFLDFileListContainer::SetWantedMimeTypesL()
       
   494 // (other items were commented in a header).
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 EXPORT_C void CFLDFileListContainer::ResetExclusiveMediaTypes()
       
   498 	{
       
   499 	iModel->ResetExclusiveMediaTypes();
       
   500 	}
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CFLDFileListContainer::SetMaxFileSize()
       
   504 // (other items were commented in a header).
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 EXPORT_C void CFLDFileListContainer::SetMaxFileSize( const TInt aMaxFileSize )
       
   508     {
       
   509     iModel->SetMaxFileSize( aMaxFileSize );
       
   510     }	
       
   511 
       
   512 
       
   513 //  End of File