bluetoothengine/btui/Ecom/src/BTUISap.cpp
branchRCL_3
changeset 23 9386f31cc85b
equal deleted inserted replaced
22:613943a21004 23:9386f31cc85b
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  This module is created for Bluetooth SIM Access Profile 
       
    15 *				  feature variant.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <aknnotewrappers.h>
       
    20 #include <aknradiobuttonsettingpage.h>
       
    21 #include <BtuiViewResources.rsg>		// Compiled resource ids
       
    22 #include <BTSapDomainPSKeys.h>	
       
    23 #include <centralrepository.h> 
       
    24 #include <AknMediatorFacade.h>
       
    25 #include <btengconnman.h>       // for disconnect type and connection observer
       
    26 #include <btengsettings.h>
       
    27 #include <btengdevman.h>
       
    28 #include <SecondaryDisplay/BtuiSecondaryDisplayAPI.h>
       
    29 #include <btfeaturescfg.h>					// For EnterpriseEnablementL()
       
    30 #include <btnotif.h>
       
    31 #include <utf.h>
       
    32 #include <bluetoothuiutil.h>
       
    33 #include "btdevmodel.h"
       
    34 
       
    35 #include "debug.h"
       
    36 #include "BTUIMainView.h"
       
    37 
       
    38 // ----------------------------------------------------
       
    39 // CBTUIMainView::SetSapStatusL
       
    40 // ----------------------------------------------------
       
    41 //
       
    42 void CBTUIMainView::SetSapStatusL( TBTSapMode aValue )
       
    43 	{
       
    44 	TRACE_FUNC_ENTRY
       
    45 
       
    46 	TInt previousSapMode = GetSapStatusL();	
       
    47 	
       
    48 	if(previousSapMode==EBTSapEnabled)
       
    49 		previousSapMode=ETrue;
       
    50 		
       
    51 	TBool legalToChange = ETrue;
       
    52 
       
    53 	if ( ( previousSapMode ) && ( !aValue ) ) // SAP Enabled -> Disabled
       
    54 		{
       
    55 		// Check active SAP connections before query
       
    56 		TInt connStatus = EBTSapNotConnected;
       
    57         RProperty::Get(KPSUidBluetoothSapConnectionState, KBTSapConnectionState, connStatus);
       
    58 						
       
    59 		if(connStatus == EBTSapConnected) 
       
    60 			{
       
    61 			//Get name of the currently connected SAP device
       
    62 
       
    63 			TBTDeviceName connectedSap;			
       
    64 			TInt error = GetConnectedSapNameL( connectedSap ); 
       
    65 
       
    66 			if ( error )
       
    67 				{
       
    68 				TBTUIViewsCommonUtils::ShowGeneralErrorNoteL();
       
    69 				}
       
    70 			else
       
    71 				{
       
    72 
       
    73 				// Create confirmation query
       
    74 				RBuf stringholder;
       
    75 				CleanupClosePushL( stringholder );
       
    76 				BluetoothUiUtil::LoadResourceAndSubstringL( stringholder, 
       
    77 				        R_BT_DISCONNECT_FROM, connectedSap, 0 );
       
    78 				CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
    79 
       
    80 				if(iCoverDisplayEnabled)
       
    81 					{
       
    82 					CleanupStack::PushL(dlg); 						
       
    83 				    dlg->PublishDialogL(ECmdShowDisconnectQuery, KUidCoverUiCategoryBtui); // initializes cover support    
       
    84 					CAknMediatorFacade* covercl = AknMediatorFacade(dlg); // uses MOP, so control provided 
       
    85 					if (covercl) // returns null if __COVER_DISPLAY is not defined
       
    86 					    {	    
       
    87 					    covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(connectedSap);// takes copy so consts are ok too
       
    88 					    covercl->BufStream().CommitL(); // no more data to send so commit buf
       
    89 					    }
       
    90 					CleanupStack::Pop(dlg);
       
    91 					}
       
    92 					
       
    93 				TInt keypress = dlg->ExecuteLD( R_BT_DISCONNECT_FROM_QUERY, stringholder );
       
    94 
       
    95 				CleanupStack::PopAndDestroy(&stringholder);	// stringholder
       
    96 
       
    97 				if( keypress )	// User has accepted the dialog
       
    98 					{
       
    99 					legalToChange = ETrue;
       
   100 					}
       
   101 				else 
       
   102 					{
       
   103 					legalToChange = EFalse;
       
   104 					}
       
   105 				}
       
   106 			}
       
   107 		}
       
   108 			
       
   109 	else if ( ( !previousSapMode ) && ( aValue ) ) // SAP Disabled	-> Enabled 
       
   110 		{
       
   111 		
       
   112 		//if Bluetooth is off
       
   113         TBTPowerStateValue powerState;
       
   114         iBtEngSettings->GetPowerState(powerState);				
       
   115 		if(powerState!=EBTPowerOn)
       
   116 			{
       
   117 			CAknNoteDialog* dlg2 = new (ELeave) CAknNoteDialog( CAknNoteDialog::EConfirmationTone,
       
   118 																   CAknNoteDialog::ENoTimeout/*ELongTimeout*/ );
       
   119 		if(iCoverDisplayEnabled)
       
   120 			{
       
   121 			CleanupStack::PushL(dlg2); 						
       
   122 			dlg2->PublishDialogL(ECmdShowBtSapEnableNote, KUidCoverUiCategoryBtui); // initializes cover support    
       
   123 			CleanupStack::Pop(dlg2); 						
       
   124 			}
       
   125 
       
   126 			dlg2->ExecuteLD( R_BT_SAP_ENABLE_NOTE );
       
   127 			}
       
   128 	
       
   129 		}		
       
   130 
       
   131 	// Switch sapmode
       
   132 	//
       
   133 	if ( legalToChange )
       
   134 		{		
       
   135         CRepository* cenRep = NULL;
       
   136         cenRep = CRepository::NewL( KCRUidBTEngPrivateSettings );
       
   137         CleanupStack::PushL(cenRep);                         
       
   138         TInt err = cenRep->Set( KBTSapEnabled, aValue );        
       
   139         CleanupStack::PopAndDestroy(cenRep);        	
       
   140 		}		
       
   141 	TRACE_FUNC_EXIT
       
   142 	}
       
   143 
       
   144 // ----------------------------------------------------------
       
   145 // CBTUIMainView::AskSapModeDlgL
       
   146 // ----------------------------------------------------------
       
   147 //
       
   148 void CBTUIMainView::AskSapModeDlgL()
       
   149 	{
       
   150 	TRACE_FUNC_ENTRY
       
   151 
       
   152 	if ( BluetoothFeatures::EnterpriseEnablementL() == BluetoothFeatures::EDataProfilesDisabled )
       
   153 		{
       
   154 		RNotifier notifier;
       
   155         User::LeaveIfError(notifier.Connect());
       
   156         CleanupClosePushL(notifier);
       
   157 		User::LeaveIfError(notifier.StartNotifier(KBTEnterpriseItSecurityInfoNotifierUid, KNullDesC8 ));
       
   158 		CleanupStack::PopAndDestroy(&notifier);
       
   159 		}
       
   160 	else
       
   161 		{
       
   162 		CDesCArrayFlat* items = iCoeEnv->ReadDesCArrayResourceL( R_BT_SAP_MODES );
       
   163 		CleanupStack::PushL(items);	
       
   164 		
       
   165 		TInt currentItem = KErrNotFound;
       
   166 		if(GetSapStatusL() == EBTSapEnabled )
       
   167 			{
       
   168 				currentItem=0;
       
   169 			}
       
   170 		else
       
   171 			{
       
   172 				currentItem=1;
       
   173 			
       
   174 			}
       
   175 		CAknRadioButtonSettingPage* dlg = new ( ELeave )CAknRadioButtonSettingPage(
       
   176 		   R_BT_SAP_SETTING_PAGE, currentItem, items );
       
   177 		if( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ))
       
   178 			{
       
   179 			if(currentItem == 1)
       
   180 				{
       
   181 				SetSapStatusL( static_cast<TBTSapMode>(  EBTSapDisabled ) ); 
       
   182 				// Cast it back (invert again)
       
   183 				}			
       
   184 			else
       
   185 				{
       
   186 				SetSapStatusL( static_cast<TBTSapMode>(  EBTSapEnabled ) ); 
       
   187 				// Cast it back (invert again)			
       
   188 				}
       
   189 			} 
       
   190 		CleanupStack::PopAndDestroy(items); 
       
   191 		}
       
   192 	TRACE_FUNC_EXIT
       
   193 	}
       
   194 
       
   195 // ----------------------------------------------------------
       
   196 // CBTUIMainView::GetSapStatusL
       
   197 // ----------------------------------------------------------
       
   198 //
       
   199 TInt CBTUIMainView::GetSapStatusL()
       
   200 	{
       
   201 	TRACE_FUNC_ENTRY	
       
   202 	TInt sapStatus;
       
   203 	CRepository* repository = CRepository::NewL(KCRUidBTEngPrivateSettings);
       
   204 	CleanupStack::PushL(repository);            	
       
   205 	repository->Get(KBTSapEnabled, sapStatus);
       
   206 	CleanupStack::PopAndDestroy(repository);
       
   207 	TRACE_FUNC_EXIT
       
   208 	return sapStatus;	
       
   209 	}
       
   210     
       
   211 // ----------------------------------------------------------
       
   212 // CBTUIModel::GetConnectedSapNameL
       
   213 // ----------------------------------------------------------
       
   214 //
       
   215 
       
   216 TInt CBTUIMainView::GetConnectedSapNameL( TDes& aName )
       
   217 	{
       
   218 	TRACE_FUNC_ENTRY
       
   219 
       
   220     
       
   221     CBTEngConnMan* cm = CBTEngConnMan::NewL(NULL);
       
   222     CleanupStack::PushL(cm);
       
   223         
       
   224     RBTDevAddrArray devAddrArray;
       
   225     cm->GetConnectedAddresses(devAddrArray, EBTProfileSAP);
       
   226     if(devAddrArray.Count()>0)
       
   227     {
       
   228         CBTEngDevMan* devMan = CBTEngDevMan::NewL(NULL);  
       
   229          
       
   230         TBTRegistrySearch search;
       
   231         search.FindAddress(devAddrArray[0]);
       
   232         
       
   233         CBTDeviceArray* deviceArray= new (ELeave) CBTDeviceArray(devAddrArray.Count());
       
   234         //the name is in first CBTDevice in returned CBTDeviceArray. 
       
   235         devMan->GetDevices(search, deviceArray); 
       
   236         
       
   237         aName = *(CnvUtfConverter::ConvertToUnicodeFromUtf8L(deviceArray->At(0)->DeviceName()));
       
   238         
       
   239         deviceArray->ResetAndDestroy();
       
   240         delete deviceArray;
       
   241         
       
   242         delete devMan;
       
   243     }
       
   244         
       
   245     devAddrArray.Close();
       
   246     CleanupStack::PopAndDestroy(cm);               	
       
   247 	TRACE_FUNC_EXIT
       
   248 	return KErrNone;
       
   249 	}