coreapplicationuis/accfwuinotifier/src/AccFwUiNoteNotifier.cpp
branchRCL_3
changeset 19 924385140d98
parent 9 332e7bf3b42f
child 20 c2c61fdca848
equal deleted inserted replaced
18:0818dd463d41 19:924385140d98
     1 /*
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <featmgr.h>
    20 #include <featmgr.h>
    21 #include <accfwnoteuinotifier.rsg>
    21 #include <accfwnoteuinotifier.rsg>
    22 #include <data_caging_path_literals.hrh> 
    22 #include <data_caging_path_literals.hrh> 
    23 #include <aknnotewrappers.h>
    23 #include <SecondaryDisplay/SecondaryDisplayAccFwAPI.h>
    24 #include <secondarydisplay/SecondaryDisplayAccFwAPI.h>
       
    25 #include <bautils.h>
    24 #include <bautils.h>
    26 
    25 #include <hbdevicemessageboxsymbian.h>
    27 #include "AccFwUiNoteNotifier.h"
    26 #include "AccFwUiNoteNotifier.h"
    28 #include "acc_debug.h"
    27 #include "acc_debug.h"
    29 
    28 
    30 // EXTERNAL DATA STRUCTURES
    29 // EXTERNAL DATA STRUCTURES
    31 
    30 
    66 // Destructor
    65 // Destructor
    67 CAccFwUiNoteNotifier::~CAccFwUiNoteNotifier()
    66 CAccFwUiNoteNotifier::~CAccFwUiNoteNotifier()
    68     {
    67     {
    69     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::~CAccFwUiNoteNotifier()" );
    68     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::~CAccFwUiNoteNotifier()" );
    70 
    69 
    71     delete iNote;
       
    72     delete iNoteText;
    70     delete iNoteText;
    73     CActive::Cancel();
    71     CActive::Cancel();
    74     
    72     
    75     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccPolAccessoryPolicy::~CAccFwUiNoteNotifier() - return void" );
    73     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccPolAccessoryPolicy::~CAccFwUiNoteNotifier() - return void" );
    76     }
    74     }
   209     HBufC* defaultText = NULL;
   207     HBufC* defaultText = NULL;
   210     TBool showNote = EFalse;
   208     TBool showNote = EFalse;
   211 
   209 
   212     if ( aBuffer.Length() )
   210     if ( aBuffer.Length() )
   213         {
   211         {
   214 		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default accessory selection or headphones information" );
   212 		//Do nothing as accessory is rightly detected by accessory server and adaptation.
   215 
       
   216     	TInt value( 0 );
       
   217     	TPckg<TInt> pckg( value );
       
   218     	pckg.Copy( aBuffer );
       
   219 
       
   220    		//get "default enhancement" string resource
       
   221 		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read default enhancement string" );
       
   222         defaultText = iCoeEnv->AllocReadResourceLC( R_TEXT_DEFAULT_ENHANC );
       
   223 
       
   224   		TPtrC enhancement;
       
   225   		TBool enhancementOk( ETrue );
       
   226 
       
   227   		if ( value != 0 )
       
   228   		    {
       
   229 			API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default selection" );
       
   230 
       
   231   			enhancementOk = EFalse;
       
   232             HBufC8* literals = iCoeEnv->AllocReadResourceAsDes8L( R_SELECTION_DIALOG_LITERALS );
       
   233             TResourceReader reader;
       
   234         	reader.SetBuffer( literals );
       
   235 
       
   236 			TInt count( reader.ReadInt16() );
       
   237 			API_TRACE_1( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read literals, count %d", count );
       
   238 
       
   239 			// Find correct accessory literal
       
   240 			for ( TInt i = 0; i < count; i++ )
       
   241 			    {
       
   242 				//read from resource
       
   243 				TUint32 index( reader.ReadUint32() );
       
   244 				API_TRACE_1( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read literal, index %d", index );
       
   245 
       
   246 				if ( index == value )
       
   247 				    {
       
   248 					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Literal found!" );
       
   249 					// Literal found
       
   250 					enhancement.Set( reader.ReadTPtrC() );
       
   251 					enhancementOk = ETrue;
       
   252 					break;
       
   253 				    }
       
   254 				else
       
   255 				    {
       
   256 					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Not found!" );
       
   257 					reader.ReadTPtrC();
       
   258 				    }
       
   259 			    }
       
   260 			    
       
   261 			delete literals;
       
   262   		    }
       
   263 
       
   264 		if ( enhancementOk )
       
   265 		    {
       
   266 			API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Enhancement OK!" );
       
   267 			HBufC* noteStr = NULL;
       
   268 
       
   269 			// Headphones...
       
   270 			if ( value == 0x08 || value == 0x40 || value == 0 )
       
   271 			    {
       
   272 				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Show headphones information!" );
       
   273 
       
   274 				// Default enhancement string if needed
       
   275 				if ( value != 0 )
       
   276 				    {
       
   277 					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Show also default information!" );
       
   278 				 	noteStr = HBufC::NewL( defaultText->Length() + enhancement.Length() + 3 );
       
   279 
       
   280 				 	TPtr ptr( noteStr->Des() );	
       
   281 					ptr.Append( defaultText->Des() );
       
   282 					ptr.Append( ' ' );
       
   283 					ptr.Append( enhancement );
       
   284 					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default string ready!" );
       
   285 				    }
       
   286 
       
   287 				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read use phone mic string!" );
       
   288                 // Read resource use phone mic and default enhancement text...
       
   289 		   	    HBufC* usePhoneMicTextHolder = iCoeEnv->AllocReadResourceLC( R_TEXT_HEADPHONES_MIC );
       
   290 				
       
   291 				TBool chekcNoteStr( EFalse );
       
   292 				if ( noteStr )
       
   293 				    {
       
   294 					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Add phone mic string to default accessory string!" );
       
   295 					CleanupStack::PushL( noteStr );
       
   296 					HBufC* temp = noteStr->ReAllocL( noteStr->Length() + 2 + usePhoneMicTextHolder->Length() + 1 );
       
   297 					CleanupStack::Pop( noteStr );
       
   298 					noteStr = temp;
       
   299 					chekcNoteStr = ETrue;
       
   300 					}
       
   301 				else
       
   302 				    {
       
   303 					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Only use phone mic string!" );
       
   304 					noteStr = HBufC::NewL( usePhoneMicTextHolder->Length() + 1 );
       
   305 				    }
       
   306 
       
   307 			 	TPtr ptr( noteStr->Des() );	
       
   308 				
       
   309 				
       
   310 				if( chekcNoteStr )
       
   311 					{
       
   312 					ptr.Append( _L( ". " ) );
       
   313 					ptr.Append( usePhoneMicTextHolder->Des() );
       
   314 					}
       
   315                 else
       
   316                 	{
       
   317                 	ptr.Append( usePhoneMicTextHolder->Des() );
       
   318                 	}
       
   319                 // Cleanup
       
   320                 CleanupStack::PopAndDestroy( usePhoneMicTextHolder );
       
   321 
       
   322 				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - String ready!" );
       
   323 			    }
       
   324 			else
       
   325 			    {
       
   326 				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Create default accessory text!" );
       
   327 				//only default accessory text
       
   328 				noteStr = HBufC::NewL( defaultText->Length() + enhancement.Length() + 1 );
       
   329             	TPtr ptr( noteStr->Des() );
       
   330 			
       
   331 				ptr.Append( defaultText->Des() );
       
   332 				ptr.Append( ' ' );
       
   333 				ptr.Append( enhancement );
       
   334 				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default accessory text ready!" );
       
   335 			    }
       
   336 
       
   337             // Pass string to member string and free local copies
       
   338             CleanupStack::PopAndDestroy( defaultText );
       
   339             CleanupStack::PushL( noteStr );
       
   340             iNoteText = HBufC::NewL( noteStr->Length() );
       
   341             TPtr ptr( iNoteText->Des() );
       
   342             ptr.Append( noteStr->Des() );
       
   343             CleanupStack::PopAndDestroy( noteStr );
       
   344             showNote = ETrue;
       
   345 		    }
       
   346 		else
       
   347 		    {
       
   348 			API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - No note" );
       
   349             // No need to check this one, always set into cleanup stack
       
   350             CleanupStack::PopAndDestroy( defaultText );
       
   351             }
       
   352         }
   213         }
   353     else
   214     else
   354         {
   215         {
   355         // Read resource string and adds heap buffer into cleanup stack.
   216         // Read resource string and adds heap buffer into cleanup stack.
   356         // This needs to be before creating 'note' for correct cleanup handling
   217         // This needs to be before creating 'note' for correct cleanup handling
   363         }
   224         }
   364 
   225 
   365     iMessage = aMessage;
   226     iMessage = aMessage;
   366     if( showNote )
   227     if( showNote )
   367         {
   228         {
   368         if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
   229         iIsCancelled = EFalse;
   369             {
       
   370     		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Cover UI supported" );
       
   371             iPublishNote = ETrue;
       
   372             }
       
   373 
       
   374     	iIsCancelled = EFalse;
       
   375         SetActive();
   230         SetActive();
   376         TRequestStatus* status = &iStatus;
   231         TRequestStatus* status = &iStatus;
   377         User::RequestComplete( status, KErrNone ); // RunL() function will get called
   232         User::RequestComplete( status, KErrNone ); // RunL() function will get called
   378         }
   233         }
   379     else
   234     else
   396 	if ( iIsCancelled )
   251 	if ( iIsCancelled )
   397 	    {
   252 	    {
   398 		return;	
   253 		return;	
   399 	    }
   254 	    }
   400     
   255     
   401     // Create note
   256    	CHbDeviceMessageBoxSymbian *messageBox = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation);
   402     iNote = new ( ELeave ) CAknNoteDialog(
   257 	           CleanupStack::PushL(messageBox);
   403         CAknNoteDialog::ENoTone,
   258 	           messageBox->SetTextL(*iNoteText);
   404         CAknNoteDialog::ELongTimeout );
   259 	           messageBox->ShowL();
   405 
   260 	           CleanupStack::PopAndDestroy(messageBox); // messageBox
   406     iNote->PrepareLC( R_ACCFWUINOTIFIER_INFORMATION_NOTE ); // Adds to CleanupStack
   261 	           delete iNoteText;
   407 
   262 	           iNoteText = NULL;
   408     if ( iPublishNote )
       
   409         {
       
   410         iNote->PublishDialogL( ECmdShowAccessoryNotSupportedNote, KCatAccFw );
       
   411         iPublishNote = EFalse;
       
   412         }
       
   413 
       
   414     iNote->SetTextL( *iNoteText );
       
   415     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - iNote->RunLD()!" );
       
   416     iNote->RunLD();
       
   417     iNote = NULL;
       
   418     delete iNoteText;
       
   419     iNoteText = NULL;
       
   420 
   263 
   421     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - Complete message" );
   264     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - Complete message" );
   422 	iMessage.Complete( KErrNone );
   265 	iMessage.Complete( KErrNone );
   423 
   266 
   424     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - return" );
   267     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - return" );
   463     {
   306     {
   464     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - enter" );
   307     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - enter" );
   465 
   308 
   466     iIsCancelled = ETrue;
   309     iIsCancelled = ETrue;
   467     
   310     
   468     if ( iNote )
   311     	   // Cancel active object and free resources
   469         {
       
   470 	   // Cancel active object, delete dialog and free resources
       
   471         if ( IsActive() )
   312         if ( IsActive() )
   472             {
   313             {
   473             CActive::Cancel();    
   314             CActive::Cancel();    
   474             }
   315             }
   475 	    delete iNote;
   316 	      delete iNoteText;
   476 	    iNote = NULL;
       
   477         delete iNoteText;
       
   478         iNoteText = NULL;
   317         iNoteText = NULL;
   479 
   318 
   480         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - Complete message with Cancel" );
   319         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - Complete message with Cancel" );
   481         iMessage.Complete( KErrCancel );
   320         iMessage.Complete( KErrCancel );
   482         }
   321        
   483 
   322 
   484     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - return" );
   323     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - return" );
   485     }
   324     }
   486 
   325 
   487 // -----------------------------------------------------------------------------
   326 // -----------------------------------------------------------------------------