bluetoothengine/btui/Ecom/src/BTUIPairedDevicesView.cpp
branchRCL_3
changeset 56 9386f31cc85b
child 72 4b59561a31c0
equal deleted inserted replaced
55:613943a21004 56: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 is view that handles listing and 
       
    15  *  unblocking blocked devices view.
       
    16  *
       
    17 */
       
    18 
       
    19 #include <avkon.hrh>                    // AVKON components
       
    20 #include <akntitle.h>
       
    21 #include <aknViewAppUi.h>
       
    22 #include <BtuiViewResources.rsg>        // Compiled resource ids
       
    23 #include <featmgr.h>                    // Feature Manager
       
    24 
       
    25 #include <AknGlobalNote.h>
       
    26 #include <aknnotewrappers.h>
       
    27 #include <StringLoader.h>   			// Series 60 localisation stringloader
       
    28 #include <AknMediatorFacade.h>
       
    29 #include <aknmessagequerydialog.h>
       
    30 #include <aknnotewrappers.h>
       
    31 #include <aknnavi.h>
       
    32 #include <hlplch.h>         			// Help launcher
       
    33 #include <btengdiscovery.h> 			// for device search
       
    34 
       
    35 #include <ctsydomainpskeys.h>
       
    36 #include <bt_subscribe.h>
       
    37 #include <btengsettings.h>
       
    38 #include <centralrepository.h>
       
    39 #include <CoreApplicationUIsSDKCRKeys.h>
       
    40 #include <bamdesca.h>
       
    41 
       
    42 #include "debug.h"             
       
    43 #include "btui.h" 						// Global declarations
       
    44 #include "BTUIPairedDevicesView.h"
       
    45 #include "BTUIDeviceContainer.h"
       
    46 #include <SecondaryDisplay/BtuiSecondaryDisplayAPI.h>
       
    47 #include <csxhelp/bt.hlp.hrh>   // Help IDs
       
    48 
       
    49 #include <gstabhelper.h>
       
    50 #include <btui.mbg>						// Tab icon for General Setting
       
    51 #include <bluetoothuiutil.h>
       
    52 #include "BTUIMainView.h" 				// base View.
       
    53 
       
    54 
       
    55 const TInt KAutoConnect2ndTry = 1;
       
    56 const TUint32 SetExcludePairedDeviceMask = 0x800000;
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CBTUIPairedDevicesView::NewL
       
    62 // Two phased constructor called by BT AppUI when serve as part of btui.exe
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 CBTUIPairedDevicesView* CBTUIPairedDevicesView::NewL(MBtuiPluginViewActivationObserver* aObserver)
       
    66     {
       
    67     CBTUIPairedDevicesView* self = new (ELeave) CBTUIPairedDevicesView(aObserver);
       
    68 	CleanupStack::PushL(self);
       
    69 	
       
    70 	self->iConstructAsGsPlugin = EFalse;	
       
    71  	self->ConstructL();
       
    72 	CleanupStack::Pop(self);
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CBTUIPairedDevicesView::NewLC
       
    78 // Two phased constructor called by mainView when serve as GS Plugin.
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 CBTUIPairedDevicesView* CBTUIPairedDevicesView::NewLC(CBTUIMainView* aBaseView, CArrayPtrFlat<MGSTabbedView>* aTabViewArray)
       
    82     {
       
    83     CBTUIPairedDevicesView* self = new (ELeave) CBTUIPairedDevicesView();    
       
    84 	CleanupStack::PushL( self );
       
    85 		
       
    86 	self->iConstructAsGsPlugin = ETrue;
       
    87  	self->ConstructL( aBaseView, aTabViewArray );
       
    88 
       
    89     return self;
       
    90     }
       
    91     
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CBTUIPairedDevicesView::ConstructL
       
    95 // Symbian 2nd phase constructor can leave.
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 void CBTUIPairedDevicesView::ConstructL()
       
    99     {
       
   100 	TRACE_FUNC_ENTRY
       
   101 
       
   102     BaseConstructL(R_BTUI_OTHER_DEVICES_VIEW);
       
   103 
       
   104     iCoverDisplayEnabled = FeatureManager::FeatureSupported(KFeatureIdCoverDisplay); 
       
   105     iHelpEnabled = FeatureManager::FeatureSupported(KFeatureIdHelp);
       
   106     
       
   107    	iDeviceSearcher = CBTEngDiscovery::NewL(this);   	
       
   108 	iBtEngSettings = CBTEngSettings::NewL(this);
       
   109 	iBTPluginMan = CBTUIPluginMan::NewL( AppUi() );
       
   110 	iIsAlreadyConnected = EFalse;
       
   111 	iExpectedCallBack = 0;
       
   112 	TRACE_INFO(_L("Initial iIsAlreadyConnected -> False"))
       
   113     TRACE_FUNC_EXIT
       
   114     }
       
   115 
       
   116 void CBTUIPairedDevicesView::ConstructL( CBTUIMainView* aBaseView, CArrayPtrFlat<MGSTabbedView>* aTabViewArray )
       
   117     {
       
   118     TRACE_FUNC_ENTRY
       
   119     
       
   120 	iBaseView = aBaseView,
       
   121     iTabHelper = CGSTabHelper::NewL();
       
   122     aTabViewArray->AppendL(this); 
       
   123     
       
   124     BaseConstructL(R_BTUI_OTHER_DEVICES_VIEW_GS);
       
   125     iCoverDisplayEnabled = FeatureManager::FeatureSupported(KFeatureIdCoverDisplay); 
       
   126     iHelpEnabled = FeatureManager::FeatureSupported(KFeatureIdHelp);
       
   127     
       
   128    	iDeviceSearcher = CBTEngDiscovery::NewL(this);
       
   129     iBtEngSettings=CBTEngSettings::NewL(this);	
       
   130     iBTPluginMan = CBTUIPluginMan::NewL( AppUi() );
       
   131 	iIsAlreadyConnected = EFalse;
       
   132 	TRACE_INFO(_L("Initial iIsAlreadyConnected = False"))
       
   133     iExpectedCallBack = 0;
       
   134 	
       
   135 	TRACE_FUNC_EXIT
       
   136     }
       
   137   
       
   138 // ---------------------------------------------------------
       
   139 // CBTUIBlockedDevicesView::CBTUIBlockedDevicesView
       
   140 // ---------------------------------------------------------
       
   141     
       
   142 CBTUIPairedDevicesView::CBTUIPairedDevicesView( MBtuiPluginViewActivationObserver* aObserver )
       
   143 	: iActivationObserver(aObserver)
       
   144 	{
       
   145 	}        
       
   146 
       
   147 // ---------------------------------------------------------
       
   148 // Destructor
       
   149 // ---------------------------------------------------------
       
   150 //
       
   151 CBTUIPairedDevicesView::~CBTUIPairedDevicesView()
       
   152     {
       
   153 	TRACE_FUNC_ENTRY
       
   154 
       
   155 	//close dialogs if any
       
   156 	TRAP_IGNORE(
       
   157 		DialogDismissedL(EAknSoftkeyCancel);
       
   158 	);
       
   159 
       
   160 	delete iActive;
       
   161 	
       
   162     if (iContainer)
       
   163         {
       
   164         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   165 		delete iContainer;           
       
   166 		iContainer = NULL;
       
   167         }
       
   168             
       
   169     if(iDeviceSearcher)
       
   170         {
       
   171     	// Canceling devicesearches is done by DialogDismissedL(),
       
   172     	// so it is not done here    	
       
   173     	delete iDeviceSearcher;
       
   174     	iDeviceSearcher = NULL ;
       
   175         }
       
   176 	delete iConnectDevice;
       
   177 	iConnectDevice=NULL;
       
   178 	
       
   179 	delete iPairingDevice;
       
   180 	delete iBtEngSettings;
       
   181 	delete iBTPluginMan;
       
   182 	
       
   183 	if(iConstructAsGsPlugin)
       
   184 	    	delete iTabHelper;	
       
   185 	
       
   186 	CancelDisconnectQueryDlg();
       
   187 	
       
   188     TRACE_FUNC_EXIT
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // From CAknView
       
   193 // CBTUIPairedDevicesView::Id
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 TUid CBTUIPairedDevicesView::Id() const
       
   197     {
       
   198 	TRACE_FUNC_ENTRY    
       
   199     return KBtuiPluginUidPairedDevicesView;//KBTOtherDevicesViewId;
       
   200     }
       
   201 
       
   202 
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // From CAknView
       
   207 // CBTUIPairedDevicesView::HandleCommandL 
       
   208 // Redirects commands to the appui class.
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 void CBTUIPairedDevicesView::HandleCommandL(TInt aCommand)
       
   212     {
       
   213 	TRACE_FUNC_ENTRY
       
   214 
       
   215     switch (aCommand)
       
   216         {
       
   217         
       
   218         case EAknSoftkeyBack:      
       
   219             // do not exit if devicechange is in progress.
       
   220             if(iModel->DeviceChangeInProgress() )
       
   221             	return;                
       
   222 	        AppUi()->ActivateLocalViewL(iBaseView->GetParentView().iViewUid );
       
   223             break;
       
   224             
       
   225         case EAknSoftkeyExit:
       
   226             {
       
   227 			TRACE_INFO(_L("EAknSoftkeyExit"))
       
   228             // do not exit if devicechange or bt discovery is in progress.				
       
   229             if(iModel->DeviceChangeInProgress() 
       
   230                     || iSearchOngoing )   
       
   231             	{
       
   232             	TRACE_INFO(_L("exit denied, due to operation"))
       
   233             	return;
       
   234 	           	}
       
   235 	           	
       
   236 			TRACE_INFO(_L("exit in progress"))
       
   237 			AppUi()->ProcessCommandL(EEikCmdExit);            
       
   238             break;
       
   239             }
       
   240 
       
   241         case EAknCmdHelp:
       
   242             {
       
   243             #ifdef __SERIES60_HELP
       
   244                 HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(),AppUi()->AppHelpContextL());
       
   245             #endif
       
   246             break;
       
   247             }          
       
   248         	
       
   249         case EBTUICmdNewPairedDevice:
       
   250             {
       
   251             iSearchOngoing=ETrue;
       
   252             NewPairedDeviceDlgL();
       
   253             break;
       
   254             }
       
   255 
       
   256         case EBTUICmdDelete:
       
   257             {
       
   258             DeleteDeviceDlgL();
       
   259             break;
       
   260             }
       
   261 
       
   262         case EBTUICmdDeleteAll:
       
   263             {
       
   264             DeleteAllDevicesDlgL();
       
   265             break;
       
   266             }
       
   267 
       
   268         case EBTUICmdGiveNickname:
       
   269             {
       
   270             RenameDeviceDlgL();
       
   271             break;
       
   272             }
       
   273 
       
   274         case EBTUICmdSetTrusted:
       
   275             {
       
   276             ChangeDeviceSecurityL(ETrue);
       
   277             break;
       
   278             }
       
   279 
       
   280         case EBTUICmdSetUnTrusted:
       
   281             {
       
   282             ChangeDeviceSecurityL(EFalse);
       
   283             break;
       
   284             }
       
   285 
       
   286         case EBTUICmdConnect:
       
   287         case EBTUICmdConnectAudio: 
       
   288             {
       
   289             TBTDevice device;
       
   290             device.iIndex = iContainer->CurrentItemIndex();
       
   291             iModel->GetDevice(device);
       
   292             if ( device.iStatus & EStatusBtuiConnected )
       
   293                 {
       
   294                 // If device is already connected, we do nothing here. 
       
   295                 break;
       
   296                 }
       
   297             device.iOperation = EOpConnect;
       
   298             ConnectL( device, ETrue );
       
   299 	        break;            	
       
   300             }
       
   301 
       
   302         case EBTUICmdDisconnect:
       
   303             {
       
   304             DisconnectL();
       
   305             break;
       
   306             }
       
   307   
       
   308         case EBTUICmdSetBlocked:
       
   309         	{
       
   310         	BlockDeviceDlgL();
       
   311         	break;
       
   312         	}
       
   313         	
       
   314         case EBTUICmdSettings:
       
   315         	{
       
   316         	LaunchSettingViewL();
       
   317         	break;
       
   318         	}
       
   319         	
       
   320         default:
       
   321             {
       
   322             AppUi()->HandleCommandL(aCommand);
       
   323             break;
       
   324             }
       
   325         }
       
   326 	TRACE_FUNC_EXIT        
       
   327     }
       
   328 
       
   329 
       
   330 // ---------------------------------------------------------
       
   331 // From CAknView
       
   332 // CBTUIPairedDevicesView::DoActivateL
       
   333 // ---------------------------------------------------------
       
   334 //
       
   335 void CBTUIPairedDevicesView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
       
   336                                                TUid /*aCustomMessageId*/,
       
   337                                          const TDesC8& /*aCustomMessage*/)
       
   338     {
       
   339 	TRACE_FUNC_ENTRY
       
   340 
       
   341     iModel = CBTDevModel::NewL(EGroupPaired, this);
       
   342     iContainer = CBTUiDeviceContainer::NewL(ClientRect(), this, EGroupPaired, this);
       
   343     iContainer->SetMopParent(this); // MObjectProvider
       
   344 
       
   345     // Setup title
       
   346     HBufC* btTitlePairedDevices = 
       
   347     	iCoeEnv->AllocReadResourceLC(R_BT_TITLE_PAIRED_DEV);
       
   348     CEikStatusPane* statusPane = StatusPane();
       
   349     CAknTitlePane* titlePane;
       
   350     titlePane = (CAknTitlePane*) statusPane->ControlL(
       
   351     	TUid::Uid(EEikStatusPaneUidTitle));
       
   352     titlePane->SetTextL(btTitlePairedDevices->Des());
       
   353     CleanupStack::PopAndDestroy(btTitlePairedDevices); // btTitlePairedDevices
       
   354     btTitlePairedDevices = NULL;
       
   355 
       
   356     AppUi()->AddToStackL(*this, iContainer);
       
   357 
       
   358     if( iBaseView && iConstructAsGsPlugin)
       
   359         {
       
   360         iTabHelper->CreateTabGroupL( Id(), 
       
   361             static_cast<CArrayPtrFlat<MGSTabbedView>*>
       
   362             (iBaseView->TabbedViews()) ); 
       
   363         } 
       
   364         
       
   365 	// MSK menu is added here.
       
   366 	// the left key menu is added by resources.
       
   367     MenuBar()->SetContextMenuTitleResourceId(
       
   368     	R_BTUI_MENUBAR_OTHER_DEVICES_VIEW_CONTEXT);		
       
   369 	// notify observer   
       
   370     if( iActivationObserver  && iConstructAsGsPlugin == EFalse)
       
   371     {    	    
       
   372         iActivationObserver->PluginViewActivated(EPairedDevicesViewId);        
       
   373     }
       
   374 
       
   375 	TRACE_FUNC_EXIT
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------
       
   379 // From CAknView
       
   380 // CBTUIPairedDevicesView::DoDeactivate
       
   381 // ---------------------------------------------------------
       
   382 //
       
   383 void CBTUIPairedDevicesView::DoDeactivate()
       
   384     {
       
   385 	TRACE_FUNC_ENTRY
       
   386 
       
   387     if (iContainer)
       
   388         {
       
   389         AppUi()->RemoveFromStack(iContainer);
       
   390         delete iContainer;
       
   391         iContainer = NULL;
       
   392         }
       
   393 	if ( iDeviceSearcher )
       
   394 	    {
       
   395 	    iDeviceSearcher->CancelSearchRemoteDevice();
       
   396 	    }
       
   397     delete iModel;
       
   398     iModel=NULL;
       
   399     if(iConstructAsGsPlugin)
       
   400 	    iTabHelper->RemoveTabGroup();  
       
   401     delete iActive;
       
   402     iActive = NULL;
       
   403     iIsPairConnect = EFalse;
       
   404     TRACE_FUNC_EXIT
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------
       
   408 // From CAknView
       
   409 // CBTUIPairedDevicesView::DynInitMenuPaneL
       
   410 // Shows only options supported for selected device, if any.
       
   411 // If not show only options supported regardless of selected
       
   412 // device
       
   413 // ---------------------------------------------------------
       
   414 //
       
   415 void CBTUIPairedDevicesView::DynInitMenuPaneL(TInt aResId, CEikMenuPane* aMenu)
       
   416     {
       
   417 	TRACE_FUNC_ENTRY
       
   418 	
       
   419 	// dim help if it exists and is not supported	
       
   420 	TInt tmp;	
       
   421 	if (  aMenu->MenuItemExists(EAknCmdHelp,tmp ) )			
       
   422 		{			
       
   423 		aMenu->SetItemDimmed(EAknCmdHelp,
       
   424 		  !FeatureManager::FeatureSupported( KFeatureIdHelp ) );
       
   425 		}
       
   426 	
       
   427 	if ( aResId == R_BTUI_OTHER_DEVICES_VIEW_MENU  )
       
   428 	    {
       
   429 
       
   430         TInt index = iContainer->CurrentItemIndex();
       
   431     
       
   432         if ( index < 0 ) // No devices at list. Hide all device related commands.
       
   433             {
       
   434             aMenu->SetItemDimmed(EBTUICmdDeleteAll, ETrue); 
       
   435             }
       
   436         else
       
   437             {
       
   438             SetupMenuCmd(index, aMenu);             
       
   439             }        
       
   440 	    }
       
   441 	
       
   442     if ( aResId == R_BTUI_OTHER_DEVICES_VIEW_MENU_CONTEXT )
       
   443         {
       
   444         iActiveMenuPane = aMenu;
       
   445         TInt index = iContainer->CurrentItemIndex();
       
   446    
       
   447         // If user is fast enough to click the RSK option between 
       
   448         // bt discovery view and device found view,  bt ui will crash.
       
   449         // Therefore, we disable commands if bt discovery is onging.
       
   450         //          
       
   451         if(iSearchOngoing)
       
   452             {
       
   453             aMenu->SetItemDimmed(EBTUICmdGiveNickname, ETrue);
       
   454             aMenu->SetItemDimmed(EBTUICmdSetTrusted, ETrue);
       
   455             aMenu->SetItemDimmed(EBTUICmdSetUnTrusted, ETrue);
       
   456             aMenu->SetItemDimmed(EBTUICmdSetBlocked, ETrue);
       
   457             aMenu->SetItemDimmed(EBTUICmdDelete, ETrue);
       
   458             aMenu->SetItemDimmed(EBTUICmdConnect, ETrue);
       
   459             aMenu->SetItemDimmed(EBTUICmdConnectAudio, ETrue);
       
   460             aMenu->SetItemDimmed(EBTUICmdDisconnect, ETrue);            
       
   461             aMenu->SetItemDimmed(EBTUICmdNewPairedDevice, ETrue);
       
   462             return;
       
   463             }
       
   464         
       
   465         if(index < 0)  // No devices at list. Hide all device related commands.
       
   466             {            
       
   467             TRACE_INFO(_L("no devices in list"))
       
   468             
       
   469             aMenu->SetItemDimmed(EBTUICmdGiveNickname, ETrue);
       
   470             aMenu->SetItemDimmed(EBTUICmdSetTrusted, ETrue);
       
   471             aMenu->SetItemDimmed(EBTUICmdSetUnTrusted, ETrue);
       
   472             aMenu->SetItemDimmed(EBTUICmdSetBlocked, ETrue);
       
   473             aMenu->SetItemDimmed(EBTUICmdDelete, ETrue);
       
   474             aMenu->SetItemDimmed(EBTUICmdConnect, ETrue);
       
   475             aMenu->SetItemDimmed(EBTUICmdConnectAudio, ETrue);
       
   476             aMenu->SetItemDimmed(EBTUICmdDisconnect, ETrue);
       
   477             aMenu->SetItemDimmed(EBTUICmdSettings, ETrue);
       
   478             }
       
   479         else // There are devices at list
       
   480             {
       
   481             SetupMenuCmd(index, aMenu);
       
   482             //Hide New pair device in context menu
       
   483             aMenu->SetItemDimmed(EBTUICmdNewPairedDevice, ETrue);
       
   484             }
       
   485         }
       
   486 	TRACE_FUNC_EXIT        
       
   487     }
       
   488     
       
   489 
       
   490 // ----------------------------------------------------------
       
   491 // CBTUIPairedDevicesView::RenameDeviceDlgL
       
   492 // ----------------------------------------------------------
       
   493 //
       
   494 void CBTUIPairedDevicesView::RenameDeviceDlgL()
       
   495     {
       
   496 	TRACE_FUNC_ENTRY
       
   497 
       
   498 	TInt index = iContainer->CurrentItemIndex();
       
   499 	if(index == KErrNotFound) return;
       
   500     
       
   501 	TBTDevice device;
       
   502     device.iIndex = index;
       
   503 	iModel->GetDevice(device);
       
   504 	TBTDeviceName name = device.iName;
       
   505 	
       
   506     CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(device.iName);
       
   507     TInt keypress = dlg->ExecuteLD(R_BT_ENTER_NICKNAME_QUERY);
       
   508 
       
   509     if(keypress)  // User has accepted the dialog
       
   510         {
       
   511         if(device.iName != name) // Check if the user really changed the name
       
   512         	{
       
   513     		device.iOperation = EOpChangeName;        
       
   514     		// Remove trouble making control chars
       
   515 		    AknTextUtils::StripCharacters(device.iName, KAknStripListControlChars);    
       
   516 	        device.iName.TrimAll();  // Remove extra spaces    		
       
   517         	iModel->ChangeDevice(device);        	
       
   518         	}
       
   519         }
       
   520 	TRACE_FUNC_EXIT        
       
   521     }
       
   522     
       
   523 
       
   524 // ----------------------------------------------------------
       
   525 // CBTUIPairedDevicesView::NewPairedDeviceDlgL
       
   526 //
       
   527 // Initiate bonding (pairing) by opening the search dialog.
       
   528 // DeviceSearchComplete is called after that.
       
   529 // ----------------------------------------------------------
       
   530 //
       
   531 void CBTUIPairedDevicesView::NewPairedDeviceDlgL()
       
   532 	{
       
   533 	TRACE_FUNC_ENTRY	
       
   534 	// we must not have other pairing in progress.
       
   535 	// we maight issue an error, but none is defined by 
       
   536 	// ui spec. Anyhow this should be possible
       
   537 	// only by pressing everything roo rapidly.
       
   538 	if(iPairingDevice!=NULL)
       
   539 		return;
       
   540 	iPairingDevice = CBTDevice::NewL();
       
   541 	
       
   542 	// Here we use last bit in device class to inform bt inquiry notifier 
       
   543 	// not to display the device which is already paired and in the paired 
       
   544 	// device list.  
       
   545 	    
       
   546 	// We use DeviceClass to tell btnotif not to show paired device in 
       
   547 	// bt discovery notifier through bteng.
       
   548 	// Set bit 24 to 1 ( bit 24 is not used for any other purpose currently )	
       
   549 	iPairingDevice->SetDeviceClass(iPairingDevice->DeviceClass().DeviceClass() | SetExcludePairedDeviceMask );
       
   550 	TInt err = iDeviceSearcher->SearchRemoteDevice(iPairingDevice,
       
   551                                                    &iPairingDevNameEntry, 
       
   552                                                    iPairingDevice->DeviceClass().DeviceClass());
       
   553 
       
   554 
       
   555 	if(err != KErrNone)
       
   556 		{
       
   557 		delete iPairingDevice;
       
   558 		iPairingDevice=NULL;
       
   559         TBTUIViewsCommonUtils::ShowGeneralErrorNoteL();        
       
   560     	}
       
   561 	TRACE_FUNC_EXIT    	
       
   562 	}
       
   563 
       
   564 // ----------------------------------------------------------
       
   565 // CBTUIPairedDevicesView::DeleteDeviceDlgL
       
   566 // ----------------------------------------------------------
       
   567 //
       
   568 void CBTUIPairedDevicesView::DeleteDeviceDlgL()
       
   569     {
       
   570 	TRACE_FUNC_ENTRY
       
   571 	
       
   572     iExpectedCallBack = 0;
       
   573 	TInt index = iContainer->CurrentItemIndex();
       
   574 	if(index == KErrNotFound) return;
       
   575 
       
   576     TBTDevice device;
       
   577     device.iIndex = index;
       
   578     iModel->GetDevice(device);
       
   579 
       
   580     RBuf stringholder;
       
   581     CleanupClosePushL( stringholder );
       
   582 
       
   583 	TInt tmp=EStatusBtuiConnected|EStatusPhysicallyConnected;
       
   584     // Choose confirmation phrase
       
   585     TInt resourceId = ( device.iStatus & tmp ) ? R_BT_WARN_ERASE_CONNECTED :
       
   586         R_BT_WARN_ERASE;
       
   587     BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   588             stringholder, resourceId, device.iName, 0 );
       
   589 
       
   590     // Create confirmation query
       
   591     //
       
   592     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   593 
       
   594 	if(iCoverDisplayEnabled)
       
   595 		{
       
   596         CleanupStack::PushL(dlg); 
       
   597 	    dlg->PublishDialogL(ECmdShowBtWarnEraseNote, KUidCoverUiCategoryBtui); 
       
   598 	    // initializes cover support    
       
   599         CleanupStack::Pop(dlg); 
       
   600 
       
   601 		CAknMediatorFacade* covercl = AknMediatorFacade(dlg); // uses MOP, so control provided 
       
   602 		if (covercl) // returns null if __COVER_DISPLAY is not defined
       
   603 		    {	    
       
   604 		    covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(device.iName) ;// takes copy so consts are ok too
       
   605 		    covercl->BufStream().CommitL(); // no more data to send so commit buf
       
   606 		    }  
       
   607 		}
       
   608     TInt keypress = dlg->ExecuteLD(R_BT_WARN_ERASE_QUERY, stringholder);
       
   609 
       
   610     CleanupStack::PopAndDestroy(&stringholder);  // stringholder
       
   611 
       
   612     if(keypress)  // User has accepted the dialog
       
   613         {
       
   614         // If device is connected we need to first to disconnect 
       
   615         // then unpair, otherwise unpairing does not succeed.
       
   616         if((device.iStatus & EStatusBtuiConnected) == EStatusBtuiConnected)
       
   617         {
       
   618             iExpectedCallBack++;
       
   619             DisconnectWithoutQuery();            
       
   620             return;
       
   621         }
       
   622         device.iOperation = EOpUnpair;
       
   623         iModel->ChangeDevice(device);       
       
   624         }
       
   625 
       
   626 	TRACE_FUNC_EXIT
       
   627     }
       
   628 
       
   629 // ----------------------------------------------------------
       
   630 // CBTUIPairedDevicesView::DeleteAllDevicesDlgL
       
   631 // ----------------------------------------------------------
       
   632 //
       
   633 void CBTUIPairedDevicesView::DeleteAllDevicesDlgL()
       
   634     {
       
   635 	TRACE_FUNC_ENTRY
       
   636 	
       
   637     iExpectedCallBack = 0;
       
   638     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   639     TInt keypress = KErrNone;
       
   640     
       
   641     CleanupStack::PushL(dlg); 
       
   642 
       
   643     // Choose and execute confirmation query
       
   644     //
       
   645     if (iModel->IsAnyDeviceConnected())
       
   646         {
       
   647 		if(iCoverDisplayEnabled)
       
   648 			{
       
   649             dlg->PublishDialogL(ECmdShowBtWarnEraseAllConnectedQuery, KUidCoverUiCategoryBtui); // initializes cover support    
       
   650 			}
       
   651 
       
   652         keypress = dlg->ExecuteLD(R_BT_WARN_ERASE_ALL_CONNECTED_QUERY);
       
   653         }
       
   654     else
       
   655         {        
       
   656 		if(iCoverDisplayEnabled)
       
   657 			{
       
   658 	        dlg->PublishDialogL(ECmdShowBtWarnEraseAllQuery, KUidCoverUiCategoryBtui); // initializes cover support    
       
   659 			}
       
   660 
       
   661         keypress = dlg->ExecuteLD(R_BT_WARN_ERASE_ALL_QUERY);
       
   662         }
       
   663     CleanupStack::Pop(dlg); 
       
   664 
       
   665     if(keypress)  // User has accepted the dialog
       
   666         {
       
   667         TInt count = iContainer->CountItems();   
       
   668         for (TInt i = 0; i < count; i++)
       
   669            {
       
   670            // If device is connected we need to first to disconnect 
       
   671            // then unpair, otherwise unpairing does not succeed.                      
       
   672            TBTDevice device;
       
   673            device.iIndex = i;
       
   674            iModel->GetDevice(device);
       
   675            if((device.iStatus & EStatusBtuiConnected) == EStatusBtuiConnected)
       
   676                {
       
   677                iExpectedCallBack++;
       
   678                }
       
   679            }
       
   680         TRACE_INFO((_L("iExpectedCallBack %d"), iExpectedCallBack ))
       
   681         
       
   682         for (TInt i = 0; i < count; i++)
       
   683             {
       
   684             // If device is connected we need to first to disconnect 
       
   685             // then unpair, otherwise unpairing does not succeed.                      
       
   686             TBTDevice device;
       
   687             device.iIndex = i;
       
   688             iModel->GetDevice(device);           
       
   689             
       
   690             if((device.iStatus & EStatusBtuiConnected) == EStatusBtuiConnected)
       
   691                 {
       
   692                 //disconnect it first, removal will be done in 
       
   693                 //callback NotifyChangeDeviceCompleteL for ChangeDevice() below
       
   694                 TRACE_INFO((_L("EOpDisconnect issued for %d"), i ))
       
   695                 device.iOperation = EOpDisconnect;
       
   696                 iModel->ChangeDevice(device);  
       
   697                 }
       
   698             else
       
   699                 {
       
   700                 //otherwise, just remove it from the paired view
       
   701                 device.iOperation = EOpUnpair;
       
   702                 iModel->ChangeDevice(device);
       
   703                 }
       
   704             }
       
   705         }
       
   706 
       
   707 	TRACE_FUNC_EXIT
       
   708     }
       
   709 // ----------------------------------------------------------
       
   710 // CBTUIPairedDevicesView::BlockDeviceDlgL
       
   711 // ----------------------------------------------------------
       
   712 void CBTUIPairedDevicesView::BlockDeviceDlgL()
       
   713 	{
       
   714 	TRACE_FUNC_ENTRY
       
   715 
       
   716 	TInt index = iContainer->CurrentItemIndex();
       
   717 	if(index == KErrNotFound) return;
       
   718 			
       
   719     TBTDevice device;
       
   720     device.iIndex = index;
       
   721     iModel->GetDevice(device);
       
   722 
       
   723 	//check if this is connected device
       
   724 		
       
   725 	HBufC* header= iCoeEnv->AllocReadResourceLC(R_BT_OPTION_BLOCK_DEVICE_HEADER); 
       
   726 	
       
   727 	RBuf stringHolder;
       
   728 	CleanupClosePushL( stringHolder );
       
   729 	TInt resouseId;
       
   730 	if (device.iStatus & (EStatusBtuiConnected|EStatusPhysicallyConnected) )
       
   731 	    {
       
   732 	    resouseId = iHelpEnabled? R_BT_OPTION_BLOCK_PAIRED_DEVICE_HELP : 
       
   733             R_BT_OPTION_BLOCK_PAIRED_DEVICE_NOHELP;
       
   734 	    }
       
   735 	else
       
   736 	    {
       
   737 	    resouseId = iHelpEnabled ? R_BT_OPTION_BLOCK_PAIRED_DEVICE_HELP :
       
   738             R_BT_OPTION_BLOCK_PAIRED_DEVICE_NOHELP;
       
   739 	    }
       
   740 	BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   741 	        stringHolder, resouseId, device.iName, 0 );
       
   742 	
       
   743 	CAknMessageQueryDialog *queryDialog = CAknMessageQueryDialog::NewL (stringHolder, 
       
   744 	  CAknQueryDialog::EConfirmationTone);		
       
   745 	queryDialog->PrepareLC(R_BT_MESSAGE_QUERY);
       
   746 	
       
   747 	(queryDialog)->Heading()->SetTextL(*header);
       
   748 	queryDialog->SetFocus(ETrue);
       
   749 
       
   750     TInt keypress=EFalse;
       
   751 #ifdef __SERIES60_HELP    
       
   752 	if (iHelpEnabled)
       
   753         {
       
   754 		HBufC* queryLink = StringLoader::LoadL(R_BT_BLOCK_DEVICE_LINK);
       
   755 		TCoeHelpContext hc(KBtuiUid3,KBT_HLP_BLOCKED);
       
   756 		TCallBack helpCallBack(CBTUIPairedDevicesView::LaunchHelp , &hc);
       
   757 		
       
   758 		TRAPD(err,
       
   759 			static_cast<CAknMessageQueryDialog*>(queryDialog)->SetLinkTextL(*queryLink);
       
   760 			static_cast<CAknMessageQueryDialog*>(queryDialog)->SetLink(helpCallBack););
       
   761 		if(err==KErrNone)
       
   762 			{
       
   763 			keypress = queryDialog->RunLD();
       
   764 			}
       
   765         	
       
   766 		delete queryLink; 
       
   767         queryLink = NULL;
       
   768         }
       
   769     else
       
   770 #endif    
       
   771         {
       
   772         keypress = queryDialog->RunLD();
       
   773         }
       
   774 	
       
   775 	CleanupStack::PopAndDestroy(&stringHolder);  				 
       
   776 	CleanupStack::PopAndDestroy(header);
       
   777 	        
       
   778 	if(keypress)
       
   779 		{
       
   780 		device.iOperation = EOpBlock;
       
   781 		iModel->ChangeDevice(device);
       
   782 		}
       
   783 	TRACE_FUNC_EXIT		
       
   784 	}
       
   785 // ----------------------------------------------------------
       
   786 // CBTUIPairedDevicesView::ChangeDeviceSecurityL
       
   787 // ----------------------------------------------------------
       
   788 //
       
   789 void CBTUIPairedDevicesView::ChangeDeviceSecurityL(TBool aTrusted)
       
   790     {
       
   791    	TRACE_FUNC_ENTRY
       
   792 
       
   793 	TInt index = iContainer->CurrentItemIndex();
       
   794 	if(index == KErrNotFound) return;
       
   795 			
       
   796     TBTDevice device;
       
   797     device.iIndex = index;
       
   798     iModel->GetDevice(device);
       
   799     
       
   800     if(aTrusted)
       
   801         {
       
   802         // set to trusted
       
   803         CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   804         
       
   805 		if(iCoverDisplayEnabled)
       
   806 			{
       
   807 			CleanupStack::PushL(dlg); 
       
   808 	        dlg->PublishDialogL(ECmdShowBtAuthConfirmQuery, KUidCoverUiCategoryBtui); // initializes cover support    
       
   809 		    CleanupStack::Pop(dlg); 
       
   810 			}
       
   811         TInt keypress = dlg->ExecuteLD(R_BT_SET_TRUSTED_QUERY);
       
   812 
       
   813         if(keypress)  // User has accepted the dialog
       
   814             {
       
   815             device.iOperation = EOpTrust;
       
   816             iModel->ChangeDevice(device);
       
   817             }
       
   818         }
       
   819     else
       
   820         {
       
   821         device.iOperation = EOpUntrust;
       
   822         iModel->ChangeDevice(device);        
       
   823         }
       
   824 	TRACE_FUNC_EXIT        
       
   825     }
       
   826     
       
   827 // ----------------------------------------------------
       
   828 // CBTUIMainView::VisibilityModeChanged
       
   829 // ----------------------------------------------------
       
   830 //    
       
   831 void CBTUIPairedDevicesView::VisibilityModeChanged( TBTVisibilityMode  )
       
   832     {
       
   833 	TRACE_FUNC_ENTRY
       
   834 	
       
   835 	
       
   836 	TRACE_FUNC_EXIT	
       
   837     }
       
   838     
       
   839         
       
   840 // ----------------------------------------------------
       
   841 // CBTUIMainView::PowerStateChanged
       
   842 // ----------------------------------------------------
       
   843 //
       
   844 void CBTUIPairedDevicesView::PowerStateChanged( TBTPowerStateValue  )
       
   845     {
       
   846 	TRACE_FUNC_ENTRY
       
   847 	
       
   848 	if ( iIsConnectDevice )
       
   849 		{
       
   850 		iModel->ChangeDevice(*iConnectDevice);
       
   851 		iIsConnectDevice = EFalse;   // reset flag
       
   852 		}
       
   853 	
       
   854 	TRACE_FUNC_EXIT	
       
   855     }
       
   856     
       
   857 // ----------------------------------------------------------
       
   858 // CBTUIPairedDevicesView::ConnectL
       
   859 // ----------------------------------------------------------
       
   860 //
       
   861 void CBTUIPairedDevicesView::ConnectL(
       
   862         const TBTDevice& aDevice, TBool aNewWaitNote )
       
   863 	{
       
   864 	TRACE_FUNC_ENTRY
       
   865 	
       
   866 	iIsAlreadyConnected = EFalse;
       
   867 	TRACE_INFO(_L("Set iIsAlreadyConnected -> False"))
       
   868 	//Check that there is not more than max amount of connections allready.		
       
   869 	TInt connNum = 0;
       
   870     RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, connNum);
       
   871 	if(connNum > KBtUiMaxConnections) 
       
   872   		{
       
   873         ConnectCompleteL(KErrServerBusy, aDevice);
       
   874   		}
       
   875   	else if(CallOnGoing()&& connNum > 1)
       
   876 	  	{
       
   877     	CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog(CAknNoteDialog::ENoTone,
       
   878                                                        CAknNoteDialog::ELongTimeout);
       
   879 		if(iCoverDisplayEnabled)
       
   880 			{
       
   881 			CleanupStack::PushL(dlg); 
       
   882     		dlg->PublishDialogL(ECmdShowBtImpossibleIncallNote, KUidCoverUiCategoryBtui); // initializes cover support    
       
   883 			CleanupStack::Pop(dlg); 
       
   884 			}
       
   885 	
       
   886     	dlg->ExecuteLD(R_BT_NOT_INCALL_NOTE);    	
       
   887   		}
       
   888     else
       
   889         {
       
   890 		if(TBTUIViewsCommonUtils::TurnBTOnIfNeededL(iBtEngSettings,iCoverDisplayEnabled)!= KErrNone)
       
   891 			return;
       
   892 		
       
   893 		TInt errorCode = KErrNone;  
       
   894 		TBTPowerStateValue currentPowerMode;		
       
   895 		errorCode=iBtEngSettings->GetPowerState(currentPowerMode); 
       
   896 		
       
   897 	    if(errorCode)    
       
   898 	    	{
       
   899 	    	// handle the error code
       
   900 	    	return;
       
   901 	    	}
       
   902 	    if ( aNewWaitNote )
       
   903 	        {
       
   904             // Launch wait note              
       
   905             OpenWaitNoteL(iWaitForConnectDlg,R_BT_CONNECTING_TO_WAIT_NOTE,R_BT_CONNECTING_TO ,
       
   906                 ECmdShowBtWaitConnectingToNote,aDevice.iName); 
       
   907 	        }
       
   908 		iConnectDevice=new(ELeave) TBTDevice(aDevice);            
       
   909 		iConnectDevice->iOperation=EOpConnect;
       
   910 		     
       
   911 		if( currentPowerMode == EBTPowerOff )
       
   912 			{
       
   913 				// turn on the flag IsConnectDevice
       
   914 				//
       
   915 				iIsConnectDevice = ETrue;
       
   916 			}
       
   917         else
       
   918         	{	
       
   919         		// connect device
       
   920         		//
       
   921         		iModel->ChangeDevice(*iConnectDevice);
       
   922         		
       
   923         		// reset IsConnectDevice flag
       
   924         		iIsConnectDevice = EFalse;
       
   925         	}
       
   926         }
       
   927     TRACE_FUNC_EXIT
       
   928 	}
       
   929 	
       
   930 // ----------------------------------------------------------
       
   931 // CBTUIPairedDevicesView::OpenWaitNoteL
       
   932 // ----------------------------------------------------------
       
   933 void CBTUIPairedDevicesView::OpenWaitNoteL(CAknWaitDialog*& aWaitDialog,TUint aNoteResource,TUint aNoteTextResource,
       
   934 		TSecondaryDisplayBtuiDialogs aSec,const TDesC& aDevName)
       
   935 	{
       
   936 	TRAPD(err,
       
   937 	        RBuf stringholder;
       
   938 	        CleanupClosePushL( stringholder );
       
   939 	        BluetoothUiUtil::LoadResourceAndSubstringL( 
       
   940 	                stringholder, aNoteTextResource, aDevName, 0 );
       
   941 	    aWaitDialog = new (ELeave) CAknWaitDialog(
       
   942                     reinterpret_cast<CEikDialog**>(&aWaitDialog), ETrue);
       
   943 	    aWaitDialog->PrepareLC(aNoteResource);
       
   944 	    aWaitDialog->SetTextL(stringholder);
       
   945 
       
   946 	    if(iCoverDisplayEnabled)
       
   947 	        {
       
   948 	        aWaitDialog->PublishDialogL(
       
   949 	          aSec, KUidCoverUiCategoryBtui); // initializes cover support    
       
   950 	        CAknMediatorFacade* covercl = AknMediatorFacade(aWaitDialog); // uses MOP, so control provided 
       
   951 	        if (covercl) // returns null if __COVER_DISPLAY is not defined
       
   952 	            {	    
       
   953 	            covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(aDevName);// takes copy so consts are ok too
       
   954 	            covercl->BufStream().CommitL(); // no more data to send so commit buf
       
   955 	            }  
       
   956 	        }	        
       
   957 	    aWaitDialog->SetCallback(this); // for capturing Cancel keypress	            
       
   958 	    aWaitDialog->RunLD();
       
   959 	    
       
   960     	CleanupStack::PopAndDestroy(&stringholder); // stringholder
       
   961     );
       
   962     // if the above functions leaves the iWaitNote is deleted, but
       
   963     // not set to NULL. This will cause a problem, when
       
   964     // the items may be deleted again, since it has to
       
   965     // be a member variable, in order to be closed
       
   966     // programmatically.
       
   967     if(err!=KErrNone)
       
   968     	{
       
   969     	// that is why we set it to NULL here and
       
   970     	// continue leaving further.
       
   971         aWaitDialog=NULL;
       
   972 		User::Leave(err);	
       
   973     	}
       
   974 	}
       
   975 
       
   976 // ----------------------------------------------------------
       
   977 // CBTUIPairedDevicesView::LaunchSettingViewL
       
   978 // ----------------------------------------------------------
       
   979 //
       
   980 void CBTUIPairedDevicesView::LaunchSettingViewL()
       
   981 	{
       
   982 	TRACE_FUNC_ENTRY
       
   983 	
       
   984 	TInt index = iContainer->CurrentItemIndex();
       
   985 	if(index == KErrNotFound) return;			
       
   986 	TBTDevice device;
       
   987 	device.iIndex = index;
       
   988 	iModel->GetDevice(device);
       
   989 	
       
   990 	CAknView* settingView = iBTPluginMan->GetSettingViewL(device);
       
   991 	if(settingView != NULL)
       
   992 		{
       
   993 		TUid viewId = settingView->Id();		
       
   994         if(( device.iStatus & EStatusBtuiConnected) == EStatusBtuiConnected )
       
   995             {
       
   996             TBuf8<KMaxBCBluetoothNameLen> DeviceName;
       
   997             DeviceName.Copy(device.iName);
       
   998             AppUi()->ActivateLocalViewL( viewId, KNullUid, DeviceName); 
       
   999             }
       
  1000         else
       
  1001             {
       
  1002             AppUi()->ActivateLocalViewL( viewId ); 
       
  1003             }
       
  1004 		}
       
  1005 	else 
       
  1006 		{
       
  1007 		User::Leave(KErrNotFound);
       
  1008 		}	
       
  1009 		
       
  1010 	TRACE_FUNC_EXIT
       
  1011 	}
       
  1012 
       
  1013 // ----------------------------------------------------------
       
  1014 // CBTUIPairedDevicesView::DisconnectL
       
  1015 // ----------------------------------------------------------
       
  1016 //
       
  1017 void CBTUIPairedDevicesView::DisconnectL()
       
  1018     {
       
  1019 	TRACE_FUNC_ENTRY
       
  1020     
       
  1021 	TInt index = iContainer->CurrentItemIndex();
       
  1022 	if(index == KErrNotFound) return;
       
  1023 			
       
  1024     TBTDevice device;
       
  1025     device.iIndex = index;
       
  1026     iModel->GetDevice(device);
       
  1027     
       
  1028     if ( !( device.iStatus & EStatusBtuiConnected) )
       
  1029         {
       
  1030         // If device is already disconnected, return immediately.
       
  1031         return;
       
  1032         }
       
  1033     
       
  1034 	iDisconnectQueryDevice = device;//remember device related with query dialog
       
  1035 
       
  1036     // Create confirmation query
       
  1037     RBuf stringholder;
       
  1038     CleanupClosePushL( stringholder );
       
  1039     BluetoothUiUtil::LoadResourceAndSubstringL( 
       
  1040             stringholder, R_BT_DISCONNECT_FROM, device.iName, 0 );
       
  1041     if ( !iDisconnectQueryDlg )
       
  1042         {
       
  1043         iDisconnectQueryDlg = CAknQueryDialog::NewL();
       
  1044         }
       
  1045 
       
  1046 	if(iCoverDisplayEnabled)
       
  1047 		{
       
  1048 	    iDisconnectQueryDlg->PublishDialogL(ECmdShowDisconnectQuery, KUidCoverUiCategoryBtui); // initializes cover support    
       
  1049 	
       
  1050 		CAknMediatorFacade* covercl = AknMediatorFacade(iDisconnectQueryDlg); // uses MOP, so control provided 
       
  1051 		if (covercl) // returns null if __COVER_DISPLAY is not defined
       
  1052 		    {	    
       
  1053 		    covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(device.iName);// takes copy so consts are ok too
       
  1054 		    covercl->BufStream().CommitL(); // no more data to send so commit buf
       
  1055 		    }  
       
  1056 		}
       
  1057 			
       
  1058     TInt keypress = iDisconnectQueryDlg->ExecuteLD(R_BT_DISCONNECT_FROM_QUERY, stringholder);
       
  1059 
       
  1060     CleanupStack::PopAndDestroy(&stringholder);  // stringholder
       
  1061 
       
  1062 	iDisconnectQueryDlg = NULL;
       
  1063     if(keypress)  // User has accepted the dialog
       
  1064         {
       
  1065         device.iOperation = EOpDisconnect;
       
  1066 	    iModel->ChangeDevice(device);
       
  1067 		}
       
  1068 	TRACE_FUNC_EXIT		
       
  1069 	}
       
  1070 	
       
  1071 // ----------------------------------------------------------
       
  1072 // CBTUIPairedDevicesView::CancelDisconnectQueryDlgL
       
  1073 // ----------------------------------------------------------
       
  1074 //
       
  1075 void CBTUIPairedDevicesView::CancelDisconnectQueryDlg()
       
  1076 {
       
  1077 	TRACE_FUNC_ENTRY
       
  1078 	
       
  1079 	if(iDisconnectQueryDlg)
       
  1080 	{
       
  1081 		delete iDisconnectQueryDlg;
       
  1082 		iDisconnectQueryDlg = NULL;
       
  1083 	}
       
  1084 	
       
  1085 	TRACE_FUNC_EXIT	
       
  1086 }
       
  1087 
       
  1088 // ----------------------------------------------------------
       
  1089 // CBTUIPairedDevicesView::DisconnectWithoutQuery
       
  1090 // ----------------------------------------------------------
       
  1091 //
       
  1092 void CBTUIPairedDevicesView::DisconnectWithoutQuery()
       
  1093 {
       
  1094 	TRACE_FUNC_ENTRY
       
  1095     
       
  1096 	TInt index = iContainer->CurrentItemIndex();
       
  1097 	if(index == KErrNotFound) return;
       
  1098 			
       
  1099     TBTDevice device;
       
  1100     device.iIndex = index;
       
  1101     iModel->GetDevice(device);  
       
  1102     device.iOperation = EOpDisconnect;
       
  1103     iModel->ChangeDevice(device);      
       
  1104 }
       
  1105 // ----------------------------------------------------------
       
  1106 // CBTUIPairedDevicesView::ConnectCompleteL
       
  1107 // ----------------------------------------------------------
       
  1108 //
       
  1109 void CBTUIPairedDevicesView::ConnectCompleteL(TInt aError,const TBTDevice& aDevice,
       
  1110 	const RBTDevNameArray* aConflictingDeviceNames)
       
  1111     {
       
  1112 	TRACE_FUNC_ENTRY
       
  1113 
       
  1114     // Dismiss wait note
       
  1115     //   
       
  1116     if(iConnectDevice)
       
  1117         {
       
  1118         delete iConnectDevice;
       
  1119         iConnectDevice=NULL;
       
  1120         }
       
  1121     
       
  1122 	if ( iIsPairConnect )
       
  1123 	    {
       
  1124 	    iIsPairConnect = EFalse;
       
  1125 	    if ( aError != KErrNone && 
       
  1126 	         aError != KErrCancel &&
       
  1127 	         aError != KErrNotSupported &&
       
  1128 	         aError != KErrAlreadyExists && 
       
  1129 	         aError != KErrServerBusy )
       
  1130 	        {
       
  1131 	        // It is possible that we started connecting too soon before the
       
  1132 	        // device moves to conntable mode from pairing mode. Let's try
       
  1133 	        // once more:
       
  1134 	        if ( !iActive )
       
  1135 	            {
       
  1136 	            iActive = CBTUIActive::NewL( 
       
  1137 	                        this, KAutoConnect2ndTry, CActive::EPriorityStandard );
       
  1138 	            }
       
  1139 	        iActive->RequestStatus() = KRequestPending;
       
  1140 	        iActive->GoActive();	
       
  1141 	        TRequestStatus* stptr = &( iActive->RequestStatus() );
       
  1142 	        User::RequestComplete( stptr, KErrNone );
       
  1143 	        TRACE_INFO( _L("CBTUIPairedDevicesView, sceadule auto connect 2nd try") )
       
  1144             return;
       
  1145 	        }
       
  1146 	    }
       
  1147 
       
  1148     if(iWaitForConnectDlg)
       
  1149         {
       
  1150         TRACE_INFO(_L("waiting dialog is active, dismiss it"))
       
  1151         iWaitForConnectDlg->ProcessFinishedL();
       
  1152         }
       
  1153 	
       
  1154     switch (aError)
       
  1155         {
       
  1156         case KErrCancel:
       
  1157         	TRACE_INFO(_L("aError = KErrCancel"))
       
  1158             break;
       
  1159         case KErrAlreadyExists:	// connection exists allready
       
  1160         	{
       
  1161           	RBuf stringholder;
       
  1162           	CleanupClosePushL( stringholder );
       
  1163           	if(aConflictingDeviceNames && aConflictingDeviceNames->Count()> 0)
       
  1164         		{        		
       
  1165         		if(aConflictingDeviceNames->Count() == 1)
       
  1166         			{
       
  1167         			BluetoothUiUtil::LoadResourceAndSubstringL( stringholder, 
       
  1168         			        R_BT_DISCONNECT_FIRST_PROMPT, 
       
  1169         			        *(*aConflictingDeviceNames)[0], 0 );
       
  1170         			}
       
  1171         		else
       
  1172         			{
       
  1173         			BluetoothUiUtil::LoadResourceAndSubstringL( stringholder, 
       
  1174                         R_BT_DISCONNECT_FIRST_STEREO_PROMPT, 
       
  1175                         *(*aConflictingDeviceNames)[0], 0 );
       
  1176         			BluetoothUiUtil::AddSubstringL( stringholder, *(*aConflictingDeviceNames)[1], 1 );       					
       
  1177         			}
       
  1178         		TRACE_INFO(_L("KErrAllreadyExists"))      	  		  
       
  1179           		}
       
  1180           	else
       
  1181           		{
       
  1182        			// Showing a note in this case would always show a note with "%U" in it
       
  1183        			// so the note is not shown at all
       
  1184        			TRACE_INFO(_L("KErrAlreadyExists, but no device given, not showing a notification"))
       
  1185 				CleanupStack::PopAndDestroy(&stringholder);
       
  1186 	          	break;	
       
  1187           		}
       
  1188 
       
  1189            	CAknInformationNote* note = new (ELeave) CAknInformationNote();
       
  1190             
       
  1191 			if(iCoverDisplayEnabled)
       
  1192 				{
       
  1193 				CleanupStack::PushL(note); 			
       
  1194 		    	note->PublishDialogL(ECmdShowBtDisconnectFirstNote, KUidCoverUiCategoryBtui); // initializes cover support    
       
  1195 				CleanupStack::Pop(note); 
       
  1196 
       
  1197 				CAknMediatorFacade* covercl = AknMediatorFacade(note); // uses MOP, so control provided 
       
  1198 				if (covercl) // returns null if __COVER_DISPLAY is not defined
       
  1199 			    	{	
       
  1200 					if(aConflictingDeviceNames && aConflictingDeviceNames->Count()> 0)			    	    
       
  1201 						{
       
  1202 							covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(*(*aConflictingDeviceNames)[0]);	
       
  1203 						}			    	
       
  1204 			    	covercl->BufStream().CommitL(); // no more data to send so commit buf
       
  1205 			    	}  
       
  1206 				}
       
  1207 		
       
  1208         	note->ExecuteLD(stringholder);
       
  1209         	CleanupStack::PopAndDestroy(&stringholder);
       
  1210         	}
       
  1211         	break;	
       
  1212 		case KErrServerBusy:
       
  1213 			{
       
  1214         	CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog(
       
  1215         		CAknNoteDialog::ENoTone,CAknNoteDialog::ELongTimeout);                
       
  1216 			if(iCoverDisplayEnabled)
       
  1217 				{
       
  1218 				CleanupStack::PushL(dlg); 			
       
  1219 				dlg->PublishDialogL(ECmdBtuiShowBtBusyNote, KUidCoverUiCategoryBtui); // initializes cover support    
       
  1220 				CleanupStack::Pop(dlg); 			
       
  1221 				}
       
  1222 			
       
  1223         	dlg->ExecuteLD(R_BT_BUSY);
       
  1224 			}
       
  1225 			break;        		
       
  1226         case KErrNone:
       
  1227             {           
       
  1228             
       
  1229             TRACE_INFO(_L("aError = KErrNone"))
       
  1230             // Create note 
       
  1231             //          
       
  1232 			CAknInformationNote* notePtr = new (ELeave) CAknInformationNote();
       
  1233 
       
  1234             RBuf stringHolder;
       
  1235             CleanupClosePushL( stringHolder );
       
  1236             
       
  1237             BluetoothUiUtil::LoadResourceAndSubstringL( stringHolder,
       
  1238                     R_BT_CONF_CONNECTED_PROMPT, aDevice.iName, 0 );
       
  1239             
       
  1240             if(iCoverDisplayEnabled)
       
  1241                     {
       
  1242                     CleanupStack::PushL(notePtr); 			
       
  1243                     notePtr->PublishDialogL(ECmdBtuiShowBtConfConnected, KUidCoverUiCategoryBtui); // initializes cover support    
       
  1244                     CleanupStack::Pop(notePtr); 
       
  1245 
       
  1246                     CAknMediatorFacade* covercl = AknMediatorFacade(notePtr); // uses MOP, so control provided 
       
  1247                     if (covercl) // returns null if __COVER_DISPLAY is not defined
       
  1248                         {	
       
  1249                             covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(aDevice.iName);	
       
  1250                           covercl->BufStream().CommitL(); // no more data to send so commit buf
       
  1251                         }  
       
  1252                     }
       
  1253                 
       
  1254             notePtr->ExecuteLD(stringHolder);        
       
  1255             CleanupStack::PopAndDestroy(&stringHolder);
       
  1256             }
       
  1257             
       
  1258             TRAP_IGNORE(LaunchSettingViewL();)
       
  1259             break;
       
  1260 
       
  1261         case KErrNotSupported:
       
  1262             {
       
  1263             TRACE_INFO(_L("error = KErrNotSupported"))
       
  1264             
       
  1265             RBuf stringHolder;
       
  1266             CleanupClosePushL( stringHolder );
       
  1267             
       
  1268             BluetoothUiUtil::LoadResourceAndSubstringL( stringHolder,
       
  1269                     R_BT_DEVICE_NOT_SUPPORTED, aDevice.iName, 0 );
       
  1270 			
       
  1271 			// create note
       
  1272 			//
       
  1273 			CAknInformationNote* note = new (ELeave) CAknInformationNote();
       
  1274             
       
  1275 			if(iCoverDisplayEnabled)
       
  1276 				{
       
  1277 				CleanupStack::PushL(note); 			
       
  1278 		    	note->PublishDialogL(ECmdBtuiShowBtDeviceNotSupported, KUidCoverUiCategoryBtui); // initializes cover support    
       
  1279 				CleanupStack::Pop(note); 
       
  1280 
       
  1281 				CAknMediatorFacade* covercl = AknMediatorFacade(note); // uses MOP, so control provided 
       
  1282 				if (covercl) // returns null if __COVER_DISPLAY is not defined
       
  1283 			    	{	
       
  1284 						covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(aDevice.iName);	
       
  1285 						covercl->BufStream().CommitL(); // no more data to send so commit buf
       
  1286 			    	}  
       
  1287 				}
       
  1288 			note->ExecuteLD(stringHolder);
       
  1289         	CleanupStack::PopAndDestroy(&stringHolder);
       
  1290             }
       
  1291             break;
       
  1292 
       
  1293         default:
       
  1294             {
       
  1295             // Create note
       
  1296            	CAknInformationNote* note = new (ELeave) CAknInformationNote();
       
  1297             HBufC* stringHolder=StringLoader::LoadLC(R_BT_DEVICE_NOT_AVAIL_NOTE );
       
  1298 	      
       
  1299 			if(iCoverDisplayEnabled)
       
  1300 				{
       
  1301 				CleanupStack::PushL(note); 			
       
  1302 		    	note->PublishDialogL(ECmdBtuiShowBtDeviceNotAvail, KUidCoverUiCategoryBtui); // initializes cover support    
       
  1303 				CleanupStack::Pop(note); 
       
  1304 			
       
  1305 				}
       
  1306 		
       
  1307         	note->ExecuteLD(*stringHolder);
       
  1308         	CleanupStack::PopAndDestroy(stringHolder);
       
  1309         	TRACE_INFO(_L("default error note BT-not-available"))
       
  1310             }
       
  1311             break;
       
  1312         }    
       
  1313 	TRACE_FUNC_EXIT
       
  1314     }
       
  1315 
       
  1316 // ------------------------------------------------------
       
  1317 // CBTUIPairedDevicesView::LaunchHelp
       
  1318 // static help launching function for TCallback
       
  1319 // ------------------------------------------------------
       
  1320 TInt CBTUIPairedDevicesView::LaunchHelp(TAny* aCoeHelpContext)
       
  1321 	{	
       
  1322 #ifdef __SERIES60_HELP      
       
  1323 	//TRACE_FUNC_ENTRY
       
  1324 	TCoeHelpContext hc;
       
  1325 	
       
  1326 	if(aCoeHelpContext==NULL)
       
  1327 		hc = TCoeHelpContext(KBtuiUid3,KBT_HLP_BLOCKED);
       
  1328 	else
       
  1329 		hc = *static_cast<TCoeHelpContext*>(aCoeHelpContext);
       
  1330 	TRAPD(err,		 
       
  1331 		CArrayFix< TCoeHelpContext >* array=new (ELeave) CArrayFixFlat< TCoeHelpContext >(1);
       
  1332 		array->AppendL(hc);
       
  1333 		CleanupStack::PushL(array);
       
  1334 		// codescan will complain about CCoeEnv::Static(), however it is not reasonable
       
  1335 		// avoidable, since this is static funtion.
       
  1336         HlpLauncher::LaunchHelpApplicationL(CCoeEnv::Static()->WsSession() , array);
       
  1337         CleanupStack::Pop(array);
       
  1338    );
       
  1339     
       
  1340     // the array is not deleted, since deleting it will result
       
  1341     // to E32User-CBase 3. It is assumed that HlpLancher is taking care of it.
       
  1342     // however this has not been documented.
       
  1343     //TRACE_FUNC_EXIT
       
  1344     return err;
       
  1345 #else
       
  1346 	return KErrNone;    
       
  1347 #endif    
       
  1348 	}
       
  1349 
       
  1350 // ------------------------------------------------------
       
  1351 // CBTUIPairedDevicesView::CallOnGoing
       
  1352 // ------------------------------------------------------
       
  1353 TBool CBTUIPairedDevicesView::CallOnGoing()
       
  1354 	{
       
  1355 	TRACE_FUNC_ENTRY	
       
  1356 	TInt callState;
       
  1357 	// Try to get the call state property
       
  1358     
       
  1359 	TInt err = RProperty::Get(KPSUidCtsyCallInformation,
       
  1360 	 KCTsyCallState, callState); //KPSUidTelephonyCallInformation should be used   // Check also,if retrieving the property value succeeded
       
  1361 	return (err == KErrNone) ?
       
  1362            (callState != EPSCTsyCallStateNone && 
       
  1363            callState != EPSCTsyCallStateUninitialized) :
       
  1364            EFalse;
       
  1365 	}
       
  1366 // ----------------------------------------------------------
       
  1367 // From MProgressDialogCallback
       
  1368 // CBTUIPairedDevicesView::DialogDismissedL
       
  1369 //
       
  1370 // Cancels pairing/connection operation if user has pressed Cancel softkey.
       
  1371 // Does nothing if the dialog has been dismissed by this program.
       
  1372 // ----------------------------------------------------------
       
  1373 //
       
  1374 void CBTUIPairedDevicesView::DialogDismissedL(TInt aButtonId )
       
  1375     {    
       
  1376 	TRACE_FUNC_ENTRY
       
  1377 
       
  1378 	// it was not canceled, but dialog was closed
       
  1379 	// because it ended normally, so there is nothing to clean up.
       
  1380    if( aButtonId != EAknSoftkeyCancel )
       
  1381    		return;
       
  1382    
       
  1383     // Cancel ongoing operations if any
       
  1384     //
       
  1385     if ( iWaitForConnectDlg)
       
  1386     	{
       
  1387         if( iConnectDevice )
       
  1388         	{
       
  1389 	        iModel->CancelChange(*iConnectDevice);
       
  1390 	        delete iConnectDevice;        	
       
  1391 			iConnectDevice=NULL;	  
       
  1392 			iIsPairConnect = EFalse;
       
  1393         	}            	
       
  1394     	iWaitForConnectDlg = NULL;
       
  1395     	}    	
       
  1396     if ( iWaitForPairingDlg )
       
  1397         {
       
  1398         if( iPairingDevice )
       
  1399         	{
       
  1400 	        TBTDevice device;
       
  1401 	        device.iAddr = iPairingDevice->BDAddr();
       
  1402 	        device.iOperation = EOpPair;
       
  1403 
       
  1404         	iDeviceSearcher->CancelSearchRemoteDevice();
       
  1405         	
       
  1406 	        iModel->CancelChange(device);
       
  1407         	        	
       
  1408 	        delete iPairingDevice;        	
       
  1409 			iPairingDevice=NULL;	        			
       
  1410         	}        
       
  1411         // The dialog has already been deleted by UI framework and
       
  1412         // must not be deleted manually.        	
       
  1413         iWaitForPairingDlg = NULL;
       
  1414         }
       
  1415 	
       
  1416 	TRACE_FUNC_EXIT
       
  1417     }    
       
  1418 // ------------------------------------------------------
       
  1419 // From MBTEngSdpResultReceiver
       
  1420 // CBTUIPairedDevicesView::ServiceSearchComplete
       
  1421 // not used and implemented as empty
       
  1422 // ------------------------------------------------------
       
  1423 void CBTUIPairedDevicesView::ServiceSearchComplete(const RSdpRecHandleArray& , TUint , TInt)
       
  1424 	{
       
  1425 	TRACE_FUNC_ENTRY	
       
  1426 	}
       
  1427 // ------------------------------------------------------
       
  1428 // From MBTEngSdpResultReceiver
       
  1429 // CBTUIPairedDevicesView::AttributeSearchComplete
       
  1430 // not used and implemented as empty
       
  1431 // ------------------------------------------------------
       
  1432 void CBTUIPairedDevicesView::AttributeSearchComplete(TSdpServRecordHandle, 
       
  1433 	const RSdpResultArray& ,TInt)
       
  1434 	{
       
  1435 	TRACE_FUNC_ENTRY	
       
  1436 	}
       
  1437 // ------------------------------------------------------
       
  1438 // From MBTEngSdpResultReceiver
       
  1439 // CBTUIPairedDevicesView::AttributeSearchComplete
       
  1440 // not used and implemented as empty
       
  1441 // ------------------------------------------------------
       
  1442 void CBTUIPairedDevicesView::ServiceAttributeSearchComplete(TSdpServRecordHandle ,
       
  1443 	const RSdpResultArray& ,TInt )
       
  1444 	{
       
  1445 	TRACE_FUNC_ENTRY	
       
  1446 	}
       
  1447 // ------------------------------------------------------
       
  1448 // From MBTEngSdpResultReceiver
       
  1449 // CBTUIPairedDevicesView::DeviceSearchComplete
       
  1450 // ------------------------------------------------------	
       
  1451 void CBTUIPairedDevicesView::DeviceSearchComplete(CBTDevice* aDevice, TInt aErr)
       
  1452 	{
       
  1453 	TRACE_FUNC_ENTRY	
       
  1454 
       
  1455 	TRAPD(err,	DeviceSearchCompleteL(aDevice, NULL, aErr);
       
  1456 		);
       
  1457 		// something went wrong.
       
  1458 	if(err != KErrNone)
       
  1459 		{
       
  1460 		TRAP_IGNORE( TBTUIViewsCommonUtils::ShowGeneralErrorNoteL(); );
       
  1461 		}			
       
  1462     iSearchOngoing=EFalse;
       
  1463 	TRACE_FUNC_EXIT		
       
  1464 	}
       
  1465 
       
  1466 // ------------------------------------------------------
       
  1467 // From MBTEngSdpResultReceiver
       
  1468 // CBTUIPairedDevicesView::DeviceSearchComplete
       
  1469 // ------------------------------------------------------   
       
  1470 void CBTUIPairedDevicesView::DeviceSearchComplete( CBTDevice* aDevice, 
       
  1471         TNameEntry* aNameEntry, TInt aErr )
       
  1472     {
       
  1473 	TRACE_FUNC_ENTRY	
       
  1474 
       
  1475 	TRAPD(err,	DeviceSearchCompleteL(aDevice, aNameEntry, aErr);
       
  1476 		);
       
  1477 		// something went wrong.
       
  1478 	if(err != KErrNone)
       
  1479 		{
       
  1480 		TRAP_IGNORE( TBTUIViewsCommonUtils::ShowGeneralErrorNoteL(); );
       
  1481 		}
       
  1482     iSearchOngoing=EFalse;
       
  1483 	TRACE_FUNC_EXIT		    
       
  1484     }
       
  1485 
       
  1486 // ------------------------------------------------------
       
  1487 // CBTUIPairedDevicesView::DeviceSearchCompleteL
       
  1488 // Leaving version of DeviceSearchComplete
       
  1489 // ------------------------------------------------------
       
  1490 
       
  1491 void CBTUIPairedDevicesView::DeviceSearchCompleteL(CBTDevice* aDevice, 
       
  1492         TNameEntry* aNameEntry, TInt aErr)
       
  1493 	{
       
  1494 	TRACE_FUNC_ENTRY	
       
  1495     iSearchOngoing=EFalse;
       
  1496 	if ( !iPairingDevice )
       
  1497 	    {
       
  1498 	    delete iModel;
       
  1499 	    iModel = NULL;
       
  1500 	    return;
       
  1501 	    }
       
  1502 		// we must  not have multiple pairings at the same time
       
  1503 	__ASSERT_DEBUG(aDevice->BDAddr() == iPairingDevice->BDAddr(),
       
  1504 		PANIC(EBTPanicTwoPairingAttemptsAtTheSameTime) );
       
  1505 
       
  1506 	// other error condition, most likely dialog cancel.
       
  1507 	if(aErr != KErrNone && (aErr != KErrAlreadyExists))
       
  1508 		{
       
  1509 		delete iPairingDevice;
       
  1510 		iPairingDevice=NULL;
       
  1511 		return;
       
  1512 		}
       
  1513 
       
  1514     // In case user switches the view fast enough before searching starts, 
       
  1515 	// It crashes the whole btui by iModel is null value.
       
  1516 	// We add an extra check here
       
  1517 	//
       
  1518 	if ( !iModel )
       
  1519 	    {
       
  1520 	    delete iPairingDevice;
       
  1521 	    iPairingDevice=NULL;
       
  1522 	    return;
       
  1523 	    }
       
  1524 		
       
  1525 	TBTDevice *tmpDevice=iModel->CreateDeviceL(aDevice, aNameEntry);
       
  1526 	CleanupStack::PushL(tmpDevice);	
       
  1527     if(tmpDevice->iStatus & (EStatusPhysicallyConnected|EStatusBtuiConnected|EStatusPaired))	
       
  1528         {
       
  1529         ShowDisconnecNoteL(tmpDevice);        
       
  1530         CleanupStack::PopAndDestroy(tmpDevice);            
       
  1531 	    delete iPairingDevice;
       
  1532 	    iPairingDevice=NULL;                                  
       
  1533         return;
       
  1534         }
       
  1535     else        
       
  1536 	    {
       
  1537     	// Launch wait note
       
  1538     	OpenWaitNoteL(iWaitForPairingDlg,R_BT_WAITING,R_BT_WAITING_PROMPT,
       
  1539            		ECmdShowBtWaitingNote,tmpDevice->iName);     
       
  1540 
       
  1541     	CleanupStack::PopAndDestroy(tmpDevice); 
       
  1542     	tmpDevice=NULL;
       
  1543     	// and start the pairing	
       
  1544     	iModel->ChangeDevice(aDevice, aNameEntry, EOpPair);
       
  1545     	// aDevice is not deleted, since it points to iPairingDevice and it is still used
       
  1546     	// after this
       
  1547         }
       
  1548 	TRACE_FUNC_EXIT		
       
  1549 	}
       
  1550 
       
  1551 
       
  1552 // ------------------------------------------------------
       
  1553 // CBTUIPairedDevicesView::ShowDisconnecNote
       
  1554 // ------------------------------------------------------	
       
  1555 void CBTUIPairedDevicesView::ShowDisconnecNoteL(TBTDevice *aDevice)
       
  1556     {
       
  1557     RBuf stringholder;
       
  1558     CleanupClosePushL( stringholder );
       
  1559     BluetoothUiUtil::LoadResourceAndSubstringL( 
       
  1560             stringholder, R_BT_DISCONNECT_FIRST_PROMPT, aDevice->iName, 0 );
       
  1561     // Launch a waiting confirmation note
       
  1562     //
       
  1563     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote(ETrue);
       
  1564 
       
  1565     if(iCoverDisplayEnabled)
       
  1566     	{
       
  1567         CleanupStack::PushL(note); 				
       
  1568         note->PublishDialogL(ECmdShowBtSuccesfullyPairedNote, 
       
  1569           KUidCoverUiCategoryBtui); // initializes cover support    
       
  1570     	CAknMediatorFacade* covercl = AknMediatorFacade(note); // uses MOP, so control provided 
       
  1571     	if (covercl) // returns null if __COVER_DISPLAY is not defined
       
  1572     	    {	    
       
  1573     	    covercl->BufStream() << BTDeviceNameConverter::ToUTF8L(aDevice->iName);// takes copy so consts are ok too
       
  1574     	    covercl->BufStream().CommitL(); // no more data to send so commit buf
       
  1575     	    }  
       
  1576         CleanupStack::Pop(note); 				
       
  1577     	}
       
  1578 
       
  1579     note->ExecuteLD(stringholder);
       
  1580 
       
  1581     CleanupStack::PopAndDestroy(&stringholder); // stringholder    
       
  1582     
       
  1583     }
       
  1584 
       
  1585 void CBTUIPairedDevicesView::ConnectIfNeededAfterPairL( TInt aCount )
       
  1586     {
       
  1587     TRACE_FUNC_ENTRY
       
  1588     TBTDevice device;
       
  1589     device.iAddr = iPairConnectAddr;
       
  1590     iModel->GetDevice(device);
       
  1591     device.iOperation = EOpConnect;
       
  1592     ConnectL( device, ( aCount ) ? EFalse : ETrue );
       
  1593     TRACE_FUNC_EXIT
       
  1594     }
       
  1595 
       
  1596 // ------------------------------------------------------
       
  1597 // CBTUIPairedDevicesView::BondingCompleted
       
  1598 // called by NotifyChangeDeviceComplete
       
  1599 // ------------------------------------------------------
       
  1600 void CBTUIPairedDevicesView::BondingCompleteL(TInt aError, const TBTDevice& aDevice)
       
  1601 	{
       
  1602     TRACE_INFO((_L("aError=%d"), aError))
       
  1603 	// We need to make a copy of the device, since it may be cleaned up
       
  1604 	// by device refresh.
       
  1605 	TBTDevice bDevice= aDevice;
       
  1606 	
       
  1607 	// this may look useless, however if the device has a given shortName it is listed with it
       
  1608 	// all the time. If you omnit this line it will be shown with its original deviceName,
       
  1609 	// dispite it will be listed with the given name
       
  1610 	iModel->GetDevice(bDevice);
       
  1611 	 	
       
  1612 	delete iPairingDevice;
       
  1613 	iPairingDevice=NULL;
       
  1614 	           
       
  1615     // Dismiss wait note
       
  1616     if(iWaitForPairingDlg)
       
  1617         {
       
  1618         iWaitForPairingDlg->ProcessFinishedL();
       
  1619         iWaitForPairingDlg = NULL;
       
  1620         }
       
  1621 	
       
  1622     // Error handling
       
  1623     switch(aError)
       
  1624         {
       
  1625         case KErrCancel:
       
  1626             break;
       
  1627         case KErrAlreadyExists: // This is a legal return value
       
  1628         case KErrNone:
       
  1629         case KHCIErrorBase:
       
  1630             {
       
  1631 	        if( (bDevice.iStatus & EStatusConnectable) 
       
  1632 	                && (bDevice.iDeviceClass.MajorDeviceClass() != EMajorDeviceComputer)) 
       
  1633 	            // Only automatically query for a connectable device but not a computer
       
  1634 	        	{
       
  1635 	            iPairConnectAddr = aDevice.iAddr;
       
  1636 	        	iIsPairConnect = ETrue;
       
  1637 	        	ConnectIfNeededAfterPairL( 0 );
       
  1638 	        	}
       
  1639             break;
       
  1640 			}
       
  1641         default:
       
  1642             {
       
  1643             break;
       
  1644           }
       
  1645         }  
       
  1646 	TRACE_FUNC_EXIT
       
  1647 	}
       
  1648 
       
  1649 // -----------------------------------------------
       
  1650 // From MBTDeviceObserver
       
  1651 // CBTUIPairedDevicesView::RefreshDeviceList
       
  1652 // calls the container to refresh the deviceList
       
  1653 // -----------------------------------------------
       
  1654 void CBTUIPairedDevicesView::RefreshDeviceList(const RDeviceArray* aDevices,
       
  1655        TInt aSelectedItemIndex)
       
  1656 	{
       
  1657 	TRACE_FUNC_ENTRY	
       
  1658 	TRAPD(err,
       
  1659 		if(iContainer)
       
  1660 			{			
       
  1661 				iContainer->RefreshDeviceListL(aDevices,aSelectedItemIndex);			
       
  1662 			}
       
  1663 		);			
       
  1664 	if (iActiveMenuPane && iActiveMenuPane->NumberOfItemsInPane()>0 ) 
       
  1665 	    {
       
  1666 		TInt index = iContainer->CurrentItemIndex();
       
  1667 	    if ( index >=0 )
       
  1668 		    {
       
  1669 		    TBTDevice device;
       
  1670 		    device.iIndex = index;
       
  1671 		    iModel->GetDevice(device);
       
  1672 			if ( iMenuDevice.iAddr == device.iAddr && 
       
  1673 			    ( ( iMenuDevice.iStatus & EStatusBtuiConnected ) != ( device.iStatus & EStatusBtuiConnected ) ) )
       
  1674 			    {
       
  1675 			    TRACE_INFO(_L("Device status changed, update menupane"));
       
  1676 			    iMenuDevice = device;
       
  1677 			    iActiveMenuPane->Close();
       
  1678 			    TRAP_IGNORE( this->ProcessCommandL(EAknSoftkeyContextOptions) );
       
  1679 			    }
       
  1680 		    }
       
  1681 	    }
       
  1682 	if(err!= KErrNone)	    
       
  1683         {
       
  1684 		TRAP_IGNORE( TBTUIViewsCommonUtils::ShowGeneralErrorNoteL(); );
       
  1685         }
       
  1686 	TRACE_FUNC_EXIT        
       
  1687 	}
       
  1688 
       
  1689 
       
  1690 // -----------------------------------------------
       
  1691 // 
       
  1692 // -----------------------------------------------
       
  1693 void CBTUIPairedDevicesView::RequestCompletedL( CBTUIActive* aActive, TInt aId, 
       
  1694                         TInt aStatus )
       
  1695     {
       
  1696     TRACE_INFO( ( _L("CBTUIPairedDevicesView::RequestCompletedL err %d"), aStatus ) )
       
  1697     (void) aActive;
       
  1698     (void) aId;
       
  1699     (void) aStatus;
       
  1700     TRACE_INFO( _L("CBTUIPairedDevicesView, auto connect 2nd try ... ") )
       
  1701     ConnectIfNeededAfterPairL( 1 );
       
  1702     }
       
  1703 
       
  1704 // -----------------------------------------------
       
  1705 // 
       
  1706 // -----------------------------------------------
       
  1707 void CBTUIPairedDevicesView::HandleError( CBTUIActive* aActive, TInt aId, 
       
  1708                   TInt aError )
       
  1709     {
       
  1710     (void) aActive;
       
  1711     (void) aId;
       
  1712     (void) aError;
       
  1713     iIsPairConnect = EFalse;
       
  1714     }
       
  1715 
       
  1716 // ---------------------------------------------------------
       
  1717 // From MBTDeviceObserver
       
  1718 // CBTUIPairedDevicesView::NotifyChangeDeviceComplete
       
  1719 // This function implement the functionality of command complete.
       
  1720 // The lists of shown devices are refreshed by RefreshDeviceList, 
       
  1721 // not by this function
       
  1722 // ---------------------------------------------------------
       
  1723 //
       
  1724 void CBTUIPairedDevicesView::NotifyChangeDeviceComplete(const TInt aErr, 
       
  1725 		const TBTDevice& aDevice, const RBTDevNameArray* aDevNameArray)
       
  1726 	{
       
  1727 	TRACE_FUNC_ENTRY
       
  1728 	TBTDevice tmpDevice=aDevice;
       
  1729 	TRAPD(err,NotifyChangeDeviceCompleteL(aErr,tmpDevice,aDevNameArray
       
  1730 		););
       
  1731 	if(err!= KErrNone)	    
       
  1732         {
       
  1733 		TRAP_IGNORE( TBTUIViewsCommonUtils::ShowGeneralErrorNoteL(); );
       
  1734         }
       
  1735 	TRACE_FUNC_EXIT		
       
  1736 	}
       
  1737 // ---------------------------------------------------------
       
  1738 // CBTUIPairedDevicesView::NotifyChangeDeviceCompleteL
       
  1739 // Leaving version of notifyChangeDevice
       
  1740 // ---------------------------------------------------------
       
  1741 
       
  1742 void CBTUIPairedDevicesView::NotifyChangeDeviceCompleteL(const TInt aErr, 
       
  1743 		const TBTDevice& aDevice, const RBTDevNameArray* aDevNameArray)
       
  1744 	{
       
  1745 	TRACE_FUNC_ENTRY
       
  1746 	if(iContainer == NULL) return;
       
  1747 
       
  1748 	TRACE_INFO((_L("aErr=%d"), aErr))
       
  1749 	TRACE_INFO((_L("aDevice.iOperation=%d"), aDevice.iOperation))
       
  1750 	TRACE_INFO((_L("aDevice.iStatus=%d"), aDevice.iStatus))
       
  1751 	TRACE_INFO((_L("iIsAlreadyConnected=%d"), iIsAlreadyConnected))
       
  1752 	
       
  1753     if (aDevice.iOperation == EOpDisconnect && iExpectedCallBack>0 )
       
  1754         {
       
  1755         TBTDevice device;
       
  1756         device.iIndex = aDevice.iIndex;
       
  1757         iModel->GetDevice(device);    
       
  1758         device.iOperation = EOpUnpair;
       
  1759         iModel->ChangeDevice(device); 
       
  1760         iExpectedCallBack--;
       
  1761         }
       
  1762 	
       
  1763 	if( aDevice.iOperation == EOpConnect )
       
  1764 		{
       
  1765 		if( aErr == KErrNone && iIsAlreadyConnected )
       
  1766 		    {
       
  1767 		    TRACE_INFO(_L("Don't show notes several times for the same device with different profile connections"))
       
  1768 		    return; 
       
  1769 		    }
       
  1770 		ConnectCompleteL(aErr, aDevice, aDevNameArray );
       
  1771 		iIsAlreadyConnected = ETrue;
       
  1772 		TRACE_INFO(_L("iIsAlreadyConnected False -> True"))
       
  1773 		return;
       
  1774 		}
       
  1775 	if(aDevice.iOperation == EOpPair)		
       
  1776 		{		
       
  1777 		BondingCompleteL(aErr, aDevice);
       
  1778 		}
       
  1779 	if(aErr != KErrNone)
       
  1780 		{
       
  1781         // The user tried to rename to a name that allready exists.
       
  1782         if(aDevice.iOperation == EOpChangeName && aErr == KErrAlreadyExists)
       
  1783             {
       
  1784             CAknNoteDialog* dlg2 = new (ELeave) CAknNoteDialog(CAknNoteDialog::EErrorTone,
       
  1785                                                                 CAknNoteDialog::ELongTimeout);
       
  1786             dlg2->ExecuteLD(R_BT_NAME_EXISTS_NOTE);
       
  1787 
       
  1788             RenameDeviceDlgL();
       
  1789             return;
       
  1790             }
       
  1791         // Need to properly handle situation when "Disconnect from xxx" query 
       
  1792         // has been shown and paired device has been turned off simultaneously.
       
  1793         // CancelDisconnectQuery dialog need to be closed. 
       
  1794         if(aErr == KErrDisconnected)
       
  1795             {
       
  1796             if(iDisconnectQueryDlg && aDevice.iAddr == iDisconnectQueryDevice.iAddr)
       
  1797                 CancelDisconnectQueryDlg();
       
  1798             
       
  1799             TRACE_FUNC_EXIT
       
  1800             return;
       
  1801             }
       
  1802         // show general error if any of these failed
       
  1803         if(	aDevice.iOperation== EOpTrust ||
       
  1804             aDevice.iOperation== EOpUntrust ||
       
  1805             aDevice.iOperation== EOpBlock ||
       
  1806             aDevice.iOperation== EOpChangeName)		
       
  1807             {
       
  1808             TBTUIViewsCommonUtils::ShowGeneralErrorNoteL();
       
  1809             }
       
  1810 		return;
       
  1811 		}		
       
  1812 	
       
  1813         if(aDevice.iOperation == EOpUntrust) 	        
       
  1814             {		
       
  1815             // Unauthorise ok note,
       
  1816             CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone,
       
  1817                                                                    CAknNoteDialog::ELongTimeout);
       
  1818             
       
  1819             if(iCoverDisplayEnabled)
       
  1820                 {
       
  1821                 CleanupStack::PushL(dlg); 
       
  1822                 dlg->PublishDialogL(ECmdShowBtDevSetAsUntrustNote, KUidCoverUiCategoryBtui); 
       
  1823                 // initializes cover support    
       
  1824                 CleanupStack::Pop(dlg); 
       
  1825                 }
       
  1826             dlg->ExecuteLD( R_BT_DEVICE_UNTRUSTED_NOTE );				
       
  1827             }
       
  1828 	TRACE_FUNC_EXIT		
       
  1829 	}
       
  1830 
       
  1831 // ---------------------------------------------------------------------------
       
  1832 // CBTUIPairedDevicesView::CreateTabIconL()
       
  1833 // Creates icon for tab.
       
  1834 // ---------------------------------------------------------------------------
       
  1835 //    
       
  1836 CGulIcon* CBTUIPairedDevicesView::CreateTabIconL()
       
  1837     {
       
  1838     TFileName bmpFilename;
       
  1839     bmpFilename += KBitmapFileDrive;
       
  1840     bmpFilename += KDC_APP_BITMAP_DIR;
       
  1841     bmpFilename += KBtuiBmpFileName;
       
  1842         
       
  1843     CGulIcon* icon = AknsUtils::CreateGulIconL(
       
  1844         AknsUtils::SkinInstance(), 
       
  1845         KAknsIIDQgnPropBtDevicesTab3,  
       
  1846         bmpFilename, 
       
  1847         EMbmBtuiQgn_prop_bt_devices_tab3, 
       
  1848         EMbmBtuiQgn_prop_bt_devices_tab3_mask );
       
  1849           
       
  1850     return icon;
       
  1851     }   
       
  1852 
       
  1853 
       
  1854 void CBTUIPairedDevicesView::SetupMenuCmd(TInt aIndex, CEikMenuPane* aMenu)
       
  1855     {
       
  1856     TBTDevice device;
       
  1857     device.iIndex = aIndex;
       
  1858     iModel->GetDevice(device);
       
  1859     iMenuDevice = device;           
       
  1860                     
       
  1861     TRACE_INFO(_L("there are device in list"))
       
  1862     
       
  1863     TBool dim = (device.iStatus & EStatusTrusted) == EStatusTrusted;
       
  1864                     
       
  1865     aMenu->SetItemDimmed(EBTUICmdSetTrusted, dim);
       
  1866     aMenu->SetItemDimmed(EBTUICmdSetUnTrusted, !dim);
       
  1867                      
       
  1868     // Check if device can be connected or disconnected
       
  1869     dim = (! (device.iStatus & EStatusConnectable) 
       
  1870             || device.iStatus & EStatusBtuiConnected);
       
  1871                     
       
  1872     if (dim) 
       
  1873         {
       
  1874         aMenu->SetItemDimmed(EBTUICmdConnect, dim);
       
  1875         aMenu->SetItemDimmed(EBTUICmdConnectAudio, dim);
       
  1876         }
       
  1877     else
       
  1878         {
       
  1879         if ( device.iDeviceClass.MajorDeviceClass() == EMajorDeviceComputer) 
       
  1880             {
       
  1881             aMenu->SetItemDimmed(EBTUICmdConnect, ETrue);
       
  1882             }
       
  1883         else 
       
  1884             {
       
  1885             aMenu->SetItemDimmed(EBTUICmdConnectAudio, ETrue);
       
  1886             }
       
  1887         }
       
  1888     dim = (device.iStatus & EStatusBtuiConnected) != EStatusBtuiConnected;
       
  1889     aMenu->SetItemDimmed(EBTUICmdDisconnect, dim);
       
  1890     
       
  1891     if ( !iBTPluginMan->IsPluginAvaiable(device.iDeviceClass) ) 
       
  1892         {
       
  1893         aMenu->SetItemDimmed(EBTUICmdSettings, ETrue);
       
  1894         }
       
  1895     else
       
  1896         {                
       
  1897         dim = (device.iStatus & EStatusBtuiConnected) != EStatusBtuiConnected;
       
  1898         aMenu->SetItemDimmed(EBTUICmdSettings, dim);
       
  1899         }                    
       
  1900     }
       
  1901 
       
  1902     
       
  1903 // End of File
       
  1904