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 <stdio.h> 6 7 #include <Alert.h> 8 #include <Catalog.h> 9 #include <Locale.h> 10 #include <Messenger.h> 11 12 #include <Directory.h> 13 #include <Entry.h> 14 #include <File.h> 15 #include <Path.h> 16 17 #include <GroupLayoutBuilder.h> 18 #include <SpaceLayoutItem.h> 19 20 #include <PincodeWindow.h> 21 #include <bluetooth/RemoteDevice.h> 22 23 #include "BluetoothWindow.h" 24 #include "defs.h" 25 #include "DeviceListItem.h" 26 #include "InquiryPanel.h" 27 #include "RemoteDevicesView.h" 28 29 #define TR_CONTEXT "Remote devices" 30 31 static const uint32 kMsgAddDevices = 'ddDv'; 32 static const uint32 kMsgRemoveDevice = 'rmDv'; 33 static const uint32 kMsgPairDevice = 'trDv'; 34 static const uint32 kMsgBlockDevice = 'blDv'; 35 static const uint32 kMsgRefreshDevices = 'rfDv'; 36 37 using namespace Bluetooth; 38 39 RemoteDevicesView::RemoteDevicesView(const char* name, uint32 flags) 40 : BView(name, flags) 41 { 42 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 43 44 addButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS), 45 new BMessage(kMsgAddDevices)); 46 47 removeButton = new BButton("remove", TR("Remove"), 48 new BMessage(kMsgRemoveDevice)); 49 50 pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS), 51 new BMessage(kMsgPairDevice)); 52 53 54 blockButton = new BButton("block", TR("As blocked"), 55 new BMessage(kMsgBlockDevice)); 56 57 58 availButton = new BButton("check", TR("Refresh" B_UTF8_ELLIPSIS), 59 new BMessage(kMsgRefreshDevices)); 60 61 // Set up device list 62 fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST); 63 64 fScrollView = new BScrollView("ScrollView", fDeviceList, 0, false, true); 65 fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 66 67 SetLayout(new BGroupLayout(B_VERTICAL)); 68 69 // TODO: use all the additional height 70 AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) 71 .Add(fScrollView) 72 //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) 73 .Add(BGroupLayoutBuilder(B_VERTICAL) 74 .Add(addButton) 75 .Add(removeButton) 76 .AddGlue() 77 .Add(availButton) 78 .AddGlue() 79 .Add(pairButton) 80 .Add(blockButton) 81 .AddGlue() 82 .SetInsets(0, 15, 0, 15) 83 ) 84 .SetInsets(5, 5, 5, 100) 85 ); 86 87 fDeviceList->SetSelectionMessage(NULL); 88 } 89 90 91 RemoteDevicesView::~RemoteDevicesView(void) 92 { 93 94 } 95 96 97 void 98 RemoteDevicesView::AttachedToWindow(void) 99 { 100 fDeviceList->SetTarget(this); 101 addButton->SetTarget(this); 102 removeButton->SetTarget(this); 103 pairButton->SetTarget(this); 104 blockButton->SetTarget(this); 105 availButton->SetTarget(this); 106 107 LoadSettings(); 108 fDeviceList->Select(0); 109 } 110 111 112 void 113 RemoteDevicesView::MessageReceived(BMessage* message) 114 { 115 switch (message->what) { 116 case kMsgAddDevices: 117 { 118 InquiryPanel* inquiryPanel = new InquiryPanel(BRect(100, 100, 450, 450), 119 ActiveLocalDevice); 120 inquiryPanel->Show(); 121 break; 122 } 123 124 case kMsgRemoveDevice: 125 printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0)); 126 fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0)); 127 break; 128 case kMsgAddToRemoteList: 129 { 130 BListItem* device; 131 message->FindPointer("device", (void**)&device); 132 fDeviceList->AddItem(device); 133 fDeviceList->Invalidate(); 134 break; 135 } 136 137 case kMsgPairDevice: 138 { 139 DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList 140 ->ItemAt(fDeviceList->CurrentSelection(0))); 141 RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device()); 142 143 if (remote != NULL) 144 remote->Authenticate(); 145 146 break; 147 } 148 149 default: 150 BView::MessageReceived(message); 151 break; 152 } 153 } 154 155 156 void RemoteDevicesView::LoadSettings(void) 157 { 158 159 } 160 161 162 bool RemoteDevicesView::IsDefaultable(void) 163 { 164 return true; 165 } 166 167