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 <GroupLayoutBuilder.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 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
46 addButton
= new BButton("add", B_TRANSLATE("Add" B_UTF8_ELLIPSIS
),
47 new BMessage(kMsgAddDevices
));
49 removeButton
= new BButton("remove", B_TRANSLATE("Remove"),
50 new BMessage(kMsgRemoveDevice
));
52 pairButton
= new BButton("pair", B_TRANSLATE("Pair" B_UTF8_ELLIPSIS
),
53 new BMessage(kMsgPairDevice
));
55 disconnectButton
= new BButton("disconnect", B_TRANSLATE("Disconnect"),
56 new BMessage(kMsgDisconnectDevice
));
58 blockButton
= new BButton("block", B_TRANSLATE("As blocked"),
59 new BMessage(kMsgBlockDevice
));
62 availButton
= new BButton("check", B_TRANSLATE("Refresh" B_UTF8_ELLIPSIS
),
63 new BMessage(kMsgRefreshDevices
));
66 fDeviceList
= new BListView("DeviceList", B_SINGLE_SELECTION_LIST
);
68 fScrollView
= new BScrollView("ScrollView", fDeviceList
, 0, false, true);
69 fScrollView
->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR
));
71 SetLayout(new BGroupLayout(B_VERTICAL
));
73 // TODO: use all the additional height
74 AddChild(BGroupLayoutBuilder(B_HORIZONTAL
, 10)
76 //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
77 .Add(BGroupLayoutBuilder(B_VERTICAL
)
84 .Add(disconnectButton
)
87 .SetInsets(0, 15, 0, 15)
89 .SetInsets(5, 5, 5, 100)
92 fDeviceList
->SetSelectionMessage(NULL
);
96 RemoteDevicesView::~RemoteDevicesView(void)
103 RemoteDevicesView::AttachedToWindow(void)
105 fDeviceList
->SetTarget(this);
106 addButton
->SetTarget(this);
107 removeButton
->SetTarget(this);
108 pairButton
->SetTarget(this);
109 disconnectButton
->SetTarget(this);
110 blockButton
->SetTarget(this);
111 availButton
->SetTarget(this);
114 fDeviceList
->Select(0);
119 RemoteDevicesView::MessageReceived(BMessage
* message
)
121 switch (message
->what
) {
124 InquiryPanel
* inquiryPanel
= new InquiryPanel(BRect(100, 100, 450, 450),
126 inquiryPanel
->Show();
130 case kMsgRemoveDevice
:
131 printf("kMsgRemoveDevice: %ld\n", fDeviceList
->CurrentSelection(0));
132 fDeviceList
->RemoveItem(fDeviceList
->CurrentSelection(0));
134 case kMsgAddToRemoteList
:
137 message
->FindPointer("device", (void**)&device
);
138 fDeviceList
->AddItem(device
);
139 fDeviceList
->Invalidate();
145 DeviceListItem
* device
= static_cast<DeviceListItem
*>(fDeviceList
146 ->ItemAt(fDeviceList
->CurrentSelection(0)));
147 RemoteDevice
* remote
= dynamic_cast<RemoteDevice
*>(device
->Device());
150 remote
->Authenticate();
154 case kMsgDisconnectDevice
:
156 DeviceListItem
* device
= static_cast<DeviceListItem
*>(fDeviceList
157 ->ItemAt(fDeviceList
->CurrentSelection(0)));
158 RemoteDevice
* remote
= dynamic_cast<RemoteDevice
*>(device
->Device());
161 remote
->Disconnect();
167 BView::MessageReceived(message
);
173 void RemoteDevicesView::LoadSettings(void)
179 bool RemoteDevicesView::IsDefaultable(void)