fat: Greatly simplify and clean up dosfs_get_file_map().
[haiku.git] / src / preferences / bluetooth / BluetoothDeviceView.cpp
blobcb8203edee71a346d906be416eab08f20d545f58
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>
8 #include <bluetooth/LocalDevice.h>
9 #include <bluetooth/HCI/btHCI_command.h>
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>
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),
28 fDevice(bDevice)
30 SetViewColor(B_TRANSPARENT_COLOR);
31 SetLowColor(0, 0, 0);
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,
46 B_ALIGN_MIDDLE));
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,
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));
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));
72 SetBluetoothDevice(bDevice);
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)
98 // .Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
99 .SetInsets(10, 10, 10, 10)
105 BluetoothDeviceView::~BluetoothDeviceView(void)
111 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());
125 string = "";
126 bDevice->GetDeviceClass().GetMajorDeviceClass(string);
127 string << " / ";
128 bDevice->GetDeviceClass().GetMinorDeviceClass(string);
129 fClass->SetText(string.String());
131 bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top));
133 uint32 value;
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 ;
141 fHCIVersionProperties->SetText(string.String());
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());
150 string = "";
151 if (bDevice->GetProperty("manufacturer", &value) == B_OK)
152 string << B_TRANSLATE("Manufacturer: ")
153 << BluetoothManufacturer(value);
154 fManufacturerProperties->SetText(string.String());
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());
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());
175 void
176 BluetoothDeviceView::SetTarget(BHandler* target)
182 void
183 BluetoothDeviceView::MessageReceived(BMessage* message)
185 // If we received a dropped message, try to see if it has color data
186 // in it
187 if (message->WasDropped()) {
191 // The default
192 BView::MessageReceived(message);
196 void
197 BluetoothDeviceView::SetEnabled(bool value)