bluetoothengine/btui/btuimodel/btuimodelutil.h
changeset 33 837dcc42fd6a
parent 19 43824b19ee35
child 37 91746b151f97
equal deleted inserted replaced
19:43824b19ee35 33:837dcc42fd6a
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : btuimutil.h
       
     4 *  Part of     : BluetoothUI / bluetoothuimodel       *** Info from the SWAD
       
     5 *  Description : utilities in the model for some often used functions, 
       
     6 *                e.g. conversions between Qt and Symbian types.
       
     7 *
       
     8 *  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     9 *  All rights reserved.
       
    10 *  This component and the accompanying materials are made available
       
    11 *  under the terms of "Eclipse Public License v1.0"
       
    12 *  which accompanies this distribution, and is available
       
    13 *  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    14 *
       
    15 *  Initial Contributors:
       
    16 *  Nokia Corporation - initial contribution.
       
    17 *
       
    18 *  Contributors:
       
    19 *  Nokia Corporation
       
    20 * ============================================================================
       
    21 * Template version: 4.2
       
    22 */
       
    23 
       
    24 #ifndef BTUIMODELUTIL_H
       
    25 #define BTUIMODELUTIL_H
       
    26 
       
    27 #include <qglobal.h>
       
    28 #include <bt_sock.h>
       
    29 
       
    30 _LIT(KDefaultBTDevName, "Bluetooth Device" );
       
    31 
       
    32 /*!
       
    33   Converts a QString which contains a BT device address in readable format to
       
    34   Symbian native TBTDevAddr type.
       
    35  */
       
    36 inline void addrReadbleStringToSymbian( const QString &readable, TBTDevAddr &addr)
       
    37 {
       
    38     TBuf<KBTDevAddrSize * 2> buffer(readable.utf16());
       
    39     addr.SetReadable( buffer );
       
    40 }
       
    41 
       
    42 /*!
       
    43   Converts a Symbian native TBTDevAddr to 
       
    44   QString which contains the BT device address in readable format.
       
    45  */
       
    46 inline void addrSymbianToReadbleString( QString &readable, const TBTDevAddr &addr)
       
    47 {
       
    48     TBuf<KBTDevAddrSize * 2> buffer;
       
    49     addr.GetReadable( buffer );
       
    50     readable = QString::fromUtf16( buffer.Ptr(), buffer.Length() );
       
    51 }
       
    52 
       
    53 /*!
       
    54   Decide the device name to display from the device information, and 
       
    55   converts the name if necessary. If the device doesn't have a valid name,
       
    56   the given default name will be used.
       
    57 */
       
    58 inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device ,
       
    59     const TDesC& defaultName )
       
    60 {
       
    61     // friendly name is preferred if available
       
    62     if( device.IsValidFriendlyName() && device.FriendlyName().Length()){
       
    63         dispName = QString::fromUtf16( 
       
    64                 device.FriendlyName().Ptr(), device.FriendlyName().Length() );
       
    65     }
       
    66     // next preferred is actual device name
       
    67     else if( device.IsValidDeviceName() && device.DeviceName().Length() ) {
       
    68         dispName = QString::fromUtf8( 
       
    69                 (char*) device.DeviceName().Ptr(), device.DeviceName().Length() );
       
    70     }
       
    71     else {
       
    72         // finally, use default name if nothing else is available
       
    73         dispName = QString::fromUtf16( 
       
    74                 defaultName.Ptr(), defaultName.Length() );
       
    75     }
       
    76 }
       
    77 
       
    78 /*!
       
    79   Decide the device name to display from the device information, and 
       
    80   converts the name if necessary. If the device doesn't have a valid name,
       
    81   the given default name will be used.
       
    82 */
       
    83 inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device  )
       
    84 {
       
    85     getDeviceDisplayName( dispName, device, KDefaultBTDevName );
       
    86 }
       
    87 
       
    88 
       
    89 /*!
       
    90   Guess if the given Class of Device indicates an Audio/Video device (headset and carkit)
       
    91   or not.
       
    92   Computer device supporting audio is not considered as AV device.
       
    93 */
       
    94 inline bool isAVDevice( const TBTDeviceClass &cod )
       
    95 {
       
    96     int majorDevCls = cod.MajorDeviceClass();
       
    97     int minorDevCls = cod.MinorDeviceClass();
       
    98     return ( ( majorDevCls == EMajorDeviceAV ) 
       
    99         || ( cod.MajorServiceClass() == EMajorServiceRendering 
       
   100         && majorDevCls != EMajorDeviceImaging ) );
       
   101 }
       
   102 
       
   103 /*!
       
   104   Guess if the given Class of Device indicates an input device (keyboard and mouse)
       
   105   or not.
       
   106 */
       
   107 inline bool isHIDDevice( const TBTDeviceClass &cod )
       
   108 {
       
   109     int majorDevCls = cod.MajorDeviceClass();
       
   110     int minorDevCls = cod.MinorDeviceClass();
       
   111     return ( ( majorDevCls == EMajorDevicePeripheral ) &&
       
   112         ( minorDevCls == EMinorDevicePeripheralKeyboard || 
       
   113         minorDevCls == EMinorDevicePeripheralPointer ) );
       
   114 }
       
   115 
       
   116 /*!
       
   117   Tells if the given device has been paired.
       
   118 */
       
   119 inline bool isPaired( const CBTDevice &dev )
       
   120 {
       
   121     return dev.IsValidPaired() && dev.IsPaired() &&
       
   122         dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable;
       
   123 }
       
   124 
       
   125 /*!
       
   126   Tells if the given device supports file transfer.
       
   127 */
       
   128 inline bool supportsFileTransfer( const TBTDeviceClass &cod )
       
   129 {
       
   130     int majorDevCls = cod.MajorDeviceClass();
       
   131     return ( majorDevCls == EMajorDevicePhone 
       
   132             || majorDevCls == EMajorDeviceComputer ); 
       
   133 }
       
   134 
       
   135 /*! 
       
   136     Tells if the given device is currently connected.
       
   137 */
       
   138 inline bool isConnected( CBTEngConnMan &btConnMan, 
       
   139         const TBTDevAddr &addr )
       
   140 {
       
   141     TBTEngConnectionStatus connectStatus( EBTEngNotConnected );
       
   142     btConnMan.IsConnected( addr, connectStatus );
       
   143     return connectStatus == EBTEngConnected;
       
   144 }
       
   145 
       
   146 /*! 
       
   147     Tells if the given device is currently connected.
       
   148 */
       
   149 inline bool isConnected( CBTEngConnMan &btConnMan, 
       
   150         const CBTDevice &dev )
       
   151 {
       
   152     return isConnected( btConnMan, dev.BDAddr() );
       
   153 }
       
   154 
       
   155 /*! 
       
   156     Tells if the given device is connectible with services managed by bteng.
       
   157 */
       
   158 inline bool isConnectible( CBTEngConnMan &btConnMan, 
       
   159         const TBTDeviceClass &devClass )
       
   160 {
       
   161     TBool connectible( false );
       
   162     btConnMan.IsConnectable( devClass, connectible );
       
   163     return connectible;
       
   164 }
       
   165 
       
   166 /*! 
       
   167     Tells if the given device is connectible with services managed by bteng.
       
   168 */
       
   169 inline bool isConnectible( CBTEngConnMan &btConnMan, 
       
   170         const CBTDevice &dev )
       
   171 {
       
   172     return isConnectible( btConnMan, dev.DeviceClass() );
       
   173 }
       
   174 #endif // BTUIMODELUTIL_H