coreapplicationuis/accfwuinotifier/src/AccFwUiNoteNotifier.cpp
branchRCL_3
changeset 63 c2c61fdca848
parent 62 924385140d98
child 66 9af619316cbf
--- a/coreapplicationuis/accfwuinotifier/src/AccFwUiNoteNotifier.cpp	Tue Aug 31 15:24:25 2010 +0300
+++ b/coreapplicationuis/accfwuinotifier/src/AccFwUiNoteNotifier.cpp	Wed Sep 01 12:24:48 2010 +0100
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -20,9 +20,10 @@
 #include <featmgr.h>
 #include <accfwnoteuinotifier.rsg>
 #include <data_caging_path_literals.hrh> 
-#include <SecondaryDisplay/SecondaryDisplayAccFwAPI.h>
+#include <aknnotewrappers.h>
+#include <secondarydisplay/SecondaryDisplayAccFwAPI.h>
 #include <bautils.h>
-#include <hbdevicemessageboxsymbian.h>
+
 #include "AccFwUiNoteNotifier.h"
 #include "acc_debug.h"
 
@@ -67,6 +68,7 @@
     {
     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::~CAccFwUiNoteNotifier()" );
 
+    delete iNote;
     delete iNoteText;
     CActive::Cancel();
     
@@ -209,7 +211,144 @@
 
     if ( aBuffer.Length() )
         {
-		//Do nothing as accessory is rightly detected by accessory server and adaptation.
+		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default accessory selection or headphones information" );
+
+    	TInt value( 0 );
+    	TPckg<TInt> pckg( value );
+    	pckg.Copy( aBuffer );
+
+   		//get "default enhancement" string resource
+		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read default enhancement string" );
+        defaultText = iCoeEnv->AllocReadResourceLC( R_TEXT_DEFAULT_ENHANC );
+
+  		TPtrC enhancement;
+  		TBool enhancementOk( ETrue );
+
+  		if ( value != 0 )
+  		    {
+			API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default selection" );
+
+  			enhancementOk = EFalse;
+            HBufC8* literals = iCoeEnv->AllocReadResourceAsDes8L( R_SELECTION_DIALOG_LITERALS );
+            TResourceReader reader;
+        	reader.SetBuffer( literals );
+
+			TInt count( reader.ReadInt16() );
+			API_TRACE_1( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read literals, count %d", count );
+
+			// Find correct accessory literal
+			for ( TInt i = 0; i < count; i++ )
+			    {
+				//read from resource
+				TUint32 index( reader.ReadUint32() );
+				API_TRACE_1( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read literal, index %d", index );
+
+				if ( index == value )
+				    {
+					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Literal found!" );
+					// Literal found
+					enhancement.Set( reader.ReadTPtrC() );
+					enhancementOk = ETrue;
+					break;
+				    }
+				else
+				    {
+					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Not found!" );
+					reader.ReadTPtrC();
+				    }
+			    }
+			    
+			delete literals;
+  		    }
+
+		if ( enhancementOk )
+		    {
+			API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Enhancement OK!" );
+			HBufC* noteStr = NULL;
+
+			// Headphones...
+			if ( value == 0x08 || value == 0x40 || value == 0 )
+			    {
+				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Show headphones information!" );
+
+				// Default enhancement string if needed
+				if ( value != 0 )
+				    {
+					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Show also default information!" );
+				 	noteStr = HBufC::NewL( defaultText->Length() + enhancement.Length() + 3 );
+
+				 	TPtr ptr( noteStr->Des() );	
+					ptr.Append( defaultText->Des() );
+					ptr.Append( ' ' );
+					ptr.Append( enhancement );
+					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default string ready!" );
+				    }
+
+				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Read use phone mic string!" );
+                // Read resource use phone mic and default enhancement text...
+		   	    HBufC* usePhoneMicTextHolder = iCoeEnv->AllocReadResourceLC( R_TEXT_HEADPHONES_MIC );
+				
+				TBool chekcNoteStr( EFalse );
+				if ( noteStr )
+				    {
+					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Add phone mic string to default accessory string!" );
+					CleanupStack::PushL( noteStr );
+					HBufC* temp = noteStr->ReAllocL( noteStr->Length() + 2 + usePhoneMicTextHolder->Length() + 1 );
+					CleanupStack::Pop( noteStr );
+					noteStr = temp;
+					chekcNoteStr = ETrue;
+					}
+				else
+				    {
+					API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Only use phone mic string!" );
+					noteStr = HBufC::NewL( usePhoneMicTextHolder->Length() + 1 );
+				    }
+
+			 	TPtr ptr( noteStr->Des() );	
+				
+				
+				if( chekcNoteStr )
+					{
+					ptr.Append( _L( ". " ) );
+					ptr.Append( usePhoneMicTextHolder->Des() );
+					}
+                else
+                	{
+                	ptr.Append( usePhoneMicTextHolder->Des() );
+                	}
+                // Cleanup
+                CleanupStack::PopAndDestroy( usePhoneMicTextHolder );
+
+				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - String ready!" );
+			    }
+			else
+			    {
+				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Create default accessory text!" );
+				//only default accessory text
+				noteStr = HBufC::NewL( defaultText->Length() + enhancement.Length() + 1 );
+            	TPtr ptr( noteStr->Des() );
+			
+				ptr.Append( defaultText->Des() );
+				ptr.Append( ' ' );
+				ptr.Append( enhancement );
+				API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Default accessory text ready!" );
+			    }
+
+            // Pass string to member string and free local copies
+            CleanupStack::PopAndDestroy( defaultText );
+            CleanupStack::PushL( noteStr );
+            iNoteText = HBufC::NewL( noteStr->Length() );
+            TPtr ptr( iNoteText->Des() );
+            ptr.Append( noteStr->Des() );
+            CleanupStack::PopAndDestroy( noteStr );
+            showNote = ETrue;
+		    }
+		else
+		    {
+			API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - No note" );
+            // No need to check this one, always set into cleanup stack
+            CleanupStack::PopAndDestroy( defaultText );
+            }
         }
     else
         {
@@ -226,7 +365,13 @@
     iMessage = aMessage;
     if( showNote )
         {
-        iIsCancelled = EFalse;
+        if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
+            {
+    		API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - Cover UI supported" );
+            iPublishNote = ETrue;
+            }
+
+    	iIsCancelled = EFalse;
         SetActive();
         TRequestStatus* status = &iStatus;
         User::RequestComplete( status, KErrNone ); // RunL() function will get called
@@ -253,13 +398,25 @@
 		return;	
 	    }
     
-   	CHbDeviceMessageBoxSymbian *messageBox = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation);
-	           CleanupStack::PushL(messageBox);
-	           messageBox->SetTextL(*iNoteText);
-	           messageBox->ShowL();
-	           CleanupStack::PopAndDestroy(messageBox); // messageBox
-	           delete iNoteText;
-	           iNoteText = NULL;
+    // Create note
+    iNote = new ( ELeave ) CAknNoteDialog(
+        CAknNoteDialog::ENoTone,
+        CAknNoteDialog::ELongTimeout );
+
+    iNote->PrepareLC( R_ACCFWUINOTIFIER_INFORMATION_NOTE ); // Adds to CleanupStack
+
+    if ( iPublishNote )
+        {
+        iNote->PublishDialogL( ECmdShowAccessoryNotSupportedNote, KCatAccFw );
+        iPublishNote = EFalse;
+        }
+
+    iNote->SetTextL( *iNoteText );
+    API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::StartL() - iNote->RunLD()!" );
+    iNote->RunLD();
+    iNote = NULL;
+    delete iNoteText;
+    iNoteText = NULL;
 
     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::RunL() - Complete message" );
 	iMessage.Complete( KErrNone );
@@ -308,17 +465,21 @@
 
     iIsCancelled = ETrue;
     
-    	   // Cancel active object and free resources
+    if ( iNote )
+        {
+	   // Cancel active object, delete dialog and free resources
         if ( IsActive() )
             {
             CActive::Cancel();    
             }
-	      delete iNoteText;
+	    delete iNote;
+	    iNote = NULL;
+        delete iNoteText;
         iNoteText = NULL;
 
         API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - Complete message with Cancel" );
         iMessage.Complete( KErrCancel );
-       
+        }
 
     API_TRACE_( "[AccFW: ACCFWUINOTIFIER] CAccFwUiNoteNotifier::Cancel() - return" );
     }