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