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> 8*bef020d3SAdrien 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> 13*bef020d3SAdrien 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 2596455f01SOliver Ruiz Dorantes static const uint32 kMsgAddDevices = 'ddDv'; 26623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRemoveDevice = 'rmDv'; 27623f4e65SOliver Ruiz Dorantes static const uint32 kMsgTrustDevice = 'trDv'; 28623f4e65SOliver Ruiz Dorantes static const uint32 kMsgBlockDevice = 'blDv'; 29623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRefreshDevices = 'rfDv'; 3096455f01SOliver Ruiz Dorantes 3196455f01SOliver Ruiz Dorantes RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags) 3296455f01SOliver Ruiz Dorantes : BView(name, flags) 3396455f01SOliver Ruiz Dorantes { 3496455f01SOliver Ruiz Dorantes SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 3596455f01SOliver Ruiz Dorantes 36*bef020d3SAdrien Destugues addButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS), 37623f4e65SOliver Ruiz Dorantes new BMessage(kMsgAddDevices)); 3896455f01SOliver Ruiz Dorantes 39*bef020d3SAdrien Destugues removeButton = new BButton("remove", TR("Remove"), 40623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRemoveDevice)); 4196455f01SOliver Ruiz Dorantes 42*bef020d3SAdrien Destugues trustButton = new BButton("trust", TR("As Trusted"), 43623f4e65SOliver Ruiz Dorantes new BMessage(kMsgTrustDevice)); 4496455f01SOliver Ruiz Dorantes 4596455f01SOliver Ruiz Dorantes 46*bef020d3SAdrien Destugues blockButton = new BButton("trust", TR("As Blocked"), 47623f4e65SOliver Ruiz Dorantes new BMessage(kMsgBlockDevice)); 4896455f01SOliver Ruiz Dorantes 4996455f01SOliver Ruiz Dorantes 50*bef020d3SAdrien Destugues availButton = new BButton("check", TR("Refresh" B_UTF8_ELLIPSIS), 51623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRefreshDevices)); 5296455f01SOliver Ruiz Dorantes 5396455f01SOliver Ruiz Dorantes 5496455f01SOliver Ruiz Dorantes 55623f4e65SOliver Ruiz Dorantes // Set up device list 56623f4e65SOliver Ruiz Dorantes fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST); 5796455f01SOliver Ruiz Dorantes 58623f4e65SOliver Ruiz Dorantes fScrollView = new BScrollView("ScrollView", fDeviceList, 0, false, true); 5996455f01SOliver Ruiz Dorantes fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 6096455f01SOliver Ruiz Dorantes 6196455f01SOliver Ruiz Dorantes SetLayout(new BGroupLayout(B_VERTICAL)); 6296455f01SOliver Ruiz Dorantes 63cafd739dSOliver Ruiz Dorantes // TODO: use all the additional height 6496455f01SOliver Ruiz Dorantes AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) 6596455f01SOliver Ruiz Dorantes .Add(fScrollView) 6696455f01SOliver Ruiz Dorantes //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) 6796455f01SOliver Ruiz Dorantes .Add(BGroupLayoutBuilder(B_VERTICAL) 6896455f01SOliver Ruiz Dorantes .Add(addButton) 6996455f01SOliver Ruiz Dorantes .Add(removeButton) 7096455f01SOliver Ruiz Dorantes .AddGlue() 7196455f01SOliver Ruiz Dorantes .Add(availButton) 7296455f01SOliver Ruiz Dorantes .AddGlue() 7396455f01SOliver Ruiz Dorantes .Add(trustButton) 7496455f01SOliver Ruiz Dorantes .Add(blockButton) 7596455f01SOliver Ruiz Dorantes .AddGlue() 7696455f01SOliver Ruiz Dorantes .SetInsets(0, 15, 0, 15) 7796455f01SOliver Ruiz Dorantes ) 7896455f01SOliver Ruiz Dorantes .SetInsets(5, 5, 5, 100) 7996455f01SOliver Ruiz Dorantes ); 8096455f01SOliver Ruiz Dorantes 81623f4e65SOliver Ruiz Dorantes fDeviceList->SetSelectionMessage(NULL); 8296455f01SOliver Ruiz Dorantes } 8396455f01SOliver Ruiz Dorantes 8496455f01SOliver Ruiz Dorantes RemoteDevicesView::~RemoteDevicesView(void) 8596455f01SOliver Ruiz Dorantes { 8696455f01SOliver Ruiz Dorantes 8796455f01SOliver Ruiz Dorantes } 8896455f01SOliver Ruiz Dorantes 8996455f01SOliver Ruiz Dorantes void 9096455f01SOliver Ruiz Dorantes RemoteDevicesView::AttachedToWindow(void) 9196455f01SOliver Ruiz Dorantes { 92623f4e65SOliver Ruiz Dorantes fDeviceList->SetTarget(this); 933fcbf7dcSOliver Ruiz Dorantes addButton->SetTarget(this); 94623f4e65SOliver Ruiz Dorantes removeButton->SetTarget(this); 95623f4e65SOliver Ruiz Dorantes trustButton->SetTarget(this); 96623f4e65SOliver Ruiz Dorantes blockButton->SetTarget(this); 97623f4e65SOliver Ruiz Dorantes availButton->SetTarget(this); 9896455f01SOliver Ruiz Dorantes 9996455f01SOliver Ruiz Dorantes LoadSettings(); 100623f4e65SOliver Ruiz Dorantes fDeviceList->Select(0); 10196455f01SOliver Ruiz Dorantes } 10296455f01SOliver Ruiz Dorantes 10396455f01SOliver Ruiz Dorantes void 10496455f01SOliver Ruiz Dorantes RemoteDevicesView::MessageReceived(BMessage *msg) 10596455f01SOliver Ruiz Dorantes { 106623f4e65SOliver Ruiz Dorantes printf("what = %ld\n", msg->what); 10796455f01SOliver Ruiz Dorantes switch(msg->what) { 1083fcbf7dcSOliver Ruiz Dorantes case kMsgAddDevices: 1093fcbf7dcSOliver Ruiz Dorantes { 110cafd739dSOliver Ruiz Dorantes InquiryPanel* iPanel = new InquiryPanel(BRect(100,100,450,450), ActiveLocalDevice); 1113fcbf7dcSOliver Ruiz Dorantes iPanel->Show(); 1123fcbf7dcSOliver Ruiz Dorantes } 1133fcbf7dcSOliver Ruiz Dorantes break; 114623f4e65SOliver Ruiz Dorantes case kMsgRemoveDevice: 115623f4e65SOliver Ruiz Dorantes printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0)); 116623f4e65SOliver Ruiz Dorantes fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0)); 117623f4e65SOliver Ruiz Dorantes break; 118623f4e65SOliver Ruiz Dorantes case kMsgAddToRemoteList: 119623f4e65SOliver Ruiz Dorantes { 120623f4e65SOliver Ruiz Dorantes BListItem* device; 121623f4e65SOliver Ruiz Dorantes msg->FindPointer("device", (void**)&device); 122623f4e65SOliver Ruiz Dorantes fDeviceList->AddItem(device); 123d254a0ebSOliver Ruiz Dorantes fDeviceList->Invalidate(); 124623f4e65SOliver Ruiz Dorantes } 125623f4e65SOliver Ruiz Dorantes break; 12696455f01SOliver Ruiz Dorantes default: 12796455f01SOliver Ruiz Dorantes BView::MessageReceived(msg); 12896455f01SOliver Ruiz Dorantes break; 12996455f01SOliver Ruiz Dorantes } 13096455f01SOliver Ruiz Dorantes } 13196455f01SOliver Ruiz Dorantes 13296455f01SOliver Ruiz Dorantes void RemoteDevicesView::LoadSettings(void) 13396455f01SOliver Ruiz Dorantes { 13496455f01SOliver Ruiz Dorantes 13596455f01SOliver Ruiz Dorantes } 13696455f01SOliver Ruiz Dorantes 13796455f01SOliver Ruiz Dorantes bool RemoteDevicesView::IsDefaultable(void) 13896455f01SOliver Ruiz Dorantes { 13996455f01SOliver Ruiz Dorantes return true; 14096455f01SOliver Ruiz Dorantes } 14196455f01SOliver Ruiz Dorantes 142