fat: Greatly simplify and clean up dosfs_get_file_map().
[haiku.git] / src / preferences / bluetooth / RemoteDevicesView.cpp
blobe4ebf545606389df69f8f93065c3969402729e62
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 <GroupLayoutBuilder.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 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));
65 // Set up device list
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)
75 .Add(fScrollView)
76 //.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
77 .Add(BGroupLayoutBuilder(B_VERTICAL)
78 .Add(addButton)
79 .Add(removeButton)
80 .AddGlue()
81 .Add(availButton)
82 .AddGlue()
83 .Add(pairButton)
84 .Add(disconnectButton)
85 .Add(blockButton)
86 .AddGlue()
87 .SetInsets(0, 15, 0, 15)
89 .SetInsets(5, 5, 5, 100)
92 fDeviceList->SetSelectionMessage(NULL);
96 RemoteDevicesView::~RemoteDevicesView(void)
102 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);
113 LoadSettings();
114 fDeviceList->Select(0);
118 void
119 RemoteDevicesView::MessageReceived(BMessage* message)
121 switch (message->what) {
122 case kMsgAddDevices:
124 InquiryPanel* inquiryPanel = new InquiryPanel(BRect(100, 100, 450, 450),
125 ActiveLocalDevice);
126 inquiryPanel->Show();
127 break;
130 case kMsgRemoveDevice:
131 printf("kMsgRemoveDevice: %ld\n", fDeviceList->CurrentSelection(0));
132 fDeviceList->RemoveItem(fDeviceList->CurrentSelection(0));
133 break;
134 case kMsgAddToRemoteList:
136 BListItem* device;
137 message->FindPointer("device", (void**)&device);
138 fDeviceList->AddItem(device);
139 fDeviceList->Invalidate();
140 break;
143 case kMsgPairDevice:
145 DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList
146 ->ItemAt(fDeviceList->CurrentSelection(0)));
147 RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device());
149 if (remote != NULL)
150 remote->Authenticate();
152 break;
154 case kMsgDisconnectDevice:
156 DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList
157 ->ItemAt(fDeviceList->CurrentSelection(0)));
158 RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device());
160 if (remote != NULL)
161 remote->Disconnect();
163 break;
166 default:
167 BView::MessageReceived(message);
168 break;
173 void RemoteDevicesView::LoadSettings(void)
179 bool RemoteDevicesView::IsDefaultable(void)
181 return true;