1/*
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.
4 */
5#include "BluetoothDeviceView.h"
6#include <bluetooth/bdaddrUtils.h>
7
8#include <bluetooth/LocalDevice.h>
9#include <bluetooth/HCI/btHCI_command.h>
10
11
12#include <Bitmap.h>
13#include <Catalog.h>
14#include <GroupLayoutBuilder.h>
15#include <Locale.h>
16#include <SpaceLayoutItem.h>
17#include <StringView.h>
18#include <TextView.h>
19
20
21#undef B_TRANSLATION_CONTEXT
22#define B_TRANSLATION_CONTEXT "Device View"
23
24BluetoothDeviceView::BluetoothDeviceView(BRect frame, BluetoothDevice* bDevice,
25	uint32 resizingMode, uint32 flags)
26	:
27	BView(frame,"BluetoothDeviceView", resizingMode, flags | B_WILL_DRAW),
28	fDevice(bDevice)
29{
30	SetViewColor(B_TRANSPARENT_COLOR);
31	SetLowColor(0, 0, 0);
32
33	SetLayout(new BGroupLayout(B_VERTICAL));
34
35	fName = new BStringView("name", "");
36	fName->SetFont(be_bold_font);
37	fName->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
38
39	fBdaddr = new BStringView("bdaddr",
40		bdaddrUtils::ToString(bdaddrUtils::NullAddress()));
41	fBdaddr->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
42
43	fClassService = new BStringView("ServiceClass",
44		B_TRANSLATE("Service classes: "));
45	fClassService->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
46		B_ALIGN_MIDDLE));
47
48	fClass = new BStringView("class", "- / -");
49	fClass->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
50
51	fHCIVersionProperties = new BStringView("hci", "");
52	fHCIVersionProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
53		B_ALIGN_MIDDLE));
54	fLMPVersionProperties = new BStringView("lmp", "");
55	fLMPVersionProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
56		B_ALIGN_MIDDLE));
57	fManufacturerProperties = new BStringView("manufacturer", "");
58	fManufacturerProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
59		B_ALIGN_MIDDLE));
60	fACLBuffersProperties = new BStringView("buffers acl", "");
61	fACLBuffersProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
62		B_ALIGN_MIDDLE));
63	fSCOBuffersProperties = new BStringView("buffers sco", "");
64	fSCOBuffersProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
65		B_ALIGN_MIDDLE));
66
67
68	fIcon = new BView(BRect(0, 0, 32 - 1, 32 - 1), "Icon", B_FOLLOW_ALL,
69		B_WILL_DRAW);
70	fIcon->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
71
72	SetBluetoothDevice(bDevice);
73
74	AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 5)
75				.Add(fIcon)
76				.AddGlue()
77				.Add(BGroupLayoutBuilder(B_VERTICAL)
78						.Add(fName)
79						.AddGlue()
80						.Add(fBdaddr)
81						.AddGlue()
82						.Add(fClass)
83						.AddGlue()
84						.Add(fClassService)
85						.AddGlue()
86						.AddGlue()
87						.Add(fHCIVersionProperties)
88						.AddGlue()
89						.Add(fLMPVersionProperties)
90						.AddGlue()
91						.Add(fManufacturerProperties)
92						.AddGlue()
93						.Add(fACLBuffersProperties)
94						.AddGlue()
95						.Add(fSCOBuffersProperties)
96						.SetInsets(5, 5, 5, 5)
97					)
98			//	.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
99			.SetInsets(10, 10, 10, 10)
100	);
101
102}
103
104
105BluetoothDeviceView::~BluetoothDeviceView(void)
106{
107
108}
109
110
111void
112BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
113{
114	if (bDevice != NULL) {
115
116		SetName(bDevice->GetFriendlyName().String());
117
118		fName->SetText(bDevice->GetFriendlyName().String());
119		fBdaddr->SetText(bdaddrUtils::ToString(bDevice->GetBluetoothAddress()));
120
121		BString string(B_TRANSLATE("Service classes: "));
122		bDevice->GetDeviceClass().GetServiceClass(string);
123		fClassService->SetText(string.String());
124
125		string = "";
126		bDevice->GetDeviceClass().GetMajorDeviceClass(string);
127		string << " / ";
128		bDevice->GetDeviceClass().GetMinorDeviceClass(string);
129		fClass->SetText(string.String());
130
131		bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top));
132
133		uint32 value;
134
135		string = "";
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 ;
140
141		fHCIVersionProperties->SetText(string.String());
142
143		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());
149
150		string = "";
151		if (bDevice->GetProperty("manufacturer", &value) == B_OK)
152			string << B_TRANSLATE("Manufacturer: ")
153			   	<< BluetoothManufacturer(value);
154		fManufacturerProperties->SetText(string.String());
155
156		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());
162
163		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());
169
170	}
171
172}
173
174
175void
176BluetoothDeviceView::SetTarget(BHandler* target)
177{
178
179}
180
181
182void
183BluetoothDeviceView::MessageReceived(BMessage* message)
184{
185	// If we received a dropped message, try to see if it has color data
186	// in it
187	if (message->WasDropped()) {
188
189	}
190
191	// The default
192	BView::MessageReceived(message);
193}
194
195
196void
197BluetoothDeviceView::SetEnabled(bool value)
198{
199
200}
201