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