bluetoothengine/btnotif/src/BTNGenericQueryNotifier.cpp
changeset 19 43824b19ee35
parent 17 f05641c183ff
child 33 837dcc42fd6a
equal deleted inserted replaced
17:f05641c183ff 19:43824b19ee35
     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:  Bluetooth visibility timeout notifier class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <StringLoader.h>       // Localisation stringloader
       
    22 #include <secondarydisplay/BTnotifSecondaryDisplayAPI.h>
       
    23 #include <e32cmn.h>
       
    24 #include <BTNotif.rsg>          // Own resources
       
    25 #include <btengsettings.h>
       
    26 #include <bluetoothuiutil.h>
       
    27 #include "BTNGenericQueryNotifier.h"      // Own class definition
       
    28 #include "btNotifDebug.h"       // Debugging macros
       
    29 
       
    30 #ifdef __SERIES60_HELP
       
    31 #include <hlplch.h>
       
    32 #include <csxhelp/bt.hlp.hrh> // The bt hrh info is needed, for help launching
       
    33 #endif
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ----------------------------------------------------------
       
    38 // CBTGenericQueryNotifier::NewL
       
    39 // Two-phased constructor.
       
    40 // ----------------------------------------------------------
       
    41 //
       
    42 CBTGenericQueryNotifier* CBTGenericQueryNotifier::NewL()
       
    43     {
       
    44     CBTGenericQueryNotifier* self=new (ELeave) CBTGenericQueryNotifier();
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ----------------------------------------------------------
       
    52 // CBTGenericQueryNotifier::CBTGenericQueryNotifier
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // ----------------------------------------------------------
       
    56 //
       
    57 CBTGenericQueryNotifier::CBTGenericQueryNotifier()
       
    58     {	
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------
       
    62 // Destructor
       
    63 // ----------------------------------------------------------
       
    64 //
       
    65 CBTGenericQueryNotifier::~CBTGenericQueryNotifier()
       
    66     {
       
    67     Cancel();   // Free own resources
       
    68     delete iName; 
       
    69     iQueryMessage.Close(); 
       
    70 	delete iQueryHeader;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------
       
    74 // CBTGenericQueryNotifier::RegisterL
       
    75 // Register notifier.
       
    76 // ----------------------------------------------------------
       
    77 //
       
    78 CBTGenericQueryNotifier::TNotifierInfo CBTGenericQueryNotifier::RegisterL()
       
    79     {
       
    80     iInfo.iUid=KBTGenericQueryNotifierUid;
       
    81     iInfo.iChannel=KBTGenericQueryNotifierUid;
       
    82     iInfo.iPriority=ENotifierPriorityHigh;
       
    83     return iInfo;
       
    84     }
       
    85 
       
    86 
       
    87 // ----------------------------------------------------------
       
    88 // CBTGenericQueryNotifier::StartL
       
    89 // Synchronic notifier launch. Contructs and shows a global
       
    90 // note, no parameters need here.
       
    91 // ----------------------------------------------------------
       
    92 //
       
    93 TPtrC8 CBTGenericQueryNotifier::StartL( const TDesC8& /*aBuffer*/ )
       
    94     {
       
    95     FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::StartL()"));
       
    96 
       
    97     TPtrC8 ret(KNullDesC8);
       
    98     return (ret);    
       
    99     
       
   100     }
       
   101 
       
   102 // ----------------------------------------------------------
       
   103 // CBTGenericQueryNotifier::GetParamsL
       
   104 // Mandatory for BT Notifiers when using asynchronous launch. 
       
   105 // This notifier is synchronous so no implementation is needed.
       
   106 // ----------------------------------------------------------
       
   107 //
       
   108 void CBTGenericQueryNotifier::GetParamsL(const TDesC8& aBuffer, 
       
   109                                      TInt aReplySlot, 
       
   110                                      const RMessagePtr2& aMessage)
       
   111     {
       
   112    	FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::GetParamsL"));    
       
   113 
       
   114    	if (iMessage.Handle())
       
   115    	    {
       
   116    	    aMessage.Complete(KErrInUse);
       
   117    	    return;
       
   118    	    }
       
   119    	
       
   120 	ProcessParamBufferL(aBuffer);
       
   121 	
       
   122     iMessage = aMessage;
       
   123     iReplySlot = aReplySlot;
       
   124     
       
   125     ShowQueryAndCompleteL();
       
   126     
       
   127    	FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::GetParamsL Complete"));    
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------------
       
   131 // CBTGenericQueryNotifier::ProcessParamBufferL
       
   132 // Parse the data out of the message that is sent by the
       
   133 // client of the notifier.
       
   134 // ----------------------------------------------------------
       
   135 void CBTGenericQueryNotifier::ProcessParamBufferL(const TDesC8& aBuffer)
       
   136 	{
       
   137 	
       
   138 	TBTGenericQueryNotifierParams bParams;
       
   139 	TPckgC<TBTGenericQueryNotifierParams> bPckg(bParams);
       
   140 	bPckg.Set( aBuffer );
       
   141 
       
   142 	if( bPckg().iMessageType == EBTNameQuery )
       
   143 	    {
       
   144 	    iIsNameQuery = ETrue;
       
   145 	    return;
       
   146 	    }
       
   147 	iSecondaryDisplayCommand = ECmdBTnotifUnavailable;
       
   148 	switch (bPckg().iMessageType)
       
   149 		{
       
   150 		case EBTReceiveMessageQuery:
       
   151 			iIsMessageQuery=EFalse;
       
   152 			iMessageResourceId=R_BT_RECEIVE_MESSAGE	;	
       
   153 			iSecondaryDisplayCommand=ECmdShowReceiveMessageFromDeviceDlg; 
       
   154 			break;
       
   155 		case EBTReceiveMessagePairedQuery:
       
   156 			iIsMessageQuery=EFalse;		
       
   157 			iMessageResourceId=R_BT_RECEIVE_MESSAGE_PAIRED;
       
   158 			iSecondaryDisplayCommand= ECmdShowReceiveMessageFromPairedDeviceDlg; 
       
   159 			break;			
       
   160 		case EBTIsOffQuery:
       
   161 			iIsMessageQuery=EFalse;		
       
   162     		iMessageResourceId=R_BT_POWER_IS_OFF ;
       
   163 			iSecondaryDisplayCommand=ECmdShowBtIsOffDlg;		
       
   164 			break;			
       
   165 		case EBTActivateOffLineQuery:
       
   166 			iIsMessageQuery=EFalse;		
       
   167     		iMessageResourceId=R_BT_ACTIVATE_IN_OFFLINE;
       
   168 			iSecondaryDisplayCommand=ECmdShowBtActivateInOfflineDlg;		
       
   169 			break;			
       
   170 		case EBTNoDevicesFoundQuery:
       
   171 			iIsMessageQuery=EFalse;		
       
   172 			iMessageResourceId=R_BT_NO_DEVICES_FOUND;
       
   173 			break;	
       
   174 		case EBTAcceptRequestQuery:
       
   175 			iIsMessageQuery=EFalse;		
       
   176 			iMessageResourceId=R_BT_AUTHORISATION_NAME ;
       
   177 			iSecondaryDisplayCommand=ECmdShowAcceptConnRequestDlg;
       
   178 			break;		
       
   179 			
       
   180 		case EBTIsOffJavaQuery:	
       
   181 			iIsMessageQuery=ETrue; 	
       
   182 			if( bPckg().iNameExists )			
       
   183 				{
       
   184 				iMessageResourceId=R_BT_IS_OFF_JAVA_APPNAME; // when caller provide Java application name.	
       
   185 				}
       
   186 			else
       
   187 				{
       
   188 				iMessageResourceId=R_BT_IS_OFF_JAVA; //r_bt_is_hidden_java	
       
   189 				}		
       
   190 			iSecondaryDisplayCommand=ECmdShowBtBtIsOffJavaDlg;
       
   191 			iQueryHeader=StringLoader::LoadL( R_BT_IS_OFF_JAVA_HEADER);		
       
   192 			break;
       
   193 
       
   194 		case EBTIsNotShownQuery:
       
   195 			iIsMessageQuery=ETrue;			
       
   196 			if( bPckg().iNameExists )
       
   197 				{
       
   198 				iMessageResourceId=R_BT_IS_HIDDEN_JAVA_APPNAME; // when caller provide Java application name.	
       
   199 				}
       
   200 			else
       
   201 				{
       
   202 				iMessageResourceId=R_BT_IS_HIDDEN_JAVA; //r_bt_is_hidden_java	
       
   203 				}									
       
   204 			iSecondaryDisplayCommand=ECmdShowBtIsNotVisibleDlg;
       
   205 			iQueryHeader=StringLoader::LoadL( R_BT_IS_HIDDEN_JAVA_HEADER);
       
   206 			break;
       
   207 			
       
   208 		case EBTBlockConnectionQuery:
       
   209 		case EBTBlockPairedConnectionQuery:		
       
   210 			iIsMessageQuery=ETrue;		
       
   211 			if( bPckg().iMessageType == EBTBlockConnectionQuery )
       
   212 				iMessageResourceId = R_BT_BLOCK_DEVICE_NOHELP; 
       
   213 			else
       
   214 				iMessageResourceId = R_BT_BLOCK_PAIRED_DEVICE_NOHELP ; 
       
   215 				
       
   216 			iQueryHeader= StringLoader::LoadL( R_BT_BLOCK_DEVICE_HEADER );
       
   217 			break;
       
   218 			
       
   219 		case EBTSwitchOffAnyway:
       
   220 			iIsMessageQuery=EFalse;		
       
   221 			iMessageResourceId=R_BT_SWITCH_OFF_ANYWAY;
       
   222 			break;		
       
   223 					
       
   224 		default:
       
   225 			FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier:: Unkown messageType! ")); 
       
   226  			User::Leave(KErrNotFound);		
       
   227 		}
       
   228 	
       
   229 	// if the logic string contains substitute indicator "%U", replace it with device name:
       
   230 	//
       
   231 	HBufC* buf = StringLoader::LoadL( iMessageResourceId);
       
   232 	iQueryMessage.Assign( buf );
       
   233 
       
   234 	TInt keyLen;
       
   235 	TInt pos = BluetoothUiUtil::GetStringSubstringKeyPos( 
       
   236 	        iQueryMessage, 0, keyLen );
       
   237 	if( pos > KErrNotFound)
       
   238 		{		
       
   239 		//if no device name provided, default name will be used:
       
   240 		if( !bPckg().iNameExists )			
       
   241 			iName=StringLoader::LoadL(R_BT_DIALOG_DEF_NAME);
       
   242 		else
       
   243 			{
       
   244 			iName=HBufC::NewL(bPckg().iName.Length() );
       
   245 			iName->Des().Copy(bPckg().iName);
       
   246 			}
       
   247 		BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   248 		        iQueryMessage, iMessageResourceId, *iName, 0);
       
   249 		}
       
   250 	else
       
   251 		{
       
   252 		iName=NULL;		
       
   253 		}		
       
   254 	}
       
   255 
       
   256 // ----------------------------------------------------------
       
   257 // CBTGenericQueryNotifier::UpdateL
       
   258 // Update notifier according to new data
       
   259 // ----------------------------------------------------------
       
   260 //	
       
   261 TPtrC8 CBTGenericQueryNotifier::UpdateL(const TDesC8& aBuffer)
       
   262 	{
       
   263    	FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::UpdateL")); 
       
   264 	ProcessParamBufferL(aBuffer);
       
   265 	if( !iNotifUiUtil->IsQueryReleased() )
       
   266 		{
       
   267 		if(iIsMessageQuery )
       
   268 		    {
       
   269 		    iNotifUiUtil->UpdateMessageQueryDlgL(iQueryMessage);
       
   270 		    }
       
   271 		else
       
   272 		    {
       
   273 		    iNotifUiUtil->UpdateQueryDlgL(iQueryMessage);
       
   274 		    }
       
   275 		}
       
   276    	FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::UpdateL complete")); 	
       
   277 
       
   278     TPtrC8 ret(KNullDesC8);
       
   279     return (ret);   	
       
   280 	}
       
   281 
       
   282 // ----------------------------------------------------------
       
   283 // CBTGenericQueryNotifier::ShowQueryAndCompleteL
       
   284 // Shows the notifier in backround and complete message
       
   285 // ----------------------------------------------------------
       
   286 //
       
   287 void CBTGenericQueryNotifier::ShowQueryAndCompleteL()
       
   288 	{ 
       
   289    	FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL")); 	
       
   290 	
       
   291 	// Turn lights on and deactivate apps -key
       
   292 	//
       
   293    	iNotifUiUtil->TurnLightsOn();  	
       
   294 	if( iIsNameQuery )
       
   295 	    {
       
   296 	    TBool nameStatus = IsLocalNameModifiedL();
       
   297 	    if( !nameStatus )
       
   298 	        {
       
   299 	        (void) AskLocalBTNameQueryL();
       
   300 	        }
       
   301         // Check if Local name is set again before turn BT on. 
       
   302         // Turn BT on only when there is local name, since user still has chance
       
   303         // to ignore the asking name query - like pressing End-key     
       
   304         //             
       
   305         TBTDeviceName localName;           
       
   306         localName.Zero();
       
   307         TInt err = iBTEngSettings->GetLocalName(localName);
       
   308               
       
   309         if (localName.Length() <= 0)
       
   310             {   
       
   311             err = KErrCancel;
       
   312             }
       
   313 	    	    
       
   314 	    CompleteMessage( (!err) ? ETrue : EFalse, KErrNone );
       
   315 
       
   316 	    FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL iIsNameQuery complete")); 
       
   317 	    return;
       
   318 	    }
       
   319 	
       
   320 	TInt keypress;
       
   321     TBTDeviceName name(KNullDesC);
       
   322     if( iName )
       
   323 	    {
       
   324 	    name.Copy( *iName );
       
   325 	    }
       
   326     if( iIsMessageQuery	)
       
   327 		{
       
   328 		
       
   329         keypress = iNotifUiUtil->ShowMessageQueryL(iQueryMessage, *iQueryHeader, 
       
   330                         R_BT_GENERIC_MESSAGE_QUERY, CAknQueryDialog::EConfirmationTone );        
       
   331 		}
       
   332 	else
       
   333     	{
       
   334     	keypress = iNotifUiUtil->ShowQueryL( iQueryMessage, R_BT_GENERIC_QUERY, 
       
   335     	        iSecondaryDisplayCommand, name, CAknQueryDialog::EConfirmationTone );
       
   336     	}
       
   337 	
       
   338    	CompleteMessage( (keypress) ? ETrue: EFalse, KErrNone );
       
   339 
       
   340    	FLOG(_L("[BTNOTIF]\t CBTGenericQueryNotifier::ShowQueryAndCompleteL complete")); 			
       
   341 	}
       
   342 
       
   343 // End of File