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> 9*b973d02fSOliver Ruiz Dorantes #include <Locale.h> 10*b973d02fSOliver Ruiz Dorantes #include <Messenger.h> 11*b973d02fSOliver Ruiz Dorantes 1296455f01SOliver Ruiz Dorantes #include <Directory.h> 1396455f01SOliver Ruiz Dorantes #include <Entry.h> 1496455f01SOliver Ruiz Dorantes #include <File.h> 1596455f01SOliver Ruiz Dorantes #include <Path.h> 16*b973d02fSOliver Ruiz Dorantes 17*b973d02fSOliver Ruiz Dorantes #include <GroupLayoutBuilder.h> 1896455f01SOliver Ruiz Dorantes #include <SpaceLayoutItem.h> 1996455f01SOliver Ruiz Dorantes 20*b973d02fSOliver Ruiz Dorantes #include <PincodeWindow.h> 2196455f01SOliver Ruiz Dorantes 22b36b65f9SOliver Ruiz Dorantes #include "defs.h" 233fcbf7dcSOliver Ruiz Dorantes #include "InquiryPanel.h" 2496455f01SOliver Ruiz Dorantes #include "BluetoothWindow.h" 25b36b65f9SOliver Ruiz Dorantes 26b36b65f9SOliver Ruiz Dorantes #include "RemoteDevicesView.h" 2796455f01SOliver Ruiz Dorantes 284cbc2061SAdrien Destugues #define TR_CONTEXT "Remote devices" 294cbc2061SAdrien Destugues 3096455f01SOliver Ruiz Dorantes static const uint32 kMsgAddDevices = 'ddDv'; 31623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRemoveDevice = 'rmDv'; 32*b973d02fSOliver Ruiz Dorantes static const uint32 kMsgPairDevice = 'trDv'; 33623f4e65SOliver Ruiz Dorantes static const uint32 kMsgBlockDevice = 'blDv'; 34623f4e65SOliver Ruiz Dorantes static const uint32 kMsgRefreshDevices = 'rfDv'; 3596455f01SOliver Ruiz Dorantes 3696455f01SOliver Ruiz Dorantes RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags) 3796455f01SOliver Ruiz Dorantes : BView(name, flags) 3896455f01SOliver Ruiz Dorantes { 3996455f01SOliver Ruiz Dorantes SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 4096455f01SOliver Ruiz Dorantes 41bef020d3SAdrien Destugues addButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS), 42623f4e65SOliver Ruiz Dorantes new BMessage(kMsgAddDevices)); 4396455f01SOliver Ruiz Dorantes 44bef020d3SAdrien Destugues removeButton = new BButton("remove", TR("Remove"), 45623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRemoveDevice)); 4696455f01SOliver Ruiz Dorantes 47*b973d02fSOliver Ruiz Dorantes pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS), 48*b973d02fSOliver Ruiz Dorantes new BMessage(kMsgPairDevice)); 4996455f01SOliver Ruiz Dorantes 5096455f01SOliver Ruiz Dorantes 51*b973d02fSOliver Ruiz Dorantes blockButton = new BButton("block", TR("As Blocked"), 52623f4e65SOliver Ruiz Dorantes new BMessage(kMsgBlockDevice)); 5396455f01SOliver Ruiz Dorantes 5496455f01SOliver Ruiz Dorantes 55bef020d3SAdrien Destugues availButton = new BButton("check", TR("Refresh" B_UTF8_ELLIPSIS), 56623f4e65SOliver Ruiz Dorantes new BMessage(kMsgRefreshDevices)); 5796455f01SOliver Ruiz Dorantes 58623f4e65SOliver Ruiz Dorantes // Set up device list 59623f4e65SOliver Ruiz Dorantes fDeviceList = new BListView("DeviceList", B_SINGLE_SELECTION_LIST); 6096455f01SOliver Ruiz Dorantes 61623f4e65SOliver Ruiz Dorantes fScrollView = new BScrollView("ScrollView", fDeviceList, 0, false, true); 6296455f01SOliver Ruiz Dorantes fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 6396455f01SOliver Ruiz Dorantes 6496455f01SOliver Ruiz Dorantes SetLayout(new BGroupLayout(B_VERTICAL)); 6596455f01SOliver Ruiz Dorantes 66cafd739dSOliver Ruiz Dorantes // TODO: use all the additional height 6796455f01SOliver Ruiz Dorantes AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) 6896455f01SOliver Ruiz Dorantes .Add(fScrollView) 6996455f01SOliver Ruiz Dorantes //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5)) 7096455f01SOliver Ruiz Dorantes .Add(BGroupLayoutBuilder(B_VERTICAL) 7196455f01SOliver Ruiz Dorantes .Add(addButton) 7296455f01SOliver Ruiz Dorantes .Add(removeButton) 7396455f01SOliver Ruiz Dorantes .AddGlue() 7496455f01SOliver Ruiz Dorantes .Add(availButton) 7596455f01SOliver Ruiz Dorantes .AddGlue() 76*b973d02fSOliver Ruiz Dorantes .Add(pairButton) 7796455f01SOliver Ruiz Dorantes .Add(blockButton) 7896455f01SOliver Ruiz Dorantes .AddGlue() 7996455f01SOliver Ruiz Dorantes .SetInsets(0, 15, 0, 15) 8096455f01SOliver Ruiz Dorantes ) 8196455f01SOliver Ruiz Dorantes .SetInsets(5, 5, 5, 100) 8296455f01SOliver Ruiz Dorantes ); 8396455f01SOliver Ruiz Dorantes 84623f4e65SOliver Ruiz Dorantes fDeviceList->SetSelectionMessage(NULL); 8596455f01SOliver Ruiz Dorantes } 8696455f01SOliver Ruiz Dorantes 8796455f01SOliver Ruiz Dorantes RemoteDevicesView::~RemoteDevicesView(void) 8896455f01SOliver Ruiz Dorantes { 8996455f01SOliver Ruiz Dorantes 9096455f01SOliver Ruiz Dorantes } 9196455f01SOliver Ruiz Dorantes 9296455f01SOliver Ruiz Dorantes void 9396455f01SOliver Ruiz Dorantes RemoteDevicesView::AttachedToWindow(void) 9496455f01SOliver Ruiz Dorantes { 95623f4e65SOliver Ruiz Dorantes fDeviceList->SetTarget(this); 963fcbf7dcSOliver Ruiz Dorantes addButton->SetTarget(this); 97623f4e65SOliver Ruiz Dorantes removeButton->SetTarget(this); 98*b973d02fSOliver Ruiz Dorantes pairButton->SetTarget(this); 99623f4e65SOliver Ruiz Dorantes blockButton->SetTarget(this); 100623f4e65SOliver Ruiz Dorantes availButton->SetTarget(this); 10196455f01SOliver Ruiz Dorantes 10296455f01SOliver Ruiz Dorantes LoadSettings(); 103623f4e65SOliver Ruiz Dorantes fDeviceList->Select(0); 10496455f01SOliver Ruiz Dorantes } 10596455f01SOliver Ruiz Dorantes 10696455f01SOliver Ruiz Dorantes void 10796455f01SOliver Ruiz Dorantes RemoteDevicesView::MessageReceived(BMessage *msg) 10896455f01SOliver Ruiz Dorantes { 109623f4e65SOliver Ruiz Dorantes printf("what = %ld\n", msg->what); 11096455f01SOliver Ruiz Dorantes switch(msg->what) { 1113fcbf7dcSOliver Ruiz Dorantes case kMsgAddDevices: 1123fcbf7dcSOliver Ruiz Dorantes { 113cafd739dSOliver Ruiz Dorantes InquiryPanel* iPanel = new InquiryPanel(BRect(100,100,450,450), ActiveLocalDevice); 1143fcbf7dcSOliver Ruiz Dorantes iPanel->Show(); 1153fcbf7dcSOliver Ruiz Dorantes break; 116*b973d02fSOliver Ruiz Dorantes } 117*b973d02fSOliver Ruiz Dorantes 118623f4e65SOliver Ruiz Dorantes case kMsgRemoveDevice: 119623f4e65SOliver Ruiz Dorantes printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0)); 120623f4e65SOliver Ruiz Dorantes fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0)); 121623f4e65SOliver Ruiz Dorantes break; 122623f4e65SOliver Ruiz Dorantes case kMsgAddToRemoteList: 123623f4e65SOliver Ruiz Dorantes { 124623f4e65SOliver Ruiz Dorantes BListItem* device; 125623f4e65SOliver Ruiz Dorantes msg->FindPointer("device", (void**)&device); 126623f4e65SOliver Ruiz Dorantes fDeviceList->AddItem(device); 127d254a0ebSOliver Ruiz Dorantes fDeviceList->Invalidate(); 128623f4e65SOliver Ruiz Dorantes break; 129*b973d02fSOliver Ruiz Dorantes } 130*b973d02fSOliver Ruiz Dorantes 131*b973d02fSOliver Ruiz Dorantes case kMsgPairDevice: 132*b973d02fSOliver Ruiz Dorantes { 133*b973d02fSOliver Ruiz Dorantes bdaddr_t address; 134*b973d02fSOliver Ruiz Dorantes address.b[5] = 0x55; 135*b973d02fSOliver Ruiz Dorantes address.b[4] = 0x44; 136*b973d02fSOliver Ruiz Dorantes address.b[3] = 0x33; 137*b973d02fSOliver Ruiz Dorantes address.b[2] = 0x22; 138*b973d02fSOliver Ruiz Dorantes address.b[1] = 0x11; 139*b973d02fSOliver Ruiz Dorantes address.b[0] = 0x00; 140*b973d02fSOliver Ruiz Dorantes 141*b973d02fSOliver Ruiz Dorantes PincodeWindow* iPincode = new PincodeWindow(address, 0); 142*b973d02fSOliver Ruiz Dorantes iPincode->Show(); 143*b973d02fSOliver Ruiz Dorantes break; 144*b973d02fSOliver Ruiz Dorantes } 145*b973d02fSOliver Ruiz Dorantes 14696455f01SOliver Ruiz Dorantes default: 14796455f01SOliver Ruiz Dorantes BView::MessageReceived(msg); 14896455f01SOliver Ruiz Dorantes break; 14996455f01SOliver Ruiz Dorantes } 15096455f01SOliver Ruiz Dorantes } 15196455f01SOliver Ruiz Dorantes 15296455f01SOliver Ruiz Dorantes void RemoteDevicesView::LoadSettings(void) 15396455f01SOliver Ruiz Dorantes { 15496455f01SOliver Ruiz Dorantes 15596455f01SOliver Ruiz Dorantes } 15696455f01SOliver Ruiz Dorantes 15796455f01SOliver Ruiz Dorantes bool RemoteDevicesView::IsDefaultable(void) 15896455f01SOliver Ruiz Dorantes { 15996455f01SOliver Ruiz Dorantes return true; 16096455f01SOliver Ruiz Dorantes } 16196455f01SOliver Ruiz Dorantes 162