coreapplicationuis/accfwuinotifier/src/AccFwUiDialogNotifier.cpp
changeset 56 11a052f4b02e
parent 49 76883296a0d5
child 65 8a530a83576a
equal deleted inserted replaced
49:76883296a0d5 56:11a052f4b02e
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Implementation of Accessory selection dialog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AccFwUiDialogNotifier.h"
       
    21 #include "acc_debug.h"
       
    22 
       
    23 #include <featmgr.h>
       
    24 #include <SecondaryDisplay/SecondaryDisplayAccFwAPI.h>
       
    25 #include <accfwnoteuinotifier.rsg>
       
    26 #include <aknlistquerydialog.h> 
       
    27 #include <aknlists.h> 
       
    28 #include <bautils.h>
       
    29 #include <data_caging_path_literals.hrh> 
       
    30 
       
    31 // EXTERNAL DATA STRUCTURES
       
    32 
       
    33 // EXTERNAL FUNCTION PROTOTYPES
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 const TUid KScreenOutputChannel = { 0x10282E0A };
       
    38 _LIT(KAccFwUiNotifierResource, "accfwnoteuinotifier.rsc"); 
       
    39 
       
    40 
       
    41 // MACROS
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS ===============================
       
    52    
       
    53 // ============================ MEMBER FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CAccFwUiDialogNotifier::CAccFwUiDialogNotifier()
       
    57 // C++ default constructor can NOT contain any code, that
       
    58 // might leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CAccFwUiDialogNotifier::CAccFwUiDialogNotifier()	
       
    62 	: CActive( EPriorityStandard)
       
    63     {
       
    64     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::CAccFwUiDialogNotifier() - enter" );
       
    65     
       
    66     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::CAccFwUiDialogNotifier() - return void" );
       
    67     }
       
    68    
       
    69 // Destructor
       
    70 CAccFwUiDialogNotifier::~CAccFwUiDialogNotifier()
       
    71     {
       
    72     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::~CAccFwUiDialogNotifier() - enter" );
       
    73 	
       
    74 	delete iDialog;
       
    75 	delete iCoverUIITems;
       
    76     iSelections.Close();
       
    77     CActive::Cancel();
       
    78 
       
    79     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccPolAccessoryPolicy::~CAccFwUiDialogNotifier() - return void" );
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CAccFwUiDialogNotifier::ConstructL()
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CAccFwUiDialogNotifier::ConstructL()
       
    88     {
       
    89     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::ConstructL() - enter" );
       
    90     
       
    91     iErr = KErrNone;
       
    92     
       
    93     //get pointer to CEikonEnv
       
    94 	iCoeEnv = CEikonEnv::Static();    
       
    95     
       
    96     if ( !iCoeEnv )
       
    97         {
       
    98         User::Leave( KErrGeneral );        
       
    99         }
       
   100     
       
   101     iLockKeys = ETrue;
       
   102     
       
   103 	//Open resource file
       
   104     TFileName fileName;
       
   105     fileName.Zero();
       
   106 
       
   107     TFileName drivePath;
       
   108     Dll::FileName( drivePath );
       
   109 
       
   110     fileName.Append( TParsePtrC( drivePath ).Drive() );
       
   111     fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   112     fileName.Append( KAccFwUiNotifierResource );
       
   113     
       
   114     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   115 
       
   116 	//handle to resource file
       
   117     iResourceFileOffset = iCoeEnv->AddResourceFileL( fileName );
       
   118 
       
   119 	//add to scheduler
       
   120     CActiveScheduler::Add( this );
       
   121     
       
   122     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::ConstructL() - return void" );
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CAccFwUiDialogNotifier::NewL()
       
   127 // Two-phased constructor.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CAccFwUiDialogNotifier* CAccFwUiDialogNotifier::NewL()
       
   131     {
       
   132     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::NewL() - enter" );
       
   133 
       
   134     CAccFwUiDialogNotifier* self = new( ELeave ) CAccFwUiDialogNotifier;
       
   135     
       
   136     CleanupStack::PushL( self );
       
   137     self->ConstructL();
       
   138     CleanupStack::Pop( self );
       
   139 
       
   140     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::CAccFwUiDialogNotifier::NewL() - return" );
       
   141     return self;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CAccFwUiDialogNotifier::Release()
       
   146 // (other items were commented in a header).
       
   147 // -----------------------------------------------------------------------------
       
   148 void CAccFwUiDialogNotifier::Release()
       
   149     {
       
   150     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Release() - enter" );
       
   151     
       
   152     if( iResourceFileOffset )
       
   153         {
       
   154         iCoeEnv->DeleteResourceFile( iResourceFileOffset );
       
   155         }
       
   156 
       
   157     delete this;
       
   158 
       
   159     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Release() - return void" );
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CAccFwUiDialogNotifier::RegisterL()
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 CAccFwUiDialogNotifier::TNotifierInfo CAccFwUiDialogNotifier::RegisterL()
       
   167     {
       
   168     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RegisterL() - enter" );
       
   169     
       
   170     iInfo.iUid=KAccFwUiDialogNotifierUid;
       
   171     iInfo.iChannel=KScreenOutputChannel;
       
   172     iInfo.iPriority=ENotifierPriorityHigh;
       
   173     
       
   174     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::CAccFwUiDialogNotifier::RegisterL() - return" );
       
   175     return iInfo;
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CAccFwUiDialogNotifier::Info()
       
   180 // (other items were commented in a header).
       
   181 // -----------------------------------------------------------------------------
       
   182 CAccFwUiDialogNotifier::TNotifierInfo CAccFwUiDialogNotifier::Info() const
       
   183     {
       
   184     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Info() - enter" );
       
   185     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Info() - return void" );
       
   186     return iInfo;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CAccFwUiDialogNotifier::StartL()
       
   191 // (other items were commented in a header).
       
   192 // -----------------------------------------------------------------------------
       
   193 TPtrC8 CAccFwUiDialogNotifier::StartL( const TDesC8& /*aBuffer*/ )
       
   194     {
       
   195     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::StartL() - enter" );
       
   196     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::StartL() - return void" );
       
   197     return KNullDesC8();
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CAccFwUiDialogNotifier::StartL()
       
   202 // (other items were commented in a header).
       
   203 // -----------------------------------------------------------------------------
       
   204 void CAccFwUiDialogNotifier::StartL(
       
   205     const TDesC8& aBuffer, 
       
   206     TInt aReplySlot, 
       
   207     const RMessagePtr2& aMessage )
       
   208     {
       
   209     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::StartL() - enter" );
       
   210      
       
   211     // Connect to AknKeylock2 server;
       
   212     iErr = iServer.Connect();
       
   213     
       
   214     //get selection bit mask
       
   215 	TUint32 selectionBitmask( 0 );
       
   216 	TPckg<TUint32> selectioPckg( selectionBitmask );
       
   217 	selectioPckg.Copy( aBuffer );
       
   218 
       
   219 	//prepare selection array	
       
   220 	iSelections.Close();
       
   221 	
       
   222 	
       
   223 	// construct listbox item array
       
   224 	iItemList = new ( ELeave ) CDesCArrayFlat( 10 );
       
   225 	
       
   226 	//if cover UI exist
       
   227 	if( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
       
   228         {	
       
   229 		delete iCoverUIITems;
       
   230 		iCoverUIITems = 0;
       
   231 		iCoverUIITems = new ( ELeave ) CArrayFixFlat<TInt>( 10 );
       
   232         }
       
   233 	TResourceReader reader;
       
   234 	HBufC8* literals = iCoeEnv->AllocReadResourceAsDes8LC( R_SELECTION_DIALOG_LITERALS );
       
   235 	reader.SetBuffer( literals );
       
   236 
       
   237 	TInt count( reader.ReadInt16() );
       
   238 	TInt coverUIItemCounter( 0 );
       
   239 		
       
   240 	//add items to dialog
       
   241 	for ( TInt i(0); i < count; i++ )
       
   242 	    {
       
   243 		//read from resource
       
   244 		TUint32 index( reader.ReadUint32() );
       
   245 		HBufC * buf( reader.ReadHBufCL() );
       
   246 		CleanupStack::PushL( buf );
       
   247 		
       
   248 		if ( index & selectionBitmask )
       
   249 		    {
       
   250 			iItemList->AppendL( *buf );
       
   251 			iSelections.Append( index );
       
   252 			
       
   253 			//append cover UI items
       
   254 			if ( iCoverUIITems )
       
   255 			    {
       
   256 				iCoverUIITems->AppendL( coverUIItemCounter++ );	
       
   257 			    }
       
   258 		    }
       
   259 
       
   260 		CleanupStack::PopAndDestroy( buf );
       
   261 
       
   262 		if ( ( index << 1  ) > selectionBitmask )
       
   263 		    {
       
   264 			//stop for-loop, selectionbitmask can't match anymore
       
   265 			break;
       
   266 		    }
       
   267 	    }
       
   268     CleanupStack::PopAndDestroy( literals );
       
   269 	iMessage = aMessage;
       
   270 	iReplySlot = aReplySlot;
       
   271 	iIsCancelled = EFalse;
       
   272     
       
   273     //prepare active object
       
   274     SetActive();
       
   275     TRequestStatus* status = &iStatus;
       
   276     User::RequestComplete( status, KErrNone );//RunL() function will get called
       
   277 
       
   278     
       
   279     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::StartL() - return void" );
       
   280     }
       
   281     
       
   282     
       
   283 // -----------------------------------------------------------------------------
       
   284 // CAccFwUiDialogNotifier::RunL()
       
   285 // (other items were commented in a header).
       
   286 // -----------------------------------------------------------------------------
       
   287 
       
   288 void CAccFwUiDialogNotifier::RunL()
       
   289     {
       
   290     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - enter" );
       
   291 
       
   292 	if ( iIsCancelled )
       
   293 	    {
       
   294 		return;	
       
   295 	    }
       
   296     
       
   297     if( iErr == KErrNone )
       
   298         {
       
   299         iWasLocked = iServer.IsKeyLockEnabled();
       
   300         // Change the bit on and off. SysAp will detect that
       
   301         // the lights should be switched on for the specified time.
       
   302         iServer.DisableKeyLock();
       
   303         }
       
   304     
       
   305 	TInt replyValue;
       
   306 
       
   307 	//create and prepare dialog
       
   308 	iDialog =  new ( ELeave ) CAknListQueryDialog ( &replyValue ); 
       
   309     iDialog->PrepareLC( R_SELECTION_DIALOG_LIST_QUERY );
       
   310 
       
   311 	//add items to popup list
       
   312 	iDialog->SetItemTextArray( iItemList );
       
   313 		
       
   314 	if( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
       
   315         {
       
   316 		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Publish cover UI ");
       
   317     	iDialog->PublishDialogL( ECmdShowAccessorySelectionDialog,
       
   318         					  	 KCatAccFw,
       
   319         					  	 iCoverUIITems );
       
   320 		//iDialog take ownership
       
   321 		iCoverUIITems = 0;        					
       
   322         }	
       
   323 	
       
   324 	//show dialog...
       
   325     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Show dialog -> RunLD()" );
       
   326 	TBool result = iDialog->RunLD();
       
   327 	iDialog = 0;
       
   328 
       
   329     //create package
       
   330     TInt returnValue( 0 );
       
   331     TPckg<TInt> valuePck( returnValue );
       
   332 
       
   333     if ( !iIsCancelled )
       
   334         {
       
   335 	    API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Check dialog result" );
       
   336 
       
   337     	if ( result )
       
   338         	{
       
   339 			//write selected item to reply slot
       
   340 			if ( returnValue >= 0 && iSelections.Count() )
       
   341 	    		{
       
   342 				returnValue = iSelections[ replyValue ];
       
   343 			    API_TRACE_1( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Set selection: %d", returnValue );
       
   344 		    	}
       
   345 		    // Don't lock keys if something was selected
       
   346 		    iLockKeys = EFalse;
       
   347     	    }
       
   348     	else
       
   349     	    {
       
   350 		    API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Cancel pressed" );
       
   351     		returnValue = 0;
       
   352     		iLockKeys = ETrue;
       
   353         	}
       
   354 
       
   355     	//complete client requests
       
   356 	    API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Write response value to message" );
       
   357 		iMessage.Write( iReplySlot, valuePck, 0 );	
       
   358 	    API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Complete message" );
       
   359  		iMessage.Complete( KErrNone );	
       
   360         }
       
   361     else
       
   362         {
       
   363         // Message is being completed with KErrCancel in Cancel-method
       
   364         }
       
   365 
       
   366     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - Release resources" );
       
   367 	delete iCoverUIITems;
       
   368 	iCoverUIITems = 0;
       
   369     iSelections.Close();
       
   370     
       
   371     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunL() - return void" );    
       
   372     }
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CAccFwUiDialogNotifier::RunError()
       
   376 // (other items were commented in a header).
       
   377 // -----------------------------------------------------------------------------
       
   378 TInt CAccFwUiDialogNotifier::RunError(TInt aError)
       
   379     {
       
   380     API_TRACE_1( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunError() - %d", aError );
       
   381     if( !iMessage.IsNull() )
       
   382         {
       
   383         iMessage.Complete( aError );
       
   384         }
       
   385     aError = KErrNone;
       
   386     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::RunError() - return" );
       
   387     return aError;
       
   388     }
       
   389     
       
   390 // -----------------------------------------------------------------------------
       
   391 // CAccFwUiDialogNotifier::DoCancel()
       
   392 // (other items were commented in a header).
       
   393 // -----------------------------------------------------------------------------
       
   394 void CAccFwUiDialogNotifier::DoCancel()
       
   395     {
       
   396     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::DoCancel() - enter" );
       
   397     if( !iMessage.IsNull() )
       
   398         {
       
   399         iMessage.Complete( KErrCancel );
       
   400         }
       
   401     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::DoCancel() - return" );
       
   402     }
       
   403     
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CAccFwUiDialogNotifier::Cancel()
       
   407 // (other items were commented in a header).
       
   408 // -----------------------------------------------------------------------------
       
   409 void CAccFwUiDialogNotifier::Cancel()
       
   410     {
       
   411     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Cancel() - enter" );
       
   412 
       
   413     iIsCancelled = ETrue;
       
   414     
       
   415     if( iLockKeys && iWasLocked && ( iErr == KErrNone ) )
       
   416         {
       
   417         iServer.EnableKeyLock();
       
   418         }
       
   419     
       
   420     iLockKeys = ETrue;
       
   421     
       
   422     if ( iDialog )
       
   423         {
       
   424 	   //cancel active object, delete dialog and release resources
       
   425         if ( IsActive() )
       
   426             {
       
   427             CActive::Cancel();    
       
   428             }
       
   429 	    delete iDialog;
       
   430 	    iDialog = 0;
       
   431 		delete iCoverUIITems;
       
   432 		iCoverUIITems = 0;
       
   433 	    iSelections.Close();    	
       
   434 
       
   435         TInt returnValue( 0 );
       
   436         TPckg<TInt> valuePck( returnValue );
       
   437         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Cancel() - Write response value to message" );
       
   438         iMessage.Write( iReplySlot, valuePck, 0 );
       
   439         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Cancel() - Complete message with Cancel" );
       
   440         iMessage.Complete( KErrCancel );
       
   441         }
       
   442     
       
   443     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::Cancel() - return void" );
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CAccFwUiDialogNotifier::UpdateL()
       
   448 // (other items were commented in a header).
       
   449 // -----------------------------------------------------------------------------
       
   450 TPtrC8 CAccFwUiDialogNotifier::UpdateL(
       
   451     const TDesC8& /*aBuffer*/ )
       
   452     {
       
   453     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::UpdateL() - enter" );
       
   454     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiDialogNotifier::UpdateL() - return void" );
       
   455     return KNullDesC8();
       
   456     }
       
   457 
       
   458 //  End of File