xref: /haiku/src/preferences/bluetooth/BluetoothDeviceView.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
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 <LayoutBuilder.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 
24 BluetoothDeviceView::BluetoothDeviceView(BluetoothDevice* bDevice, uint32 flags)
25 	:
26 	BView("BluetoothDeviceView", flags | B_WILL_DRAW),
27 	fDevice(bDevice)
28 {
29 	fName = new BStringView("name", "");
30 	fName->SetFont(be_bold_font);
31 	fName->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
32 
33 	fBdaddr = new BStringView("bdaddr",
34 		bdaddrUtils::ToString(bdaddrUtils::NullAddress()));
35 	fBdaddr->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
36 
37 	fClassService = new BStringView("ServiceClass",
38 		B_TRANSLATE("Service classes: "));
39 	fClassService->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
40 		B_ALIGN_MIDDLE));
41 
42 	fClass = new BStringView("class", "- / -");
43 	fClass->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
44 
45 	fHCIVersionProperties = new BStringView("hci", "");
46 	fHCIVersionProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
47 		B_ALIGN_MIDDLE));
48 	fLMPVersionProperties = new BStringView("lmp", "");
49 	fLMPVersionProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
50 		B_ALIGN_MIDDLE));
51 	fManufacturerProperties = new BStringView("manufacturer", "");
52 	fManufacturerProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
53 		B_ALIGN_MIDDLE));
54 	fACLBuffersProperties = new BStringView("buffers acl", "");
55 	fACLBuffersProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
56 		B_ALIGN_MIDDLE));
57 	fSCOBuffersProperties = new BStringView("buffers sco", "");
58 	fSCOBuffersProperties->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
59 		B_ALIGN_MIDDLE));
60 
61 	fIcon = new BView(BRect(0, 0, 32 - 1, 32 - 1), "Icon", B_FOLLOW_ALL,
62 		B_WILL_DRAW);
63 	fIcon->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
64 
65 	SetBluetoothDevice(bDevice);
66 
67 	BLayoutBuilder::Group<>(this, B_HORIZONTAL, 5)
68 		.SetInsets(10)
69 		.Add(fIcon)
70 		.AddGroup(B_VERTICAL, 0)
71 			.SetInsets(5)
72 			.Add(fName)
73 			.Add(fBdaddr)
74 			.Add(fClass)
75 			.Add(fClassService)
76 			.Add(fHCIVersionProperties)
77 			.Add(fLMPVersionProperties)
78 			.Add(fManufacturerProperties)
79 			.Add(fACLBuffersProperties)
80 			.Add(fSCOBuffersProperties)
81 		.End()
82 		.AddGlue()
83 	.End();
84 
85 }
86 
87 
88 BluetoothDeviceView::~BluetoothDeviceView()
89 {
90 }
91 
92 
93 void
94 BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
95 {
96 	if (bDevice != NULL) {
97 		SetName(bDevice->GetFriendlyName().String());
98 
99 		fName->SetText(bDevice->GetFriendlyName().String());
100 		fBdaddr->SetText(bdaddrUtils::ToString(bDevice->GetBluetoothAddress()));
101 
102 		BString string(B_TRANSLATE("Service classes: "));
103 		bDevice->GetDeviceClass().GetServiceClass(string);
104 		fClassService->SetText(string.String());
105 
106 		string = "";
107 		bDevice->GetDeviceClass().GetMajorDeviceClass(string);
108 		string << " / ";
109 		bDevice->GetDeviceClass().GetMinorDeviceClass(string);
110 		fClass->SetText(string.String());
111 
112 		bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top));
113 
114 		uint32 value;
115 
116 		string = "";
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 ;
121 
122 		fHCIVersionProperties->SetText(string.String());
123 
124 		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());
130 
131 		string = "";
132 		if (bDevice->GetProperty("manufacturer", &value) == B_OK)
133 			string << B_TRANSLATE("Manufacturer: ")
134 			   	<< BluetoothManufacturer(value);
135 		fManufacturerProperties->SetText(string.String());
136 
137 		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());
143 
144 		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());
150 	}
151 }
152 
153 
154 void
155 BluetoothDeviceView::SetTarget(BHandler* target)
156 {
157 }
158 
159 
160 void
161 BluetoothDeviceView::MessageReceived(BMessage* message)
162 {
163 	// If we received a dropped message, try to see if it has color data
164 	// in it
165 	if (message->WasDropped()) {
166 
167 	}
168 
169 	// The default
170 	BView::MessageReceived(message);
171 }
172 
173 
174 void
175 BluetoothDeviceView::SetEnabled(bool value)
176 {
177 }
178