profilesservices/FileList/Src/CFLDController.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 *     CFLDController observes the list box and invokes a MFLDFileProcessor
       
    16 *     if the timer expires.
       
    17 *
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 //  CLASS HEADER
       
    23 #include "CFLDController.h"
       
    24 
       
    25 //	INTERNAL INCLUDES
       
    26 #include "MFLDFileObserver.h"
       
    27 #include "CFLDRingingTonePlayer.h"
       
    28 
       
    29 #ifdef RD_VIDEO_AS_RINGING_TONE
       
    30 	#include "CFLDVideoPlayer.h"
       
    31 	#include "CFLDSoftKeyChanger.h"
       
    32 #endif
       
    33 
       
    34 //	EXTERNAL INCLUDES
       
    35 #include <bautils.h>
       
    36 #include <data_caging_path_literals.hrh>
       
    37 #include <CLFContentListing.hrh>
       
    38 #include <pathinfo.h>	// For PathInfo
       
    39 
       
    40 #include <caf/caf.h>
       
    41 #include <Oma2Agent.h>
       
    42 
       
    43 
       
    44 // CONSTANTS
       
    45 namespace
       
    46 	{
       
    47 	_LIT( KFLDResourceFileName, "FileList.RSC" );
       
    48 	}
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CFLDController::NewL
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C CFLDController* CFLDController::NewL( TBool aShowErrorMsgs,
       
    58  TTimeIntervalMicroSeconds32 aDelay )
       
    59     {
       
    60     CFLDController* self = CFLDController::NewLC( aShowErrorMsgs, aDelay );
       
    61     CleanupStack::Pop( self ); // self
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CFLDController::NewLC
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CFLDController* CFLDController::NewLC( TBool aShowErrorMsgs,
       
    72  TTimeIntervalMicroSeconds32 aDelay )
       
    73     {
       
    74     CFLDController* self = new( ELeave ) CFLDController( aShowErrorMsgs, aDelay );
       
    75     CleanupStack::PushL( self );
       
    76 
       
    77     self->ConstructL( );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // Destructor
       
    82 EXPORT_C CFLDController::~CFLDController()
       
    83     {
       
    84     iResourceLoader.Close();
       
    85     
       
    86 	Release();
       
    87 
       
    88 	delete iTimer;
       
    89 	delete iAudioProcessor;
       
    90 
       
    91 #ifdef RD_VIDEO_AS_RINGING_TONE
       
    92 	delete iSoftKeyChanger;
       
    93     delete iVideoProcessor;
       
    94 #endif
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CFLDController::Release
       
    99 // (other items were commented in a header).
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CFLDController::Release()
       
   103 	{
       
   104 	iTimer->Cancel();
       
   105 	iAudioProcessor->Cancel();
       
   106 
       
   107 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   108 	iVideoProcessor->Cancel();
       
   109 #endif
       
   110 	}
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CFLDController::CFLDFileListModel
       
   114 // C++ constructor can NOT contain any code, that might leave.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CFLDController::CFLDController( TBool aShowErrorMsgs,
       
   118  TTimeIntervalMicroSeconds32 aDelay )
       
   119     :  iDelay( aDelay ),
       
   120     iShowErrorMsgs( aShowErrorMsgs ),
       
   121     iResourceLoader( *( CCoeEnv::Static() ) )
       
   122     {
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CFLDController::ConstructL
       
   127 // Symbian 2nd phase constructor can leave.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CFLDController::ConstructL()
       
   131     {
       
   132     TFileName* fn = new (ELeave) TFileName
       
   133 		( TParsePtrC( PathInfo::RomRootPath() ).Drive() );
       
   134 	CleanupStack::PushL( fn );
       
   135 
       
   136 	fn->Append( KDC_RESOURCE_FILES_DIR );
       
   137 	fn->Append( KFLDResourceFileName );
       
   138 	iResourceLoader.OpenL( *fn );
       
   139 	CleanupStack::PopAndDestroy( fn );
       
   140 		
       
   141     iTimer = CPeriodic::NewL( EPriorityNormal );
       
   142     iAudioProcessor = CFLDRingingTonePlayer::NewL( iShowErrorMsgs );
       
   143     
       
   144 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   145 	iVideoProcessor = CFLDVideoPlayer::NewL( iShowErrorMsgs );
       
   146     iSoftKeyChanger = CFLDSoftKeyChanger::NewL();
       
   147 #endif
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CFLDController::CompleteConstructionL()
       
   152 // (other items were commented in a header).
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CFLDController::CompleteConstructionL( RWindow& aWindow )
       
   156 	{
       
   157 	iWindow = &aWindow;
       
   158 	}
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CFLDController::SetDelay()
       
   162 // (other items were commented in a header).
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void CFLDController::SetDelay( TTimeIntervalMicroSeconds32 aDelay )
       
   166     {
       
   167     iDelay = aDelay;
       
   168     }
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CFLDController::SetVolume()
       
   173 // (other items were commented in a header).
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 EXPORT_C void CFLDController::SetVolume( TInt aVolume )
       
   177     {
       
   178    	iRingingVolume = aVolume;
       
   179    	iAudioProcessor->SetVolume( iRingingVolume );
       
   180 
       
   181 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   182  	iVideoProcessor->SetVolume( iRingingVolume );
       
   183 #endif
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CFLDController::SetRingingType()
       
   188 // (other items were commented in a header).
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 EXPORT_C void CFLDController::SetRingingType( TInt aRingingType )
       
   192     {
       
   193   	iRingingType = aRingingType;
       
   194  	iAudioProcessor->SetRingingType( iRingingType );
       
   195 
       
   196 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   197  	iVideoProcessor->SetRingingType( iRingingType );
       
   198 #endif
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CFLDController::SetVibra()
       
   203 // (other items were commented in a header).
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 EXPORT_C void CFLDController::SetVibra( TBool aVibra )
       
   207     {
       
   208     iVibra = aVibra;
       
   209     iAudioProcessor->SetVibra( iVibra );
       
   210 
       
   211 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   212    	iVideoProcessor->SetVibra( iVibra );
       
   213 #endif
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CFLDController::SetFileObserver()
       
   218 // (other items were commented in a header).
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C void CFLDController::SetFileObserver( MFLDFileObserver* aFileObserver )
       
   222 	{
       
   223 	iFileObserver = aFileObserver;
       
   224 	}
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CFLDController::Set3dEffects()
       
   228 // (other items were commented in a header).
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 EXPORT_C void CFLDController::Set3dEffects( TBool a3dEffects )
       
   232 	{
       
   233 	i3dEffects = a3dEffects;
       
   234 	iAudioProcessor->Set3dEffects( i3dEffects );
       
   235 	}
       
   236 	
       
   237 // -----------------------------------------------------------------------------
       
   238 // CFLDController::HandleSoftKeyState()
       
   239 // (other items were commented in a header).
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void CFLDController::HandleSoftKeyState( TFileListSoftKeyState& aSoftKeyState )
       
   243 	{
       
   244 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   245 	aSoftKeyState = iSoftKeyChanger->SoftKeyState();
       
   246 #else
       
   247 	aSoftKeyState = EToneSelectionSoftKeyState;	// Just remove compiler warnings
       
   248 #endif
       
   249 	}
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CFLDController::HandleFileListBoxEventL()
       
   253 // (other items were commented in a header).
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 EXPORT_C void CFLDController::HandleFileListBoxEventL( TFileListBoxEvent aEvent,
       
   257                                                    const TDesC& aFileName )
       
   258     {
       
   259     iCurrentFile = aFileName;
       
   260 
       
   261     switch( aEvent )
       
   262     	{
       
   263     	// User changes focus in tonelist
       
   264     	case EFocusChanged:
       
   265     		{
       
   266 			Release();
       
   267 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   268 			iSoftKeyChanger->RestoreOldToneSelectionSoftKeysL();
       
   269 #endif
       
   270 
       
   271     		if( iDelay >= TTimeIntervalMicroSeconds32( 0 ) )
       
   272     			{
       
   273     			iTimer->Start( iDelay, iDelay, TCallBack( HandleTimerTickL, this ) ); // CSI: 10 # iTimer is cancelled in Release()
       
   274     			}
       
   275     		break;
       
   276     		}
       
   277 
       
   278 		// Some other key was pressed than softkeys
       
   279     	case EOtherKeyEvent:
       
   280     		{
       
   281 			Release();
       
   282 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   283 			iSoftKeyChanger->RestoreOldToneSelectionSoftKeysL();
       
   284 #endif
       
   285     		break;
       
   286     		}
       
   287 
       
   288 		// User selects the video or audio as ringingtone in tonelist
       
   289 		case EListBoxClosed:
       
   290 			{
       
   291 			Release();
       
   292 
       
   293     		if( iDelay >= TTimeIntervalMicroSeconds32( 0 ) )
       
   294     			{
       
   295     			iTimer->Start( iDelay, iDelay, TCallBack( HandleTimerTickL, this ) ); // CSI: 10 # iTimer is cancelled in Release()
       
   296     			}
       
   297     		break;
       
   298 			}
       
   299 
       
   300 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   301 		// Video has been focused for 1s and preview cba is selected
       
   302     	case EVideoPreview:
       
   303     		{
       
   304 			Release();
       
   305 			iSoftKeyChanger->ChangeNewSoftKeysPreviewL();
       
   306 			if( iRingingType != ERingingTypeBeepOnce )
       
   307 				{
       
   308 				iVideoProcessor->ProcessFileL( iCurrentFile, iWindow );
       
   309 				}
       
   310 			else
       
   311 				{
       
   312 				// BeebOnce
       
   313 				iAudioProcessor->ProcessFileL( iCurrentFile, NULL );
       
   314 				iVideoProcessor->ProcessFileL( iCurrentFile, iWindow );
       
   315 				}
       
   316 			iSoftKeyChanger->ChangeNewSoftKeysPreviewSelectL();
       
   317 			break;
       
   318     		}
       
   319 
       
   320 
       
   321 		// Video is running in preview window and user has selected it
       
   322     	case EVideoPreviewSelected:
       
   323     		{
       
   324     		// Cleanup is done in destructor
       
   325     		break;
       
   326     		}
       
   327 
       
   328 		// Video is running in preview window and user has canceled it
       
   329     	case EVideoPreviewCanceled:
       
   330     		{
       
   331             // Only cancel and restore softkeys if video is being previewed
       
   332             if( iSoftKeyChanger->SoftKeyState() == EPreviewSelectSoftKeyState )
       
   333                 {
       
   334                 Release();
       
   335                 iSoftKeyChanger->RestoreOldToneSelectionSoftKeysL();
       
   336                 }
       
   337 			break;
       
   338     		}
       
   339 #endif
       
   340 
       
   341     	default:
       
   342     		{
       
   343     		break;
       
   344     		}
       
   345 
       
   346     	};
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CFLDController::HandleTimerTickL()
       
   351 // (other items were commented in a header).
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 TInt CFLDController::HandleTimerTickL( TAny* aPtr )
       
   355     {
       
   356     CFLDController* controller = reinterpret_cast< CFLDController* >( aPtr );
       
   357     controller->iTimer->Cancel();
       
   358 
       
   359 #ifdef RD_VIDEO_AS_RINGING_TONE
       
   360 	TBool isVideo( EFalse );
       
   361 	if( controller->iFileObserver )
       
   362 		{
       
   363 		if( controller->iFileObserver->MediaFileType(
       
   364 		 controller->iCurrentFile ) == ECLFMediaTypeVideo )
       
   365 			{
       
   366 			isVideo = ETrue;
       
   367 			}
       
   368 		}
       
   369 
       
   370 	if( isVideo )
       
   371 		{
       
   372 		// File is video
       
   373 		// If it is OMA DRM 2 protected, it cannot be previewed in FileList (yet)
       
   374 		using namespace ContentAccess;
       
   375 	   	CContent* content = CContent::NewLC( controller->iCurrentFile,
       
   376 	   										 EContentShareReadWrite );
       
   377 	   	TInt deliveryMethod = 0;
       
   378 	   	content->GetAttribute( EDeliveryMethod, deliveryMethod );
       
   379 	   	CleanupStack::PopAndDestroy(); // content
       
   380 	   	if( deliveryMethod != EOmaDrm2 )
       
   381 	   		{
       
   382 	   		// Change softkeys for preview
       
   383 		 	controller->iSoftKeyChanger->ChangeNewSoftKeysPreviewL();
       
   384 	   		}
       
   385 		}
       
   386 	 else
       
   387 	 	{
       
   388 	 	// File is audio
       
   389  		if( ( controller->iFileObserver &&
       
   390 			!controller->iFileObserver->IsFileValidL(
       
   391         	controller->iCurrentFile, MFLDFileObserver::EPlay ) ) )
       
   392 			{
       
   393 			// If there is a file observer and the file is not valid,
       
   394 			// don't call ProcessFileL.
       
   395 			return 0;
       
   396 			}
       
   397 		controller->iAudioProcessor->ProcessFileL( controller->iCurrentFile, NULL );
       
   398 	 	}
       
   399 #else
       
   400 	if( ( controller->iFileObserver &&
       
   401 		!controller->iFileObserver->IsFileValidL(
       
   402         controller->iCurrentFile, MFLDFileObserver::EPlay ) ) )
       
   403 		{
       
   404 		// If there is a file observer and the file is not valid,
       
   405 		// don't call ProcessFileL.
       
   406 		return 0;
       
   407 		}
       
   408 	controller->iAudioProcessor->ProcessFileL( controller->iCurrentFile, NULL );
       
   409 #endif
       
   410 
       
   411     return 0;
       
   412     }
       
   413 
       
   414 //  End of File