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