bluetoothengine/btnotif/src/BTNGenericInfoNotifier.cpp
branchRCL_3
changeset 22 613943a21004
parent 21 0ba996a9b75d
child 23 9386f31cc85b
equal deleted inserted replaced
21:0ba996a9b75d 22:613943a21004
     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 <BTNotif.rsg>          // Own resources
       
    23 #include "BTNGenericInfoNotifier.h"      // Own class definition
       
    24 #include "btNotifDebug.h"       // Debugging macros
       
    25 #include <SecondaryDisplay/BTnotifSecondaryDisplayAPI.h>
       
    26 #include <e32cmn.h>
       
    27 #include <bluetoothuiutil.h>
       
    28 #include "btnotifnameutils.h"
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 // ----------------------------------------------------------
       
    33 // CBTGenericInfoNotifier::NewL
       
    34 // Two-phased constructor.
       
    35 // ----------------------------------------------------------
       
    36 //
       
    37 CBTGenericInfoNotifier* CBTGenericInfoNotifier::NewL()
       
    38     {
       
    39     CBTGenericInfoNotifier* self=new (ELeave) CBTGenericInfoNotifier();
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop();
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------
       
    47 // CBTGenericInfoNotifier::CBTGenericInfoNotifier
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // ----------------------------------------------------------
       
    51 //
       
    52 CBTGenericInfoNotifier::CBTGenericInfoNotifier() 
       
    53     {
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------
       
    57 // Destructor
       
    58 // ----------------------------------------------------------
       
    59 //
       
    60 CBTGenericInfoNotifier::~CBTGenericInfoNotifier()
       
    61     {
       
    62     Cancel();   // Free own resources
       
    63     iQueryMessage.Close(); 
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------
       
    67 // CBTGenericInfoNotifier::RegisterL
       
    68 // Register notifier.
       
    69 // ----------------------------------------------------------
       
    70 //
       
    71 CBTGenericInfoNotifier::TNotifierInfo CBTGenericInfoNotifier::RegisterL()
       
    72     {
       
    73     iInfo.iUid=KBTGenericInfoNotifierUid;
       
    74     iInfo.iChannel=KBTGenericInfoNotifierUid;
       
    75     iInfo.iPriority=ENotifierPriorityHigh;
       
    76     return iInfo;
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------
       
    80 // CBTGenericInfoNotifier::StartL
       
    81 // Synchronic notifier launch. Contructs and shows a global
       
    82 // note when temp visibility expire, no parameters need here.
       
    83 // ----------------------------------------------------------
       
    84 //
       
    85 TPtrC8 CBTGenericInfoNotifier::StartL( const TDesC8& aBuffer )
       
    86     {
       
    87     FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier::StartL()"));
       
    88     if( !iNotifUiUtil )
       
    89         {
       
    90         iNotifUiUtil = CBTNotifUIUtil::NewL( iIsCoverUI );
       
    91         }
       
    92     ProcessParamBufferL(aBuffer, ETrue);
       
    93     FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier::StartL() completed"));
       
    94 
       
    95     TPtrC8 ret(KNullDesC8);
       
    96     return (ret);
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------
       
   100 // CBTGenericInfoNotifier::GetParamsL
       
   101 // Mandatory for BT Notifiers when using asynchronous launch. 
       
   102 // ----------------------------------------------------------
       
   103 //
       
   104 void CBTGenericInfoNotifier::GetParamsL(const TDesC8& aBuffer, 
       
   105                                      TInt /*aReplySlot*/, 
       
   106                                      const RMessagePtr2& aMessage )
       
   107     {
       
   108 	FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier::GetParamsL"));  
       
   109 	if (!iMessage.IsNull())
       
   110 	    {
       
   111 	    aMessage.Complete(KErrInUse);
       
   112 	    return;
       
   113 	    }
       
   114     iMessage = aMessage;
       
   115  	ProcessParamBufferL(aBuffer, EFalse);
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------
       
   119 // CBTGenericInfoNotifier::ProcessParamBufferL
       
   120 // Parse the data out of the message that is sent by the
       
   121 // client of the notifier.
       
   122 // ----------------------------------------------------------
       
   123 void CBTGenericInfoNotifier::ProcessParamBufferL(const TDesC8& aBuffer, TBool aSyncCall)
       
   124 	{
       
   125 	TBTGenericInfoNotifierParams bParams;
       
   126 	TPckgC<TBTGenericInfoNotifierParams> bPckg(bParams);
       
   127 		
       
   128 	bPckg.Set( aBuffer );
       
   129 	iSecondaryDisplayCommand = ECmdBTnotifUnavailable;
       
   130 	switch (bPckg().iMessageType)
       
   131 		{
       
   132 		case EBTConnected: 			
       
   133 			iMessageResourceId= R_BT_CONF_CONNECTED_PROMPT; 
       
   134 			iSecondaryDisplayCommand=ECmdShowBtConnectedNote;
       
   135 			break;
       
   136 		case EBTDisconnected: 		
       
   137 			iMessageResourceId= R_BT_CONF_DISCONNECTED_PROMPT; 
       
   138 			iSecondaryDisplayCommand=ECmdShowBtDisconnectedNote;
       
   139 			break;
       
   140 		case EBTAudioAccessory: 	
       
   141 			iMessageResourceId= R_BT_AUDIO_ACCESSORY_PROMPT; 
       
   142 			iSecondaryDisplayCommand=ECmdShowBtAudioAccessoryNote;
       
   143 			break;
       
   144 		case EBTAudioHandset: 		
       
   145 			iMessageResourceId= R_BT_AUDIO_HANDSET_PROMPT; 
       
   146 			iSecondaryDisplayCommand=ECmdShowBtAudioHandsetNote;
       
   147 			break;
       
   148 		case EBTClosed: 			
       
   149 			iMessageResourceId= R_BT_CONN_CLOSED_PROMPT; 
       
   150 			iSecondaryDisplayCommand=ECmdShowBtDisconnectedNote;
       
   151 			break;
       
   152 		case EBTDeviceNotAvailable: 
       
   153 			iMessageResourceId= R_BT_DEVICE_NOT_AVAIL; 
       
   154 			iSecondaryDisplayCommand=ECmdShowBtDeviceNotAvailableNote;
       
   155 			break;
       
   156 		case EBTOfflineDisabled: 	
       
   157 			iMessageResourceId= R_BT_OFFLINE_DISABLED; 
       
   158 			iSecondaryDisplayCommand=ECmdShowBtOfflineDisableNote;
       
   159 			break;	
       
   160 		case EBTVisibilityTimeout: 	
       
   161 			iMessageResourceId= R_BT_HIDDEN_FROM_OTHERS_NOTE; 
       
   162 			iSecondaryDisplayCommand=ECmdShowBtHiddenFromOthersNote;
       
   163 			break;	
       
   164 		case EBTEnterSap: 			
       
   165 			iMessageResourceId= R_BT_ENTER_SAP_NOTE; 
       
   166 			iSecondaryDisplayCommand=ECmdShowBtSapEnteringNote;
       
   167 			break;
       
   168 		case EBTSapOk: 				
       
   169 			iMessageResourceId= R_BT_ENTER_SAP_SUCCEED_NOTE; 
       
   170 			iSecondaryDisplayCommand=ECmdShowBtSapEnteringSucceededNote;
       
   171 			break;
       
   172 		case EBTSapFailed: 			
       
   173 			iMessageResourceId= R_BT_ENTER_SAP_FAILED_NOTE; 
       
   174 			iSecondaryDisplayCommand=ECmdShowBtSapEnteringFailedNote;
       
   175 			break;
       
   176 		case EBTSapNoSim: 			
       
   177 			iMessageResourceId= R_BT_SAP_NO_SIM_NOTE; 
       
   178 			iSecondaryDisplayCommand=ECmdShowBtSapNoSimNote;
       
   179 			break;			
       
   180 		case EBTDeviceBusy: 
       
   181 			iMessageResourceId=R_BT_BUSY_TEXT;
       
   182 			iSecondaryDisplayCommand=ECmdShowBtBusyNote;
       
   183 			break;
       
   184 		case EIRNotSupported: 
       
   185 			iMessageResourceId=R_IR_NOT_SUPPORTED;
       
   186 			iSecondaryDisplayCommand=ECmdShowIrNotSupportedNote;
       
   187 			break;
       
   188 		case ECmdShowBtBatteryLow:
       
   189 			iMessageResourceId= R_BT_ACCESSORY_LOW;
       
   190 			iSecondaryDisplayCommand= ECmdShowBtBatteryLowNote;
       
   191 			break;
       
   192 		case ECmdShowBtBatteryCritical:
       
   193 			iMessageResourceId= R_BT_ACCESSORY_CRITICAL; 
       
   194 			iSecondaryDisplayCommand= ECmdShowBtBatteryCriticalNote;
       
   195 			break;
       
   196         case EBTStayPowerOn:
       
   197             iMessageResourceId= R_BT_PERMANENTLY_ON; 
       
   198             break;
       
   199     	case EBTSwitchedOn:
       
   200     		iMessageResourceId= R_BT_SWITCHED_ON; 
       
   201     		break;
       
   202     	case EBTSwitchedOff:
       
   203     		iMessageResourceId= R_BT_SWITCHED_OFF;
       
   204     		break;
       
   205 		default:
       
   206 			FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier:: Unkown messageType! ")); 
       
   207 			User::Leave(KErrNotFound);		
       
   208 		}
       
   209     
       
   210 	// if the logic string contains substitute indicator "%U", replace it with device name:
       
   211 	HBufC* buf = StringLoader::LoadL( iMessageResourceId);
       
   212 	iQueryMessage.Assign( buf );
       
   213 	
       
   214     TInt keyLen;
       
   215     TInt pos = BluetoothUiUtil::GetStringSubstringKeyPos( 
       
   216             iQueryMessage, 0, keyLen );
       
   217     if( pos > KErrNotFound)
       
   218 		{
       
   219 		iBTAddr = TBTDevAddr( bPckg().iRemoteAddr );
       
   220 		if( !iDevice )
       
   221 		    {
       
   222             iDevice = CBTDevice::NewL(iBTAddr);
       
   223 		    }
       
   224 	    GetDeviceFromRegL( iBTAddr );
       
   225 		}
       
   226 	else
       
   227 	    {
       
   228 	    ShowNoteAndCompleteL(aSyncCall);
       
   229 	    }
       
   230 	}
       
   231 	
       
   232 // ----------------------------------------------------------
       
   233 // CBTGenericInfoNotifier::ShowNoteAndCompleteL
       
   234 // Shows the notifier in backround 
       
   235 // ----------------------------------------------------------
       
   236 //
       
   237 void CBTGenericInfoNotifier::ShowNoteAndCompleteL(TBool aSyncCall)
       
   238 	{
       
   239 	iNotifUiUtil->ShowInfoNoteL( iQueryMessage, iSecondaryDisplayCommand );
       
   240 	if (!aSyncCall)
       
   241 		{
       
   242         CompleteMessage(KErrNone);
       
   243         }
       
   244     FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier::ShowNoteAndComplete() complete"));
       
   245 	}
       
   246 
       
   247 void CBTGenericInfoNotifier::HandleGetDeviceCompletedL(const CBTDevice* /*aDev*/)
       
   248     {
       
   249     FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier::HandleGetDeviceCompleted()"));
       
   250     
       
   251     TBTDeviceName name;
       
   252     BtNotifNameUtils::GetDeviceDisplayName(name, iDevice);
       
   253     iQueryMessage.Zero();
       
   254     BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   255             iQueryMessage, iMessageResourceId, name, 0);      
       
   256     
       
   257     ShowNoteAndCompleteL(EFalse);
       
   258 
       
   259     FLOG(_L("[BTNOTIF]\t CBTGenericInfoNotifier::HandleGetDeviceComplete() Complete"));        
       
   260     }
       
   261 
       
   262 // End of File