bluetoothengine/btui/Ecom/inc/BTUIPairedDevicesView.h
branchRCL_3
changeset 55 613943a21004
parent 54 0ba996a9b75d
child 56 9386f31cc85b
equal deleted inserted replaced
54:0ba996a9b75d 55:613943a21004
     1 /*
       
     2 * Copyright (c) 2006-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:  The view that handles paired devices.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef BTUIPAIREDDEVICESVIEW_H
       
    19 #define BTUIPAIREDDEVICESVIEW_H
       
    20 
       
    21 #include <aknview.h>
       
    22 #include <eikmenup.h>       // Menu pane definitions
       
    23 #include <AknWaitDialog.h>
       
    24 #include <AknQueryDialog.h>
       
    25 #include <btengconstants.h>
       
    26 #include <btengdiscovery.h>
       
    27 #include "BtuiPluginInterface.h"
       
    28 #include "btdevmodel.h"
       
    29 #include "BTUIListedDevicesView.h"
       
    30 #include "btuipluginman.h"
       
    31 #include "BTUIActive.h"
       
    32 #include <SecondaryDisplay/BtuiSecondaryDisplayAPI.h>
       
    33 #include <gstabbedview.h>
       
    34 
       
    35 class CAknNavigationControlContainer;
       
    36 class CBTUiDeviceContainer;        
       
    37 class CGSTabHelper;
       
    38 class CBTEngSettings;
       
    39 class CBTUIMainView;
       
    40 
       
    41 // if there are more connection that this, it is disallowed to
       
    42 // connect to any device
       
    43 const TInt KBtUiMaxConnections = 6; 
       
    44 
       
    45 /**
       
    46 * Paired devicew view of the pluetooth application.
       
    47 *
       
    48 * This view handles lists of paired device and pairing new devices, unpairing devices
       
    49 * and setting previously paired devices as blocked. Also connecting and disconnecting 
       
    50 * are done by using this view.
       
    51 *
       
    52 *@lib BTUIPlugin.dll
       
    53 *@since S60 v3.0
       
    54 */
       
    55 class CBTUIPairedDevicesView : public CBTUIListedDevicesView,
       
    56 							  public MBTEngSettingsObserver,
       
    57 		                      public MProgressDialogCallback,
       
    58 		                      public MBTEngSdpResultReceiver, // for bt discovery. SDP is not used
       
    59 		                      public MGSTabbedView,
       
    60 		                      public MBTUIActiveObserver
       
    61 {	
       
    62     public:
       
    63 
       
    64 		/**
       
    65         * ECOM implementation instantiation function of 
       
    66         * interface "CBtuiPluginInterface", to be used by BTUI Application.
       
    67         */        
       
    68         static CBTUIPairedDevicesView* NewL(MBtuiPluginViewActivationObserver* aObserver = NULL);
       
    69 
       
    70 		static CBTUIPairedDevicesView* NewLC(CBTUIMainView* aBaseView, CArrayPtrFlat<MGSTabbedView>* aTabViewArray);
       
    71 		
       
    72 		/**
       
    73         * Symbian 2nd phase constructor.
       
    74         */
       
    75         void ConstructL();
       
    76 
       
    77 		void ConstructL( CBTUIMainView* aBaseView, CArrayPtrFlat<MGSTabbedView>* aTabViewArray );
       
    78 
       
    79 		/**
       
    80         * Destructor.
       
    81         */
       
    82         virtual ~CBTUIPairedDevicesView();
       
    83 
       
    84         /**
       
    85         * From MGSTabbedView:
       
    86         * Creates new icon for tab. Ownership is transferred to client.
       
    87         * @since 3.1
       
    88         */       
       
    89         CGulIcon* CreateTabIconL();        
       
    90 
       
    91     public: // Functions from base classes
       
    92         
       
    93         /**
       
    94         * From CAknView Returns view id.
       
    95         * @param None.
       
    96         * @return View id.
       
    97         */
       
    98         TUid Id() const;
       
    99 
       
   100         /**
       
   101         * From CAknView Handles user commands.
       
   102         * @param aCommand A command id.        
       
   103         * @return None.
       
   104         */
       
   105         void HandleCommandL(TInt aCommand);
       
   106 
       
   107 	protected:		
       
   108         /**
       
   109         * C++ default constructor.
       
   110         */
       
   111         CBTUIPairedDevicesView (MBtuiPluginViewActivationObserver* aObserver= NULL);
       
   112 
       
   113     private: // Functions from base classes
       
   114 
       
   115         /**
       
   116         * From CAknView Activates view.
       
   117         * @param aPrevViewId Id of previous view.
       
   118         * @param aCustomMessageId Custom message id.
       
   119         * @param aCustomMessage Custom message.
       
   120         * @return None.
       
   121         */
       
   122         void DoActivateL( const TVwsViewId& aPrevViewId,
       
   123                                 TUid aCustomMessageId,
       
   124                           const TDesC8& aCustomMessage );
       
   125 
       
   126         /**
       
   127         * From CAknView Deactivates view.        
       
   128         * @param None.
       
   129         * @return None.
       
   130         */
       
   131         void DoDeactivate();       
       
   132 
       
   133         /**
       
   134         * From CAknView Dynamically initialises options menu.
       
   135         * @param aResourceId Id identifying the menu pane to initialise.
       
   136         * @param aMenuPane The in-memory representation of the menu pane.
       
   137         * @return None.
       
   138         */
       
   139         void DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane);
       
   140 
       
   141 		// implemented from MProgressDialogCallback
       
   142         /** This is used to cancel connecting and pairing, if user presses the Cancel-button.
       
   143         * From MProgressDialogCallback Get's called when a dialog is dismissed.        
       
   144         * @param aButtonId Id of the pressed button.
       
   145         * @return None.
       
   146         */
       
   147         void DialogDismissedL( TInt aButtonId );
       
   148 
       
   149 	public: // from MBTDeviceObserver
       
   150     	/**
       
   151         * Informs the observer that an error happened in changing device status or a new device added.
       
   152         * @param aErr Symbian error code
       
   153         * @param aDevice the device which is changed.
       
   154         * @param aDevNameArray hold conflicting devices' short names if "AlreadyExist" error happened during "connect"
       
   155         * @return None.
       
   156         */
       
   157 		void NotifyChangeDeviceComplete(const TInt aErr, const TBTDevice& aDevice,
       
   158 			const RBTDevNameArray* /*aDevNameArray*/ )	;
       
   159     	/**
       
   160         * Leaving version of NotifyChangeDeviceComplete
       
   161         * @param aErr Symbian error code
       
   162         * @param aDevice the device which is changed.
       
   163         * @param aDevNameArray hold conflicting devices' short names if "AlreadyExist" error happened during "connect"
       
   164         * @return None.
       
   165         */
       
   166 		void NotifyChangeDeviceCompleteL(const TInt aErr, const TBTDevice& aDevice,
       
   167 			const RBTDevNameArray* /*aDevNameArray*/ )	;
       
   168 		
       
   169 		/** Updates the shown device list. This module will send this list forward
       
   170 		 * to container that takes care of the actual display of those devices
       
   171 		 *
       
   172 		 *@param aDevices all the devices to be shown
       
   173 		 *@param aSelectedItemIndex currently selected item after refresh.
       
   174 		 */
       
   175 		void RefreshDeviceList(const RDeviceArray* aDevices,TInt aSelectedItemIndex);	
       
   176 		
       
   177 	private: // From MBTUIActiveObserver
       
   178 	    
       
   179 	    /**
       
   180 	     * Callback to notify that an outstanding request has completed.
       
   181 	     * @param aActive Pointer to the active object that completed.
       
   182 	     * @param aId The ID that identifies the outstanding request.
       
   183 	     * @param aStatus The status of the completed request.
       
   184 	     */
       
   185 	    void RequestCompletedL( CBTUIActive* aActive, TInt aId, 
       
   186 	                            TInt aStatus );
       
   187 
       
   188 	    /**
       
   189 	     * Callback to notify that an error has occurred in RunL.
       
   190 	     *
       
   191 	     * @param aActive Pointer to the active object that completed.
       
   192 	     * @param aId The ID that identifies the outstanding request.
       
   193 	     * @param aStatus The status of the completed request.
       
   194 	     */
       
   195 	    void HandleError( CBTUIActive* aActive, TInt aId, 
       
   196 	                      TInt aError );
       
   197 		
       
   198 	public: // Operations to devices not containing confirmation queries
       
   199         /**
       
   200         * Sets the current security setting of the device.
       
   201         * Does not ask user about it.
       
   202         *
       
   203         * @param aTrusted  ETrue when trusted, EFalse if untrusted.
       
   204         * @return None.
       
   205         */
       
   206         void ChangeDeviceSecurityL( TBool aTrusted );
       
   207         		
       
   208         /**
       
   209         * Issues prompts to connects to specified accessory.
       
   210         * Connects to it if user andswers yes.
       
   211         *
       
   212         * @param TBTDevice  connect to this device
       
   213         * @return None.
       
   214         */
       
   215 		void ConnectL( const TBTDevice& aDevice, TBool aNewWaitNote );        
       
   216    
       
   217         /**
       
   218         * Disconnects from the selected BT Accessory.
       
   219         *
       
   220         * @param None.
       
   221         * @return None.
       
   222         */
       
   223         void DisconnectL();
       
   224 		
       
   225 		/**
       
   226         * Removes iDisconnectQueryDlg created in DisconnectL
       
   227         *
       
   228         * @param None.
       
   229         * @return None.
       
   230         */        
       
   231         void CancelDisconnectQueryDlg();
       
   232         
       
   233         /**
       
   234         * Disconnects from the selected BT Accessory without query.
       
   235         *
       
   236         * @param None.
       
   237         * @return None.
       
   238         */        
       
   239         void DisconnectWithoutQuery();
       
   240 
       
   241     	/** Checks if there is an active phonecall.
       
   242     	*@return ETrue if there is, EFalse otherwise
       
   243     	*/
       
   244     	TBool CallOnGoing();
       
   245               		
       
   246 
       
   247 		/** This is used to create TCallBack to help. This is static, since TCallBack does not
       
   248 		 * allow instance methods. This is used by BlockDeviceDlgL to add help callback to the query.
       
   249 		 *
       
   250 		 * @param aTCoeHelpContext. Must be instance TCoeHelpContext, or NULL.
       
   251 		 * If this is not specified this will open help about blocked devices.
       
   252 		 * This is not an instance of TCoeHelpContext, since TCallback does not allow
       
   253 		 * parameters of other type that TAny*.
       
   254 		 * @return allways KErrNone. TCallBack does not allow void functions
       
   255 		 */
       
   256 		static TInt LaunchHelp(TAny *aTCoeHelpContext=NULL);
       
   257 
       
   258 	private: //These handle command given by user	
       
   259         /**
       
   260         * Asks new nick name for the BT Device from user and
       
   261         * attempt to rename the device. Failures are handled by NotifyChangeDeviceComplete.
       
   262         *
       
   263         * @param None.
       
   264         * @return None.
       
   265         */
       
   266         void RenameDeviceDlgL();
       
   267 
       
   268         /**
       
   269         * Asks confirmation for deleting a BT Device from user.
       
   270         * Delete the current device if yes replied yes.
       
   271         *
       
   272         * @param None.
       
   273         * @return None.
       
   274         */
       
   275         void DeleteDeviceDlgL();
       
   276 
       
   277         /**
       
   278         * Asks confirmation for deleting all BT devices from user.
       
   279         * Delete the devices if yes replied yes.
       
   280         *
       
   281         * @param None.
       
   282         * @return None.
       
   283         */
       
   284         void DeleteAllDevicesDlgL();
       
   285 
       
   286         /**
       
   287         * Initiates the pairing procedure to get a new paired device.
       
   288         * DeviceSearchComplete is called after the dialog is done.
       
   289         *
       
   290         * @param None.
       
   291         * @return None.
       
   292         */
       
   293         void NewPairedDeviceDlgL();
       
   294         
       
   295   		/**
       
   296         * Asks confirmation for Blocking the selected BT Device.
       
   297         * Blocks the current device if yes replied yes.
       
   298         *
       
   299         * @param None.
       
   300         * @return None.
       
   301         */
       
   302 		void BlockDeviceDlgL();
       
   303 		
       
   304 		/**Opens a wait note.
       
   305 		 *
       
   306 		 *@param dialog. The dialog object to be used for displaying this note.
       
   307 		 *@param aNoteResource The resource of the note, not including the text.
       
   308 		 *@param aNoteTextResource The text resource. The %U if this note is filled up with aDevName.
       
   309 		 *@param aSec SecondaryDisplaycommand
       
   310 		 *@param aDevName The dev name filled in aNoteTextResource
       
   311 		 */		
       
   312 		void OpenWaitNoteL(CAknWaitDialog *&dialog,TUint aNoteResource,TUint aNoteTextResource,
       
   313 			TSecondaryDisplayBtuiDialogs aSec,const TDesC& aDevName);
       
   314 		
       
   315 		/** Open Setting view for peripheral devices
       
   316 		 * 
       
   317 		 * @param None.
       
   318 		 * @return None.
       
   319 		 */
       
   320 		void LaunchSettingViewL();
       
   321 
       
   322 		/** Setup device specific menu options
       
   323 		 * 
       
   324 		 * @param None.
       
   325 		 * @return None.
       
   326 		 */
       
   327 		void SetupMenuCmd(TInt aIndex, CEikMenuPane* aMenu);
       
   328 		
       
   329 		
       
   330 	public:	// Inherited from MBTEngSdpResultReceiver
       
   331 		
       
   332 		
       
   333 		/** Inherited from MBTEngSdpResultReceiver and implemented as empty, 
       
   334 		 * since this class will not do service searches, only device searches.
       
   335 		 */
       
   336 		void ServiceSearchComplete( const RSdpRecHandleArray& aResult, 
       
   337 			TUint aTotalRecordsCount, TInt aErr ) ;
       
   338 		/** Inherited from MBTEngSdpResultReceiver and implemented as empty, 
       
   339 		 * since this class will not do attributes seaches, only device searches.
       
   340 		 */
       
   341     	void AttributeSearchComplete( TSdpServRecordHandle aHandle, 
       
   342     		const RSdpResultArray& aAttr,TInt aErr ) ;		
       
   343 		/** Inherited from MBTEngSdpResultReceiver and implemented as empty, 
       
   344 		 * since this class will not do service attribute seaches, only device searches.
       
   345 		 */
       
   346 	    void ServiceAttributeSearchComplete( TSdpServRecordHandle aHandle,
       
   347 	    	const RSdpResultArray& aAttr,TInt aErr );
       
   348 
       
   349 	  /**
       
   350 	    * Provides notification of the result of the discovery of nearby 
       
   351 	    * Bluetooth devices. If a device is selected this class will try to pair it.
       
   352 		*
       
   353 	    * @param aDevice The data structure encapsulates all information 
       
   354 	    *                about the selected device. Ownership of the data 
       
   355 	    *                structure has not been transfered and is still with
       
   356 	    *                the API client.
       
   357 	    *				 This is not TBTDevice that is normally used inside the UI.	    
       
   358 	    * @param aErr Error code of the device search operation; KErrNone if 
       
   359 	    *             sucessful, KErrCancel if the user cancelled the 
       
   360 	    *             dialog, KErrAbort if CBTEngDiscovery::CancelSearchRemoteDevice
       
   361 	    *             was called; otherwise one of the system-wide error codes.
       
   362 	    */
       
   363 	    void DeviceSearchComplete( CBTDevice* aDevice, TInt aErr );
       
   364 	    
       
   365 	    /**
       
   366 	     * Provides notification of the result of the discovery of nearby 
       
   367 	     * Bluetooth devices and EIR data. If a device is selected this class will try to pair it.
       
   368 	     *
       
   369 	     * @since S60 v5.1
       
   370 	     * @param aDevice The data structure encapsulates information 
       
   371 	     *                about the selected device. 
       
   372 	     *                Ownership of the data structure has not been transfered and
       
   373 	     *                is still with the API client.
       
   374 	     * @param aEirWrapper Contains the EIR data of the remote device.
       
   375 	     *                Ownership of the data structure has not been transfered and
       
   376 	     *                is still with the API client. 
       
   377 	     * @param aErr Error code of the device search operation; KErrNone if 
       
   378 	     *             sucessful, KErrCancel if the user cancelled the 
       
   379 	     *             dialog, KErrAbort if CBTEngDiscovery::CancelSearchRemoteDevice
       
   380 	     *             was called; otherwise one of the system-wide error codes.
       
   381 	     */	    
       
   382 	    void DeviceSearchComplete( CBTDevice* aDevice, 
       
   383 	            TNameEntry* aNameEntry, 
       
   384 	            TInt aErr );
       
   385 	    
       
   386 private:	    
       
   387 	  /** Leaving version of DeviceSearchComplete.
       
   388 		*
       
   389 	    * @param aDevice The data structure encapsulates all information 
       
   390 	    *                about the selected device. Ownership of the data 
       
   391 	    *                structure has not been transfered and is still with
       
   392 	    *                the API client.
       
   393 	    *				 This is not TBTDevice that is normally used inside the UI.
       
   394 	    * @param aEirWrapper Contains the EIR data of the remote device.
       
   395         *                Ownership of the data structure has not been transfered and
       
   396         *                is still with the API client.	    
       
   397 	    * @param aErr Error code of the device search operation; KErrNone if 
       
   398 	    *             sucessful, KErrCancel if the user cancelled the 
       
   399 	    *             dialog, KErrAbort if CBTEngDiscovery::CancelSearchRemoteDevice
       
   400 	    *             was called; otherwise one of the system-wide error codes.
       
   401 	    */
       
   402 	    
       
   403 	    void DeviceSearchCompleteL( CBTDevice* aDevice, 
       
   404 	            TNameEntry* aNameEntry, TInt aErr );
       
   405 	    
       
   406 	  /** Shows 'Disonnect first' note
       
   407 		*
       
   408 	    * @param aDevice 
       
   409 	    */	    
       
   410         void ShowDisconnecNoteL(TBTDevice *aDevice);	
       
   411         
       
   412         /**
       
   413          * Auto connect to headset after pairing succeeded.
       
   414          * @param aCount the counter of connecting request issuing staring from 0.
       
   415          */
       
   416         void ConnectIfNeededAfterPairL( TInt aCount );
       
   417         
       
   418 	public: // internal methods for informing operation completes	    
       
   419         /**
       
   420         * Informs that pairing attempt of a device has been completed.
       
   421         * Dismisses wait note and displays questions about authorizing and
       
   422         * connecting, if the device is connectable.
       
   423         *
       
   424         * This method is called by ModifyDeviceChangeL. This method will not inform
       
   425         * iContainer about the pairing since that is done by ModifyDeviceChangeL.
       
   426         *
       
   427         * @param aError Status code of the operation.
       
   428         * @param aDeviceIndex the new place of the device in UI
       
   429         * @return None.
       
   430         */  
       
   431 	    void BondingCompleteL( TInt aError,const TBTDevice& aDevice);
       
   432 	    
       
   433 	    /** Informs that attempt to connect to a device is completed. Closes wait
       
   434 	     * note and if there was an error shows the error notice.
       
   435 	     *
       
   436          * This method is called by ModifyDeviceChangeL. This method will not inform
       
   437          * iContainer about the pairing since that is done by ModifyDeviceChangeL.	    
       
   438          *
       
   439 	     * @param aError KErrNone or system wide error code
       
   440 	     * @param aDeviceIndex The index of the new device 
       
   441 	     * @param aConflictingDeviceName this is filled only when
       
   442 	     */    	
       
   443     	void ConnectCompleteL(TInt aError,const TBTDevice& aDevice,
       
   444     	  const RBTDevNameArray* aConflictingDeviceNames=NULL);
       
   445     	  
       
   446     	  
       
   447        /**
       
   448         * From MBTEngSettingsObserver - Called when powerstate is changed
       
   449         * @param TBTPowerStateValue power state
       
   450         * @return None
       
   451         */       
       
   452 		void PowerStateChanged( TBTPowerStateValue aState );
       
   453 		
       
   454         /**
       
   455         * From MBTEngSettingsObserver - Called when visibility is changed
       
   456         * @param TBTPowerStateValue state of visibility mode
       
   457         * @return None
       
   458         */    		
       
   459 		void VisibilityModeChanged( TBTVisibilityMode aState );
       
   460 		 
       
   461     	
       
   462     private: // Data
       
   463     
       
   464         CAknWaitDialog*                 iWaitForPairingDlg; 	// Wait note for pairing
       
   465         CAknWaitDialog*                 iWaitForConnectDlg; 	// Wait note for connecting to BT Accessory        
       
   466 		CAknQueryDialog* 				iDisconnectQueryDlg;	// Question dialog for disconnecting BT Accessory
       
   467         TBool                           iHelpEnabled; 				// Flag for the Help feature
       
   468 		
       
   469 		// these are needed so these are owened by someone
       
   470 		// and can be cleaned up, in case the operations are interrupted by the user.
       
   471 		CBTDevice*						iPairingDevice;
       
   472 		TNameEntry                      iPairingDevNameEntry;
       
   473 		TBTDevice* 						iConnectDevice; 	//device we are trying to connect to
       
   474 		TBTDevice 						iDisconnectQueryDevice; 	//device we are trying to disconnect
       
   475 				
       
   476 		CBTEngDiscovery*				iDeviceSearcher;	// used only for searching devices, not for device discovery
       
   477 		CBTEngSettings*					iBtEngSettings;		// used only for turning on bluetooth, 
       
   478 		CBTUIPluginMan* 				iBTPluginMan;		
       
   479         CGSTabHelper* 					iTabHelper;
       
   480 	    CBTUIMainView*					iBaseView; 
       
   481 		TBool							iConstructAsGsPlugin;	// Flag that indicate this obj is served as GS plugin not BTUI app's plugin.
       
   482         TInt                            iExpectedCallBack;      // In case of DeleteAll, counter for expected callback NotifyChangeDeviceCompleteL()
       
   483         TBool                           iSearchOngoing;        
       
   484         TBool							iIsConnectDevice;
       
   485 		MBtuiPluginViewActivationObserver* iActivationObserver; // view activation observer        
       
   486         TBool 							iIsAlreadyConnected; // used only for showing "Connected to" note once for Stereo device 
       
   487         TBTDevice                       iMenuDevice;
       
   488         CEikMenuPane*                   iActiveMenuPane;
       
   489         CBTUIActive*                    iActive;   // used for subscribing notifier lock status
       
   490         TBTDevAddr                      iPairConnectAddr; // the address of the just paired device
       
   491                                                           // with which a connection establishment is pending
       
   492         TBool                           iIsPairConnect; // if we are doing auto-connecting after pairing or not
       
   493 
       
   494 };
       
   495 
       
   496 #endif
       
   497 
       
   498