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