1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef BTUIUTIL_H |
|
19 #define BTUIUTIL_H |
|
20 |
|
21 #include <qglobal.h> |
|
22 #include <bt_sock.h> |
|
23 |
|
24 /*! |
|
25 Converts a QString which contains a BT device address in readable format to |
|
26 Symbian native TBTDevAddr type. |
|
27 */ |
|
28 inline void addrReadbleStringToSymbian( const QString &readable, TBTDevAddr &addr) |
|
29 { |
|
30 TBuf<KBTDevAddrSize * 2> buffer(readable.utf16()); |
|
31 addr.SetReadable( buffer ); |
|
32 } |
|
33 |
|
34 /*! |
|
35 Converts a Symbian native TBTDevAddr to |
|
36 QString which contains the BT device address in readable format. |
|
37 */ |
|
38 inline void addrSymbianToReadbleString( QString &readable, const TBTDevAddr &addr) |
|
39 { |
|
40 TBuf<KBTDevAddrSize * 2> buffer; |
|
41 addr.GetReadable( buffer ); |
|
42 readable = QString::fromUtf16( buffer.Ptr(), buffer.Length() ); |
|
43 } |
|
44 |
|
45 /*! |
|
46 Decide the device name to display from the device information, and |
|
47 converts the name if necessary. If the device doesn't have a valid name, |
|
48 the given default name will be used. |
|
49 */ |
|
50 inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device , |
|
51 const TDesC& defaultName ) |
|
52 { |
|
53 // friendly name is preferred if available |
|
54 if( device.IsValidFriendlyName() && device.FriendlyName().Length()){ |
|
55 dispName = QString::fromUtf16( |
|
56 device.FriendlyName().Ptr(), device.FriendlyName().Length() ); |
|
57 } |
|
58 // next preferred is actual device name |
|
59 else if( device.IsValidDeviceName() && device.DeviceName().Length() ) { |
|
60 dispName = QString::fromUtf8( |
|
61 (char*) device.DeviceName().Ptr(), device.DeviceName().Length() ); |
|
62 } |
|
63 else { |
|
64 // finally, use default name if nothing else is available |
|
65 dispName = QString::fromUtf16( |
|
66 defaultName.Ptr(), defaultName.Length() ); |
|
67 } |
|
68 } |
|
69 |
|
70 /*! |
|
71 Guess if the given Class of Device indicates an Audio/Video device (headset and carkit) |
|
72 or not. |
|
73 Computer device supporting audio is not considered as AV device. |
|
74 */ |
|
75 inline bool isAVDevice( const TBTDeviceClass &cod ) |
|
76 { |
|
77 int majorDevCls = cod.MajorDeviceClass(); |
|
78 int minorDevCls = cod.MinorDeviceClass(); |
|
79 return ( ( majorDevCls == EMajorDeviceAV ) |
|
80 || ( cod.MajorServiceClass() == EMajorServiceRendering |
|
81 && majorDevCls != EMajorDeviceImaging ) ); |
|
82 } |
|
83 |
|
84 /*! |
|
85 Guess if the given Class of Device indicates an input device (keyboard and mouse) |
|
86 or not. |
|
87 */ |
|
88 inline bool isHIDDevice( const TBTDeviceClass &cod ) |
|
89 { |
|
90 int majorDevCls = cod.MajorDeviceClass(); |
|
91 int minorDevCls = cod.MinorDeviceClass(); |
|
92 return ( ( majorDevCls == EMajorDevicePeripheral ) && |
|
93 ( minorDevCls == EMinorDevicePeripheralKeyboard || |
|
94 minorDevCls == EMinorDevicePeripheralPointer ) ); |
|
95 } |
|
96 |
|
97 /*! |
|
98 Tells if the given device is bonded. |
|
99 */ |
|
100 inline bool isBonded( const CBTDevice &dev ) |
|
101 { |
|
102 // todo: this has not addresses Just Works pairing mode yet. |
|
103 return dev.IsValidPaired() && dev.IsPaired() && |
|
104 dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; |
|
105 } |
|
106 |
|
107 /*! |
|
108 Tells if the given device supports file transfer. |
|
109 */ |
|
110 inline bool supportsFileTransfer( const TBTDeviceClass &cod ) |
|
111 { |
|
112 int majorDevCls = cod.MajorDeviceClass(); |
|
113 return ( majorDevCls == EMajorDevicePhone |
|
114 || majorDevCls == EMajorDeviceComputer ); |
|
115 } |
|
116 |
|
117 #endif // BTUIMODELUTIL_H |
|