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 "ExtendedLocalDeviceView.h" 6 7 #include <bluetooth/bdaddrUtils.h> 8 9 #include "defs.h" 10 11 #include <Bitmap.h> 12 #include <CheckBox.h> 13 #include <GroupLayoutBuilder.h> 14 #include <SpaceLayoutItem.h> 15 #include <StringView.h> 16 17 18 ExtendedLocalDeviceView::ExtendedLocalDeviceView(BRect frame, LocalDevice* bDevice, uint32 resizingMode, uint32 flags) 19 : BView(frame,"ExtendedLocalDeviceView", resizingMode, flags | B_WILL_DRAW), 20 fDevice(bDevice), 21 fScanMode(0) 22 { 23 SetViewColor(B_TRANSPARENT_COLOR); 24 SetLowColor(0,0,0); 25 BRect iDontCare(0,0,0,0); 26 27 SetLayout(new BGroupLayout(B_HORIZONTAL)); 28 29 fDeviceView = new BluetoothDeviceView(BRect(0,0,5,5), bDevice); 30 31 fDiscoverable = new BCheckBox(iDontCare, "Discoverable","Discoverable", new BMessage(SET_DISCOVERABLE)); 32 fVisible = new BCheckBox(iDontCare, "Visible", "Show Name", new BMessage(SET_VISIBLE)); 33 34 fDiscoverable->SetEnabled(false); 35 fVisible->SetEnabled(false); 36 37 AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) 38 .Add(fDeviceView) 39 .Add(BGroupLayoutBuilder(B_HORIZONTAL) 40 .AddGlue() 41 .Add(fDiscoverable) 42 .Add(fVisible) 43 .SetInsets(5, 5, 5, 5) 44 ) 45 .Add(BSpaceLayoutItem::CreateVerticalStrut(0)) 46 .SetInsets(5, 5, 5, 5) 47 ); 48 49 } 50 51 52 ExtendedLocalDeviceView::~ExtendedLocalDeviceView(void) 53 { 54 55 } 56 57 58 void 59 ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice) 60 { 61 if (lDevice != NULL) { 62 fDevice = lDevice; 63 SetName(lDevice->GetFriendlyName().String()); 64 fDeviceView->SetBluetoothDevice(lDevice); 65 } 66 } 67 68 69 void 70 ExtendedLocalDeviceView::AttachedToWindow() 71 { 72 fDiscoverable->SetTarget(this); 73 fVisible->SetTarget(this); 74 } 75 76 77 void 78 ExtendedLocalDeviceView::SetTarget(BHandler *tgt) 79 { 80 81 } 82 83 84 void 85 ExtendedLocalDeviceView::MessageReceived(BMessage *msg) 86 { 87 if(msg->WasDropped()) { 88 89 } 90 91 switch(msg->what) 92 { 93 case SET_DISCOVERABLE: 94 case SET_VISIBLE: 95 fScanMode = 0; 96 97 if (fDiscoverable->Value()) { 98 fScanMode = 1; 99 fVisible->SetEnabled(true); 100 } else { 101 fVisible->SetValue(false); 102 fVisible->SetEnabled(false); 103 } 104 105 if (fVisible->Value()) 106 fScanMode |= 2; 107 if (fDevice != NULL) 108 fDevice->SetDiscoverable(fScanMode); 109 110 break; 111 112 default: 113 BView::MessageReceived(msg); 114 break; 115 } 116 } 117 118 119 void 120 ExtendedLocalDeviceView::SetEnabled(bool value) 121 { 122 fDiscoverable->SetEnabled(value); 123 } 124