libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / preferences / bluetooth / BluetoothDeviceView.cpp
blob4bddea8e95e52f61c48e1e9551984049ef3c1397
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 <LayoutBuilder.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(BluetoothDevice* bDevice, uint32 flags)
26 BView("BluetoothDeviceView", flags | B_WILL_DRAW),
27 fDevice(bDevice)
29 fName = new BStringView("name", "");
30 fName->SetFont(be_bold_font);
31 fName->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
33 fBdaddr = new BStringView("bdaddr",
34 bdaddrUtils::ToString(bdaddrUtils::NullAddress()));
35 fBdaddr->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
37 fClassService = new BStringView("ServiceClass",
38 B_TRANSLATE("Service classes: "));
39 fClassService->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
40 B_ALIGN_MIDDLE));
42 fClass = new BStringView("class", "- / -");
43 fClass->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
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));
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);
65 SetBluetoothDevice(bDevice);
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();
88 BluetoothDeviceView::~BluetoothDeviceView()
93 void
94 BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
96 if (bDevice != NULL) {
97 SetName(bDevice->GetFriendlyName().String());
99 fName->SetText(bDevice->GetFriendlyName().String());
100 fBdaddr->SetText(bdaddrUtils::ToString(bDevice->GetBluetoothAddress()));
102 BString string(B_TRANSLATE("Service classes: "));
103 bDevice->GetDeviceClass().GetServiceClass(string);
104 fClassService->SetText(string.String());
106 string = "";
107 bDevice->GetDeviceClass().GetMajorDeviceClass(string);
108 string << " / ";
109 bDevice->GetDeviceClass().GetMinorDeviceClass(string);
110 fClass->SetText(string.String());
112 bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top));
114 uint32 value;
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 ;
122 fHCIVersionProperties->SetText(string.String());
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());
131 string = "";
132 if (bDevice->GetProperty("manufacturer", &value) == B_OK)
133 string << B_TRANSLATE("Manufacturer: ")
134 << BluetoothManufacturer(value);
135 fManufacturerProperties->SetText(string.String());
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());
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());
154 void
155 BluetoothDeviceView::SetTarget(BHandler* target)
160 void
161 BluetoothDeviceView::MessageReceived(BMessage* message)
163 // If we received a dropped message, try to see if it has color data
164 // in it
165 if (message->WasDropped()) {
169 // The default
170 BView::MessageReceived(message);
174 void
175 BluetoothDeviceView::SetEnabled(bool value)