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