196455f01SOliver Ruiz Dorantes /* 296455f01SOliver Ruiz Dorantes * Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com> 396455f01SOliver Ruiz Dorantes * All rights reserved. Distributed under the terms of the MIT License. 496455f01SOliver Ruiz Dorantes */ 5b36b65f9SOliver Ruiz Dorantes #include <stdio.h> 696455f01SOliver Ruiz Dorantes 796455f01SOliver Ruiz Dorantes #include <Alert.h> 896455f01SOliver Ruiz Dorantes #include <Directory.h> 996455f01SOliver Ruiz Dorantes #include <Entry.h> 1096455f01SOliver Ruiz Dorantes #include <File.h> 1196455f01SOliver Ruiz Dorantes #include <GroupLayoutBuilder.h> 1296455f01SOliver Ruiz Dorantes #include <Messenger.h> 1396455f01SOliver Ruiz Dorantes #include <Path.h> 1496455f01SOliver Ruiz Dorantes #include <SpaceLayoutItem.h> 1596455f01SOliver Ruiz Dorantes 1696455f01SOliver Ruiz Dorantes 17b36b65f9SOliver Ruiz Dorantes #include "defs.h" 183fcbf7dcSOliver Ruiz Dorantes #include "InquiryPanel.h" 1996455f01SOliver Ruiz Dorantes #include "BluetoothWindow.h" 20b36b65f9SOliver Ruiz Dorantes 21b36b65f9SOliver Ruiz Dorantes #include "RemoteDevicesView.h" 2296455f01SOliver Ruiz Dorantes 2396455f01SOliver Ruiz Dorantes static const uint32 kMsgAddDevices = 'ddDv'; 24623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRemoveDevice = 'rmDv'; 25623f4e65SOliver Ruiz Dorantes static const uint32 kMsgTrustDevice = 'trDv'; 26623f4e65SOliver Ruiz Dorantes static const uint32 kMsgBlockDevice = 'blDv'; 27623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRefreshDevices = 'rfDv'; 2896455f01SOliver Ruiz Dorantes 2996455f01SOliver Ruiz Dorantes RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags) 3096455f01SOliver Ruiz Dorantes : BView(name, flags) 3196455f01SOliver Ruiz Dorantes { 3296455f01SOliver Ruiz Dorantes SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 3396455f01SOliver Ruiz Dorantes 34623f4e65SOliver Ruiz Dorantes addButton = new BButton("add", "Add" B_UTF8_ELLIPSIS, 35623f4e65SOliver Ruiz Dorantes new BMessage(kMsgAddDevices)); 3696455f01SOliver Ruiz Dorantes 37623f4e65SOliver Ruiz Dorantes removeButton = new BButton("remove", "Remove", 38623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRemoveDevice)); 3996455f01SOliver Ruiz Dorantes 40623f4e65SOliver Ruiz Dorantes trustButton = new BButton("trust", "As Trusted", 41623f4e65SOliver Ruiz Dorantes new BMessage(kMsgTrustDevice)); 4296455f01SOliver Ruiz Dorantes 4396455f01SOliver Ruiz Dorantes 44623f4e65SOliver Ruiz Dorantes blockButton = new BButton("trust", "As Blocked", 45623f4e65SOliver Ruiz Dorantes new BMessage(kMsgBlockDevice)); 4696455f01SOliver Ruiz Dorantes 4796455f01SOliver Ruiz Dorantes 48623f4e65SOliver Ruiz Dorantes availButton = new BButton("check", "Refresh" B_UTF8_ELLIPSIS, 49623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRefreshDevices)); 5096455f01SOliver Ruiz Dorantes 5196455f01SOliver Ruiz Dorantes 5296455f01SOliver Ruiz Dorantes 53623f4e65SOliver Ruiz Dorantes // Set up device list 54623f4e65SOliver Ruiz Dorantes fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST); 5596455f01SOliver Ruiz Dorantes 56623f4e65SOliver Ruiz Dorantes fScrollView = new BScrollView("ScrollView", fDeviceList, 0, false, true); 5796455f01SOliver Ruiz Dorantes fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 5896455f01SOliver Ruiz Dorantes 5996455f01SOliver Ruiz Dorantes SetLayout(new BGroupLayout(B_VERTICAL)); 6096455f01SOliver Ruiz Dorantes 61*cafd739dSOliver Ruiz Dorantes // TODO: use all the additional height 6296455f01SOliver Ruiz Dorantes AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) 6396455f01SOliver Ruiz Dorantes .Add(fScrollView) 6496455f01SOliver Ruiz Dorantes //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) 6596455f01SOliver Ruiz Dorantes .Add(BGroupLayoutBuilder(B_VERTICAL) 6696455f01SOliver Ruiz Dorantes .Add(addButton) 6796455f01SOliver Ruiz Dorantes .Add(removeButton) 6896455f01SOliver Ruiz Dorantes .AddGlue() 6996455f01SOliver Ruiz Dorantes .Add(availButton) 7096455f01SOliver Ruiz Dorantes .AddGlue() 7196455f01SOliver Ruiz Dorantes .Add(trustButton) 7296455f01SOliver Ruiz Dorantes .Add(blockButton) 7396455f01SOliver Ruiz Dorantes .AddGlue() 7496455f01SOliver Ruiz Dorantes .SetInsets(0, 15, 0, 15) 7596455f01SOliver Ruiz Dorantes ) 7696455f01SOliver Ruiz Dorantes .SetInsets(5, 5, 5, 100) 7796455f01SOliver Ruiz Dorantes ); 7896455f01SOliver Ruiz Dorantes 79623f4e65SOliver Ruiz Dorantes fDeviceList->SetSelectionMessage(NULL); 8096455f01SOliver Ruiz Dorantes } 8196455f01SOliver Ruiz Dorantes 8296455f01SOliver Ruiz Dorantes RemoteDevicesView::~RemoteDevicesView(void) 8396455f01SOliver Ruiz Dorantes { 8496455f01SOliver Ruiz Dorantes 8596455f01SOliver Ruiz Dorantes } 8696455f01SOliver Ruiz Dorantes 8796455f01SOliver Ruiz Dorantes void 8896455f01SOliver Ruiz Dorantes RemoteDevicesView::AttachedToWindow(void) 8996455f01SOliver Ruiz Dorantes { 90623f4e65SOliver Ruiz Dorantes fDeviceList->SetTarget(this); 913fcbf7dcSOliver Ruiz Dorantes addButton->SetTarget(this); 92623f4e65SOliver Ruiz Dorantes removeButton->SetTarget(this); 93623f4e65SOliver Ruiz Dorantes trustButton->SetTarget(this); 94623f4e65SOliver Ruiz Dorantes blockButton->SetTarget(this); 95623f4e65SOliver Ruiz Dorantes availButton->SetTarget(this); 9696455f01SOliver Ruiz Dorantes 9796455f01SOliver Ruiz Dorantes LoadSettings(); 98623f4e65SOliver Ruiz Dorantes fDeviceList->Select(0); 9996455f01SOliver Ruiz Dorantes } 10096455f01SOliver Ruiz Dorantes 10196455f01SOliver Ruiz Dorantes void 10296455f01SOliver Ruiz Dorantes RemoteDevicesView::MessageReceived(BMessage *msg) 10396455f01SOliver Ruiz Dorantes { 104623f4e65SOliver Ruiz Dorantes printf("what = %ld\n", msg->what); 10596455f01SOliver Ruiz Dorantes switch(msg->what) { 1063fcbf7dcSOliver Ruiz Dorantes case kMsgAddDevices: 1073fcbf7dcSOliver Ruiz Dorantes { 108*cafd739dSOliver Ruiz Dorantes InquiryPanel* iPanel = new InquiryPanel(BRect(100,100,450,450), ActiveLocalDevice); 1093fcbf7dcSOliver Ruiz Dorantes iPanel->Show(); 1103fcbf7dcSOliver Ruiz Dorantes } 1113fcbf7dcSOliver Ruiz Dorantes break; 112623f4e65SOliver Ruiz Dorantes case kMsgRemoveDevice: 113623f4e65SOliver Ruiz Dorantes printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0)); 114623f4e65SOliver Ruiz Dorantes fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0)); 115623f4e65SOliver Ruiz Dorantes break; 116623f4e65SOliver Ruiz Dorantes case kMsgAddToRemoteList: 117623f4e65SOliver Ruiz Dorantes { 118623f4e65SOliver Ruiz Dorantes BListItem* device; 119623f4e65SOliver Ruiz Dorantes msg->FindPointer("device", (void**)&device); 120623f4e65SOliver Ruiz Dorantes fDeviceList->AddItem(device); 121623f4e65SOliver Ruiz Dorantes } 122623f4e65SOliver Ruiz Dorantes break; 12396455f01SOliver Ruiz Dorantes default: 12496455f01SOliver Ruiz Dorantes BView::MessageReceived(msg); 12596455f01SOliver Ruiz Dorantes break; 12696455f01SOliver Ruiz Dorantes } 12796455f01SOliver Ruiz Dorantes } 12896455f01SOliver Ruiz Dorantes 12996455f01SOliver Ruiz Dorantes void RemoteDevicesView::LoadSettings(void) 13096455f01SOliver Ruiz Dorantes { 13196455f01SOliver Ruiz Dorantes 13296455f01SOliver Ruiz Dorantes } 13396455f01SOliver Ruiz Dorantes 13496455f01SOliver Ruiz Dorantes bool RemoteDevicesView::IsDefaultable(void) 13596455f01SOliver Ruiz Dorantes { 13696455f01SOliver Ruiz Dorantes return true; 13796455f01SOliver Ruiz Dorantes } 13896455f01SOliver Ruiz Dorantes 139