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> 8bef020d3SAdrien Destugues #include <Catalog.h> 996455f01SOliver Ruiz Dorantes #include <Directory.h> 1096455f01SOliver Ruiz Dorantes #include <Entry.h> 1196455f01SOliver Ruiz Dorantes #include <File.h> 1296455f01SOliver Ruiz Dorantes #include <GroupLayoutBuilder.h> 13bef020d3SAdrien Destugues #include <Locale.h> 1496455f01SOliver Ruiz Dorantes #include <Messenger.h> 1596455f01SOliver Ruiz Dorantes #include <Path.h> 1696455f01SOliver Ruiz Dorantes #include <SpaceLayoutItem.h> 1796455f01SOliver Ruiz Dorantes 1896455f01SOliver Ruiz Dorantes 19b36b65f9SOliver Ruiz Dorantes #include "defs.h" 203fcbf7dcSOliver Ruiz Dorantes #include "InquiryPanel.h" 2196455f01SOliver Ruiz Dorantes #include "BluetoothWindow.h" 22b36b65f9SOliver Ruiz Dorantes 23b36b65f9SOliver Ruiz Dorantes #include "RemoteDevicesView.h" 2496455f01SOliver Ruiz Dorantes 25*4cbc2061SAdrien Destugues #define TR_CONTEXT "Remote devices" 26*4cbc2061SAdrien Destugues 2796455f01SOliver Ruiz Dorantes static const uint32 kMsgAddDevices = 'ddDv'; 28623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRemoveDevice = 'rmDv'; 29623f4e65SOliver Ruiz Dorantes static const uint32 kMsgTrustDevice = 'trDv'; 30623f4e65SOliver Ruiz Dorantes static const uint32 kMsgBlockDevice = 'blDv'; 31623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRefreshDevices = 'rfDv'; 3296455f01SOliver Ruiz Dorantes 3396455f01SOliver Ruiz Dorantes RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags) 3496455f01SOliver Ruiz Dorantes : BView(name, flags) 3596455f01SOliver Ruiz Dorantes { 3696455f01SOliver Ruiz Dorantes SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 3796455f01SOliver Ruiz Dorantes 38bef020d3SAdrien Destugues addButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS), 39623f4e65SOliver Ruiz Dorantes new BMessage(kMsgAddDevices)); 4096455f01SOliver Ruiz Dorantes 41bef020d3SAdrien Destugues removeButton = new BButton("remove", TR("Remove"), 42623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRemoveDevice)); 4396455f01SOliver Ruiz Dorantes 44bef020d3SAdrien Destugues trustButton = new BButton("trust", TR("As Trusted"), 45623f4e65SOliver Ruiz Dorantes new BMessage(kMsgTrustDevice)); 4696455f01SOliver Ruiz Dorantes 4796455f01SOliver Ruiz Dorantes 48bef020d3SAdrien Destugues blockButton = new BButton("trust", TR("As Blocked"), 49623f4e65SOliver Ruiz Dorantes new BMessage(kMsgBlockDevice)); 5096455f01SOliver Ruiz Dorantes 5196455f01SOliver Ruiz Dorantes 52bef020d3SAdrien Destugues availButton = new BButton("check", TR("Refresh" B_UTF8_ELLIPSIS), 53623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRefreshDevices)); 5496455f01SOliver Ruiz Dorantes 5596455f01SOliver Ruiz Dorantes 5696455f01SOliver Ruiz Dorantes 57623f4e65SOliver Ruiz Dorantes // Set up device list 58623f4e65SOliver Ruiz Dorantes fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST); 5996455f01SOliver Ruiz Dorantes 60623f4e65SOliver Ruiz Dorantes fScrollView = new BScrollView("ScrollView", fDeviceList, 0, false, true); 6196455f01SOliver Ruiz Dorantes fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 6296455f01SOliver Ruiz Dorantes 6396455f01SOliver Ruiz Dorantes SetLayout(new BGroupLayout(B_VERTICAL)); 6496455f01SOliver Ruiz Dorantes 65cafd739dSOliver Ruiz Dorantes // TODO: use all the additional height 6696455f01SOliver Ruiz Dorantes AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) 6796455f01SOliver Ruiz Dorantes .Add(fScrollView) 6896455f01SOliver Ruiz Dorantes //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) 6996455f01SOliver Ruiz Dorantes .Add(BGroupLayoutBuilder(B_VERTICAL) 7096455f01SOliver Ruiz Dorantes .Add(addButton) 7196455f01SOliver Ruiz Dorantes .Add(removeButton) 7296455f01SOliver Ruiz Dorantes .AddGlue() 7396455f01SOliver Ruiz Dorantes .Add(availButton) 7496455f01SOliver Ruiz Dorantes .AddGlue() 7596455f01SOliver Ruiz Dorantes .Add(trustButton) 7696455f01SOliver Ruiz Dorantes .Add(blockButton) 7796455f01SOliver Ruiz Dorantes .AddGlue() 7896455f01SOliver Ruiz Dorantes .SetInsets(0, 15, 0, 15) 7996455f01SOliver Ruiz Dorantes ) 8096455f01SOliver Ruiz Dorantes .SetInsets(5, 5, 5, 100) 8196455f01SOliver Ruiz Dorantes ); 8296455f01SOliver Ruiz Dorantes 83623f4e65SOliver Ruiz Dorantes fDeviceList->SetSelectionMessage(NULL); 8496455f01SOliver Ruiz Dorantes } 8596455f01SOliver Ruiz Dorantes 8696455f01SOliver Ruiz Dorantes RemoteDevicesView::~RemoteDevicesView(void) 8796455f01SOliver Ruiz Dorantes { 8896455f01SOliver Ruiz Dorantes 8996455f01SOliver Ruiz Dorantes } 9096455f01SOliver Ruiz Dorantes 9196455f01SOliver Ruiz Dorantes void 9296455f01SOliver Ruiz Dorantes RemoteDevicesView::AttachedToWindow(void) 9396455f01SOliver Ruiz Dorantes { 94623f4e65SOliver Ruiz Dorantes fDeviceList->SetTarget(this); 953fcbf7dcSOliver Ruiz Dorantes addButton->SetTarget(this); 96623f4e65SOliver Ruiz Dorantes removeButton->SetTarget(this); 97623f4e65SOliver Ruiz Dorantes trustButton->SetTarget(this); 98623f4e65SOliver Ruiz Dorantes blockButton->SetTarget(this); 99623f4e65SOliver Ruiz Dorantes availButton->SetTarget(this); 10096455f01SOliver Ruiz Dorantes 10196455f01SOliver Ruiz Dorantes LoadSettings(); 102623f4e65SOliver Ruiz Dorantes fDeviceList->Select(0); 10396455f01SOliver Ruiz Dorantes } 10496455f01SOliver Ruiz Dorantes 10596455f01SOliver Ruiz Dorantes void 10696455f01SOliver Ruiz Dorantes RemoteDevicesView::MessageReceived(BMessage *msg) 10796455f01SOliver Ruiz Dorantes { 108623f4e65SOliver Ruiz Dorantes printf("what = %ld\n", msg->what); 10996455f01SOliver Ruiz Dorantes switch(msg->what) { 1103fcbf7dcSOliver Ruiz Dorantes case kMsgAddDevices: 1113fcbf7dcSOliver Ruiz Dorantes { 112cafd739dSOliver Ruiz Dorantes InquiryPanel* iPanel = new InquiryPanel(BRect(100,100,450,450), ActiveLocalDevice); 1133fcbf7dcSOliver Ruiz Dorantes iPanel->Show(); 1143fcbf7dcSOliver Ruiz Dorantes } 1153fcbf7dcSOliver Ruiz Dorantes break; 116623f4e65SOliver Ruiz Dorantes case kMsgRemoveDevice: 117623f4e65SOliver Ruiz Dorantes printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0)); 118623f4e65SOliver Ruiz Dorantes fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0)); 119623f4e65SOliver Ruiz Dorantes break; 120623f4e65SOliver Ruiz Dorantes case kMsgAddToRemoteList: 121623f4e65SOliver Ruiz Dorantes { 122623f4e65SOliver Ruiz Dorantes BListItem* device; 123623f4e65SOliver Ruiz Dorantes msg->FindPointer("device", (void**)&device); 124623f4e65SOliver Ruiz Dorantes fDeviceList->AddItem(device); 125d254a0ebSOliver Ruiz Dorantes fDeviceList->Invalidate(); 126623f4e65SOliver Ruiz Dorantes } 127623f4e65SOliver Ruiz Dorantes break; 12896455f01SOliver Ruiz Dorantes default: 12996455f01SOliver Ruiz Dorantes BView::MessageReceived(msg); 13096455f01SOliver Ruiz Dorantes break; 13196455f01SOliver Ruiz Dorantes } 13296455f01SOliver Ruiz Dorantes } 13396455f01SOliver Ruiz Dorantes 13496455f01SOliver Ruiz Dorantes void RemoteDevicesView::LoadSettings(void) 13596455f01SOliver Ruiz Dorantes { 13696455f01SOliver Ruiz Dorantes 13796455f01SOliver Ruiz Dorantes } 13896455f01SOliver Ruiz Dorantes 13996455f01SOliver Ruiz Dorantes bool RemoteDevicesView::IsDefaultable(void) 14096455f01SOliver Ruiz Dorantes { 14196455f01SOliver Ruiz Dorantes return true; 14296455f01SOliver Ruiz Dorantes } 14396455f01SOliver Ruiz Dorantes 144