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 <GroupLayoutBuilder.h>
16 #include <SpaceLayoutItem.h>
17 #include <StringView.h>
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "Device View"
24 BluetoothDeviceView::BluetoothDeviceView(BRect frame
, BluetoothDevice
* bDevice
,
25 uint32 resizingMode
, uint32 flags
)
27 BView(frame
,"BluetoothDeviceView", resizingMode
, flags
| B_WILL_DRAW
),
30 SetViewColor(B_TRANSPARENT_COLOR
);
33 SetLayout(new BGroupLayout(B_VERTICAL
));
35 fName
= new BStringView("name", "");
36 fName
->SetFont(be_bold_font
);
37 fName
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
39 fBdaddr
= new BStringView("bdaddr",
40 bdaddrUtils::ToString(bdaddrUtils::NullAddress()));
41 fBdaddr
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
43 fClassService
= new BStringView("ServiceClass",
44 B_TRANSLATE("Service classes: "));
45 fClassService
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
48 fClass
= new BStringView("class", "- / -");
49 fClass
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
51 fHCIVersionProperties
= new BStringView("hci", "");
52 fHCIVersionProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
54 fLMPVersionProperties
= new BStringView("lmp", "");
55 fLMPVersionProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
57 fManufacturerProperties
= new BStringView("manufacturer", "");
58 fManufacturerProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
60 fACLBuffersProperties
= new BStringView("buffers acl", "");
61 fACLBuffersProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
63 fSCOBuffersProperties
= new BStringView("buffers sco", "");
64 fSCOBuffersProperties
->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT
,
68 fIcon
= new BView(BRect(0, 0, 32 - 1, 32 - 1), "Icon", B_FOLLOW_ALL
,
70 fIcon
->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
72 SetBluetoothDevice(bDevice
);
74 AddChild(BGroupLayoutBuilder(B_HORIZONTAL
, 5)
77 .Add(BGroupLayoutBuilder(B_VERTICAL
)
87 .Add(fHCIVersionProperties
)
89 .Add(fLMPVersionProperties
)
91 .Add(fManufacturerProperties
)
93 .Add(fACLBuffersProperties
)
95 .Add(fSCOBuffersProperties
)
96 .SetInsets(5, 5, 5, 5)
98 // .Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
99 .SetInsets(10, 10, 10, 10)
105 BluetoothDeviceView::~BluetoothDeviceView(void)
112 BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice
* bDevice
)
114 if (bDevice
!= NULL
) {
116 SetName(bDevice
->GetFriendlyName().String());
118 fName
->SetText(bDevice
->GetFriendlyName().String());
119 fBdaddr
->SetText(bdaddrUtils::ToString(bDevice
->GetBluetoothAddress()));
121 BString
string(B_TRANSLATE("Service classes: "));
122 bDevice
->GetDeviceClass().GetServiceClass(string
);
123 fClassService
->SetText(string
.String());
126 bDevice
->GetDeviceClass().GetMajorDeviceClass(string
);
128 bDevice
->GetDeviceClass().GetMinorDeviceClass(string
);
129 fClass
->SetText(string
.String());
131 bDevice
->GetDeviceClass().Draw(fIcon
, BPoint(Bounds().left
, Bounds().top
));
136 if (bDevice
->GetProperty("hci_version", &value
) == B_OK
)
137 string
<< "HCI ver: " << BluetoothHciVersion(value
);
138 if (bDevice
->GetProperty("hci_revision", &value
) == B_OK
)
139 string
<< " HCI rev: " << value
;
141 fHCIVersionProperties
->SetText(string
.String());
144 if (bDevice
->GetProperty("lmp_version", &value
) == B_OK
)
145 string
<< "LMP ver: " << BluetoothLmpVersion(value
);
146 if (bDevice
->GetProperty("lmp_subversion", &value
) == B_OK
)
147 string
<< " LMP subver: " << value
;
148 fLMPVersionProperties
->SetText(string
.String());
151 if (bDevice
->GetProperty("manufacturer", &value
) == B_OK
)
152 string
<< B_TRANSLATE("Manufacturer: ")
153 << BluetoothManufacturer(value
);
154 fManufacturerProperties
->SetText(string
.String());
157 if (bDevice
->GetProperty("acl_mtu", &value
) == B_OK
)
158 string
<< "ACL mtu: " << value
;
159 if (bDevice
->GetProperty("acl_max_pkt", &value
) == B_OK
)
160 string
<< B_TRANSLATE(" packets: ") << value
;
161 fACLBuffersProperties
->SetText(string
.String());
164 if (bDevice
->GetProperty("sco_mtu", &value
) == B_OK
)
165 string
<< "SCO mtu: " << value
;
166 if (bDevice
->GetProperty("sco_max_pkt", &value
) == B_OK
)
167 string
<< B_TRANSLATE(" packets: ") << value
;
168 fSCOBuffersProperties
->SetText(string
.String());
176 BluetoothDeviceView::SetTarget(BHandler
* target
)
183 BluetoothDeviceView::MessageReceived(BMessage
* message
)
185 // If we received a dropped message, try to see if it has color data
187 if (message
->WasDropped()) {
192 BView::MessageReceived(message
);
197 BluetoothDeviceView::SetEnabled(bool value
)