coreapplicationuis/accfwuinotifier/src/AccFwUiNoteNotifier.cpp
changeset 21 c4cbaa4fb734
parent 0 2e3d3ce01487
child 29 6a787171e1de
equal deleted inserted replaced
0:2e3d3ce01487 21:c4cbaa4fb734
     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;
    70   //  delete iNote;
    72     delete iNoteText;
    71     delete iNoteText;
    73     CActive::Cancel();
    72     CActive::Cancel();
    74     
    73     
    75     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccPolAccessoryPolicy::~CAccFwUiNoteNotifier() - return void" );
    74     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccPolAccessoryPolicy::~CAccFwUiNoteNotifier() - return void" );
    76     }
    75     }
   209     HBufC* defaultText = NULL;
   208     HBufC* defaultText = NULL;
   210     TBool showNote = EFalse;
   209     TBool showNote = EFalse;
   211 
   210 
   212     if ( aBuffer.Length() )
   211     if ( aBuffer.Length() )
   213         {
   212         {
   214 		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default accessory selection or headphones information" );
   213 		//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         }
   214         }
   353     else
   215     else
   354         {
   216         {
   355         // Read resource string and adds heap buffer into cleanup stack.
   217         // Read resource string and adds heap buffer into cleanup stack.
   356         // This needs to be before creating 'note' for correct cleanup handling
   218         // This needs to be before creating 'note' for correct cleanup handling
   396 	if ( iIsCancelled )
   258 	if ( iIsCancelled )
   397 	    {
   259 	    {
   398 		return;	
   260 		return;	
   399 	    }
   261 	    }
   400     
   262     
   401     // Create note
   263    	CHbDeviceMessageBoxSymbian *messageBox = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation);
   402     iNote = new ( ELeave ) CAknNoteDialog(
   264 	           CleanupStack::PushL(messageBox);
   403         CAknNoteDialog::ENoTone,
   265 	           messageBox->SetTextL(*iNoteText);
   404         CAknNoteDialog::ELongTimeout );
   266 	           messageBox->ShowL();
   405 
   267 	           CleanupStack::PopAndDestroy(messageBox); // messageBox
   406     iNote->PrepareLC( R_ACCFWUINOTIFIER_INFORMATION_NOTE ); // Adds to CleanupStack
   268 	           delete iNoteText;
   407 
   269 	           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 
   270 
   421     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - Complete message" );
   271     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - Complete message" );
   422 	iMessage.Complete( KErrNone );
   272 	iMessage.Complete( KErrNone );
   423 
   273 
   424     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - return" );
   274     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - return" );
   463     {
   313     {
   464     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - enter" );
   314     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - enter" );
   465 
   315 
   466     iIsCancelled = ETrue;
   316     iIsCancelled = ETrue;
   467     
   317     
   468     if ( iNote )
   318     	   // Cancel active object, delete dialog and free resources
   469         {
       
   470 	   // Cancel active object, delete dialog and free resources
       
   471         if ( IsActive() )
   319         if ( IsActive() )
   472             {
   320             {
   473             CActive::Cancel();    
   321             CActive::Cancel();    
   474             }
   322             }
   475 	    delete iNote;
   323 	      delete iNoteText;
   476 	    iNote = NULL;
       
   477         delete iNoteText;
       
   478         iNoteText = NULL;
   324         iNoteText = NULL;
   479 
   325 
   480         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - Complete message with Cancel" );
   326         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - Complete message with Cancel" );
   481         iMessage.Complete( KErrCancel );
   327         iMessage.Complete( KErrCancel );
   482         }
   328        
   483 
   329 
   484     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - return" );
   330     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - return" );
   485     }
   331     }
   486 
   332 
   487 // -----------------------------------------------------------------------------
   333 // -----------------------------------------------------------------------------