libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / preferences / bluetooth / RemoteDevicesView.cpp
blob15545a9cccd556082a95a1ec8f9d7f3ae8bec83f
1 /*
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.
4 */
5 #include <stdio.h>
7 #include <Alert.h>
8 #include <Catalog.h>
9 #include <Messenger.h>
11 #include <Directory.h>
12 #include <Entry.h>
13 #include <File.h>
14 #include <Path.h>
16 #include <LayoutBuilder.h>
17 #include <SpaceLayoutItem.h>
19 #include <PincodeWindow.h>
20 #include <bluetooth/RemoteDevice.h>
22 #include "BluetoothWindow.h"
23 #include "defs.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)
42 : BView(name, 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));
63 // Set up device list
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)
69 .SetInsets(5)
70 .Add(fScrollView)
71 //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
72 .AddGroup(B_VERTICAL)
73 .SetInsets(0, 15, 0, 15)
74 .Add(addButton)
75 .Add(removeButton)
76 .AddGlue()
77 .Add(availButton)
78 .AddGlue()
79 .Add(pairButton)
80 .Add(disconnectButton)
81 .Add(blockButton)
82 .AddGlue()
83 .End()
84 .End();
86 fDeviceList->SetSelectionMessage(NULL);
90 RemoteDevicesView::~RemoteDevicesView(void)
96 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);
107 LoadSettings();
108 fDeviceList->Select(0);
112 void
113 RemoteDevicesView::MessageReceived(BMessage* message)
115 switch (message->what) {
116 case kMsgAddDevices:
118 InquiryPanel* inquiryPanel= new InquiryPanel(
119 BRect(100, 100, 450, 450), ActiveLocalDevice);
120 inquiryPanel->Show();
121 break;
124 case kMsgRemoveDevice:
125 printf("kMsgRemoveDevice: %" B_PRId32 "\n",
126 fDeviceList->CurrentSelection(0));
127 fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0));
128 break;
129 case kMsgAddToRemoteList:
131 BListItem* device;
132 message->FindPointer("device", (void**)&device);
133 fDeviceList->AddItem(device);
134 fDeviceList->Invalidate();
135 break;
138 case kMsgPairDevice:
140 DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList
141 ->ItemAt(fDeviceList->CurrentSelection(0)));
142 if (device == NULL)
143 break;
145 RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device());
146 if (remote == NULL)
147 break;
149 remote->Authenticate();
151 break;
153 case kMsgDisconnectDevice:
155 DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList
156 ->ItemAt(fDeviceList->CurrentSelection(0)));
157 if (device == NULL)
158 break;
160 RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device());
161 if (remote == NULL)
162 break;
164 remote->Disconnect();
166 break;
169 default:
170 BView::MessageReceived(message);
171 break;
176 void RemoteDevicesView::LoadSettings(void)
182 bool RemoteDevicesView::IsDefaultable(void)
184 return true;