xref: /haiku/src/preferences/bluetooth/BluetoothDeviceView.cpp (revision 3be9edf8da228afd9fec0390f408c964766122aa)
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 #define TR_CONTEXT "Device View"
22 
23 BluetoothDeviceView::BluetoothDeviceView(BRect frame, BluetoothDevice* bDevice, uint32 resizingMode, uint32 flags)
24  :	BView(frame,"BluetoothDeviceView", resizingMode, flags | B_WILL_DRAW),
25     fDevice(bDevice)
26 {
27 	SetViewColor(B_TRANSPARENT_COLOR);
28 	SetLowColor(0,0,0);
29 
30 	SetLayout(new BGroupLayout(B_VERTICAL));
31 
32 	fName = new BStringView("name", "");
33 	fName->SetFont(be_bold_font);
34 
35 	fBdaddr = new BStringView("bdaddr", bdaddrUtils::ToString(bdaddrUtils::NullAddress()));
36 
37 	fClassService = new BStringView("ServiceClass", TR("Service Classes: "));
38 
39 	fClass = new BStringView("class", "- / -");
40 
41 	fHCIVersionProperties = new BStringView("hci", "");
42 	fLMPVersionProperties = new BStringView("lmp", "");
43 	fManufacturerProperties = new BStringView("manufacturer", "");
44 	fBuffersProperties = new BStringView("buffers", "");
45 
46 	fIcon = new BView(BRect(0, 0, 32 - 1, 32 - 1),"Icon", B_FOLLOW_ALL, B_WILL_DRAW);
47 	fIcon->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
48 
49 	SetBluetoothDevice(bDevice);
50 
51 	AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10)
52 				.Add(fIcon)
53 				.AddGlue()
54 				.Add(BGroupLayoutBuilder(B_VERTICAL)
55 						.Add(fName)
56 						.AddGlue()
57 						.Add(fBdaddr)
58 						.AddGlue()
59 						.AddGlue()
60 						.Add(fClass)
61 						.AddGlue()
62 						.Add(fClassService)
63 						.AddGlue()
64 						.Add(fHCIVersionProperties)
65 						.AddGlue()
66 						.Add(fLMPVersionProperties)
67 						.AddGlue()
68 						.Add(fManufacturerProperties)
69 						.AddGlue()
70 						.Add(fBuffersProperties)
71 						.SetInsets(5, 25, 25, 25)
72 					)
73 				.Add(BSpaceLayoutItem::CreateHorizontalStrut(10)
74 			).SetInsets(20, 20, 20, 20)
75 	);
76 
77 }
78 
79 
80 BluetoothDeviceView::~BluetoothDeviceView(void)
81 {
82 
83 }
84 
85 
86 void
87 BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
88 {
89 	if (bDevice != NULL) {
90 
91 		SetName(bDevice->GetFriendlyName().String());
92 
93 		fName->SetText(bDevice->GetFriendlyName().String());
94 		fBdaddr->SetText(bdaddrUtils::ToString(bDevice->GetBluetoothAddress()));
95 
96 		BString str(TR("Service Classes: "));
97 		bDevice->GetDeviceClass().GetServiceClass(str);
98 		fClassService->SetText(str.String());
99 
100 		str = "";
101 		bDevice->GetDeviceClass().GetMajorDeviceClass(str);
102 		str << " / ";
103 		bDevice->GetDeviceClass().GetMinorDeviceClass(str);
104 		fClass->SetText(str.String());
105 
106 		bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top));
107 
108 		uint32 value;
109 
110 		str = "";
111 		if (bDevice->GetProperty("hci_version", &value) == B_OK)
112 			str << "HCI ver: " << BluetoothHciVersion(value);
113 		if (bDevice->GetProperty("hci_revision", &value) == B_OK)
114 			str << " HCI rev: " << value ;
115 
116 		fHCIVersionProperties->SetText(str.String());
117 
118 		str = "";
119 		if (bDevice->GetProperty("lmp_version", &value) == B_OK)
120 			str << "LMP ver: " << BluetoothLmpVersion(value);
121 		if (bDevice->GetProperty("lmp_subversion", &value) == B_OK)
122 			str << " LMP subver: " << value;
123 		fLMPVersionProperties->SetText(str.String());
124 
125 		str = "";
126 		if (bDevice->GetProperty("manufacturer", &value) == B_OK)
127 			str << "Manufacturer: " << BluetoothManufacturer(value);
128 		fManufacturerProperties->SetText(str.String());
129 
130 		str = "";
131 		if (bDevice->GetProperty("acl_mtu", &value) == B_OK)
132 			str << "ACL mtu: " << value;
133 		if (bDevice->GetProperty("acl_max_pkt", &value) == B_OK)
134 			str << " packets: " << value;
135 		if (bDevice->GetProperty("sco_mtu", &value) == B_OK)
136 			str << " SCO mtu: " << value;
137 		if (bDevice->GetProperty("sco_max_pkt", &value) == B_OK)
138 			str << " packets: " << value;
139 
140 		fBuffersProperties->SetText(str.String());
141 
142 
143 
144 	}
145 
146 
147 }
148 
149 
150 void
151 BluetoothDeviceView::SetTarget(BHandler *tgt)
152 {
153 
154 }
155 
156 
157 void
158 BluetoothDeviceView::MessageReceived(BMessage *msg)
159 {
160 	// If we received a dropped message, try to see if it has color data
161 	// in it
162 	if(msg->WasDropped()) {
163 
164 	}
165 
166 	// The default
167 	BView::MessageReceived(msg);
168 }
169 
170 
171 void
172 BluetoothDeviceView::SetEnabled(bool value)
173 {
174 
175 }
176