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.
11 #include <Directory.h>
16 #include <LayoutBuilder.h>
17 #include <SpaceLayoutItem.h>
19 #include <PincodeWindow.h>
20 #include <bluetooth/RemoteDevice.h>
22 #include "BluetoothWindow.h"
24 #include "DeviceListItem.h"
25 #include "InquiryPanel.h"
26 #include "RemoteDevicesView.h"
29 #undef B_TRANSLATION_CONTEXT
30 #define B_TRANSLATION_CONTEXT "Remote devices"
32 static const uint32 kMsgAddDevices
= 'ddDv';
33 static const uint32 kMsgRemoveDevice
= 'rmDv';
34 static const uint32 kMsgPairDevice
= 'trDv';
35 static const uint32 kMsgDisconnectDevice
= 'dsDv';
36 static const uint32 kMsgBlockDevice
= 'blDv';
37 static const uint32 kMsgRefreshDevices
= 'rfDv';
39 using namespace Bluetooth
;
41 RemoteDevicesView::RemoteDevicesView(const char* name
, uint32 flags
)
44 addButton
= new BButton("add", B_TRANSLATE("Add" B_UTF8_ELLIPSIS
),
45 new BMessage(kMsgAddDevices
));
47 removeButton
= new BButton("remove", B_TRANSLATE("Remove"),
48 new BMessage(kMsgRemoveDevice
));
50 pairButton
= new BButton("pair", B_TRANSLATE("Pair" B_UTF8_ELLIPSIS
),
51 new BMessage(kMsgPairDevice
));
53 disconnectButton
= new BButton("disconnect", B_TRANSLATE("Disconnect"),
54 new BMessage(kMsgDisconnectDevice
));
56 blockButton
= new BButton("block", B_TRANSLATE("As blocked"),
57 new BMessage(kMsgBlockDevice
));
60 availButton
= new BButton("check", B_TRANSLATE("Refresh" B_UTF8_ELLIPSIS
),
61 new BMessage(kMsgRefreshDevices
));
64 fDeviceList
= new BListView("DeviceList", B_SINGLE_SELECTION_LIST
);
66 fScrollView
= new BScrollView("ScrollView", fDeviceList
, 0, false, true);
68 BLayoutBuilder::Group
<>(this, B_HORIZONTAL
, 10)
71 //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
73 .SetInsets(0, 15, 0, 15)
80 .Add(disconnectButton
)
86 fDeviceList
->SetSelectionMessage(NULL
);
90 RemoteDevicesView::~RemoteDevicesView(void)
97 RemoteDevicesView::AttachedToWindow(void)
99 fDeviceList
->SetTarget(this);
100 addButton
->SetTarget(this);
101 removeButton
->SetTarget(this);
102 pairButton
->SetTarget(this);
103 disconnectButton
->SetTarget(this);
104 blockButton
->SetTarget(this);
105 availButton
->SetTarget(this);
108 fDeviceList
->Select(0);
113 RemoteDevicesView::MessageReceived(BMessage
* message
)
115 switch (message
->what
) {
118 InquiryPanel
* inquiryPanel
= new InquiryPanel(
119 BRect(100, 100, 450, 450), ActiveLocalDevice
);
120 inquiryPanel
->Show();
124 case kMsgRemoveDevice
:
125 printf("kMsgRemoveDevice: %" B_PRId32
"\n",
126 fDeviceList
->CurrentSelection(0));
127 fDeviceList
->RemoveItem(fDeviceList
->CurrentSelection(0));
129 case kMsgAddToRemoteList
:
132 message
->FindPointer("device", (void**)&device
);
133 fDeviceList
->AddItem(device
);
134 fDeviceList
->Invalidate();
140 DeviceListItem
* device
= static_cast<DeviceListItem
*>(fDeviceList
141 ->ItemAt(fDeviceList
->CurrentSelection(0)));
145 RemoteDevice
* remote
= dynamic_cast<RemoteDevice
*>(device
->Device());
149 remote
->Authenticate();
153 case kMsgDisconnectDevice
:
155 DeviceListItem
* device
= static_cast<DeviceListItem
*>(fDeviceList
156 ->ItemAt(fDeviceList
->CurrentSelection(0)));
160 RemoteDevice
* remote
= dynamic_cast<RemoteDevice
*>(device
->Device());
164 remote
->Disconnect();
170 BView::MessageReceived(message
);
176 void RemoteDevicesView::LoadSettings(void)
182 bool RemoteDevicesView::IsDefaultable(void)