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