2 * Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
3 * All rights reserved. Distributed under the terms of the MIT License.
5 #include "BluetoothDeviceView.h"
6 #include <bluetooth/bdaddrUtils.h>
8 #include <bluetooth/LocalDevice.h>
9 #include <bluetooth/HCI/btHCI_command.h>
14 #include <LayoutBuilder.h>
16 #include <SpaceLayoutItem.h>
17 #include <StringView.h>
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "Device View"
24 BluetoothDeviceView::BluetoothDeviceView(BluetoothDevice
* bDevice
, uint32 flags
)
26 BView("BluetoothDeviceView", flags
| B_WILL_DRAW
),
29 fName
= new BStringView("name", "");
30 fName
->SetFont(be_bold_font
);
31 fName
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
33 fBdaddr
= new BStringView("bdaddr",
34 bdaddrUtils::ToString(bdaddrUtils::NullAddress()));
35 fBdaddr
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
37 fClassService
= new BStringView("ServiceClass",
38 B_TRANSLATE("Service classes: "));
39 fClassService
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
42 fClass
= new BStringView("class", "- / -");
43 fClass
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
45 fHCIVersionProperties
= new BStringView("hci", "");
46 fHCIVersionProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
48 fLMPVersionProperties
= new BStringView("lmp", "");
49 fLMPVersionProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
51 fManufacturerProperties
= new BStringView("manufacturer", "");
52 fManufacturerProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
54 fACLBuffersProperties
= new BStringView("buffers acl", "");
55 fACLBuffersProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
57 fSCOBuffersProperties
= new BStringView("buffers sco", "");
58 fSCOBuffersProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
61 fIcon
= new BView(BRect(0, 0, 32 - 1, 32 - 1), "Icon", B_FOLLOW_ALL
,
63 fIcon
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
65 SetBluetoothDevice(bDevice
);
67 BLayoutBuilder::Group
<>(this, B_HORIZONTAL
, 5)
70 .AddGroup(B_VERTICAL
, 0)
76 .Add(fHCIVersionProperties
)
77 .Add(fLMPVersionProperties
)
78 .Add(fManufacturerProperties
)
79 .Add(fACLBuffersProperties
)
80 .Add(fSCOBuffersProperties
)
88 BluetoothDeviceView::~BluetoothDeviceView()
94 BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice
* bDevice
)
96 if (bDevice
!= NULL
) {
97 SetName(bDevice
->GetFriendlyName().String());
99 fName
->SetText(bDevice
->GetFriendlyName().String());
100 fBdaddr
->SetText(bdaddrUtils::ToString(bDevice
->GetBluetoothAddress()));
102 BString
string(B_TRANSLATE("Service classes: "));
103 bDevice
->GetDeviceClass().GetServiceClass(string
);
104 fClassService
->SetText(string
.String());
107 bDevice
->GetDeviceClass().GetMajorDeviceClass(string
);
109 bDevice
->GetDeviceClass().GetMinorDeviceClass(string
);
110 fClass
->SetText(string
.String());
112 bDevice
->GetDeviceClass().Draw(fIcon
, BPoint(Bounds().left
, Bounds().top
));
117 if (bDevice
->GetProperty("hci_version", &value
) == B_OK
)
118 string
<< "HCI ver: " << BluetoothHciVersion(value
);
119 if (bDevice
->GetProperty("hci_revision", &value
) == B_OK
)
120 string
<< " HCI rev: " << value
;
122 fHCIVersionProperties
->SetText(string
.String());
125 if (bDevice
->GetProperty("lmp_version", &value
) == B_OK
)
126 string
<< "LMP ver: " << BluetoothLmpVersion(value
);
127 if (bDevice
->GetProperty("lmp_subversion", &value
) == B_OK
)
128 string
<< " LMP subver: " << value
;
129 fLMPVersionProperties
->SetText(string
.String());
132 if (bDevice
->GetProperty("manufacturer", &value
) == B_OK
)
133 string
<< B_TRANSLATE("Manufacturer: ")
134 << BluetoothManufacturer(value
);
135 fManufacturerProperties
->SetText(string
.String());
138 if (bDevice
->GetProperty("acl_mtu", &value
) == B_OK
)
139 string
<< "ACL mtu: " << value
;
140 if (bDevice
->GetProperty("acl_max_pkt", &value
) == B_OK
)
141 string
<< B_TRANSLATE(" packets: ") << value
;
142 fACLBuffersProperties
->SetText(string
.String());
145 if (bDevice
->GetProperty("sco_mtu", &value
) == B_OK
)
146 string
<< "SCO mtu: " << value
;
147 if (bDevice
->GetProperty("sco_max_pkt", &value
) == B_OK
)
148 string
<< B_TRANSLATE(" packets: ") << value
;
149 fSCOBuffersProperties
->SetText(string
.String());
155 BluetoothDeviceView::SetTarget(BHandler
* target
)
161 BluetoothDeviceView::MessageReceived(BMessage
* message
)
163 // If we received a dropped message, try to see if it has color data
165 if (message
->WasDropped()) {
170 BView::MessageReceived(message
);
175 BluetoothDeviceView::SetEnabled(bool value
)